#!/usr/bin/make -f

PHPAPI := $(shell php-config --phpapi)
PYTHON_SITELIB := $(shell python -c 'from distutils.sysconfig import get_python_lib; print get_python_lib()')
PYTHON_SITEARCH := $(shell python -c 'from distutils.sysconfig import get_python_lib; print get_python_lib(1)')

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
export DH_OPTIONS=-v

%:
	dh $@ --parallel

binary-arch:
	echo "php:Depends=phpapi-${PHPAPI}" >> debian/php-kolabformat.substvars
	dh binary-arch

override_dh_auto_configure:
	dh_auto_configure -- \
		-DSWIG=/usr/bin/swig2.0 \
		-DPHP_BINDINGS=ON \
		-DPHP4_EXECUTABLE=/usr/bin/php5 \
		-DPHP4_INCLUDE_PATH=/usr/include/php5/ \
		-DPHP_INSTALL_DIR=/usr/lib/php5/$(PHPAPI) \
		-DPYTHON_BINDINGS=ON \
		-DPYTHON_INSTALL_DIR=$(PYTHON_SITEARCH)

override_dh_install:
	mkdir -p debian/tmp/usr/share/php5/kolab
	echo "extension=kolabformat.so" > debian/tmp/usr/share/php5/kolab/kolabformat.ini
	mkdir -p debian/tmp/usr/share/php
	mv debian/tmp/usr/lib/php5/$(PHPAPI)/kolabformat.php debian/tmp/usr/share/php/kolabformat.php
	dh_install --fail-missing
