#!/usr/bin/make -f

TCLVERSIONS = 8.6 9.0

PACKAGE=tcl-tclex
DIR=$(CURDIR)/debian/$(PACKAGE)
TMPDIR=$(CURDIR)/debian/tmp

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/architecture.mk

%:
	dh $@

override_dh_auto_configure:
	for v in $(TCLVERSIONS) ; do \
		dh_auto_configure -B$(CURDIR)/debian/$$v \
				  -Dsrc -- \
				  --prefix=/usr \
				  --with-tcl=/usr/lib/tcl$$v ; \
	done

override_dh_auto_build:
	for v in $(TCLVERSIONS) ; do \
		$(MAKE) -C$(CURDIR)/debian/$$v ; \
	done

override_dh_auto_clean:
	for v in $(TCLVERSIONS) ; do \
		rm -rf $(CURDIR)/debian/$$v ; \
	done

override_dh_auto_install:
	for v in $(TCLVERSIONS) ; do \
		dh_auto_install -B$(CURDIR)/debian/$$v \
				-Dsrc -- \
				TCL_PREFIX=$(TMPDIR)/usr ; \
	done
	mkdir -p $(TMPDIR)/usr/lib/$(DEB_HOST_MULTIARCH)
	mv $(TMPDIR)/usr/lib/tc* $(TMPDIR)/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_installdocs:
	dh_installdocs
	# be an irritating wise-a** and change .htm in .html where possible
	for a in `cd doc/en; ls *.htm`; do \
	    cat doc/en/$$a | perl -pe 's/("\w+)\.htm\b/\1.html/g' \
		>$(DIR)/usr/share/doc/$(PACKAGE)/html/$${a}l ; \
	done

override_dh_gencontrol:
	tcltk-depends
	dh_gencontrol

.PHONY: override_dh_auto_configure override_dh_auto_build \
	override_dh_auto_clean override_dh_auto_install \
	override_dh_installexamples override_dh_gencontrol
