#!/usr/bin/make -f

#DH_VERBOSE:=1
export PKG_CONFIG_PATH:=$(CURDIR)/debian/pkg-config/

%:
	dh $@

override_dh_auto_configure:
	# regenerate configure, since one of our patches modifies
	# configure.ac
	autoreconf
	dh_auto_configure

# dh_auto_install blindly dumps every thing in debian/mscgen/
# However this means that the package ends up with two upstream
# changelogs and COPYING, which is one too much of each.
override_dh_auto_install:
	dh_auto_install
	cd debian/mscgen/usr/share/doc/mscgen/ && \
	  rm -f COPYING && \
	  mv -f ChangeLog changelog

guard:
	dh_testdir
	# Move auto-generated out of the way to avoid "changes" 
	# to source.
	mkdir -p debian/save/ && \
	  mv src/language.c src/language.h src/lexer.c debian/save
	touch $@

build: guard
	dh $@

clean:
	dh $@
	# Restore the auto-generated files. Always succeed so we don't 
	# fail if we are cleaning twice in a row.
	(test -d debian/save && mv -f debian/save/* src/ && \
	  rmdir debian/save) || true
	rm -f guard configure aclocal.m4 config.h.in
	find -name 'Makefile.in' -delete
