Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / solenv / bin / mkdocs.sh
blob99579f71340a1048ffd415162060c52e91cea9e4
1 #!/usr/bin/env bash
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # Doxygen / README doc generation
11 # See git for contributors
14 function header {
15 title=$1
16 breadcrumb=$2
17 output=$3
19 cat - > $output <<EOF
20 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
21 <html>
22 <head>
23 <title>$title</title>
25 <style>
26 * { margin: 0; padding: 0; }
27 body { font-family: sans-serif; font-size: 12px; }
28 #head { padding: 20px; background: #00A500; }
29 #head a { color: #000; }
30 #body { padding: 20px; }
31 #foot { padding: 10px; font-size: 9px; border-top: 1px #18A303 solid; margin-top: 25px; }
32 p { line-height: 1.7em; margin-bottom: 1em; }
33 pre { margin-bottom: 0.5em; }
34 .multi-col { -moz-column-width: 20em; -webkit-column-width: 20em; -moz-column-gap: 1em; -webkit-column-gap: 1em; }
35 h1 { margin-bottom: 0.5em; }
36 h2,h3,h4 { margin: 1.3em 0 0.5em 0; }
37 ul, ol { margin: 0.5em 1.5em; }
38 </style>
39 </head>
40 <body>
41 <div id="head">
42 <h1>$title</h1>
43 <p>$breadcrumb</p>
44 </div>
45 <div id="body" style="multi-col">
46 EOF
49 function footer {
50 output=$1
52 cat - >> $output <<EOF
54 </div>
55 <div id="foot">
56 <small>
57 <p>Generated by Libreoffice <a href="https://cgit.freedesktop.org/libreoffice/core/plain/solenv/bin/mkdocs.sh">Module Description Tool</a></p>
58 <p>Last updated:
59 EOF
60 LANG= date >> $output
61 cat - >> $output <<EOF
62 </p>
63 </small>
64 </div>
65 </body>
66 </html>
67 EOF
71 function proc_text {
72 # Local links: [[...]]
73 # Git links: [git:...]
74 # Other remote links: [...]
75 # Headings: == bleh ==
76 # Paragraphs: \n\n
77 sed -re ' s/\[\[([-_a-zA-Z0-9]+)\]\]/<a href="\1.html">\1<\/a>/g' - \
78 | sed -re ' s/\[git:([^]]+)\]/<a href="https:\/\/cgit.freedesktop.org\/libreoffice\/core\/tree\/\1">\1<\/a>/g' \
79 | sed -re ' s/\[([^]]+)\]/<a href="\1">\1<\/a>/g' \
80 | sed -re ' s/====([^=]+)====/<h4>\1<\/h4>/g' \
81 | sed -re ' s/===([^=]+)===/<h3>\1<\/h3>/g' \
82 | sed -re ' s/==([^=]+)==/<h2>\1<\/h2>/g' \
83 | sed -re ':a;N;$!ba;s/\n\n/<\/p><p>/g' \
84 | awk 'BEGIN { print "<p>" } { print } END { print "</p>" }'
87 function proc_text_markdown {
88 sed -re ' s/\[\[([-_a-zA-Z0-9]+)\]\]/<a href="\1.html">\1<\/a>/g' - \
89 | sed -re ' s/\[git:([^]]+)\]/<a href="https:\/\/cgit.freedesktop.org\/libreoffice\/core\/tree\/\1">\1<\/a>/g'
92 function check_cmd {
93 cmds_needed="$1"
94 error_msg="$2"
96 found=0; cmd=
97 for cmd_needed in $cmds_needed; do
98 which $cmd_needed > /dev/null 2>&1 && { found=1; cmd=$cmd_needed; }
99 done
100 if [ $found = 0 ]; then
101 echo "$error_msg" >&2
102 exit 1
104 alias "${cmds_needed%% *}"=$cmd
107 function setup {
108 parm=$1
109 if [ -z "${!parm}" ] ; then
110 echo "grep \"${parm}=\" ./config_host.mk | sed -re \" s/${parm}=//\")"
111 echo "$parm=$(grep \"${parm}=\" ./config_host.mk | sed -re \" s/${parm}=//\")"
112 eval "$parm=$(grep \"${parm}=\" ./config_host.mk | sed -re \" s/${parm}=//\")"
114 if [ -z "${!parm}" ] ; then
115 echo "could not determine $parm" >&2
116 exit 1
120 # binaries that we need
121 check_cmd doxygen "You need doxygen for doc generation"
122 check_cmd dot "You need the graphviz tools to create the nice inheritance graphs"
123 check_cmd "markdown markdown2" "You need either markdown or markdown2 in order to convert README.md into html"
125 # suck setup
126 setup "SOLARINC"
127 shopt -s nullglob
129 # Title of the documentation
130 DOXYGEN_PROJECT_PREFIX="LibreOffice"
132 # get list of modules
133 if [ -z "$INPUT_PROJECTS" ]; then
134 INPUT_PROJECTS="`ls */Module_*.mk | sed 's#/.*##'`"
138 # output directory for generated documentation
139 BASE_OUTPUT="$1"
140 mkdir -p "$BASE_OUTPUT" || {
141 echo "Cannot create $BASE_OUTPUT"
142 exit 1
145 # paths for binary and configuration file
146 BASE_PATH=`pwd`
147 DOXYGEN_CFG="$2"
148 if test ! -f "$DOXYGEN_CFG"; then
149 echo "doxygen.cfg not found"
150 exit 1
153 # strip -I. and bin -I prefix; exlude system headers
154 DOXYGEN_INCLUDE_PATH=`echo $SOLARINC | sed -e 's/-I\.//g' -e 's/ -I/ /'g -e 's/ -isystem/ /g' -e 's|/usr/[^ ]*| |g'`
156 # setup version string
157 DOXYGEN_VERSION="master"
160 ###################################################
162 # Generate docs
164 ###################################################
166 # cleanup
167 echo "cleaning up" && rm -rf $BASE_OUTPUT/*
169 # make the stuff world-readable
170 umask 022
172 # generate docs
173 echo "generating doxygen docs"
174 DOXYGEN_REF_TAGFILES=""
175 for PROJECT in $INPUT_PROJECTS;
177 # avoid processing of full project subdirs, only add source and inc
179 # project header files can be in $PROJECT/inc and/or include/$PROJECT
180 if [ -d "$PROJECT/inc" ]; then
181 PROJECT_INCLUDE="$PROJECT/inc"
182 else
183 PROJECT_INCLUDE=""
186 if [ -d "include/$PROJECT" ]; then
187 PROJECT_INCLUDE="$PROJECT_INCLUDE include/$PROJECT"
188 if [ "$PROJECT" = "sal" ]; then
189 PROJECT_INCLUDE="$PROJECT_INCLUDE include/osl include/rtl"
193 DOXYGEN_INPUT=`printf "%s" "$PROJECT/source $PROJECT_INCLUDE"`
195 DOXYGEN_OUTPUT="$BASE_OUTPUT/$PROJECT"
196 DOXYGEN_OUR_TAGFILE="$DOXYGEN_OUTPUT/$PROJECT.tags"
197 DOXYGEN_PROJECTNAME="$DOXYGEN_PROJECT_PREFIX Module $PROJECT"
199 # export variables referenced in doxygen config file
200 export DOXYGEN_INPUT
201 export DOXYGEN_OUTPUT
202 export DOXYGEN_INCLUDE_PATH
203 export DOXYGEN_VERSION
204 export DOXYGEN_OUR_TAGFILE
205 export DOXYGEN_REF_TAGFILES
206 export DOXYGEN_PROJECTNAME
208 # debug
209 echo "Calling $DOXYGEN_PATH/doxygen $DOXYGEN_CFG with"
210 echo "Input: $DOXYGEN_INPUT"
211 echo "Output: $DOXYGEN_OUTPUT"
212 echo "Include: $DOXYGEN_INCLUDE_PATH"
213 echo "Version: $DOXYGEN_VERSION"
214 echo "Tagfile: $DOXYGEN_OUR_TAGFILE"
215 echo "Ref-Tags: $DOXYGEN_REF_TAGFILES"
216 echo "Title: $DOXYGEN_PROJECTNAME"
218 nice -15 doxygen "$DOXYGEN_CFG" >>$BASE_OUTPUT/doxygen.log 2>&1 || exit 1
220 # setup referenced tagfiles for next round
221 DOXYGEN_REF_TAGFILES="$DOXYGEN_REF_TAGFILES $DOXYGEN_OUR_TAGFILE=$BASE_URL/$PROJECT/html"
222 done
224 # generate entry page
225 echo "generating index page"
226 header "LibreOffice Modules" " " "$BASE_OUTPUT/index.html"
227 for module_name in *; do
228 if [ -d $module_name ]; then
229 cur_file=$(echo $module_name/README* $module_name/readme.txt*)
230 if [ -f "$cur_file" ]; then
231 # write index.html entry
232 text="<h2><a href=\"${module_name}.html\">${module_name}</a></h2>\n"
234 if [ ${cur_file: -3} == ".md" ]; then
235 # This is a markdown file.
236 header_text="$(head -n1 $cur_file)"
237 header_text="$(echo ${header_text} | sed -e 's/^\#*//g')"
238 text="${text}${header_text}"
239 else
240 text="${text}$(head -n1 $cur_file | proc_text)"
242 echo -e $text >> "$BASE_OUTPUT/index.html"
244 # write detailed module content
245 header "$module_name" "<a href=\"index.html\">LibreOffice</a> &raquo; ${module_name}" "$BASE_OUTPUT/${module_name}.html"
246 text="<p><b>View module in:</b>"
247 text="${text} &nbsp; <a href=\"https://cgit.freedesktop.org/libreoffice/core/tree/${module_name}\">cgit</a>"
248 if $(echo $INPUT_PROJECTS | grep -q $module_name); then
249 text="${text} &nbsp; <a href=\"${module_name}/html/classes.html\">Doxygen</a>"
251 text="${text} </p><p>&nbsp;</p>"
252 echo -e $text >> "$BASE_OUTPUT/${module_name}.html"
254 if [ ${cur_file: -3} == ".md" ]; then
255 # This is a markdown file.
256 text="$(markdown $cur_file | proc_text_markdown)"
257 echo $text >> "$BASE_OUTPUT/${module_name}.html"
258 else
259 proc_text < $cur_file >> "$BASE_OUTPUT/${module_name}.html"
261 footer "$BASE_OUTPUT/${module_name}.html"
262 else
263 empty_modules[${#empty_modules[*]}]=$module_name
266 done
268 if [ ${#empty_modules[*]} -gt 0 ]; then
269 echo -e "<p>&nbsp;</p><p>READMEs were not available for these modules:</p><ul>\n" >> "$BASE_OUTPUT/index.html"
270 for module_name in "${empty_modules[@]}"; do
271 echo -e "<li><a href=\"https://cgit.freedesktop.org/libreoffice/core/tree/${module_name}\">${module_name}</a></li>\n" >> "$BASE_OUTPUT/index.html"
272 done
273 echo -e "</ul>\n" >> "$BASE_OUTPUT/index.html"
276 footer "$BASE_OUTPUT/index.html"
278 ## done