#!/usr/bin/make -f
#export DH_VERBOSE=1

%:
	dh $@ --with autoreconf

DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -g
else
	CXXFLAGS += -g -O2 -fomit-frame-pointer
endif
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif

override_dh_auto_build:
	convert debian/sauerbraten.png debian/sauerbraten.xpm
	$(MAKE) CXXFLAGS="$(CXXFLAGS)"

override_dh_auto_clean:
	# Because newer arches will FTBFS because of outdated config.* infrastructure,
	# we need to copy them in for the upstream distclean target.
	# Ugh, and we need a hack for building the source package, too!
	dh_autotools-dev_updateconfig
	$(MAKE) clean
	rm -f debian/sauerbraten.xpm
	dh_autotools-dev_restoreconfig

override_dh_auto_install:
	# This override target must not be removed (even it empty!) to stop dh
	# from trying upstream's broken install target.
	# Uhm... yes, it's a hack to strip \.dfsg.* from the version string...
	# Improvements appreciated! It's used by dh_gencontrol
	echo "sauerbraten-data-ver=`head -n1 debian/changelog | egrep -o '\(.*\)' | sed -e 's/(//' | sed -e 's/\.dfsg.*//'`" \
		>> debian/sauerbraten.substvars

override_dh_strip:
	dh_strip -psauerbraten --dbg-package=sauerbraten-dbg
	dh_strip

override_dh_installdocs:
	dh_installdocs --all debian/README.Debian
	dh_installdocs -psauerbraten debian/NEWS.Debian
