DocumentRoot = /should/be/set/or/autodetected
UseSymlinks = 0

all:
	@echo ""
	@echo "Please run one of the following commands:"
	@echo ""
	@echo "	make install  # autodetects DocumentRoot if possible"
	@echo "	make install DocumentRoot=/home/apache/html"
	@echo "	make install UseSymlinks=1  # don't copy anything, use symlinks"
	@echo ""
	@echo "This copies one file archzoom.cgi and creates one directory archzoom-data"
	@echo "inside the specified or autodetected DocumentRoot dir of your web server."
	@echo "Alternativelly, symlinks are used instead of copying."
	@echo ""

install:
	@DocumentRoot=$(DocumentRoot); \
	if [ ! -d "$$DocumentRoot" ]; then \
		for i in \
			/etc/httpd/conf/httpd.conf \
			/etc/apache/httpd.conf \
			/etc/apache2/sites-available/default \
			/var/www/conf/httpd.conf \
		; do \
			if [ -f $$i ]; then \
				DocumentRoot="`grep '^DocumentRoot' $$i | head -1 | cut -d' ' -f2- | tr -d '\"'`"; \
			fi; \
		done; \
	fi; \
	if [ ! -d "$$DocumentRoot" ]; then \
		echo "Can't autodetect web server's DocumentRoot dir, specify explicitely"; \
		exit 1; \
	fi; \
	echo "=============================================================="; \
	echo "Installing into $$DocumentRoot"; \
	echo ""; \
	rm -f "$$DocumentRoot/archzoom.cgi"; \
	rm -rf "$$DocumentRoot/archzoom-data"; \
	if [ $(UseSymlinks) = 0 ]; then \
		cp bin/archzoom.cgi "$$DocumentRoot/"; \
		mkdir "$$DocumentRoot/archzoom-data"; \
		cp -r templates perllib conf "$$DocumentRoot/archzoom-data/"; \
	else \
		ln -s "`pwd`/bin/archzoom.cgi" "$$DocumentRoot/archzoom.cgi"; \
		ln -s "`pwd`" "$$DocumentRoot/archzoom-data"; \
	fi; \
	echo "=============================================================="; \
	echo "$$DocumentRoot/archzoom.cgi is installed, define it as cgi-script in httpd.conf"; \
	echo ""
