-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
255 lines (221 loc) · 11.4 KB
/
Copy pathMakefile
File metadata and controls
255 lines (221 loc) · 11.4 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Makefile for satpulse: requires GNU make
# Where the config file will be installed by the install target.
CONFIG_FILE=/usr/local/etc/satpulse.toml
CMD=github.com/jclark/satpulse/gps/app/cmd
VERSION:=$(shell cat VERSION)
VERSION_TAG:=v$(VERSION)
BUILD_DATE:=$(shell date -u --rfc-3339=seconds)
# Refresh the index so unchanged-but-touched files don't show as dirty.
DIRTY:=$(shell git update-index -q --refresh >/dev/null 2>&1; git diff-index --quiet HEAD 2>/dev/null || echo .dirty)
GIT_VERSION:=$(shell env TZ=UTC git log -1 --format="%cd.%h" --date=format-local:%Y%m%d)$(DIRTY)
DEB_VERSION=1
RPM_RELEASE=1
CMD_VERSION:=$(VERSION)
DEB_PKG_VERSION:=$(VERSION)-$(DEB_VERSION)
RPM_VERSION:=$(VERSION)
GH_RELEASE:=$(VERSION)
CURRENT_TAG:=$(shell git describe --tags --exact-match 2>/dev/null)
ifneq ($(CURRENT_TAG)$(DIRTY),$(VERSION_TAG))
# It's a prerelease
CMD_VERSION:=$(VERSION)-pre.$(GIT_VERSION)
DEB_PKG_VERSION:=$(VERSION)~git$(GIT_VERSION)-$(DEB_VERSION)
RPM_VERSION:=$(VERSION)~$(shell env TZ=UTC git log -1 --format="%cdgit%h" --date=format-local:%Y%m%d)
GH_RELEASE:=$(VERSION)-pre-$(shell env TZ=UTC git log -1 --format="%cd" --date=format-local:%Y%m%d)
endif
RPM_PKG_VERSION=$(RPM_VERSION)-$(RPM_RELEASE)
XFLAGS:=-X \"$(CMD).version=$(CMD_VERSION)\" -X \"$(CMD).buildDate=$(BUILD_DATE)\"
TAGS=netgo,osusergo
# ARM architecture version for 32-bit arm builds; ignored when GOARCH is not arm.
GOARM=6
# The GOARCHs we support.
ALL_GOARCH=arm64 amd64 arm
TOMLS:=$(patsubst %,out/%/satpulse.toml,$(ALL_GOARCH))
ARCH:=$(shell uname -m)
MAN_PAGES=satpulsetool.1 satpulsetool-gps.1 satpulsetool-serial.1 satpulsetool-pack.1 satpulsetool-scan.1 satpulsetool-sdp.1 satpulsetool-syncsim.1 satpulsetool-convobs.1 satpulsewb.1 satpulse.toml.5 satpulsed.8
MAN_TARGETS = $(addprefix out/, $(MAN_PAGES))
MAN_GZ_TARGETS = $(addsuffix .gz, $(MAN_TARGETS))
MAN_TXT_TARGETS = $(addsuffix .txt, $(MAN_TARGETS))
# Set goarch based on detected architecture
ifeq ($(ARCH),x86_64)
GOARCH:=amd64
else ifeq ($(ARCH),aarch64)
GOARCH:=arm64
else
$(error Unsupported architecture $(ARCH))
endif
all: $(GOARCH) out/$(GOARCH)/satpulse.toml
allarch: $(ALL_GOARCH) $(TOMLS)
$(ALL_GOARCH):
env GOOS=linux GOARCH=$@ GOARM=$(GOARM) go build -tags "$(TAGS)" -o out/$@/ -ldflags "$(XFLAGS)" ./...
windows_amd64:
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags "$(TAGS)" -o out/$@/ -ldflags "$(XFLAGS)" ./cmd/satpulsed ./cmd/satpulsetool ./cmd/satpulsewb
out/arm64/satpulse.toml out/arm/satpulse.toml: configs/satpulse.toml
sed -e '/^#:schema /s; \./; /usr/share/doc/satpulse/;' -e '/interface/s/"enp1s0"/"eth0"/' -e '/device/s;"/dev/ttyUSB0";"/dev/ttyAMA0";' $< > $@
out/amd64/satpulse.toml: configs/satpulse.toml
sed -e '/^#:schema /s; \./; /usr/share/doc/satpulse/;' $< > $@
man: $(MAN_TARGETS)
man.gz: $(MAN_GZ_TARGETS)
gpsmsg:
mkdir -p out
cd configs/gpsmsg && git ls-files . > ../../out/gpsmsg.files
out/%: docs/man/%.md
pandoc -s --metadata=title="$(basename $*)" --metadata=section="$(subst .,,$(suffix $*))" --metadata=author="James Clark" -t man -o $@ $<
out/%.txt: docs/man/%.md
pandoc -t plain $< | sed 's/$$/\r/' > $@
out/%.gz: out/%
gzip -c $< > $@
install: out/$(GOARCH)/satpulsed out/$(GOARCH)/satpulsetool out/$(GOARCH)/satpulsewb out/$(GOARCH)/satpulse.toml $(MAN_TARGETS) gpsmsg
install out/$(GOARCH)/satpulsed /usr/local/sbin/satpulsed
install out/$(GOARCH)/satpulsetool /usr/local/bin/satpulsetool
install out/$(GOARCH)/satpulsewb /usr/local/bin/satpulsewb
sed -e 's;/etc/satpulse.toml;$(CONFIG_FILE);g' \
-e 's;/etc/satpulse.d/;/usr/local/etc/satpulse.d/;g' \
-e 's;/usr/sbin/satpulsed;/usr/local/sbin/satpulsed;g' \
configs/satpulse@.service >/etc/systemd/system/satpulse@.service
[ -f "$(CONFIG_FILE)" ] || sed -e '/^#:schema /s;/usr/;/usr/local/;' out/$(GOARCH)/satpulse.toml >"$(CONFIG_FILE)"
install -m 644 -D configs/config-schema.json /usr/local/share/doc/satpulse/config-schema.json
for f in `cat out/gpsmsg.files`; do \
install -D -m 644 configs/gpsmsg/$$f /usr/local/share/satpulse/gpsmsg/$$f; \
done
install -D -m 644 out/satpulsetool.1 /usr/local/share/man/man1/satpulsetool.1
sed 's;/usr/share/satpulse/gpsmsg;/usr/local/share/satpulse/gpsmsg;g' out/satpulsetool-gps.1 > /usr/local/share/man/man1/satpulsetool-gps.1
install -D -m 644 out/satpulsetool-serial.1 /usr/local/share/man/man1/satpulsetool-serial.1
install -D -m 644 out/satpulsetool-pack.1 /usr/local/share/man/man1/satpulsetool-pack.1
install -D -m 644 out/satpulsetool-scan.1 /usr/local/share/man/man1/satpulsetool-scan.1
install -D -m 644 out/satpulsetool-sdp.1 /usr/local/share/man/man1/satpulsetool-sdp.1
install -D -m 644 out/satpulsetool-syncsim.1 /usr/local/share/man/man1/satpulsetool-syncsim.1
install -D -m 644 out/satpulsetool-convobs.1 /usr/local/share/man/man1/satpulsetool-convobs.1
install -D -m 644 out/satpulsewb.1 /usr/local/share/man/man1/satpulsewb.1
install -D -m 644 out/satpulse.toml.5 /usr/local/share/man/man5/satpulse.toml.5
install -d /usr/local/share/man/man8
sed 's;/etc/satpulse.toml;$(CONFIG_FILE);g' out/satpulsed.8 > /usr/local/share/man/man8/satpulsed.8
systemctl daemon-reload
uninstall:
systemctl stop 'satpulse@*.service'
rm -f /etc/systemd/system/satpulse@.service
rm -f /usr/local/sbin/satpulsed
rm -f /usr/local/bin/satpulsetool
rm -f /usr/local/bin/satpulsewb
# we don't uninstall /usr/local/etc/satpulse.toml
rm -f /usr/local/share/doc/satpulse/config-schema.json
rm -rf /usr/local/share/satpulse/gpsmsg
rm -f /usr/local/share/man/man1/satpulsetool.1
rm -f /usr/local/share/man/man1/satpulsetool-gps.1
rm -f /usr/local/share/man/man1/satpulsetool-serial.1
rm -f /usr/local/share/man/man1/satpulsetool-pack.1
rm -f /usr/local/share/man/man1/satpulsetool-scan.1
rm -f /usr/local/share/man/man1/satpulsetool-sdp.1
rm -f /usr/local/share/man/man1/satpulsetool-syncsim.1
rm -f /usr/local/share/man/man1/satpulsetool-convobs.1
rm -f /usr/local/share/man/man1/satpulsewb.1
rm -f /usr/local/share/man/man5/satpulse.toml.5
rm -f /usr/local/share/man/man8/satpulsed.8
systemctl daemon-reload
test:
go test ./...
smoketest: out/$(GOARCH)/satpulsed out/$(GOARCH)/satpulsetool out/$(GOARCH)/satpulsewb
python3 smoketest/run.py
clean:
-rm -rf out
pkg: deb rpm winzip
WIN_ZIP=out/satpulse_$(GH_RELEASE)_windows_amd64.zip
winzip: $(WIN_ZIP)
$(WIN_ZIP): windows_amd64 $(MAN_TXT_TARGETS) gpsmsg
rm -fr out/windows_amd64/zip
install -D out/windows_amd64/satpulsed.exe out/windows_amd64/zip/satpulsed.exe
install -D out/windows_amd64/satpulsetool.exe out/windows_amd64/zip/satpulsetool.exe
install -D out/windows_amd64/satpulsewb.exe out/windows_amd64/zip/satpulsewb.exe
install -D -m 644 configs/satpulse.toml out/windows_amd64/zip/satpulse.toml
for f in `sed -n '/\.toml$$/p' out/gpsmsg.files`; do \
install -D -m 644 configs/gpsmsg/$$f out/windows_amd64/zip/gpsmsg/$$f; \
done
for f in $(MAN_TXT_TARGETS); do \
install -D -m 644 $$f out/windows_amd64/zip/docs/`basename $$f`; \
done
rm -f $@
cd out/windows_amd64/zip && zip -r ../../$(notdir $@) .
DEB_PATTERN=out/satpulse_$(DEB_PKG_VERSION)_%.deb
GH_DEB_PATTERN=out/satpulse_$(GH_RELEASE)_%.deb
ALL_DEB_ARCH=arm64 amd64 armhf
DEBS:=$(patsubst %,$(DEB_PATTERN), $(ALL_DEB_ARCH))
GH_DEBS:=$(patsubst %,$(GH_DEB_PATTERN), $(ALL_DEB_ARCH))
deb: $(GH_DEBS)
$(GH_DEBS): $(DEBS)
$(GH_DEB_PATTERN): $(DEB_PATTERN)
ln -sf $(notdir $<) $@
# Debian's armhf is GOARCH=arm; map the package arch (the deb stem) to its build dir.
DEB_GOARCH=$(subst armhf,arm,$*)
$(DEB_PATTERN): $(ALL_GOARCH) $(TOMLS) $(MAN_GZ_TARGETS) gpsmsg
rm -fr out/$*/deb
install -D -m 644 debian/conffiles out/$*/deb/DEBIAN/conffiles
install -D debian/postinst out/$*/deb/DEBIAN/postinst
install -D out/$(DEB_GOARCH)/satpulsed out/$*/deb/usr/sbin/satpulsed
install -D out/$(DEB_GOARCH)/satpulsetool out/$*/deb/usr/bin/satpulsetool
install -D out/$(DEB_GOARCH)/satpulsewb out/$*/deb/usr/bin/satpulsewb
install -D -m 644 out/$(DEB_GOARCH)/satpulse.toml out/$*/deb/etc/satpulse.toml
install -D -m 644 configs/ptp4l.service out/$*/deb/usr/share/doc/satpulse/ptp4l.service
install -D -m 644 configs/chrony.conf out/$*/deb/usr/share/doc/satpulse/chrony.conf
install -D -m 644 configs/config-schema.json out/$*/deb/usr/share/doc/satpulse/config-schema.json
for f in `cat out/gpsmsg.files`; do \
install -D -m 644 configs/gpsmsg/$$f out/$*/deb/usr/share/satpulse/gpsmsg/$$f; \
done
install -D -m 644 LICENSE out/$*/deb/usr/share/doc/satpulse/copyright
install -D -m 644 configs/satpulse@.service out/$*/deb/lib/systemd/system/satpulse@.service
install -D -m 644 out/satpulsetool.1.gz out/$*/deb/usr/share/man/man1/satpulsetool.1.gz
install -D -m 644 out/satpulsetool-gps.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-gps.1.gz
install -D -m 644 out/satpulsetool-serial.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-serial.1.gz
install -D -m 644 out/satpulsetool-pack.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-pack.1.gz
install -D -m 644 out/satpulsetool-scan.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-scan.1.gz
install -D -m 644 out/satpulsetool-sdp.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-sdp.1.gz
install -D -m 644 out/satpulsetool-syncsim.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-syncsim.1.gz
install -D -m 644 out/satpulsetool-convobs.1.gz out/$*/deb/usr/share/man/man1/satpulsetool-convobs.1.gz
install -D -m 644 out/satpulsewb.1.gz out/$*/deb/usr/share/man/man1/satpulsewb.1.gz
install -D -m 644 out/satpulse.toml.5.gz out/$*/deb/usr/share/man/man5/satpulse.toml.5.gz
install -D -m 644 out/satpulsed.8.gz out/$*/deb/usr/share/man/man8/satpulsed.8.gz
installed_size=`du -s -k out/$*/deb | cut -f1`;\
sed -e '/^Architecture:/s/any/$*/' -e '/^Package:/a\
Version: $(DEB_PKG_VERSION)' -e '/^Maintainer:/a\
Installed-Size: '"$$installed_size" debian/control >out/$*/deb/DEBIAN/control
dpkg-deb --root-owner-group --build out/$*/deb out
RPM_PATTERN=out/satpulse-$(RPM_PKG_VERSION).%.rpm
GH_RPM_PATTERN=out/satpulse-$(GH_RELEASE).%.rpm
ALL_RPM_ARCH=aarch64 x86_64
RPMS:=$(patsubst %,$(RPM_PATTERN),$(ALL_RPM_ARCH))
GH_RPMS:=$(patsubst %,$(GH_RPM_PATTERN),$(ALL_RPM_ARCH))
rpm: $(GH_RPMS)
$(GH_RPMS): $(RPMS)
# The challenge here is that rpmbuild wants to put the generated RPMs in a subdirectory named by the architecture.
# But if we follow that we will get endless pain from having patterns with two %s in them.
# So we symlink each architecture to the current directory to avoid having the subdirectories.
$(RPM_PATTERN): $(ALL_GOARCH) $(TOMLS) $(MAN_GZ_TARGETS) gpsmsg
goarch=$(subst x86_64,amd64,$(subst aarch64,arm64,$*)); \
test -L out/$* || ln -s . out/$*; \
echo ls -l out/$*; \
cwd=`pwd`; \
rpmbuild -bb --target $* --define "goarch $$goarch" \
--build-in-place \
--buildroot "$$cwd/out/$$goarch/rpm" \
--define "debug_package %{nil}" \
--define "version $(RPM_VERSION)" \
--define "_rpmdir $$cwd/out" \
satpulse.spec
$(GH_RPM_PATTERN): $(RPM_PATTERN)
ln -sf $(notdir $<) $@
release: $(GH_DEBS) $(GH_RPMS) $(WIN_ZIP)
@if ! gh auth status >/dev/null 2>&1; then \
echo "GitHub CLI is not authenticated. Run 'gh auth login --insecure-storage' on the host and try again."; \
exit 1; \
fi
gh release create "v$(GH_RELEASE)" \
--repo "jclark/satpulse" \
--title "Release v$(GH_RELEASE)" \
--notes "Automatically generated draft release" \
--draft \
$^
tag:
git update-index -q --refresh
git diff-index --exit-code HEAD
git tag -f -a "$(VERSION_TAG)" -m "Release $(VERSION_TAG)"
untag:
git tag -d "$(VERSION_TAG)"
.PHONY: $(ALL_GOARCH) all windows_amd64 test smoketest install uninstall clean pkg deb rpm winzip release man man.gz gpsmsg tag untag