#!/usr/bin/make -f
#export DH_VERBOSE=1

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

CFLAGS = -O2 -Wall -fno-strict-aliasing

# 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

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

build-stamp: 
	dh build
	sed "s#@EXTDIR@#`php-config5 --extension-dir`#" debian/xcache.ini.in > debian/xcache.ini
	sed "s@EXT_DIR=.*@EXT_DIR=`php-config5 --extension-dir`@" -i debian/php5-xcache.postinst
	touch $@

override_dh_auto_configure:
	phpize5
	dh_auto_configure -- \
		--with-php-config=/usr/bin/php-config5 \
		--enable-xcache=shared \
		--disable-xcache-constant  \
		--enable-xcache-optimizer \
		--enable-xcache-coverager \
		--enable-xcache-assembler \
		--enable-xcache-encoder   \
		--enable-xcache-decoder
	
override_dh_auto_clean:
	dh_auto_clean
	phpize5 --clean

clean:
	dh clean

override_dh_auto_install:
	$(MAKE) install INSTALL_ROOT=debian/php5-xcache

override_dh_auto_test:
	cd tests; ln -s ../debian/tests/* .
	$(MAKE) xcachetest REPORT_EXIT_STATUS=1 NO_INTERACTION=y

override_dh_fixperms:
	dh_fixperms
	find debian/php5-xcache/usr/share/xcache -type f -print0 | xargs -0 chmod 644
	chmod 644 debian/php5-xcache/usr/share/doc/php5-xcache/examples/xcache.ini

install: build
	dh install

# Build architecture-independent files here.
binary-indep:

# Build architecture-dependent files here.
binary-arch: build install
	echo "php:Depends=phpapi-`php-config5 --phpapi`" >> debian/php5-xcache.substvars
	dh binary-arch

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