diff --git a/Makefile b/Makefile index 6eb32a5..05faa5c 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,18 @@ NAME=tun2socks -BUILDDIR=$(shell pwd)/build -CMDDIR=$(shell pwd)/cmd +BUILD_DIR=$(shell pwd)/build +CMD_DIR=$(shell pwd)/cmd VERSION=$(shell git describe --tags --long || echo "unknown version") +BUILD_TIME=$(shell date -u) BUILD_TAGS='fakeDNS stats' -BUILD_LDFLAGS='-s -w -X "main.version=$(VERSION)"' -DEBUG_BUILD_LDFLAGS='-s -w -X "main.version=$(VERSION)-debug"' +BUILD_LDFLAGS='-s -w -X "github.com/xjasonlyu/tun2socks/constant.Version=$(VERSION)" -X "github.com/xjasonlyu/tun2socks/constant.BuildTime=$(BUILD_TIME)"' all: build build: - cd $(CMDDIR) && go build -ldflags $(BUILD_LDFLAGS) -v -tags $(BUILD_TAGS) -o $(BUILDDIR)/$(NAME) + cd $(CMD_DIR) && go build -ldflags $(BUILD_LDFLAGS) -v -tags $(BUILD_TAGS) -o $(BUILD_DIR)/$(NAME) debug: - cd $(CMDDIR) && go build -ldflags $(DEBUG_BUILD_LDFLAGS) -v -tags $(BUILD_TAGS) -race -o $(BUILDDIR)/$(NAME) + cd $(CMD_DIR) && go build -ldflags $(BUILD_LDFLAGS) -v -tags $(BUILD_TAGS) -race -o $(BUILD_DIR)/$(NAME) clean: - rm -rf $(BUILDDIR) \ No newline at end of file + rm -rf $(BUILD_DIR) \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 6e9b0c5..2e23e15 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -19,6 +19,7 @@ import ( D "github.com/xjasonlyu/tun2socks/common/dns" S "github.com/xjasonlyu/tun2socks/common/stats" + C "github.com/xjasonlyu/tun2socks/constant" // init logger _ "github.com/xjasonlyu/tun2socks/common/log/simple" @@ -27,9 +28,6 @@ import ( const MTU = 1500 var ( - version = "unknown version" - description = "A tun2socks implementation written in Go." - args = new(CmdArgs) postFlagsInitFn []func() @@ -87,8 +85,7 @@ func main() { flag.Parse() if *args.Version { - fmt.Println("Go-tun2socks", version) - fmt.Println(description) + fmt.Println("Go-tun2socks", C.Version, C.BuildTime) os.Exit(0) } diff --git a/constant/version.go b/constant/version.go new file mode 100644 index 0000000..17a26f8 --- /dev/null +++ b/constant/version.go @@ -0,0 +1,6 @@ +package constant + +var ( + Version = "unknown version" + BuildTime = "unknown time" +)