#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

include /usr/share/quilt/quilt.make

clean: clean-patched unpatch

clean-patched:
	dh_testdir
	dh_testroot
	rm -rf configure-*stamp
	dh_clean 

configure-stamp: patch
	dh_testdir

	touch configure-stamp

install: configure-stamp
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	# copy file and remove dos newlines if necessary
	sed -e 's/\r//' $(CURDIR)/include/distconfig.php > $(CURDIR)/debian/websvn/etc/websvn/config.php
	echo '<?php' >> $(CURDIR)/debian/websvn/etc/websvn/config.php
	echo 'if ( file_exists("/etc/websvn/svn_deb_conf.inc") ) {' >> $(CURDIR)/debian/websvn/etc/websvn/config.php
	echo '  include("/etc/websvn/svn_deb_conf.inc");' >> $(CURDIR)/debian/websvn/etc/websvn/config.php
	echo '}' >> $(CURDIR)/debian/websvn/etc/websvn/config.php
	echo '?>' >> $(CURDIR)/debian/websvn/etc/websvn/config.php
	# main install
	for i in *.php languages templates include; do \
	  cp -pr $(CURDIR)/$$i $(CURDIR)/debian/websvn/usr/share/websvn; \
	done
	# fix permissions
	find $(CURDIR)/debian/websvn/usr/share/websvn -type f -exec chmod 644 {} \;
	find $(CURDIR)/debian/websvn/usr/share/websvn -type d -exec chmod 755 {} \;
#	chown -R www-data:www-data $(CURDIR)/debian/websvn/usr/share/websvn
	chown www-data:www-data debian/websvn/var/cache/websvn
	# wsvn.php IS a config file !
	sed -e 's/\$$locwebsvnreal = .*$$/\$$locwebsvnreal = "\/usr\/share\/websvn\";/; s/\r//' < $(CURDIR)/debian/websvn/usr/share/websvn/wsvn.php > $(CURDIR)/debian/websvn/etc/websvn/wsvn.php

	install -m 0644 $(CURDIR)/debian/apache.conf $(CURDIR)/debian/websvn/etc/websvn/



# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs changes.txt
	dh_installcron
	dh_installdebconf -pwebsvn
	dh_installdocs
	dh_install
	dh_compress
	dh_fixperms -Xusr/share/websvn -Xvar/cache/websvn
	dh_install
	dh_link
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:

binary-arch: build install

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