#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2004, 2005, 2006 Sergio Talens-Oliag <sto@debian.org>

include /usr/share/cdbs/1/rules/simple-patchsys.mk
include /usr/share/cdbs/1/rules/debhelper.mk

# Build locale files
ifdef _cdbs_rules_debhelper
$(patsubst %,binary-install/%,$(DEB_PACKAGES)) :: binary-install/%:
	for po in `ls doc/po/*/childsplay.po`; do \
		lang=`echo $$po | sed -e 's%doc/po/%%;s%/childsplay.po%%'`; \
		mkdir -p debian/$(cdbs_curpkg)/usr/share/locale/$$lang/LC_MESSAGES/; \
		msgfmt $$po -o debian/$(cdbs_curpkg)/usr/share/locale/$$lang/LC_MESSAGES/childsplay.mo; \
	done
endif

# Recompress the manpage to get max compression
ifdef _cdbs_rules_debhelper
manpage = debian/$(cdbs_curpkg)/usr/share/man/man6/childsplay.6
$(patsubst %,binary-install/%,$(DEB_PACKAGES)) :: binary-install/%:
	if [ -f $(manpage).gz ] ; then \
		gunzip $(manpage).gz ; \
		gzip -9 $(manpage) ;   \
	fi
endif

# Use debhelper's "dh_python" command; makefile code taken from
# '/usr/share/cdbs/1/class/python-distutils.mk'
ifdef _cdbs_rules_debhelper
$(patsubst %,binary-install/%,$(DEB_PACKAGES)) :: binary-install/%:
	dh_pysupport -p$(cdbs_curpkg) /usr/share/childsplay
	dh_python -p$(cdbs_curpkg) /usr/share/childsplay
endif

common-binary-post-install-indep::
	# Remove unneded .ttf fonts (they are replaced by links)
	find debian/childsplay/ -name '*.ttf' -type f -exec rm {} \;
	# Fix execute permissions for all scripts after installation
	chmod ugo+x debian/childsplay/usr/share/childsplay/childsplay.py
	chmod ugo+x debian/childsplay/usr/share/childsplay/letters-trans.py
	chmod ugo+x debian/childsplay/usr/share/childsplay/pyassetmlcreator.py
	# Remove multiTablesrc, it belongs to the plugins package
	rm debian/childsplay/usr/share/childsplay/lib/ConfigData/multiTablesrc
