#!/usr/bin/make -f
#
# Debian build rules for s5 using debhelper

# Variables also used in the get-orig-source script - keep them in sync!

B=$(CURDIR)/build
S=$B/s5
C=build/cmd
D=$(CURDIR)/debian/s5

# Variables only used in the rules file

REBASE=		s,/usr/local/etc,/etc,g;s,/usr/local,/usr,g

get-orig-source:
	. debian/get-orig-source.sh

override_dh_auto_build:
	mkdir -p $C $S
	tar -cf - --exclude=.DS_Store *.html pix primer ui | tar -C $S -xf -
	cd $S && unzip -x ../../s5-blank.zip
	find $S -name __MACOSX -or -name .DS_Store | xargs rm -rf
	find $S -regextype posix-extended -type f -iregex '.*\.(css|htc|html|js|txt)' -print0 | xargs -0 sed -i.debbuild -e 's/
$$//'
	find $S -type f -name '*.debbuild' -delete
	sed -e "${REBASE}" debian/s5.sh > $C/s5
	sed -e "${REBASE}" debian/s5.conf > $C/s5.conf
	sed -e "${REBASE}" debian/s5.1 > $C/s5.1

override_dh_auto_clean:
	rm -rf build

override_dh_auto_install:
	(cd $B && tar -cf - s5) | tar -C $D/usr/share -xf -
	find $D/usr/share/s5 -type d | xargs chown root:root
	find $D/usr/share/s5 -type d | xargs chmod 755
	find $D/usr/share/s5 -type f | xargs chown root:root
	find $D/usr/share/s5 -type f | xargs chmod 644

%:
	dh $@
