| 1 | # plugin_fetch - SCORPIOX BOT open-source URL fetch & HTML-to-Markdown MCP connector |
| 2 | # |
| 3 | # Zero runtime dependencies on every artefact. The only third-party C in the |
| 4 | # tree is vendored under vendor/: yyjson (MIT) and the mbedTLS 3.6.7 library |
| 5 | # (Apache-2.0) whose sources sit in vendor/mbedtlslib with their public |
| 6 | # headers flattened into vendor/mbedtls and vendor/psa. On _WIN32 the HTTP and |
| 7 | # TLS legs are WinHTTP instead, so the static PE needs no extra DLLs and no |
| 8 | # crypto objects are reached. |
| 9 | # |
| 10 | # The multi-arch dist publish lives in scorpiox-cli-botplugin (it owns the |
| 11 | # musl / aarch64 / MinGW / macOS toolchains, the dist upload and the plugingit |
| 12 | # mirror) - see release-dist.sh. That tool compiles every src/**/*.c and |
| 13 | # vendor/**/*.c with -I src and -I vendor, which is exactly what `make native` |
| 14 | # reproduces here. |
| 15 | # |
| 16 | # Targets: |
| 17 | # make native build -> ./plugin_fetch |
| 18 | # make musl static musl x86_64 -> ./plugin_fetch.musl |
| 19 | # make arm64 static arm64 musl -> ./plugin_fetch.arm64 |
| 20 | # make win64 MinGW-w64 static -> ./plugin_fetch.exe |
| 21 | # make macos Apple clang -> ./plugin_fetch (run this on macOS) |
| 22 | # make asan ASan + UBSan + leaks -> ./plugin_fetch-asan |
| 23 | # make fortify -D_FORTIFY_SOURCE=2 -> ./plugin_fetch-fortify |
| 24 | # make zlib native build with gzip support (-DHAVE_ZLIB -lz) |
| 25 | # make objs the cached mbedTLS object set (fast incremental dev builds) |
| 26 | # make ui regenerate src/ui_html.h from src/ui.html |
| 27 | # make test build + run tests/run.sh |
| 28 | # make e2e build + run tests/e2e.py (Playwright) |
| 29 | # make clean |
| 30 | |
| 31 | CC ?= cc |
| 32 | WARN := -Wall -Wextra -Wno-overlength-strings |
| 33 | STD := -std=c99 |
| 34 | INCLUDES := -I src -I vendor -I vendor/mbedtlslib |
| 35 | CFLAGS ?= -O2 $(STD) $(WARN) $(INCLUDES) |
| 36 | LDFLAGS ?= |
| 37 | MUSL_CC ?= musl-gcc |
| 38 | MUSL_CFLAGS := -O2 $(STD) $(WARN) $(INCLUDES) -static |
| 39 | ARM_CC ?= aarch64-linux-gnu-gcc |
| 40 | ARM_CFLAGS := -O2 $(STD) $(WARN) $(INCLUDES) -static |
| 41 | WIN_CC ?= x86_64-w64-mingw32-gcc |
| 42 | WIN_CFLAGS := -O2 $(STD) $(WARN) $(INCLUDES) -static |
| 43 | WIN_LIBS := -lwinhttp -lws2_32 -lbcrypt -lcrypt32 |
| 44 | |
| 45 | SRC_C := $(wildcard src/*.c) |
| 46 | VENDOR_C := $(wildcard vendor/*.c) $(wildcard vendor/mbedtlslib/*.c) |
| 47 | UI_SRC := src/ui.html |
| 48 | UI_HDR := src/ui_html.h |
| 49 | BIN := plugin_fetch |
| 50 | EXE := plugin_fetch.exe |
| 51 | OBJS := /tmp/fetch-objs |
| 52 | |
| 53 | .PHONY: all native musl arm64 win64 macos asan fortify zlib objs ui test e2e clean help |
| 54 | |
| 55 | all: native |
| 56 | |
| 57 | $(UI_HDR): $(UI_SRC) tools/gen_ui.py |
| 58 | @echo "==> regenerating $(UI_HDR)" |
| 59 | python3 tools/gen_ui.py |
| 60 | |
| 61 | ui: $(UI_HDR) |
| 62 | |
| 63 | native: $(BIN) |
| 64 | |
| 65 | $(BIN): $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 66 | @echo "==> native build ($(CC))" |
| 67 | $(CC) $(CFLAGS) -o $(BIN) $(SRC_C) $(VENDOR_C) $(LDFLAGS) |
| 68 | |
| 69 | # Static musl build - the universal Linux artefact (Alpine, Debian, Arch, Omarchy) |
| 70 | musl: $(BIN).musl |
| 71 | |
| 72 | $(BIN).musl: $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 73 | @echo "==> static musl build ($(MUSL_CC))" |
| 74 | $(MUSL_CC) $(MUSL_CFLAGS) -o $(BIN).musl $(SRC_C) $(VENDOR_C) |
| 75 | |
| 76 | # Static aarch64 build - Raspberry Pi 5 / ARM64 servers |
| 77 | arm64: $(BIN).arm64 |
| 78 | |
| 79 | $(BIN).arm64: $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 80 | @echo "==> static arm64 build ($(ARM_CC))" |
| 81 | $(ARM_CC) $(ARM_CFLAGS) -o $(BIN).arm64 $(SRC_C) $(VENDOR_C) |
| 82 | |
| 83 | # Native Win64 static PE - runs on any Windows 10/11 x64 node |
| 84 | win64: $(EXE) |
| 85 | |
| 86 | $(EXE): $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 87 | @echo "==> MinGW-w64 build ($(WIN_CC))" |
| 88 | $(WIN_CC) $(WIN_CFLAGS) -o $(EXE) $(SRC_C) $(VENDOR_C) $(WIN_LIBS) |
| 89 | |
| 90 | # Apple clang build (run this on macOS; the CLI does it over ssh otherwise) |
| 91 | macos: $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 92 | @echo "==> Apple clang build" |
| 93 | $(CC) $(CFLAGS) -o $(BIN) $(SRC_C) $(VENDOR_C) |
| 94 | |
| 95 | # Sanitizer build - tests/run.sh drives the whole surface through this binary |
| 96 | asan: $(BIN)-asan |
| 97 | |
| 98 | $(BIN)-asan: $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 99 | @echo "==> ASan + UBSan build" |
| 100 | $(CC) -O1 -g $(STD) $(WARN) $(INCLUDES) -fsanitize=address,undefined \ |
| 101 | -fno-omit-frame-pointer -o $(BIN)-asan $(SRC_C) $(VENDOR_C) |
| 102 | |
| 103 | fortify: $(BIN)-fortify |
| 104 | |
| 105 | $(BIN)-fortify: $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 106 | @echo "==> _FORTIFY_SOURCE=2 build" |
| 107 | $(CC) -O2 $(STD) $(WARN) $(INCLUDES) -D_FORTIFY_SOURCE=2 \ |
| 108 | -o $(BIN)-fortify $(SRC_C) $(VENDOR_C) |
| 109 | |
| 110 | # Optional gzip support. The published artefacts deliberately do NOT link it |
| 111 | # (a plugin must stay standalone); this target exists so the suite can prove |
| 112 | # the decoding path works when the library happens to be present. |
| 113 | zlib: $(SRC_C) $(UI_HDR) $(VENDOR_C) |
| 114 | @echo "==> native build with gzip support" |
| 115 | $(CC) $(CFLAGS) -DHAVE_ZLIB -o $(BIN)-zlib $(SRC_C) $(VENDOR_C) -lz |
| 116 | |
| 117 | # Cached mbedTLS objects for the fast development loop (dev-build.sh uses them). |
| 118 | objs: |
| 119 | @mkdir -p $(OBJS) |
| 120 | @ls $(VENDOR_C) | while read -r f; do \ |
| 121 | o=$(OBJS)/$$(basename "$${f%.c}").o; \ |
| 122 | if [ ! -f "$$o" ] || [ "$$f" -nt "$$o" ]; then \ |
| 123 | echo "$$f"; \ |
| 124 | fi; \ |
| 125 | done | xargs -P $$(nproc) -I{} sh -c \ |
| 126 | '$(CC) -O2 -w $(INCLUDES) -c "{}" -o $(OBJS)/$$(basename "{}" .c).o' |
| 127 | @echo "==> cached $(words $(VENDOR_C)) vendor objects in $(OBJS)" |
| 128 | |
| 129 | test: native |
| 130 | @sh tests/run.sh |
| 131 | |
| 132 | e2e: native |
| 133 | @python3 tests/e2e.py |
| 134 | |
| 135 | clean: |
| 136 | rm -f $(BIN) $(EXE) $(BIN).musl $(BIN).arm64 $(BIN)-asan $(BIN)-fortify \ |
| 137 | $(BIN)-zlib $(BIN).asan *.o |
| 138 | rm -rf bin tests/__pycache__ |
| 139 | |
| 140 | help: |
| 141 | @echo "make | make musl | make arm64 | make win64 | make macos | make asan |" |
| 142 | @echo "make fortify | make zlib | make objs | make ui | make test | make e2e | make clean" |