-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (84 loc) · 3.56 KB
/
Copy pathMakefile
File metadata and controls
93 lines (84 loc) · 3.56 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
# Project Variables
PROJECT_NAME = SubScript
BUILD_TYPE = release
PROJECT_ROOT = $(shell pwd)
BUILD_DIR = $(PROJECT_ROOT)/.build/$(BUILD_TYPE)
APP_BUNDLE = $(BUILD_DIR)/$(PROJECT_NAME).app
METALLIB_SRC = $(PROJECT_ROOT)/.build/checkouts/speech-swift/.build/release/mlx.metallib
FFMPEG_BIN_DIR = $(PROJECT_ROOT)/Sources/SubScript/Resources/Binaries
FFMPEG_BIN = $(FFMPEG_BIN_DIR)/ffmpeg
ICON_SET = $(PROJECT_ROOT)/Sources/SubScript/Assets.xcassets/AppIcon.appiconset
DMG_OUT = $(PROJECT_ROOT)/$(PROJECT_NAME).dmg
# Commands
SWIFT = swift
XCODEBUILD = xcodebuild
Hdiutil = hdiutil
.PHONY: all setup metallib build bundle dmg clean
all: dmg
setup:
@echo "=== Setting up Environment ==="
@$(XCODEBUILD) -downloadComponent MetalToolchain || echo "Metal Toolchain already installed"
@mkdir -p $(FFMPEG_BIN_DIR)
@ARCH=$$(uname -m); \
if [ "$$ARCH" = "arm64" ]; then \
FFMPEG_URL="https://ffmpeg.martin-riedl.de/redirect/latest/macos/arm64/snapshot/ffmpeg.zip"; \
else \
FFMPEG_URL="https://ffmpeg.martin-riedl.de/redirect/latest/macos/amd64/snapshot/ffmpeg.zip"; \
fi; \
if [ ! -f $(FFMPEG_BIN) ]; then \
echo "Downloading FFmpeg ($$ARCH)..."; \
curl -L "$$FFMPEG_URL" -o ffmpeg.zip; \
unzip -o ffmpeg.zip; \
mv ffmpeg $(FFMPEG_BIN); \
chmod +x $(FFMPEG_BIN); \
rm -f ffmpeg.zip; \
else \
echo "✓ FFmpeg already exists"; \
fi
@echo "=== Resolving SPM packages ==="
@$(SWIFT) package resolve
@echo "✓ Packages resolved"
metallib: setup
@echo "=== Building MLX metallib ==="
@cd $(PROJECT_ROOT)/.build/checkouts/speech-swift && \
$(SWIFT) build -c release --disable-sandbox && \
chmod +x scripts/build_mlx_metallib.sh && \
./scripts/build_mlx_metallib.sh release
@echo "✓ MLX metallib ready"
build: metallib
@echo "=== Building $(PROJECT_NAME) ($(BUILD_TYPE)) ==="
@$(SWIFT) build -c $(BUILD_TYPE) --disable-sandbox
@cp $(METALLIB_SRC) $(BUILD_DIR)/mlx.metallib
@echo "✓ Build complete"
bundle: build
@echo "=== Creating App Bundle ==="
@mkdir -p $(APP_BUNDLE)/Contents/MacOS
@mkdir -p $(APP_BUNDLE)/Contents/Resources
@cp $(BUILD_DIR)/$(PROJECT_NAME) $(APP_BUNDLE)/Contents/MacOS/$(PROJECT_NAME)
@chmod +x $(APP_BUNDLE)/Contents/MacOS/$(PROJECT_NAME)
@cp $(METALLIB_SRC) $(APP_BUNDLE)/Contents/MacOS/
@cp $(FFMPEG_BIN) $(APP_BUNDLE)/Contents/Resources/
@cp -R $(PROJECT_ROOT)/Sources/SubScript/Resources/*.lproj $(APP_BUNDLE)/Contents/Resources/ 2>/dev/null || true
@cp $(ICON_SET)/* $(APP_BUNDLE)/Contents/Resources/ 2>/dev/null || true
@codesign --force --deep --sign - $(APP_BUNDLE)
@mkdir -p $(APP_BUNDLE)/Contents/Resources/AppIcon.iconset
@cp $(APP_BUNDLE)/Contents/Resources/icon_*.png $(APP_BUNDLE)/Contents/Resources/AppIcon.iconset/ 2>/dev/null || true
@$(XCODEBUILD) -downloadComponent MetalToolchain 2>/dev/null || true
@iconutil -c icns $(APP_BUNDLE)/Contents/Resources/AppIcon.iconset -o $(APP_BUNDLE)/Contents/Resources/AppIcon.icns 2>/dev/null || true
@rm -rf $(APP_BUNDLE)/Contents/Resources/AppIcon.iconset $(APP_BUNDLE)/Contents/Resources/icon_*.png 2>/dev/null || true
@$(PROJECT_ROOT)/generate_plist.sh $(APP_BUNDLE)/Contents/Info.plist
@echo "✓ App bundle created: $(APP_BUNDLE)"
dmg: bundle
@echo "=== Creating DMG Image ==="
@rm -rf /tmp/SubScriptDMG
@mkdir -p /tmp/SubScriptDMG
@cp -R $(APP_BUNDLE) /tmp/SubScriptDMG/
@ln -s /Applications /tmp/SubScriptDMG/Applications
@$(Hdiutil) create -volname "$(PROJECT_NAME)" -srcfolder /tmp/SubScriptDMG -ov -format UDZO $(DMG_OUT)
@rm -rf /tmp/SubScriptDMG
@echo "✓ DMG created: $(DMG_OUT)"
clean:
@echo "=== Cleaning build artifacts ==="
@rm -rf .build
@rm -f $(DMG_OUT)
@echo "✓ Cleaned"