| 1 | # plugin_memory - SCORPIOX BOT open-source knowledge-graph memory connector |
| 2 | # |
| 3 | # Targets: |
| 4 | # make native build -> ./plugin_memory |
| 5 | # make musl static musl x86_64 -> ./plugin_memory.musl |
| 6 | # make arm64 static arm64 musl (aarch64 cross) -> ./plugin_memory.arm64 |
| 7 | # make win64 MinGW-w64 static -> ./plugin_memory.exe |
| 8 | # make macos Apple clang -> ./plugin_memory (run this on macOS) |
| 9 | # make ui regenerate src/ui_html.h from src/ui.html |
| 10 | # make asan ASan/UBSan + _FORTIFY_SOURCE=2 build -> ./plugin_memory.asan |
| 11 | # make test build + run tests/run.sh |
| 12 | # make e2e build + run tests/e2e.py (Playwright) |
| 13 | # make clean |
| 14 | # |
| 15 | # The binary is four translation units plus the vendored yyjson amalgamation: |
| 16 | # src/plugin_memory.c entry, --meta, the --mcp JSON-RPC loop |
| 17 | # src/graph.c JSONL storage, atomic save, the store, shared helpers |
| 18 | # src/tools.c the nine tools, shared by --mcp and the HTTP API |
| 19 | # src/api.c the CGI JSON actions and the HTML page |
| 20 | # vendor/yyjson.c vendored JSON parser/writer (zero runtime deps) |
| 21 | |
| 22 | CC ?= cc |
| 23 | SRCS := src/plugin_memory.c src/graph.c src/tools.c src/api.c vendor/yyjson.c |
| 24 | CFLAGS ?= -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings -I src -I vendor |
| 25 | MUSL_CC ?= musl-gcc |
| 26 | MUSL_CFLAGS := -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -I src -I vendor -static |
| 27 | ARM_CC ?= aarch64-linux-gnu-gcc |
| 28 | ARM_CFLAGS := -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -I src -I vendor -static |
| 29 | WIN_CC ?= x86_64-w64-mingw32-gcc |
| 30 | WIN_CFLAGS := -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -I src -I vendor -static |
| 31 | UI_SRC := src/ui.html |
| 32 | UI_HDR := src/ui_html.h |
| 33 | BIN := plugin_memory |
| 34 | EXE := plugin_memory.exe |
| 35 | |
| 36 | .PHONY: all native musl arm64 win64 macos ui asan test e2e clean help |
| 37 | |
| 38 | all: native |
| 39 | |
| 40 | $(UI_HDR): $(UI_SRC) tools/gen_ui.py |
| 41 | @echo "==> regenerating $(UI_HDR)" |
| 42 | python3 tools/gen_ui.py |
| 43 | |
| 44 | ui: $(UI_HDR) |
| 45 | |
| 46 | native: $(BIN) |
| 47 | |
| 48 | $(BIN): $(SRCS) $(UI_HDR) |
| 49 | @echo "==> native build ($(CC))" |
| 50 | $(CC) $(CFLAGS) -o $(BIN) $(SRCS) |
| 51 | |
| 52 | # Static musl build - the universal Linux artifact (Alpine, Debian, Arch, Omarchy) |
| 53 | musl: $(SRCS) $(UI_HDR) |
| 54 | @echo "==> static musl build ($(MUSL_CC))" |
| 55 | $(MUSL_CC) $(MUSL_CFLAGS) -o $(BIN).musl $(SRCS) |
| 56 | |
| 57 | # Static aarch64 build - Raspberry Pi 5 / ARM64 servers |
| 58 | arm64: $(SRCS) $(UI_HDR) |
| 59 | @echo "==> static arm64 build ($(ARM_CC))" |
| 60 | $(ARM_CC) $(ARM_CFLAGS) -o $(BIN).arm64 $(SRCS) |
| 61 | |
| 62 | # Native Win64 static PE - runs on any Windows 10/11 x64 node |
| 63 | win64: $(SRCS) $(UI_HDR) |
| 64 | @echo "==> MinGW-w64 build ($(WIN_CC))" |
| 65 | $(WIN_CC) $(WIN_CFLAGS) -o $(EXE) $(SRCS) |
| 66 | |
| 67 | # Apple clang build (run this on macOS) |
| 68 | macos: $(SRCS) $(UI_HDR) |
| 69 | @echo "==> Apple clang build" |
| 70 | $(CC) $(CFLAGS) -o $(BIN) $(SRCS) |
| 71 | |
| 72 | # Address/undefined sanitizers plus fortify. This is the build that finds the |
| 73 | # overlap, use-after-free and truncation bugs the -O2 suite cannot see, so it |
| 74 | # runs in tests/run.sh, not just by hand. |
| 75 | asan: $(SRCS) $(UI_HDR) |
| 76 | @echo "==> sanitizer build" |
| 77 | $(CC) -O1 -g -std=c99 -Wall -Wextra -I src -I vendor \ |
| 78 | -fsanitize=address,undefined -fno-omit-frame-pointer \ |
| 79 | -D_FORTIFY_SOURCE=2 -o $(BIN).asan $(SRCS) |
| 80 | |
| 81 | test: native |
| 82 | @sh tests/run.sh |
| 83 | |
| 84 | e2e: native |
| 85 | @python3 tests/e2e.py |
| 86 | |
| 87 | clean: |
| 88 | rm -f $(BIN) $(EXE) $(BIN).musl $(BIN).arm64 $(BIN).macos-arm64 \ |
| 89 | $(BIN).macos-x86_64 $(BIN).asan |
| 90 | rm -rf bin |
| 91 | |
| 92 | help: |
| 93 | @echo "make | make musl | make arm64 | make win64 | make macos | make ui | make asan | make test | make e2e | make clean" |