@@ -7,6 +7,7 @@ MANINSTALLDIR=${PREFIX}/share/man
7
7
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
8
8
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
9
9
COMMIT := $(if $(shell git status --porcelain --untracked-files=no) ,"${COMMIT_NO}-dirty","${COMMIT_NO}")
10
+ VERSION := $(shell git describe --tags --always | cut -c 2-)
10
11
DOCKER_IMAGE := manifest-tool-dev$(if $(GIT_BRANCH ) ,:$(GIT_BRANCH ) )
11
12
# set env like gobuildtag?
12
13
DOCKER_RUN := docker run --rm -i # $(DOCKER_ENVS)
@@ -22,17 +23,19 @@ DOCKER_RUN_DOCKER := $(DOCKER_RUN) -v $(shell pwd):/go/src/github.com/estesp/man
22
23
all : binary
23
24
24
25
build :
25
- $(DOCKER_RUN ) -v $(shell pwd) :/go/src/github.com/estesp/manifest-tool -w /go/src/github.com/estesp/manifest-tool golang:1.17 /bin/bash -c " \
26
- cd v2 && go build -ldflags \" -X main.gitCommit=${COMMIT} \" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool"
26
+ $(DOCKER_RUN ) -v $(shell pwd) :/go/src/github.com/estesp/manifest-tool -w /go/src/github.com/estesp/manifest-tool golang:1.20 /bin/bash -c " \
27
+ cd v2 && go build -ldflags \" -X main.gitCommit=${COMMIT} main.version= ${VERSION} \" -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool"
27
28
28
29
# Target to build a dynamically linked binary
29
30
binary : v2/pkg/util/oslist.go
30
- cd v2 && go build -ldflags " -X main.gitCommit=${COMMIT} " -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
31
+ cd v2 && go build \
32
+ -ldflags " -X main.gitCommit=${COMMIT} -X main.version=${VERSION} " \
33
+ -o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
31
34
32
35
# Target to build a statically linked binary
33
36
static : v2/pkg/util/oslist.go
34
37
cd v2 && GO_EXTLINK_ENABLED=0 CGO_ENABLED=0 go build \
35
- -ldflags " -w -extldflags -static -X main.gitCommit=${COMMIT} " \
38
+ -ldflags " -w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version= ${VERSION} " \
36
39
-tags netgo -installsuffix netgo \
37
40
-o ../manifest-tool github.com/estesp/manifest-tool/v2/cmd/manifest-tool
38
41
0 commit comments