#!/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.
	-mkdir apache
	$(CC) -shared -fPIC -DCOMPILE_DL=1 -I. -I/usr/include/php3 -I/usr/include/php3/apache -I/usr/include/apache-1.3 -I/usr/include/mysql -o apache/mysql.so mysql.c -lmysqlclient -L/usr/lib/apache/1.3 -lphp3 -lc
	$(CC) -shared -fPIC -DCOMPILE_DL=1 -DHAVE_LIBTTF=1 -I. -I/usr/include/php3 -I/usr/include/php3/apache -I/usr/include/apache-1.3 -o apache/gd.so gd.c -lgd -lttf gdcache.c gdttf.c -L/usr/lib/apache/1.3 -lphp3 -lc
	touch apache-stamp

cgi-stamp:
	dh_testdir
	# Add here commands to compile the package.
	-mkdir cgi
	$(CC) -shared -fPIC -DCOMPILE_DL=1 -I. -I/usr/include/php3 -I/usr/include/php3/cgi -I/usr/include/mysql -o cgi/mysql.so mysql.c -lmysqlclient -lc
	$(CC) -shared -fPIC -DCOMPILE_DL=1 -DHAVE_LIBTTF=1 -I. -I/usr/include/php3 -I/usr/include/php3/cgi -o cgi/gd.so gd.c gdcache.c gdttf.c -lgd -lttf -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/mysql.so debian/tmp/usr/lib/php3/apache
	cp cgi/mysql.so debian/tmp/usr/lib/php3/cgi
	cp apache/gd.so debian/php3-gd/usr/lib/php3/apache
	cp cgi/gd.so debian/php3-gd/usr/lib/php3/cgi
	dh_installdocs -a
	dh_installchangelogs -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	LD_LIBRARY_PATH=/usr/lib/apache/1.3 dh_shlibdeps -a
	echo "php3:Depends=php3 (>= $(php3ver)), php3 (<< $(php3ver).0.1)" >>debian/substvars
	echo "php3:Depends=php3 (>= $(php3ver)), php3 (<< $(php3ver).0.1)" >>debian/php3-gd.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
