| 
3 | 3 | GIT_COMMIT := $(shell git log -1 --format='%H' 2>/dev/null || echo "unknown")  | 
4 | 4 | GIT_TAG    := $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//')  | 
5 | 5 | 
 
  | 
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 \  | 
8 | 11 | 	-X github.com/sentinel-official/sentinel-go-sdk/version.Commit=$(GIT_COMMIT) \  | 
9 | 12 | 	-X github.com/sentinel-official/sentinel-go-sdk/version.Tag=$(GIT_TAG)  | 
10 | 13 | 
 
  | 
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  | 
12 | 23 | 
 
  | 
13 | 24 | GOBIN ?= $(shell go env GOBIN)  | 
14 | 25 | ifeq ($(GOBIN),)  | 
15 | 26 |   GOBIN := $(shell go env GOPATH)/bin  | 
16 | 27 | endif  | 
17 | 28 | 
 
  | 
 | 29 | +IMAGE ?= sentinel-dvpnx:latest  | 
 | 30 | + | 
18 | 31 | .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}'  | 
28 | 35 | 
 
  | 
29 | 36 | .PHONY: build  | 
30 |  | -build:  | 
 | 37 | +build: ## Build the binary (./bin/sentinel-dvpnx)  | 
31 | 38 | 	go build $(build_flags) -o ./bin/sentinel-dvpnx main.go  | 
32 | 39 | 
 
  | 
33 | 40 | .PHONY: install  | 
34 |  | -install:  | 
 | 41 | +install: ## Install the binary into $GOBIN  | 
35 | 42 | 	go build $(build_flags) -o "$(GOBIN)/sentinel-dvpnx" main.go  | 
36 | 43 | 
 
  | 
37 | 44 | .PHONY: clean  | 
38 |  | -clean:  | 
 | 45 | +clean: ## Remove build artifacts  | 
39 | 46 | 	$(RM) -r ./bin ./vendor  | 
40 | 47 | 
 
  | 
41 | 48 | .PHONY: test  | 
42 |  | -test:  | 
 | 49 | +test: ## Run tests  | 
43 | 50 | 	go test -cover -mod=readonly -v ./...  | 
44 | 51 | 
 
  | 
45 | 52 | .PHONY: benchmark  | 
46 |  | -benchmark:  | 
 | 53 | +benchmark: ## Run benchmarks  | 
47 | 54 | 	go test -bench -mod=readonly -v ./...  | 
48 | 55 | 
 
  | 
49 | 56 | .PHONY: go-lint  | 
50 |  | -go-lint:  | 
 | 57 | +go-lint: ## Run golangci-lint with auto-fix  | 
51 | 58 | 	golangci-lint run --fix  | 
52 | 59 | 
 
  | 
53 | 60 | .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