]> git.proxmox.com Git - mirror_ovs.git/blob - build-aux/dist-docs
93709c8cc0a426ba7324b7c4d70dbf9ae2bc3544
[mirror_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 (cat <<EOF
77 <html><head>
78 <meta charset="UTF-8"></head>
79 <link rel="stylesheet" type="text/css" href="style.css">
80 <title>$file (Open vSwitch $VERSION)</title>
81 </head><body>
82 EOF
83 markdown "$distdir/$file.txt"
84 echo "</body></html>") > "$distdir/$file.html"
85 cat <<EOF
86 <tr>
87 <td>$file</td>
88 <td>$title</td>
89 <td><a href="$file.html">HTML</a>, <a href="$file.txt">plain text</a></td>
90 </tr>
91 EOF
92 ;;
93
94 *)
95 cp "$srcdir/$file" "$distdir/$file"
96 cat <<EOF
97 <tr>
98 <td>$file</td>
99 <td>$title</td>
100 <td><a href="$file">plain text</a></td>
101 </tr>
102 EOF
103 ;;
104 esac
105 done >&3
106
107 # Add header for manpages to index.html.
108 cat >&3 <<EOF
109 </table>
110 <h2>Manpages</h2>
111 <table>
112 EOF
113
114 # Add manpages to index.html, translating them into PDF, HTML, and plain text.
115 # The HTML is just slightly marked up from the plain text version; although
116 # groff supports better HTML output, on my system some of the OVS manpages
117 # cause the groff HTML output engine to segfault (!).
118 (cd $distdir
119 for manpage in $manpages; do
120 man -l -Tps $manpage | ps2pdf - > $manpage.pdf
121 GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed 's/.\b//g' > $manpage.txt
122 (echo '<html><head><meta charset="UTF-8"></head><body><pre>'
123 GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed '
124 s/&/&amp;/g
125 s/</&lt;/g
126 s/>/&gt;/g
127 s,\(.\)\b\1,<b>\1</b>,g
128 s,_\b\(.\),<u>\1</u>,g'
129 echo '</pre></body></html>'
130 ) > $manpage.html
131
132 name=`echo $manpage | sed 's/\.\([0-9]\)$/(\1)/'`
133 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>"
134 done
135 ) >&3
136 cat >&3 <<EOF
137 </table>
138 </body></html>
139 EOF
140
141 # Create CSS style file.
142 cat >$distdir/style.css <<'EOF'
143 div { vertical-align:top; }
144 p {
145 vertical-align:baseline;
146 }
147 a {
148 text-decoration: none;
149 font-weight: 700;
150 }
151 a:hover {
152 color:#444;
153 }
154 a:visited {
155 color:#447099;
156 }
157 a:link {
158 color:#447099;
159 }
160
161 body {
162 font-family: Arial,Helvetica,sans-serif;
163 font-size: 14px;
164 line-height: 1.5em;
165 color: #444;
166 background-color:#f5f5f5;
167 }
168 EOF