#!/bin/sh
# Create docbook-xml links

# most things will be under this path.
DOCB=/usr/share/sgml/docbook

# potential location for xhtml/docbook.xsl
XSLDIRS="$DOCB/xsl-stylesheets* $DOCB/stylesheet/xsl/nwalsh"

# potential location for docbookx.dtd
DTDDIRS="$DOCB/xml-dtd* $DOCB/dtd/xml/*"

# look for a file (arg 1) in a set of dirs (arg 2). If it exists, create a link
# (arg 3), in the current directory to the dir.
condlink() {
	file=$1
	dirs=$2
	link=$3

	for d in $dirs
	do
		if [ -f $d/$file ]
		then
			dir=$d
			break
		fi
	done

	if [ -z "$dir" ]
	then
		echo Docbook support not found.  See README.  Faking it. >&2
		exit 1
	else
		ln -sfn "$dir" "$link"
	fi
}

condlink "xhtml/docbook.xsl" "$XSLDIRS" "link-xhtml"
condlink "docbookx.dtd" "$DTDDIRS" "link-dtd"
