#! /usr/bin/make -f
#
# rules do debianize man-db package
#

# The name of the package
package = man-db

list_build_enabled=1
_debian_policy_ = 1
-include debian/policy


# build flags tha need overwrite
NLS = all

DBG-CFLAGS = -g -DENABLE_HTML
DBG-LDFLAGS = 
LDFLAGS = 

./configure incl/config.h.in:	./configure.in ./acconfig.h
	# this creates incl/config.h.in from acconfig.h
	autoheader
	# this creates configure from configure.in
	autoconf

GNUmakefile:	./configure
# create the makefile needed both from build and clean rules
	./configure --prefix=/usr --enable-setuid \
	            --with-db=db2 --with-device=latin1 

tags:
	-test -x $(which ctags-exuberant) && ctags-exuberant */*.[ch]
	touch $@

debug:		GNUmakefile tags
	${checkdir}
	cd src && rm -f *.o
	cd src && ${MAKE} nls="${NLS}" CFLAGS="${DBG-CFLAGS}" LDFLAGS="${DBG-LDFLAGS}" 
	# don't worry, this is not executed in normal building!
	cd src && sudo chown man.root man && sudo chmod 4755 man 

build:		GNUmakefile tags
# Builds the binary package.
	${checkdir}
	${MAKE} nls="${NLS}" 
	touch build

clean:		GNUmakefile
	${checkdir}
	-${MAKE} -i distclean
	-rm -f build man/index.* `find . -name '*~'`
	-rm -f core tags TAGS */*.i
	-rm -rf debian/tmp
	-cd debian && rm -f files* core substvars tags TAGS 
	-cd po && rm -f stamp-cat-id cat-id-tbl.c man-db.pot
	${update_standards_version} debian/control

binary-indep:	checkroot build
	${checkdir}

binary-arch:	checkroot build
	${checkdir}
	-rm -rf ${d_build}
	${install_dir}  ${d_dirs} ${d_doc}/examples
	# ==== install cron files in /etc ====
	cd debian && ${install_cron_files}
	# ==== install all ====
	# prefix must be relative because subdir's makefiles add ../  gosh!
	${MAKE} install prefix=debian/tmp/usr 
	chmod 775 ${d_bin}/*
	  # just to get the md5sum
	cd ${d_bin} && ln -f wrapper man
	cd ${d_bin} && ln -f wrapper mandb
	mv ${d_etc}/manpath.config ${d_doc}/examples
	  #
	${install_bin}  tools/chconfig	${d_mlib}
	${install_data} debian/config_md5	${d_mlib}
	# calculates md5 of manpath.config, and add to config_md5.
	cp /usr/lib/man-db/config_md5 debian/tmp || touch debian/tmp/config_md5 
	sed 's/\#.*$$//' ${d_doc}/examples/manpath.config |\
		tr -s '\t ' '  ' | sort -u | md5sum |\
		cat debian/tmp/config_md5 debian/config_md5 |\
		sort -u > ${d_mlib}/config_md5
	-rm debian/tmp/config_md5
	# ==== DEBIAN control files ====
	cd debian && ${install_DEBIAN_scripts}
	${install_data} debian/conffiles	${d_deb}
	# ==== manpages ====
	gzip -r9 ${d_man}
	# now do manual changes needed by debian
	# change locale names
	mv ${d_man}/de_DE.88591 ${d_man}/de
	mv ${d_man}/es_ES.88591 ${d_man}/es
	mv ${d_man}/it_IT.88591 ${d_man}/it
	mv ${d_man}/ja_JP.ujis  ${d_man}/ja
	rm -rf ${d_man}/de_DE.ascii
	#
	# ==== docs ====
	# particular documents that must be present with exactly this name
	${install_data}    debian/changelog     ${d_doc}/changelog.Debian
	${install_data}    debian/copyright     ${d_doc}/copyright
	#
	# documents to be installed by hand
	${install_data}	README	${d_doc}
	cd debian && ${install_data}	\
		man-db-manual.txt \
		man-db-manual.html \
					${d_doc}
	cd docs && ${install_data}	NEWS ToDo	${d_doc}
	cd docs && ${install_data}	ChangeLog	${d_doc}/changelog
	cd debian && ${install_data} manpage.example ${d_doc}/examples
	#
	# now compress only large documents
	cd ${d_doc} && ${compress_docs}
	#
	# doc-base subsystem: need also one row in postinst and in prerm
	cd debian && ${install_data}	doc-base	${d_doc-base}/${package}
	#
	# ==== clean dirs ====
	-${clean_dirs}
	# ==== md5sums ====
	cd ${d_build} && ${install_md5sums}
	  # this only after taken the md5sums ...
	-rm -f ${d_bin}/man ${d_bin}/mandb
	echo -e "#!/bin/sh\n/bin/echo -e \"Package man-db not yet configured.\n\""\
				> ${d_bin}/man
	cat ${d_bin}/man	> ${d_bin}/mandb
	chmod 775 ${d_bin}/man ${d_bin}/mandb
	chmod 775 ${d_mlib}/man ${d_mlib}/mandb
	# ==== finds dependencies ====
	dpkg-shlibdeps ${d_mlib}/man ${d_sbin}/*
	# ==== process control file ====
	dpkg-gencontrol -isp -p${package}
	chown -R root.root ${d_build}
	chmod -R go=rX ${d_build}
	${list_build_if_enabled}
	dpkg --build  ${d_build} ..


binary:	binary-indep	binary-arch

checkroot:
	${checkdir}
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot

