diff --git a/Makefile b/Makefile index b42ccac..a29314c 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ graftcp: main.o util.o string-set.o $(CC) $(CFLAGS) -c -o $@ $< $(GRAFTCP_LOCAL_BIN):: - $(MAKE) -C graftcp-local + $(MAKE) -C graftcp-local VERSION=$(VERSION) install:: graftcp $(GRAFTCP_LOCAL_BIN) $(INSTALL) $< $(DESTDIR)$(BINDIR)/$< diff --git a/graftcp-local/Makefile b/graftcp-local/Makefile index d861d5d..1a5fdb8 100644 --- a/graftcp-local/Makefile +++ b/graftcp-local/Makefile @@ -1,6 +1,10 @@ export GOPATH := $(CURDIR)/.gopath export PATH := $(PATH):$(CURDIR)/.gopath/bin +ifneq ($(shell echo $(VERSION) | head -c 1), v) + VERSION=v0.3 +endif + PREFIX = /usr/local BINDIR = $(PREFIX)/bin @@ -11,7 +15,7 @@ GO_IMPORT_PATH := github.com/hmgle/graftcp/graftcp-local all:: graftcp-local graftcp-local: .gopath/.created $(wildcard *.go) - go build -ldflags "-s -w" $(GO_IMPORT_PATH) + go build -ldflags "-s -w -X main.version=${VERSION}" $(GO_IMPORT_PATH) .gopath/.created: rm -rf .gopath diff --git a/graftcp-local/main.go b/graftcp-local/main.go index c84cad5..74880f1 100644 --- a/graftcp-local/main.go +++ b/graftcp-local/main.go @@ -10,7 +10,10 @@ import ( "github.com/kardianos/service" ) -var selectProxyMode string +var ( + selectProxyMode string + version = "v0.3" +) type App struct { ListenAddr string @@ -86,7 +89,12 @@ func main() { "Set the mode for select a proxy [auto | random | only_http_proxy | only_socks5]") flag.StringVar(&configFile, "config", "", "Path to the configuration file") flag.StringVar(&app.PipePath, "pipepath", "/tmp/graftcplocal.fifo", "Pipe path for graftcp to send address info") + v := flag.Bool("version", false, "Print the graftcp-local version information") flag.Parse() + if *v { + fmt.Printf("graftcp-local version %s\n", version) + os.Exit(0) + } ParseConfigFile(configFile, app) dlog.Noticef("graftcp-local start")