Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
55 lines (43 loc) · 1.79 KB
/
Copy pathMakefile
File metadata and controls
55 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
PKG := ./cmd/agent
BIN := ipsupport-code
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64
# Version stamped into the binary: the current tag, else the short commit.
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
.PHONY: build release archives test race vet fmt fmtcheck tidy clean
build: ## host binary for local testing
go build -ldflags "$(LDFLAGS)" -o dist/$(BIN) $(PKG)
release: ## stripped static binaries for every target into dist/
@mkdir -p dist
@for p in $(PLATFORMS); do \
set -e; \
os=$${p%/*}; arch=$${p#*/}; ext=$$( [ "$$os" = windows ] && echo .exe || echo ); \
echo "→ $$os/$$arch"; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -trimpath -ldflags "$(LDFLAGS)" -o dist/$(BIN)-$$os-$$arch$$ext $(PKG); \
done
archives: release ## package the release binaries into .tar.gz/.zip + SHA-256 checksums
@cd dist && rm -f *.tar.gz *.zip checksums.txt && \
for f in $(BIN)-*; do \
oa=$${f#$(BIN)-}; \
case $$f in \
*.exe) oa=$${oa%.exe}; cp "$$f" $(BIN).exe; zip -q "$(BIN)_$(VERSION)_$$oa.zip" $(BIN).exe; rm $(BIN).exe ;; \
*) cp "$$f" $(BIN); tar -czf "$(BIN)_$(VERSION)_$$oa.tar.gz" $(BIN); rm $(BIN) ;; \
esac; \
done && \
sha256sum $(BIN)_*.tar.gz $(BIN)_*.zip > checksums.txt && \
echo "→ archives + checksums.txt in dist/"
test: ## run all tests
go test ./...
race: ## run all tests with the race detector
go test -race ./...
vet: ## go vet
go vet ./...
fmt: ## format the code
gofmt -w .
fmtcheck: ## fail if anything is unformatted
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then echo "gofmt needed on:"; echo "$$unformatted"; exit 1; fi
tidy: ## tidy modules
go mod tidy
clean: ## remove build artifacts
rm -rf dist