#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

DIR = $(shell pwd)/debian/tcl-tdbc-sqlite3
DOCSRC = $(shell pwd)/doc
TCLVERSIONS = 8.6 9.1

%:
	dh $@

override_dh_auto_install:
	for v in $(TCLVERSIONS) ; do \
		BUILD_DIR="debian/tdbcsqlite3/tcl$$v" ; \
		echo "Install tdbsqlite3 files for Tcl$$v version from $$BUILD_DIR" ; \
		dh_auto_install --builddir=$$BUILD_DIR  -- ; \
	done ; \
	mkdir --parent $(DIR)/usr/share/man/man3 ; \
	f1=$(DOCSRC)/tdbc_sqlite3.n ; \
	f2=$(DIR)/usr/share/man/man3/tdbc_sqlite3.3tcl ;\
	cat $$f1 | sed	-e 's/^\.TH \([^ ]\+\|"[^"]\+"\) [3n]/.TH \1 3tcl/' \
			-e 's/\(Tk_[0-9A-Za-z]*\)(3)/\1(3tk)/g' \
			-e 's/\([A-Z][0-9A-Za-z_]*\)(3)/\1(3tcl)/g' \
			-e 's/send(n)/send(3tk)/g' \
			-e 's/text(n)/text(3tk)/g' \
			-e 's/tk(n)/tk(3tk)/g' \
			-e 's/winfo(n)/winfo(3tk)/g' \
			-e 's/(n)/(3tcl)/g' \
			-e "s/\\N'244'/\\[^o]/g" > $$f2 ; \
	rm -rf $(DIR)/usr/share/man/mann

override_dh_auto_configure:
	for v in $(TCLVERSIONS) ; do \
		BUILD_DIR="debian/tdbcsqlite3/tcl$$v" ; \
		echo "Configuring package for Tcl$$v in $$BUILD_DIR" ; \
		dh_auto_configure  	--builddir=$$BUILD_DIR	--     \
					--with-tcl="/usr/lib/tcl$$v"   \
					--prefix=/usr                  \
					--includedir=/usr/include      \
					--mandir=/usr/share/man        \
					--infodir=/usr/share/info      \
					--sysconfdir=/etc              \
					--localstatedir=/var           \
					--libdir=/usr/share/tcltk/     \
					--libexecdir=/usr/share/tcltk  \
					--with-tdbc=$$(ls -dv /usr/lib/tcltk/$(DEB_HOST_MULTIARCH)/tdbc1.* | tail -n 1) ; \
	done
