#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# AFM  27nov2006 variables MUST be set outside target rules
# target rules MUST start at column 1, then followed by ":"
# actions MUST start after a TAB, not blank spaces
# AFM 11dec2006 builddir for using dh_install for .war files.
	BUILDDIR := debian/php-java-bridge
	DESTDIR := ${CURDIR}/${BUILDDIR}
	PHP_EXT_DIR := $(shell /usr/bin/php-config --extension-dir)



CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

# AFM 07dec2006 using dpatch for flexibility
configure: patchsource configure-stamp

configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
#	phpize --clean
	phpize

# AFM 27nov2006
	./configure --with-java=/usr/lib/jvm/java-1.5.0-sun --prefix=${DESTDIR}

	touch configure-stamp




build: build-stamp

# AFM 07dec2006 using dpatch for flexibility, no mv anymore
build-stamp: configure 
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	#docbook-to-man debian/php-java-bridge.sgml > php-java-bridge.1

	touch $@

# AFM 07dec2006 using dpatch for flexibility
clean-patched:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-$(MAKE) clean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs 

	# Add here commands to install the package into debian/php-java-bridge.

# AFM 27nov2006 to specifiy destdir debian way
	$(MAKE) install-modules DESTDIR=${DESTDIR}

# AFM 11dec2006 using dh_installdirs and dh_install for this task
# note the absence of leading "/"
	dh_install java.ini java-servlet.ini mono.ini etc/php5/conf.d


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

# AFM 11dec2006 using dh_installdirs and dh_install for this task
# note the absence of leading "/"
	dh_install ${BUILDDIR}$(PHP_EXT_DIR)/JavaBridge.war var/lib/tomcat5/webapps

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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

# AFM 07dec2006 using dpatch for flexibility
unpatch:
	dpatch deapply-all
	rm -rf patch-stamp debian/patched

patchsource: patch-stamp

patch-stamp:
	dpatch apply-all
	dpatch cat-all >patch-stamp

clean: clean-patched unpatch
