#! /usr/bin/make -f
%:
	dh $@ --parallel

DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

dtmp=debian/trn4

override_dh_auto_configure:
	cp debian/Policy.sh .
	# Configure adds -DDEBUG for us when we use -g.
	./Configure -OdErs
	perl -pi -e "s,^egrep='[^']*/egrep',egrep='egrep'," config.sh
	./Configure -desS

ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
# This is nasty, but the set of things inserted into config.h by Configure
# is small enough that we should be able to get away with it.
override_dh_auto_build:
	dh_auto_build -- CC=$(DEB_HOST_GNU_TYPE)-gcc
endif

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) -i spotless

override_dh_auto_install:
	# Do the install ourselves, as we use a slightly different directory
	# layout to what 'make install' wants, and we may not want to strip
	# binaries.

override_dh_install:
	dh_install

	# Group-scanning configuration files.
	install -p -m 0644 default_topic $(dtmp)/etc/trn4/trn4top

	# Man pages.
	install -p -m 0644 trn.1 $(dtmp)/usr/share/man/man1/trn4.1
	for x in Pnews Rnmail strn; do \
		install -p -m 0644 $$x.1 \
			$(dtmp)/usr/share/man/man1/trn4-$$x.1; \
	done
	for x in nntplist trn-artchk; do \
		install -p -m 0644 debian/$$x.1 \
			$(dtmp)/usr/share/man/man1/trn4-$$x.1; \
	done

override_dh_installdocs:
	dh_installdocs
	mv $(dtmp)/usr/share/doc/trn4/changelog $(dtmp)/usr/share/doc/trn4/NEWS

override_dh_installchangelogs:
	dh_installchangelogs debian/changelog.upstream

override_dh_compress:
	dh_compress -X examples
