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

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

LDFLAGS += -Wl,--as-needed

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -O0
else
    CFLAGS += -O2
endif

PYVER=$(shell pyversions -vd)

configure_flags += \
			-DCMAKE_INSTALL_PREFIX="/usr" \
			-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:
	mv $(CURDIR)/debian/tmp/usr/bin/plutil-* \
		$(CURDIR)/debian/tmp/usr/bin/plutil

	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

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
