#!/usr/bin/make -f

TCLVERSIONS = 8.6

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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 -- \
			--with-tcl=/usr/lib/tcl$$v \
			--with-tk=/usr/lib/tk$$v \
			--with-tcl-includes=/usr/include/tcl$$v \
	    		--enable-shared \
			--enable-threads ; \
	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 \
		$(MAKE) -C$(CURDIR)/debian/$$v install DESTDIR=$(CURDIR)/debian/tmp ; \
		dir=$$(echo $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/tclx*) ; \
		ln -s $$(basename $$dir/libtclx*.so) $$dir/libtclx.so ; \
	done
	#
	# Fix up manpages
	sh ./debian/install_manpages $(CURDIR)/debian/tmp
	ln -nfs TclX.3tcl.gz $(CURDIR)/debian/tmp/usr/share/man/man3/tclx.3tcl.gz
	#
	# Load only on Tcl 8.6
	sed -i '1i if {![package vsatisfies [package provide Tcl] 8.6]} return' \
	    $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/tclx*/pkgIndex.tcl

override_dh_gencontrol:
	tcltk-depends
	dh_gencontrol

.PHONY: override_dh_auto_configure override_dh_auto_clean override_dh_auto_install \
	override_dh_gencontrol
