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

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

PACKAGE=limesurvey

build:  patch

clean-patched:
	dh_testdir
	dh_testroot
	dh_clean

clean:	clean-patched unpatch


install:build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -X.svn -XCVS
	dh_install -XCVS -X.svn
	# fix permissions
	chown -R www-data:www-data debian/limesurvey/var/lib/limesurvey
	chown -R root:www-data debian/limesurvey/usr/share/limesurvey
	cp debian/changelog docs/

# Everything else is handled by dh_install

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs -XCVS -X.svn
	dh_installexamples -X.svn
	dh_installdebconf	
	dh_link
	dh_compress
	dh_fixperms
	# fix permissions
	chown -R www-data:www-data debian/limesurvey/var/lib/limesurvey
	chown -R root:www-data debian/limesurvey/usr/share/limesurvey
	find debian/limesurvey/var/lib/limesurvey -type d | xargs chmod 750 
	find debian/limesurvey/var/lib/limesurvey -type f | xargs chmod 640
	find debian/limesurvey/usr/share/limesurvey -type d | xargs chmod 755 
	# find debian/limesurvey/usr/share/limesurvey -type f | xargs chmod 644
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep
.PHONY: build clean binary-indep binary install #PHONY_CONFIGURE#

binary-arch: 

# Apply patches to the package
patch: patch-stamp
patch-stamp:
	dh_testdir
	@patches=debian/patches/*.patch; for patch in $$patches; do \
		test -f $$patch || continue; \
		echo "Applying $$patch"; \
		patch -stuN -p1 < $$patch || exit 1; \
	done
	touch $@

# Remove patches from the package
unpatch:
	dh_testdir
	@if test -f patch-stamp; then \
		patches=debian/patches/*.patch; \
		for patch in $$patches; do \
			reversepatches="$$patch $$reversepatches"; \
		done; \
		for patch in $$reversepatches; do \
			test -f $$patch || continue; \
			echo "Reversing $$patch"; \
			patch -suRf -p1 < $$patch || exit 1; \
		done; \
		rm -f patch-stamp; \
	fi


