
-include local_makefile.mk


# build and run locally #

build::
	cargo build

run_debug_8001::
	RUST_BACKTRACE=1 CONF=integ/rrdnsd.json LOCAL_NODE=127.0.0.1:8001 target/debug/rrdnsd

build_dev_deb::
	dpkg-buildpackage -us -uc -nc -b
	

# unit testing #

test::
	cargo test

test_with_coverage::
	# requires `cargo install tarpaulin`
	cargo tarpaulin --out Html --engine ptrace --skip-clean --verbose --bin rrdnsd --offline


# integration testing #

# WARNING: integ testing runs `tc` on local host!
# TODO: move to podman

target/debug/testhttpserver:
	cargo build --bin testhttpserver

test_integ::
	cargo test --test integration_test -- --nocapture --color always

integ_test_stop::
	-killall -qw rrdnsd
	-killall -qw knotd

integ_test_setup_net::
	sudo ./integ/setup_net.sh

integ_test_reset_net::
	-sudo tc qdisc del dev lo root

integ_test_run_knot_server::
	/usr/sbin/knotd --config integ/knot/knot.conf

integ_testn_run_knot_client::
	/usr/sbin/knotc --config integ/knot/knot.conf

integ_test_spawn_three_runners::
	./integ/spawn_three_runners.sh


# documentation #

generate_html_doc::
	# Requires asciidoctor
	asciidoctor -a rouge -a source-highlighter=rouge -a rouge-style=thankful_eyes  README.adoc
	mkdir -p html_output/docs
	-diff README.html html_output/index.html
	mv README.html html_output/index.html
	cp docs/*.svg html_output/docs/
	cp docs/*.png html_output/docs/

grep_statd_metrics_in_codebase::
	# Used to update documentation
	grep -oP '(?<=// statsd metric ).*' src/main.rs | sort
	
generate_codebase_doc::
	cargo doc --no-deps -v --bin rrdnsd

# containerized build for different OS version or architectures #

podman-build-bookworm::
	podman build -f Containerfile.bookworm -t rrdnsd:bookworm .
	podman run --rm --entrypoint cat localhost/rrdnsd:bookworm /app/rrdnsd > ./rrdnsd_bookworm

podman-build-bullseye::
	podman build -f Containerfile.bullseye -t rrdnsd:bullseye .
	podman run --rm --entrypoint cat localhost/rrdnsd:bullseye /app/rrdnsd > ./rrdnsd_bullseye

podman-build-aarch64::
	podman build -f Containerfile.aarch64 -t rrdnsd:aarch64 .
