Add a daemon-only build path (no Python GUI) that builds the eBPF objects against the running kernel's headers, deriving the BPF DataLayout from clang and finalizing with opt; a structural unprivileged check target; an install path that never clobbers existing units/config/rules; an Arch PKGBUILD.in + prepare.sh and a test_install.sh harness. Document the workflow and the event-loss diagnostics in README.md and ebpf_prog/README. Gitignore the compiled ebpf_prog/*.o artifacts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
56 lines
2 KiB
Makefile
56 lines
2 KiB
Makefile
# Keep dependency resolution separate from normal builds.
|
|
SRC := $(shell find . -type f \( -name '*.go' -o -name '*.h' -o -name '*.c' \))
|
|
GO ?= go
|
|
PREFIX ?= /usr/local
|
|
SYSCONFDIR ?= /etc/opensnitchd
|
|
SYSTEMDUNITDIR ?= /etc/systemd/system
|
|
|
|
.PHONY: all install install-binary install-service install-config clean
|
|
|
|
all: opensnitchd
|
|
|
|
opensnitchd: $(SRC) go.mod go.sum Makefile
|
|
$(GO) build -mod=readonly -o opensnitchd .
|
|
|
|
# Safe for unprivileged package staging. Never reload/start/restart systemd.
|
|
install: install-binary install-service install-config
|
|
|
|
install-binary: opensnitchd
|
|
install -Dm755 opensnitchd "$(DESTDIR)$(PREFIX)/bin/opensnitchd"
|
|
|
|
# Preserve local unit overrides. A package can select /usr/lib/systemd/system
|
|
# with SYSTEMDUNITDIR; existing /etc overrides remain the operator's choice.
|
|
install-service:
|
|
@set -eu; \
|
|
dir="$(DESTDIR)$(SYSTEMDUNITDIR)"; \
|
|
install -d "$$dir"; \
|
|
if test ! -e "$$dir/opensnitchd.service" && test ! -L "$$dir/opensnitchd.service"; then \
|
|
sed 's|^ExecStart=/usr/local/bin/opensnitchd$$|ExecStart="$(PREFIX)/bin/opensnitchd"|' \
|
|
data/init/opensnitchd.service > "$$dir/opensnitchd.service"; \
|
|
chmod 644 "$$dir/opensnitchd.service"; \
|
|
fi
|
|
|
|
# Seed missing defaults only. Never reset existing firewall policy, rules,
|
|
# aliases or tasks, including existing symlinks. No implicit migration.
|
|
install-config:
|
|
@set -eu; \
|
|
dir="$(DESTDIR)$(SYSCONFDIR)"; \
|
|
install -d "$$dir/rules" "$$dir/tasks"; \
|
|
for name in default-config.json system-fw.json network_aliases.json; do \
|
|
if test ! -e "$$dir/$$name" && test ! -L "$$dir/$$name"; then \
|
|
install -m644 "data/$$name" "$$dir/$$name"; \
|
|
fi; \
|
|
done; \
|
|
for src in data/rules/*; do \
|
|
test -f "$$src" || continue; \
|
|
name=$${src##*/}; \
|
|
if test ! -e "$$dir/rules/$$name" && test ! -L "$$dir/rules/$$name"; then \
|
|
install -m600 "$$src" "$$dir/rules/$$name"; \
|
|
fi; \
|
|
done; \
|
|
if test ! -e "$$dir/tasks/tasks.json" && test ! -L "$$dir/tasks/tasks.json"; then \
|
|
install -m600 data/tasks/tasks.json "$$dir/tasks/tasks.json"; \
|
|
fi
|
|
|
|
clean:
|
|
rm -f opensnitchd
|