-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
235 lines (184 loc) · 5.77 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/make -ef
export NAME = go-ma-actor
MODULE_NAME = github.com/bahner/go-ma-actor
export VERSION = "v0.0.2"
GO ?= go
BUILDFLAGS ?= -ldflags="-s -w"
PREFIX ?= /usr/local
TAR = tar cf -
ZSTD = zstdmt --ultra -22 -o
ZIP = 7z u -tzip
UPX = -qqq
CKSUM = sha256sum
CC = gcc
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
BINDIR = $(PREFIX)/bin
RELEASEDIR = releases
SIGNATURE_FILE = signature
SIGNATURES = $(RELEASEDIR)/$(SIGNATURE_FILE)
CMDS = actor relay node robot pong document keyset
ANDROID = android-arm64
DARWIN = darwin-amd64 darwin-arm64
FREEBSD = freebsd-amd64 freebsd-arm64
LINUX = linux-amd64 linux-mips64 linux-mips64le linux-ppc64 linux-ppc64le linux-s390x linux-arm64
NETBSD = netbsd-amd64 netbsd-arm64
OPENBSD = openbsd-amd64 openbsd-arm64
WINDOWS = windows-386 windows-amd64 windows-arm64
POSIX = $(ANDROID) $(DARWIN) $(FREEBSD) $(LINUX) $(NETBSD) $(OPENBSD)
ARM64 = android-arm64 darwin-arm64 netbsd-arm64 openbsd-arm64
AMD64 = darwin-amd64 freebsd-amd64 linux-amd64 netbsd-amd64 openbsd-amd64 windows-amd64
PLATFORMS = $(ANDROID) $(DARWIN) $(FREEBSD) $(LINUX) $(NETBSD) $(OPENBSD) $(WINDOWS)
ifneq (,$(wildcard ./.env))
include .env
export
endif
ifeq ($(GOOS), windows)
EXTENSION = .exe
endif
default: clean tidy $(NAME)
all: $(addprefix build-,$(PLATFORMS))
local: clean tidy install
$(BINDIR):
test -d $(BINDIR) || mkdir -p $(BINDIR)
install: build-$(GOOS)-$(GOARCH) $(BINDIR)
@$(foreach cmd,$(CMDS), \
echo Installing $(cmd) for $(GOOS)-$(GOARCH); \
sudo install -m755 $(GOOS)-$(GOARCH)/$(cmd)$(EXTENSION) $(DESTDIR)$(BINDIR)/; \
)
debug: BUILDFLAGS += -tags=debug
debug: install
tidy: go.mod
$(GO) mod tidy
clean:
rm -rf $(PLATFORMS) $(RELEASEDIR)/* $(CMDS) *.tar *.zip *.log
distclean: clean
rm -rf $(RELEASEDIR) $(shell git ls-files --others)
release: VERSION := $(shell ./.version)
release: clean $(RELEASEDIR) \
$(addsuffix .tar,$(RELEASEDIR)/$(POSIX)) \
$(addsuffix .zip,$(RELEASEDIR)/$(WINDOWS))
#git tag -a $(VERSION) -m "Release $(VERSION)"
$(SIGNATURES): $(RELEASEDIR)
cd $(RELEASEDIR) && \
$(CKSUM) *.zip *.tar > $(SIGNATURE_FILE)
$(RELEASEDIR):
mkdir -p $(RELEASEDIR)
# Dynamic build commands
build-%: GOOS = $(firstword $(subst -, ,$*))
build-%: GOARCH = $(word 2, $(subst -, ,$*))
build-%: BUILD = $(GOOS)-$(GOARCH)
build-%: $(addprefix $(BUILD),$(CMDS))
$(eval TARGET_GOOS := $(word 1, $(subst -, ,$*)))
$(eval TARGET_GOARCH := $(word 2, $(subst -, ,$*)))
# Conditionally set EXTENSION for Windows targets
$(if $(findstring windows,$(TARGET_GOOS)), $(eval EXTENSION := .exe))
@echo "Building for $(TARGET_GOOS)-$(TARGET_GOARCH)..."
$(foreach cmd,$(CMDS), \
echo "Building $(cmd) for $(TARGET_GOOS)-$(TARGET_GOARCH)"; \
mkdir -p $(TARGET_GOOS)-$(TARGET_GOARCH); \
GOOS=$(TARGET_GOOS) GOARCH=$(TARGET_GOARCH) $(GO) build \
-o $(TARGET_GOOS)-$(TARGET_GOARCH)/$(cmd)$(EXTENSION) \
$(BUILDFLAGS) ./cmd/$(cmd) || exit 1; \
)
# Dynamic release packaging
$(RELEASEDIR)/%: GOOS = $(firstword $(subst -, ,$*))
$(RELEASEDIR)/%: GOARCH = $(firstword $(subst ., ,$(word 2, $(subst -, ,$*))))
$(RELEASEDIR)/%: BUILD = $(GOOS)-$(GOARCH)
$(RELEASEDIR)/%: $(RELEASEDIR) $(BUILD)/$(CMDS)
@echo "Packaging $(BUILD) build..."
@if [ "$(GOOS)" = "windows" ]; then \
$(ZIP) $(RELEASEDIR)/$(NAME)-$(BUILD).zip $(BUILD)/*$(EXTENSION); \
else \
$(TAR) $(BUILD) | $(ZSTD) $(RELEASEDIR)/$(BUILD).tar; \
fi
android-arm64: export CC=aarch64-linux-android-gcc
android-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
darwin-amd64: export CC=x86_64-apple-darwin20-clang
darwin-amd64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
darwin-arm64: export CC=aarch64-apple-darwin20-clang
darwin-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
freebsd-amd64: export CC=x86_64-unknown-freebsd13-clang
freebsd-amd64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
freebsd-arm64: export CC=aarch64-unknown-freebsd13-clang
freebsd-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
linux-amd64: export CC=x86_64-linux-musl-gcc
linux-amd64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
linux-mips64: export CC=mips64-linux-musl-gcc
linux-mips64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/[email protected]
linux-mips64le: export CC=mips64el-linux-musl-gcc
linux-mips64le:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
linux-ppc64: export CC=powerpc64-linux-musl-gcc
linux-ppc64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
linux-ppc64le: export CC=powerpc64le-linux-musl-gcc
linux-ppc64le:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
linux-s390x: export CC=s390x-linux-musl-gcc
linux-s390x:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
linux-arm64: export CC=aarch64-linux-musl-gcc
linux-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
netbsd-amd64: export CC=x86_64-unknown-netbsd9-clang
netbsd-amd64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
netbsd-arm64: export CC=aarch64-unknown-netbsd9-clang
netbsd-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
openbsd-amd64: export CC=x86_64-unknown-openbsd7-clang
openbsd-amd64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
openbsd-arm64: export CC=aarch64-unknown-openbsd7-clang
openbsd-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
windows-386: export CC=i686-w64-mingw32-gcc
windows-386:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
windows-amd64: export CC=x86_64-w64-mingw32-gcc
windows-amd64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
windows-arm64: export CC=aarch64-w64-mingw32-gcc
windows-arm64:
$(MAKE) build-$@
$(MAKE) $(RELEASEDIR)/$@
android: $(ANDROID)
darwin: $(DARWIN)
freebsd: $(FREEBSD)
linux: $(LINUX)
netbsd: $(NETBSD)
openbsd: $(OPENBSD)
windows: $(WINDOWS)
arm64: $(ARM64)
amd64: $(AMD64)
lint:
find -name "*.yaml" -exec yamllint -c .yamllintrc {} \;
.PHONY: default all local install debug tidy clean distclean release lint \
android darwin freebsd linux netbsd openbsd windows \
arm64 amd64