#!/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-stamp

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

override_dh_auto_configure:
	phpize5 --clean
	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

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
