11PACKAGE := tryssh/cmd/version
2- VERSION := v0.3.4
32GO_VERSION := $(shell go version | awk '{print $$3}')
43BUILD_TIME := $(shell date -u '+% Y-% m-% d % H:% M:% S')
54LDFLAGS :=
65
7- LDFLAGS += -X '$(PACKAGE ) .TrysshVersion=$(VERSION ) '
6+ GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
7+
8+ os-archs =darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm linux:arm64 windows:amd64 windows:arm64
9+
10+ ifdef VERSION
11+ BINARY_VERSION = $(VERSION)
12+ endif
13+ BINARY_VERSION ?= ${GIT_TAG}
14+
15+ # Only set Version if building a tag or VERSION is set
16+ ifneq ($(BINARY_VERSION ) ,)
17+ LDFLAGS += -X '$(PACKAGE).TrysshVersion=$(BINARY_VERSION)'
18+ else
19+ # If you cannot find any information that can be used as a version number, change it to debug
20+ BINARY_VERSION = "debug"
21+ endif
22+
823LDFLAGS += -X '$(PACKAGE ) .BuildGoVersion=$(GO_VERSION ) '
924LDFLAGS += -X '$(PACKAGE ) .BuildTime=$(BUILD_TIME ) UTC'
1025
@@ -13,12 +28,27 @@ default: build
1328
1429.PHONY : build
1530build : tidy
16- @go build -ldflags " $( LDFLAGS) " ./
31+ @go build -v -trimpath - ldflags " $( LDFLAGS) " ./
1732
1833.PHONY : tidy
19- tidy :
34+ tidy : clean
2035 @go mod tidy
2136
2237.PHONY : clean
2338clean :
2439 @go clean
40+ @rm -rf ./release
41+
42+ .PHONY : multi
43+ multi : tidy
44+ @$(foreach n, $(os-archs ) ,\
45+ os=$(shell echo "$(n ) " | cut -d : -f 1) ; \
46+ arch=$(shell echo "$(n ) " | cut -d : -f 2) ; \
47+ target_suffix=${BINARY_VERSION} -$$ {os}-$$ {arch}; \
48+ echo " Build $$ {os}-$$ {arch}..." ; \
49+ env CGO_ENABLED=0 GOOS=$$ {os} GOARCH=$$ {arch} go build -v -trimpath -ldflags " $( LDFLAGS) " \
50+ -o ./release/tryssh-$$ {target_suffix}; \
51+ echo " Build $$ {os}-$$ {arch} done" ; \
52+ )
53+ @mv ./release/tryssh-${BINARY_VERSION} -windows-amd64 ./release/tryssh-${BINARY_VERSION} -windows-amd64.exe
54+ @mv ./release/tryssh-${BINARY_VERSION} -windows-arm64 ./release/tryssh-${BINARY_VERSION} -windows-arm64.exe
0 commit comments