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

package		:= sgml-data

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

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

binary-indep:	build
	$(checkdir)
	$(checkroot)
	dh_clean -k
	$(make_dir) $(libdir) $(docdir)					\
	  $(sgmldir)/dtd $(sgmldir)/entities $(sgmldir)/declaration

#	 SGML catalog
	$(install_file) sgml.catalog $(libdir)/

#	 DTDs
	set -e; for file in dtd/*; do					\
		[ ! -f $$file ] ||					\
		  $(install_file) $$file $(sgmldir)/dtd/		;\
	done

#	 entities
	set -e; for file in entities/*; do				\
		[ ! -f $$file ] ||					\
		  $(install_file) $$file $(sgmldir)/entities/		;\
	done

#	 XML materials (entities and DTDs) go in $(sgmldir)/dtd/<dir>
	set -e								;\
	  for dir in xhtml-1.0 xhtml-1.1; do				\
	  $(make_dir) $(sgmldir)/dtd/$$dir				;\
	  for file in xml/$$dir/*; do					\
		[ ! -f $$file ] ||					\
		  $(install_file) $$file $(sgmldir)/dtd/$$dir/		;\
	  done								\
	done

#	 declarations
	set -e; for file in declarations/*; do				\
		[ ! -f $$file ] ||					\
		  $(install_file) $$file $(sgmldir)/declaration/	;\
	done
#	 compatability links
	ln -s html-4.decl $(sgmldir)/declaration/html.decl
	ln -s xml.dcl $(sgmldir)/declaration/xml.decl
	$(make_dir) $(sgmldir)/sgml
	set -e; for file in $(sgmldir)/declaration/*; do		\
		fbase=`basename $$file`					;\
		ln -s ../declaration/$$fbase $(sgmldir)/sgml/$$fbase	;\
	done

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

#	 create all the nice links as specified in SGML FS Guidelines
	./sgml-catalog-check.pl -l -v 0

#	 move in documentation
	$(install_file) copyright-w3o-documents.html $(docdir)/
	$(install_file) debian/README.Debian debian/TODO.Debian		\
	    debian/copyright $(docdir)/
	$(install_file) debian/changelog $(docdir)/

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

#	 check for bad links
	if [ `symlinks -r debian/tmp | grep dangling | wc -l` -gt 0 ]	;\
	then								\
		exit 1							;\
	fi

	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 sgml.catalog
	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:
