-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
275 lines (247 loc) · 8.98 KB
/
Makefile
File metadata and controls
275 lines (247 loc) · 8.98 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#
# Makefile
# sqlite-agent
#
# Created by Gioele Cantoni on 05/11/25.
#
# Makefile for SQLite Agent Extension
# Supports compilation for Linux, macOS, Windows, Android and iOS
# Customize sqlite3 executable with
# make test SQLITE3=/opt/homebrew/Cellar/sqlite/3.49.1/bin/sqlite3
SQLITE3 ?= sqlite3
# Set default platform if not specified
ifeq ($(OS),Windows_NT)
PLATFORM := windows
HOST := windows
CPUS := $(shell powershell -Command "[Environment]::ProcessorCount")
else
HOST = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ifeq ($(HOST),darwin)
PLATFORM := macos
CPUS := $(shell sysctl -n hw.ncpu)
else
PLATFORM := $(HOST)
CPUS := $(shell nproc)
endif
endif
# Speed up builds by using all available CPU cores
MAKEFLAGS += -j$(CPUS)
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(LIBS_DIR)
# Directories
SRC_DIR = src
DIST_DIR = dist
BUILD_DIR = build
LIBS_DIR = libs
VPATH = $(SRC_DIR)
# Files
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES = $(patsubst %.c, $(BUILD_DIR)/%.o, $(notdir $(SRC_FILES)))
# Platform-specific settings
ifeq ($(PLATFORM),windows)
TARGET := $(DIST_DIR)/agent.dll
LDFLAGS += -shared
DEF_FILE := $(BUILD_DIR)/agent.def
STRIP = strip --strip-unneeded $@
else ifeq ($(PLATFORM),macos)
TARGET := $(DIST_DIR)/agent.dylib
MACOS_MIN_VERSION = 11.0
ifndef ARCH
LDFLAGS += -arch x86_64 -arch arm64
CFLAGS += -arch x86_64 -arch arm64
else
LDFLAGS += -arch $(ARCH)
CFLAGS += -arch $(ARCH)
endif
LDFLAGS += -dynamiclib -undefined dynamic_lookup -headerpad_max_install_names -mmacosx-version-min=$(MACOS_MIN_VERSION)
CFLAGS += -mmacosx-version-min=$(MACOS_MIN_VERSION)
STRIP = strip -x -S $@
else ifeq ($(PLATFORM),android)
ifndef ARCH
$(error "Android ARCH must be set to ARCH=x86_64 or ARCH=arm64-v8a")
endif
ifndef ANDROID_NDK
$(error "Android NDK must be set")
endif
BIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/$(HOST)-x86_64/bin
PATH := $(BIN):$(PATH)
ifneq (,$(filter $(ARCH),arm64 arm64-v8a))
override ARCH := aarch64
ANDROID_ABI := android26
else ifeq ($(ARCH),armeabi-v7a)
override ARCH := armv7a
ANDROID_ABI := androideabi26
else
ANDROID_ABI := android26
endif
CC = $(BIN)/$(ARCH)-linux-$(ANDROID_ABI)-clang
TARGET := $(DIST_DIR)/agent.so
LDFLAGS += -shared -Wl,-z,max-page-size=16384
CFLAGS += -fPIC
STRIP = $(BIN)/llvm-strip --strip-unneeded $@
else ifeq ($(PLATFORM),ios)
TARGET := $(DIST_DIR)/agent.dylib
SDK := -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=11.0
LDFLAGS += -dynamiclib $(SDK) -headerpad_max_install_names
CFLAGS += -arch arm64 $(SDK)
STRIP = strip -x -S $@
else ifeq ($(PLATFORM),ios-sim)
TARGET := $(DIST_DIR)/agent.dylib
SDK := -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) -miphonesimulator-version-min=11.0
LDFLAGS += -arch x86_64 -arch arm64 -dynamiclib $(SDK) -headerpad_max_install_names
CFLAGS += -arch x86_64 -arch arm64 $(SDK)
STRIP = strip -x -S $@
else # linux
TARGET := $(DIST_DIR)/agent.so
LDFLAGS += -shared
CFLAGS += -fPIC
STRIP = strip --strip-unneeded $@
endif
# Windows .def file generation
$(DEF_FILE):
ifeq ($(PLATFORM),windows)
@echo "LIBRARY agent.dll" > $@
@echo "EXPORTS" >> $@
@echo " sqlite3_agent_init" >> $@
endif
$(shell mkdir -p $(BUILD_DIR) $(DIST_DIR))
all: extension
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -O3 -c $< -o $@
$(TARGET): $(OBJ_FILES) $(DEF_FILE)
$(CC) $(CFLAGS) $(SRC_DIR)/sqlite-agent.c $(LDFLAGS) -o $@
$(STRIP)
extension: $(TARGET)
test: extension
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./dist/agent" "SELECT agent_version();"
# Build and run Playwright MCP test
playwright: extension
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
-I$(LIBS_DIR) -c $(LIBS_DIR)/sqlite3.c -o $(BUILD_DIR)/sqlite3.o 2>/dev/null || true
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
-I$(LIBS_DIR) test/playwright.c $(BUILD_DIR)/sqlite3.o -o $(BUILD_DIR)/test-playwright
@echo "Note: Make sure Playwright MCP server is running on localhost:8931"
@echo " Start with: npx @playwright/mcp@latest --port 8931 --headless"
@echo ""
$(BUILD_DIR)/test-playwright
# Build and run Airbnb MCP test
airbnb: extension
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
-I$(LIBS_DIR) -c $(LIBS_DIR)/sqlite3.c -o $(BUILD_DIR)/sqlite3.o 2>/dev/null || true
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
-I$(LIBS_DIR) test/airbnb.c $(BUILD_DIR)/sqlite3.o -o $(BUILD_DIR)/test-airbnb
@echo "Note: Make sure Airbnb MCP server is running on localhost:8000/mcp"
@echo ""
$(BUILD_DIR)/test-airbnb
# Build and run GitHub MCP test
github: extension
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
-I$(LIBS_DIR) -c $(LIBS_DIR)/sqlite3.c -o $(BUILD_DIR)/sqlite3.o 2>/dev/null || true
$(CC) -Wall -Wextra -Wno-unused-parameter -O3 \
-I$(LIBS_DIR) test/github.c $(BUILD_DIR)/sqlite3.o -o $(BUILD_DIR)/test-github
@echo "Note: Set GITHUB_TOKEN environment variable with your GitHub Personal Access Token and make sure GitHub MCP server is running"
@echo " export GITHUB_TOKEN=\"ghp_your_token_here\""
@echo ""
$(BUILD_DIR)/test-github
clean:
rm -rf $(BUILD_DIR) $(DIST_DIR)
.NOTPARALLEL: %.dylib
%.dylib:
rm -rf $(BUILD_DIR) && $(MAKE) PLATFORM=$*
mv $(DIST_DIR)/agent.dylib $(DIST_DIR)/$@
define PLIST
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\
<plist version=\"1.0\">\
<dict>\
<key>CFBundleDevelopmentRegion</key>\
<string>en</string>\
<key>CFBundleExecutable</key>\
<string>agent</string>\
<key>CFBundleIdentifier</key>\
<string>ai.sqlite.agent</string>\
<key>CFBundleInfoDictionaryVersion</key>\
<string>6.0</string>\
<key>CFBundlePackageType</key>\
<string>FMWK</string>\
<key>CFBundleSignature</key>\
<string>????</string>\
<key>CFBundleVersion</key>\
<string>$(shell make version)</string>\
<key>CFBundleShortVersionString</key>\
<string>$(shell make version)</string>\
<key>MinimumOSVersion</key>\
<string>11.0</string>\
</dict>\
</plist>
endef
define MODULEMAP
framework module agent {\
umbrella header \"sqlite-agent.h\"\
export *\
}
endef
LIB_NAMES = ios.dylib ios-sim.dylib macos.dylib
FMWK_NAMES = ios-arm64 ios-arm64_x86_64-simulator macos-arm64_x86_64
$(DIST_DIR)/%.xcframework: $(LIB_NAMES)
@$(foreach i,1 2 3,\
lib=$(word $(i),$(LIB_NAMES)); \
fmwk=$(word $(i),$(FMWK_NAMES)); \
mkdir -p $(DIST_DIR)/$$fmwk/agent.framework/Headers; \
mkdir -p $(DIST_DIR)/$$fmwk/agent.framework/Modules; \
cp $(SRC_DIR)/sqlite-agent.h $(DIST_DIR)/$$fmwk/agent.framework/Headers; \
printf "$(PLIST)" > $(DIST_DIR)/$$fmwk/agent.framework/Info.plist; \
printf "$(MODULEMAP)" > $(DIST_DIR)/$$fmwk/agent.framework/Modules/module.modulemap; \
mv $(DIST_DIR)/$$lib $(DIST_DIR)/$$fmwk/agent.framework/agent; \
install_name_tool -id "@rpath/agent.framework/agent" $(DIST_DIR)/$$fmwk/agent.framework/agent; \
)
xcodebuild -create-xcframework $(foreach fmwk,$(FMWK_NAMES),-framework $(DIST_DIR)/$(fmwk)/agent.framework) -output $@
rm -rf $(foreach fmwk,$(FMWK_NAMES),$(DIST_DIR)/$(fmwk))
xcframework: $(DIST_DIR)/agent.xcframework
AAR_ARM64 = packages/android/src/main/jniLibs/arm64-v8a/
AAR_ARM = packages/android/src/main/jniLibs/armeabi-v7a/
AAR_X86 = packages/android/src/main/jniLibs/x86_64/
aar:
mkdir -p $(AAR_ARM64) $(AAR_ARM) $(AAR_X86)
$(MAKE) clean && $(MAKE) PLATFORM=android ARCH=arm64-v8a
mv $(DIST_DIR)/agent.so $(AAR_ARM64)
$(MAKE) clean && $(MAKE) PLATFORM=android ARCH=armeabi-v7a
mv $(DIST_DIR)/agent.so $(AAR_ARM)
$(MAKE) clean && $(MAKE) PLATFORM=android ARCH=x86_64
mv $(DIST_DIR)/agent.so $(AAR_X86)
cd packages/android && ./gradlew clean assembleRelease
cp packages/android/build/outputs/aar/android-release.aar $(DIST_DIR)/agent.aar
# Extract version from header
version:
@echo $(shell sed -n 's/^#define SQLITE_AGENT_VERSION[[:space:]]*"\([^"]*\)".*/\1/p' $(SRC_DIR)/sqlite-agent.h)
# Help target
help:
@echo "SQLite Agent Extension Makefile"
@echo ""
@echo "Usage: make [PLATFORM=platform] [ARCH=arch] [target]"
@echo ""
@echo "Targets:"
@echo " all - Build the extension (default)"
@echo " extension - Build the SQLite extension"
@echo " test - Run quick CLI test"
@echo " playwright - Build and run Playwright test"
@echo " airbnb - Build and run Airbnb test"
@echo " github - Build and run GitHub test"
@echo " clean - Remove all build artifacts"
@echo " version - Display extension version"
@echo " help - Display this help message"
@echo ""
@echo "Platforms:"
@echo " macos - macOS (default on Darwin)"
@echo " linux - Linux (default on Linux)"
@echo " windows - Windows (default on Windows)"
@echo " android - Android (requires ARCH and ANDROID_NDK)"
@echo " ios - iOS device"
@echo " ios-sim - iOS simulator"
@echo ""
@echo "Examples:"
@echo " make # Build for current platform"
@echo " make test # Build and test"
@echo " make PLATFORM=android ARCH=arm64-v8a # Build for Android ARM64"
.PHONY: all extension test playwright airbnb github clean version help