1MAKEFLAGS += -j4
2MEX_ASSURE="cc docker wget xxd"
3
4include makext.mk
5
6LLAMA_DIR = llama.cpp
7
8CFLAGS = -Wall -Wextra -O3 -I$(LLAMA_DIR)/include -I$(LLAMA_DIR)/ggml/include
9LDFLAGS = -L$(LLAMA_DIR)/build/src -L$(LLAMA_DIR)/build/ggml/src \
10 -lpthread -lm -ldl -lstdc++ -g \
11 -lllama -lggml -lggml-cpu -lggml-base
12
13PROMPT_TXT := $(wildcard prompts/*.txt)
14PROMPT_HEADERS := $(PROMPT_TXT:.txt=.h)
15
16MAP_TXT := $(wildcard maps/*.txt)
17MAP_HEADERS := $(MAP_TXT:.txt=.h)
18
19CORPUS_TXT := $(wildcard corpus/*.txt)
20CORPUS_VDB := $(CORPUS_TXT:.txt=.vdb)
21
22help: .help
23
24build/llama.cpp: .assure # Build llama.cpp libraries
25 mkdir $(LLAMA_DIR)/build && \
26 cd $(LLAMA_DIR)/build && \
27 cmake ../ -DBUILD_SHARED_LIBS=OFF && \
28 make -j8
29
30build/context: context.c vectordb.c models.h # Build context binary for testing
31 $(CC) $(CFLAGS) context.c vectordb.c -o context $(LDFLAGS)
32
33build/npc: build/prompts npc.c vectordb.c models.h # Build npc binary for testing
34 $(CC) $(CFLAGS) npc.c vectordb.c -o npc $(LDFLAGS)
35
36build/game: build/prompts build/maps game.c vectordb.c models.h # Build npc binary for testing
37 $(CC) $(CFLAGS) game.c vectordb.c -o game $(LDFLAGS)
38
39build/prompts: $(PROMPT_HEADERS) # Generate prompts in C style header
40
41build/maps: $(MAP_HEADERS) # Generate maps in C style header
42
43build/corpus: $(CORPUS_VDB) # Build vector DBs for all corpuses
44
45run/fetch-models: .assure # Fetch GGUF models
46 -mkdir -p models
47 cd models && wget -nc -i ../models.txt
48
49run/docker: .assure # Runs npc in Docker container
50 docker build -t npcd .
51 docker run -it npcd
52
53run/clean: # Cleans up all the build artefacts
54 -rm -f npc
55 cd $(LLAMA_DIR)/build && make clean
56 -rm -Rf $(LLAMA_DIR)/build
57
58prompts/%.h: prompts/%.txt .assure
59 xxd -i $< > $@
60
61maps/%.h: maps/%.txt .assure
62 xxd -i $< > $@
63
64corpus/%.vdb: corpus/%.txt build/context
65 ./context -m qwen3 -i $< -o $@