diff --git a/Makefile b/Makefile index 4093c13..297136b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +TARGETS = darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386 +GIT_COMMIT = $(shell git rev-parse HEAD) DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')" BINDATA_IGNORE = $(shell git ls-files -io --exclude-standard $< | sed 's/^/-ignore=/;s/[.]/[.]/g') @@ -37,7 +39,10 @@ build: assets @echo "You can now execute ./pgweb" release: assets - gox -osarch="darwin/amd64 darwin/386 linux/amd64 linux/386 windows/amd64 windows/386" -output="./bin/pgweb_{{.OS}}_{{.Arch}}" + gox \ + -osarch="$(TARGETS)" \ + -ldflags "-X main.GitCommit $(GIT_COMMIT)" \ + -output="./bin/pgweb_{{.OS}}_{{.Arch}}" bootstrap: gox -build-toolchain diff --git a/main.go b/main.go index 0fc7b05..b87a62f 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,9 @@ import ( const VERSION = "0.5.2" +// The git commit that was compiled. This will be filled in by the compiler. +var GitCommit string + var options command.Options func exitWithMessage(message string) { @@ -61,11 +64,20 @@ func initOptions() { options = command.Opts if options.Version { - fmt.Printf("pgweb v%s\n", VERSION) + printVersion() os.Exit(0) } - fmt.Println("Pgweb version", VERSION) + printVersion() +} + +func printVersion() { + str := fmt.Sprintf("Pgweb v%s", VERSION) + if GitCommit != "" { + str += fmt.Sprintf(" (git: %s)", GitCommit) + } + + fmt.Println(str) } func startServer() {