#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

# This is the debhelper compatibility version to use.
export DH_COMPAT=3
# custom
tmp = $(CURDIR)/debian/blackhole-exim
install_file = install -p    -o root -g root -m 644
install_program = install -p    -o root -g root -m 755
makedirectory = install -p -d -o root -g root -m 755
make_sticky = install -p -d -o root -g root -m 1777
make_sticky_mail = install -p -d -o root -g mail -m 1777
patchdir = $(CURDIR)/debian/patches/*
#
LINTIANDIR:= $(tmp)/usr/share/lintian/overrides
package = blackhole-exim
# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

config.status: configure
	dh_testdir
	# Add here commands to configure the package.
	for i in $(patchdir); do  patch -p0 < $${i}; done;
	./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)   --enable-debug  --with-perl-bin=/usr/bin/perl --with-clamscan-bin=/usr/bin/clamscan  --with-razor-bin=/usr/bin/razor-check  --without-sophos-libs --without-tmicro-libs --disable-sql-config --enable-one-box  --prefix=/usr --enable-sendmail --enable-sendmail-setgid --without-mysql-includes --without-pgsql-includes --without-mysql-libs  --without-pgsql-includes           

build: build-stamp

build-stamp:  config.status
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	#/usr/bin/docbook-to-man debian/blackhole.sgml > blackhole.1

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	-$(MAKE) clean
	-test -r /usr/share/misc/config.sub && \
	  cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
	  cp -f /usr/share/misc/config.guess config.guess


	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs  

	# Add here commands to install the package into debian/blackhole.
	#patch -p0 < debian/prefix.patch
	$(makedirectory) $(tmp)/var/spool/blackhole
	$(makedirectory) $(tmp)/usr/share/blackhole	
	$(makedirectory) $(LINTIANDIR)
	$(make_sticky) $(tmp)/var/spool/blackhole/mime 
	$(make_sticky)  $(tmp)var/spool/blackhole/msg/cur 
	$(make_sticky)  $(tmp)/var/spool/blackhole/msg/new 
	$(make_sticky_mail)  $(tmp)/var/spool/blackhole/msg/tmp 
	$(make_sticky) $(tmp)/var/spool/blackhole/scanner 
	$(install_program) blackhole  $(tmp)/usr/bin 
	$(install_program) scripts/bhedit  $(tmp)/usr/bin 
	$(install_program) scripts/bhconf  $(tmp)/usr/bin 
	#$(install_program) scripts/bhtest  $(tmp)/usr/bin 
	$(install_program) scripts/bhinstall  $(tmp)/usr/bin 
	$(install_file) etc/dot-blackhole.temp $(tmp)/usr/share/blackhole
	$(install_file) etc/dot-muttrc-spam $(tmp)/usr/share/blackhole
	$(install_file) etc/dot-muttrc-virus $(tmp)/usr/share/blackhole
	$(install_file) debian/blackhole.conf $(tmp)/etc
	echo  -e '$(package): non-standard-dir-perm'\
        > $(LINTIANDIR)/$(package)
#$(MAKE)  prefix=`pwd`/debian/`dh_listpackages`/usr install

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf	
	dh_installdocs README TODO NEWS debian/QuickStart debian/README.Debian
	dh_installexamples byz_scripts scripts/parse_assassin_rules.pl scripts/parse_bad_wordlist.pl scripts/spam scripts/virus debian/dot-exim debian/blackhole.conf.example 
#	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
#	dh_installcron
	dh_installman debian/bh_doc/bhconf.1 debian/bh_doc/bhinstall.1 debian/bh_doc/blackhole.1 debian/bh_doc/dot_blackhole.5
#	dh_installinfo
#	dh_undocumented bhtest.1
	dh_installchangelogs ChangeLog
	dh_link  usr/share/man/man1/bhconf.1  usr/share/man/man1/bhedit.1  
	dh_strip
	dh_compress
#	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install 
