#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independant
# package.

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

php3ver=$(shell head -1 debian/changelog | cut '-d ' -f 2 | sed 's/[()]//g' | cut -d- -f1)

build: build-stamp

apache-stamp:
	dh_testdir
	# Add here commands to compile the package.
	test -d apache || mkdir apache
	$(CC) -shared -fPIC -DCOMPILE_DL=1 -I. -I/usr/include/php3 -I/usr/include/php3/apache -I/usr/include/apache-1.3 -o apache/msql.so msql.c -lmsql -lc
	touch apache-stamp

cgi-stamp:
	dh_testdir
	# Add here commands to compile the package.
	test -d cgi || mkdir cgi
	$(CC) -shared -fPIC -DCOMPILE_DL=1 -I. -I/usr/include/php3 -I/usr/include/php3/cgi -o cgi/msql.so msql.c -lmsql -lc
	touch cgi-stamp

build-stamp: apache-stamp cgi-stamp
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp apache-stamp cgi-stamp
	# Add here commands to clean up after the build process.
	rm -rf apache cgi
	dh_clean

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

# Build architecture-dependent files here.
binary-arch: build
	dh_testdir -a
	dh_testroot  -a
	dh_clean -k -a
	dh_installdirs -a
	cp apache/msql.so debian/tmp/usr/lib/php3/apache
	cp cgi/msql.so debian/php3-cgi-msql/usr/lib/php3/cgi
	dh_installdocs -a
	dh_installchangelogs -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	echo "php3:Depends=php3 (>= $(php3ver)), php3 (<< $(php3ver).1)" >>debian/substvars
	echo "php3-cgi:Depends=php3-cgi (>= $(php3ver)), php3-cgi (<< $(php3ver).1)" >>debian/php3-cgi-msql.substvars
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

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