# Foomuuri - Multizone bidirectional nftables firewall.

SUBDIRS	?= $(sort $(wildcard ??-*))
SOURCE	?= ../src/foomuuri ../src/tests/ ../prometheus/prometheus-foomuuri-exporter

.PHONY: all lint test clean distclean $(SUBDIRS)

ifdef COVERAGE
export RUN	= unshare --map-root-user --net coverage run --append --data-file=$(CURDIR)/../.coverage
else
export RUN	= python3
endif

all: lint test

lint:
	ruff check $(SOURCE)
	ruff format --diff $(SOURCE)
	ty check --ignore=unresolved-import --ignore=unused-ignore-comment $(SOURCE)
	pylint $(SOURCE)

test: $(SUBDIRS)
	cd ../ ; $(RUN) -m unittest

clean distclean:
	rm -f */*.fw
	rm -f */iplist-cache.json
	rm -f */zone

$(SUBDIRS):
	[ ! -f $@/Makefile ] || $(MAKE) -C $@
	$(RUN) ../src/foomuuri --set=etc_dir=$@ --set=share_dir=../etc --set=state_dir=$@ --set=run_dir=$@ check
	diff -u $@/golden.txt $@/next.fw
