Skip to content

Commit 9297c8b

Browse files
committed
chore: refactor Makefile
1 parent 1e4864c commit 9297c8b

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

Makefile

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,60 @@
33
GIT_COMMIT := $(shell git log -1 --format='%H' 2>/dev/null || echo "unknown")
44
GIT_TAG := $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//')
55

6-
TAGS := $(strip netgo)
7-
LD_FLAGS := -s -w \
6+
comma := ,
7+
whitespace := $(empty) $(empty)
8+
9+
build_tags := netgo
10+
ld_flags := -s -w \
811
-X github.com/sentinel-official/sentinel-go-sdk/version.Commit=$(GIT_COMMIT) \
912
-X github.com/sentinel-official/sentinel-go-sdk/version.Tag=$(GIT_TAG)
1013

11-
build_flags = -ldflags="$(LD_FLAGS)" -mod=readonly -tags="$(TAGS)" -trimpath
14+
ifeq ($(STATIC),true)
15+
build_tags += muslc
16+
ld_flags += -linkmode=external -extldflags '-Wl,-z,muldefs -static'
17+
endif
18+
19+
BUILD_TAGS := $(subst $(whitespace),$(comma),$(build_tags))
20+
LD_FLAGS := $(ld_flags)
21+
22+
build_flags = -ldflags="$(LD_FLAGS)" -mod=readonly -tags="$(BUILD_TAGS)" -trimpath
1223

1324
GOBIN ?= $(shell go env GOBIN)
1425
ifeq ($(GOBIN),)
1526
GOBIN := $(shell go env GOPATH)/bin
1627
endif
1728

29+
IMAGE ?= sentinel-dvpnx:latest
30+
1831
.PHONY: help
19-
help:
20-
@echo "Available targets:"
21-
@echo " build Build the binary (./bin/sentinel-dvpnx)"
22-
@echo " install Install the binary to \$$GOBIN"
23-
@echo " clean Remove build artifacts"
24-
@echo " test Run tests with coverage"
25-
@echo " benchmark Run benchmarks"
26-
@echo " go-lint Run golangci-lint with auto-fix"
27-
@echo " build-image Build Docker image"
32+
help: ## Show available targets
33+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
34+
awk 'BEGIN {FS = ":.*?## "}; {printf "%-20s %s\n", $$1, $$2}'
2835

2936
.PHONY: build
30-
build:
37+
build: ## Build the binary (./bin/sentinel-dvpnx)
3138
go build $(build_flags) -o ./bin/sentinel-dvpnx main.go
3239

3340
.PHONY: install
34-
install:
41+
install: ## Install the binary into $GOBIN
3542
go build $(build_flags) -o "$(GOBIN)/sentinel-dvpnx" main.go
3643

3744
.PHONY: clean
38-
clean:
45+
clean: ## Remove build artifacts
3946
$(RM) -r ./bin ./vendor
4047

4148
.PHONY: test
42-
test:
49+
test: ## Run tests
4350
go test -cover -mod=readonly -v ./...
4451

4552
.PHONY: benchmark
46-
benchmark:
53+
benchmark: ## Run benchmarks
4754
go test -bench -mod=readonly -v ./...
4855

4956
.PHONY: go-lint
50-
go-lint:
57+
go-lint: ## Run golangci-lint with auto-fix
5158
golangci-lint run --fix
5259

5360
.PHONY: build-image
54-
build-image:
55-
docker build --compress --file Dockerfile --force-rm --tag sentinel-dvpnx .
61+
build-image: ## Build Docker image
62+
docker build --compress --file Dockerfile --force-rm --tag $(IMAGE) .

0 commit comments

Comments
 (0)