#!/usr/bin/make -f

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

# enable dpkg build flags
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export DEB_HOST_MULTIARCH

export SHELL := /bin/sh -e

PECL_NAME    := libvirt-php
INSTALL_ROOT := $(CURDIR)/debian/php-$(PECL_NAME)

PHP_VERSIONS := $(shell /usr/sbin/phpquery -V)

%:
	dh $@ --with php --with autoreconf --with autotools-dev

debian/autoreconf:
	: > debian/autoreconf
	for v in $(PHP_VERSIONS); do \
	  echo "source-$$v" >> debian/autoreconf; \
	done

override_dh_auto_configure:
	for v in $(PHP_VERSIONS); do \
	  dh_auto_configure --builddirectory=$(CURDIR)/build-$$v -- --with-php-config=/usr/bin/php-config$$v; \
	done

override_dh_auto_build:
	for v in $(PHP_VERSIONS); do \
	  dh_auto_build --builddirectory=$(CURDIR)/build-$$v; \
	done

override_dh_auto_install:
	for v in $(PHP_VERSIONS); do \
	  dh_auto_install --builddirectory=$(CURDIR)/build-$$v -- \
		INSTALL_ROOT=$(INSTALL_ROOT) \
		PHPCDIR=/etc/php/$$v/modules-available \
		PHPEDIR=$$(/usr/bin/php-config$$v --extension-dir); \
	  rm -r $(INSTALL_ROOT)/etc/php/$$v; \
	done
	rm -r $(INSTALL_ROOT)/usr/share/doc/libvirt-php-*
	rm -f $(INSTALL_ROOT)/usr/lib/php/*/*.la

override_dh_auto_clean:
	for v in $(PHP_VERSIONS); do \
	  dh_auto_clean --builddirectory=$(CURDIR)/build-$$v; \
	  rm -rf $(CURDIR)/build-$$v; \
	done
