#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export CCACHE_DIR=$(CURDIR)/ccache

# 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 $@ --parallel --with autoreconf,systemd

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTS)

override_dh_auto_install:
	dh_installchangelogs ChangeLog
ifneq (,$(findstring bzflag-server, $(shell dh_listpackages)))
	misc/copyplugindocs debian/bzflag-server/usr/share/doc/bzflag-server/plugins/
	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
	# 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
