summaryrefslogtreecommitdiff
path: root/build-aux/dist-docs
blob: fdaa066927eeabda0cf043376448470ea46ad341 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! /bin/sh

set -e

# Check command line.
if test ! -d "$1" || test $# -lt 2; then
    cat <<EOF
$0: HTML documentation generator for Open vSwitch
usage: $0 srcdir docfile...

The VERSION environment variable should be set to the Open vSwitch version.
Must be invoked from an Open vSwitch build directory.
Most conveniently invoked via "make dist-docs".
EOF
    exit 1
fi

# Parse command line.
srcdir=$1
shift

# Check for programs we'll need.
search_path () {
    save_IFS=$IFS
    IFS=:
    for dir in $PATH; do
        IFS=$save_IFS
        if test -x "$dir/$1"; then
            return 0
        fi
    done
    IFS=$save_IFS
    echo >&2 "$0: $1 not found in \$PATH, please install and try again"
    exit 1
}
search_path man
search_path markdown
search_path rst2html
search_path ps2pdf

# Create dist-docs directory.
distdir=dist-docs
abs_distdir=`pwd`/dist-docs
rm -rf $distdir
mkdir $distdir

# Install manpages.
${MAKE-make} install-man mandir="$abs_distdir"/man
(cd $distdir && mv `find man -type f` . && rm -rf man)
manpages=`cd $distdir && echo *`

# Start writing index.html.
exec 3>$distdir/index.html
cat >&3 <<EOF
<html><head>
  <meta charset="UTF-8"></head>
  <link rel="stylesheet" type="text/css" href="style.css">
  <title>Open vSwitch $VERSION Documentation</title>
</head><body>
<h1>Open vSwitch $VERSION Documentation</h1>
<h2>Documents</h2>
<table>
EOF

# Add top-level documentation to index.html, giving it .txt extensions so that
# the webserver doesn't serve it as Markdown/rST and make your web browser try
# to invoke some kind of external helper you don't have installed.
#
# Also translate documentation to HTML.
for file
do
    title=`head -1 "$srcdir/$file"`
    dir=$distdir/`dirname $file`; test -d "$dir" || mkdir "$dir"
    case $file in
        *.md)
            cp "$srcdir/$file" "$distdir/$file.txt"
            ln -s $(basename "$file.txt") "$distdir/$file"
            (cat <<EOF
<html><head>
  <meta charset="UTF-8"></head>
  <link rel="stylesheet" type="text/css" href="style.css">
  <title>$file (Open vSwitch $VERSION)</title>
</head><body>
EOF
             markdown "$distdir/$file.txt"
             echo "</body></html>") > "$distdir/$file.html"
            cat <<EOF
<tr>
  <td>$file</td>
  <td>$title</td>
  <td><a href="$file.html">HTML</a>, <a href="$file.txt">plain text</a></td>
</tr>
EOF
            ;;

        *.rst)
            title=`grep -A 1 -e "^=" $srcdir/$file | sed -n 2p`
            cp "$srcdir/$file" "$distdir/$file.txt"
            ln -s $(basename "$file.txt") "$distdir/$file"
            rst2html "$distdir/$file.txt" --stylesheet-path="style.css" \
                --link-stylesheet --title="$file (Open vSwitch $VERSION)" \
                > "$distdir/$file.html"
            cat <<EOF
<tr>
  <td>$file</td>
  <td>$title</td>
  <td><a href="$file.html">HTML</a>, <a href="$file.txt">plain text</a></td>
</tr>
EOF
            ;;

        *)
            cp "$srcdir/$file" "$distdir/$file"
            cat <<EOF
<tr>
  <td>$file</td>
  <td>$title</td>
  <td><a href="$file">plain text</a></td>
</tr>
EOF
            ;;
    esac
done >&3

# Add header for manpages to index.html.
cat >&3 <<EOF
</table>
<h2>Manpages</h2>
<table>
EOF

# Add manpages to index.html, translating them into PDF, HTML, and plain text.
# The HTML is just slightly marked up from the plain text version; although
# groff supports better HTML output, on my system some of the OVS manpages
# cause the groff HTML output engine to segfault (!).
(cd $distdir
 for manpage in $manpages; do
     man -l -Tps $manpage | ps2pdf - > $manpage.pdf
     GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed 's/.//g' > $manpage.txt
     (echo '<html><head><meta charset="UTF-8"></head><body><pre>'
      GROFF_NO_SGR=1 man -l -Tutf8 $manpage | sed '
s/&/&amp;/g
s/</&lt;/g
s/>/&gt;/g
s,\(.\)\1,<b>\1</b>,g
s,_\(.\),<u>\1</u>,g'
      echo '</pre></body></html>'
     ) > $manpage.html

     name=`echo $manpage | sed 's/\.\([0-9]\)$/(\1)/'`
     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>"
 done
) >&3
cat >&3 <<EOF
</table>
</body></html>
EOF

# Create CSS style file.
cat >$distdir/style.css <<'EOF'
div { vertical-align:top; }
p {
    vertical-align:baseline;
}
a {
    text-decoration: none;
    font-weight: 700;
}
a:hover {
    color:#444;
}
a:visited {
    color:#447099;
}
a:link {
    color:#447099;
}

body {
    font-family: Arial,Helvetica,sans-serif;
    font-size: 14px;
    line-height: 1.5em;
    color: #444;
    background-color:#f5f5f5;
}
EOF