#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export CCACHE_DIR=$(CURDIR)/ccache
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CONFIGURE_OPTS := --prefix=/usr --datarootdir=/usr/share/games

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CONFIGURE_OPTS += --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --enable-debug
endif

%:
	dh $@ --with systemd

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTS)

override_dh_auto_install:
	dh_installchangelogs ChangeLog
ifneq (,$(findstring bzflag-server, $(shell dh_listpackages)))
	dh_installinit -pbzflag-server --name=bzflag
endif
	dh_auto_install

override_dh_systemd_enable:
	dh_systemd_enable --name=bzflag

override_dh_install:
	# Fix #728167 and install bzfquery to /usr/games
	cp misc/bzfquery.pl misc/bzfquery
	dh_install -XMakefile
	# Remove the DejaVu.License file installed by the wildcard in
	# bzflag-data.install
	$(RM) debian/bzflag-data/usr/share/games/bzflag/fonts/DejaVu.License
	$(RM) misc/bzfquery

override_dh_fixperms:
	dh_fixperms
ifneq (,$(findstring bzflag-server, $(shell dh_listpackages)))
	chown -R games:games debian/bzflag-server/var/log/bzflag
endif

override_dh_clean:
	dh_clean
	$(RM) -r ccache

get-orig-source:
	uscan --verbose --download-current-version --force-download
