-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (173 loc) · 6.09 KB
/
Copy pathMakefile
File metadata and controls
194 lines (173 loc) · 6.09 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
NAME := StillCore
LOCAL ?=
WORKSPACE ?=
CONFIGURATION ?= Debug
DESTINATION ?= platform=macOS,arch=arm64
DERIVED_DATA := .build
XCODEBUILD_FLAGS := \
-quiet -hideShellScriptEnvironment \
ENABLE_CODE_COVERAGE=NO
DEVELOPMENT_TEAM ?=
ifneq ($(DEVELOPMENT_TEAM),)
XCODEBUILD_FLAGS += DEVELOPMENT_TEAM=$(DEVELOPMENT_TEAM)
endif
ifneq ($(LOCAL),)
WORKSPACE := $(NAME).local
MACMON_XCFRAMEWORK_PATH := ../macmon/dist/CMacmon.xcframework
export MACMON_XCFRAMEWORK_PATH
endif
XCODE_CONTAINER := -project $(NAME).xcodeproj
ifneq ($(WORKSPACE),)
XCODE_CONTAINER := -workspace $(WORKSPACE).xcworkspace
endif
APP_PATH = $(DERIVED_DATA)/Build/Products/$(CONFIGURATION)/$(NAME).app
APP_EXEC_PATH = $(APP_PATH)/Contents/MacOS/$(NAME)
.PHONY: help
help:
@printf '%s\n' \
'make app Build $(NAME).app' \
'LOCAL=1 make app Build with local workspace and local macmon xcframework' \
'make run Build and run $(NAME) in this terminal' \
'make open-app Build and open $(NAME).app' \
'make release Build Release, create $(NAME).dmg, submit for notarization' \
' DEVELOPMENT_TEAM=... Team id for Developer ID signing' \
' NOTARY_PROFILE=... Keychain profile for notarytool (default: $(NOTARY_PROFILE))' \
'make dmg Build Release, create $(NAME).dmg suitable for local running (ad-hoc)' \
'make helper-restart Build app and restart battery helper' \
'make helper-uninstall Build app and uninstall battery helper' \
'make profile Build $(NAME) and launch xctrace Time Profiler' \
'make benchmarks Run charts benchmarks' \
'make install-hooks Use repo-managed git hooks' \
'make clean Remove .build'
.PHONY: app
app:
xcodebuild $(XCODE_CONTAINER) build \
-scheme $(NAME) -configuration $(CONFIGURATION) \
-destination '$(DESTINATION)' \
-derivedDataPath $(DERIVED_DATA) \
$(XCODEBUILD_FLAGS)
.PHONY: run
run: app
$(APP_EXEC_PATH)
.PHONY: open-app
open-app: app
open "$(APP_PATH)"
.PHONY: helper-restart
helper-restart: app
"$(APP_EXEC_PATH)" --helper-restart
.PHONY: helper-uninstall
helper-uninstall: app
"$(APP_EXEC_PATH)" --helper-uninstall
.PHONY: benchmarks
benchmarks:
swift run -c release --package-path Benchmarks Benchmarks \
--warmup-iterations 3 --max-iterations 2000 --min-time 1 \
--time-unit us --columns name,time,throughput,std,iterations
.PHONY: install-hooks
install-hooks:
git config core.hooksPath .githooks
.PHONY: profile
PROFILE_TRACE ?= $(DERIVED_DATA)/$(NAME)-Time-Profiler.trace
PROFILE_TEMPLATE ?= Time Profiler
profile: CONFIGURATION=Release
profile: app
rm -rf "$(PROFILE_TRACE)"
@set -e; \
"$(APP_EXEC_PATH)" & \
app_pid=$$!; \
echo "Profiling PID $$app_pid"; \
xcrun xctrace record \
--template "$(PROFILE_TEMPLATE)" \
--output "$(PROFILE_TRACE)" \
--attach "$$app_pid"; \
open "$(PROFILE_TRACE)"
.PHONY: clean
clean:
rm -rf "$(DERIVED_DATA)"
rm -rf "./Benchmarks/.build"
# -------------------------------- dmg -------------------------------------------------
.PHONY: archive
_ARCHIVE_PATH = $(DERIVED_DATA)/$(NAME).xcarchive
_ARCHIVE_TEAM = $(shell plutil -extract ApplicationProperties.Team raw -o - "$(_ARCHIVE_PATH)/Info.plist" 2>/dev/null)
archive:
rm -rf "$(_ARCHIVE_PATH)"
xcodebuild $(XCODE_CONTAINER) archive \
-scheme $(NAME) -configuration Release \
-destination '$(DESTINATION)' \
-derivedDataPath $(DERIVED_DATA) \
-archivePath "$(_ARCHIVE_PATH)" \
$(XCODEBUILD_FLAGS)
.PHONY: export-app
EXPORT_DIR ?= .
EXPORT_METHOD ?= $(if $(_ARCHIVE_TEAM),debugging,mac-application)
_EXPORT_PLIST = $(DERIVED_DATA)/exportOptions.plist
export-app: archive
mkdir -p "$(EXPORT_DIR)"
rm -f "$(_EXPORT_PLIST)"
plutil -create xml1 "$(_EXPORT_PLIST)"
plutil -insert destination -string export "$(_EXPORT_PLIST)"
plutil -insert method -string "$(EXPORT_METHOD)" "$(_EXPORT_PLIST)"
plutil -insert stripSwiftSymbols -bool YES "$(_EXPORT_PLIST)"
plutil -insert manageAppVersionAndBuildNumber -bool NO "$(_EXPORT_PLIST)"
xcodebuild -exportArchive \
-archivePath "$(_ARCHIVE_PATH)" \
-exportPath "$(EXPORT_DIR)" \
-exportOptionsPlist "$(_EXPORT_PLIST)"
.PHONY: _prepare-dmg-staging-dir
_prepare-dmg-staging-dir:
rm -rf "$(DMG_STAGING_DIR)"
mkdir -p "$(DMG_STAGING_DIR)"
ln -s /Applications "$(DMG_STAGING_DIR)/Applications"
.PHONY: dmg
DMG_PATH = $(NAME).dmg
DMG_EXPORT_DIR = $(DERIVED_DATA)/export
DMG_STAGING_DIR = $(DERIVED_DATA)/dmg
dmg: EXPORT_DIR=$(DMG_EXPORT_DIR)
dmg: _prepare-dmg-staging-dir export-app
cp -R "$(DMG_EXPORT_DIR)/$(NAME).app" "$(DMG_STAGING_DIR)/"
rm -f "$(DMG_PATH)"
hdiutil create -volname "$(NAME)" \
-srcfolder "$(DMG_STAGING_DIR)" \
-ov -format UDZO \
"$(DMG_PATH)"
# -------------------------------- release ---------------------------------------------
.PHONY: _require-development-team
_require-development-team:
@if [ -z "$(DEVELOPMENT_TEAM)" ]; then \
echo ""; \
echo "DEVELOPMENT_TEAM is required for make release."; \
echo "Example: make release DEVELOPMENT_TEAM=5Q4AEAVS86"; \
echo ""; \
exit 1; \
fi
.PHONY: _require-keychain-profile
_require-keychain-profile:
@if xcrun notarytool history --keychain-profile "$(NOTARY_PROFILE)" >/dev/null 2>&1; then \
:; \
else \
echo ""; \
echo "Missing or invalid notarytool keychain profile: $(NOTARY_PROFILE)"; \
echo ""; \
echo "Create it once with:"; \
echo " xcrun notarytool store-credentials \"$(NOTARY_PROFILE)\" --apple-id \"<apple-id>\" --team-id \"$(DEVELOPMENT_TEAM)\""; \
echo ""; \
echo "notarytool will then prompt for the app-specific password and save it in Keychain."; \
exit 1; \
fi
.PHONY: release
NOTARY_PROFILE ?= $(NAME)-Notarization
NOTARY_FLAGS := \
CODE_SIGN_IDENTITY="Developer ID Application" \
CODE_SIGN_STYLE=Manual \
CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO \
RUNTIME_EXCEPTION_DISABLE_LIBRARY_VALIDATION=NO \
OTHER_CODE_SIGN_FLAGS="--timestamp"
release: EXPORT_METHOD=developer-id
release: XCODEBUILD_FLAGS += $(NOTARY_FLAGS)
release: _require-development-team _require-keychain-profile dmg
xcrun notarytool submit "$(DMG_PATH)" \
--keychain-profile "$(NOTARY_PROFILE)" \
--wait
xcrun stapler staple "$(DMG_PATH)"
xcrun stapler validate "$(DMG_PATH)"
@echo "Release artifact: $(DMG_PATH)"