Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
193 lines (175 loc) · 7.8 KB
/
Copy pathMakefile
File metadata and controls
193 lines (175 loc) · 7.8 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
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)
TEST_RUNNER = $(BUILD_DIR)/FreeFlowTests
TEST_CONTEXT_HARNESS = $(BUILD_DIR)/ContextCaptureHarness.swift
TEST_DISPATCH_HARNESS = $(BUILD_DIR)/AppTextInsertionDispatchHarness.swift
TEST_PRODUCTION_SOURCES = \
Sources/APIConfigurationDraft.swift \
Sources/AppContextService.swift \
Sources/AppName.swift \
Sources/AppTextInsertionCore.swift \
Sources/AppTextInsertionTarget.swift \
Sources/ContextInferenceFailure.swift \
Sources/LLMAPITransport.swift \
Sources/LLMCooldownManager.swift \
Sources/ModelConfiguration.swift \
Sources/OriginalFieldInsertionPreference.swift \
Sources/PostProcessingService.swift \
Sources/RecordingCaptureTiming.swift \
Sources/RecordingTimerPreference.swift \
Sources/ShortcutCleanupPreference.swift \
Sources/TranscriptionErrorPresentationCore.swift \
Sources/TranscriptTextCore.swift \
Sources/TemperatureCapabilityCache.swift \
Sources/TranscriptionService.swift \
Sources/UpdateManager.swift \
Sources/ShortcutCore/DictationShortcutSessionController.swift \
Sources/ShortcutCore/ShortcutMatcher.swift \
Sources/ShortcutCore/ShortcutModels.swift
TEST_SOURCES = $(shell find Tests -name '*.swift' -type f | LC_ALL=C sort)
SHELL_SCRIPTS = $(shell find .github/scripts .agents/skills -name '*.sh' -type f | LC_ALL=C sort)
YAML_FILES = $(shell find .github -type f \( -name '*.yml' -o -name '*.yaml' \) | 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 check clean run icon dmg codesign-dmg notarize test typecheck validate
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)"
check: typecheck test validate
typecheck:
swiftc \
-parse-as-library \
-typecheck \
-warnings-as-errors \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx13.0 \
$(SOURCES)
$(TEST_CONTEXT_HARNESS): Sources/AppState.swift Sources/SettingsView.swift Tests/generate-context-capture-harness.rb
@mkdir -p "$(BUILD_DIR)"
ruby Tests/generate-context-capture-harness.rb $< Sources/SettingsView.swift "$@"
$(TEST_DISPATCH_HARNESS): Sources/AppState.swift Tests/generate-insertion-dispatch-harness.rb
@mkdir -p "$(BUILD_DIR)"
ruby Tests/generate-insertion-dispatch-harness.rb $< "$@"
test: $(TEST_CONTEXT_HARNESS) $(TEST_DISPATCH_HARNESS)
@mkdir -p "$(BUILD_DIR)"
swiftc \
-parse-as-library \
-warnings-as-errors \
-o "$(TEST_RUNNER)" \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx13.0 \
$(TEST_PRODUCTION_SOURCES) \
$(TEST_SOURCES) \
"$(TEST_CONTEXT_HARNESS)" \
"$(TEST_DISPATCH_HARNESS)"
@$(TEST_RUNNER)
validate:
plutil -lint Info.plist FreeFlow.entitlements
@set -e; for script in $(SHELL_SCRIPTS); do bash -n "$$script"; done
@ruby -e 'require "yaml"; ARGV.each { |file| YAML.load_file(file) }' $(YAML_FILES)
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)" \
--background "Resources/dmg-background.tiff" \
--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)"