#! /usr/bin/make -f
#
# Last modification: Thu, 29 May 1997 10:28:49 +0300
#
# rules do debianize man-db package
#

# The name of the package
package = man-db
my-version = 63

list_build_enabled=1
_debian_policy_ = 1
-include debian/policy


# build flags tha need overwrite
NLS = all

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

# This rule is just a hack, and can be called by hand.
# The distributed source builds correctly without calling it.
.PHONY: debian/changelog
debian/changelog:
	if [ -r debian/changelog.src ]; then \
	if	[ "`cat /etc/debian_version`" = "1.3" ]; \
	then	echo "man-db (2.3.10-59bo${my-version}) bo-unstable; urgency=low" > $@ ; \
	elif	[ "`cat /etc/debian_version`" = "2.0" \
		-o "`cat /etc/debian_version`" = "2.0 (unstable)" ]; \
	then	echo "man-db (2.3.10-${my-version}) unstable; urgency=low" > $@ ; \
	fi &&	cat debian/changelog.src >> $@ ; fi

./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 

debug:		GNUmakefile
	${checkdir}
	# tags only on _my_ machine :-)
	-if [ "`uname -n`" = polacco ]; then ctags */*.[ch]; fi
	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
# Builds the binary package.
	${checkdir}
	# tags only on _my_ machine :-)
	-if [ "`uname -n`" = polacco ]; then ctags */*.[ch]; fi
	${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} 
	# ==== DEBIAN control files ====
	cd debian && ${install_DEBIAN_scripts}
	cd debian && ${install_data} conffiles	${d_deb}
	# ==== 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 
	# ==== 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
	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 .dwww-index manpage.example \
					${d_doc}
	cd docs && ${install_data}	ChangeLog NEWS ToDo	${d_doc}
	#
	# now compress only large documents
	cd ${d_doc} && ${compress_docs}
	#
	# menu subsystem: need also one row in postinst and in prerm
	cd debian && ${install_data}	menu	${d_menu}/${package}
	#
	# ==== clean dirs ====
	-${clean_dirs}
	# ==== md5sums ====
	cd ${d_build} && ${install_md5sums}
	# ==== finds dependencies ====
	dpkg-shlibdeps ${d_bin}/* ${d_sbin}/*
	# ==== process control file ====
	dpkg-gencontrol -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

