Files
apex-twin/Makefile
T
lotherk be4e833b91 apex-twin 0.12.0: sanitizer and analyzer pass
New build targets, no new features:

  make asan       apex-twin-asan with -fsanitize=address,undefined
  make test-asan  the whole suite against it (APEX_BIN override)
  make analyze    gcc -fanalyzer over every translation unit

Results: 239/239 checks pass against the ASan/UBSan binary with no report; a
batch of error paths, network captures, report generation and evidence/traffic
reads run with LeakSanitizer on: no leaks. make analyze is clean (0 warnings).

The analyzer was red first on vendor/libmcp/mcp.h: 'b->p = realloc(b->p, want)'
loses the only pointer to the old block when realloc fails. It now grows through
a temporary and assigns after the NULL check. That is a real robustness fix, not
a suppression.

.gitignore covers apex-twin-asan and build-asan/. README documents the targets
and the result.
2026-11-21 07:26:34 +00:00

61 lines
1.8 KiB
Makefile

CC ?= cc
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Wpedantic -Werror \
-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE
LIBDIR ?= vendor/libmcp
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DOCDIR ?= $(PREFIX)/share/doc/apex-twin
UNITDIR ?= $(PREFIX)/lib/systemd/system
SRC := $(wildcard src/*.c)
OBJ := $(SRC:.c=.o)
ASAN_BIN := apex-twin-asan
ASAN_OBJ := $(SRC:src/%.c=build-asan/%.o)
ASAN_FLAGS := -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer
all: apex-twin
apex-twin: $(OBJ)
$(CC) $(CFLAGS) -o $@ $(OBJ)
src/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h
$(CC) $(CFLAGS) -I$(LIBDIR) -Isrc -c -o $@ $<
test: apex-twin
./tests/run.sh
asan: $(ASAN_BIN)
test-asan: $(ASAN_BIN)
ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=halt_on_error=1 \
APEX_BIN=$(CURDIR)/$(ASAN_BIN) ./tests/run.sh
build-asan:
mkdir -p build-asan
build-asan/%.o: src/%.c src/apex.h $(LIBDIR)/mcp.h | build-asan
$(CC) $(CFLAGS) $(ASAN_FLAGS) -I$(LIBDIR) -Isrc -c -o $@ $<
$(ASAN_BIN): $(ASAN_OBJ)
$(CC) $(CFLAGS) $(ASAN_FLAGS) -o $@ $(ASAN_OBJ)
# Static analysis, one translation unit at a time. Warnings are expected to be
# read, not piped away; the target fails on a compiler error.
analyze:
@for f in $(SRC); do \
echo " ANALYZE $$f"; \
$(CC) $(CFLAGS) -fanalyzer -I$(LIBDIR) -Isrc -c -o /dev/null $$f || exit 1; \
done
install: apex-twin
mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(UNITDIR)
install -m 0755 apex-twin $(DESTDIR)$(BINDIR)/apex-twin
install -m 0644 README.md $(DESTDIR)$(DOCDIR)/README.md
install -m 0644 systemd/apex-twin.service $(DESTDIR)$(UNITDIR)/apex-twin.service
install -m 0644 systemd/apex-twin-proxy.service $(DESTDIR)$(UNITDIR)/apex-twin-proxy.service
clean:
rm -f apex-twin $(OBJ) $(ASAN_BIN)
rm -rf build-asan
.PHONY: all test asan test-asan analyze install clean