-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (136 loc) · 5.36 KB
/
Makefile
File metadata and controls
147 lines (136 loc) · 5.36 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
APP=Scripta
ENTITLEMENTS=Scripta.entitlements
INSTALL_DIR=/Applications
CERT_NAME=Scripta Dev
DEV_BUNDLE=build/$(APP).app
WHISPER_DIR=vendor/whisper.cpp
WHISPER_BUILD=$(WHISPER_DIR)/build-static
WHISPER_LIB=Sources/CWhisper/lib/libwhisper.a
.PHONY: build run install setup-cert test clean reset-permissions whisper-lib
whisper-lib: $(WHISPER_LIB)
$(WHISPER_LIB):
@echo "Building whisper.cpp static library ..."
@mkdir -p vendor
@if [ ! -d "$(WHISPER_DIR)" ]; then \
git clone --depth 1 https://github.com/ggerganov/whisper.cpp.git $(WHISPER_DIR); \
fi
@cmake -B $(WHISPER_BUILD) -S $(WHISPER_DIR) \
-DCMAKE_OSX_ARCHITECTURES="arm64" \
-DBUILD_SHARED_LIBS=OFF \
-DGGML_METAL=ON \
-DWHISPER_COREML=OFF \
-DWHISPER_BUILD_TESTS=OFF \
-DWHISPER_BUILD_EXAMPLES=OFF \
-DCMAKE_BUILD_TYPE=Release 2>&1 | tail -5
@cmake --build $(WHISPER_BUILD) --config Release -j$$(sysctl -n hw.ncpu) 2>&1 | tail -5
@mkdir -p Sources/CWhisper/lib Sources/CWhisper/include
@libtool -static -o $(WHISPER_LIB) \
$(WHISPER_BUILD)/src/libwhisper.a \
$(WHISPER_BUILD)/ggml/src/libggml.a \
$(WHISPER_BUILD)/ggml/src/libggml-base.a \
$(WHISPER_BUILD)/ggml/src/libggml-cpu.a \
$(WHISPER_BUILD)/ggml/src/ggml-metal/libggml-metal.a \
$(WHISPER_BUILD)/ggml/src/ggml-blas/libggml-blas.a 2>/dev/null
@cp $(WHISPER_DIR)/include/whisper.h Sources/CWhisper/include/
@cp $(WHISPER_DIR)/ggml/include/ggml.h Sources/CWhisper/include/
@cp $(WHISPER_DIR)/ggml/include/ggml-cpu.h Sources/CWhisper/include/
@cp $(WHISPER_DIR)/ggml/include/ggml-backend.h Sources/CWhisper/include/
@cp $(WHISPER_DIR)/ggml/include/ggml-alloc.h Sources/CWhisper/include/
@echo "whisper.cpp static library built: $(WHISPER_LIB)"
build: $(WHISPER_LIB)
swift build
setup-cert:
@bash scripts/setup-cert.sh
run: setup-cert
@set -e; \
echo "Building ..."; \
swift build 2>&1; \
BIN_PATH="$$(swift build --show-bin-path)"; \
SRC_BIN="$$BIN_PATH/$(APP)"; \
CONTENTS_DIR="$(DEV_BUNDLE)/Contents"; \
MACOS_DIR="$$CONTENTS_DIR/MacOS"; \
DST_BIN="$$MACOS_DIR/$(APP)"; \
HASH_FILE="build/.binary_hash"; \
mkdir -p "$$MACOS_DIR"; \
NEW_HASH=$$(shasum -a 256 "$$SRC_BIN" | cut -d' ' -f1); \
OLD_HASH=""; \
if [ -f "$$HASH_FILE" ]; then OLD_HASH=$$(cat "$$HASH_FILE"); fi; \
if [ "$$NEW_HASH" != "$$OLD_HASH" ] || ! codesign --verify --deep --strict "$(DEV_BUNDLE)" 2>/dev/null; then \
echo "Binary changed — copying and signing ..."; \
cp "$$SRC_BIN" "$$DST_BIN"; \
cp "Sources/Scripta/Info.plist" "$$CONTENTS_DIR/Info.plist"; \
mkdir -p "$$CONTENTS_DIR/Resources"; \
if [ -f "Resources/AppIcon.icns" ]; then \
cp "Resources/AppIcon.icns" "$$CONTENTS_DIR/Resources/AppIcon.icns"; \
fi; \
echo "$$NEW_HASH" > "$$HASH_FILE"; \
/usr/bin/codesign --force --sign "$(CERT_NAME)" \
--entitlements $(ENTITLEMENTS) \
--deep "$(DEV_BUNDLE)"; \
echo "Signed. TCC may ask for permissions on first launch."; \
else \
echo "Binary unchanged — skipping re-sign (TCC permissions preserved)."; \
fi; \
echo "Launching $(DEV_BUNDLE) ..."; \
open "$(DEV_BUNDLE)"
install: setup-cert
@set -e; \
echo "Building release binary ..."; \
swift build -c release; \
BIN_PATH="$$(swift build -c release --show-bin-path)"; \
APP_BUNDLE="$(INSTALL_DIR)/$(APP).app"; \
CONTENTS_DIR="$$APP_BUNDLE/Contents"; \
MACOS_DIR="$$CONTENTS_DIR/MacOS"; \
mkdir -p "$$MACOS_DIR"; \
cp "$$BIN_PATH/$(APP)" "$$MACOS_DIR/$(APP)"; \
cp "Sources/Scripta/Info.plist" "$$CONTENTS_DIR/Info.plist"; \
xattr -cr "$$APP_BUNDLE"; \
/usr/bin/codesign --force --sign "$(CERT_NAME)" \
--entitlements $(ENTITLEMENTS) \
--deep "$$APP_BUNDLE"; \
echo ""; \
echo "Installed to $(INSTALL_DIR)/$(APP).app"; \
echo "Signed with certificate '$(CERT_NAME)'"; \
echo ""; \
echo "First launch: open /Applications/$(APP).app"; \
echo "Grant Microphone + Screen Recording when prompted."
deploy: setup-cert
@set -e; \
echo "Building release binary for deployment ..."; \
swift build -c release 2>&1; \
BIN_PATH="$$(swift build -c release --show-bin-path)"; \
DEPLOY_DIR="build/deploy"; \
APP_DIR="$$DEPLOY_DIR/$(APP).app/Contents"; \
MACOS_DIR="$$APP_DIR/MacOS"; \
rm -rf "$$DEPLOY_DIR"; \
mkdir -p "$$MACOS_DIR"; \
cp "$$BIN_PATH/$(APP)" "$$MACOS_DIR/$(APP)"; \
cp "Sources/Scripta/Info.plist" "$$APP_DIR/Info.plist"; \
xattr -cr "$$DEPLOY_DIR/$(APP).app"; \
/usr/bin/codesign --force --sign "$(CERT_NAME)" \
--entitlements Scripta-deploy.entitlements \
--deep "$$DEPLOY_DIR/$(APP).app"; \
echo ""; \
echo "=== Deploy package ready ==="; \
echo "App: $$DEPLOY_DIR/$(APP).app"; \
echo "Signed with MINIMAL entitlements (audio-input only)."; \
echo ""; \
echo "To install on target Mac:"; \
echo " 1. Copy $(APP).app to /Applications/"; \
echo " 2. Run: xattr -cr /Applications/$(APP).app"; \
echo " 3. Open from /Applications/ (not /tmp or ~/Downloads)"; \
echo " 4. Grant permissions when prompted"; \
echo ""; \
cd "$$DEPLOY_DIR" && zip -r ../$(APP)-deploy.zip $(APP).app; \
echo "Zip: build/$(APP)-deploy.zip ($$(du -h ../$(APP)-deploy.zip | cut -f1))"
test:
swift test
clean:
rm -rf .build build vendor Sources/CWhisper/lib/*.a
reset-permissions:
tccutil reset ScreenCapture com.thehwang.scripta
tccutil reset Microphone com.thehwang.scripta
@echo ""
@echo "TCC permissions reset. Re-launch the app to re-grant."
@echo "If Screen Recording doesn't work, add the app manually:"
@echo " System Settings → Privacy & Security → Screen Recording → + → select Scripta"