#!/usr/bin/make -f

PY3VERS = $(shell py3versions -v -r debian/control)

%:
	dh $@ --with python3

override_dh_auto_build:
	$(MAKE) CFLAGS="$(CPPFLAGS) $(CFLAGS)"
	cd py-smbus && for v in $(PY3VERS) ; do \
		CFLAGS="$(CPPFLAGS) $(CFLAGS) -I../include" python$$v setup.py build ; \
	done

override_dh_auto_install:
	$(MAKE) install PREFIX=/usr DESTDIR=$(CURDIR)/debian/tmp prefix=/usr libdir=/usr/lib/$(DEB_HOST_MULTIARCH)
	cd py-smbus && for v in $(PY3VERS) ; do \
		CFLAGS="$(CPPFLAGS) $(CFLAGS) -I../include" python$$v setup.py install --install-layout=deb --root=$(CURDIR)/debian/tmp ; \
	done

override_dh_auto_clean:
	rm -rf py-smbus/build
	dh_auto_clean

override_dh_perl:
	# Perl scripts in "ic2-tools" only need "perl-base" to run (and not the
	# full "perl" package. This allows "ic2-tools" to be installable on
	# target since "perl" depends on "libperl5.X" which depends on "libgdbm*"
	# which is not available in target because under GPL-3 license.
	dh_perl -d
