-
Notifications
You must be signed in to change notification settings - Fork 38
/
Makefile
68 lines (53 loc) · 1.56 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
# wiretap Makefile
# Double ## are used in the help mesage
VERSION=$(shell git describe --tags --abbrev=0 --always)
# defaults
OS=$(shell go env GOOS)## Target OS
ARCH=$(shell go env GOARCH)## Target architecture
BIN=../bin## Binary location
# env
GOOS=GOOS=$(OS)
GOARCH=GOARCH=$(ARCH)
CGO=CGO_ENABLED=0
ENV=env $(GOOS) $(GOARCH) $(CGO)
# gobuild
GOCMD=go
GOBUILD=$(GOCMD) build
# flags with no arguments
NOARGFLAGS=-trimpath
# output extension
ifeq ($(OS), windows)
EXT=.exe
else
EXT=
endif
OUTPUT=$(BIN)/$@_$(OS)_$(ARCH)$(EXT)## Output location
# ld flags
LDFLAGS=-s -w
LDFLAGS+=-X wiretap/cmd.Version=$(VERSION)
.PHONY: all packed wiretap clean help
.DEFAULT_GOAL := wiretap
## wiretap: Build binary for the specified OS and architecture
wiretap:
$(ENV) $(GOBUILD) $(NOARGFLAGS) -o $(OUTPUT) -ldflags "$(LDFLAGS)" *.go
## all: Build binaries for every OS/ARCH pair listed in the Makefile
all:
$(MAKE) OS=windows ARCH=amd64
$(MAKE) OS=darwin ARCH=amd64
$(MAKE) OS=linux ARCH=amd64
## packed: Build and pack all binaries with upx
packed: all
upx --brute $(BIN)/wiretap_*
## clean: Remove all binaries
clean:
rm -vf $(BIN)/*
# reference: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
## help: Print this message
help:
@echo "Wiretap Makefile"
@echo ""
@echo "Targets:"
@grep -E '^## [a-zA-Z_-]+: .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ": |## "}; {printf " %-30s %s\n", $$2, $$3}'
@echo ""
@echo "Variables (KEY=DEFAULT):"
@grep -E '^[a-zA-Z_-]+=.+?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = "## "}; {printf " %-30s %s\n", $$1, $$2}'