Files
splinter/Makefile
T
lotherk 6debe213c3 ask: the wait for an answer is the operator's to set, and a late answer is refused
The 900 s wait was not the defect -- a person reads and thinks. Being hard
coded was: a run with no operator attached (an older protocol client that
does not know SP_EV_ASK, a script) lost the turn for fifteen minutes and
nobody could shorten it. Measured before the change: a client that ignores
the event saw the question and then no turn for 10 s.

sp_ask_wait_s() reads $SPLINTER_ASK_TIMEOUT, then ask_timeout from the
config, then SP_ASK_WAIT_S = 900. No upper bound: how long a turn may wait
is the operator's call. Consumers: engine_ask, tg_ask.

protocol.c also dropped sp_engine_answer's return value, so an answer that
arrived after the question was gone (wait expired, turn cancelled) looked
accepted. It now reports "no question is pending", as steer already did.

Test evidence:
- tests/test_ask_timeout.sh (new, wired into make check): with
  SPLINTER_ASK_TIMEOUT=3 the turn returns in 3 s with the "no answer"
  observation instead of parking. Proven red against the old code (env
  ignored: 5 FAILs, the client got no turn at all) and green on the fix.
- ask_timeout in the config file takes effect too: measured 3.1 s against a
  running --serve, so the docs line is not a claim.
- sp_ask_wait_s() edge cases: unset/0/-5/abc -> 900, 1 -> 1, 42 -> 42,
  999999999999 -> clamped.
- make check green (336 s), make check-asan and check-tsan clean (46
  binaries each).
2026-11-24 09:00:49 +00:00

466 lines
25 KiB
Makefile

# splinter -- POSIX make for our own code, GNU make only for the vendored curses.
#
# make libsplinter.so, the splinter binary, the example plugin
# make check builds and runs every test binary
# make curses builds the vendored NetBSD curses explicitly
# make clean removes generated files only
#
# The layout is deliberate: the backend lives in libsplinter.so (src/backend,
# the engine and everything it owns). The front ends are src/frontend/curses.c
# (the screen), src/frontend/protocol.c (the engine on a socket) and
# src/frontend/client.c (the reference client); src/main.c launches them.
# Every one of them links that single library, so there is exactly one copy of
# each symbol in the process. Two copies would mean two registries.
CC ?= cc
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Werror -D_POSIX_C_SOURCE=200809L \
-fPIC -Iinclude -Isrc/backend -Isrc/frontend -Ivendor/libmcp -Ivendor/netbsd-curses/libcurses
LDFLAGS ?=
LIBS ?= -lpthread
PREFIX ?= /usr/local
# Curses: the vendored NetBSD tree by default. A package build sets
# CURSES_LIB and CURSES_DEP instead and gets the base system's curses: the
# vendored tree needs host tools (nbperf, host_tic) that a cross build cannot
# run, and on NetBSD the base already has libcurses and libterminfo
# (ext/src/splinter/pkgsrc/Makefile). CURSES_LIB is what to link, CURSES_DEP
# the file that has to exist first -- empty means "nothing to build".
CURSES_DIR = vendor/netbsd-curses
CURSES_LIB ?= $(CURSES_DIR)/libcurses/libcurses.a \
$(CURSES_DIR)/libterminfo/libterminfo.a
CURSES_DEP ?= $(CURSES_LIB)
LIB = libsplinter.so
# Links name the library by file, never through a search path. A search path
# loses: a package build passes -L=/usr/pkg/lib ahead of anything this Makefile
# can append, so `-lsplinter` found the copy installed by the previous release
# instead of the one built a second ago (measured 2026-11-23:
# /usr/pkg/lib/libsplinter.so from 22.11. 22:26 made `splinter` fail with
# "undefined reference to sp_engine_sources", a function added to engine.c the
# same day). Naming the file is order-independent, and the SONAME the library
# carries (see the $(LIB) rule) is what the binary records as its dependency,
# so the installed program still looks for "libsplinter.so" and not for a
# build path.
SPLLIB = $(LIB)
LIBOBJ = src/backend/buf.o src/backend/tool.o src/backend/session.o src/backend/conv.o src/backend/compact.o src/backend/transport.o \
src/backend/json.o src/backend/sse.o src/backend/openai.o src/backend/transport_openai.o \
src/backend/anthropic.o src/backend/transport_anthropic.o src/backend/builtin.o \
src/backend/agent.o src/backend/theme.o src/backend/palettes.o src/backend/decomp.o src/backend/i18n.o src/backend/delegate.o src/backend/telegram.o src/backend/log.o src/backend/cmdscript.o src/backend/folder.o src/backend/interview.o src/backend/ack.o src/backend/mcpserver.o src/backend/mcpsession.o src/backend/skills.o src/backend/user.o src/backend/prompt.o src/backend/config.o src/backend/plugin.o src/backend/curl.o src/backend/swarm.o src/backend/provstate.o src/backend/md.o src/backend/tgmd.o src/backend/b64.o src/backend/a2aserver.o src/backend/providers.o src/backend/usage.o src/backend/confblock.o src/backend/embed.o src/backend/agents.o src/backend/foreignopen.o src/backend/engine.o src/backend/http.o src/backend/openai_server.o src/backend/catalogs.o
# buildinfo.o is separate: buildinfo.c is generated from the objects below.
LIBOBJ_ALL = $(LIBOBJ) src/backend/buildinfo.o
BIN = splinter
BINOBJ = src/main.o src/frontend/curses.o src/frontend/protocol.o \
src/frontend/ui_local.o src/frontend/ui_remote.o
CLIENT = splinterctl
CLIENTOBJ = src/frontend/client.o
PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
plugins/cli/cli.so plugins/focus/focus.so plugins/mcp/mcp.so \
plugins/ring/ring.so plugins/reminder/reminder.so \
plugins/kids/kids.so plugins/status/status.so plugins/processes/processes.so \
plugins/provider/provider.so \
plugins/scheduler/scheduler.so \
plugins/a2a/a2a.so \
plugins/junction/junction.so \
plugins/self/self.so \
plugins/cache/cache.so \
plugins/session/session.so \
plugins/foreign/foreign.so
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \
tests/test_transport tests/test_agent tests/test_openai \
tests/test_theme tests/test_plugin tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_anthropic tests/test_cli tests/test_compactor tests/test_corecompact tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_tgmd tests/test_providers tests/test_b64 tests/test_pause tests/test_swarm tests/test_provstate tests/test_usage tests/test_agents tests/test_confblock tests/test_jobs tests/test_engine tests/test_self tests/test_fuzz \
tests/test_sessiontools tests/test_embed tests/test_foreign \
tests/test_foreignopen tests/test_remote_list
RPATH = -Wl,-rpath,'$$ORIGIN'
PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..'
TEST_RPATH = -Wl,-rpath,'$$ORIGIN/..'
all: $(LIB) $(BIN) $(CLIENT) $(PLUGIN)
# The vendored tree ships a GNUmakefile; this is the only place that needs GNU
# make, and it is why the comment above says so out loud.
# Only when the vendored tree is what is wanted: CURSES_DEP names a file
# that already exists when the base system's curses is linked.
$(CURSES_LIB):
cd $(CURSES_DIR) && $(MAKE) -f GNUmakefile libcurses/libcurses.a \
libterminfo/libterminfo.a
curses: $(CURSES_LIB)
src/backend/catalogs.c: share/locale/de.msg share/locale/en.msg share/locale/pt_BR.msg tools/embed_catalogs.sh
sh tools/embed_catalogs.sh share/locale/*.msg > $@
# The build stamp --version prints. It is regenerated only when one of the
# objects it describes is newer, so a no-op make keeps the old stamp: the
# stamp says when this binary was actually built, not when make last ran.
# The revision is included because 0.1.0 does not tell two builds apart.
src/backend/buildinfo.c: $(LIBOBJ) $(BINOBJ)
@{ \
rev=`git rev-parse --short HEAD 2>/dev/null` || rev=unknown; \
if [ -n "`git status --porcelain --untracked-files=no 2>/dev/null | head -n 1`" ]; then \
rev="$$rev-dirty"; \
fi; \
printf '/* generated by make: the build stamp of this binary */\nconst char *sp_build_time = "%s";\nconst char *sp_build_rev = "%s";\n' \
"`date '+%Y-%m-%d %H:%M:%S %Z'`" "$$rev"; \
} > $@
$(LIB): $(LIBOBJ_ALL) $(CURSES_DEP)
$(CC) -shared -Wl,-soname,$(LIB) -o $@ $(LIBOBJ_ALL) $(CURSES_LIB) $(LIBS)
# curses belongs to the front end, not to the library: a plugin that drew into
# a WINDOW would be a plugin holding the UI thread's state.
# The reference client links the library for the JSON it cannot be bothered to
# write twice, but never the curses code and never the engine's internals.
$(CLIENT): $(CLIENTOBJ) $(LIB)
$(CC) $(CFLAGS) -o $@ $(CLIENTOBJ) $(SPLLIB) $(LDFLAGS) $(RPATH) \
$(LIBS)
$(BIN): $(BINOBJ) $(LIB) $(CURSES_DEP)
$(CC) $(CFLAGS) -o $@ $(BINOBJ) $(SPLLIB) $(LDFLAGS) $(RPATH) \
$(CURSES_LIB) $(LIBS)
plugins/clock/clock.so: plugins/clock/clock.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/clock/clock.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/lcm/lcm.so: plugins/lcm/lcm.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/lcm/lcm.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/session/session.so: plugins/session/session.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/session/session.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/foreign/foreign.so: plugins/foreign/foreign.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/foreign/foreign.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/cli/cli.so: plugins/cli/cli.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/cli/cli.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/ring/ring.so: plugins/ring/ring.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/ring/ring.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/kids/kids.so: plugins/kids/kids.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/kids/kids.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/processes/processes.so: plugins/processes/processes.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/processes/processes.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/status/status.so: plugins/status/status.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/status/status.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/reminder/reminder.so: plugins/reminder/reminder.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/reminder/reminder.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/mcp/mcp.so: plugins/mcp/mcp.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/mcp/mcp.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/focus/focus.so: plugins/focus/focus.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/focus/focus.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/cps/cps.so: plugins/cps/cps.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/cps/cps.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
# A cli delegate's child has to find plugins/cli/cli.so. Beside an installed
# binary there is no such file, so the build directory this binary came from is
# compiled in as the last resort (sp_delegate_cli_plugin in src/backend/delegate.c).
src/backend/delegate.o: src/backend/delegate.c
$(CC) $(CFLAGS) -DSPLINTER_PLUGIN_DIR='"$(CURDIR)"' -c -o $@ $<
# POSIX make has no automatic dependencies. Rather than a list that is wrong
# the day somebody adds an #include, every object depends on the headers that
# make up the interface: a change there rebuilds everything that could see it.
HDRS = include/splinter.h include/splinter_engine.h include/splinter_plugin.h \
src/backend/config.h src/backend/ack.h \
src/backend/curl.h src/backend/log.h src/backend/i18n.h src/backend/md.h src/backend/b64.h src/backend/a2aserver.h
$(LIBOBJ) $(BINOBJ): $(HDRS)
$(PLUGIN): $(HDRS)
#
# The tests too: a test that allocates a struct sp_reply by value and
# links a freshly built library is one header change away from reading
# the fields of a different layout. That failure looks like a broken
# test, not like a stale object, so it costs an hour every time.
$(TESTS): $(HDRS)
src/backend/agent.o: include/splinter.h
src/backend/buf.o: include/splinter.h
src/backend/tool.o: include/splinter.h
src/backend/session.o: include/splinter.h
src/backend/transport.o: include/splinter.h
src/backend/conv.o: include/splinter.h
src/backend/json.o: vendor/libmcp/mcp.h
src/backend/sse.o: include/splinter.h vendor/libmcp/mcp.h
src/backend/openai.o: include/splinter.h vendor/libmcp/mcp.h
src/backend/transport_openai.o: include/splinter.h src/backend/curl.h src/backend/log.h
src/backend/anthropic.o: include/splinter.h vendor/libmcp/mcp.h
src/backend/transport_anthropic.o: include/splinter.h src/backend/curl.h src/backend/log.h vendor/libmcp/mcp.h
src/backend/curl.o: src/backend/curl.h include/splinter.h
src/backend/builtin.o: include/splinter.h
src/backend/theme.o: src/backend/theme.h src/backend/palettes.h include/splinter.h
src/backend/palettes.o: src/backend/palettes.h
src/backend/decomp.o: src/backend/decomp.h
src/backend/i18n.o: src/backend/i18n.h include/splinter.h
src/backend/delegate.o: src/backend/config.h include/splinter.h
src/backend/telegram.o: include/splinter.h src/backend/curl.h src/backend/ack.h
src/backend/log.o: src/backend/log.h
src/backend/cmdscript.o: src/backend/cmdscript.h include/splinter.h
src/backend/folder.o: src/backend/folder.h include/splinter.h
src/backend/ack.o: src/backend/ack.h include/splinter.h
src/backend/interview.o: src/backend/interview.h include/splinter.h
src/backend/mcpserver.o: src/backend/mcpserver.h include/splinter.h
src/backend/skills.o: src/backend/skills.h src/backend/config.h include/splinter.h
src/backend/prompt.o: src/backend/prompt.h include/splinter.h
src/backend/config.o: src/backend/config.h include/splinter.h
src/backend/plugin.o: include/splinter.h include/splinter_plugin.h
src/frontend/curses.o: src/frontend/ui.h src/frontend/ui_backend.h \
include/splinter_engine.h src/backend/theme.h src/backend/decomp.h src/backend/i18n.h include/splinter.h include/splinter_plugin.h src/backend/md.h
src/backend/md.o: src/backend/md.h include/splinter.h
src/backend/b64.o: src/backend/b64.h include/splinter.h
src/backend/a2aserver.o: src/backend/a2aserver.h include/splinter.h vendor/libmcp/mcp.h
src/frontend/ui_local.o: src/frontend/ui_backend.h include/splinter_engine.h src/frontend/ui.h
src/frontend/ui_remote.o: src/frontend/ui_backend.h src/frontend/protocol.h include/splinter_engine.h vendor/libmcp/mcp.h
src/frontend/client.o: src/frontend/protocol.h include/splinter.h
src/frontend/protocol.o: src/frontend/protocol.h include/splinter_engine.h include/splinter.h src/backend/i18n.h
src/backend/http.o: src/backend/http.h include/splinter.h
src/backend/openai_server.o: src/backend/openai_server.h src/backend/http.h src/backend/config.h include/splinter.h vendor/libmcp/mcp.h
src/backend/engine.o: include/splinter_engine.h src/backend/config.h src/backend/providers.h src/backend/agents.h src/backend/swarm.h src/backend/cmdscript.h src/backend/i18n.h include/splinter_plugin.h
src/backend/providers.o: src/backend/providers.h src/backend/config.h include/splinter.h include/splinter_plugin.h
src/main.o: include/splinter.h include/splinter_engine.h \
src/frontend/ui_backend.h src/backend/config.h src/backend/i18n.h include/splinter_plugin.h src/frontend/ui.h src/backend/theme.h src/backend/a2aserver.h
tests/test_buf: tests/test_buf.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_buf.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_tool: tests/test_tool.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_tool.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_session: tests/test_session.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_session.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_transport: tests/test_transport.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_transport.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_agent: tests/test_agent.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_agent.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_conv: tests/test_conv.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_conv.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_openai: tests/test_openai.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_openai.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_theme: tests/test_theme.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_theme.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_focus: tests/test_focus.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_focus.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_skills: tests/test_skills.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_skills.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_telegram: tests/test_telegram.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_telegram.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_delegate: tests/test_delegate.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_delegate.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_builtin: tests/test_builtin.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_builtin.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_ack: tests/test_ack.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_ack.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_i18n: tests/test_i18n.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_i18n.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_ascii: tests/test_ascii.c $(LIB) $(BINOBJ) $(CURSES_DEP)
$(CC) $(CFLAGS) -o $@ tests/test_ascii.c src/frontend/curses.o $(SPLLIB) \
$(TEST_RPATH) $(CURSES_LIB) $(LIBS)
tests/test_md: tests/test_md.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_md.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_tgmd: tests/test_tgmd.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_tgmd.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_providers: tests/test_providers.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_providers.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_b64: tests/test_b64.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_b64.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_pause: tests/test_pause.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_pause.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_swarm: tests/test_swarm.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_swarm.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_provstate: tests/test_provstate.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_provstate.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_agents: tests/test_agents.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_agents.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_confblock: tests/test_confblock.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_confblock.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_engine: tests/test_engine.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_engine.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_junction: tests/test_junction.c $(LIB) plugins/junction/junction.so
$(CC) $(CFLAGS) -o $@ tests/test_junction.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_self: tests/test_self.c $(LIB) plugins/self/self.so
$(CC) $(CFLAGS) -o $@ tests/test_self.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_fuzz: tests/test_fuzz.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_fuzz.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_sessiontools: tests/test_sessiontools.c $(LIB) plugins/session/session.so plugins/foreign/foreign.so
$(CC) $(CFLAGS) -o $@ tests/test_sessiontools.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_foreign: tests/test_foreign.c $(LIB) plugins/foreign/foreign.so
$(CC) $(CFLAGS) -o $@ tests/test_foreign.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_foreignopen: tests/test_foreignopen.c $(LIB) plugins/foreign/foreign.so
$(CC) $(CFLAGS) -o $@ tests/test_foreignopen.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
# ui_remote.o is linked next to the library: the backend under test is front-end
# code (it speaks the protocol over a socket) and libsplinter has no ui_* in it.
tests/test_remote_list: tests/test_remote_list.c $(LIB) src/frontend/ui_remote.o \
src/frontend/protocol.o
$(CC) $(CFLAGS) -o $@ tests/test_remote_list.c src/frontend/ui_remote.o \
src/frontend/protocol.o $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_usage: tests/test_usage.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_usage.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_jobs: tests/test_jobs.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_jobs.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_config: tests/test_config.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_config.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_anthropic: tests/test_anthropic.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_anthropic.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_sse: tests/test_sse.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_sse.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_cli: tests/test_cli.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_cli.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_compactor: tests/test_compactor.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_compactor.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_corecompact: tests/test_corecompact.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_corecompact.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_secrets: tests/test_secrets.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_secrets.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_mcpclient: tests/test_mcpclient.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_mcpclient.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_kids: tests/test_kids.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_kids.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_embed: tests/test_embed.c $(LIB) $(HDRS)
$(CC) $(CFLAGS) -o $@ tests/test_embed.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/plugin_lifecycle.so: tests/plugin_lifecycle.c $(LIB) $(HDRS)
$(CC) $(CFLAGS) -shared -o $@ tests/plugin_lifecycle.c $(SPLLIB) \
$(TEST_RPATH) $(LIBS)
tests/test_lifecycle: tests/test_lifecycle.c $(LIB) tests/plugin_lifecycle.so
$(CC) $(CFLAGS) -o $@ tests/test_lifecycle.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_plugin.c $(SPLLIB) $(TEST_RPATH) $(LIBS)
# Every test runs under a 64 MB address-space limit: splinter is meant to
# be small, and a test that runs away (a retry loop appending to a buffer
# took 17 GB, 2026-11-18) must die at once instead of swapping the host.
TEST_MEM_KB ?= 65536
check: $(LIB) $(BIN) $(CLIENT) $(PLUGIN) $(TESTS) tests/test_junction
@set -e; python3 tools/check_i18n.py; \
ulimit -v $(TEST_MEM_KB); \
export LD_LIBRARY_PATH=.; \
SPLINTER_SESSION_DIR=$$(mktemp -d "$${TMPDIR:-/tmp}/splinter-check-XXXXXX"); \
export SPLINTER_SESSION_DIR; \
trap 'rm -rf "$$SPLINTER_SESSION_DIR"' EXIT; \
for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
echo "== tests/test_delegate_cli.sh"; sh tests/test_delegate_cli.sh; \
echo "== tests/test_args.sh"; sh tests/test_args.sh; \
echo "== tests/test_interview.sh"; sh tests/test_interview.sh; \
echo "== tests/test_gateway.sh"; sh tests/test_gateway.sh; \
echo "== tests/test_a2a.sh"; sh tests/test_a2a.sh; \
echo "== tests/test_a2a_ui.sh"; sh tests/test_a2a_ui.sh; \
echo "== tests/test_a2a_server.sh"; sh tests/test_a2a_server.sh; \
echo "== tests/test_a2a_context.sh"; sh tests/test_a2a_context.sh; \
echo "== tests/test_limit_wait.sh"; sh tests/test_limit_wait.sh; \
echo "== tests/test_pools.sh"; sh tests/test_pools.sh; \
echo "== tests/test_anthropic.sh"; sh tests/test_anthropic.sh; \
echo "== tests/test_agents_ui.sh"; sh tests/test_agents_ui.sh; \
echo "== tests/test_a2a_input.sh"; sh tests/test_a2a_input.sh; \
echo "== tests/test_swarm_socket.sh"; sh tests/test_swarm_socket.sh; \
echo "== tests/test_ui.sh"; sh tests/test_ui.sh; \
echo "== tests/test_ask_ui.sh"; sh tests/test_ask_ui.sh; \
echo "== tests/test_protocol.sh"; sh tests/test_protocol.sh; \
echo "== tests/test_attach.sh"; sh tests/test_attach.sh; \
echo "== tests/test_attach_busy.sh"; sh tests/test_attach_busy.sh; \
echo "== tests/test_gateway_openai.sh"; sh tests/test_gateway_openai.sh; \
echo "== tests/test_usage_request.sh"; sh tests/test_usage_request.sh; \
echo "== tests/test_compact_resume.sh"; sh tests/test_compact_resume.sh; \
echo "== tests/test_reconnect.sh"; sh tests/test_reconnect.sh; \
echo "== tests/test_junction.sh"; sh tests/test_junction.sh; \
echo "== tests/test_mcpsession.sh"; sh tests/test_mcpsession.sh; \
echo "== tests/test_ask_mcp.sh"; sh tests/test_ask_mcp.sh; \
echo "== tests/test_ask_timeout.sh"; sh tests/test_ask_timeout.sh; \
echo "all tests passed"
# The unit tests under ASAN/UBSAN with leak detection. Rebuilds the tree with
# sanitizers and back; run it when nothing else builds in this tree.
check-asan:
@sh tests/check_asan.sh
# The unit tests under ThreadSanitizer: the engine has a turn thread, a UI
# thread, widget threads and one thread per MCP server. Rebuilds the tree with
# -fsanitize=thread and back; run it when nothing else builds in this tree.
check-tsan:
@sh tests/check_tsan.sh
# the test binaries as a list, for check_asan.sh
print-tests:
@echo $(TESTS)
# The installed binary finds its own library through an rpath relative to itself
# ($ORIGIN), so 'make install PREFIX=$HOME/.local' produces a program that runs
# without a wrapper, without LD_LIBRARY_PATH and without an environment file.
# Install by rename, never in place. A running splinter has these files
# mapped: cp truncates the old inode and writes into pages the process is
# executing, which killed a gateway that was up while make install ran
# (SIGSEGV at a nonsense address). A rename swaps the directory entry and
# leaves the mapped inode alone.
install: all $(CURSES_DEP)
mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib \
$(DESTDIR)$(PREFIX)/lib/splinter/plugins
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../lib' \
-o $(DESTDIR)$(PREFIX)/bin/.splinter.new $(BINOBJ) $(SPLLIB) \
$(CURSES_LIB) $(LIBS)
mv -f $(DESTDIR)$(PREFIX)/bin/.splinter.new \
$(DESTDIR)$(PREFIX)/bin/splinter
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../lib' \
-o $(DESTDIR)$(PREFIX)/bin/.$(CLIENT).new $(CLIENTOBJ) $(SPLLIB) \
$(LIBS)
mv -f $(DESTDIR)$(PREFIX)/bin/.$(CLIENT).new \
$(DESTDIR)$(PREFIX)/bin/$(CLIENT)
cp $(LIB) $(DESTDIR)$(PREFIX)/lib/.$(LIB).new
mv -f $(DESTDIR)$(PREFIX)/lib/.$(LIB).new $(DESTDIR)$(PREFIX)/lib/$(LIB)
for p in $(PLUGIN); do \
cp "$$p" "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/.new.$$$$" && \
mv -f "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/.new.$$$$" \
"$(DESTDIR)$(PREFIX)/lib/splinter/plugins/$${p##*/}" || exit 1; \
done
@echo "installed $(DESTDIR)$(PREFIX)/bin/splinter"
clean:
rm -f src/backend/catalogs.c src/backend/buildinfo.c $(BIN) $(CLIENT) $(LIB) $(LIBOBJ_ALL) $(BINOBJ) \
$(CLIENTOBJ) $(PLUGIN) $(TESTS) tests/plugin_lifecycle.so \
tests/test_junction
.PHONY: all check curses install clean
plugins/provider/provider.so: plugins/provider/provider.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/provider/provider.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/scheduler/scheduler.so: plugins/scheduler/scheduler.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/scheduler/scheduler.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/a2a/a2a.so: plugins/a2a/a2a.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/a2a/a2a.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/junction/junction.so: plugins/junction/junction.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/junction/junction.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)
plugins/cache/cache.so: plugins/cache/cache.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/cache/cache.c $(SPLLIB) \
$(PLUGIN_LDFLAGS)
plugins/self/self.so: plugins/self/self.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/self/self.c $(SPLLIB) \
$(PLUGIN_RPATH) $(LIBS)