summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-07-26 16:41:51 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-07-26 17:29:45 +0800
commit3fc0bbf69d2839389c63b1d7af8b7e9064ad2e1b (patch)
treeef33af2d0a4c27f3c229c17656345495832e3447
downloadwordbook-3fc0bbf69d2839389c63b1d7af8b7e9064ad2e1b.tar.gz
Makefile to build with llama statically.
-rw-r--r--.gitignore3
-rw-r--r--Makefile83
-rw-r--r--main.c11
3 files changed, 97 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..43e4558
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+*.cgi
+deps/
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
+
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..e221a28
--- /dev/null
+++ b/main.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include "llama.h"
+
+int main(int argc , char *argv[])
+{
+ llama_backend_init();
+
+ llama_backend_free();
+
+ return 0;
+}