#! /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=4

# 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)

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

build-stamp:	build-arch-stamp
	dh_testdir
	./configure --prefix=/usr
	$(MAKE) all
	touch build-stamp

build-stamp:	build

clean:
	dh_testdir 
	-$(MAKE) clean
	rm -f build-arch-stamp install-arch-stamp
	dh_clean

install-stamp: build
	dh_testdir
	#dh_clean -k -a
	./configure
	$(MAKE) install DESTDIR=$(CURDIR)/debian/sagator/
	mkdir -p $(CURDIR)/debian/sagator-libclamav/usr/lib/sagator
	mv -f $(CURDIR)/debian/sagator/usr/lib/sagator/*clam*.so $(CURDIR)/debian/sagator-libclamav/usr/lib/sagator
	mkdir -p $(CURDIR)/debian/sagator-pydspam/usr/lib/sagator
	mv -f $(CURDIR)/debian/sagator/usr/lib/sagator/*dspam*.so $(CURDIR)/debian/sagator-pydspam/usr/lib/sagator \
		|| true
	rm -f $(CURDIR)/debian/var/spool/vscan
	touch install-stamp

install:	install-stamp

sagator: install
	dh_testdir
	dh_installdirs -p$@
	dh_installdocs -p$@
	chmod +x $(CURDIR)/debian/sagator/usr/share/doc/sagator/test/{smtptest,pattern,bigtest,mimeattach.py}
	dh_install -p$@
	dh_installinit -p$@
	dh_installman -p$@
	dh_installchangelogs ChangeLog
	dh_strip -p$@
	dh_compress -p$@ -X.pdf -X.html -X.css -X.png
	dh_installdebconf -p$@
	dh_md5sums -p$@
	dh_installdeb -p$@
	dh_gencontrol -p$@
	dh_fixperms -p$@
	dh_builddeb -p$@

sagator-libclamav: install
	dh_testdir
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_install -p$@
	dh_installchangelogs ChangeLog
	dh_strip -p$@
	dh_compress -p$@
	dh_makeshlibs -V -p$@
	dh_md5sums -p$@
	dh_installdeb -p$@
	dh_shlibdeps -l debian/sagator-libclamav/usr/lib -p$@
	dh_gencontrol -p$@
	dh_fixperms -p$@
	dh_builddeb -p$@

sagator-pydspam: install
	dh_testdir
	dh_installdirs -p$@
	dh_installdocs -p$@
	dh_install -p$@
	dh_installchangelogs ChangeLog
	dh_strip -p$@
	dh_compress -p$@
	dh_makeshlibs -V -p$@
	dh_md5sums -p$@
	dh_installdeb -p$@
	dh_shlibdeps -l debian/sagator-pydspam/usr/lib -p$@
	dh_gencontrol -p$@
	dh_fixperms -p$@
	dh_builddeb -p$@

# Build architecture independant packages using the common target.
binary-indep: install sagator

# Build architecture dependant packages using the common target.
binary-arch: install sagator-libclamav sagator-pydspam

binary: clean binary-indep binary-arch

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