3030# Speed up builds by using all available CPU cores
3131MAKEFLAGS += -j$(CPUS )
3232
33+ # Mac Catalyst uses the Apple-native NSURLSession networking path. This needs to
34+ # be set before the common linker flags decide whether libcurl is required.
35+ ifeq ($(PLATFORM ) ,mac-catalyst)
36+ override NATIVE_NETWORK := ON
37+ endif
38+
3339# Compiler and flags
3440CC = gcc
3541CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR ) -I$(SRC_DIR ) /sqlite -I$(SRC_DIR ) /postgresql -I$(SRC_DIR ) /network -I$(SQLITE_DIR ) -I$(CURL_DIR ) /include -Imodules/fractional-indexing
@@ -150,6 +156,19 @@ else ifeq ($(PLATFORM),ios-sim)
150156 CFLAGS += -arch x86_64 -arch arm64 $(SDK)
151157 CURL_CONFIG = --host=arm64-apple-darwin --with-secure-transport CFLAGS="-arch x86_64 -arch arm64 -isysroot $$(xcrun --sdk iphonesimulator --show-sdk-path) -miphonesimulator-version-min=11.0"
152158 STRIP = strip -x -S $@
159+ else ifeq ($(PLATFORM),mac-catalyst)
160+ TARGET := $(DIST_DIR)/cloudsync.dylib
161+ MAC_CATALYST_DEPLOYMENT_TARGET ?= 14.0
162+ ifndef ARCH
163+ MAC_CATALYST_UNIVERSAL := true
164+ STRIP = strip -x -S $@
165+ else
166+ SDK := -isysroot $(shell xcrun --sdk macosx --show-sdk-path) -target $(ARCH)-apple-ios$(MAC_CATALYST_DEPLOYMENT_TARGET)-macabi
167+ LDFLAGS += -framework Security -framework CoreFoundation -dynamiclib $(SDK) -headerpad_max_install_names
168+ T_LDFLAGS = -framework Security
169+ CFLAGS += $(SDK)
170+ STRIP = strip -x -S $@
171+ endif
153172else # linux
154173 TARGET := $(DIST_DIR)/cloudsync.so
155174 LDFLAGS += -shared -lssl -lcrypto -lm
@@ -195,6 +214,20 @@ $(shell mkdir -p $(BUILD_DIRS) $(DIST_DIR))
195214extension : $(TARGET )
196215all : $(TARGET )
197216
217+ ifeq ($(MAC_CATALYST_UNIVERSAL ) ,true)
218+ MAC_CATALYST_ARCHS = x86_64 arm64
219+ MAC_CATALYST_DYLIBS = $(foreach arch,$(MAC_CATALYST_ARCHS ) ,$(DIST_DIR ) /cloudsync-mac-catalyst-$(arch ) .dylib)
220+
221+ $(TARGET ) :
222+ @for arch in $(MAC_CATALYST_ARCHS ) ; do \
223+ rm -rf $(BUILD_DIRS ) ; \
224+ $(MAKE ) PLATFORM=mac-catalyst ARCH=$$ arch MAC_CATALYST_DEPLOYMENT_TARGET=$(MAC_CATALYST_DEPLOYMENT_TARGET ) ; \
225+ mv $(DIST_DIR ) /cloudsync.dylib $(DIST_DIR ) /cloudsync-mac-catalyst-$$ arch.dylib; \
226+ done
227+ lipo -create $(MAC_CATALYST_DYLIBS ) -output $@
228+ rm -f $(MAC_CATALYST_DYLIBS )
229+ $(STRIP )
230+ else
198231# Loadable library
199232ifdef NATIVE_NETWORK
200233$(TARGET ) : $(RELEASE_OBJ ) $(DEF_FILE )
@@ -208,6 +241,7 @@ ifeq ($(PLATFORM),windows)
208241endif
209242 # Strip debug symbols
210243 $(STRIP)
244+ endif
211245
212246# Test executable
213247$(TEST_TARGET ) : $(TEST_OBJ )
@@ -404,10 +438,10 @@ framework module CloudSync {\
404438}
405439endef
406440
407- LIB_NAMES = ios.dylib ios-sim.dylib macos.dylib
408- FMWK_NAMES = ios-arm64 ios-arm64_x86_64-simulator macos-arm64_x86_64
441+ LIB_NAMES = ios.dylib ios-sim.dylib mac-catalyst.dylib macos.dylib
442+ FMWK_NAMES = ios-arm64 ios-arm64_x86_64-simulator ios-arm64_x86_64-maccatalyst macos-arm64_x86_64
409443$(DIST_DIR ) /% .xcframework : $(LIB_NAMES )
410- @$(foreach i,1 2,\
444+ @$(foreach i,1 2 3 ,\
411445 lib=$(word $(i ) ,$(LIB_NAMES ) ) ; \
412446 fmwk=$(word $(i ) ,$(FMWK_NAMES ) ) ; \
413447 mkdir -p $(DIST_DIR ) /$$ fmwk/CloudSync.framework/Headers; \
@@ -418,8 +452,8 @@ $(DIST_DIR)/%.xcframework: $(LIB_NAMES)
418452 mv $(DIST_DIR ) /$$ lib $(DIST_DIR ) /$$ fmwk/CloudSync.framework/CloudSync; \
419453 install_name_tool -id " @rpath/CloudSync.framework/CloudSync" $(DIST_DIR ) /$$ fmwk/CloudSync.framework/CloudSync; \
420454 )
421- @lib=$(word 3 ,$(LIB_NAMES ) ) ; \
422- fmwk=$(word 3 ,$(FMWK_NAMES ) ) ; \
455+ @lib=$(word 4 ,$(LIB_NAMES ) ) ; \
456+ fmwk=$(word 4 ,$(FMWK_NAMES ) ) ; \
423457 mkdir -p $(DIST_DIR ) /$$ fmwk/CloudSync.framework/Versions/A/Headers; \
424458 mkdir -p $(DIST_DIR ) /$$ fmwk/CloudSync.framework/Versions/A/Modules; \
425459 mkdir -p $(DIST_DIR ) /$$ fmwk/CloudSync.framework/Versions/A/Resources; \
@@ -473,6 +507,7 @@ help:
473507 @echo " android (needs ARCH to be set to x86_64, arm64-v8a, or armeabi-v7a and ANDROID_NDK to be set)"
474508 @echo " ios (only on macOS - can be compiled with native network support)"
475509 @echo " ios-sim (only on macOS - can be compiled with native network support)"
510+ @echo " mac-catalyst (only on macOS - builds a universal arm64 + x86_64 Catalyst dylib)"
476511 @echo " "
477512 @echo " Targets:"
478513 @echo " all - Build the extension (default)"
0 commit comments