#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# This file is public domain software, originally written by Joey Hess.
#
# This version is for packages that are architecture independent.
#
# Rules to build etherpad
#
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	#$(MAKE)
	bin/build.sh
	touch build-stamp

clean:
	# update template translation strings commented out as git-buildpackage complains that the file changes all the times otherwise...
	# debconf-updatepo
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	#$(MAKE) clean
	#$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/<packagename>.
	#$(MAKE) prefix=`pwd`/debian/`dh_listpackages`/usr install

	# Add here commands to install the indep part of the package into
	# debian/<package>-doc.
	#INSTALLDOC#

	mkdir -p debian/etherpad/usr/share/etherpad

	# try to copy content correctly
	cp -a $$(ls | grep -E -v 'debian|LICENSE|COPYING|INSTALL') debian/etherpad/usr/share/etherpad
	# fix ups (because the above copy is too dump), remove unneeded stuff
	find debian/etherpad -type f -and -name ".gitignore" -exec rm {} +
	find debian/etherpad -type f -and -name "build-stamp" -exec rm {} +

	# create directory to save user data
	mkdir -p debian/etherpad/usr/share/etherpad/etherpad/data

	mkdir -p debian/etherpad/etc
	mv debian/etherpad/usr/share/etherpad/etherpad/etc debian/etherpad/etc/etherpad
	ln -s /etc/etherpad debian/etherpad/usr/share/etherpad/etherpad/etc

	mkdir -p debian/etherpad/usr/share/lintian/overrides
	cp debian/source/lintian-overrides debian/etherpad/usr/share/lintian/overrides/etherpad

	#mkdir -p debian/etherpad/etc/init.d
	#ln -s /usr/share/etherpad/bin/etherpad.init.d debian/etherpad/etc/init.d/etherpad
	dh_installinit --update-rcd-params="start 05 2 3 4 5 . stop 95 0 1 6 ."

	dh_install -i


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	# on the fly final copyright file creation:
	cat debian/copyright LICENSE > debian/etherpad/usr/share/doc/etherpad/copyright
	dh_installexamples
#	dh_installmenu
	dh_installdebconf
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installcatalogs
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installwm
#	dh_installudev
#	dh_lintian
#	dh_bugfiles
#	dh_undocumented
	dh_installman
	dh_link
	dh_compress
	dh_fixperms
#	dh_perl
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

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