#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1

# query for the architecture triplet we build for
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# See FEATURE AREAS in dpkg-buildflags(1).
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic -I/usr/include/tcl
DIR = $(shell pwd)/debian/tcl-unix-sockets

%:
	dh $@

override_dh_gencontrol:
	tcltk-depends
	dh_gencontrol

override_dh_auto_configure:
	dh_auto_configure -- 				\
	--with-tcl=/usr/lib/tcl8.6 			\
	--prefix=/usr 					\
	--libdir=/usr/lib/tcltk/$(DEB_HOST_MULTIARCH) 	\
	--libexecdir=/usr/lib/tcltk/$(DEB_HOST_MULTIARCH)

override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install
	mkdir $(DIR)/usr/share/man/man3
	# Fix up the manpages.
	echo "mangling names in tcl-syslog.n"
	cd $(DIR)/usr/share/man/mann && \
	cat unix_sockets.n | sed -e 's/unix_sockets n/unix_sockets 3tcl/g' > unix_sockets.3tcl ; \
	mv -v unix_sockets.3tcl ../man3/ ; \
	rm -v unix_sockets.n; \
	find $(DIR) -empty -prune -exec rmdir \{\} \; ;
