netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / build-aux / dist-docs
1 #! /bin/sh
2
3 set -e
4
5 # Check command line.
6 if test ! -d "$1" || test $# -lt 2; then
7     cat <<EOF
8 $0: HTML documentation generator for Open vSwitch
9 usage: $0 srcdir docfile...
10
11 The VERSION environment variable should be set to the Open vSwitch version.
12 Must be invoked from an Open vSwitch build directory.
13 Most conveniently invoked via "make dist-docs".
14 EOF
15     exit 1
16 fi
17
18 # Parse command line.
19 srcdir=$1
20 shift
21
22 # Check for programs we'll need.
23 search_path () {
24     save_IFS=$IFS
25     IFS=:
26     for dir in $PATH; do
27         IFS=$save_IFS
28         if test -x "$dir/$1"; then
29             return 0
30         fi
31     done
32     IFS=$save_IFS
33     echo >&2 "$0: $1 not found in \$PATH, please install and try again"
34     exit 1
35 }
36 search_path man
37 search_path markdown
38 search_path ps2pdf
39
40 # Create dist-docs directory.
41 distdir=dist-docs
42 abs_distdir=`pwd`/dist-docs
43 rm -rf $distdir
44 mkdir $distdir
45
46 # Install manpages.
47 ${MAKE-make} install-man mandir="$abs_distdir"/man
48 (cd $distdir && mv `find man -type f` . && rm -rf man)
49 manpages=`cd $distdir && echo *`
50
51 # Start writing index.html.
52 exec 3>$distdir/index.html
53 cat >&3 <<EOF
54 <html><head>
55   <meta charset="UTF-8"></head>
56   <link rel="stylesheet" type="text/css" href="style.css">
57   <title>Open vSwitch $VERSION Documentation</title>
58 </head><body>
59 <h1>Open vSwitch $VERSION Documentation</h1>
60 <h2>Documents</h2>
61 <table>
62 EOF
63
64 # Add top-level documentation to index.html, giving it .txt extensions so
65 # that the webserver doesn't serve it as Markdown and make your web browser
66 # try to invoke some kind of external helper you don't have installed.
67 #
68 # Also translate documentation to HTML.
69 for file
70 do
71     title=`head -1 "$srcdir/$file"`
72     dir=$distdir/`dirname $file`; test -d "$dir" || mkdir "$dir"
73     case $file in
74         *.md)
75             cp "$srcdir/$file" "$distdir/$file.txt"
76             ln -s $(basename "$file.txt") "$distdir/$file"
77             (cat <<EOF
78 <html><head>
79   <meta charset="UTF-8"></head>
80   <link rel="stylesheet" type="text/css" href="style.css">
81   <title>$file (Open vSwitch $VERSION)</title>
82 </head><body>
83 EOF
84              markdown "$distdir/$file.txt"
85              echo "</body></html>") > "$distdir/$file.html"
86             cat <<EOF
87 <tr>
88   <td>$file</td>
89   <td>$title</td>
90   <td><a href="$file.html">HTML</a>, <a href="$file.txt">plain text</a></td>
91 </tr>
92 EOF
93             ;;
94
95         *)
96             cp "$srcdir/$file" "$distdir/$file"
97             cat <<EOF
98 <tr>
99   <td>$file</td>
100   <td>$title</td>
101   <td><a href="$file">plain text</a></td>
102 </tr>
103 EOF
104             ;;
105     esac
106 done >&3
107
108 # Add header for manpages to index.html.
109 cat >&3 <<EOF
110 </table>
111 <h2>Manpages</h2>
112 <table>
113 EOF
114
115 # Add manpages to index.html, translating them into PDF, HTML, and plain text.
116 # The HTML is just slightly marked up from the plain text version; although
117 # groff supports better HTML output, on my system some of the OVS manpages
118 # cause the groff HTML output engine to segfault (!).
119 (cd $distdir
120  for manpage in $manpages; do
121      man -l -Tps $manpage | ps2pdf - > $manpage.pdf
122      GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed 's/.\b//g' > $manpage.txt
123      (echo '<html><head><meta charset="UTF-8"></head><body><pre>'
124       GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed '
125 s/&/&amp;/g
126 s/</&lt;/g
127 s/>/&gt;/g
128 s,\(.\)\b\1,<b>\1</b>,g
129 s,_\b\(.\),<u>\1</u>,g'
130       echo '</pre></body></html>'
131      ) > $manpage.html
132
133      name=`echo $manpage | sed 's/\.\([0-9]\)$/(\1)/'`
134      echo "  <tr><td>$name</td><td><a href=\"$manpage.pdf\">PDF</a>, <a href=\"$manpage.html\">HTML</a>, <a href=\"$manpage.txt\">plain text</a></td></tr>"
135  done
136 ) >&3
137 cat >&3 <<EOF
138 </table>
139 </body></html>
140 EOF
141
142 # Create CSS style file.
143 cat >$distdir/style.css <<'EOF'
144 div { vertical-align:top; }
145 p {
146     vertical-align:baseline;
147 }
148 a {
149     text-decoration: none;
150     font-weight: 700;
151 }
152 a:hover {
153     color:#444;
154 }
155 a:visited {
156     color:#447099;
157 }
158 a:link {
159     color:#447099;
160 }
161
162 body {
163     font-family: Arial,Helvetica,sans-serif;
164     font-size: 14px;
165     line-height: 1.5em;
166     color: #444;
167     background-color:#f5f5f5;
168 }
169 EOF