Skip to content

Commit d5d7940

Browse files
committed
Refactor Makefile.
- Fix incorrect .PHONY clause for the binary. - Change `dist` to the more conventional `build`. - Rename binary to `kaf-relay` from `kaf-relay.bin`. - Make version string construction more robust.
1 parent a1cd0a7 commit d5d7940

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

.goreleaser.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ before:
44

55
builds:
66
- env:
7-
- CGO_ENABLED=1
7+
- CGO_ENABLED=0
88
binary: kaf-relay
99
goos:
1010
- linux
1111
goarch:
1212
- amd64
13+
ldflags:
14+
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" -X "main.versionString={{ .Tag }}"
1315

1416
archives:
1517
- format: tar.gz
1618
files:
1719
- config.toml.sample
1820
- README.md
19-
- LICENSE
21+
- LICENSE

Makefile

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# Git version for injecting into Go bins.
2-
LAST_COMMIT := $(shell git rev-parse --short HEAD)
3-
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT})
4-
VERSION := $(shell git describe --tags)
5-
BUILDSTR := ${VERSION} (Commit: ${LAST_COMMIT_DATE} (${LAST_COMMIT}), Build: $(shell date +"%Y-%m-%d% %H:%M:%S %z"))
1+
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
2+
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"")
63

7-
BIN := kaf-relay.bin
8-
DIST := dist
4+
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
5+
VERSION := $(or $(LISTMONK_VERSION),$(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP 'tag: \Kv\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?' VERSION),"v0.0.0")
6+
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
97

10-
.PHONY: dist
11-
dist:
12-
mkdir -p ${DIST}
13-
CGO_ENABLED=1 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"
14-
cp ${BIN} ${DIST}
8+
BIN := kaf-relay
9+
10+
.PHONY: build
11+
build: $(BIN)
12+
13+
$(BIN):
14+
CGO_ENABLED=0 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"
1515

1616
.PHONY: clean
1717
clean:
18-
rm -rf ${DIST}
18+
rm -rf ${BIN}

0 commit comments

Comments
 (0)