-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
490 lines (443 loc) · 20.3 KB
/
Makefile
File metadata and controls
490 lines (443 loc) · 20.3 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# ModSwitchIME - macOS IME Switcher
# Makefile for building, testing, and distributing ModSwitchIME
#===============================================================================
# CONFIGURATION
#===============================================================================
# Project settings
PROJECT_NAME = ModSwitchIME
SCHEME = ModSwitchIME
XCODE_PROJECT = $(PROJECT_NAME).xcodeproj
DESTINATION = "platform=macOS"
# Build configurations
CONFIGURATION_DEBUG = Debug
CONFIGURATION_RELEASE = Release
# Build directories
BUILD_DIR = build
DEV_BUILD_DIR = $(BUILD_DIR)/dev
PROD_BUILD_DIR = $(BUILD_DIR)/release
ARCHIVE_PATH = $(PROD_BUILD_DIR)/$(PROJECT_NAME).xcarchive
EXPORT_PATH = $(PROD_BUILD_DIR)/export
DMG_PATH = $(PROD_BUILD_DIR)/$(PROJECT_NAME).dmg
# Environment variables (from .envrc)
DEVELOPMENT_TEAM ?= $(DEVELOPMENT_TEAM)
PRODUCT_BUNDLE_IDENTIFIER ?= $(PRODUCT_BUNDLE_IDENTIFIER)
TEST_BUNDLE_IDENTIFIER ?= $(TEST_BUNDLE_IDENTIFIER)
# Version management
VERSION_FILE = VERSION
VERSION = $(shell cat $(VERSION_FILE) 2>/dev/null || echo "1.0.0")
BUILD_NUMBER = $(shell date +%Y%m%d%H%M%S)
BUILD_NUMBER ?= $(shell git rev-list --count HEAD 2>/dev/null || echo "1")
APPLE_ID ?= $(APPLE_ID)
APPLE_PASSWORD ?= $(APPLE_PASSWORD)
# Colors for output
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
BLUE = \033[0;34m
NC = \033[0m # No Color
#===============================================================================
# PHONY TARGETS
#===============================================================================
# Development targets
.PHONY: all help build-dev test test-coverage test-specific test-only test-safe lint lint-nocache lint-fix clean-dev version status
# Production targets
.PHONY: build archive package dmg notarize notarize-status notarize-staple release clean-release
# Common targets
.PHONY: clean clean-all
#===============================================================================
# DEFAULT & HELP
#===============================================================================
.DEFAULT_GOAL := help
help: ## Show this help message
@echo "$(BLUE)ModSwitchIME Makefile$(NC)"
@echo ""
@echo "$(YELLOW)=== Development Commands ===$(NC)"
@echo " $(GREEN)make build-dev$(NC) Build and run development version"
@echo " $(GREEN)make test$(NC) Run all tests"
@echo " $(GREEN)make lint$(NC) Run SwiftLint"
@echo " $(GREEN)make clean-dev$(NC) Clean development build"
@echo ""
@echo "$(YELLOW)=== Production Commands ===$(NC)"
@echo " $(GREEN)make build$(NC) Build production version"
@echo " $(GREEN)make release$(NC) Full release build (clean, lint, test, archive, package, dmg)"
@echo " $(GREEN)make notarize$(NC) Notarize DMG for distribution"
@echo " $(GREEN)make clean-release$(NC) Clean release build"
@echo ""
@echo "$(YELLOW)All available targets:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
all: clean test build-dev ## Default: clean, test, and build development version
#===============================================================================
# DEVELOPMENT TARGETS
#===============================================================================
build-dev: ## Build and run development version (keeps permissions)
@echo "$(BLUE)Building $(PROJECT_NAME) for development...$(NC)"
@echo "$(YELLOW)Team ID: $(DEVELOPMENT_TEAM)$(NC)"
@mkdir -p $(DEV_BUILD_DIR)
xcodebuild -project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-configuration $(CONFIGURATION_DEBUG) \
-destination $(DESTINATION) \
-derivedDataPath $(DEV_BUILD_DIR)/DerivedData \
-xcconfig ModSwitchIME/Config/Version.xcconfig \
DEVELOPMENT_TEAM=$(DEVELOPMENT_TEAM) \
PRODUCT_BUNDLE_IDENTIFIER="$(PRODUCT_BUNDLE_IDENTIFIER)" \
CODE_SIGN_STYLE=Manual \
CODE_SIGN_IDENTITY="Developer ID Application: Yoshihiko Nishida (R7LKF73J2W)" \
PROVISIONING_PROFILE_SPECIFIER="" \
build
@echo "$(GREEN)Copying to dev directory...$(NC)"
@BUILD_PATH=$$(xcodebuild -project $(XCODE_PROJECT) -scheme $(SCHEME) -configuration $(CONFIGURATION_DEBUG) -derivedDataPath $(DEV_BUILD_DIR)/DerivedData -showBuildSettings DEVELOPMENT_TEAM=$(DEVELOPMENT_TEAM) | grep -E '^\s*BUILT_PRODUCTS_DIR' | awk '{print $$3}'); \
if [ -d "$$BUILD_PATH/$(PROJECT_NAME).app" ]; then \
cp -R "$$BUILD_PATH/$(PROJECT_NAME).app" $(DEV_BUILD_DIR)/; \
echo "$(GREEN)Development build available at: $(DEV_BUILD_DIR)/$(PROJECT_NAME).app$(NC)"; \
codesign -dv --verbose=2 "$(DEV_BUILD_DIR)/$(PROJECT_NAME).app"; \
echo "$(YELLOW)Checking for existing $(PROJECT_NAME) processes...$(NC)"; \
EXISTING_PIDS=$$(pgrep -x $(PROJECT_NAME) || true); \
if [ -n "$$EXISTING_PIDS" ]; then \
echo "$(YELLOW)Stopping existing processes: $$EXISTING_PIDS$(NC)"; \
pkill -x $(PROJECT_NAME) || true; \
sleep 2; \
fi; \
echo "$(BLUE)Starting development version...$(NC)"; \
open "$(DEV_BUILD_DIR)/$(PROJECT_NAME).app"; \
fi
#===============================================================================
# PRODUCTION BUILD TARGETS
#===============================================================================
build: ## Build production version
@echo "$(BLUE)Building $(PROJECT_NAME) for production...$(NC)"
@mkdir -p $(PROD_BUILD_DIR)
xcodebuild -project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-configuration $(CONFIGURATION_RELEASE) \
-destination $(DESTINATION) \
-derivedDataPath $(PROD_BUILD_DIR)/DerivedData \
-xcconfig ModSwitchIME/Config/Version.xcconfig \
DEVELOPMENT_TEAM=$(DEVELOPMENT_TEAM) \
PRODUCT_BUNDLE_IDENTIFIER="$(PRODUCT_BUNDLE_IDENTIFIER)" \
TEST_BUNDLE_IDENTIFIER="$(TEST_BUNDLE_IDENTIFIER)" \
CODE_SIGN_STYLE=Manual \
CODE_SIGN_IDENTITY="Developer ID Application: Yoshihiko Nishida (R7LKF73J2W)" \
OTHER_CODE_SIGN_FLAGS="--timestamp --options=runtime" \
CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO \
ARCHS="x86_64 arm64" \
ONLY_ACTIVE_ARCH=NO \
build
@echo "$(GREEN)Copying to prod directory...$(NC)"
@BUILD_PATH=$$(xcodebuild -project $(XCODE_PROJECT) -scheme $(SCHEME) -configuration $(CONFIGURATION_RELEASE) -derivedDataPath $(PROD_BUILD_DIR)/DerivedData -showBuildSettings DEVELOPMENT_TEAM=$(DEVELOPMENT_TEAM) | grep -E '^\s*BUILT_PRODUCTS_DIR' | awk '{print $$3}'); \
if [ -d "$$BUILD_PATH/$(PROJECT_NAME).app" ]; then \
cp -R "$$BUILD_PATH/$(PROJECT_NAME).app" $(PROD_BUILD_DIR)/; \
echo "$(GREEN)Production build available at: $(PROD_BUILD_DIR)/$(PROJECT_NAME).app$(NC)"; \
codesign -dv --verbose=2 "$(PROD_BUILD_DIR)/$(PROJECT_NAME).app"; \
fi
#===============================================================================
# TEST TARGETS
#===============================================================================
test: ## Run all tests
@echo "$(BLUE)Running tests...$(NC)"
@rm -rf $(BUILD_DIR)/DerivedData/Logs/Test/ModSwitchIME.xcresult || true
RUN_STRESS_TESTS=0 xcodebuild test \
-project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-destination $(DESTINATION) \
-derivedDataPath $(BUILD_DIR)/DerivedData \
-resultBundlePath $(BUILD_DIR)/DerivedData/Logs/Test/ModSwitchIME.xcresult \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
test-coverage: ## Run tests with coverage report
@echo "$(BLUE)Running tests with coverage...$(NC)"
@rm -rf $(BUILD_DIR)/DerivedData/Logs/Test/ModSwitchIME.xcresult || true
RUN_STRESS_TESTS=0 xcodebuild test \
-project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-destination $(DESTINATION) \
-enableCodeCoverage YES \
-derivedDataPath $(BUILD_DIR)/DerivedData \
-resultBundlePath $(BUILD_DIR)/DerivedData/Logs/Test/ModSwitchIME.xcresult \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
test-specific: ## Run specific test (use TEST=ClassName)
@if [ -z "$(TEST)" ]; then \
echo "$(RED)Error: Please specify a test class with TEST=ClassName$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Running test: $(TEST)...$(NC)"
@rm -rf $(BUILD_DIR)/DerivedData/Logs/Test/ModSwitchIME.xcresult || true
RUN_STRESS_TESTS=0 xcodebuild test \
-project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-destination $(DESTINATION) \
-derivedDataPath $(BUILD_DIR)/DerivedData \
-resultBundlePath $(BUILD_DIR)/DerivedData/Logs/Test/ModSwitchIME.xcresult \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
-only-testing:ModSwitchIMETests/$(TEST)
test-only: ## Run specific test class quickly (use ONLY=ClassName)
@if [ -z "$(ONLY)" ]; then \
echo "$(RED)Error: Please specify a test class with ONLY=ClassName$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Running quick test: $(ONLY)...$(NC)"
xcodebuild test \
-project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-destination $(DESTINATION) \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
-only-testing:ModSwitchIMETests/$(ONLY)
test-safe: ## Run sandbox-safe subset of tests
@echo "$(BLUE)Running sandbox-safe tests subset...$(NC)"
xcodebuild test \
-project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-destination $(DESTINATION) \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
-only-testing:ModSwitchIMETests/IconMappingTests \
-only-testing:ModSwitchIMETests/InputSourceHelpersTests \
-only-testing:ModSwitchIMETests/ModifierKeyMappingTests \
-only-testing:ModSwitchIMETests/MenuBarIconDebounceTests
#===============================================================================
# CODE QUALITY
#===============================================================================
lint: ## Run SwiftLint
@if command -v swiftlint >/dev/null 2>&1; then \
echo "$(BLUE)Running SwiftLint...$(NC)"; \
swiftlint --no-cache; \
else \
echo "$(YELLOW)SwiftLint not found. Install with: brew install swiftlint$(NC)"; \
fi
lint-nocache: ## Run SwiftLint without cache (CI/sandbox friendly)
@if command -v swiftlint >/dev/null 2>&1; then \
echo "$(BLUE)Running SwiftLint (no cache)...$(NC)"; \
swiftlint --no-cache; \
else \
echo "$(YELLOW)SwiftLint not found. Install with: brew install swiftlint$(NC)"; \
fi
lint-fix: ## Auto-fix SwiftLint issues
@if command -v swiftlint >/dev/null 2>&1; then \
echo "$(BLUE)Auto-fixing SwiftLint issues...$(NC)"; \
swiftlint --fix; \
else \
echo "$(YELLOW)SwiftLint not found. Install with: brew install swiftlint$(NC)"; \
fi
#===============================================================================
# PRODUCTION DISTRIBUTION TARGETS
#===============================================================================
archive: ## Create xcarchive with Developer ID signing
@echo "$(BLUE)Creating xcarchive...$(NC)"
@mkdir -p $(PROD_BUILD_DIR)
xcodebuild -project $(XCODE_PROJECT) \
-scheme $(SCHEME) \
-configuration $(CONFIGURATION_RELEASE) \
-archivePath $(ARCHIVE_PATH) \
-destination $(DESTINATION) \
-allowProvisioningUpdates \
-xcconfig ModSwitchIME/Config/Version.xcconfig \
DEVELOPMENT_TEAM=$(DEVELOPMENT_TEAM) \
PRODUCT_BUNDLE_IDENTIFIER="$(PRODUCT_BUNDLE_IDENTIFIER)" \
TEST_BUNDLE_IDENTIFIER="$(TEST_BUNDLE_IDENTIFIER)" \
CODE_SIGN_STYLE=Manual \
CODE_SIGN_IDENTITY="Developer ID Application: Yoshihiko Nishida (R7LKF73J2W)" \
OTHER_CODE_SIGN_FLAGS="--timestamp --options=runtime" \
CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO \
archive
@echo "$(GREEN)Archive created at: $(ARCHIVE_PATH)$(NC)"
package: archive ## Export app from archive with Developer ID
@echo "$(BLUE)Exporting app from archive...$(NC)"
@mkdir -p $(EXPORT_PATH)
@echo "$(BLUE)Creating exportOptions.plist...$(NC)"
@echo '<?xml version="1.0" encoding="UTF-8"?>' > $(EXPORT_PATH)/exportOptions.plist
@echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> $(EXPORT_PATH)/exportOptions.plist
@echo '<plist version="1.0">' >> $(EXPORT_PATH)/exportOptions.plist
@echo '<dict>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <key>method</key>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <string>developer-id</string>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <key>teamID</key>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <string>$(DEVELOPMENT_TEAM)</string>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <key>signingCertificate</key>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <string>Developer ID Application</string>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <key>signingStyle</key>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <string>manual</string>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <key>hardened-runtime</key>' >> $(EXPORT_PATH)/exportOptions.plist
@echo ' <true/>' >> $(EXPORT_PATH)/exportOptions.plist
@echo '</dict>' >> $(EXPORT_PATH)/exportOptions.plist
@echo '</plist>' >> $(EXPORT_PATH)/exportOptions.plist
xcodebuild -exportArchive \
-archivePath $(ARCHIVE_PATH) \
-exportPath $(EXPORT_PATH) \
-exportOptionsPlist $(EXPORT_PATH)/exportOptions.plist \
-allowProvisioningUpdates
@echo "$(GREEN)App exported to: $(EXPORT_PATH)/$(PROJECT_NAME).app$(NC)"
@echo "$(BLUE)Verifying signature...$(NC)"
@codesign -dv --verbose=2 "$(EXPORT_PATH)/$(PROJECT_NAME).app"
@echo "$(BLUE)Copying to release directory...$(NC)"
@rm -rf "$(PROD_BUILD_DIR)/$(PROJECT_NAME).app"
@cp -R "$(EXPORT_PATH)/$(PROJECT_NAME).app" "$(PROD_BUILD_DIR)/"
@echo "$(GREEN)Production app ready at: $(PROD_BUILD_DIR)/$(PROJECT_NAME).app$(NC)"
dmg: package ## Create DMG for distribution
@echo "$(BLUE)Creating DMG...$(NC)"
@echo "$(BLUE)Preparing DMG contents...$(NC)"
@rm -rf "$(PROD_BUILD_DIR)/dmg_temp"
@mkdir -p "$(PROD_BUILD_DIR)/dmg_temp"
@cp -R "$(PROD_BUILD_DIR)/$(PROJECT_NAME).app" "$(PROD_BUILD_DIR)/dmg_temp/"
@ln -s /Applications "$(PROD_BUILD_DIR)/dmg_temp/Applications"
@if command -v create-dmg >/dev/null 2>&1; then \
create-dmg \
--volname "$(PROJECT_NAME)" \
--window-pos 200 120 \
--window-size 600 400 \
--icon-size 100 \
--icon "$(PROJECT_NAME).app" 150 200 \
--hide-extension "$(PROJECT_NAME).app" \
--app-drop-link 450 200 \
--background-color "FFFFFF" \
"$(DMG_PATH)" \
"$(PROD_BUILD_DIR)/dmg_temp/"; \
else \
echo "$(YELLOW)create-dmg not found. Install with: brew install create-dmg$(NC)"; \
echo "$(BLUE)Creating simple DMG...$(NC)"; \
hdiutil create -volname "$(PROJECT_NAME)" -srcfolder "$(PROD_BUILD_DIR)/dmg_temp" -ov -format UDZO "$(DMG_PATH)"; \
fi
@rm -rf "$(PROD_BUILD_DIR)/dmg_temp"
@echo "$(BLUE)Signing DMG...$(NC)"
codesign --force --sign "Developer ID Application" "$(DMG_PATH)" -v
notarize: ## Submit DMG for notarization (async - returns submission ID)
@echo "$(BLUE)Submitting DMG for notarization...$(NC)"
@if [ -z "$(APPLE_ID)" ] || [ -z "$(APPLE_PASSWORD)" ]; then \
echo "$(RED)Error: APPLE_ID and APPLE_PASSWORD environment variables must be set$(NC)"; \
exit 1; \
fi
@if [ ! -f "$(DMG_PATH)" ]; then \
echo "$(RED)Error: DMG file not found at $(DMG_PATH)$(NC)"; \
echo "$(YELLOW)Run 'make dmg' first to create the DMG$(NC)"; \
exit 1; \
fi
@SUBMISSION_ID=$$(xcrun notarytool submit "$(DMG_PATH)" \
--apple-id "$(APPLE_ID)" \
--password "$(APPLE_PASSWORD)" \
--team-id "$(DEVELOPMENT_TEAM)" \
--output-format json | grep -o '"id":"[^"]*"' | cut -d'"' -f4); \
if [ -n "$$SUBMISSION_ID" ]; then \
echo "$(GREEN)Submission ID: $$SUBMISSION_ID$(NC)"; \
echo "$$SUBMISSION_ID" > $(PROD_BUILD_DIR)/notarization-id.txt; \
echo ""; \
echo "$(YELLOW)Next steps:$(NC)"; \
echo " 1. Check status: make notarize-status"; \
echo " 2. Once approved, staple: make notarize-staple"; \
echo ""; \
echo "$(BLUE)Or check status directly:$(NC)"; \
echo " xcrun notarytool info $$SUBMISSION_ID --apple-id \"$(APPLE_ID)\" --password \"$(APPLE_PASSWORD)\" --team-id \"$(DEVELOPMENT_TEAM)\""; \
else \
echo "$(RED)Failed to submit for notarization$(NC)"; \
exit 1; \
fi
notarize-status: ## Check notarization status (use SUBMISSION_ID=xxx or reads from file)
@echo "$(BLUE)Checking notarization status...$(NC)"
@if [ -z "$(APPLE_ID)" ] || [ -z "$(APPLE_PASSWORD)" ]; then \
echo "$(RED)Error: APPLE_ID and APPLE_PASSWORD environment variables must be set$(NC)"; \
exit 1; \
fi
@if [ -z "$(SUBMISSION_ID)" ] && [ -f "$(PROD_BUILD_DIR)/notarization-id.txt" ]; then \
SUBMISSION_ID=$$(cat $(PROD_BUILD_DIR)/notarization-id.txt); \
fi; \
if [ -z "$$SUBMISSION_ID" ]; then \
echo "$(RED)Error: No SUBMISSION_ID provided and no saved ID found$(NC)"; \
echo "$(YELLOW)Usage: make notarize-status SUBMISSION_ID=xxx$(NC)"; \
exit 1; \
fi; \
echo "$(BLUE)Submission ID: $$SUBMISSION_ID$(NC)"; \
xcrun notarytool info "$$SUBMISSION_ID" \
--apple-id "$(APPLE_ID)" \
--password "$(APPLE_PASSWORD)" \
--team-id "$(DEVELOPMENT_TEAM)"
notarize-staple: ## Staple notarization ticket to DMG after approval
@echo "$(BLUE)Stapling notarization ticket to DMG...$(NC)"
@if [ ! -f "$(DMG_PATH)" ]; then \
echo "$(RED)Error: DMG file not found at $(DMG_PATH)$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Checking if DMG is notarized...$(NC)"
@if xcrun stapler staple "$(DMG_PATH)"; then \
echo "$(GREEN)Successfully stapled notarization ticket!$(NC)"; \
echo "$(GREEN)DMG is ready for distribution: $(DMG_PATH)$(NC)"; \
echo ""; \
echo "$(BLUE)Verifying stapled DMG...$(NC)"; \
spctl -a -t open --context context:primary-signature -v "$(DMG_PATH)" || true; \
else \
echo "$(RED)Failed to staple notarization ticket$(NC)"; \
echo "$(YELLOW)Make sure notarization is complete with: make notarize-status$(NC)"; \
exit 1; \
fi
release: clean lint test dmg ## Full release build (clean, lint, test, archive, package, dmg)
@echo "$(GREEN)Release build complete!$(NC)"
@echo "$(GREEN)DMG ready at: $(DMG_PATH)$(NC)"
@echo ""
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Set APPLE_ID and APPLE_PASSWORD environment variables"
@echo " 2. Run 'make notarize' to submit DMG for notarization"
@echo " 3. Run 'make notarize-status' to check notarization progress"
@echo " 4. Run 'make notarize-staple' once notarization is approved"
#===============================================================================
# UTILITIES
#===============================================================================
clean: ## Clean build artifacts
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
xcodebuild -project $(XCODE_PROJECT) -scheme $(SCHEME) clean
clean-all: clean ## Clean all artifacts including caches
@echo "$(BLUE)Cleaning all artifacts...$(NC)"
@rm -rf $(BUILD_DIR)
@rm -rf ~/Library/Developer/Xcode/DerivedData/$(PROJECT_NAME)-*
clean-dev: ## Clean development build artifacts
@echo "$(BLUE)Cleaning development build...$(NC)"
@rm -rf $(DEV_BUILD_DIR)
clean-release: ## Clean release build artifacts
@echo "$(BLUE)Cleaning release build...$(NC)"
@rm -rf $(PROD_BUILD_DIR)
version: ## Show current version information
@echo "$(BLUE)Version Information:$(NC)"
@echo "Project: $(PROJECT_NAME)"
@echo "Version: $(VERSION)"
@echo "Build: $(BUILD_NUMBER)"
@echo "Team ID: $(DEVELOPMENT_TEAM)"
@echo "Git commit: $(shell git rev-parse --short HEAD 2>/dev/null || echo "N/A")"
@echo "Git branch: $(shell git branch --show-current 2>/dev/null || echo "N/A")"
status: ## Show project status
@echo "$(BLUE)Project Status:$(NC)"
@echo ""
@echo "$(YELLOW)Git status:$(NC)"
@git status --short || echo "Not a git repository"
@echo ""
@echo "$(YELLOW)Build artifacts:$(NC)"
@ls -la $(BUILD_DIR) 2>/dev/null || echo "No build artifacts"
@echo ""
@echo "$(YELLOW)Development Team:$(NC)"
@echo "$(DEVELOPMENT_TEAM)"
@echo ""
@echo "$(YELLOW)Installed version:$(NC)"
@if [ -d "/Applications/$(PROJECT_NAME).app" ]; then \
defaults read "/Applications/$(PROJECT_NAME).app/Contents/Info.plist" CFBundleShortVersionString 2>/dev/null || echo "Cannot read version"; \
else \
echo "Not installed"; \
fi
#===============================================================================
# VERSION MANAGEMENT
#===============================================================================
show-version: ## Show version from xcconfig files
@echo "$(BLUE)Version from xcconfig:$(NC)"
@echo "Marketing Version: $$(grep '^MARKETING_VERSION' ModSwitchIME/Config/Version.xcconfig | cut -d'=' -f2 | xargs)"
@echo "Build Number: $$(grep '^CURRENT_PROJECT_VERSION' ModSwitchIME/Config/Version.xcconfig | cut -d'=' -f2 | xargs)"
bump-version: ## Update version (usage: make bump-version VERSION=1.0.3)
@if [ -z "$(VERSION)" ]; then \
echo "$(RED)Error: VERSION not specified$(NC)"; \
echo "Usage: make bump-version VERSION=1.0.3"; \
exit 1; \
fi
@./Scripts/update_version.sh $(VERSION)
bump-build: ## Increment build number only
@./Scripts/update_version.sh --build-only