@@ -45,44 +45,43 @@ ifeq ($(PLATFORM),windows)
4545 LDFLAGS += -shared
4646 # Create .def file for Windows
4747 DEF_FILE := $(BUILD_DIR)/vector.def
48+ STRIP = strip --strip-unneeded $@
4849else ifeq ($(PLATFORM),macos)
4950 TARGET := $(DIST_DIR)/vector.dylib
5051 LDFLAGS += -arch x86_64 -arch arm64 -dynamiclib -undefined dynamic_lookup
5152 CFLAGS += -arch x86_64 -arch arm64
53+ STRIP = strip -x -S $@
5254else ifeq ($(PLATFORM),android)
53- # Set ARCH to find Android NDK's Clang compiler, the user should set the ARCH
54- ifeq ($(filter %,$(ARCH)),)
55+ ifndef ARCH # Set ARCH to find Android NDK's Clang compiler, the user should set the ARCH
5556 $(error "Android ARCH must be set to ARCH=x86_64 or ARCH=arm64-v8a")
5657 endif
57- # Set ANDROID_NDK path to find android build tools
58- # e.g. on MacOS: export ANDROID_NDK=/Users/username/Library/Android/sdk/ndk/25.2.9519653
59- ifeq ($(filter %,$(ANDROID_NDK)),)
58+ ifndef ANDROID_NDK # Set ANDROID_NDK path to find android build tools; e.g. on MacOS: export ANDROID_NDK=/Users/username/Library/Android/sdk/ndk/25.2.9519653
6059 $(error "Android NDK must be set")
6160 endif
62-
6361 BIN = $(ANDROID_NDK)/toolchains/llvm/prebuilt/$(HOST)-x86_64/bin
64- PATH := $(BIN):$(PATH)
65-
6662 ifneq (,$(filter $(ARCH),arm64 arm64-v8a))
6763 override ARCH := aarch64
6864 endif
69-
7065 CC = $(BIN)/$(ARCH)-linux-android26-clang
7166 TARGET := $(DIST_DIR)/vector.so
7267 LDFLAGS += -lm -shared
68+ STRIP = $(BIN)/llvm-strip --strip-unneeded $@
7369else ifeq ($(PLATFORM),ios)
7470 TARGET := $(DIST_DIR)/vector.dylib
7571 SDK := -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=11.0
7672 LDFLAGS += -dynamiclib $(SDK)
7773 CFLAGS += -arch arm64 $(SDK)
78- else ifeq ($(PLATFORM),isim)
74+ STRIP = strip -x -S $@
75+ else ifeq ($(PLATFORM),ios-sim)
7976 TARGET := $(DIST_DIR)/vector.dylib
8077 SDK := -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) -miphonesimulator-version-min=11.0
8178 LDFLAGS += -arch x86_64 -arch arm64 -dynamiclib $(SDK)
8279 CFLAGS += -arch x86_64 -arch arm64 $(SDK)
80+ STRIP = strip -x -S $@
8381else # linux
8482 TARGET := $(DIST_DIR)/vector.so
8583 LDFLAGS += -shared
84+ STRIP = strip --strip-unneeded $@
8685endif
8786
8887# Windows .def file generation
@@ -107,6 +106,8 @@ ifeq ($(PLATFORM),windows)
107106 # Generate import library for Windows
108107 dlltool -D $@ -d $(DEF_FILE) -l $(DIST_DIR)/vector.lib
109108endif
109+ # Strip debug symbols
110+ $(STRIP)
110111
111112# Object files
112113$(BUILD_DIR ) /% .o : % .c
@@ -119,6 +120,67 @@ test: $(TARGET)
119120clean :
120121 rm -rf $(BUILD_DIR ) /* $(DIST_DIR ) /* * .gcda * .gcno * .gcov * .sqlite
121122
123+ .NOTPARALLEL : % .dylib
124+ % .dylib :
125+ rm -rf $(BUILD_DIR ) && $(MAKE ) PLATFORM=$*
126+ mv $(DIST_DIR ) /vector.dylib $(DIST_DIR ) /$@
127+
128+ define PLIST
129+ <?xml version=\"1.0\" encoding=\"UTF-8\"?>\
130+ <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\
131+ <plist version=\"1.0\">\
132+ <dict>\
133+ <key>CFBundleDevelopmentRegion</key>\
134+ <string>en</string>\
135+ <key>CFBundleExecutable</key>\
136+ <string>vector</string>\
137+ <key>CFBundleIdentifier</key>\
138+ <string>ai.sqlite.vector</string>\
139+ <key>CFBundleInfoDictionaryVersion</key>\
140+ <string>6.0</string>\
141+ <key>CFBundlePackageType</key>\
142+ <string>FMWK</string>\
143+ <key>CFBundleSignature</key>\
144+ <string>????</string>\
145+ <key>CFBundleVersion</key>\
146+ <string>$(shell make version) </string>\
147+ <key>CFBundleShortVersionString</key>\
148+ <string>$(shell make version) </string>\
149+ <key>MinimumOSVersion</key>\
150+ <string>11.0</string>\
151+ </dict>\
152+ </plist>
153+ endef
154+
155+ define MODULEMAP
156+ framework module vector {\
157+ umbrella header \"sqlite-vector.h\"\
158+ export *\
159+ }
160+ endef
161+
162+ LIB_NAMES = ios.dylib ios-sim.dylib macos.dylib
163+ FMWK_NAMES = ios-arm64 ios-arm64_x86_64-simulator macos-arm64_x86_64
164+ $(DIST_DIR ) /% .xcframework : $(LIB_NAMES )
165+ @$(foreach i,1 2 3,\
166+ lib=$(word $(i ) ,$(LIB_NAMES ) ) ; \
167+ fmwk=$(word $(i ) ,$(FMWK_NAMES ) ) ; \
168+ mkdir -p $(DIST_DIR ) /$$ fmwk/vector.framework/Headers; \
169+ mkdir -p $(DIST_DIR ) /$$ fmwk/vector.framework/Modules; \
170+ cp src/sqlite-vector.h $(DIST_DIR ) /$$ fmwk/vector.framework/Headers; \
171+ printf " $( PLIST) " > $(DIST_DIR ) /$$ fmwk/vector.framework/Info.plist; \
172+ printf " $( MODULEMAP) " > $(DIST_DIR ) /$$ fmwk/vector.framework/Modules/module.modulemap; \
173+ mv $(DIST_DIR ) /$$ lib $(DIST_DIR ) /$$ fmwk/vector.framework/vector; \
174+ install_name_tool -id " @rpath/vector.framework/vector" $(DIST_DIR ) /$$ fmwk/vector.framework/vector; \
175+ )
176+ xcodebuild -create-xcframework $(foreach fmwk,$(FMWK_NAMES ) ,-framework $(DIST_DIR ) /$(fmwk ) /vector.framework) -output $@
177+ rm -rf $(foreach fmwk,$(FMWK_NAMES ) ,$(DIST_DIR ) /$(fmwk ) )
178+
179+ xcframework : $(DIST_DIR ) /vector.xcframework
180+
181+ version :
182+ @echo $(shell sed -n 's/^#define SQLITE_VECTOR_VERSION[[:space:]]* "\([^"]* \) " .*/\1/p' src/sqlite-vector.h)
183+
122184# Help message
123185help :
124186 @echo " SQLite Vector Extension Makefile"
@@ -131,12 +193,13 @@ help:
131193 @echo " windows (default on Windows)"
132194 @echo " android (needs ARCH to be set to x86_64 or arm64-v8a and ANDROID_NDK to be set)"
133195 @echo " ios (only on macOS)"
134- @echo " isim (only on macOS)"
196+ @echo " ios-sim (only on macOS)"
135197 @echo " "
136198 @echo " Targets:"
137- @echo " all - Build the extension (default)"
138- @echo " clean - Remove built files"
139- @echo " test - Test the extension"
140- @echo " help - Display this help message"
199+ @echo " all - Build the extension (default)"
200+ @echo " clean - Remove built files"
201+ @echo " test - Test the extension"
202+ @echo " help - Display this help message"
203+ @echo " xcframework - Build the Apple XCFramework"
141204
142- .PHONY : all clean test extension help
205+ .PHONY : all clean test extension help version xcframework
0 commit comments