Avoid passing test invalid arguments when string is empty.
[mplayer/glamo.git] / DOCS / xml / configure
blob880a8a8a399cc5a91cbdbc3c916a68315ce28b0c
1 #!/bin/sh
3 # Script to check for catalogs, stylesheets, XSL processors and all
4 # the other stuff necessary to convert the XML documentation.
6 _xsltwrapper="xsltproc.sh"
7 _xmllintwrapper="xmllint.sh"
9 echo "Searching for XML catalogs..."
10 for _try_catalog in \
11 /etc/sgml/catalog \
12 /usr/share/xml/docbook/*/catalog.xml \
13 /opt/local/share/xml/docbook-xml/*/catalog.xml \
14 /usr/share/sgml/docbook/xml-dtd-4.1.2/xmlcatalog \
15 /usr/share/apps/ksgmltools2/customization/en/catalog \
16 /usr/share/sgml/catalog \
17 /usr/local/share/sgml/catalog \
18 /usr/lib/sgml/catalog \
19 /usr/local/lib/sgml/catalog \
20 /usr/share/docbook-xml42/catalog.xml \
21 /usr/share/sgml/docbook/xmlcatalog
23 if test -f "$_try_catalog"
24 then
25 _catalog=$_try_catalog
26 break
28 done
30 if test -n "$_catalog"
31 then
32 echo "Found SGML catalog at $_catalog"
33 _sgmlcatalog="export SGML_CATALOG_FILES=$_catalog"
34 else
35 echo "No SGML catalog found."
40 echo "Searching for stylesheets..."
41 echo "Searching for html/chunk.xsl..."
42 for _try_chunk_xsl in \
43 /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
44 /usr/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
45 /usr/local/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl \
46 /usr/local/share/sgml/docbook/yelp/docbook/html/chunk.xsl \
47 /usr/share/docbook-xsl/html/chunk.xsl \
48 /usr/share/sgml/docbook/xsl-stylesheets*/html/chunk.xsl \
49 /usr/share/xml/docbook/stylesheet/nwalsh/current/html/chunk.xsl \
50 /opt/local/share/xsl/docbook-xsl/html/chunk.xsl \
53 if test -f "$_try_chunk_xsl"
54 then
55 _chunk_xsl=$_try_chunk_xsl
56 break
58 done
60 if test -z "$_chunk_xsl"
61 then
62 _chunk_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/chunk.xsl
63 echo "Not found. Using default ($_chunk_xsl)"
64 _fake_chunk_xsl=yes
65 else
66 echo "Found chunk.xsl at $_chunk_xsl"
69 echo "Searching for html/docbook.xsl..."
70 for _try_docbook_xsl in \
71 /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
72 /usr/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
73 /usr/local/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl \
74 /usr/local/share/sgml/docbook/yelp/docbook/html/docbook.xsl \
75 /usr/share/docbook-xsl/html/docbook.xsl \
76 /usr/share/sgml/docbook/xsl-stylesheets*/html/docbook.xsl \
77 /usr/share/xml/docbook/stylesheet/nwalsh/current/html/docbook.xsl \
78 /opt/local/share/xsl/docbook-xsl/html/docbook.xsl \
81 if test -f "$_try_docbook_xsl"
82 then
83 _docbook_xsl=$_try_docbook_xsl
84 break
86 done
88 if test -z "$_docbook_xsl"
89 then
90 _docbook_xsl=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/html/docbook.xsl
91 echo "Not found. Using default ($_docbook_xsl)"
92 _fake_docbook_xsl=yes
93 else
94 echo "Found docbook.xsl at $_docbook_xsl"
97 cat > html-chunk.xsl << EOF
98 <?xml version="1.0" encoding="utf-8"?>
99 <!-- **************************************************
100 This file is generated automatically. DO NOT EDIT.
101 ************************************************** -->
102 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
103 version="1.0">
105 <xsl:import href="$_chunk_xsl"/>
106 <xsl:include href="html-common.xsl"/>
108 </xsl:stylesheet>
112 cat > html-single.xsl << EOF
113 <?xml version="1.0" encoding="utf-8"?>
114 <!-- **************************************************
115 This file is generated automatically. DO NOT EDIT.
116 ************************************************** -->
117 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
118 version="1.0">
120 <xsl:import href="$_docbook_xsl"/>
121 <xsl:include href="html-common.xsl"/>
123 </xsl:stylesheet>
126 echo "Searching for DTD..."
127 #FIXME: This should prefer higher version numbers, not the other way around ..
128 for _try_dtd in \
129 /usr/share/xml/docbook/*/dtd/4*/docbookx.dtd \
130 /usr/share/xml/docbook/*/docbookx.dtd \
131 /usr/share/sgml/docbook/*/docbookx.dtd \
132 /usr/share/sgml/docbook/dtd/*/docbookx.dtd \
133 /usr/share/sgml/docbook/dtd/xml/*/docbookx.dtd \
134 /usr/share/docbook-xml*/docbookx.dtd \
135 /opt/local/share/xml/docbook-xml/*/docbookx.dtd \
136 /usr/share/apps/ksgmltools2/docbook/*/docbookx.dtd
138 if test -f "$_try_dtd"
139 then
140 _dtd=$_try_dtd
141 break
143 done
145 if test -z "$_dtd"
146 then
147 _dtd=/usr/share/sgml/docbook/dtd/xml/4.1.2/docbookx.dtd
148 echo "Not found. Using default ($_dtd)."
149 else
150 echo "Found docbookx.dtd at $_dtd"
153 for lang in `grep 'SUBDIRS =' Makefile|cut -d= -f2`; do
154 cat > $lang/main.xml << EOF
155 <?xml version="1.0" encoding="utf-8" standalone="no"?>
156 <!-- **************************************************
157 This file is generated automatically. DO NOT EDIT.
158 ************************************************** -->
159 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
160 "$_dtd"
164 for file in `find $lang en -name \*.xml -exec basename \{\} \; | sort -u`; do
165 echo '<!ENTITY '$file' SYSTEM "'$file'">' >> $lang/main.xml
166 done
168 cat >> $lang/main.xml << EOF
170 <book id="index" lang="$lang">
171 &documentation.xml;
172 </book>
175 done
177 echo "Looking for a valid XSLT processor..."
178 # Checks for xsltproc, then checks for the Saxon processor (it needs Java).
179 # Also checks for Jade/OpenJade.
180 #FIXME: Add support for the xalan/xalan2 XSLT processors.
182 if xsltproc --version &> /dev/null
183 then
184 if test -z "$_fake_chunk_xsl"
185 then
186 echo "Found xsltproc. If it works, it's probably the best choice."
187 if test -n "$_catalog"
188 then
189 _xsltcommand="xsltproc --catalogs -o \$1 \$2 \$3"
190 else
191 _xsltcommand="xsltproc -o \$1 \$2 \$3"
193 else
194 echo "Found xsltproc but no stylesheets on your system."
195 echo "xsltproc is unusable without stylesheets."
199 # xsltproc not found.
200 # Now try to find a good Java virtual machine.
201 # FIXME: We need more checks for Java virtual machines.
202 if test -z "$_xsltcommand"
203 then
204 #FIXME: Add more suitable machines!!!
205 for _try_java in java gij-3.3 gij-3.2 gij-3.1 gij-3.0 gij
207 if $_try_java --version > /dev/null 2>&1 || $_try_java -version > /dev/null 2>&1
208 then
209 _java=$_try_java
210 break
212 done
213 if test -z "$_java"
214 then
215 echo "Java VM not found."
216 else
217 # Try to find the right jar files for classpath.
218 # This must not trigger on something like saxon-fop-6.4.4.jar.
219 for _try_saxon_jar in \
220 /usr/share/java/saxon-[0-9]*.jar \
221 /usr/local/share/java/saxon-[0-9]*.jar \
222 /usr/share/java/saxon.jar \
223 /usr/local/share/java/saxon.jar
225 if test -f "$_try_saxon_jar"
226 then
227 _saxon_jar=$_try_saxon_jar
228 #Don't break to find the _latest_ saxon.jar.
230 done
231 if test -n "$_saxon_jar"
232 then
233 if test -z "$_fake_chunk_xsl"
234 then
235 # _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"
236 _xsltcommand="
237 if test \"\`dirname \$2 | head -c 1\`\" = \".\"
238 then
239 _STYLESHEET=\$_IN_DIR/\$2
240 else
241 _STYLESHEET=\$2
244 if test -d \$1
245 then
246 _DIRNAME=\"\$1\"
247 _OUTPUT=\"\"
248 else
249 _DIRNAME=\"\`dirname \$1\`\"
250 _OUTPUT=\"-o \`basename \$1\`\"
253 cd \$_DIRNAME &&
254 java -classpath /usr/share/java/saxon.jar com.icl.saxon.StyleSheet \$_OUTPUT \$_IN_DIR/\$3 \$_STYLESHEET
257 echo "Found the Saxon XSLT Processor ($_saxon_jar), using Java VM '$_java'."
258 else
259 echo "Found the Saxon XSLT processor but no stylesheets on your system."
260 echo "Saxon is unusable without stylesheets."
266 if test -z "$_xsltcommand"
267 then
268 # Java not found.
269 # now try openjade/jade.
270 for _try_jade in jade openjade
272 if command -v $_try_jade > /dev/null
273 then
274 _jade=$_try_jade
275 break
277 done
278 if test -n "$_jade"
279 then
280 echo "xsltproc and Saxon XSLT processors not found."
281 echo "I will try to use OpenJade or Jade (using '$_jade')."
282 echo "They aren't (currently) fully supported, however."
283 for _try_docbook_dsl in \
284 /usr/share/sgml/docbook/stylesheet/dsssl/modular/html/docbook.dsl \
285 /usr/local/share/sgml/docbook/stylesheet/dsssl/modular/html/docbook.dsl
287 if test -f "$_try_docbook_dsl"
288 then
289 _docbook_dsl=$_try_docbook_dsl
290 break
292 done
293 for _try_xml_dcl in \
294 /usr/share/sgml/declaration/xml.dcl \
295 /usr/local/share/sgml/declaration/xml.dcl
297 if test -f "$_try_xml_dcl"
298 then
299 _xml_dcl=$_try_xml_dcl
300 break
302 done
303 if test "x$_docbook_dsl" = "x" -o "x$_xml_dcl" = "x"
304 then
305 echo "One of the files docbook.dsl and xml.dcl or both of them weren't found."
306 echo "Bailing out."
307 exit 1
309 _xsltcommand="cd \$1 && $_jade -t xml -d $_docbook_dsl $_xml_dcl \$_IN_DIR/\$3"
310 else
311 echo "No valid XSLT processor found."
312 echo "Bailing out."
313 exit 1
319 cat > $_xsltwrapper << EOF
320 #!/bin/sh
321 # **************************************************
322 # This file is generated automatically. DO NOT EDIT.
323 # **************************************************
324 # This is a small wrapper script around many ways to call the XSLT processor.
325 # It accepts 3 arguments: <output_dir> <stylesheet_name> <main XML file name>
326 _IN_DIR=\`pwd\`
328 $_sgmlcatalog
329 $_xsltcommand
332 chmod +x $_xsltwrapper
335 echo "Searching for XML checker..."
336 for _try_xmllint in xmllint
338 if command -v $_try_xmllint > /dev/null 2>&1
339 then
340 echo "Found $_try_xmllint"
341 if test -n "$_catalog"
342 then
343 _xmllint_command="$_try_xmllint --noout --noent --postvalid --catalogs \$*"
344 else
345 _xmllint_command="$_try_xmllint --noout --noent --postvalid \$*"
347 break
349 done
351 if test -z "$_xmllint_command"
352 then
353 echo "Not found"
354 _xmllint_command=true
357 cat > $_xmllintwrapper << EOF
358 #!/bin/sh
359 # **************************************************
360 # This file is generated automatically. DO NOT EDIT.
361 # **************************************************
362 # This is a small wrapper for XML lintian programs.
363 $_sgmlcatalog
364 $_xmllint_command
367 chmod +x $_xmllintwrapper