#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk

P23S=$(shell pwd)/debian/tmp
DEB_PYTHON_INSTALL_ARGS_ALL = --no-compile -O0 --root=$(P23S)

common-install-prehook-indep::
#	Fix lintian warning
	mkdir -p $(P23S)/usr/share/doc/python2.3-simpy; \
	cp CHANGES_FROM_VERSION_1_3.txt \
	    $(P23S)/usr/share/doc/python2.3-simpy/changelog

#	Copy documentation
	cp -R SimPyDocs/* $(P23S)/usr/share/doc/python2.3-simpy/
#	rename files with space, it's just too ugly (upstream bug #890942)
	( cd $(P23S)/usr/share/doc/python2.3-simpy; \
	    mv -i Interfacing/SimGUI\ manual Interfacing/SimGUI_manual; \
	    mv -i Interfacing/SimGUI_manual/SimGUI\ manual.html \
		Interfacing/SimGUI_manual/SimGUI_manual.html; \
	    mv -i Interfacing/SimGUI_manual/SimGUI\ manual.txt \
		Interfacing/SimGUI_manual/SimGUI_manual.txt; \
	    mv -i Interfacing/SimPlot\ manual Interfacing/SimPlot_manual )

#	Copy examples
	mkdir -p $(P23S)/usr/share/doc/python2.3-simpy/examples; \
	cp -R SimPyModels/* $(P23S)/usr/share/doc/python2.3-simpy/examples/; \
	cp SimPy/testSimPy.py $(P23S)/usr/share/doc/python2.3-simpy/examples/

#	remove some weird files/dirs (upstream bugs #890942, #895215, #895223)
	find $(P23S) -depth \( -name "_vti_*" -o -name CVS \
	    -o -name '*.html.html' \) -exec rm -rf {} \; ; \
	rm -f $(P23S)/usr/share/doc/python2.3-simpy/LISTOFMODELS.html

binary-post-install/python2.3-simpy binary-post-install/python2.3-simpy-gui::
#	Replace all '#!' calls to python with /usr/bin/python2.3 and
#	make them executable. Might not be necessary with future
#	versions (>> 1.22.9) of lintian!
	for i in `find debian/python2.3-simpy*/ -name '*.py' -type f`; do \
	    sed '1s,#!.*python[^ ]*\(.*\),#!/usr/bin/python2.3\1,' \
		$$i > $$i.temp; \
	    if cmp --quiet $$i $$i.temp; then \
		rm -f $$i.temp; \
	    else \
		mv -f $$i.temp $$i; \
		echo "fixed interpreter: $$i"; \
	    fi; \
	    head -1 $$i | grep -q '^#!.*python'; \
	    if [ "$$?" -eq 1 ]; then \
		echo '#!/usr/bin/python2.3' > $$i.temp; \
		cat $$i >> $$i.temp; \
		mv -f $$i.temp $$i; \
	    fi; \
	    chmod 755 $$i; \
	done
