gendocs.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. #!/bin/sh -e
  2. # gendocs.sh -- generate a GNU manual in many formats. This script is
  3. # mentioned in maintain.texi. See the help message below for usage details.
  4. scriptversion=2012-09-02.17
  5. # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
  6. # Free Software Foundation, Inc.
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # Original author: Mohit Agarwal.
  22. # Send bug reports and any other correspondence to bug-texinfo@gnu.org.
  23. #
  24. # The latest version of this script, and the companion template, is
  25. # available from Texinfo CVS:
  26. # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh
  27. # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template
  28. #
  29. # An up-to-date copy is also maintained in Gnulib (gnu.org/software/gnulib).
  30. prog=`basename "$0"`
  31. srcdir=`pwd`
  32. scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh"
  33. templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
  34. : ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
  35. : ${MAKEINFO="makeinfo"}
  36. : ${TEXI2DVI="texi2dvi -t @finalout"}
  37. : ${DVIPS="dvips"}
  38. : ${DOCBOOK2HTML="docbook2html"}
  39. : ${DOCBOOK2PDF="docbook2pdf"}
  40. : ${DOCBOOK2PS="docbook2ps"}
  41. : ${DOCBOOK2TXT="docbook2txt"}
  42. : ${GENDOCS_TEMPLATE_DIR="."}
  43. : ${TEXI2HTML="texi2html"}
  44. unset CDPATH
  45. unset use_texi2html
  46. version="gendocs.sh $scriptversion
  47. Copyright 2012 Free Software Foundation, Inc.
  48. There is NO warranty. You may redistribute this software
  49. under the terms of the GNU General Public License.
  50. For more information about these matters, see the files named COPYING."
  51. usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
  52. Generate output in various formats from PACKAGE.texinfo (or .texi or
  53. .txi) source. See the GNU Maintainers document for a more extensive
  54. discussion:
  55. http://www.gnu.org/prep/maintain_toc.html
  56. Options:
  57. -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
  58. -o OUTDIR write files into OUTDIR, instead of manual/.
  59. --email ADR use ADR as contact in generated web pages.
  60. --docbook convert to DocBook too (xml, txt, html, pdf and ps).
  61. --html ARG pass indicated ARG to makeinfo or texi2html for HTML targets.
  62. --info ARG pass indicated ARG to makeinfo for Info, instead of --no-split.
  63. --texi2html use texi2html to generate HTML targets.
  64. --help display this help and exit successfully.
  65. --version display version information and exit successfully.
  66. Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
  67. Typical sequence:
  68. cd PACKAGESOURCE/doc
  69. wget \"$scripturl\"
  70. wget \"$templateurl\"
  71. $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
  72. Output will be in a new subdirectory \"manual\" (by default;
  73. use -o OUTDIR to override). Move all the new files into your web CVS
  74. tree, as explained in the Web Pages node of maintain.texi.
  75. Please do use the --email ADDRESS option to specify your bug-reporting
  76. address in the generated HTML pages.
  77. MANUAL-TITLE is included as part of the HTML <title> of the overall
  78. manual/index.html file. It should include the name of the package being
  79. documented. manual/index.html is created by substitution from the file
  80. $GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
  81. generic template for your own purposes.)
  82. If you have several manuals, you'll need to run this script several
  83. times with different MANUAL values, specifying a different output
  84. directory with -o each time. Then write (by hand) an overall index.html
  85. with links to them all.
  86. If a manual's Texinfo sources are spread across several directories,
  87. first copy or symlink all Texinfo sources into a single directory.
  88. (Part of the script's work is to make a tar.gz of the sources.)
  89. As implied above, by default monolithic Info files are generated.
  90. If you want split Info, or other Info options, use --info to override.
  91. You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML, and
  92. DVIPS to control the programs that get executed, and
  93. GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is
  94. looked for. With --docbook, the environment variables DOCBOOK2HTML,
  95. DOCBOOK2PDF, DOCBOOK2PS, and DOCBOOK2TXT are also respected.
  96. By default, makeinfo and texi2dvi are run in the default (English)
  97. locale, since that's the language of most Texinfo manuals. If you
  98. happen to have a non-English manual and non-English web site, see the
  99. SETLANG setting in the source.
  100. Email bug reports or enhancement requests to bug-texinfo@gnu.org.
  101. "
  102. calcsize()
  103. {
  104. size=`ls -ksl $1 | awk '{print $1}'`
  105. echo $size
  106. }
  107. MANUAL_TITLE=
  108. PACKAGE=
  109. EMAIL=webmasters@gnu.org # please override with --email
  110. htmlarg=
  111. infoarg=--no-split
  112. outdir=manual
  113. srcfile=
  114. while test $# -gt 0; do
  115. case $1 in
  116. --email) shift; EMAIL=$1;;
  117. --help) echo "$usage"; exit 0;;
  118. --version) echo "$version"; exit 0;;
  119. -s) shift; srcfile=$1;;
  120. -o) shift; outdir=$1;;
  121. --docbook) docbook=yes;;
  122. --html) shift; htmlarg=$1;;
  123. --info) shift; infoarg=$1;;
  124. --texi2html) use_texi2html=1;;
  125. -*)
  126. echo "$0: Unknown option \`$1'." >&2
  127. echo "$0: Try \`--help' for more information." >&2
  128. exit 1;;
  129. *)
  130. if test -z "$PACKAGE"; then
  131. PACKAGE=$1
  132. elif test -z "$MANUAL_TITLE"; then
  133. MANUAL_TITLE=$1
  134. else
  135. echo "$0: extra non-option argument \`$1'." >&2
  136. exit 1
  137. fi;;
  138. esac
  139. shift
  140. done
  141. # For most of the following, the base name is just $PACKAGE
  142. base=$PACKAGE
  143. if test -n "$srcfile"; then
  144. # but here, we use the basename of $srcfile
  145. base=`basename "$srcfile"`
  146. case $base in
  147. *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
  148. esac
  149. PACKAGE=$base
  150. elif test -s "$srcdir/$PACKAGE.texinfo"; then
  151. srcfile=$srcdir/$PACKAGE.texinfo
  152. elif test -s "$srcdir/$PACKAGE.texi"; then
  153. srcfile=$srcdir/$PACKAGE.texi
  154. elif test -s "$srcdir/$PACKAGE.txi"; then
  155. srcfile=$srcdir/$PACKAGE.txi
  156. else
  157. echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
  158. exit 1
  159. fi
  160. if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
  161. echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
  162. echo "$0: it is available from $templateurl." >&2
  163. exit 1
  164. fi
  165. case $outdir in
  166. /*) abs_outdir=$outdir;;
  167. *) abs_outdir=$srcdir/$outdir;;
  168. esac
  169. echo "Generating output formats for $srcfile"
  170. cmd="$SETLANG $MAKEINFO -o $PACKAGE.info $infoarg \"$srcfile\""
  171. echo "Generating info file(s)... ($cmd)"
  172. eval "$cmd"
  173. mkdir -p "$outdir/"
  174. tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info*
  175. info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"`
  176. # do not mv the info files, there's no point in having them available
  177. # separately on the web.
  178. cmd="$SETLANG ${TEXI2DVI} \"$srcfile\""
  179. echo "Generating dvi ... ($cmd)"
  180. eval "$cmd"
  181. # now, before we compress dvi:
  182. echo "Generating postscript..."
  183. ${DVIPS} $PACKAGE -o
  184. gzip -f -9 $PACKAGE.ps
  185. ps_gz_size=`calcsize $PACKAGE.ps.gz`
  186. mv $PACKAGE.ps.gz "$outdir/"
  187. # compress/finish dvi:
  188. gzip -f -9 $PACKAGE.dvi
  189. dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
  190. mv $PACKAGE.dvi.gz "$outdir/"
  191. cmd="$SETLANG ${TEXI2DVI} --pdf \"$srcfile\""
  192. echo "Generating pdf ... ($cmd)"
  193. eval "$cmd"
  194. pdf_size=`calcsize $PACKAGE.pdf`
  195. mv $PACKAGE.pdf "$outdir/"
  196. cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
  197. echo "Generating ASCII... ($cmd)"
  198. eval "$cmd"
  199. ascii_size=`calcsize $PACKAGE.txt`
  200. gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz"
  201. ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"`
  202. mv $PACKAGE.txt "$outdir/"
  203. html_split()
  204. {
  205. opt="--split=$1 $htmlarg --node-files"
  206. cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
  207. echo "Generating html by $1... ($cmd)"
  208. eval "$cmd"
  209. split_html_dir=$PACKAGE.html
  210. (
  211. cd ${split_html_dir} || exit 1
  212. ln -sf ${PACKAGE}.html index.html
  213. tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html
  214. )
  215. eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"`
  216. rm -f "$outdir"/html_$1/*.html
  217. mkdir -p "$outdir/html_$1/"
  218. mv ${split_html_dir}/*.html "$outdir/html_$1/"
  219. rmdir ${split_html_dir}
  220. }
  221. if test -z "$use_texi2html"; then
  222. opt="--no-split --html -o $PACKAGE.html $htmlarg"
  223. cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
  224. echo "Generating monolithic html... ($cmd)"
  225. rm -rf $PACKAGE.html # in case a directory is left over
  226. eval "$cmd"
  227. html_mono_size=`calcsize $PACKAGE.html`
  228. gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
  229. html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
  230. mv $PACKAGE.html "$outdir/"
  231. cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\""
  232. echo "Generating html by node... ($cmd)"
  233. eval "$cmd"
  234. split_html_dir=$PACKAGE.html
  235. (
  236. cd ${split_html_dir} || exit 1
  237. tar -czf "$abs_outdir/${PACKAGE}.html_node.tar.gz" -- *.html
  238. )
  239. html_node_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node.tar.gz"`
  240. rm -f "$outdir"/html_node/*.html
  241. mkdir -p "$outdir/html_node/"
  242. mv ${split_html_dir}/*.html "$outdir/html_node/"
  243. rmdir ${split_html_dir}
  244. else
  245. cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $htmlarg \"$srcfile\""
  246. echo "Generating monolithic html... ($cmd)"
  247. rm -rf $PACKAGE.html # in case a directory is left over
  248. eval "$cmd"
  249. html_mono_size=`calcsize $PACKAGE.html`
  250. gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
  251. html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
  252. mv $PACKAGE.html "$outdir/"
  253. html_split node
  254. html_split chapter
  255. html_split section
  256. fi
  257. echo Making .tar.gz for sources...
  258. d=`dirname $srcfile`
  259. (
  260. cd "$d"
  261. srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null` || true
  262. tar cvzfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles
  263. )
  264. texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
  265. if test -n "$docbook"; then
  266. cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
  267. echo "Generating docbook XML... ($cmd)"
  268. eval "$cmd"
  269. docbook_xml_size=`calcsize $PACKAGE-db.xml`
  270. gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz"
  271. docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"`
  272. mv $PACKAGE-db.xml "$outdir/"
  273. split_html_db_dir=html_node_db
  274. cmd="${DOCBOOK2HTML} -o $split_html_db_dir \"${outdir}/$PACKAGE-db.xml\""
  275. echo "Generating docbook HTML... ($cmd)"
  276. eval "$cmd"
  277. (
  278. cd ${split_html_db_dir} || exit 1
  279. tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
  280. )
  281. html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"`
  282. rm -f "$outdir"/html_node_db/*.html
  283. mkdir -p "$outdir/html_node_db"
  284. mv ${split_html_db_dir}/*.html "$outdir/html_node_db/"
  285. rmdir ${split_html_db_dir}
  286. cmd="${DOCBOOK2TXT} \"${outdir}/$PACKAGE-db.xml\""
  287. echo "Generating docbook ASCII... ($cmd)"
  288. eval "$cmd"
  289. docbook_ascii_size=`calcsize $PACKAGE-db.txt`
  290. mv $PACKAGE-db.txt "$outdir/"
  291. cmd="${DOCBOOK2PS} \"${outdir}/$PACKAGE-db.xml\""
  292. echo "Generating docbook PS... ($cmd)"
  293. eval "$cmd"
  294. gzip -f -9 -c $PACKAGE-db.ps >"$outdir/$PACKAGE-db.ps.gz"
  295. docbook_ps_gz_size=`calcsize "$outdir/$PACKAGE-db.ps.gz"`
  296. mv $PACKAGE-db.ps "$outdir/"
  297. cmd="${DOCBOOK2PDF} \"${outdir}/$PACKAGE-db.xml\""
  298. echo "Generating docbook PDF... ($cmd)"
  299. eval "$cmd"
  300. docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
  301. mv $PACKAGE-db.pdf "$outdir/"
  302. fi
  303. echo "Writing index file..."
  304. if test -z "$use_texi2html"; then
  305. CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
  306. /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
  307. else
  308. CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
  309. fi
  310. curdate=`$SETLANG date '+%B %d, %Y'`
  311. sed \
  312. -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
  313. -e "s!%%EMAIL%%!$EMAIL!g" \
  314. -e "s!%%PACKAGE%%!$PACKAGE!g" \
  315. -e "s!%%DATE%%!$curdate!g" \
  316. -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
  317. -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
  318. -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
  319. -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
  320. -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
  321. -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
  322. -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
  323. -e "s!%%PDF_SIZE%%!$pdf_size!g" \
  324. -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
  325. -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
  326. -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
  327. -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
  328. -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
  329. -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
  330. -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
  331. -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
  332. -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
  333. -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
  334. -e "s,%%SCRIPTURL%%,$scripturl,g" \
  335. -e "s!%%SCRIPTNAME%%!$prog!g" \
  336. -e "$CONDS" \
  337. $GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html"
  338. echo "Done, see $outdir/ subdirectory for new files."
  339. # Local variables:
  340. # eval: (add-hook 'write-file-hooks 'time-stamp)
  341. # time-stamp-start: "scriptversion="
  342. # time-stamp-format: "%:y-%02m-%02d.%02H"
  343. # time-stamp-end: "$"
  344. # End: