#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

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

%:
	dh $@ --sourcedirectory=src

override_dh_auto_clean:

override_dh_auto_build:
	dh_auto_build -- \
		CXXFLAGS="$(CXXFLAGS) $(CPPFLAGS) -ffast-math" \
		LDFLAGS="$(LDFLAGS) -Wl,--as-needed" \
		appnamefull="" \
		appversion="" \
		weapon-names="" \
		cube2font

override_dh_strip:
	dh_strip --dbgsym-migration='cube2font-dbg (<< 1.5.1-1~)'

override_dh_auto_install:
	make -C src/ system-install-cube2font DESTDIR=$(CURDIR)/debian/cube2font \
		appnamefull="" \
		appversion="" \
		weapon-names="" \
		prefix=/usr

DIR=cube2font-$(DEB_VERSION_UPSTREAM).orig
get-orig-source:
	uscan --noconf --rename --force-download --download-current-version --destdir=.
	rm -rf $(DIR)
	tar -xf cube2font_$(DEB_VERSION_UPSTREAM).orig.tar.gz
	rm -f cube2font_$(DEB_VERSION_UPSTREAM).orig.tar.gz
	mv base-$(DEB_VERSION_UPSTREAM) $(DIR)
	find $(DIR) -mindepth 1 -not -name src \
				-not -name shared \
				-not -name doc \
				-not -name man \
				-not -name cube2font.1 \
				-not -wholename $(DIR)/src/Makefile \
				-not -name system-install.mk \
				-not -name dist.mk \
				-not -name wiki.mk \
				-not -wholename $(DIR)/doc/license.txt \
				-not -name cube2font.c \
				-not -name redeclipse.cbp \
				-delete
	XZ="-6" tar --create --xz --owner root --group root --mode a+rX \
		-f cube2font_$(DEB_VERSION_UPSTREAM).orig.tar.xz $(DIR)
	rm -rf $(DIR)
