forked from scouzi1966/maclocal-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (122 loc) · 4.83 KB
/
Copy pathMakefile
File metadata and controls
142 lines (122 loc) · 4.83 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
# AFM - Apple Foundation Models API
# Makefile for building and distributing the portable CLI
.PHONY: build clean install uninstall portable dist test help submodules submodule-status webui build-with-webui patch patch-check
PATCH_SH := Scripts/apply-mlx-patches.sh
PATCH_STAMP := vendor/mlx-swift-lm/.patches-applied
# Default target
all: build
# Apply vendor patches (idempotent — stamp file tracks state)
$(PATCH_STAMP): $(PATCH_SH) $(wildcard Scripts/patches/*)
@echo "🩹 Applying vendor patches..."
@bash $(PATCH_SH)
@touch $(PATCH_STAMP)
patch: $(PATCH_STAMP)
patch-check:
@bash $(PATCH_SH) --check
# Build the release binary (portable by default)
build: $(PATCH_STAMP)
@echo "🔨 Building AFM..."
@swift build -c release \
--product afm \
-Xswiftc -O \
-Xswiftc -whole-module-optimization \
-Xswiftc -cross-module-optimization
@strip .build/release/afm
@echo "✅ Build complete: .build/release/afm"
@echo "📊 Size: $$(ls -lh .build/release/afm | awk '{print $$5}')"
# Build with enhanced portability optimizations
portable:
@./build-portable.sh
# Initialize git submodules (pinned to specific commit for reproducibility)
# NOTE: llama.cpp is pinned to a specific commit - do not use --remote flag
submodules:
@echo "📦 Initializing git submodules (pinned version)..."
@git submodule update --init
@echo "✅ Submodules initialized (llama.cpp @ $$(cd vendor/llama.cpp && git rev-parse --short HEAD))"
# Show pinned submodule versions
submodule-status:
@echo "📌 Pinned submodule versions:"
@git submodule status
# Build the webui from llama.cpp
webui: submodules
@echo "🌐 Building webui..."
@if [ ! -d "vendor/llama.cpp/tools/server/webui" ]; then \
echo "❌ Error: webui source not found. Run 'make submodules' first."; \
exit 1; \
fi
@cd vendor/llama.cpp/tools/server/webui && npm install && npm run build
@mkdir -p Resources/webui
@cp vendor/llama.cpp/tools/server/public/index.html.gz Resources/webui/
@echo "✅ WebUI built: Resources/webui/index.html.gz"
# Build with webui included
build-with-webui: webui build
@echo "✅ Build with webui complete"
# Clean build artifacts and revert vendor patches
clean:
@echo "🧹 Cleaning build artifacts..."
@if [ -f $(PATCH_STAMP) ]; then bash $(PATCH_SH) --revert; rm -f $(PATCH_STAMP); fi
@swift package clean
@rm -rf .build
@rm -f dist/*.tar.gz
@echo "✅ Clean complete"
# Install to system (requires sudo)
install: build
@echo "📦 Installing AFM to /usr/local/bin..."
@sudo cp .build/release/afm /usr/local/bin/afm
@sudo chmod +x /usr/local/bin/afm
@echo "✅ AFM installed to /usr/local/bin/afm"
# Uninstall from system
uninstall:
@echo "🗑️ Uninstalling AFM..."
@sudo rm -f /usr/local/bin/afm
@echo "✅ AFM uninstalled"
# Create distribution package
dist: portable
@./create-distribution.sh
# Test the binary
test: build
@echo "🧪 Testing AFM binary..."
@./.build/release/afm --help > /dev/null && echo "✅ Binary test passed" || echo "❌ Binary test failed"
@cp .build/release/afm /tmp/afm-test-$$$$ && \
/tmp/afm-test-$$$$ --version > /dev/null 2>&1 && \
echo "✅ Portability test passed" || echo "⚠️ Portability test failed"; \
rm -f /tmp/afm-test-$$$$
# Development build (debug)
debug: $(PATCH_STAMP)
@echo "🐛 Building debug version..."
@swift build
@echo "✅ Debug build complete: .build/debug/afm"
# Run the server (development)
run: debug
@echo "🚀 Starting AFM server..."
@./.build/debug/afm --port 9999
# Show help
help:
@echo "AFM - Apple Foundation Models API"
@echo "=================================="
@echo ""
@echo "Available targets:"
@echo " build - Build release binary (default, patches+portable)"
@echo " portable - Build with enhanced portability"
@echo " clean - Clean build artifacts and revert patches"
@echo " patch - Apply vendor patches only"
@echo " patch-check - Verify vendor patch status"
@echo " install - Install to /usr/local/bin (requires sudo)"
@echo " uninstall - Remove from /usr/local/bin"
@echo " dist - Create distribution package"
@echo " test - Test the binary and portability"
@echo " debug - Build debug version"
@echo " run - Build and run debug server"
@echo " submodules - Initialize git submodules"
@echo " webui - Build webui from llama.cpp (requires Node.js)"
@echo " build-with-webui - Build with webui included"
@echo " help - Show this help"
@echo ""
@echo "Examples:"
@echo " make build # Build portable executable"
@echo " make build-with-webui # Build with webui support"
@echo " make install # Build and install to system"
@echo " make dist # Create distribution package"
@echo " make test # Test binary works"
@echo ""
@echo "Output: .build/release/afm (portable executable)"