#!/usr/bin/make -f

export BDIR             := BUILD
export LDFLAGS          := -Wl,--as-needed    $(shell dpkg-buildflags --get LDFLAGS)
export CFLAGS           := -D_REENTRANT -Wall $(shell dpkg-buildflags --get CFLAGS)
export DESTDIR          := debian/tmp
DH_AUTO_OPTIONS         := -v -Sautoconf -B$(BDIR) --parallel

%: force
	dh "$@"

override_dh_auto_configure: $(BDIR)/configure-stamp

override_dh_auto_build:     $(BDIR)/build-arch-stamp

override_dh_auto_install:   $(BDIR)/build-arch-stamp
	dh_auto_install $(DH_AUTO_OPTIONS)


override_dh_auto_clean:
	rm -f $(BDIR)/build-arch-stamp $(BDIR)/build-indep-stamp $(BDIR)/configure-stamp
	dh_auto_clean  $(DH_AUTO_OPTIONS)
	
	rm -f core `find . \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
	        -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' -o -name 'config.log' \
	        -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -print` TAGS
	
	dh_autotools-dev_restoreconfig
	

$(BDIR)/configure-stamp:
	dh_autotools-dev_updateconfig
	dh_auto_configure $(DH_AUTO_OPTIONS) --                       \
	                   --verbose                                  \
	                   -- CFLAGS='$(CFLAGS)'                      \
	                      LDFLAGS='$(LDFLAGS)'
	touch "$@"

$(BDIR)/build-arch-stamp: $(BDIR)/configure-stamp
	dh_auto_build $(DH_AUTO_OPTIONS)
	touch "$@"

force debian/rules:



.PHONY: force debian/rules \
	override_dh_auto_build override_dh_auto_clean                  \
	override_dh_auto_configure override_dh_auto_install
