-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (159 loc) · 6.93 KB
/
Makefile
File metadata and controls
176 lines (159 loc) · 6.93 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
# APP_NAME controls the .app bundle folder; PRODUCT_NAME controls the executable and plist identity.
APP_NAME ?= WP Workspace Dev
PRODUCT_NAME ?= WP Workspace
BUNDLE_ID ?= com.automattic.wpworkspace.dev
WPCOM_OAUTH_CLIENT_SECRET_FILE ?=
WPCOM_OAUTH_CLIENT_ID ?=
BUILD_DIR = build
APP_BUNDLE = $(BUILD_DIR)/$(APP_NAME).app
CODESIGN_IDENTITY ?= -
CONTENTS = $(APP_BUNDLE)/Contents
MACOS_DIR = $(CONTENTS)/MacOS
empty :=
space := $(empty) $(empty)
APP_EXECUTABLE = $(MACOS_DIR)/$(PRODUCT_NAME)
APP_EXECUTABLE_TARGET := $(subst $(space),\ ,$(APP_EXECUTABLE))
ZIP_PATH = $(BUILD_DIR)/$(APP_NAME).zip
DMG_PATH = $(BUILD_DIR)/$(APP_NAME).dmg
DMG_SPEC = $(BUILD_DIR)/dmg-spec.json
NOTARIZE = Tools/notarize.sh
SOURCES = $(shell find Sources -name '*.swift' -type f | LC_ALL=C sort)
RESOURCES = $(CONTENTS)/Resources
ARCH ?= $(shell uname -m)
ICON_SOURCE = Resources/AppIcon-Source.png
ICON_ICNS = Resources/AppIcon.icns
WPCOM_LOGO = Resources/WPCOM-Blueberry-Pill-Logo.svg
MENU_BAR_LOGO = Resources/MenuBarWordPressLogo.svg
FONT_RESOURCES = $(shell find Resources/Fonts -type f 2>/dev/null | LC_ALL=C sort)
DRAFT_FOCUS_THEME_RESOURCES = $(shell find Resources/DraftFocusThemes -type f 2>/dev/null | LC_ALL=C sort)
DRAFT_FOCUS_SOUND_RESOURCES = $(shell find Resources/DraftFocusSounds -type f 2>/dev/null | LC_ALL=C sort)
LDFLAGS = -lsqlite3
.PHONY: all clean run icon dmg codesign-dmg notarize-app notarize-dmg zip release
all: $(APP_EXECUTABLE_TARGET)
$(APP_EXECUTABLE_TARGET): $(SOURCES) Info.plist $(ICON_ICNS) $(ICON_SOURCE) $(WPCOM_LOGO) $(MENU_BAR_LOGO) $(FONT_RESOURCES) $(DRAFT_FOCUS_THEME_RESOURCES) $(DRAFT_FOCUS_SOUND_RESOURCES)
@mkdir -p "$(MACOS_DIR)" "$(RESOURCES)"
ifeq ($(ARCH),universal)
swiftc \
-parse-as-library \
-o "$(MACOS_DIR)/$(PRODUCT_NAME)-arm64" \
-sdk $(shell xcrun --show-sdk-path) \
-target arm64-apple-macosx13.0 \
$(SOURCES) \
$(LDFLAGS)
swiftc \
-parse-as-library \
-o "$(MACOS_DIR)/$(PRODUCT_NAME)-x86_64" \
-sdk $(shell xcrun --show-sdk-path) \
-target x86_64-apple-macosx13.0 \
$(SOURCES) \
$(LDFLAGS)
lipo -create -output "$(MACOS_DIR)/$(PRODUCT_NAME)" \
"$(MACOS_DIR)/$(PRODUCT_NAME)-arm64" \
"$(MACOS_DIR)/$(PRODUCT_NAME)-x86_64"
@rm "$(MACOS_DIR)/$(PRODUCT_NAME)-arm64" "$(MACOS_DIR)/$(PRODUCT_NAME)-x86_64"
else
swiftc \
-parse-as-library \
-o "$(MACOS_DIR)/$(PRODUCT_NAME)" \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx13.0 \
$(SOURCES) \
$(LDFLAGS)
endif
@cp Info.plist "$(CONTENTS)/"
@plutil -replace CFBundleName -string "$(PRODUCT_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleDisplayName -string "$(PRODUCT_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleExecutable -string "$(PRODUCT_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleIdentifier -string "$(BUNDLE_ID)" "$(CONTENTS)/Info.plist"
@cp $(ICON_ICNS) "$(RESOURCES)/"
@cp $(ICON_SOURCE) "$(RESOURCES)/"
@cp $(WPCOM_LOGO) "$(RESOURCES)/"
@cp $(MENU_BAR_LOGO) "$(RESOURCES)/"
@rm -rf "$(RESOURCES)/Fonts"
@cp -R Resources/Fonts "$(RESOURCES)/Fonts"
@if [ -d Resources/DraftFocusThemes ]; then \
rm -rf "$(RESOURCES)/DraftFocusThemes"; \
cp -R Resources/DraftFocusThemes "$(RESOURCES)/DraftFocusThemes"; \
fi
@if [ -d Resources/DraftFocusSounds ]; then \
rm -rf "$(RESOURCES)/DraftFocusSounds"; \
cp -R Resources/DraftFocusSounds "$(RESOURCES)/DraftFocusSounds"; \
fi
@secret="$${WPCOM_OAUTH_CLIENT_SECRET:-}"; \
if [ -n "$(WPCOM_OAUTH_CLIENT_SECRET_FILE)" ]; then \
secret="$$(cat "$(WPCOM_OAUTH_CLIENT_SECRET_FILE)")"; \
fi; \
if [ -n "$(WPCOM_OAUTH_CLIENT_ID)" ]; then \
plutil -replace WPCOMOAuthClientID -string "$(WPCOM_OAUTH_CLIENT_ID)" "$(CONTENTS)/Info.plist"; \
fi; \
plutil -replace WPCOMOAuthClientSecret -string "$$secret" "$(CONTENTS)/Info.plist"
@codesign --force --options runtime --sign "$(CODESIGN_IDENTITY)" --entitlements WPWorkspace.entitlements "$(APP_BUNDLE)"
@echo "Built $(APP_BUNDLE)"
icon: $(ICON_ICNS)
$(ICON_ICNS): $(ICON_SOURCE)
@mkdir -p $(BUILD_DIR)/AppIcon.iconset
@sips -z 16 16 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_16x16.png > /dev/null
@sips -z 32 32 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_16x16@2x.png > /dev/null
@sips -z 32 32 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_32x32.png > /dev/null
@sips -z 64 64 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_32x32@2x.png > /dev/null
@sips -z 128 128 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_128x128.png > /dev/null
@sips -z 256 256 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_128x128@2x.png > /dev/null
@sips -z 256 256 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_256x256.png > /dev/null
@sips -z 512 512 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_256x256@2x.png > /dev/null
@sips -z 512 512 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_512x512.png > /dev/null
@sips -z 1024 1024 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_512x512@2x.png > /dev/null
@iconutil -c icns -o $@ $(BUILD_DIR)/AppIcon.iconset
@rm -rf $(BUILD_DIR)/AppIcon.iconset
@echo "Generated $@"
# Uses `appdmg` (npm) rather than `create-dmg` (brew) because appdmg writes the
# .DS_Store layout directly via `hdiutil` + the `ds-store` library, no AppleScript
# or Finder session required. That matters on headless CI agents, where any tool
# that drives Finder via osascript times out after ~120s.
dmg: $(DMG_PATH)
$(BUILD_DIR):
@mkdir -p "$@"
$(DMG_SPEC): Makefile | $(BUILD_DIR)
@printf '%s\n' \
'{' \
' "title": "$(APP_NAME)",' \
' "icon": "$(CURDIR)/$(ICON_ICNS)",' \
' "icon-size": 128,' \
' "format": "UDZO",' \
' "window": { "position": { "x": 200, "y": 120 }, "size": { "width": 660, "height": 400 } },' \
' "contents": [' \
' { "x": 180, "y": 170, "type": "file", "path": "$(CURDIR)/$(APP_BUNDLE)", "hide-extension": true },' \
' { "x": 480, "y": 170, "type": "link", "path": "/Applications" }' \
' ]' \
'}' > "$@"
$(DMG_PATH): $(DMG_SPEC) notarize-app
@rm -f "$@"
@echo "Creating DMG..."
@npx --yes appdmg@0.6.6 "$(DMG_SPEC)" "$@"
@rm -f "$(DMG_SPEC)"
@echo "Created $@"
codesign-dmg: $(DMG_PATH)
codesign --force --sign "$(CODESIGN_IDENTITY)" "$(DMG_PATH)"
# Notarize the .app in place. Stapling rewrites the bundle, so any
# subsequent `codesign --force` on it would strip the ticket — keep
# this step at the very end of the build chain for the .app.
notarize-app: $(APP_EXECUTABLE_TARGET)
$(NOTARIZE) "$(APP_BUNDLE)"
# ZIP the (already stapled) .app for direct distribution alongside the DMG.
zip: notarize-app
@rm -f "$(ZIP_PATH)"
@ditto -c -k --sequesterRsrc --keepParent "$(APP_BUNDLE)" "$(ZIP_PATH)"
@echo "Created $(ZIP_PATH)"
notarize-dmg: codesign-dmg
$(NOTARIZE) "$(DMG_PATH)"
# Full release: notarize+staple .app, ZIP it, build+sign+notarize+staple DMG.
# Order matters: zip pulls in notarize-app, and the DMG file target also depends
# on notarize-app so the staged bundle is always the stapled app before the DMG
# itself is signed and notarized.
release: zip notarize-dmg
@echo "Release artifacts:"
@echo " $(ZIP_PATH)"
@echo " $(DMG_PATH)"
clean:
rm -rf $(BUILD_DIR)
run: all
open "$(APP_BUNDLE)"