#!/usr/bin/make -f
# rules file for sgml-data
#
# I do not use debstd, debhelper, or any of that stuff.
# I believe in stripped down rules files; nothing that is not required
# I believe in readability through abstraction
#
# 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 --preserve-timestamps
install_program	:= install -o root -g root -m 755 --preserve-timestamps
make_dir	:= install -d -o root -g root -m 755
compress	:= gzip -9f


build:
	touch build

clean:
	$(checkdir)
	rm -f build
	find . -name "*~" | xargs rm -f
	rm -rf $(PREFIX)
	rm -f debian/files* core debian/substvars

binary-indep:	build
	$(checkdir)
	$(make_dir) $(PREFIX)
	$(make_dir) $(libdir) $(docdir)
	$(make_dir) $(sgmldir)/dtd $(sgmldir)/entities $(sgmldir)/declaration

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

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

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

        # The 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
	$(make_dir) $(sgmldir)/sgml
	set -e; for file in $(sgmldir)/declaration/*; do		\
		fbase=`basename $$file`					;\
		ln -s ../declaration/$$fbase $(sgmldir)/sgml/$$fbase	;\
	done

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

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

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

	# compress docdir (policy)	
	#find $(infodir) $(mandir) -type f | xargs $(compress)
	find $(docdir) -type f \( -size +4k -or -name "changelog*" \)	\
            ! -name "*.html" ! -name "*.gif"				\
            ! -name "copyright" | xargs $(compress)

	# move in control files
	$(make_dir) $(PREFIX)/DEBIAN
	$(install_program) debian/postinst debian/postrm $(PREFIX)/DEBIAN

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

	dpkg-gencontrol -isp
	chmod g-w $(PREFIX)/DEBIAN/control
	dpkg --build $(PREFIX) ..


binary-arch:	checkroot build
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

define checkdir
	test -f sgml.catalog
	test -f debian/rules
endef

# Below here is fairly generic really

binary:		binary-indep binary-arch

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

checkroot:
	$(checkdir)
	test root = "`whoami`"

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