TOP=	..
include ${TOP}/Makefile.config

SUBDIR=	mail.fcgi \
	weblog.fcgi

all: all-subdir
clean: prereq clean-subdir
cleandir: prereq cleandir-subdir cleandir-cache
deinstall: deinstall-subdir
depend: depend-subdir

install:
	@for D in ${SUBDIR}; do \
		echo "==> $$D"; \
		(cd $$D && ${MAKE} install); \
	done

deinstall:
	@for D in ${SUBDIR}; do \
		echo "==> $$D"; \
		(cd $$D && ${MAKE} deinstall); \
	done

configure:
	@if [ -e ".configurecache" ]; then \
		echo "rm -fR .configurecache"; \
		rm -fR .configurecache; \
	fi
	mkdir .configurecache
	@for D in ${SUBDIR}; do \
		echo "==> $$D"; \
		(cd $$D && ./configure --prefix=/var/www/$$D --with-html-source --cache=../.configurecache); \
		if [ $$? != 0 ]; then \
			echo "* "; \
			echo "* If the previous test failed due to PerCGI not being found,"; \
			echo "* make sure you have already installed PerCGI on your system"; \
			echo "* and that the agar-config binary is in your PATH."; \
			echo "* "; \
			echo "* To install PerCGI, go to the top-level directory and run:"; \
			echo "*     $ make all install"; \
			echo "* "; \
			exit 1; \
		fi; \
	done

cleandir-cache:
	rm -fR .configurecache

configure-scripts:
	for D in ${SUBDIR}; do \
		echo "==> $$D"; \
		(cd $$D && ${MAKE} configure); \
	done

prereq:
	for D in ${SUBDIR}; do \
		echo "==> $$D"; \
		touch $$D/Makefile.config; \
		touch $$D/.depend; \
	done

.PHONY: clean cleandir cleandir-cache install deinstall depend configure configure-scripts prereq

include ${TOP}/mk/build.common.mk
include ${TOP}/mk/build.subdir.mk