#!/usr/bin/make -f
#export DH_VERBOSE=1
include /usr/share/dpkg/architecture.mk
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
else
CROSS= --build $(DEB_BUILD_GNU_TYPE)
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# https://wiki.debian.org/CrossBuildPackagingGuidelines#pkg-config
-include /usr/share/dpkg/buildtools.mk
PKG_CONFIG ?= pkg-config

%:
	dh $@

override_dh_auto_configure:
	./configure $(CROSS) \
		--prefix=/usr \
		--bindir=\$${prefix}/games \
		--datarootdir=\$${prefix}/share \
		--datarootdir=\$${prefix}/share/games \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--disable-silent-rules \
		CXXFLAGS="$(CXXFLAGS) $$($(PKG_CONFIG) --cflags uuid)" \
		LIBS="$$($(PKG_CONFIG) --libs uuid)" \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)"

override_dh_auto_build:
	dh_auto_build
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	(cd doc/ && latexmk main.tex)
endif

override_dh_auto_install:
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
	rm -rfv debian/7kaa/usr/share/games/doc
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	install -D doc/main.pdf debian/7kaa-data/usr/share/doc/7kaa/manual.pdf
endif

override_dh_auto_clean:
	dh_auto_clean
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	(cd doc/ && latexmk -C main.tex)
endif
