diff --git a/Makefile b/Makefile index 18a1150..ab4aebe 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,27 @@ NAME := stc +GIT_TAG=$(shell git describe --tags --always --dirty) +LDFLAGS=-ldflags "-X main.GitTag=$(GIT_TAG)" all: $(NAME) $(NAME): *.go - go build -o $(NAME) . + go build $(LDFLAGS) -o $(NAME) . cross: - GOOS=linux GOARCH=amd64 go build -a -o $(NAME)-amd64-linux . - GOOS=linux GOARCH=arm go build -a -o $(NAME)-arm-linux . - GOOS=linux GOARCH=arm64 go build -a -o $(NAME)-arm64-linux . - GOOS=darwin GOARCH=amd64 go build -a -o $(NAME)-amd64-macos . - GOOS=darwin GOARCH=arm64 go build -a -o $(NAME)-arm64-macos . - GOOS=freebsd GOARCH=amd64 go build -a -o $(NAME)-amd64-freebsd . - GOOS=openbsd GOARCH=amd64 go build -a -o $(NAME)-amd64-openbsd . - GOOS=netbsd GOARCH=amd64 go build -a -o $(NAME)-amd64-netbsd . - GOOS=solaris GOARCH=amd64 go build -a -o $(NAME)-adm64-solaris . - GOOS=aix GOARCH=ppc64 go build -a -o $(NAME)-ppc64-aix . - GOOS=plan9 GOARCH=amd64 go build -a -o $(NAME)-amd64-plan9 . - GOOS=plan9 GOARCH=arm go build -a -o $(NAME)-arm-plan9 . - GOOS=windows GOARCH=amd64 go build -a -o $(NAME)-amd64-win64.exe - GOOS=windows GOARCH=arm64 go build -a -o $(NAME)-arm64-win64.exe - GOOS=windows GOARCH=386 go build -a -o $(NAME)-arm64-win32.exe + GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-linux . + GOOS=linux GOARCH=arm go build $(LDFLAGS) -a -o $(NAME)-arm-linux . + GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -a -o $(NAME)-arm64-linux . + GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-macos . + GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -a -o $(NAME)-arm64-macos . + GOOS=freebsd GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-freebsd . + GOOS=openbsd GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-openbsd . + GOOS=netbsd GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-netbsd . + GOOS=solaris GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-adm64-solaris . + GOOS=aix GOARCH=ppc64 go build $(LDFLAGS) -a -o $(NAME)-ppc64-aix . + GOOS=plan9 GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-plan9 . + GOOS=plan9 GOARCH=arm go build $(LDFLAGS) -a -o $(NAME)-arm-plan9 . + GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -a -o $(NAME)-amd64-win64.exe + GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -a -o $(NAME)-arm64-win64.exe + GOOS=windows GOARCH=386 go build $(LDFLAGS) -a -o $(NAME)-arm64-win32.exe + +clean: + rm -f stc stc-* diff --git a/hlp.go b/hlp.go index abac10f..0bd1261 100755 --- a/hlp.go +++ b/hlp.go @@ -33,6 +33,10 @@ func usage() { ) } +func printVer() { + fmt.Printf("stc version %v\n", GitTag) +} + func findCfgFile(homeDir string) (string, error) { getCfgFile := func(dir string) (string, error) { _, err := os.Stat(dir) diff --git a/stc.go b/stc.go index 034c2c2..1102abf 100755 --- a/stc.go +++ b/stc.go @@ -21,6 +21,8 @@ var ( target = flag.String("target", "", "Syncthing Target URL") homeDir = flag.String("homedir", "", "Syncthing Home Directory, used to get API Key and Target") igCert = flag.Bool("ignore_cert_errors", false, "ignore https/ssl/tls cert errors") + verFlag = flag.Bool("version", false, "print version") + GitTag string ) type SyncFolder struct { @@ -351,6 +353,10 @@ func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) flag.Usage = usage flag.Parse() + if *verFlag { + printVer() + os.Exit(0) + } a, t, err := cfg(*apiKey, *target, *homeDir) if err != nil {