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

include /usr/share/dpkg/default.mk

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

PYVER=$(shell pyversions -vd)

configure_flags += \
			-DCMAKE_INSTALL_PREFIX="/usr" \
			-DCMAKE_INSTALL_LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
			-DPython_ADDITIONAL_VERSIONS=$(PYVER)

%:
	dh $@ --with python2

override_dh_auto_configure:
	dh_auto_configure -- 	$(configure_flags)

override_dh_auto_build:
	dh_auto_build
	doxygen doxygen.cfg

override_dh_install:
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/plist.so

	# Remove files generated by swig
	rm -f $(CURDIR)/debian/tmp/usr/include/plist/swig/plist.i
	rm -f $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/plist/plist.py
	rm -f $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/plist/__init__.py
	rm -f $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/plist/_plist.so

	dh_install --fail-missing

manpage_name = plistutil-$(DEB_VERSION_UPSTREAM).1

debian/$(manpage_name): debian/plistutil.1
	cp $< $@

override_dh_installman: debian/$(manpage_name)
	dh_installman

override_dh_link:
	dh_link -p libplist-utils /usr/share/man/man1/$(manpage_name).gz /usr/share/man/man1/plistutil.1.gz

override_dh_python2:
	# Only build for the current version of python, not all supported.
	dh_python2 --no-guessing-versions

override_dh_strip:
	dh_strip --dbg-package=libplist-dbg

override_dh_auto_clean:
	dh_auto_clean
	rm -Rf docs/
	rm -f test/data/*.out

#override_dh_auto_test:
#Make the test suit fatal on supported arches (See README.Debian)
#ifneq (,$(filter $(DEB_HOST_ARCH),amd64 i386 kfreebsd-amd64 kfreebsd-amd64))
#	dh_auto_test
#else
#	dh_auto_test || true
#endif
