#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian.rules file - for GNU Hello (1.3).
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified
#
# Modified to be a prototype for debmake by Christoph Lameter
# <clameter@debian.org>.

package=php

configure:
	test -f config.h


build: configure
	$(checkdir)
	mkdir -p debian/module debian/cgi
	cp debian/Makefile debian/module/Makefile
	sed "s/-DAPACHE=1/ /g" < debian/Makefile > debian/cgi/Makefile
	cp debian/php.h-cgi src/php.h
	cd debian/cgi; $(MAKE) VPATH="../../src" \
		srcdir="../../src" CFLAGS="-O2 -pipe -s" libphp.a
	cd debian/cgi; $(MAKE) VPATH="../../src" \
		srcdir="../../src" CFLAGS="-O2 -pipe -s -lgdbm -lm" php.cgi
	cp debian/php.h-mod src/php.h
	cd debian/module; $(MAKE) VPATH="../../src" \
		srcdir="../../src" CFLAGS="-O2 -pipe -s -fPIC" libphp.a
	cd debian/module; $(MAKE) VPATH="../../src" \
		srcdir="../../src" CFLAGS="-O2 -Wl,-S -fPIC" mod_php-static.so
	sed "s/-DAPACHE=1/ /g" < debian/Makefile > debian/cgi/Makefile
	cp debian/php.h-cgi src/php.h
	cd debian/cgi; $(MAKE) VPATH="../../src" \
		srcdir="../../src" CFLAGS="-O2 -pipe -s" libphp.a
	cd debian/cgi; $(MAKE) VPATH="../../src" \
		srcdir="../../src" CFLAGS="-O2 -pipe -s -lgdbm -lm" php.cgi
	touch build


clean:
	$(checkdir)
	-cd src; make clean
	-rm -f build $$(find . -name "*~") src/Makefile src/libphp* src/*.so
	-rm -rf $$(find debian/* -type d) debian/files* core debian/substvars*
	chmod 755 debian/{postinst,postrm}


binary-indep:	checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

binary-arch:	checkroot build
	$(checkdir)
	-rm -rf debian/tmp && install -d debian/tmp
	cd debian/tmp && install -d $$(cat ../dirs)
	install debian/module/mod_php-static.so \
		debian/tmp/usr/lib/apache/modules/mod_php.so
	cp debian/mod_php.info debian/tmp/usr/lib/apache/modules
	install debian/cgi/php.cgi debian/tmp/usr/lib/cgi-bin
	debstd -m -p ChangeLog README doc/*
	dpkg-gencontrol
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	chown -R root.www-data debian/tmp/var/lib/php
	chmod -R g=rwX debian/tmp/var/lib/php
	dpkg --build debian/tmp ..


define checkdir
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

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

checkroot:
	$(checkdir)
	test root = "`whoami`"

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