#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1


package=photopub
rootdir=debian/$(package)

build: build-stamp
build-stamp:
	dh_testdir

	# no building required

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

        # Add here commands to clean up after the build process.
        # no building, so no cleaning

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	rm -rf $(rootdir)

	for d in /etc /usr/lib/photopub/PhotoPub \
	         /usr/lib/photopub/utils /usr/lib/photopub/cgi-bin \
	         /etc/apache/conf.d /etc/apache2/conf.d \
	         /DEBIAN /usr/share/doc/photopub ; \
          do install -d -m755 $(rootdir)$$d ; \
          done
	install -d -m2775 -o root -g www-data $(rootdir)/var/cache/photopub

	dist/mungefile.pl configfind dist/configfind.global < PhotoPub/Config.pm > $(rootdir)/usr/lib/photopub/PhotoPub/Config.pm
	chmod 644 $(rootdir)/usr/lib/photopub/PhotoPub/Config.pm

	for d in Handlers Images Ages Annots Cache Global CGIBase CLBase Images Options Utils Album Range Embed Display FileInfo ParallelLimit Search Page ; do install -m 644 PhotoPub/$$d.pm $(rootdir)/usr/lib/photopub/PhotoPub/$$d.pm ; done

	for d in album range embed display page ; do dist/mungefile.pl libsetup dist/libsetup.global < cgi-bin/$$d.pl > $(rootdir)/usr/lib/photopub/cgi-bin/$$d.pl ; chmod 755 $(rootdir)/usr/lib/photopub/cgi-bin/$$d.pl ; done

	for d in probe ; do dist/mungefile.pl libsetup dist/libsetup.global < utils/$$d.pl > $(rootdir)/usr/lib/photopub/utils/$$d.pl ; chmod 755 $(rootdir)/usr/lib/photopub/utils/$$d.pl ; done
	install -m 755 dist/mungefile.pl $(rootdir)/usr/lib/photopub/utils

	cd dist && for d in `find templates -type d` ; \
	   do install -d -m 755 ../$(rootdir)/etc/photopub/$$d ; done

	cd dist && for d in `find templates -type f` ; \
	   do install -m 644 $$d ../$(rootdir)/etc/photopub/$$d ; done

	install -m 644 dist/photopubrc $(rootdir)/etc/photopubrc

	install -m 644 dist/apache.conf $(rootdir)/etc/apache/conf.d/photopub.conf
	install -m 644 dist/apache.conf $(rootdir)/etc/apache2/conf.d/photopub.conf

	install -m 755 debian/config $(rootdir)/DEBIAN
	install -m 644 debian/templates $(rootdir)/DEBIAN


binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
#	dh_installexamples
#	dh_installmenu
	dh_installdebconf
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installman
#	dh_undocumented
	dh_installman
	dh_link
	dh_compress
	dh_fixperms -X/var/cache/photopub
	dh_installdeb
	dh_perl /usr/lib/photopub/PhotoPub
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: build install

binary: binary-indep
.PHONY: build clean binary-indep binary-arch binary install
