Skip to content

Commit

Permalink
Refactor Makefile.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
knadh committed Apr 10, 2024
1 parent a1cd0a7 commit d5d7940
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ before:

builds:
- env:
- CGO_ENABLED=1
- CGO_ENABLED=0
binary: kaf-relay
goos:
- linux
goarch:
- amd64
ldflags:
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})" -X "main.versionString={{ .Tag }}"

archives:
- format: tar.gz
files:
- config.toml.sample
- README.md
- LICENSE
- LICENSE
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Git version for injecting into Go bins.
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT})
VERSION := $(shell git describe --tags)
BUILDSTR := ${VERSION} (Commit: ${LAST_COMMIT_DATE} (${LAST_COMMIT}), Build: $(shell date +"%Y-%m-%d% %H:%M:%S %z"))
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"")

BIN := kaf-relay.bin
DIST := dist
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
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")
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))

.PHONY: dist
dist:
mkdir -p ${DIST}
CGO_ENABLED=1 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"
cp ${BIN} ${DIST}
BIN := kaf-relay

.PHONY: build
build: $(BIN)

$(BIN):
CGO_ENABLED=0 go build -o ${BIN} --ldflags="-X 'main.buildString=${BUILDSTR}'"

.PHONY: clean
clean:
rm -rf ${DIST}
rm -rf ${BIN}

0 comments on commit d5d7940

Please sign in to comment.