From 6bfbc52972c2f1283b94cc6154e1f5c2cf8c635c Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Thu, 31 Oct 2024 11:35:01 +0100 Subject: [PATCH] Build system: more robust container-image builds A container image usually consists of a image name and a tag. The tag consists usually consists only of the version number. Sometimes, information like a "pre-release" or a "build-number" are added to the tag. Example given: mtr-exporter-0.3.0-rc1 The build system tries to build a binary named mtr-exporter-0.3.0-rc1.linux.amd64 and fails because the rule to build such a binary does not exist. This commit fixes the issue by relaxing the wildcard pattern. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e0774c5..fade8f6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROJECT=mtr-exporter -VERSION=$(shell cat VERSION) +VERSION?=$(shell cat VERSION) BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") GIT_HASH=$(shell git rev-parse HEAD) CONTAINER_PLATFORM?=linux/amd64 @@ -16,7 +16,7 @@ TARGETS=linux.amd64 \ BINARIES=$(addprefix bin/$(PROJECT)-$(VERSION)., $(TARGETS)) RELEASES=$(subst windows.amd64.tar.gz,windows.amd64.zip,$(foreach r,$(subst .exe,,$(TARGETS)),releases/$(PROJECT)-$(VERSION).$(r).tar.gz)) -LDFLAGS=$(LDFLAGS) -ldflags "-X main.Version=$(VERSION) -X main.BuildDate=$(BUILD_DATE) -X main.GitHash=$(GIT_HASH)" +LDFLAGS:=$(LDFLAGS) -ldflags "-X main.Version=$(VERSION) -X main.BuildDate=$(BUILD_DATE) -X main.GitHash=$(GIT_HASH)" $(PROJECT): go build -v -o $@ ./cmd/$(PROJECT) @@ -36,9 +36,9 @@ $(PROJECT): bin/$(PROJECT) bin/$(PROJECT): cmd/$(PROJECT) bin go build -v -o $@ ./$< -bin/$(PROJECT)-$(VERSION).%: +bin/$(PROJECT)-$(VERSION)%: env GOARCH=$(subst .,,$(suffix $(subst .exe,,$@))) \ - GOOS=$(subst .,,$(suffix $(basename $(subst .exe,,$@)))) \ + GOOS=$(subst .,,$(suffix $(basename $(subst .exe,,$@)))) \ CGO_ENABLED=0 \ go build $(LDFLAGS) -o $@ ./cmd/$(PROJECT)