#!/usr/bin/make -f

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

configure_flags += \
		--prefix=/usr \
		--sysconfdir=/etc --host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--enable-dev-tools

%:
	dh --with python2 --with autoreconf $@

override_dh_auto_configure:
	dh_auto_configure -- 	$(configure_flags)

override_dh_install:
	#Remove .la files.
	rm -rf $(CURDIR)/debian/tmp/usr/lib/*.la
	rm -rf $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/imobiledevice/*.la
	#Remove .a files from python bindings.
	rm -rf $(CURDIR)/debian/tmp//usr/lib/python*/dist-packages/imobiledevice/*.a
	#Remove installed man pages, installed by *.manpages
	rm -f $(CURDIR)/debian/tmp/usr/share/man/man1/*.1
	dh_install --fail-missing

override_dh_strip:
	dh_strip --dbg-package=libimobiledevice2-dbg

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