| 1 | # plugin_websearch - SCORPIOX BOT open-source multi-provider web search connector |
| 2 | # |
| 3 | # The only third-party C in the tree is vendored under vendor/: |
| 4 | # vendor/yyjson.c (MIT, ibireme) JSON parse/write |
| 5 | # vendor/bearssl/ (MIT, Thomas Pornin) TLS 1.2+ client |
| 6 | # |
| 7 | # The vendored TLS stack lives in vendor/bearssl (sources flattened, public |
| 8 | # headers beside them) because the SCORPIOX BOT release CLI compiles every .c |
| 9 | # under src/ + vendor/ with a fixed -I src -I vendor flag set. Nothing here |
| 10 | # needs libcurl, OpenSSL or a system CA file at runtime: the roots are compiled |
| 11 | # in (src/ca_roots_pem.h). |
| 12 | # |
| 13 | # Targets: |
| 14 | # make native build -> ./plugin_websearch |
| 15 | # make musl static musl x86_64 -> ./plugin_websearch.musl |
| 16 | # make arm64 static arm64 musl -> ./plugin_websearch.arm64 |
| 17 | # make win64 MinGW-w64 static -> ./plugin_websearch.exe |
| 18 | # make macos Apple clang -> ./plugin_websearch (run this on macOS) |
| 19 | # make asan ASan + UBSan + _FORTIFY_SOURCE=2 -> ./plugin_websearch-asan |
| 20 | # make ui regenerate src/ui_html.h from src/ui.html |
| 21 | # make test build + run tests/run.sh |
| 22 | # make e2e build + run tests/e2e.py (Playwright) |
| 23 | # make clean |
| 24 | |
| 25 | CC ?= cc |
| 26 | WARN := -Wall -Wextra -Wno-overlength-strings -Wno-unused-function |
| 27 | STD := -std=c99 |
| 28 | INCLUDES := -I src -I vendor |
| 29 | CFLAGS ?= -O2 $(STD) $(WARN) $(INCLUDES) |
| 30 | MUSL_CC ?= musl-gcc |
| 31 | ARM_CC ?= aarch64-linux-gnu-gcc |
| 32 | WIN_CC ?= x86_64-w64-mingw32-gcc |
| 33 | |
| 34 | SRC_C := $(wildcard src/*.c) |
| 35 | # Every header is a prerequisite too. Without them a one-line edit to |
| 36 | # src/ws.h (a version bump, a provider id, a buffer size) left `make` |
| 37 | # reporting "Nothing to be done" and the *previous* binary in place - the |
| 38 | # build says success and the artefact is stale, which is the failure mode |
| 39 | # this project keeps paying for. vendor/ headers are included because the |
| 40 | # TLS and JSON sources are compiled straight from that tree. |
| 41 | HDR := $(wildcard src/*.h) $(wildcard vendor/*.h) $(wildcard vendor/bearssl/*.h) |
| 42 | VENDOR_C := $(wildcard vendor/*.c) $(wildcard vendor/bearssl/*.c) |
| 43 | UI_SRC := src/ui.html |
| 44 | UI_HDR := src/ui_html.h |
| 45 | BIN := plugin_websearch |
| 46 | EXE := plugin_websearch.exe |
| 47 | WIN_LIBS := -lws2_32 |
| 48 | # macOS needs the Security framework only for the notarisation-free build; the |
| 49 | # TLS stack itself is self-contained, so no extra library is required there. |
| 50 | |
| 51 | .PHONY: all native musl arm64 win64 macos asan ui test e2e clean help install |
| 52 | |
| 53 | all: native |
| 54 | |
| 55 | $(UI_HDR): $(UI_SRC) tools/gen_ui.py |
| 56 | @echo "==> regenerating $(UI_HDR)" |
| 57 | python3 tools/gen_ui.py |
| 58 | |
| 59 | ui: $(UI_HDR) |
| 60 | |
| 61 | native: $(BIN) |
| 62 | |
| 63 | $(BIN): $(SRC_C) $(HDR) $(UI_HDR) $(VENDOR_C) |
| 64 | @echo "==> native build ($(CC))" |
| 65 | $(CC) $(CFLAGS) -o $(BIN) $(SRC_C) $(VENDOR_C) |
| 66 | |
| 67 | musl: $(BIN).musl |
| 68 | $(BIN).musl: $(SRC_C) $(HDR) $(UI_HDR) $(VENDOR_C) |
| 69 | @echo "==> static musl build ($(MUSL_CC))" |
| 70 | $(MUSL_CC) $(CFLAGS) -static -fno-strict-aliasing -o $@ $(SRC_C) $(VENDOR_C) |
| 71 | |
| 72 | arm64: $(BIN).arm64 |
| 73 | $(BIN).arm64: $(SRC_C) $(HDR) $(UI_HDR) $(VENDOR_C) |
| 74 | @echo "==> static arm64 build ($(ARM_CC))" |
| 75 | $(ARM_CC) $(CFLAGS) -static -fno-strict-aliasing -o $@ $(SRC_C) $(VENDOR_C) |
| 76 | |
| 77 | win64: $(EXE) |
| 78 | $(EXE): $(SRC_C) $(HDR) $(UI_HDR) $(VENDOR_C) |
| 79 | @echo "==> MinGW-w64 build ($(WIN_CC))" |
| 80 | $(WIN_CC) $(CFLAGS) -static -D_WIN32_WINNT=0x0601 -fno-strict-aliasing \ |
| 81 | -o $@ $(SRC_C) $(VENDOR_C) $(WIN_LIBS) |
| 82 | |
| 83 | macos: $(SRC_C) $(HDR) $(UI_HDR) $(VENDOR_C) |
| 84 | @echo "==> Apple clang build" |
| 85 | $(CC) $(CFLAGS) -fno-strict-aliasing -o $(BIN) $(SRC_C) $(VENDOR_C) |
| 86 | |
| 87 | asan: $(BIN)-asan |
| 88 | $(BIN)-asan: $(SRC_C) $(HDR) $(UI_HDR) $(VENDOR_C) |
| 89 | @echo "==> ASan + UBSan + FORTIFY build" |
| 90 | $(CC) -O1 -g $(STD) $(WARN) $(INCLUDES) -D_FORTIFY_SOURCE=2 \ |
| 91 | -fsanitize=address,undefined -fno-omit-frame-pointer \ |
| 92 | -o $@ $(SRC_C) $(VENDOR_C) |
| 93 | |
| 94 | install: $(BIN) |
| 95 | PDIR="/workspace/.scorpiox/plugins"; [ -d /workspace ] || PDIR="$$HOME/.scorpiox/plugins"; \ |
| 96 | mkdir -p "$$PDIR" && cp $(BIN) "$$PDIR/$(BIN)" && chmod 0755 "$$PDIR/$(BIN)" && \ |
| 97 | echo "installed $$PDIR/$(BIN) (no restart needed: the node rescans plugins per request)" |
| 98 | |
| 99 | test: $(BIN) |
| 100 | sh tests/run.sh |
| 101 | |
| 102 | e2e: $(BIN) |
| 103 | python3 tests/e2e.py |
| 104 | |
| 105 | clean: |
| 106 | rm -f $(BIN) $(BIN).musl $(BIN).arm64 $(EXE) $(BIN)-asan |
| 107 | |
| 108 | help: |
| 109 | @sed -n '1,30p' Makefile |