-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
265 lines (214 loc) · 12.9 KB
/
Makefile
File metadata and controls
265 lines (214 loc) · 12.9 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
256
257
258
259
260
261
262
263
264
265
APP_NAME = mlController
BUNDLE_ID = com.boinx.mlcontroller
# Xcode-integrated SPM builds to .build/apple/Products/Release/
BUILD_DIR = .build/apple/Products/Release
APP_BUNDLE = $(APP_NAME).app
CONTENTS = $(APP_BUNDLE)/Contents
MACOS_DIR = $(CONTENTS)/MacOS
RESOURCES_DIR = $(CONTENTS)/Resources
FRAMEWORKS_DIR = $(CONTENTS)/Frameworks
# SPM resource bundle name: <PackageName>_<TargetName>.bundle
RESOURCE_BUNDLE = $(APP_NAME)_$(APP_NAME).bundle
# ── Release Signing ──────────────────────────────────────────────────────────
SIGN_IDENTITY = Developer ID Application: Boinx Software International GmbH (6372P8EH2J)
NOTARY_PROFILE = mlController # stored via: xcrun notarytool store-credentials
VERSION := $(shell /usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" Info.plist 2>/dev/null || echo "1.0")
RELEASE_ZIP = $(APP_NAME)-$(VERSION).zip
# ── Sparkle Framework ────────────────────────────────────────────────────────
SPARKLE_XCFW = .build/artifacts/sparkle/Sparkle/Sparkle.xcframework
SPARKLE_FW = $(SPARKLE_XCFW)/macos-arm64_x86_64/Sparkle.framework
SPARKLE_BIN = .build/artifacts/sparkle/Sparkle/bin
.PHONY: build bundle install install-login-agent uninstall-login-agent clean run \
release sign notarize zip appcast setup-notarization setup-sparkle-keys help
help:
@echo "mlController Build System"
@echo ""
@echo " Development:"
@echo " make build — compile with Swift Package Manager"
@echo " make bundle — assemble .app bundle (ad-hoc signed)"
@echo " make install — copy .app to /Applications"
@echo " make run — build and open the app"
@echo ""
@echo " Distribution:"
@echo " make release — build, sign, notarize, create ZIP + appcast"
@echo " make sign — build bundle with Developer ID signing"
@echo " make notarize — submit signed .app for Apple notarization"
@echo " make zip — create distributable .zip"
@echo " make appcast — generate Sparkle appcast.xml from releases/"
@echo " make setup-notarization — store Apple ID credentials in keychain"
@echo " make setup-sparkle-keys — generate Sparkle EdDSA signing keys"
@echo ""
@echo " System:"
@echo " make install-login-agent — install LaunchAgent (runs at login)"
@echo " make uninstall-login-agent— remove LaunchAgent"
@echo " make clean — remove build artifacts"
# ── Step 1: Build ─────────────────────────────────────────────────────────────
build:
@echo "==> Building $(APP_NAME)..."
swift build -c release --arch arm64 --arch x86_64
# ── Step 2: Assemble .app Bundle ──────────────────────────────────────────────
bundle: build
@echo "==> Assembling $(APP_BUNDLE)..."
@rm -rf $(APP_BUNDLE)
@mkdir -p $(MACOS_DIR) $(RESOURCES_DIR) $(FRAMEWORKS_DIR)
@# Binary
cp $(BUILD_DIR)/$(APP_NAME) $(MACOS_DIR)/$(APP_NAME)
@# Add rpath so the binary can find Sparkle.framework at runtime
install_name_tool -add_rpath @executable_path/../Frameworks $(MACOS_DIR)/$(APP_NAME)
@# Info.plist — expand Xcode build variable references
sed -e 's/\$$(DEVELOPMENT_LANGUAGE)/en/g' \
-e 's/\$$(EXECUTABLE_NAME)/$(APP_NAME)/g' \
-e 's/\$$(PRODUCT_BUNDLE_IDENTIFIER)/$(BUNDLE_ID)/g' \
-e 's/\$$(PRODUCT_NAME)/$(APP_NAME)/g' \
Info.plist > $(CONTENTS)/Info.plist
@# App icon
cp Sources/mlController/Resources/AppIcon.icns $(RESOURCES_DIR)/AppIcon.icns
@# Web assets — copy directly to main Resources so Bundle.main can find them
cp -r Sources/mlController/Resources/web $(RESOURCES_DIR)/web
@# Sparkle.framework — copy preserving symlinks
cp -a $(SPARKLE_FW) $(FRAMEWORKS_DIR)/Sparkle.framework
@# Ad-hoc code sign — inside-out for Sparkle (no --deep)
codesign --force --sign - --options runtime \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/XPCServices/Installer.xpc
codesign --force --sign - --options runtime \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/XPCServices/Downloader.xpc
codesign --force --sign - --options runtime \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/Autoupdate
codesign --force --sign - --options runtime \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/Updater.app
codesign --force --sign - --options runtime \
$(FRAMEWORKS_DIR)/Sparkle.framework
codesign --force --sign - --options runtime \
--entitlements mlController.entitlements \
$(APP_BUNDLE)
@echo "==> Bundle created: $(APP_BUNDLE)"
# ── Step 3: Install to /Applications ─────────────────────────────────────────
install: bundle
@echo "==> Installing to /Applications/$(APP_BUNDLE)..."
@rm -rf /Applications/$(APP_BUNDLE)
cp -a $(APP_BUNDLE) /Applications/$(APP_BUNDLE)
@echo "==> Installed."
# ══════════════════════════════════════════════════════════════════════════════
# Distribution: sign → notarize → dmg → appcast
# ══════════════════════════════════════════════════════════════════════════════
# ── Full Release Pipeline ─────────────────────────────────────────────────────
release: sign notarize zip appcast
@echo ""
@echo "════════════════════════════════════════════════════"
@echo " ✅ $(RELEASE_ZIP) is ready for distribution!"
@echo " appcast.xml has been updated."
@echo " Remember to commit appcast.xml and push."
@echo "════════════════════════════════════════════════════"
# ── Developer ID Signing ─────────────────────────────────────────────────────
sign: build
@echo "==> Assembling $(APP_BUNDLE) (Developer ID signed)..."
@rm -rf $(APP_BUNDLE)
@mkdir -p $(MACOS_DIR) $(RESOURCES_DIR) $(FRAMEWORKS_DIR)
@# Binary
cp $(BUILD_DIR)/$(APP_NAME) $(MACOS_DIR)/$(APP_NAME)
@# Add rpath so the binary can find Sparkle.framework at runtime
install_name_tool -add_rpath @executable_path/../Frameworks $(MACOS_DIR)/$(APP_NAME)
@# Info.plist
sed -e 's/\$$(DEVELOPMENT_LANGUAGE)/en/g' \
-e 's/\$$(EXECUTABLE_NAME)/$(APP_NAME)/g' \
-e 's/\$$(PRODUCT_BUNDLE_IDENTIFIER)/$(BUNDLE_ID)/g' \
-e 's/\$$(PRODUCT_NAME)/$(APP_NAME)/g' \
Info.plist > $(CONTENTS)/Info.plist
@# App icon
cp Sources/mlController/Resources/AppIcon.icns $(RESOURCES_DIR)/AppIcon.icns
@# Web assets
cp -r Sources/mlController/Resources/web $(RESOURCES_DIR)/web
@# Sparkle.framework — copy preserving symlinks
cp -a $(SPARKLE_FW) $(FRAMEWORKS_DIR)/Sparkle.framework
@# Developer ID code sign — inside-out for Sparkle (no --deep)
codesign --force --sign "$(SIGN_IDENTITY)" --options runtime --timestamp \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/XPCServices/Installer.xpc
codesign --force --sign "$(SIGN_IDENTITY)" --options runtime --timestamp \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/XPCServices/Downloader.xpc
codesign --force --sign "$(SIGN_IDENTITY)" --options runtime --timestamp \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/Autoupdate
codesign --force --sign "$(SIGN_IDENTITY)" --options runtime --timestamp \
$(FRAMEWORKS_DIR)/Sparkle.framework/Versions/B/Updater.app
codesign --force --sign "$(SIGN_IDENTITY)" --options runtime --timestamp \
$(FRAMEWORKS_DIR)/Sparkle.framework
codesign --force --sign "$(SIGN_IDENTITY)" --options runtime --timestamp \
--entitlements mlController.entitlements \
$(APP_BUNDLE)
@echo "==> Verifying signature..."
codesign --verify --deep --strict --verbose=2 $(APP_BUNDLE)
@echo "==> Signed bundle created: $(APP_BUNDLE)"
# ── Notarization ─────────────────────────────────────────────────────────────
notarize:
@echo "==> Creating ZIP for notarization..."
@rm -f $(APP_NAME)-notarize.zip
ditto -c -k --keepParent $(APP_BUNDLE) $(APP_NAME)-notarize.zip
@echo "==> Submitting to Apple notarization service..."
xcrun notarytool submit $(APP_NAME)-notarize.zip \
--keychain-profile "$(NOTARY_PROFILE)" \
--wait
@echo "==> Stapling notarization ticket..."
xcrun stapler staple $(APP_BUNDLE)
@echo "==> Verifying notarization..."
spctl --assess --type exec --verbose=2 $(APP_BUNDLE)
@rm -f $(APP_NAME)-notarize.zip
@echo "==> Notarization complete."
# ── ZIP Creation ─────────────────────────────────────────────────────────────
zip:
@echo "==> Creating $(RELEASE_ZIP)..."
@rm -f $(RELEASE_ZIP)
ditto -c -k --sequesterRsrc --keepParent $(APP_BUNDLE) $(RELEASE_ZIP)
@echo "==> Created: $(RELEASE_ZIP)"
# ── Sparkle Appcast Generation ───────────────────────────────────────────────
appcast:
@echo "==> Generating appcast..."
@mkdir -p releases
cp $(RELEASE_ZIP) releases/
$(SPARKLE_BIN)/generate_appcast releases/ -o appcast.xml \
--download-url-prefix "https://github.com/boinx/mlController/releases/download/v$(VERSION)/"
@echo "==> Appcast updated: appcast.xml"
# ── Setup: Store Notarization Credentials ────────────────────────────────────
# Run once to store your Apple ID / app-specific password in the keychain.
# This will prompt interactively for:
# - Apple ID (email)
# - App-specific password (generate at appleid.apple.com)
# - Team ID: 6372P8EH2J
setup-notarization:
@echo "==> Storing notarization credentials in keychain..."
@echo " You will need:"
@echo " • Apple ID (email address)"
@echo " • App-specific password (https://appleid.apple.com → Sign-In and Security → App-Specific Passwords)"
@echo " • Team ID: 6372P8EH2J"
@echo ""
xcrun notarytool store-credentials "$(NOTARY_PROFILE)"
@echo "==> Credentials stored as keychain profile '$(NOTARY_PROFILE)'."
# ── Sparkle Key Generation (one-time) ────────────────────────────────────────
setup-sparkle-keys:
@echo "==> Generating Sparkle EdDSA signing keys..."
@echo " The private key will be stored in your macOS Keychain."
@echo " The public key will be printed below — add it to Info.plist as SUPublicEDKey."
@echo ""
$(SPARKLE_BIN)/generate_keys
# ── Login Item (LaunchAgent) ──────────────────────────────────────────────────
install-login-agent: install
@echo "==> Installing LaunchAgent..."
@mkdir -p ~/Library/LaunchAgents
@# Unload if already loaded (ignore errors)
@launchctl unload -w ~/Library/LaunchAgents/$(BUNDLE_ID).plist 2>/dev/null || true
cp LaunchAgents/$(BUNDLE_ID).plist ~/Library/LaunchAgents/$(BUNDLE_ID).plist
launchctl load -w ~/Library/LaunchAgents/$(BUNDLE_ID).plist
@echo "==> LaunchAgent installed. mlController will launch at login."
uninstall-login-agent:
@echo "==> Removing LaunchAgent..."
@launchctl unload -w ~/Library/LaunchAgents/$(BUNDLE_ID).plist 2>/dev/null || true
@rm -f ~/Library/LaunchAgents/$(BUNDLE_ID).plist
@echo "==> LaunchAgent removed."
# ── Clean ─────────────────────────────────────────────────────────────────────
clean:
@echo "==> Cleaning..."
@swift package clean
@rm -rf $(APP_BUNDLE) .build $(APP_NAME).zip $(APP_NAME)-*.zip $(APP_NAME)-*.dmg dmg_staging releases
@echo "==> Clean complete."
# ── Quick Run (debug build, open app) ─────────────────────────────────────────
run: bundle
@echo "==> Launching $(APP_BUNDLE)..."
open $(APP_BUNDLE)