Skip to content

Commit

Permalink
fix: Update makefile for build target
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Raja Yogidas <[email protected]>
  • Loading branch information
coderbirju committed Oct 13, 2024
1 parent 090da7c commit 5887d3b
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5887d3b

Please sign in to comment.