Remove some debugging prints and add comments
[maxima.git] / doc / info / build_html.sh.in
blob3b45d1f5b0c2f0cd6f570efbf4b7463d12e8aa37
1 #!/bin/sh
3 usage () {
4 echo "build_html.sh [-lDFh?]"
5 echo " -l Specify language"
6 echo " -D Enable simple debugging of this script"
7 echo " -F Force makeinfo to build the docs"
8 echo " -h This help"
9 echo " -? This help"
10 echo "Build the html version of the manual, including both the single"
11 echo "page version and the multi-page version. This also builds all the"
12 echo "category information."
13 exit 1
16 while getopts "h?DFl:" arg
18 case $arg in
19 l) language=$OPTARG ;;
20 D) DEBUG=yes ;;
21 F) FORCE=--force ;;
22 h) usage ;;
23 \?) usage ;;
24 esac
25 done
27 pwd=`pwd`
28 if [ "x$language" = "x" ]
29 then
30 language=en
31 languagedir=@abs_srcdir@
32 languagedestdir=$pwd
33 texiinitfile=$pwd/@TEXI2HTML@
34 else
35 languagedir=@abs_srcdir@/$language
36 languagedestdir=$pwd
37 if [ "$language" = "pt_BR" ]
38 then language=pt
40 texiinitfile=$pwd/../@TEXI2HTML@
43 echo "$0: abs_srcdir=@abs_srcdir@, pwd=$pwd, language=$language, languagedir=$languagedir, texiinitfile=$texiinitfile"
45 includerfile=include-maxima.texi
47 # Extract all filenames that are included using @include commands in the order
48 # they are included
49 includedfiles=`@EGREP@ '^[[:space:]]*@include' $includerfile | @AWK@ '{ print $NF; }'`
51 # If output dir exists, remove it so we start clean
52 if [ -d tmp_html ]; then
53 rm -rf tmp_html
55 mkdir tmp_html
56 cp -r @abs_srcdir@/figures tmp_html
57 # "make distcheck" write-protects the source tree. We don't want our
58 # figures to inherit that attribute as we want to delete the temp folder
59 # again, later.
60 chmod -R u+w tmp_html
62 cat include-maxima.texi > tmp_html/include-maxima.texi
64 cd tmp_html
66 for f in $includedfiles
68 # Find the absolute path of the current element of $includedfiles
69 if [ -e $languagedir/$f ]
70 then includedfile_absolute=$languagedir/$f
71 else if [ -e @abs_srcdir@/$f ]
72 then includedfile_absolute=@abs_srcdir@/$f
73 else if [ -e ../../$f ]
74 then includedfile_absolute=../../$f
75 else if [ -e ../$f ]
76 then includedfile_absolute=../$f
77 else
78 includedfile_absolute=`pwd`/../$f
84 if [ -e $includedfile_absolute ]
85 then
86 if [ "X$DEBUG" = "Xyes" ]; then
87 echo "Taking the file $f from the path $includedfile_absolute"
89 else
90 echo Error: File $f cannot be found.
91 exit -1
94 filenamebase=`echo $includedfile_absolute | @SED@ -e 's/^.*\///;s/\.texi//'`
95 @SED@ -e 's/^@deffnx* *{[^}]*} *\([^[:blank:]]*\).*/@anchor{Item: '$filenamebase'\/deffn\/\1}\
96 &/' \
97 -e 's/^@defvrx* *{[^}]*} *\([^[:blank:]]*\).*/@anchor{Item: '$filenamebase'\/defvr\/\1}\
98 &/' \
99 -e 's/^@node *\([^,]*\).*/@anchor{Item: '$filenamebase'\/node\/\1}\
100 &/' $includedfile_absolute \
101 | @AWK@ 'BEGIN { iftex = 0; } /^@iftex/ {iftex = 1;} {if (!iftex) {print;}} /^@end iftex/ {iftex = 0;}' \
102 | @AWK@ '/@anchor/ {if (!(foo[$0])) {foo[$0] = 1; print;}} !/@anchor/' > $(basename $includedfile_absolute)
103 done
105 catprogname=make-categories.lisp
106 for f in *.texi
108 filenamebase=`echo $f | @SED@ -e 's/^.*\///;s/\.texi//'`
109 echo "(setq *filenamebase* \"$filenamebase\")"
110 echo "(setq items nil)"
111 cat $f
112 done | @AWK@ '!/^@c / && !/^@c$/ && (/^@deffn/ || /^@defvr/ || /^@end deffn/ || /^@end defvr/ || /@category/ || /@node/ || /^.setq .filenamebase/ || /^.setq items nil/)' | @SED@ -f @abs_srcdir@/extract_categories1.sed | @AWK@ -f @abs_srcdir@/extract_categories1.awk > $catprogname
114 if [ "@DEFAULTLISP@" = "gcl" ]
115 then lispprog="@GCL_NAME@"
116 lispargs="-batch -load $catprogname"
117 elif [ "@DEFAULTLISP@" = "clisp" ]
118 then lispprog="@CLISP_NAME@"
119 lispargs="$catprogname"
120 elif [ "@DEFAULTLISP@" = "cmucl" ]
121 then lispprog="@CMUCL_NAME@"
122 lispargs="-load $catprogname -eval (quit)"
123 elif [ "@DEFAULTLISP@" = "scl" ]
124 then lispprog="@SCL_NAME@"
125 lispargs="-load $catprogname -eval (quit)"
126 elif [ "@DEFAULTLISP@" = "ecl" ]
127 then lispprog="@ECL_NAME@"
128 lispargs="--shell $catprogname"
129 elif [ "@DEFAULTLISP@" = "ccl64" ]
130 then lispprog="@CCL64_NAME@"
131 lispargs="--load $catprogname --eval (quit)"
132 # NOT SURE ABOUT OPENMCL; SAME ARGS AS CCL/CCL64 OR DIFFERENT ??
133 elif [ "@DEFAULTLISP@" = "ccl" -o "@DEFAULTLISP@" = "openmcl" ]
134 then lispprog="@OPENMCL_NAME@"
135 lispargs="--load $catprogname --eval (quit)"
136 elif [ "@DEFAULTLISP@" = "sbcl" ]
137 then lispprog="@SBCL_NAME@"
138 lispargs="--script $catprogname"
139 elif [ "@DEFAULTLISP@" = "abcl" ]
140 then lispprog="@JRE@"
141 lispargs="-jar @ABCL_JAR@ --load $catprogname --eval (quit)"
142 elif [ "@DEFAULTLISP@" = "acl" ]
143 then lispprog="@ACL_NAME@"
144 lispargs="-L $catprogname --kill"
145 else
146 echo "$0: DEFAULTLISP = @DEFAULTLISP@ not recognized, assume '@DEFAULTLISP@ $catprogname' is acceptable."
147 lispprog="@DEFAULTLISP@"
148 lispargs="$catprogname"
151 echo "$0: execute category program: \"$lispprog\" $lispargs"
152 "$lispprog" $lispargs
154 # Some languages don't have documentation categories so we don't want
155 # to add the extra section if it's going to be empty. So for any
156 # language that has categories, maxima.texi MUST have the line "@c
157 # Include documentation categories" to indicate that we will add the
158 # section to the manual.
159 if @GREP@ -q '^@c Include documentation categories' $languagedir/maxima.texi; then
160 # Add documentation categories. First, replace @bye with @ifhtml
161 @SED@ -e 's/^@bye/@ifhtml/' $languagedir/maxima.texi > maxima.texi
163 # Add all Category-*.texi files to maxima.texi.
164 # If there aren't any the file named "Category-*.texi" cannot be found
165 # and therefore will be excluded by the 'if'.
166 ( for f in Category-*.texi; do
167 if [ -e "$f" ]; then
168 echo '@include' $f
170 done
171 # Done with categories files, so close the @ifhtml and mark the end
172 # of the file with @bye that was removed above.
173 echo @end ifhtml
174 echo @bye
175 ) >> maxima.texi
176 else
177 cat $languagedir/maxima.texi > maxima.texi
180 if [ "X$DEBUG" = "Xyes" ]; then
181 set -x
184 # If NEED_MATHJAX is set by configure, then the version of makeinfo is
185 # too old to support the customization variable HTML_MATH. If so,
186 # don't try to set the variable on the command line. If NEED_MATHJAX
187 # is not set, set the HTML_MATH variable so that makeinfo will include
188 # mathjax for us.
189 if [ -z "@NEED_MATHJAX@" ]; then
190 SET_HTML_MATH="--set-customization-variable HTML_MATH=mathjax"
193 # Currently the Russian documentation has errors in it, so we're just
194 # going to force makeinfo to build anyway.
196 # DO NOT do this for the English documentation! Fix the English
197 # documentation so that makeinfo runs without errors!
198 if [ "x$language" = "xru" ]; then
199 FORCE=--force
202 # --no-node-files so we don't have thousands of little html files
203 # There should be no errors in the texi files so don't use "--force -e
204 # 10000" to force building the docs. We want to fail building if
205 # there are errors now.
206 TEXIOPT="$FORCE --html -c OUTPUT_ENCODING_NAME=UTF-8 -e 10000 --document-lang=$language -I . -I $languagedir -I ../.. --css-include=@abs_srcdir@/manual.css -I @abs_srcdir@/figures --init-file $texiinitfile ${SET_HTML_MATH}"
207 # Show the commands.
208 set -x
209 @MAKEINFO@ $FORCE --split=chapter --no-node-files --output="$languagedestdir" $TEXIOPT maxima.texi
210 rc=$?
211 if [ $rc -ne 0 ]; then
212 echo Failed to build multi-page html docs
213 exit $rc
215 @MAKEINFO@ $FORCE --no-split --output="$languagedestdir/maxima_singlepage.html" $TEXIOPT maxima.texi
216 rc=$?
217 if [ $rc -ne 0 ]; then
218 echo Failed to build single page html doc
219 exit $rc
221 set +x
223 if [ "X$DEBUG" = "Xyes" ]; then
224 set -x
227 cd ..
229 if [ "X$DEBUG" != "Xyes" ]; then
230 rm -r -f tmp_html