-
Notifications
You must be signed in to change notification settings - Fork 43
/
Makefile
56 lines (48 loc) · 1.86 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
DIST_DIR = ./dist
BINARY = $(DIST_DIR)/upgit
SRC = .
LDFLAGS = -ldflags="-s -w"
create_dist_dir:
@mkdir -p $(DIST_DIR)
# Build agent should be run on macos, otherwise it will fail at macos target
# ```
# # runtime/cgo
# gcc: error: unrecognized command-line option '-arch'
# make: *** [Makefile:16: macos] Error 2
# ```
macos: create_dist_dir
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -o $(BINARY)_macos_amd64 $(LDFLAGS) $(SRC)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -o $(BINARY)_macos_arm64 $(LDFLAGS) $(SRC)
windows: create_dist_dir
GOOS=windows GOARCH=386 go build -o $(BINARY)_win_386.exe $(LDFLAGS) $(SRC)
GOOS=windows GOARCH=amd64 go build -o $(BINARY)_win_amd64.exe $(LDFLAGS) $(SRC)
GOOS=windows GOARCH=arm go build -o $(BINARY)_win_arm.exe $(LDFLAGS) $(SRC)
GOOS=windows GOARCH=arm64 go build -o $(BINARY)_win_arm64.exe $(LDFLAGS) $(SRC)
# You may need to install gcc-multilib to build 32-bit binaries on 64-bit Linux
# ```
# sudo apt-get install gcc-multilib
# ```
linux: create_dist_dir
@if x86_64-linux-musl-gcc --version >/dev/null 2>&1; then \
echo "Using musl compiler"; \
export CC=x86_64-linux-musl-gcc; \
export CXX=x86_64-linux-musl-g++; \
else \
echo "musl compiler not found. Using gnu compiler"; \
export CC=gcc; \
export CXX=g++; \
fi && \
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=$$CC CXX=$$CXX go build -o $(BINARY)_cgo_linux_amd64 $(LDFLAGS) $(SRC)
GOOS=linux GOARCH=386 go build -o $(BINARY)_linux_386 $(LDFLAGS) $(SRC)
GOOS=linux GOARCH=amd64 go build -o $(BINARY)_linux_amd64 $(LDFLAGS) $(SRC)
GOOS=linux GOARCH=arm go build -o $(BINARY)_linux_arm $(LDFLAGS) $(SRC)
GOOS=linux GOARCH=arm64 go build -o $(BINARY)_linux_arm64 $(LDFLAGS) $(SRC)
upx: all
for i in $(DIST_DIR)/*
do
upx -9 $i
done
all: windows macos linux
@echo "done."
clean:
rm -rfd $(DIST_DIR)