scorpiox-bot-plugin-fetch
←Makefiletext
142 lines · 5 KBHEADBlameDownload
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
31CC ?= cc
32WARN := -Wall -Wextra -Wno-overlength-strings
33STD := -std=c99
34INCLUDES := -I src -I vendor -I vendor/mbedtlslib
35CFLAGS ?= -O2 $(STD) $(WARN) $(INCLUDES)
36LDFLAGS ?=
37MUSL_CC ?= musl-gcc
38MUSL_CFLAGS := -O2 $(STD) $(WARN) $(INCLUDES) -static
39ARM_CC ?= aarch64-linux-gnu-gcc
40ARM_CFLAGS := -O2 $(STD) $(WARN) $(INCLUDES) -static
41WIN_CC ?= x86_64-w64-mingw32-gcc
42WIN_CFLAGS := -O2 $(STD) $(WARN) $(INCLUDES) -static
43WIN_LIBS := -lwinhttp -lws2_32 -lbcrypt -lcrypt32
44
45SRC_C := $(wildcard src/*.c)
46VENDOR_C := $(wildcard vendor/*.c) $(wildcard vendor/mbedtlslib/*.c)
47UI_SRC := src/ui.html
48UI_HDR := src/ui_html.h
49BIN := plugin_fetch
50EXE := plugin_fetch.exe
51OBJS := /tmp/fetch-objs
52
53.PHONY: all native musl arm64 win64 macos asan fortify zlib objs ui test e2e clean help
54
55all: native
56
57$(UI_HDR): $(UI_SRC) tools/gen_ui.py
58 @echo "==> regenerating $(UI_HDR)"
59 python3 tools/gen_ui.py
60
61ui: $(UI_HDR)
62
63native: $(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)
70musl: $(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
77arm64: $(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
84win64: $(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)
91macos: $(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
96asan: $(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
103fortify: $(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.
113zlib: $(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).
118objs:
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
129test: native
130 @sh tests/run.sh
131
132e2e: native
133 @python3 tests/e2e.py
134
135clean:
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
140help:
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"