#!/usr/bin/make -f

version = 1.4.2
vcsdate = 20230906
reldate = 20080503
DIR = $(shell pwd)/debian/tcl-vfs

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

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
			  --with-tcl=/usr/lib \
			  --enable-threads

override_dh_auto_install:
	# Install the package into debian/tcl-vfs.
	$(MAKE) install-binaries install-libraries DESTDIR=$(DIR)
	# Remove #! from non-executable files
	for f in fishvfs.tcl templatevfs.tcl ; do \
	    sed -i -e'1d' $(DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/vfs*/template/$$f || exit 1 ; \
	done
	# Move the library into the multiarch dir
	install -m 755 -d $(DIR)/usr/lib/tcltk/$(DEB_HOST_MULTIARCH)
	mv $(DIR)/usr/lib/$(DEB_HOST_MULTIARCH)/vfs* $(DIR)/usr/lib/tcltk/$(DEB_HOST_MULTIARCH)
	# Remove empty directories
	find $(DIR)/ -empty -prune -exec rmdir \{\} \;
	# Cleanup manpages
	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

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
