File: doc.sh

package info (click to toggle)
marionnet 0.90.6+bzr508-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,532 kB
  • sloc: ml: 18,130; sh: 5,384; xml: 1,152; makefile: 1,003; ansic: 275
file content (143 lines) | stat: -rwxr-xr-x 3,835 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash -e

# This -*- makefile -*- is part of our build system for OCaml projects
# Copyright (C) 2008  Jean-Vincent Loddo

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Usage:
# doc.sh -pp "$(PP_OPTION)" -e "$(UNDOCUMENTED)" -i $(DIRECTORIES_TO_INCLUDE)

################################
#   Set ocamldoc parameters    #
################################

UNDOCUMENTED="meta.ml myocamlbuild.ml"

function usage {
 echo 'Usage (in a Makefile):'
 echo 'doc.sh -pp "$(PP_OPTION)" -e "$(UNDOCUMENTED)" -i $(DIRECTORIES_TO_INCLUDE)'
 exit 1
}
set -x

# The first argument may be empty but must be present.
[[ $1 = "-pp" ]] || usage
PP_OPTION=$(echo $2)
if [[ $PP_OPTION != "" ]]; then
 PP_OPTION="-pp '$2'"
fi
shift 2

[[ $1 = "-e" ]] || usage
UNDOCUMENTED+=" "$(echo $2)
for i in $UNDOCUMENTED; do
  UNDOCUMENTED_FILTER+=" -a ! -name $i"
done
shift 2

[[ $1 = "-i" ]] || usage
shift
for i in "$@"; do
 INCLUDE_LIBS+=" -I +$i"
done

# ocamldoc parameters:

SOURCES=$(builtin cd _build/ && find . \( -name "*.ml" -o -name "*.mli" \) $UNDOCUMENTED_FILTER)
INCLUDES=$(builtin cd _build/ && find . -type d -printf "-I %p\n")
PROJECT=$(basename $PWD)

################################
#    Make header and footer    #
################################

cd _build/
mkdir -p doc/html

# Make header.gif
function enrich_index_html {

 which dot || {
   echo "Warning: you need dot (graphviz) in order to generated the documentation header.";
   return 0
   }

 # Get user-defined header and footer
 [[ -f ../header.html ]] && HEADER_FILE=$(< ../header.html)
 [[ -f ../footer.html ]] && FOOTER_FILE=$(< ../footer.html)
 [[ -f ../AUTHORS     ]] && AUTHORS_FILE=$(< ../AUTHORS)
 [[ -f ../AUTHORS     ]] && AUTHORS_FILE=$(awk <../AUTHORS '/$/ {print; print "<br/>"; }')

 # Make dependencies graph
 set -x;
 eval ocamldoc $PP_OPTION -dot -d doc/html/ -o doc/html/header0.dot -colorize-code $INCLUDES $INCLUDE_LIBS $SOURCES
 set +x
 echo 'Ok, the dependencies graph was built with success.'
 pushd doc/html >/dev/null
 grep -v "rankdir=\|size=\|rotate=" header0.dot > header.dot
 dot header.dot -Tgif -o header.gif
 HEADER=$(cat <<EOF
<center>
Project
<h1>$PROJECT</h1>
<br/>
<hr/>
<a href="#dependencies">Dependencies</a>
<a href="#authors">License and authors</a>
</center>
$HEADER_FILE
<hr/>
EOF
)

 FOOTER=$(cat <<EOF
<br/>
<hr/>
<center>
<h1>Dependencies</h1>
<br/>
<p/><img id="dependencies" src="header.gif" align="middle" alt="Dependencies">
</center>
$FOOTER_FILE
<hr/>
<h1 id="authors">License and authors</h1>
<br/>
<p>
$AUTHORS_FILE
</p>
EOF
)

 cat index.html | awk -v h="$HEADER" -v f="$FOOTER" '
    /^<center><h1>.*<.h1><.center>/ {print h; next}
    /^<\/body>/                     {print f "</body>"; next}
    {print}
    ' > index1.html
 mv -f index1.html index.html
 popd >/dev/null
 echo 'Ok, header and footer have been included into index.html.'
}


################################
#        Call ocamldoc         #
################################

set -x
eval ocamldoc -t $PROJECT $PP_OPTION -sort -m A -keep-code -html -colorize-code -d doc/html/ $INCLUDES $INCLUDE_LIBS $SOURCES
set +x
echo 'Ok, the documentation was built with success.'
enrich_index_html
echo 'The documentation has been built with success under _build/doc/html'