#!/usr/bin/make -f
# rules file for sgml-data
#
# Some bytes in this file may have been touched by Ian Jackson,
# so I can never remove his name from this file.  Oh boy.

#
# todo: cvs-build function
#

package		:= sgml-data

# directory abstraction
prefix		:= debian/tmp
libdir		:= $(prefix)/usr/share/$(package)
sgmldir		:= $(prefix)/usr/share/sgml

install_file	:= install -o root -g root -m 644 -p
install_program	:= install -o root -g root -m 755 -p
make_dir	:= install -d -o root -g root -m 755
compress	:= gzip -9f


build:
#	nothing to be done

clean:
	$(checkdir)
	find . -name '*.bak' -o -name '*~' | xargs rm -f
	dh_clean

binary-indep:	build
	$(checkdir)
	$(checkroot)
	dh_clean -k

#	 install dtd, entities, and HTML stuff
	set -e; for dir in  `find dtd entities html -path '*/CVS' -prune -o -type d -print`; do	\
		$(make_dir) $(sgmldir)/$$dir				;\
	done

	set -e; for file in `find dtd entities html -path '*/CVS/*' -prune -o -type f -print`; do	\
		[ ! -f $$file ] ||					\
		  $(install_file) $$file $(sgmldir)/$$file		;\
	done

#	 declarations is a misnamed dir so we do it separately
	$(make_dir) $(sgmldir)/declaration
	set -e; for file in declarations/*; do				\
		[ ! -f $$file ] ||					\
		  $(install_file) $$file $(sgmldir)/declaration/	;\
	done

#	 compatability links
	ln -s ../html/dtd/4.01/HTML4.decl $(sgmldir)/declaration/html.decl
	ln -s xml.dcl $(sgmldir)/declaration/xml.decl
	$(make_dir) $(prefix)/usr/lib/sgml/declaration
	set -e; for file in $(sgmldir)/declaration/*; do		\
		fbase=`basename $$file`					;\
		ln -s ../../../share/sgml/declaration/$$fbase		\
		      $(prefix)/usr/lib/sgml/declaration/		;\
	done

#	 checker script, until this gets added to sgml-base
	$(make_dir) $(libdir)
	$(install_program) sgml-catalog-check.pl $(libdir)/

#	 create all the nice links as specified in SGML FS Guidelines
	set -e; for file in `find dtd entities html -name catalog -o -name '*.soc'`; do	\
	    echo "checking $$file"							;\
	    ./sgml-catalog-check.pl -l -v 0 -d $(sgmldir) $$file			;\
	done

#	 move in documentation
	dh_installdocs copyright-w3o-documents.html debian/xhtml1-hygene.patch
	dh_installchangelogs
	dh_installexamples examples/*
	dh_fixperms

#	 check that maintainer scripts are good
	sh -n debian/postinst
	sh -n debian/prerm

#	 check for bad links
	symlinks -r $(prefix) | grep dangling | wc -l

	dh_compress -i

	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i


binary-arch:	build
# nothing to be done

define checkdir
	test -f copyright-w3o-documents.html
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

define checkroot
	test `id -u` = 0
endef

.PHONY: binary binary-arch binary-indep clean

#Local variables:
#mode: makefile
#End:
