#!/usr/bin/make -f

export MAKE_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# FTBFS only on i386 when PIE hardening is used (#843979), so disable PIE there
CPU_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU)
ifeq (i386,$(CPU_ARCH))
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
endif

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_configure:
	cp debian/config.state sc2
	echo | (cd sc2 && ./build.sh uqm config)

override_dh_auto_build:
	cd sc2 && ./build.sh uqm

override_dh_auto_clean:
	cd sc2 && ./build.sh uqm clean
	rm -rf sc2/obj sc2/uqm
	dh_clean sc2/config.status build-stamp configure-stamp sc2/build.vars \
		sc2/build/unix/uqm sc2/uqm-wrapper

override_dh_auto_install:
	dh_installdirs usr/games usr/share/games
	cd sc2 && DESTDIR=${CURDIR}/debian/uqm ./build.sh uqm install
	install -m 0755 -d ${CURDIR}/debian/uqm/usr/share/pixmaps/
	install -m 0644 debian/uqm.xpm ${CURDIR}/debian/uqm/usr/share/pixmaps/
	install -m 0755 -d ${CURDIR}/debian/uqm/usr/share/applications/
	install -m 0644 debian/uqm.desktop \
		 ${CURDIR}/debian/uqm/usr/share/applications/

override_dh_installchangelogs:
	dh_installchangelogs sc2/ChangeLog

override_dh_installdocs:
	dh_installdocs sc2/AUTHORS sc2/README sc2/BUGS \
		sc2/WhatsNew sc2/Contributing

override_dh_installman:
	dh_installman debian/uqm.6

.PHONY: override_dh_auto_configure override_dh_auto_build override_dh_auto_clean override_dh_auto_install override_dh_installchangelogs override_dh_installdocs override_dh_installman
