-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (113 loc) · 5.22 KB
/
Makefile
File metadata and controls
125 lines (113 loc) · 5.22 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
APP_NAME ?= FreeFlow Dev
BUNDLE_ID ?= com.zachlatta.freeflow.dev
BUILD_DIR = build
APP_BUNDLE = $(BUILD_DIR)/$(APP_NAME).app
CODESIGN_IDENTITY ?= FreeFlow Dev
CONTENTS = $(APP_BUNDLE)/Contents
MACOS_DIR = $(CONTENTS)/MacOS
empty :=
space := $(empty) $(empty)
APP_EXECUTABLE = $(MACOS_DIR)/$(APP_NAME)
APP_EXECUTABLE_TARGET := $(subst $(space),\ ,$(APP_EXECUTABLE))
SOURCES = $(shell find Sources -name '*.swift' -type f | LC_ALL=C sort)
RESOURCES = $(CONTENTS)/Resources
ARCH ?= $(shell uname -m)
# Pick the icon source based on which bundle we are building. Dev builds get
# a distinct hammer-on-waveform icon so a developer's dock shows at a glance
# which FreeFlow they are running when both are installed side by side.
ifeq ($(APP_NAME),FreeFlow Dev)
ICON_SOURCE = Resources/AppIcon-Dev-Source.png
ICON_ICNS = Resources/AppIcon-Dev.icns
else
ICON_SOURCE = Resources/AppIcon-Source.png
ICON_ICNS = Resources/AppIcon.icns
endif
.PHONY: all clean run icon dmg codesign-dmg notarize
all: $(APP_EXECUTABLE_TARGET)
$(APP_EXECUTABLE_TARGET): $(SOURCES) Info.plist $(ICON_ICNS)
@mkdir -p "$(MACOS_DIR)" "$(RESOURCES)"
ifeq ($(ARCH),universal)
swiftc \
-parse-as-library \
-o "$(MACOS_DIR)/$(APP_NAME)-arm64" \
-sdk $(shell xcrun --show-sdk-path) \
-target arm64-apple-macosx13.0 \
$(SOURCES)
swiftc \
-parse-as-library \
-o "$(MACOS_DIR)/$(APP_NAME)-x86_64" \
-sdk $(shell xcrun --show-sdk-path) \
-target x86_64-apple-macosx13.0 \
$(SOURCES)
lipo -create -output "$(MACOS_DIR)/$(APP_NAME)" \
"$(MACOS_DIR)/$(APP_NAME)-arm64" \
"$(MACOS_DIR)/$(APP_NAME)-x86_64"
@rm "$(MACOS_DIR)/$(APP_NAME)-arm64" "$(MACOS_DIR)/$(APP_NAME)-x86_64"
else
swiftc \
-parse-as-library \
-o "$(MACOS_DIR)/$(APP_NAME)" \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx13.0 \
$(SOURCES)
endif
@cp Info.plist "$(CONTENTS)/"
@plutil -replace CFBundleName -string "$(APP_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleDisplayName -string "$(APP_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleExecutable -string "$(APP_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleIdentifier -string "$(BUNDLE_ID)" "$(CONTENTS)/Info.plist"
@cp $(ICON_ICNS) "$(RESOURCES)/AppIcon.icns"
@plutil -replace NSMicrophoneUsageDescription -string "$(APP_NAME) needs microphone access to transcribe your speech." "$(CONTENTS)/Info.plist"
@plutil -replace NSSpeechRecognitionUsageDescription -string "$(APP_NAME) needs speech recognition to convert your voice to text." "$(CONTENTS)/Info.plist"
@plutil -replace NSAccessibilityUsageDescription -string "$(APP_NAME) needs accessibility access to detect the text cursor position and paste transcribed text." "$(CONTENTS)/Info.plist"
@codesign --force --options runtime --sign "$(CODESIGN_IDENTITY)" --entitlements FreeFlow.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 $@"
dmg: all
@rm -f "$(BUILD_DIR)/$(APP_NAME).dmg"
@rm -rf $(BUILD_DIR)/dmg-staging
@mkdir -p $(BUILD_DIR)/dmg-staging
@cp -R "$(APP_BUNDLE)" $(BUILD_DIR)/dmg-staging/
@osascript -e 'tell application "Finder" to make alias file to POSIX file "/Applications" at POSIX file "'"$$(cd $(BUILD_DIR)/dmg-staging && pwd)"'"'
@ALIAS=$$(find $(BUILD_DIR)/dmg-staging -maxdepth 1 -not -name '*.app' -not -name '.DS_Store' -type f | head -1) && mv "$$ALIAS" "$(BUILD_DIR)/dmg-staging/Applications"
@fileicon set "$(BUILD_DIR)/dmg-staging/Applications" /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ApplicationsFolderIcon.icns
@echo "Creating DMG..."
@create-dmg \
--volname "$(APP_NAME)" \
--volicon "$(ICON_ICNS)" \
--window-pos 200 120 \
--window-size 660 400 \
--icon-size 128 \
--icon "$(APP_NAME).app" 180 170 \
--hide-extension "$(APP_NAME).app" \
--icon "Applications" 480 170 \
--no-internet-enable \
"$(BUILD_DIR)/$(APP_NAME).dmg" \
"$(BUILD_DIR)/dmg-staging"
@rm -rf $(BUILD_DIR)/dmg-staging
@echo "Created $(BUILD_DIR)/$(APP_NAME).dmg"
codesign-dmg: dmg
codesign --force --sign "$(CODESIGN_IDENTITY)" "$(BUILD_DIR)/$(APP_NAME).dmg"
notarize:
xcrun notarytool submit "$(BUILD_DIR)/$(APP_NAME).dmg" \
--keychain-profile "$(NOTARIZE_PROFILE)" --wait
xcrun stapler staple "$(BUILD_DIR)/$(APP_NAME).dmg"
clean:
rm -rf $(BUILD_DIR)
run: all
open "$(APP_BUNDLE)"