#!/usr/bin/make -f

v = 4
dtmp=$(shell pwd)/debian/tmp

%:
	dh $@

override_dh_auto_configure:
	chmod u+x mkinstalldirs	# dpkg-source isn't very smart...
	dh_auto_configure -- \
			  --with-tcl=/usr/lib \
			  --with-tk=/usr/lib

override_dh_auto_install:
	$(MAKE) INSTALL_ROOT=$(dtmp) \
		MAN_INSTALL_DIR=$(dtmp)/usr/share/man/man3 install
	# Move the libraries
	install -d -m 755 $(dtmp)/usr/share/tcltk/
	mv $(dtmp)/usr/lib/iwidgets$(v)* $(dtmp)/usr/share/tcltk/
	# Remove redundant license file
	rm -f $(dtmp)/usr/share/tcltk/iwidgets$(v)*/license.terms
	# Move the demos
	install -d -m 755 $(dtmp)/usr/share/doc/iwidgets$(v)-doc
	mv $(dtmp)/usr/share/tcltk/iwidgets$(v)*/demos \
	   $(dtmp)/usr/share/doc/iwidgets$(v)-doc/
	# Fix up the manpages
	cd $(dtmp)/usr/share/man/man3 && \
	  for i in *.n; do \
	    mv $$i $$(basename $$i .n).3iwidget; \
	  done

override_dh_auto_test:
	# Tests require X, so disable them

override_dh_compress:
	dh_compress -Xdemos

get-orig-source: 
	wget -O iwidgets4_4.0.1.orig.tar.gz \
		http://prdownloads.sourceforge.net/incrtcl/iwidgets4.0.1.tar.gz

.PHONY: override_dh_auto_configure override_dh_auto_install override_dh_compress get-orig-source
