.PHONY: all install clean test

all: stamp-install

APVERSION=2.2.22

# Install cproxy-specific stuff in the apache directory "prefix"
stamp-install: stamp-build
	sed "s@%prefix%@`pwd`/prefix@g" < cfproxy.conf.in >prefix/conf/cfproxy.conf
	mkdir -p prefix/cf-proxy
	cp local-cproxy.cfg prefix/cf-proxy/cproxy.cfg
	cp ../proxy.pl prefix/cf-proxy
	cp ../proxy_html.conf prefix/cf-proxy/proxy_html.conf
	grep cfproxy.conf prefix/conf/httpd.conf>/dev/null || echo "Include conf/cfproxy.conf" >> prefix/conf/httpd.conf
	touch $@

stamp-build: stamp-unpack
	P=`pwd`/prefix; cd httpd-$(APVERSION); ./configure \
		--with-included-apr \
		--enable-so \
		--prefix=$$P \
		--with-port=9071 --without-sslport \
		--enable-modules=all \
		--enable-proxy \
		--enable-proxy-http
	cd httpd-$(APVERSION); make
	cd httpd-$(APVERSION); make install
	prefix/bin/apxs -c -I ../mod_proxy_html -I /usr/include/libxml2 -lxml2 ../mod_proxy_html/mod_xml2enc.c
	prefix/bin/apxs -i -n "xml2enc" ../mod_proxy_html/mod_xml2enc.la
	prefix/bin/apxs -c -I ../mod_proxy_html -I /usr/include/libxml2 -lxml2 ../mod_proxy_html/mod_proxy_html.c
	prefix/bin/apxs -i -n "proxy_html" ../mod_proxy_html/mod_proxy_html.la
	touch $@
# Removed the -a from apxs -i - no need to add them in the main config, since they
# get loaded in the proxy_html.conf

stamp-unpack:
	rm -fr httpd-$(APVERSION).tar.bz2 httpd-$(APVERSION)
	wget http://ftp.indexdata.dk/pub/support/httpd-$(APVERSION).tar.bz2
	tar jxf httpd-$(APVERSION).tar.bz2
	touch $@

prefix: stamp-install
	mkdir prefix

# Test main target
#  forces a reinstallation of stuff under apache, so you can say 'make test'
#  without having to remember 'make install' if you change anything in proxy.pl
#  or other files.
test:
	rm -f stamp-install
	make stamp-install
	rm -f prefix/logs/*log
	./mksession.sh
	./apache-start.sh
	make run-tests
	./apache-stop.sh

# TODO - Run the actual tests
run-tests:
	#curl -i "http://localhost:9071/XXX/node102/17/flurry.indexdata.dk/heikki/pxy.html"
	curl -i "http://localhost:9071/XXX/node102/17/www.lsd.dk/pxy.html"
	#curl -i "http://localhost:9071/XXX/node102/17/cproxydebug/www.lsd.dk/pxy.html"

clean:
	rm -fr prefix stamp-*

