#!/usr/bin/make -f

export BDIR             := BUILD
export LDFLAGS          := $(shell dpkg-buildflags --get LDFLAGS)  -Wl,--as-needed -Wl,-z,defs 
export CFLAGS           := $(shell dpkg-buildflags --get CFLAGS)   -Wall
export CPPFLAGS         := $(shell dpkg-buildflags --get CPPFLAGS) -D_FILE_OFFSET_BITS=64
export DESTDIR          := debian/tmp
DH_AUTO_OPTIONS         := -v -Sautoconf -B$(BDIR) --parallel
MAKEARGS                := JUDYLIB= DBILIB=

%: force
	dh "$@"


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

override_dh_auto_install:   $(BDIR)/build-arch-stamp
	dh_auto_install $(DH_AUTO_OPTIONS)  -- $(MAKEARGS)
	rm  $(DESTDIR)/usr/include/dictdplugin.h
	rm  $(DESTDIR)/usr/bin/dictdplugin-config

override_dh_auto_configure: $(BDIR)/configure-stamp

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                   \
	                --libexecdir=/usr/lib/dictd \
	                --datadir=/usr/share/dictd  \
	                --sysconfdir=/etc/dictd	    \
	                -- CFLAGS='$(CFLAGS)'       \
	                   CPPFLAGS='$(CPPFLAGS)'   \
	                   LDFLAGS='$(LDFLAGS)'     \
	                   AWK=awk
	
	touch "$@"

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


override_dh_installchangelogs:
	dh_installchangelogs -k NEWS

override_dh_installinit:
	dh_installinit -- start 20 2 3 4 5 . stop 20 1 .

override_dh_fixperms:
	dh_fixperms
	find debian -mindepth 6 -maxdepth 7 -path "*/usr/share/doc/*" \
	        '!' -name "*.gz" -name "README.*" -exec gzip -9 {} \;
	find debian -mindepth 4 -maxdepth 5 -path "*/dictd/etc/dictd/*" \
	        -name dictdconfig.alias -exec chmod 755 {} \;

force debian/rules:



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