.master 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #!/bin/bash -e
  2. #
  3. # Libreboot documentation build script
  4. # The function index() borrows from gendocs.sh, part of gnulib, the
  5. # GNU Portability Library (https://www.gnu.org/software/gnulib/). The
  6. # objective is to generate a html document which indexes the libreboot
  7. # documentation in its various formats.
  8. #
  9. # index() does not assume a certain set of formats have been
  10. # generated. It generates the index based on which files are located
  11. # in $man_dir.
  12. # INITIALIZATION #
  13. ##################
  14. # Initialization for manual directory
  15. [ -d docs/manual ] || mkdir docs/manual
  16. # Initialization for building manuals
  17. pkgname="libreboot"
  18. name=$(basename $1) # Always defined; users do not execute directly
  19. constants="docs/constants.texi"
  20. man_dir="docs/manual/"
  21. texinfo_src="docs/libreboot.texi"
  22. resources_dir="docs/resources" # for including in html tar.gz
  23. css_path="" # TODO: add css?
  24. # Default variables
  25. prefix="resources/"
  26. preprefix="../"
  27. make_cmd="makeinfo"
  28. comp_cmd="gzip -f -9 -c"
  29. c_ext=".gz"
  30. meta_type="man"
  31. type="reg"
  32. is_html="no"
  33. make_opts=""
  34. use_install=""
  35. # Initialization for generating eps images
  36. images_path="docs/resources/images"
  37. # Initialization for making index.html
  38. template_dir="docs/templates/"
  39. pkg_title="GNU Libreboot manual"
  40. pkg_email="example@libreboot.org" # sample
  41. pkg_name="libreboot"
  42. cur_date=`date '+%B %d, %Y'`
  43. # In case users try to build more than one format at once.
  44. if [ $# -gt 2 ]; then
  45. echo "ERROR: Only one docs format can be built at once."
  46. exit 1
  47. fi
  48. case "$2" in
  49. "w")
  50. meta_type="web";;
  51. "")
  52. :;; # This is the normal usage case
  53. *)
  54. echo "ERROR: Only one docs format can be built at once."
  55. echo "If you are building html files for the libreboot website, use:"
  56. echo "\$ ./build docs <html-type> w"
  57. exit 1;;
  58. esac
  59. ### FUNCTIONS ####
  60. ##################
  61. set_constants()
  62. {
  63. echo "@set docsdir $1" > $constants
  64. echo "@set useinstall $2" >> $constants
  65. }
  66. check_eps()
  67. {
  68. printf "INFO: Checking if jpgs have been converted to eps... "
  69. for i in $(find $images_path); do
  70. tdir_name=$(dirname $i)
  71. tfile_name=$(basename ${i,,})
  72. tfile_ext=${tfile_name##*.}
  73. tfile_base=$(basename -s .jpg ${i,,})
  74. if [ $tfile_ext = "jpg" ] && [ ! -e "${tdir_name}/${tfile_base}.eps" ]; then
  75. printf "converting ${i} >>>\n ${tdir_name}/${tfile_base}.eps ...\n\n"
  76. convert $i eps2:${tdir_name}/${tfile_base}.eps # using eps2 reduces file size
  77. fi
  78. done
  79. printf "Done.\n"
  80. }
  81. # FUNCTION COPIED FROM gendocs.sh
  82. # Return size of $1 in something resembling kilobytes.
  83. calcsize()
  84. {
  85. size=`ls -ksl $1 | awk '{print $1}'`
  86. echo $size
  87. }
  88. # Concatenation function called by index
  89. concat_index()
  90. {
  91. if [ -e $man_dir$1 ]; then
  92. if [ -d $man_dir$1 ]; then
  93. echo "<li><a href=\"$1/index.html\">$2</a>$3</li>" >> "${man_dir}index.html"
  94. else
  95. echo "<li><a href=\"$1\">$2</a>$3</li>" >> "${man_dir}index.html"
  96. fi
  97. fi
  98. }
  99. # Main index function
  100. build_index()
  101. {
  102. sed \
  103. -e "s!%%TITLE%%!$pkg_title!g" \
  104. -e "s!%%PACKAGE%%!$pkg_name!g" \
  105. -e "s!%%DATE%%!$cur_date!g" \
  106. ${template_dir}gendocs_template_header >"${man_dir}index.html"
  107. for i in $(ls $man_dir); do
  108. [ -d $man_dir$i ] || size=`calcsize "${man_dir}${i}"`
  109. case $i in
  110. ${pkg_name}.dvi.gz)
  111. dvi_gz_size=$size;;
  112. ${pkg_name}_by-node.tar.gz)
  113. html_node_tgz_size=$size;;
  114. ${pkg_name}_by-section.tar.gz)
  115. html_section_tgz_size=$size;;
  116. ${pkg_name}_one-page.html)
  117. html_mono_size=$size;;
  118. ${pkg_name}_one-page.tar.gz)
  119. html_mono_gz_size=$size;;
  120. ${pkg_name}.info.gz)
  121. info_gz_size=$size;;
  122. ${pkg_name}.pdf)
  123. pdf_size=$size;;
  124. ${pkg_name}.pdf.gz)
  125. pdf_gz_size=$size;;
  126. ${pkg_name}.ps.gz)
  127. ps_gz_size=$size;;
  128. ${pkg_name}.txt)
  129. plaintext_size=$size;;
  130. ${pkg_name}.txt.gz)
  131. plaintext_gz_size=$size;;
  132. ${pkg_name}.texi.gz)
  133. texinfo_gz_size=$size;;
  134. *)
  135. :;;
  136. esac
  137. done
  138. concat_index "${pkg_name}_one-page.html" "HTML (${html_mono_size}K bytes)" " - entirely on one web page."
  139. concat_index "${pkg_name}_by-node" "HTML" " - with one web page per node."
  140. concat_index "${pkg_name}_by-section" "HTML" " - with one web page per section."
  141. concat_index "${pkg_name}_one-page.tar.gz" "HTML compressed (${html_mono_gz_size}K gzipped tar file)" " - entirely on one web page."
  142. concat_index "${pkg_name}_by-node.tar.gz" "HTML compressed (${html_node_tgz_size}K gzipped tar file)" " - with one web page per node."
  143. concat_index "${pkg_name}_by-section.tar.gz" "HTML compressed (${html_section_tgz_size}K gzipped tar file)" " - with one web page per section."
  144. concat_index "${pkg_name}.info.gz" "Info document (${info_gz_size}K bytes gzipped)."
  145. concat_index "${pkg_name}.txt" "ASCII text (${plaintext_size}K bytes)."
  146. concat_index "${pkg_name}.txt.gz" "ASCII text compressed (${plaintext_gz_size}K bytes gzipped)."
  147. concat_index "${pkg_name}.dvi.gz" "TeX dvi file (${dvi_gz_size}K bytes gzipped)."
  148. concat_index "${pkg_name}.pdf" "PDF file (${pdf_size}K bytes)."
  149. concat_index "${pkg_name}.pdf.gz" "PDF file compressed (${pdf_gz_size}K bytes gzipped)."
  150. concat_index "${pkg_name}.ps.gz" "Postscript file compressed (${ps_gz_size}K bytes gzipped)."
  151. concat_index "${pkg_name}.texi.gz" "Texinfo source (${texinfo_gz_size}K bytes gzipped)."
  152. sed -e "s!%%EMAIL%%!$pkg_email!g" ${template_dir}gendocs_template_footer >>"$man_dir/index.html"
  153. }
  154. #### OPTIONS #####
  155. ##################
  156. # options to makeinfo/texi2dvi and file names
  157. case "$name" in
  158. "dvi")
  159. check_eps
  160. make_opts="-q -c -e -o"
  161. type="tex"
  162. basefile="${pkgname}.dvi";;
  163. "html")
  164. type="dir"
  165. is_html="yes"
  166. make_opts="--html --no-warn --split=node --css-include=$css_path -o"
  167. basefile="${pkgname}_by-node";;
  168. "html-by-section")
  169. type="dir"
  170. is_html="yes"
  171. make_opts="--html --no-warn --split=section --css-include=$css_path -o"
  172. basefile="${pkgname}_by-section";;
  173. "html-one-page")
  174. is_html="yes"
  175. make_opts="--html --no-warn --no-split --css-include=$css_path -o"
  176. basefile="${pkgname}_one-page.html";;
  177. "info")
  178. make_opts="--no-warn --no-split -o"
  179. basefile="${pkgname}.info";;
  180. "pdf")
  181. type="tex"
  182. make_opts="-q -c -e -p -o"
  183. basefile="${pkgname}.pdf";;
  184. "plaintext")
  185. make_opts="--no-warn --no-split --plaintext -o"
  186. basefile="${pkgname}.txt";;
  187. "postscript")
  188. check_eps
  189. make_opts="-q -c -e --ps -o"
  190. type="tex"
  191. basefile="${pkgname}.ps";;
  192. "texinfo-gz")
  193. basefile="${pkgname}.texi"
  194. type="texi";;
  195. esac
  196. # split html and pdf/postscript need special paths to resources
  197. case "$type" in
  198. "dir")
  199. preprefix="../../";;
  200. "tex")
  201. preprefix=""
  202. make_cmd="texi2dvi";;
  203. esac
  204. # compress html using tar
  205. if [ $is_html = "yes" ]; then
  206. comp_cmd="tar czf"
  207. c_ext=".tar.gz"
  208. fi
  209. # set up special paths for web mode
  210. if [ $meta_type = "web" ]; then
  211. if [ $is_html = "yes" ]; then
  212. echo "INFO: Using web mode for $name"
  213. prefix="docs/"
  214. use_install="install/"
  215. else
  216. echo "WARNING: Using web mode has no effect for non-html output."
  217. fi
  218. fi
  219. # write pathnames (prefixes) to file
  220. set_constants "$preprefix$prefix" "$use_install"
  221. outfile="$man_dir$basefile"
  222. ###### MAIN ######
  223. ##################
  224. if [ $type = "texi" ]; then
  225. echo "Making compressed manual: $outfile$c_ext..."
  226. gzip -f -9 -c $texinfo_src > $outfile$c_ext
  227. else # The normal case
  228. echo "Writing manual: $outfile..."
  229. $make_cmd $make_opts $outfile $texinfo_src
  230. # Don't compress anything if in web mode
  231. if [ ! $meta_type = "web" ]; then
  232. echo "Making compressed manual: ${outfile%\.html}$c_ext..."
  233. # tar and gzip have different usages
  234. if [ $is_html = "yes" ]; then
  235. # Include resources in html tar archives, but not .eps
  236. # and remove .html extension for html-one-page
  237. $comp_cmd ${outfile%\.html}$c_ext $outfile $resources_dir --exclude=*eps
  238. else
  239. $comp_cmd $outfile > $outfile$c_ext
  240. fi
  241. echo "Building index..."
  242. build_index # TODO: when building all, do this only once
  243. fi
  244. fi
  245. echo "Done."