Skip to content

Commit c0c0e56

Browse files
author
Daniele Briggi
committed
fix(makefile): compile extension before modules
- add suggested flags for miniaudio
1 parent 7f76a2a commit c0c0e56

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Makefile

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ else ifeq ($(PLATFORM),android)
9797
WHISPER_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=$(ANDROID_NDK)/build/cmake/android.toolchain.cmake -DANDROID_ABI=$(if $(filter aarch64,$(ARCH)),arm64-v8a,$(ARCH)) -DANDROID_PLATFORM=android-26 -DCMAKE_C_FLAGS="-march=$(if $(filter aarch64,$(ARCH)),armv8.7a,x86-64)" -DCMAKE_CXX_FLAGS="-march=$(if $(filter aarch64,$(ARCH)),armv8.7a,x86-64)" -DGGML_OPENMP=OFF -DGGML_LLAMAFILE=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON
9898
STRIP = $(BIN)/llvm-strip --strip-unneeded $@
9999
else ifeq ($(PLATFORM),ios)
100+
CC = clang
101+
CXX = clang++
100102
TARGET := $(DIST_DIR)/ai.dylib
101103
SDK := -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=14.0
102104
LLAMA_LIBS += $(BUILD_LLAMA)/ggml/src/ggml-metal/libggml-metal.a $(BUILD_LLAMA)/ggml/src/ggml-blas/libggml-blas.a
103-
LDFLAGS += -L./$(BUILD_LLAMA)/ggml/src/ggml-metal -lggml-metal -L./$(BUILD_LLAMA)/ggml/src/ggml-blas -lggml-blas -framework Accelerate -framework Metal -framework Foundation -framework CoreML -dynamiclib $(SDK)
104-
CFLAGS += -arch arm64 $(SDK)
105+
# miniaudio requires -ldl for dlopen() and compile as Objective-C on iOS
106+
# https://github.com/mackron/miniaudio/blob/master/README.md#building
107+
LDFLAGS += -L./$(BUILD_LLAMA)/ggml/src/ggml-metal -lggml-metal -L./$(BUILD_LLAMA)/ggml/src/ggml-blas -lggml-blas -framework Accelerate -framework Metal -framework Foundation -framework CoreML -dynamiclib -ldl $(SDK)
108+
CFLAGS += -arch arm64 -x objective-c $(SDK)
105109
LLAMA_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0
106110
WHISPER_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 -DWHISPER_COREML=ON
107111
STRIP = strip -x -S $@
@@ -140,8 +144,11 @@ $(shell mkdir -p $(BUILD_DIR) $(DIST_DIR))
140144
extension: $(TARGET)
141145
all: $(TARGET)
142146

147+
# Ensure object files are built first
148+
compile: $(OBJ_FILES)
149+
143150
# Loadable library
144-
$(TARGET): $(OBJ_FILES) $(DEF_FILE) $(LLAMA_LIBS) $(WHISPER_LIBS) $(MINIAUDIO_LIBS)
151+
$(TARGET): compile $(DEF_FILE) $(LLAMA_LIBS) $(WHISPER_LIBS) $(MINIAUDIO_LIBS)
145152
$(CXX) $(OBJ_FILES) $(DEF_FILE) -o $@ $(LDFLAGS)
146153
ifeq ($(PLATFORM),windows)
147154
# Generate import library for Windows
@@ -157,18 +164,18 @@ $(BUILD_DIR)/%.o: %.c
157164
test: $(TARGET)
158165
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./dist/ai" "SELECT ai_version();"
159166

160-
# Build submodules
161-
build/llama.cpp.stamp:
167+
# Build submodules (only after successful compilation)
168+
build/llama.cpp.stamp: compile
162169
cmake -B $(BUILD_LLAMA) $(LLAMA_OPTIONS) $(LLAMA_DIR)
163170
cmake --build $(BUILD_LLAMA) --config Release -- -j$(CPUS)
164171
touch $@
165172

166-
build/whisper.cpp.stamp:
173+
build/whisper.cpp.stamp: compile
167174
cmake -B $(BUILD_WHISPER) $(WHISPER_OPTIONS) $(WHISPER_DIR)
168175
cmake --build $(BUILD_WHISPER) --config Release -- -j$(CPUS)
169176
touch $@
170177

171-
build/miniaudio.stamp:
178+
build/miniaudio.stamp: compile
172179
cmake -B $(BUILD_MINIAUDIO) -DMINIAUDIO_BUILD_EXAMPLES=OFF -DMINIAUDIO_BUILD_TESTS=OFF $(MINIAUDIO_DIR)
173180
cmake --build $(BUILD_MINIAUDIO) --config Release -- -j$(CPUS)
174181
touch $@
@@ -205,4 +212,4 @@ help:
205212
@echo " test - Test the extension"
206213
@echo " help - Display this help message"
207214

208-
.PHONY: all clean test extension help
215+
.PHONY: all clean test extension help compile

0 commit comments

Comments
 (0)