]> git.proxmox.com Git - mirror_ovs.git/blame - build-aux/dist-docs
dist-docs: Fix text and HTML manpage generation with some groff versions.
[mirror_ovs.git] / build-aux / dist-docs
CommitLineData
4441a01c
BP
1#! /bin/sh
2
3set -e
4
5# Check command line.
6if test ! -d "$1" || test $# -lt 2; then
7 cat <<EOF
8$0: HTML documentation generator for Open vSwitch
9usage: $0 srcdir docfile...
10
11The VERSION environment variable should be set to the Open vSwitch version.
12Must be invoked from an Open vSwitch build directory.
13Most conveniently invoked via "make dist-docs".
14EOF
15 exit 1
16fi
17
18# Parse command line.
19srcdir=$1
20shift
21
22# Check for programs we'll need.
23search_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}
36search_path man
37search_path markdown
38search_path ps2pdf
39
40# Create dist-docs directory.
41distdir=dist-docs
42abs_distdir=`pwd`/dist-docs
43rm -rf $distdir
44mkdir $distdir
45
46# Install manpages.
47make install-man mandir="$abs_distdir"/man
48(cd $distdir && mv `find man -type f` . && rm -rf man)
49manpages=`cd $distdir && echo *`
50
51# Start writing index.html.
52exec 3>$distdir/index.html
53cat >&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>
62EOF
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.
69for file
70do
71 title=`head -1 "$srcdir/$file"`
72 dir=$distdir/`dirname $file`; test -d "$dir" || mkdir "$dir"
73 cp "$srcdir/$file" "$distdir/$file.txt"
74 (cat <<EOF
75<html><head>
76 <meta charset="UTF-8"></head>
77 <link rel="stylesheet" type="text/css" href="style.css">
78 <title>$file (Open vSwitch $VERSION)</title>
79</head><body>
80EOF
81 markdown "$distdir/$file.txt"
82 echo "</body></html>") > "$distdir/$file.html"
83 cat <<EOF
84<tr>
85 <td>$file</td>
86 <td>$title</td>
87 <td><a href="$file.html">HTML</a>, <a href="$file.txt">plain text</a></td>
88</tr>
89EOF
90done >&3
91
92# Add header for manpages to index.html.
93cat >&3 <<EOF
94</table>
95<h2>Manpages</h2>
96<table>
97EOF
98
99# Add manpages to index.html, translating them into PDF, HTML, and plain text.
100# The HTML is just slightly marked up from the plain text version; although
101# groff supports better HTML output, on my system some of the OVS manpages
102# cause the groff HTML output engine to segfault (!).
103(cd $distdir
104 for manpage in $manpages; do
105 man -l -Tps $manpage | ps2pdf - > $manpage.pdf
0e7850eb 106 GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed 's/.\b//g' > $manpage.txt
4441a01c 107 (echo '<html><head><meta charset="UTF-8"></head><body><pre>'
0e7850eb 108 GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed '
4441a01c
BP
109s/&/&amp;/g
110s/</&lt;/g
111s/>/&gt;/g
112s,\(.\)\b\1,<b>\1</b>,g
113s,_\b\(.\),<u>\1</u>,g'
114 echo '</pre></body></html>'
115 ) > $manpage.html
116
117 name=`echo $manpage | sed 's/\.\([0-9]\)$/(\1)/'`
118 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>"
119 done
120) >&3
121cat >&3 <<EOF
122</table>
123</body></html>
124EOF
125
126# Create CSS style file.
127cat >$distdir/style.css <<'EOF'
128div { vertical-align:top; }
129p {
130 vertical-align:baseline;
131}
132a {
133 text-decoration: none;
134 font-weight: 700;
135}
136a:hover {
137 color:#444;
138}
139a:visited {
140 color:#447099;
141}
142a:link {
143 color:#447099;
144}
145
146body {
147 font-family: Arial,Helvetica,sans-serif;
148 font-size: 14px;
149 line-height: 1.5em;
150 color: #444;
151 background-color:#f5f5f5;
152}
153EOF