#!/usr/bin/make -f

version = 1.4.2
vcsdate = 20230906
reldate = 20080503

TCLVERSIONS = 8.6 9.0

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 \
			  --enable-threadsa ; \
	done

override_dh_auto_install:
	for v in $(TCLVERSIONS) ; do \
		$(MAKE) -C$(CURDIR)/debian/$$v install-binaries install-libraries DESTDIR=$(CURDIR)/debian/tmp ; \
		for f in fishvfs.tcl templatevfs.tcl ; do \
	    		sed -i -e'1d' $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/vfs*/template/$$f || exit 1 ; \
		done ; \
		find $(CURDIR)/debian/tmp -empty -prune -exec rmdir \{\} \; ; \
		(cd doc && \
		 for f in *.n ; do \
	    		 sed -e'/^\.so man.macros/ d' \
	    			 -e'/^\.B[SE]$$/ d' \
	    			 -e's/^\.TH \([^ ]\+\) n/.TH \1 3tcl/' \
				 $$f >$$(basename $$f .n).3tcl || exit 1; \
		 done) ; \
	done

override_dh_auto_test:
	# Disable tests

override_dh_shlibdeps:
	tcltk-depends
	dh_shlibdeps

get-orig-source: get-orig-source-fossil

get-orig-source-release:
	wget -O tclvfs_$(version)-$(reldate).orig.tar.gz \
		http://heanet.dl.sourceforge.net/sourceforge/tclvfs/tclvfs-$(reldate).tar.gz 

get-orig-source-fossil:
	wget -O tclvfs_$(version)~$(vcsdate).orig.tar.gz \
		https://core.tcl-lang.org/tclvfs/tarball/tclvfs.tar.gz?r=trunk:$(vcsdate)
	wget -O tclvfs_$(version)~$(vcsdate).orig-tclconfig.tar.gz \
		https://core.tcl-lang.org/tclconfig/tarball/tclconfig.tar.gz?r=trunk:$(vcsdate)

.PHONY: override_dh_auto_configure override_dh_auto_install override_dh_auto_test override_dh_shlibdeps
.PHONY: get-orig-source get-orig-source-release get-orig-source-fossil
