#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# nanopb headers are in /usr/include/nanopb, but generated msg.pb.h
# header includes <pb.h>
export DEB_CPPFLAGS_MAINT_APPEND = -I/usr/include/nanopb

%:
	dh $@

src/proto/msg.pb: src/proto/msg.proto
	cd src/proto && protoc -omsg.pb msg.proto

src/proto/msg.pb.c src/proto/msg.pb.h &: src/proto/msg.pb
	cd src/proto && nanopb_generator.py msg.pb

override_dh_auto_configure: src/proto/msg.pb.c src/proto/msg.pb.h
	dh_auto_configure -- \
		-DCDOGS_BIN_DIR=/usr/games \
		-DCDOGS_DATA_DIR=/usr/share/games/cdogs-sdl/ \
		-DUSE_SHARED_ENET=ON \
		-DDEBUG=ON \
		-DBUILD_EDITOR=OFF

execute_before_dh_installdocs:
	rm -r $(CURDIR)/debian/tmp/usr/doc

execute_before_dh_install:
	find $(CURDIR)/debian/tmp -type f '(' -iname "LICENSE.md" -o -iname "README.md" -o -name "*.sh" ')' -delete
	# delete txt files (containing only license/copyright information), except a few important ones
	find $(CURDIR)/debian/tmp -type f '(' -name "*.txt" -a '!' \
		'(' -name 'gamecontroller*db.txt' -o -name 'prefixes.txt' -o -name 'suffix*.txt' ')' ')' -delete

override_dh_gencontrol:
	dh_gencontrol -- -VBuilt-Using="$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W "libnanopb-dev")"

override_dh_strip:
	dh_strip -a --no-automatic-dbgsym
