From 5887d3b53e2154943a374f41d82f658a57b5312f Mon Sep 17 00:00:00 2001 From: Arjun Raja Yogidas <arjunry@amazon.com> Date: Sun, 13 Oct 2024 04:03:57 +0000 Subject: [PATCH] fix: Update makefile for build target Signed-off-by: Arjun Raja Yogidas <arjunry@amazon.com> --- Makefile | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 1e3d706..273ff84 100644 --- a/Makefile +++ b/Makefile @@ -13,20 +13,23 @@ BINDIR ?= $(PREFIX)/bin BINARY = $(addprefix bin/,finch-daemon) -.PHONY: build -build: - $(eval PACKAGE := github.com/runfinch/finch-daemon) - $(eval VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags)) - $(eval GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)) -ifneq ($(STATIC),) - $(eval GO_BUILDTAGS := osusergo netgo) - $(eval LDFLAGS := "-X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT) -extldflags '-static'") - @echo "Building Static Binary" +PACKAGE := github.com/runfinch/finch-daemon +VERSION := $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags) +GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) + +LDFLAGS := -X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT) + +ifeq ($(STATIC),) + GO_BUILDTAGS := osusergo netgo + LDFLAGS += -extldflags '-static' + $(info Building Static Binary) else - @echo "Building Dynamic Binary" - $(eval LDFLAGS := "-X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT)") + $(info Building Dynamic Binary) endif - GOOS=linux go build $(if $(GO_BUILDTAGS), -tags "$(GO_BUILDTAGS)") -ldflags $(LDFLAGS) $(if $(STATIC), ) -v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon + +.PHONY: build +build: + GOOS=linux go build $(if $(GO_BUILDTAGS), -tags "$(GO_BUILDTAGS)") -ldflags "$(LDFLAGS)" -v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon .PHONY: linux linux: