-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
96 lines (76 loc) · 2.41 KB
/
Makefile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
.PHONY: dist install clean clean-dist dev-build
CUR_SHA=$(shell git log -n1 --pretty='%h')
CUR_BRANCH=$(shell git branch --show-current)
VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA))
GIT_PATH:=github.com/metal3d/goreorder
PACKAGE:=$(GIT_PATH)/...
COMMAND_PACKAGE:=$(GIT_PATH)/cmd/goreorder
DIST_CC:=podman run
DIST_CC_OPTS:=--rm -i --userns keep-id -v $(PWD):/go/src/github.com/metal3d/goreorder:z -w /go/src/github.com/metal3d/goreorder -e CGO_ENABLED=0 docker.io/golang:1.18
CC=go
CC_OPTS=-ldflags "-X main.version=$(VERSION)"
TARGETS=dist/goreorder-linux-amd64 dist/goreorder-darwin-amd64 dist/goreorder-windows-amd64.exe dist/goreorder-freebsd-amd64
# TEST selection
# e.g. TEST="TestFoo TestBar"
TEST=
install:
go install -v $(CC_OPTS) $(COMMAND_PACKAGE)
uninstall:
go clean -i ./...
dev-build:
go build -v $(CC_OPTS) -o goreorder ./cmd/goreorder/*.go
.ONESHELL:
dist: clean-dist $(TARGETS)
# stripping
strip dist/goreorder-linux-amd64 || true
strip dist/goreorder-darwin-amd64 || true
strip dist/goreorder-windows-amd64.exe || true
strip dist/goreorder-freebsd-amd64 || true
gpg-sign:
# sign with gpg
for i in $$(find dist -type f); do
echo "Signing $$i with gpg..."
gpg --armor --detach-sign --local-user $(SIGNER) $$i
done
dist/goreorder-linux-amd64:
@mkdir -p dist
ifeq ($(strip $(_CNT)),true)
GOOS=linux GOARCH=amd64 $(CC) build $(CC_OPTS) -o $@ $(COMMAND_PACKAGE)
else
$(DIST_CC) -e _CNT=true $(DIST_CC_OPTS) make $@
endif
dist/goreorder-darwin-amd64:
@mkdir -p dist
ifeq ($(strip $(_CNT)),true)
GOOS=darwin GOARCH=amd64 $(CC) build $(CC_OPTS) -o $@ $(COMMAND_PACKAGE)
else
$(DIST_CC) -e _CNT=true $(DIST_CC_OPTS) make $@
endif
dist/goreorder-windows-amd64.exe:
@mkdir -p dist
ifeq ($(strip $(_CNT)),true)
GOOS=windows GOARCH=amd64 $(CC) build $(CC_OPTS) -o $@ $(COMMAND_PACKAGE)
else
$(DIST_CC) -e _CNT=true $(DIST_CC_OPTS) make $@
endif
dist/goreorder-freebsd-amd64:
@mkdir -p dist
ifeq ($(strip $(_CNT)),true)
GOOS=freebsd GOARCH=amd64 $(CC) build $(CC_OPTS) -o $@ $(COMMAND_PACKAGE)
else
$(DIST_CC) -e _CNT=true $(DIST_CC_OPTS) make $@
endif
clean-dist:
rm -rf dist
clean: clean-dist
rm -f ./goreorder
test:
ifeq ($(strip $(TEST)),)
go test -v -race -cover -short ./...
else
go test -v -race -run $(TEST) ./...
endif
test-cover-html:
go test -cover -coverprofile=coverage.out ./...
go tool cover -html=coverage.out