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

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

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

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 aarch64-linux-gnu))
	CFLAGS += -g
else
	CFLAGS += -gstabs
endif

configure: configure-stamp
configure-stamp:
	phpize5
	./configure --prefix=/usr --with-php-config=/usr/bin/php-config5 \
		$(shell dpkg-buildflags --export=configure)
	touch $@

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

build-stamp: configure
	$(MAKE) DESTDIR=$(DESTDIR)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -rf configure-stamp build-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	phpize --clean
	find $(CURDIR)/tests \( -name \*.diff -o -name \*.exp -o -name \*.log -o -name \*.out -o -name \*.sh \) -exec rm {} \;
	rm -f $(CURDIR)/tests/mongo-test-cfg.inc
	dh_clean

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

check: build
#	cp $(CURDIR)/tests/mongo-test-cfg.inc.template \
		$(CURDIR)/tests/mongo-test-cfg.inc
#	$(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_php5 -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-mongo.substvars
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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