A plugin is a .so against libsplinter.so, exporting sp_plugin_describe(). The layout changes so there is exactly one copy of each symbol in the process: all logic lives in libsplinter.so and both the binary and every plugin link against it. Two copies would have meant two registries. What the ABI offers: - tools with the authorization classes the loop already enforces, so the decision stays in the harness and not in the plugin; - widgets rendered in the sidebar, one line per widget (name: text); - a worker thread per widget with tick(), which may block, read files, wait on sockets - and which cannot touch curses at all; - sp_host_widget_text() as the only thread-safe write path: the host copies the string under a mutex, so a stack buffer is safe and the UI never holds a pointer a worker could free. Error paths are part of the design: a wrong ABI number is refused with both numbers in the message, a failed init is reported and skipped, a duplicate widget name is refused, a tool without a run function is not registered, and nothing is dlclose()d while a thread might be inside it. Layout: chat on three quarters, sidebar on one (session, transport, theme, last-turn numbers, widgets), status bar underneath. The clock example plugin proves the path end to end - its widget publishes 11:45:23 into the sidebar from its own thread. Seven test binaries green; test_plugin loads the real clock.so with dlopen and checks the worker actually published, plus every refusal above.
104 lines
3.9 KiB
Makefile
104 lines
3.9 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: all logic lives in libsplinter.so. The binary and
|
|
# every plugin link against that one 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 -Ivendor/netbsd-curses/libcurses
|
|
LDFLAGS ?=
|
|
LIBS ?= -lpthread
|
|
PREFIX ?= /usr/local
|
|
|
|
CURSES_DIR = vendor/netbsd-curses
|
|
CURSES_A = $(CURSES_DIR)/libcurses/libcurses.a \
|
|
$(CURSES_DIR)/libterminfo/libterminfo.a
|
|
|
|
LIB = libsplinter.so
|
|
LIBOBJ = src/buf.o src/tool.o src/session.o src/transport.o \
|
|
src/transport_curl.o src/builtin.o src/agent.o src/theme.o \
|
|
src/palettes.o src/plugin.o
|
|
BIN = splinter
|
|
BINOBJ = src/main.o src/ui.o
|
|
PLUGIN = plugins/clock/clock.so
|
|
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_transport \
|
|
tests/test_agent tests/test_theme tests/test_plugin
|
|
|
|
RPATH = -Wl,-rpath,'$$ORIGIN'
|
|
PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..'
|
|
TEST_RPATH = -Wl,-rpath,'$$ORIGIN/..'
|
|
|
|
all: $(LIB) $(BIN) $(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.
|
|
$(CURSES_A):
|
|
cd $(CURSES_DIR) && $(MAKE) -f GNUmakefile libcurses/libcurses.a \
|
|
libterminfo/libterminfo.a
|
|
|
|
curses: $(CURSES_A)
|
|
|
|
$(LIB): $(LIBOBJ) $(CURSES_A)
|
|
$(CC) -shared -o $@ $(LIBOBJ) $(CURSES_A) $(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.
|
|
$(BIN): $(BINOBJ) $(LIB)
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BINOBJ) -L. -lsplinter $(RPATH) \
|
|
$(CURSES_A) $(LIBS)
|
|
|
|
$(PLUGIN): plugins/clock/clock.c $(LIB)
|
|
$(CC) $(CFLAGS) -shared -o $@ plugins/clock/clock.c -L. -lsplinter \
|
|
$(PLUGIN_RPATH) $(LIBS)
|
|
|
|
.c.o:
|
|
$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
src/agent.o: include/splinter.h
|
|
src/buf.o: include/splinter.h
|
|
src/tool.o: include/splinter.h
|
|
src/session.o: include/splinter.h
|
|
src/transport.o: include/splinter.h
|
|
src/transport_curl.o: include/splinter.h
|
|
src/builtin.o: include/splinter.h
|
|
src/theme.o: src/theme.h src/palettes.h include/splinter.h
|
|
src/palettes.o: src/palettes.h
|
|
src/plugin.o: include/splinter.h include/splinter_plugin.h
|
|
src/ui.o: src/ui.h src/theme.h include/splinter.h include/splinter_plugin.h
|
|
src/main.o: include/splinter.h include/splinter_plugin.h src/ui.h src/theme.h
|
|
|
|
tests/test_buf: tests/test_buf.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_buf.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_tool: tests/test_tool.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_tool.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_session: tests/test_session.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_session.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_transport: tests/test_transport.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_transport.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_agent: tests/test_agent.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_agent.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_theme: tests/test_theme.c $(LIB)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_theme.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN)
|
|
$(CC) $(CFLAGS) -o $@ tests/test_plugin.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
|
|
|
|
check: $(LIB) $(BIN) $(PLUGIN) $(TESTS)
|
|
@set -e; for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
|
|
echo "all tests passed"
|
|
|
|
install: all
|
|
mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib
|
|
cp $(BIN) $(DESTDIR)$(PREFIX)/bin/
|
|
cp $(LIB) $(DESTDIR)$(PREFIX)/lib/
|
|
|
|
clean:
|
|
rm -f $(BIN) $(LIB) $(LIBOBJ) $(BINOBJ) $(PLUGIN) $(TESTS)
|
|
|
|
.PHONY: all check curses install clean
|