#!/usr/bin/make -f
# -*- makefile -*-

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

DESTDIR=$(CURDIR)/debian/php5-xhprof

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

DEB_HOST_GNU_TYPE    ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

# Enable IEEE-conformant floating point math on alphas (not the default)
ifeq (alpha-linux-gnu,$(DEB_HOST_GNU_TYPE))
	CFLAGS += -mieee
endif

ifeq ($(DEB_HOST_GNU_TYPE), $(findstring $(DEB_HOST_GNU_TYPE), ia64-linux-gnu powerpc64-linux-gnu))
	CFLAGS += -g
else
	CFLAGS += -gstabs
endif

configure: configure-stamp
configure-stamp:
	cd $(CURDIR)/extension/ && phpize5 && \
		./configure --prefix=/usr --with-php-config=/usr/bin/php-config5
	touch $@

build-arch:
build-indep:
build: build-stamp

build-stamp: configure
	cd $(CURDIR)/extension/ && $(MAKE) DESTDIR=$(DESTDIR)
	touch $@

clean:
	dh_testdir
	dh_testroot
	cd $(CURDIR)/extension/ && phpize --clean
	rm -f $(CURDIR)/jquery.autocomplete.css
	dh_clean

install: check
	dh_testdir
	dh_testroot
	dh_prep
	cd $(CURDIR)/extension/ && $(MAKE) install INSTALL_ROOT=$(DESTDIR)
	install -D -m 644 debian/xhprof.ini \
		$(DESTDIR)/etc/php5/mods-available/xhprof.ini

check: build
	# TODO: check why all tests fail
#	cd $(CURDIR)/extension/ && $(MAKE) test

binary-indep: install

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installdirs -a
	dh_installchangelogs -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	echo "php:Depends=phpapi-`php-config5 --phpapi`" >> debian/php5-xhprof.substvars
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch
.PHONY: clean binary-indep binary-arch binary install
