#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

%:
	dh $@ --buildsystem=cmake --builddir=build

override_dh_clean:
	-test -r debian/broken-symlinks.tar && tar -xf debian/broken-symlinks.tar
	dh_clean

override_dh_auto_configure:
	cp -rt auxil/highwayhash/ highwayhash/*
	cp -rt auxil/libkqueue/ libkqueue/*
	cp -rt auxil/rapidjson/ rapidjson/*
	find -L -type l | xargs -r tar -cvf debian/broken-symlinks.tar | xargs -r rm
	dh_auto_configure -- \
		-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) \
		-DBINARY_PACKAGING_MODE=true \
		-DBIFCL_EXE_PATH=/usr/bin/bifcl \
		-DBROKER_ROOT_DIR=1 \
		-DENABLE_PERFTOOLS=1

override_dh_missing:
	dh_missing --fail-missing

override_dh_install:
	mkdir -p debian/tmp/etc/zeek
	mv debian/tmp/usr/share/zeek/site debian/tmp/etc/zeek/site
	find debian/tmp -type f -name '*.zeek' -print0 | \
		xargs -0r sed -i -e 's@from $(CURDIR)/@from @g'
	dh_install -XCOPYING

override_dh_gencontrol:
	dh_gencontrol -- \
		-Vmisc:Built-Using="$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W binpac bifcl libparaglob-dev libtsl-ordered-map-dev nlohmann-json3-dev)"
