#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk
export DEB_VERSION
VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/+ds//' -e 's/r/\./')

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

export LD_LIBRARY_PATH = .libs

include /usr/share/dpkg/architecture.mk

ifeq ($(DEB_HOST_ARCH),armhf)
	DEB_DH_AUTO_CONFIGURE_OPTS__ENABLE_TLS := --disable-tls
else
	DEB_DH_AUTO_CONFIGURE_OPTS__ENABLE_TLS := --enable-tls
endif

export DEB_CPPFLAGS_MAINT_APPEND = -I/usr/include/cliquer

default:
	@uscan --no-conf --dehs --report || true

%:
	dh $@

execute_before_dh_autoreconf:
	aclocal

override_dh_auto_configure-arch:
	dh_auto_configure --                              \
		--enable-clz                              \
		$(DEB_DH_AUTO_CONFIGURE_OPTS__ENABLE_TLS) \
		--disable-ansicontrols                    \
		--enable-generic                          \
		CC="$(CC) $(CPPFLAGS)"

override_dh_auto_configure-indep:
	@true

override_dh_auto_build-indep:
	@true

execute_before_dh_auto_test-arch:
	chmod +x runalltests

execute_after_dh_auto_test-arch:
	chmod -x runalltests

override_dh_auto_test-indep:
	@true

override_dh_auto_install-indep:
	@true

# rename gtools
execute_before_dh_install-arch:
	cd debian/tmp/usr/bin &&                        \
		for gtool in *;                         \
		do if test "$$gtool" != dreadnaut; then \
			mv "$$gtool" "nauty-$$gtool";   \
		fi;                                     \
		done

# the 128-bit integer libraries may or may not be built, so only
# install them if they are
execute_after_dh_install-arch:
	if [ -e debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libnautyQ.so ];  \
		then dh_install -plibnauty-dev usr/lib/*/libnautyQ.so;    \
	fi
	if [ -e debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libnautyQ1.so ]; \
		then dh_install -plibnauty-dev usr/lib/*/libnautyQ1.so;   \
	fi


override_dh_installdocs:
	dh_installdocs -plibnauty-dev --link-doc=libnauty-$(VERSION)
	dh_installdocs --remaining-packages

override_dh_installchangelogs:
	dh_installchangelogs --keep changes24-29.txt

execute_before_dh_installman-arch:
	mkdir -p debian/tmp/usr/share/man/man1
	cd debian/tmp/usr/bin &&                                           \
		for gtool in *;                                            \
		do help2man -N -o ../share/man/man1/$$gtool.1              \
			--version-string=$(VERSION) --no-discard-stderr    \
			-n "graph-processing utility from the nauty suite" \
			./$$gtool;                                         \
		done

override_dh_compress-indep:
	dh_compress -X.pdf -Xexamples
