#! /usr/bin/make -f

# for DEB_VERSION_UPSTREAM
include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

BUILDDIR=$(CURDIR)/build

%:
	dh $@ --builddirectory=$(BUILDDIR)

# override disabled by default rpath - we need to find libvcmi.so with it:
override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_SKIP_RPATH=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBIN_DIR=games

override_dh_strip:
	dh_strip --ddeb-migration='vcmi-dbg (<< 0.98+dfsg-3~)'

# we have to set HOME to a temporary directory when running vcmiserver because
#  - when running vcmiserver it wants to create $HOME/.config/vcmi,
#    $HOME/.cache/vcmi and $HOME/.local/share/vcmi/Saves
#  - sbuild uses the non-existing path /sbuild-nonexistent and the vcmiserver
#    invocation would fail because it cannot create it
#  - we don't want to touch the home directory of the user running dpkg-buildpackage
%.1: debian/%.1.in
	HOME=$(BUILDDIR) help2man --version-string=$(DEB_VERSION_UPSTREAM) --include=$< --output=$@ ./`basename $@ .1`

override_dh_installman: vcmiserver.1 vcmibuilder.1 vcmiclient.1
	dh_installman

override_dh_auto_install:
	dh_auto_install --destdir=debian/vcmi

override_dh_auto_build:
	dh_auto_build
	ln -s $(BUILDDIR)/server/vcmiserver ./vcmiserver
	ln -s $(BUILDDIR)/client/vcmiclient ./vcmiclient
	htlatex vcmimanual.tex

override_dh_auto_clean:
	dh_auto_clean
	rm -f ./vcmiclient ./vcmiserver
	rm -f vcmimanual.4ct vcmimanual.4tc vcmimanual.aux vcmimanual.css \
	vcmimanual.dvi vcmimanual.html vcmimanual.idv vcmimanual.lg \
	vcmimanual.log vcmimanual.tmp vcmimanual.xref

get-orig-source:
	uscan --noconf --verbose --rename --destdir=$(CURDIR) --check-dirname-level=0 --force-download --repack --compression=xz --download-current-version
