VERSION=1.0.2
NAME=indexpage
PROG=$(NAME)-$(VERSION)
TMPDIR=/tmp/$(PROG)

SOURCES = indexpage.pl \
          README \
          TODO \
          Makefile \
          COPYING \
          NEWS

dist: test
	mkdir $(TMPDIR)
	cp $(SOURCES) $(TMPDIR)
	cp -r teststuff $(TMPDIR)
	(cd $(TMPDIR)/teststuff; rm -rf CVS)
	(cd $(TMPDIR)/..; \
	    tar cfz /tmp/$(PROG).tar.gz $(PROG))
	rm -rf $(TMPDIR)

test: foo
	# Test 1
	@# indir = test1
	@rm -rf test1
	@rm -f descriptions.txt
	@mkdir test1
	@cp teststuff/default1.conf /home/hans/.indexpagerc
	@cp teststuff/pic.jpg test1/pic1.jpg
	@cp teststuff/pic.jpg test1/pic2.jpg
	@perl indexpage.pl --inplace --title=Test1 --nodesc
	@if [ -f descriptions.txt ] ; then \
	    echo "Error: descriptions file created!" ; \
	fi
	@diff teststuff/index1.html test1/index.html

	# Test 2
	@# indir = testerror
	@# header = Test header
	@# htmlfoot = <hr>\n</body>\n</html>
	@rm -rf test2
	@rm -f descriptions.txt
	@mkdir test2
	@cp teststuff/default2.conf /home/hans/.indexpagerc
	@cp teststuff/pic.jpg test2/pic1.jpg
	@cp teststuff/pic.jpg test2/pic2.jpg
	@perl indexpage.pl --inplace --title=Test2 --indir=test2 --outdir=foo
	@diff teststuff/index2.html test2/index.html

	# Test 3
	@rm -rf test3
	@rm -rf test3out
	@rm -f descriptions.txt
	@rm -f /home/hans/.indexpagerc
	@mkdir test3
	@cp teststuff/pic.jpg test3/pic1.jpg
	@cp teststuff/pic.jpg test3/pic2.jpg
	@perl indexpage.pl --title=Test3 --indir=test3 --outdir=test3out \
	    --nomakethumbs
	@diff teststuff/index3.html test3out/index.html

	# Test 4
	@rm -rf test4
	@rm -f descriptions.txt
	@rm -f index.html 2.html
	@rm -f /home/hans/.indexpagerc
	@rm -rf images thumbs
	@mkdir test4
	@cp teststuff/pic.jpg test4/pic1.jpg
	@cp teststuff/pic.jpg test4/pic2.jpg
	@perl indexpage.pl --rows=1 --cols=1 --thumbsize=250 --indir=test4
	@diff teststuff/index4.html index.html
	@diff teststuff/2-4.html 2.html
	@diff teststuff/descriptions4.txt descriptions.txt

	# Test 5
	@rm -rf test5
	@rm -f index.html
	@rm -f /home/hans/.indexpagerc
	@rm -rf images thumbs
	@mkdir test5
	@cp teststuff/pic.jpg test5/pic1.jpg
	@cp teststuff/pic.jpg test5/pic2.jpg
	@cp teststuff/descriptions5.txt descriptions.txt
	@perl indexpage.pl --indir=test5 --convert=/usr/bin/X11/convert \
	    --footer="This goes at the bottom." --title=Test5
	@diff teststuff/index5.html index.html

	# Test 6
	@rm -rf test6
	@rm -f descriptions.txt
	@rm -f /home/hans/.indexpagerc
	@mkdir test6
	@cp teststuff/pic.jpg test6/pic1.jpg
	@cp teststuff/pic.jpg test6/pic2.jpg
	@cp teststuff/pic.jpg test6/pic3.jpg
	@cp teststuff/pic.jpg test6/pic4.jpg
	@cp teststuff/descriptions6.txt test6/desc.txt
	@perl indexpage.pl --indir=test6 --title=Test6 --inplace \
	    --header="Pictures from %(indir)s." --order="3 1 4" \
	    --descfile=test6/desc.txt --imagere='^[^\d]*(\d+)[^\d]*\..*$$'
	@diff teststuff/index6.html test6/index.html

	# Test 7
	@# imagere = ^.*?\..*$
	@rm -rf test7
	@rm -rf test7out
	@rm -f descriptions.txt
	@mkdir test7
	@mkdir test7out
	@rm -f /home/hans/.indexpagerc
	@cp teststuff/pic.jpg test7/foo.jpg
	@cp teststuff/pic.jpg test7/an-image-with-a-long-name.jpg
	@cp teststuff/pic.jpg test7/test_name.jpg
	@cp teststuff/pic.jpg test7/dotted.name.jpg
	@cp teststuff/pic.jpg test7/bar.jpg
	@perl indexpage.pl --indir=test7 --title=Test7 --outdir=test7out \
	    --configfile=teststuff/default7.conf
	@diff teststuff/index7.html test7out/index.html

	@# Test 8
# 	@rm -rf test8
# 	@mkdir test8
# 	@mkdir test8/images
# 	@cp teststuff/pic.jpg test8/images/pic1.jpg
# 	@cp teststuff/pic.jpg test8/images/pic2.jpg
# 	@perl indexpage.pl --indir=test8

foo:
	touch foo
	rm -f foo

clean:
	rm -f descriptions.txt index.html 2.html
	rm -rf thumbs images
	rm -rf test1 test2 test3 test3out test4 test5 test6 test7 test7out
