#!/usr/bin/make -f

SRCVERSION := $(shell head -1 debian/changelog | sed 's/.*(//;s/).*//')
B = debian/serendipity

binary:
	@###
	dh binary-indep --before dh_installdeb

	@# set/d package version
	sed -i "s/@VERSION@/$(SRCVERSION)/" $(B)/usr/share/serendipity/www/serendipity_config_local.inc.php

	@## remove crufts
	@# SVN
	find $(B) -name .svn | xargs -r rm -r
	@# unneeded docs and examples
	cd $(B)/usr/share/serendipity/www/htmlarea && rm -fr *html ChangeLog license.txt examples
	@# fonts linked to other debian package, hope they ship the txts
	cd $(B)/usr/share/serendipity/www/plugins/serendipity_event_spamblock && rm -f *txt
	@# unneeded development scripts
	cd $(B)/usr/share/serendipity/www/lang && rm *.sh *.txt UTF-8/*.sh
	@# empty dirs, Windows thumbnail files, extra licence file
	cd $(B)/usr/share/serendipity/www/templates && \
		rmdir mt-rusty/img/ blue/img/ mt-gettysburg/img/ mt3-chalkboard/img/ kubrick/img/ && \
		rm -f contest/img/Thumbs.db contest/admin/img/Thumbs.db 
	@# HOWTO -> doc
	mv $(B)/usr/share/serendipity/www/templates/HOWTO $(B)/usr/share/doc/serendipity/HOWTO.templates

	@#TODO: chmod o=wt ?
	chgrp www-data \
		$(B)/var/cache/serendipity/templates \
		$(B)/var/lib/serendipity/archives \
		$(B)/var/lib/serendipity/uploads
	chmod u=rwx,g=wx,o= \
		$(B)/var/cache/serendipity/templates \
		$(B)/var/lib/serendipity/archives
	chmod u=rwx,g=rwx,o= \
		$(B)/var/lib/serendipity/uploads

	@# make even a pedantic lintian happy
	grep -hEv 'NEWS|\$$Id\$$' docs/NEWS docs/NEWS_OLD | gzip -9c > $(B)/usr/share/doc/serendipity/changelog.gz

	@#nextgen perms for directories needed by spartacus (patch)
	#chmod u=rwx,g=rwx,o=wxt \
	#	$(B)/var/lib/serendipity/templates \
	#	$(B)/var/lib/serendipity/plugins

	@###
	dh binary-indep --remaining

override_dh_install:
	dh_install -Xtemplates/default/YahooUI

override_dh_fixperms:
	dh_fixperms -X/var

%:
	dh $@
