#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-

# $Id: rules,v 1.15 2005/01/06 19:32:53 mquinson Exp $

# Import Common Debian Build System (CDBS).
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

# Here is a badly nammed changelog file
DEB_INSTALL_CHANGELOGS_ALL = quilt.changes

# installing under debian/tmp...
DEB_MAKE_ENVVARS := BUILD_ROOT=$(CURDIR)/debian/tmp LC_ALL=C
DEB_MAKE_CHECK_TARGET = check

# ... and moving it to the right dir using dh_install
DEB_DH_INSTALL_SOURCEDIR := debian/tmp

# also specify the full path to sendmail, as requested by policy
DEB_CONFIGURE_EXTRA_FLAGS := --with-sendmail=/usr/sbin/sendmail

# distribute a text version of the doc
common-build-indep::
	mkdir doc/tmp || true
	cd doc/tmp; LC_ALL=C hevea ../main.tex ; LC_ALL=C hevea ../main.tex; LC_ALL=C hevea ../main.tex
	perl -pe 'if (/\\sh{.*}/) {s:\\sh{(.*)}:<I>$$1</I>:}'	\
	     < doc/tmp/main.html > doc/quilt.html
	LC_ALL=C perl -e '$$/ = undef; $$f=<>; $$f =~ s|<A[^>]*?HREF="[^"]*#[^"]*">(.*?)</A>|$$1|msg; print $$f;' < doc/tmp/main.html > doc/tmp/tmp.html
	LC_ALL=C lynx doc/tmp/tmp.html -dump > doc/quilt.txt
	pod2man -c Debhelper debian/dh_quilt_patch debian/dh_quilt_patch.1
	pod2man -c Debhelper debian/dh_quilt_unpatch debian/dh_quilt_unpatch.1

clean::
	rm -rf doc/quilt.txt doc/quilt.html doc/tmp test/.pc test/d
	rm -f compat/awk compat/sendmail
	rm -f debian/dh_quilt_patch.1 debian/dh_quilt_unpatch.1

# Don't even try to build the package when /proc is not mounted since the
# checks will fail after a long while. Closes: #380598
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
pre-build::
	@if ! [ -d /proc/1 ]; then \
	   echo "quilt needs a mounted /proc to correctly build";\
	   echo "If you really want to build without /proc, add nocheck to the DEB_BUILD_OPTIONS"; \
	   exit 1; \
	fi
endif

