diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5fca7e1 --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +CC = cc +CXX = c++ +CFLAGS = -O2 -std=c11 -Wall -Wextra +CXXFLAGS = -O2 -Wall -Wextra +INCLUDES = -Ideps/include + +LLAMA_TAG = b10107 +LLAMA_URL = https://github.com/ggml-org/llama.cpp/archive/refs/tags/$(LLAMA_TAG).tar.gz +LLAMA_TAR = deps/llama-$(LLAMA_TAG).tar.gz +LLAMA_SRC_DIR = deps/llama.cpp-src +LLAMA_BUILD = $(LLAMA_SRC_DIR)/build + +STATIC_LIBS = deps/lib/libllama.a \ + deps/lib/libggml.a \ + deps/lib/libggml-cpu.a \ + +# System flags required for static linking llama on OpenBSD +SYS_LIBS = -static -pthread -lm -lc++ -lc++abi + +TARGET = wordbook.cgi +SRC = main.c +OBJS = main.o + +.PHONY: all clean distclean + +all: $(TARGET) + +# Explicit link order: libllama -> libggml-cpu -> libggml -> libggml-base +$(TARGET): deps/lib/libllama.a $(OBJS) + $(CXX) $(CXXFLAGS) $(OBJS) \ + -Wl,--start-group \ + deps/lib/libllama.a \ + deps/lib/libggml-cpu.a \ + deps/lib/libggml.a \ + deps/lib/libggml-base.a \ + -Wl,--end-group \ + $(SYS_LIBS) -o $@ + +# BSD suffix rule: compiles any .c file into .o +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + +# Download llama source and build statically +deps/lib/libllama.a deps/lib/libggml.a deps/lib/libggml-cpu.a: + @mkdir -p deps/lib deps/include + @echo "===> Downloading llama.cpp $(LLAMA_TAG) source..." + ftp -o $(LLAMA_TAR) $(LLAMA_URL) + + @echo "===> Extracting source archive..." + tar -xzf $(LLAMA_TAR) -C deps + rm -rf $(LLAMA_SRC_DIR) + mv deps/llama.cpp-$(LLAMA_TAG) $(LLAMA_SRC_DIR) + rm -f $(LLAMA_TAR) + + @echo "===> Compiling llama static archives..." + cmake -S $(LLAMA_SRC_DIR) -B $(LLAMA_BUILD) \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DGGML_OPENMP=OFF \ # Disable OpenMP; use native OpenBSD pthreads + -DGGML_VULKAN=OFF \ # Disable Vulkan GPU backend for CPU-only build + -DLLAMA_BUILD_APP=OFF \ + -DLLAMA_BUILD_COMMON=OFF \ + -DLLAMA_BUILD_TESTS=OFF \ + -DLLAMA_BUILD_EXAMPLES=OFF \ + -DLLAMA_BUILD_SERVER=OFF \ + -DLLAMA_BUILD_TOOLS=OFF + + cmake --build $(LLAMA_BUILD) --config Release -j$$(sysctl -n hw.ncpu) + + @echo "===> Installing .a files and headers into deps/..." + find $(LLAMA_BUILD) -type f -name "*.a" -exec cp {} deps/lib/ \; + cp -R $(LLAMA_SRC_DIR)/include/* deps/include/ + cp -R $(LLAMA_SRC_DIR)/ggml/include/* deps/include/ + + @echo "===> Cleaning up build directory..." + rm -rf $(LLAMA_SRC_DIR) + +clean: + rm -f $(TARGET) + +distclean: clean + rm -rf deps + |
