-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (167 loc) · 8.41 KB
/
Copy pathMakefile
File metadata and controls
197 lines (167 loc) · 8.41 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
include versions.env
export ROOT_DIR = $(shell git rev-parse --show-toplevel)
export GITCOMMIT = $(shell git rev-parse --short HEAD 2>/dev/null || true)
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
RAW_ARCH := $(shell uname -m)
ARCH := $(if $(filter x86_64,$(RAW_ARCH)),amd64,$(if $(filter aarch64,$(RAW_ARCH)),arm64,$(if $(filter armv7l,$(RAW_ARCH)),armhf,$(RAW_ARCH))))
HAMLIB_PREFIX := $(ROOT_DIR)/out/hamlib/$(HAMLIB_VERSION)/$(OS)-$(ARCH)
# Use the local Hamlib prefix if it exists; otherwise fall through to system paths.
ifneq ($(wildcard $(HAMLIB_PREFIX)/lib/pkgconfig),)
export PKG_CONFIG_PATH = $(HAMLIB_PREFIX)/lib/pkgconfig
export PATH := $(HAMLIB_PREFIX)/bin:$(PATH)
endif
VERSION := $(KEL_AGENT_VERSION)
MACOS_APP_SIGN_IDENTITY ?= $(shell security find-identity -v -p codesigning 2>/dev/null | sed -n 's/.*"\(Developer ID Application:.*\)"/\1/p' | head -n1)
MACOS_INSTALL_SIGN_IDENTITY ?= $(shell security find-identity -v -p basic 2>/dev/null | sed -n 's/.*"\(Developer ID Installer:.*\)"/\1/p' | head -n1)
GENERATED = kel-agent kel-agent.exe kel-agent.pkg kel-agent-signed.pkg kel-agent_*.pkg win/kel-agent_*.msi win/kel-agent.wixobj \
autorevision.cache ../kel-agent_* ../*.deb \
flatpak/repo/ flatpak/.flatpak-builder/ flatpak/kel_agent.flatpak flatpak/flatpak_app/ flatpak/build-out/
# ---------------------------------------------------------------------------
# 1. Developer build
# ---------------------------------------------------------------------------
.PHONY: all
all: kel-agent
.PHONY: test
test:
go test -tags hamlib ./...
go vet -tags hamlib ./...
if command -v appstream-util >/dev/null; then appstream-util validate --nonet assets/radio.k0swe.Kel_Agent.metainfo.xml; fi
if command -v desktop-file-validate >/dev/null; then desktop-file-validate assets/radio.k0swe.Kel_Agent.desktop; fi
.PHONY: test-nohamlib
test-nohamlib:
go test ./...
go vet ./...
kel-agent: test
export GITCOMMIT=$(GITCOMMIT) VERSION=v$(VERSION) && scripts/build.sh
# ---------------------------------------------------------------------------
# 2. Release build
# ---------------------------------------------------------------------------
.PHONY: hamlib
hamlib:
scripts/build-hamlib.sh
.PHONY: release
release: hamlib test
export GITCOMMIT=$(GITCOMMIT) VERSION=v$(VERSION) && scripts/build.sh
# ---------------------------------------------------------------------------
# 3. Packaging
# ---------------------------------------------------------------------------
assets/modules.txt:
go mod vendor
mv vendor/modules.txt assets/
rm -rf vendor
autorevision.cache:
autorevision -s VCS_SHORT_HASH -o ./autorevision.cache
.PHONY: deb-tarball
deb-tarball: autorevision.cache
cd .. && tar -cvJf kel-agent_$(VERSION).orig.tar.xz --exclude-vcs kel-agent
.PHONY: deb-orig-tarball
deb-orig-tarball: autorevision.cache
cd .. && tar -cvJf kel-agent_$(VERSION).orig.tar.xz --exclude-vcs --exclude=debian --exclude=.github --exclude=.idea kel-agent
# TODO: This target can be removed once the package is in Debian stable and Ubuntu stable
../golang-github-k0swe-wsjtx-go-dev_4.0.6-1_all.deb:
wget https://github.com/k0swe/wsjtx-go/releases/download/v4.0.1/golang-github-k0swe-wsjtx-go-dev_4.0.6-1_all.deb \
-O ../golang-github-k0swe-wsjtx-go-dev_4.0.6-1_all.deb
# TODO: This target can be removed once the package is in Debian stable and Ubuntu stable
../golang-github-mazznoer-csscolorparser-dev_0.1.3-1_all.deb:
wget https://github.com/k0swe/wsjtx-go/releases/download/v4.0.1/golang-github-mazznoer-csscolorparser-dev_0.1.3-1_all.deb \
-O ../golang-github-mazznoer-csscolorparser-dev_0.1.3-1_all.deb
# TODO: This target can be removed once the package is in Debian stable and Ubuntu stable
../golang-github-adrg-xdg-dev_0.4.0-1_all.deb:
wget http://ftp.us.debian.org/debian/pool/main/g/golang-github-adrg-xdg/golang-github-adrg-xdg-dev_0.4.0-1_all.deb \
-O ../golang-github-adrg-xdg-dev_0.4.0-1_all.deb
.PHONY: deb-package
deb-package: deb-tarball ../golang-github-k0swe-wsjtx-go-dev_4.0.6-1_all.deb ../golang-github-adrg-xdg-dev_0.4.0-1_all.deb ../golang-github-mazznoer-csscolorparser-dev_0.1.3-1_all.deb
# https://wiki.debian.org/sbuild
sbuild -d stable \
--extra-package=../golang-github-k0swe-wsjtx-go-dev_4.0.6-1_all.deb \
--extra-package=../golang-github-adrg-xdg-dev_0.4.0-1_all.deb \
--extra-package=../golang-github-mazznoer-csscolorparser-dev_0.1.3-1_all.deb
.PHONY: deb-package-ci
deb-package-ci: deb-tarball
@test "$$(id -u)" -eq 0 || (echo "deb-package-ci requires root access (designed for CI container environments)" && exit 1)
go mod vendor
dpkg-buildpackage -b -us -uc -d
.PHONY: flatpak
flatpak: kel-agent
cd flatpak && \
flatpak-builder --force-clean build-out radio.k0swe.Kel_Agent.yml --repo=repo && \
flatpak build-bundle repo kel_agent.flatpak radio.k0swe.Kel_Agent main
.PHONY: stage-hamlib
stage-hamlib: hamlib
@echo "==> Staging Hamlib runtime files for packaging"
mkdir -p out/hamlib/lib out/hamlib/bin
cp -a $(HAMLIB_PREFIX)/lib/libhamlib* out/hamlib/lib/ 2>/dev/null || true
cp -a $(HAMLIB_PREFIX)/bin/* out/hamlib/bin/ 2>/dev/null || true
.PHONY: mac-package
mac-package: release stage-hamlib
# Build macOS installer using native pkgbuild/productbuild (no third-party tools required)
rm -rf out/macos-pkg
mkdir -p out/macos-pkg/root/usr/local/bin
mkdir -p out/macos-pkg/root/usr/local/lib
mkdir -p out/macos-pkg/root/usr/local/share/man/man1
cp kel-agent out/macos-pkg/root/usr/local/bin/
cp out/hamlib/lib/libhamlib.4.dylib out/macos-pkg/root/usr/local/lib/
hamlib_ref=$$(otool -L out/macos-pkg/root/usr/local/bin/kel-agent | awk '/libhamlib\.4\.dylib/{print $$1; exit}'); \
if [ -z "$$hamlib_ref" ]; then \
echo "ERROR: no libhamlib.4.dylib dependency found in packaged kel-agent"; \
otool -L out/macos-pkg/root/usr/local/bin/kel-agent; \
exit 1; \
fi; \
if [ "$$hamlib_ref" != "/usr/local/lib/libhamlib.4.dylib" ]; then \
install_name_tool -change "$$hamlib_ref" /usr/local/lib/libhamlib.4.dylib out/macos-pkg/root/usr/local/bin/kel-agent; \
fi
install_name_tool -id /usr/local/lib/libhamlib.4.dylib out/macos-pkg/root/usr/local/lib/libhamlib.4.dylib
@if ! otool -L out/macos-pkg/root/usr/local/bin/kel-agent | grep -q '/usr/local/lib/libhamlib.4.dylib'; then \
echo "ERROR: packaged kel-agent is not linked to /usr/local/lib/libhamlib.4.dylib"; \
otool -L out/macos-pkg/root/usr/local/bin/kel-agent; \
exit 1; \
fi
# Sign the bundled dylib and binary with Developer ID Application so Apple's
# notarization service accepts all payloads inside the installer pkg.
# Sign the dylib first (dependency before dependent).
@test -n "$(MACOS_APP_SIGN_IDENTITY)" || (echo "ERROR: MACOS_APP_SIGN_IDENTITY is empty. Import a Developer ID Application cert or set MACOS_APP_SIGN_IDENTITY." && exit 1)
@test -n "$(MACOS_INSTALL_SIGN_IDENTITY)" || (echo "ERROR: MACOS_INSTALL_SIGN_IDENTITY is empty. Import a Developer ID Installer cert or set MACOS_INSTALL_SIGN_IDENTITY." && exit 1)
codesign --force --options runtime \
--sign "$(MACOS_APP_SIGN_IDENTITY)" \
out/macos-pkg/root/usr/local/lib/libhamlib.4.dylib
codesign --force --options runtime \
--sign "$(MACOS_APP_SIGN_IDENTITY)" \
out/macos-pkg/root/usr/local/bin/kel-agent
cp assets/kel-agent.1 out/macos-pkg/root/usr/local/share/man/man1/
pkgbuild \
--root out/macos-pkg/root \
--identifier radio.k0swe.kel-agent \
--version $(VERSION) \
--install-location / \
out/macos-pkg/kel-agent-component.pkg
productbuild \
--distribution macos/distribution.xml \
--package-path out/macos-pkg \
--resources macos \
kel-agent.pkg
productsign --sign "$(MACOS_INSTALL_SIGN_IDENTITY)" \
kel-agent.pkg kel-agent-signed.pkg
mv kel-agent-signed.pkg kel-agent_mac.pkg
.PHONY: win-package
win-package: release stage-hamlib
# https://wixtoolset.org/docs/tools/wixexe/
cd win && wix build kel-agent.wxs -arch x64 -o kel-agent.msi
# ---------------------------------------------------------------------------
# Verification helpers
# ---------------------------------------------------------------------------
.PHONY: verify-deps
verify-deps: kel-agent
ifeq ($(OS),linux)
@echo "==> Linux shared library dependencies:"
ldd kel-agent
endif
ifeq ($(OS),darwin)
@echo "==> macOS shared library dependencies:"
otool -L kel-agent
endif
# ---------------------------------------------------------------------------
# Housekeeping
# ---------------------------------------------------------------------------
.PHONY: clean
clean:
rm -rf $(GENERATED) out/