[MPlayer-dev-eng] [PATCH] Autoconfiguration for XML DOCS building system

Diego Biurrun diego at biurrun.de
Sat Jun 14 18:28:21 CEST 2003


Dmitry Baryshkov writes:
 > It took more time, than I thought.

No wonder, it's not that easy, good work!

 > Attached is a patch to main/DOCS/xml, that removes most configuration
 > options (HTMLDIR & SUBDIRS are left intact) from Makefile/Makefile.inc
 > 
 > Moreover, with this patch adding spport for other XSLT Processors/etc.
 > is easier (e.g. adding support for the Saxon XSLT Processor was a kind
 > of hack).

OK, I finally got around to checking this, I like but I did some
modifications, let's discuss it first before I commit.

Changes are spelling and cosmetics (you had a mixture of tabs and
spaces), as well as some more substantive things.

The Makefile now builds HTML by default now instead of printing a help
message.

You use things like

  if test "x$_catalog" != "x"
  if test "x$_chunk_xsl" = "x"

which is OK, but 

  if test -n "$_catalog"
  if test -z "$_chunk_xsl"

or if you prefer

  if [ -n "$_catalog" ]
  if [ -z "$_chunk_xsl" ]

are simpler IMHO.  The creation of html.xsl etc are also simplified
IMHO.
Let me know what you think (and whether it still works for you ;-)),
otherwise I will commit this during the next days.

Diego



diff -Nau xml.old/Makefile xml/Makefile
--- xml.old/Makefile	Sat Jun 14 18:06:25 2003
+++ xml/Makefile	Sat Jun 14 17:12:18 2003
@@ -1,67 +1,27 @@
 # Makefile for generating the HTML documentation
 
-#####[ Configuration ]##################################################
-
-# The xsltproc program.
-XSLTPROC = xsltproc
-
-# Another xslt converter.
-# If you want to use it, change also USE_SAXON to 1 (below)
-# Probably you must also change the path to saxon.jar.
-USE_SAXON = 0
-SAXON_COMMAND = java -cp /usr/share/java/saxon.jar com.icl.saxon.StyleSheet
-
-# The xmllint program.
-XMLLINT = xmllint
-
-# A colon separated list of catalog entry files.
-# Without this properly set up, xmllint and xsltproc might be unable
-# to find the DTDs for the system identifiers specified in the XML files.
-# If the SGML_CATALOG_FILES environment variable is not set, list one
-# or more catalogs here.
-#
-# on debian (potato?) systems, maybe others
-#SGML_CATALOG_FILES ?= /etc/sgml/catalog
-#
-# on Mandrake (9.0?) systems, maybe others
-SGML_CATALOG_FILES ?= /usr/share/sgml/docbook/xml-dtd-4.1.2/xmlcatalog
-#SGML_CATALOG_FILES ?= /usr/share/apps/ksgmltools2/customization/en/catalog
-
-# Full path of the "chunker" DocBook XSL stylesheet used to generate
-# the HTML files.
-#
-# on debian (potato?)
-#CHUNK_XSL = /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl
-#
-# on Mandrake (9.0?) systems, maybe others
-CHUNK_XSL = /usr/share/sgml/docbook/yelp/docbook/html/chunk.xsl
-
 # List of subdirectories to be processed.
 SUBDIRS = en fr
 
-# Here all generated html's go
+# Generated HTML files go here.
 HTML_TOP = ../HTML
 
-#####[ End of configuration ]###########################################
 
-export CHUNK_XSL SGML_CATALOG_FILES XMLLINT XSLTPROC SAXON_COMMAND USE_SAXON
+.PHONY: all
+all: build-html
 
-.PHONY: no-target
-no-target:
-	@echo "What to make?"
-	@echo
-	@echo "Targets"
-	@echo "*******"
+.PHONY: help
+help:
+	@echo "Targets:"
+	@echo "********"
 	@echo "all       : Build everything (same as build-html for now)."
 	@echo "build-html: Build HTML documentation."
+	@echo "test      : Check if build requirements are met."
 	@echo "clean-html: Purge the 'HTML' directory."
 	@echo "distclean : Remove ALL generated files."
 
-.PHONY: all
-all: build-html
-
 .PHONY: build-html
-build-html:
+build-html: xsltproc.sh
 	test -d $(HTML_TOP) || mkdir $(HTML_TOP)
 	for d in $(SUBDIRS); do\
 		test -f $$d/Makefile &&\
@@ -82,4 +42,7 @@
 
 .PHONY: distclean
 distclean: clean-html
-	-rm -f html.xsl
+	-rm -f html.xsl xsltproc.sh xmllint.sh
+
+xsltproc.sh: configure.sh
+	./configure.sh
diff -Nau xml.old/Makefile.inc xml/Makefile.inc
--- xml.old/Makefile.inc	Sat Jun 14 18:06:25 2003
+++ xml/Makefile.inc	Sat Jun 14 17:13:43 2003
@@ -1,10 +1,8 @@
 #
-# Makefile.inc for Makefiles in sub-directories.
+# Makefile.inc for Makefiles in subdirectories.
 #
 
-export SGML_CATALOG_FILES
-
-# Use customized html.xsl file if exists...
+# Use customized html.xsl file if it exists...
 ifeq (html.xsl,$(wildcard html.xsl))
 HTML_XSL := html.xsl
 XSL_DEPS := $(HTML_XSL) ../html.xsl ../html-common.xsl
@@ -13,19 +11,15 @@
 XSL_DEPS := $(HTML_XSL) ../html-common.xsl
 endif
 
-# Fall back to the default HTML stylesheet if not specified.
+# Fall back to the default HTML stylesheet if none is specified.
 HTML_STYLESHEET ?= ../default.css
 
 # This is the main target...
 $(HTMLDIR)/index.html: documentation.xml $(XSL_DEPS)
 	-rm -f $(HTMLDIR)/*
-	$(XMLLINT) --noout --noent --postvalid --catalogs $<
+	../xmllint.sh $<
 	cp $(HTML_STYLESHEET) $(HTMLDIR)/
-ifeq (0,$(USE_SAXON))
-	$(XSLTPROC) --catalogs -o $(HTMLDIR)/ $(HTML_XSL) $<
-else
-	cd $(HTMLDIR) && $(SAXON_COMMAND) $(CURDIR)/$< $(CURDIR)/$(HTML_XSL)
-endif
+	../xsltproc.sh $(HTMLDIR)/ $(HTML_XSL) $<
 
 ../html.xsl:
-	sh ../gen-html.xsl.sh $(CHUNK_XSL) > $@
+	cd .. && sh configure.sh $(CHUNK_XSL)
diff -Nau xml.old/configure.sh xml/configure.sh
--- xml.old/configure.sh	Thu Jan  1 01:00:00 1970
+++ xml/configure.sh	Sat Jun 14 18:13:14 2003
@@ -0,0 +1,215 @@
+#!/bin/sh
+
+# Script to check for catalogs, stylesheets, XSL processors and all
+# the other stuff necessary to convert the XML documentation.
+
+_xsltwrapper="xsltproc.sh"
+_xmllintwrapper="xmllint.sh"
+
+for _try_catalog in /etc/sgml/catalog /usr/share/sgml/docbook/xml-dtd-4.1.2/xmlcatalog /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
+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 stylesheet..."
+for _try_chunk_xsl in /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
+do
+  if test -f "$_try_chunk_xsl"
+  then
+    _chunk_xsl=$_try_chunk_xsl
+    break
+  fi
+done
+
+if test -z "$_chunk_xsl"
+then
+  echo "Not found."
+  _chunk_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl
+else
+  echo "Found chunk.xsl at $_chunk_xsl"
+fi
+
+cat > html.xsl << EOF
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- **************************************************
+     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
+
+
+
+echo "Looking for a valid XSLT processor..."
+# Checks for xsltproc, then checks for the Saxon processor (it needs Java).
+# Also checks for Jade/OpenJade.
+#FIXME: Add support for the xalan/xalan2 XSLT processors.
+
+if xsltproc --version &> /dev/null
+then
+  if test -n "$_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
+
+# xsltproc not found.
+# Now try to find a good Java virtual machine.
+# FIXME: We need more checks for Java virtual machines.
+if test -z "$_xsltcommand"
+then
+  for _try_java in java gij-3.3 gij-3.2 gij-3.1 gij-3.0 gij
+  do
+    if $_try_java --version > /dev/null 2>&1 || $_try_java -version > /dev/null 2>&1
+    then
+      _java=$_try_java
+      break
+    fi
+  done
+  # Try to find the right jar files for classpath.
+  # This must not trigger on something like saxon-fop-6.4.4.jar.
+  for _try_saxon_jar in /usr/share/java/saxon.jar /usr/local/share/java/saxon.jar /usr/share/java/saxon-[0-9]*.jar /usr/local/share/java/saxon-[0-9]*.jar
+  do
+    if test -f "$_try_saxon_jar"
+    then
+      _saxon_jar=$_try_saxon_jar
+      #Don't break to find the _latest_ saxon.jar.
+    fi
+  done
+  if test -n "$_saxon_jar"
+  then
+    if test -n "$_chunk_xsl"
+    then
+      _xsltcommand="cd \$1 && if test \"\`dirname \$2 | head -c 1\`\" = \".\" ; then $_java  -classpath $_saxon_jar com.icl.saxon.StyleSheet \$_IN_DIR/\$3 \$_IN_DIR/\$2 ; else $_java  -classpath $_saxon_jar com.icl.saxon.StyleSheet \$_IN_DIR/\$3 \$2 ;fi"
+      echo "Found the Saxon XSLT Processor ($_saxon_jar), using Java VM '$_java'."
+    else
+      echo "Found the Saxon XSLT processor but no stylesheets on your system."
+      echo "Saxon is unusable without stylesheets."
+    fi
+  fi
+fi
+
+if test -z "$_xsltcommand"
+then
+  # Java not found.
+  # now try openjade/jade.
+  for _try_jade in jade openjade
+  do
+    if command -v $_try_jade > /dev/null
+    then
+      _jade=$_try_jade
+      break
+    fi
+  done
+  if test -n "$_jade"
+  then
+    echo "xsltproc and Saxon XSLT processors not found."
+    echo "I will try to use OpenJade or Jade (using '$_jade')."
+    echo "They aren't (currently) fully supported, however."
+    for _try_docbook_dsl in /usr/share/sgml/docbook/stylesheet/dsssl/modular/html/docbook.dsl /usr/local/share/sgml/docbook/stylesheet/dsssl/modular/html/docbook.dsl 
+    do
+      if test -f "$_try_docbook_dsl"
+      then
+        _docbook_dsl=$_try_docbook_dsl
+        break
+      fi
+    done
+    for _try_xml_dcl in /usr/share/sgml/declaration/xml.dcl /usr/local/share/sgml/declaration/xml.dcl
+    do
+      if test -f "$_try_xml_dcl"
+      then
+        _xml_dcl=$_try_xml_dcl
+        break
+      fi
+    done
+      if test "x$_docbook_dsl" = "x" -o "x$_xml_dcl" = "x"
+      then
+  	echo "One of the files docbook.dsl and xml.dcl or both of them weren't found."
+  	echo "Bailing out."
+  	exit 1
+      fi
+    _xsltcommand="cd \$1 && $_jade -t xml -d $_docbook_dsl $_xml_dcl \$_IN_DIR/\$3 ; mv book1.html index.html"
+  else
+    echo "No valid XSLT processor found."
+    echo "Bailing out."
+    exit 1
+  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>
+_IN_DIR=\`pwd\`
+
+$_sgmlcatalog
+$_xsltcommand
+EOF
+
+chmod +x $_xsltwrapper
+
+
+
+for _try_xmllint in xmllint
+do
+  if command -v $_try_xmllint
+  then
+    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
+  _xmllint_command=true
+fi
+
+cat > $_xmllintwrapper << EOF
+#!/bin/sh
+# **************************************************
+# This file is generated automatically. DO NOT EDIT.
+# **************************************************
+# This is a small wrapper for XML lintian programs.
+$_sgmlcatalog
+$_xmllint_command
+EOF
+
+chmod +x $_xmllintwrapper
diff -Nau xml.old/gen-html.xsl.sh xml/gen-html.xsl.sh
--- xml.old/gen-html.xsl.sh	Sat Jun 14 18:06:25 2003
+++ xml/gen-html.xsl.sh	Thu Jan  1 01:00:00 1970
@@ -1,27 +0,0 @@
-#
-# Helper script to generate html.xsl.
-#
-
-if test $# -ne 1; then
-	echo "Usage: $0 <path to chunk.xsl>"
-	exit 1
-fi
-
-if test -f "$1"; then :; else
-	echo "$0: file not found: \"$1\""
-	exit 1
-fi
-
-cat << EOF
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- ***************************************************
-     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="$1"/>
-  <xsl:include href="html-common.xsl"/>
-
-</xsl:stylesheet>
-EOF
diff -Nau xml.old/html.xsl xml/html.xsl
--- xml.old/html.xsl	Thu Jan  1 01:00:00 1970
+++ xml/html.xsl	Sat Jun 14 18:01:44 2003
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- **************************************************
+     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="/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl"/>
+  <xsl:include href="html-common.xsl"/>
+
+</xsl:stylesheet>
diff -Nau xml.old/xmllint.sh xml/xmllint.sh
--- xml.old/xmllint.sh	Thu Jan  1 01:00:00 1970
+++ xml/xmllint.sh	Sat Jun 14 18:01:44 2003
@@ -0,0 +1,7 @@
+#!/bin/sh
+# **************************************************
+# This file is generated automatically. DO NOT EDIT.
+# **************************************************
+# This is a small wrapper for XML lintian programs.
+export SGML_CATALOG_FILES=/etc/sgml/catalog
+xmllint --noout --noent --postvalid --catalogs $*
Common subdirectories: xml.old/xsl and xml/xsl
diff -Nau xml.old/xsltproc.sh xml/xsltproc.sh
--- xml.old/xsltproc.sh	Thu Jan  1 01:00:00 1970
+++ xml/xsltproc.sh	Sat Jun 14 18:01:44 2003
@@ -0,0 +1,10 @@
+#!/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>
+_IN_DIR=`pwd`
+
+export SGML_CATALOG_FILES=/etc/sgml/catalog
+xsltproc --catalogs -o $1 $2 $3



More information about the MPlayer-dev-eng mailing list