#! /usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/architecture.mk
CONFIGURE_FLAGS = --without-python2 --enable-easy-bindings

ifeq ($(filter nopython,$(DEB_BUILD_PROFILES)),)
	CONFIGURE_FLAGS += --with-python3=yes
	PY3VERS=$(shell py3versions -vr)
else
	CONFIGURE_FLAGS += --with-python3=no
endif

ifneq ($(filter libpreludedb-doc,$(shell dh_listpackages)),)
	CONFIGURE_FLAGS += --enable-gtk-doc
endif

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_FLAGS)

override_dh_auto_build: build-core $(PY3VERS:%=build-python%)

build-core:
	dh_auto_build

build-python%:
	cd bindings/python && python$* setup.py build

override_dh_autoreconf-arch:
	env GTKDOCIZE="echo DISABLED running gtkdocize" dh_autoreconf --verbose -a

override_dh_auto_install: install-core $(PY3VERS:%=install-python%)
install-core:
	dh_auto_install
	find . -name "__pycache__" -exec rm -rvf {} +
	find . -name "*.la" -exec sed -i -e "s/^dependency_libs=.*$$/dependency_libs=''/g" {} +
	mkdir -p debian/tmp/usr/lib/${DEB_HOST_MULTIARCH}/libpreludedb/bin
	chmod +x debian/tmp/usr/share/libpreludedb/classic/mysql2sqlite.sh debian/tmp/usr/share/libpreludedb/classic/mysql2pgsql.sh
	mkdir -pv $(CURDIR)/debian/tmp/usr/share/doc/libpreludedb-doc
	ln -s /usr/share/gtk-doc/html/libpreludedb $(CURDIR)/debian/tmp/usr/share/doc/libpreludedb-doc/html

install-python%:
	cd bindings/python && python$* setup.py install --root $(CURDIR)/debian/tmp

%:
	dh $@ $(DH_ADDONS)
