#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
tmp := $(CURDIR)/debian/swish++
renamed := extract index search splitmail 
norename := man1/httpindex.1 man4/swish++.conf.4  man4/swish++.index.4  
fm := $(CURDIR)/debian/fixmanpage
patchdir := $(CURDIR)/debian/patches/*
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
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=3

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	for i in $(patchdir); do  patch -p0 < $${i}; done; 
	touch configure-stamp	

build: build-stamp



build-stamp: configure-stamp 
	dh_testdir

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

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	#-$(MAKE) clean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
#	$(MAKE)  install DESTDIR=$(tmp)
	$(makedirectory) $(tmp)/usr/lib/swish++
	$(makedirectory) $(tmp)/usr/bin
	$(install_file) WWW.pm $(tmp)/usr/lib/swish++/
	$(install_program) search $(tmp)/usr/bin/search++
	$(install_program) extract $(tmp)/usr/bin/extract++
	$(install_program) index $(tmp)/usr/bin/index++
	$(install_program) splitmail $(tmp)/usr/bin/splitmail++
	$(install_program) httpindex $(tmp)/usr/bin/httpindex
	#cd $(tmp)/usr/bin && for i in $(renamed); do mv $${i} $${i}++; done;
	cd $(CURDIR)/man/man1 && for i in $(renamed); do sh $(fm) $${i}.1; done; for i in $(renamed);\
	do mv $${i}.1 $${i}++.1; done; \
	cd $(CURDIR)/man && for i in $(norename); do sh $(fm) $${i}; done;
	#rm $(tmp)/usr/share/man/man8/searchd.8
	#rm $(tmp)/usr/share/man/man8/searchmonitor.8
	$(makedirectory) $(CURDIR)/debian/daemon
	$(install_program) searchmonitor $(CURDIR)/debian/daemon/searchmonitor
	$(install_program) searchc $(CURDIR)/debian/daemon/searchc
	$(install_program) searchd $(CURDIR)/debian/daemon/searchd
	# $(install_file) man/man8/searchd.txt $(CURDIR)/debian/daemon/searchd.txt
# 	$(install_file) man/man8/searchmonitor.txt $(CURDIR)/debian/daemon/searchmonitor.txt
# 	$(install_file) debian/searchc.txt $(CURDIR)/debian/daemon/searchc.txt
	# should customize the whole install as it's really opaque now
	# 


# 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 
	dh_installexamples $(CURDIR)/debian/email_indexing/ $(CURDIR)/swish++.conf  $(CURDIR)/www_example/ \
		$(CURDIR)/debian/daemon/ 
		# $(CURDIR)/searchd $(CURDIR)/man/man8/searchd.txt $(CURDIR)/man/man8/searchmonitor.txt $(CURDIR)/searchmonitor
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron
	dh_installman man/man1/splitmail++.1 man/man1/search++.1 man/man1/extract++.1 man/man1/index++.1 \
	man/man1/httpindex.1 man/man3/WWW.3 man/man4/swish++.conf.4 man/man4/swish++.index.4
	dh_installinfo
	dh_undocumented
	dh_installchangelogs Changes
	dh_link
	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 configure
