view DOCS/xml/configure @ 31471:da0291f41eb7

Move xsltproc target file hack to the Makefile.
author diego
date Wed, 23 Jun 2010 13:24:53 +0000
parents 7c10f547ce96
children f5b66007c5e1
line wrap: on
line source

#!/bin/sh

# Script to check for catalogs, stylesheets, XSL processors and all
# the other stuff necessary to convert the XML documentation.

_xsltwrapper="xsltproc.sh"

echo "Searching for XML catalogs..."
for _try_catalog in \
  /etc/sgml/catalog \
  /usr/share/xml/docbook/*/catalog.xml \
  /opt/local/share/xml/docbook-xml/*/catalog.xml \
  /usr/share/sgml/docbook/*/*catalog \
  /usr/share/apps/ksgmltools2/customization/en/catalog \
  /usr/share/sgml/catalog \
  /usr/local/share/sgml/catalog \
  /usr/lib/sgml/catalog \
  /usr/local/lib/sgml/catalog \
  /usr/share/docbook-xml42/catalog.xml \
  /usr/share/sgml/docbook/xmlcatalog
do
  if test -f "$_try_catalog"
  then
    _catalog=$_try_catalog
    break
  fi
done

if test -n "$_catalog"
then
  echo "Found SGML catalog at $_catalog"
  _sgmlcatalog="export SGML_CATALOG_FILES=$_catalog"
else
  echo "No SGML catalog found."
fi



echo "Searching for stylesheets..."
echo "Searching for html/chunk.xsl..."
for _try_chunk_xsl in \
  /usr/share/xml/docbook/*/html/chunk.xsl \
  /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
  /usr/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
  /usr/local/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
  /usr/local/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
  /usr/share/docbook-xsl/html/chunk.xsl \
  /usr/share/sgml/docbook/xsl-stylesheets*/html/chunk.xsl \
  /usr/share/xml/docbook/stylesheet/nwalsh/current/html/chunk.xsl \
  /opt/local/share/xsl/docbook-xsl/html/chunk.xsl \

do
  if test -f "$_try_chunk_xsl"
  then
    _chunk_xsl=$_try_chunk_xsl
    break
  fi
done

if test -z "$_chunk_xsl"
then
  _chunk_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl
  echo "Not found. Using default ($_chunk_xsl)"
  _fake_chunk_xsl=yes
else
  echo "Found chunk.xsl at $_chunk_xsl"
fi

echo "Searching for html/docbook.xsl..."
for _try_docbook_xsl in \
  /usr/share/xml/docbook/*/html/docbook.xsl \
  /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
  /usr/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
  /usr/local/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
  /usr/local/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
  /usr/share/docbook-xsl/html/docbook.xsl \
  /usr/share/sgml/docbook/xsl-stylesheets*/html/docbook.xsl \
  /usr/share/xml/docbook/stylesheet/nwalsh/current/html/docbook.xsl \
  /opt/local/share/xsl/docbook-xsl/html/docbook.xsl \

do
  if test -f "$_try_docbook_xsl"
  then
    _docbook_xsl=$_try_docbook_xsl
    break
  fi
done

if test -z "$_docbook_xsl"
then
  _docbook_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl
  echo "Not found. Using default ($_docbook_xsl)"
  _fake_docbook_xsl=yes
else
  echo "Found docbook.xsl at $_docbook_xsl"
fi

cat > html-chunk.xsl << EOF
<?xml version="1.0" encoding="utf-8"?>
<!-- **************************************************
     This file is generated automatically. DO NOT EDIT.
     ************************************************** -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:import href="$_chunk_xsl"/>
  <xsl:include href="html-common.xsl"/>

</xsl:stylesheet>
EOF


cat > html-single.xsl << EOF
<?xml version="1.0" encoding="utf-8"?>
<!-- **************************************************
     This file is generated automatically. DO NOT EDIT.
     ************************************************** -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:import href="$_docbook_xsl"/>
  <xsl:include href="html-common.xsl"/>

</xsl:stylesheet>
EOF

echo "Searching for DTD..."
#FIXME: This should prefer higher version numbers, not the other way around ..
for _try_dtd in \
  /usr/share/xml/docbook/*/dtd/4*/docbookx.dtd \
  /usr/share/xml/docbook/*/docbookx.dtd \
  /usr/share/sgml/docbook/*/docbookx.dtd \
  /usr/share/sgml/docbook/dtd/*/docbookx.dtd \
  /usr/share/sgml/docbook/dtd/xml/*/docbookx.dtd \
  /usr/share/docbook-xml*/docbookx.dtd \
  /opt/local/share/xml/docbook*/*/docbookx.dtd \
  /usr/share/apps/ksgmltools2/docbook/*/docbookx.dtd
do
  if test -f "$_try_dtd"
  then
    _dtd=$_try_dtd
    break
  fi
done

if test -z "$_dtd"
then
  _dtd=/usr/share/sgml/docbook/dtd/xml/4.1.2/docbookx.dtd
  echo "Not found. Using default ($_dtd)."
else
  echo "Found docbookx.dtd at $_dtd"
fi

for lang in `grep 'DOC_LANGS =' ../../config.mak|cut -d= -f2`; do
  cat > $lang/main.xml << EOF
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!-- **************************************************
     This file is generated automatically. DO NOT EDIT.
     ************************************************** -->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "$_dtd"
[
EOF

  for file in `find $lang en -name \*.xml -exec basename \{\} \; | sort -u`; do
    echo '<!ENTITY '$file' SYSTEM "'$file'">' >> $lang/main.xml
  done

  cat >> $lang/main.xml << EOF
]>
<book id="index" lang="$lang">
&documentation.xml;
</book>
EOF

done

echo "Looking for a valid XSLT processor..."
if xsltproc --version > /dev/null 2>&1
then
  if test -z "$_fake_chunk_xsl"
  then
    echo "Found xsltproc. If it works, it's probably the best choice."
    if test -n "$_catalog"
    then
      _xsltcommand="xsltproc --catalogs -o \$1 \$2 \$3"
    else
      _xsltcommand="xsltproc -o \$1 \$2 \$3"
    fi
  else
    echo "Found xsltproc but no stylesheets on your system."
    echo "xsltproc is unusable without stylesheets."
  fi
fi



cat > $_xsltwrapper << EOF
#!/bin/sh
# **************************************************
# This file is generated automatically. DO NOT EDIT.
# **************************************************
# This is a small wrapper script around many ways to call the XSLT processor.
# It accepts 3 arguments: <output_dir> <stylesheet_name> <main XML file name>

$_sgmlcatalog
$_xsltcommand
EOF

chmod +x $_xsltwrapper


echo "Searching for XML checker..."
for _try_xmllint in xmllint
do
  if command -v $_try_xmllint > /dev/null 2>&1
  then
    echo "Found $_try_xmllint"
    if test -n "$_catalog"
    then
      _xmllint_command="$_try_xmllint --noout --noent --postvalid --catalogs \$*"
    else
      _xmllint_command="$_try_xmllint --noout --noent --postvalid \$*"
    fi
    break
  fi
done

if test -z "$_xmllint_command"
then
  echo "Not found"
  _xmllint_command=true
fi

cat > xml.mak << EOF
CATALOG = $_catalog
XMLLINT_COMMAND = $_xmllint_command
EOF