3 # Copyright (C) 2010-2011 Red Hat Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # Wrapper script around POD utilities which can include files in the
21 # POD and controls HTML generation.
28 PACKAGE_NAME="@PACKAGE_NAME@"
29 PACKAGE_VERSION="@PACKAGE_VERSION@"
33 POD2_STDERR_OPTION="@POD2_STDERR_OPTION@"
34 POD2_UTF8_OPTION="@POD2_UTF8_OPTION@"
36 # This script could be run with any current directory, so if a source
37 # or build path is required it must be relative to the following
39 abs_top_srcdir="@abs_top_srcdir@"
40 abs_top_builddir="@abs_top_builddir@"
42 if [ -z "$abs_top_srcdir" ]; then
43 echo "*** podwrapper.sh: error: abs_top_srcdir not defined"
44 echo "probably this is a very old version of autoconf and you need to"
45 echo "upgrade to a recent version"
49 if [ -z "$abs_top_builddir" ]; then
50 echo "*** podwrapper.sh: error: abs_top_builddir not defined"
51 echo "probably this is a very old version of autoconf and you need to"
52 echo "upgrade to a recent version"
63 --long section:,name:,man:,text:,html:,insert:,verbatim: \
64 -n podwrapper.sh -- "$@"`
66 echo "podwrapper.sh: problem parsing the command line arguments"
80 [ -z "$man_output" ] || {
81 echo "podwrapper.sh: --text option specified more than once"
87 [ -z "$text_output" ] || {
88 echo "podwrapper.sh: --text option specified more than once"
94 [ -z "$html_output" ] || {
95 echo "podwrapper.sh: --html option specified more than once"
101 inserts[$nr_inserts]=`echo "$2" | awk -F: '{print $1}'`
102 pattern[$nr_inserts]=`echo "$2" | awk -F: '{print $2}'`
103 indent[$nr_inserts]=no
107 inserts[$nr_inserts]=`echo "$2" | awk -F: '{print $1}'`
108 pattern[$nr_inserts]=`echo "$2" | awk -F: '{print $2}'`
109 indent[$nr_inserts]=yes
115 echo "podwrapper.sh: internal error in option parsing"
120 # The remaining argument is the input POD file.
121 if [ $# -ne 1 ]; then
122 echo "podwrapper.sh [--options] input.pod"
128 #echo "man_output=$man_output"
129 #echo "text_output=$text_output"
130 #echo "html_output=$html_output"
131 #for i in `seq 0 $(($nr_inserts-1))`; do
132 # echo "insert $i: ${inserts[$i]} (pattern: ${pattern[$i]} indent: ${indent[$i]})"
135 # Should be at least one sort of output.
136 [ -z "$man_output" -a -z "$text_output" -a -z "$html_output" ] && {
137 echo "podwrapper.sh: no output specified"
141 # If name and section are not set, make some sensible defaults.
142 [ -z "$section" ] && section=1
143 [ -z "$name" ] && name=$(basename "$input" .pod)
145 # Perform the insertions to produce a temporary POD file.
146 tmpdir="$(mktemp -d)"
147 trap "rm -rf $tmpdir; exit $?" EXIT
149 if [ $nr_inserts -gt 0 ]; then
152 for i in `seq 0 $(($nr_inserts-1))`; do
153 if [ "${indent[$i]}" = "yes" ]; then
154 sed 's/^/ /' < "${inserts[$i]}" > $tmpdir/$i
156 cp "${inserts[$i]}" $tmpdir/$i
159 cmd="$cmd -e /${pattern[$i]}/r$tmpdir/$i -e s/${pattern[$i]}//"
162 $cmd < "$input" > $tmpdir/full.pod
164 cp "$input" $tmpdir/full.pod
167 # Now generate the final output format(s).
168 if [ -n "$man_output" ]; then
169 "$POD2MAN" "$POD2_STDERR_OPTION" "$POD2_UTF8_OPTION" \
170 --section "$section" -c "Virtualization Support" --name "$name" \
171 --release "$PACKAGE_NAME-$PACKAGE_VERSION" \
172 < $tmpdir/full.pod > "$man_output".tmp
173 mv "$man_output".tmp "$man_output"
176 if [ -n "$text_output" ]; then
177 "$POD2TEXT" "$POD2_STDERR_OPTION" "$POD2_UTF8_OPTION" \
178 < $tmpdir/full.pod > "$text_output".tmp
179 mv "$text_output".tmp "$text_output"
182 if [ -n "$html_output" ]; then
183 mkdir -p "$abs_top_builddir/html"
185 --css "pod.css" --htmldir "$abs_top_builddir/html" \
186 < $tmpdir/full.pod > "$html_output".tmp
187 mv "$html_output".tmp "$html_output"
189 # Fix up some of the mess in the HTML output, mainly to make links
190 # between man pages work properly.
192 # Rewrite <em>manpage(n)</em> to <a href=...>manpage(n)</a> if
193 # there is a linkable manual page.
195 for f in $(cd "$abs_top_builddir/html" && ls -1 *.html); do
196 b=$(basename $f .html)
197 m=$(echo $b | sed 's/\(.*\)\.\([1-9]\)$/\1(\2)/')
198 sed_cmd="$sed_cmd -e 's,<em>$m</em>,<a href=$f>$m</a>,g'"
201 eval $sed_cmd < "$html_output" > "$html_output".tmp
202 mv "$html_output".tmp "$html_output"
204 # Fix links like L<guestfs-foo(3)>
205 sed 's,<a href="#\([a-z]\+\)">guestfs-\1(\([1-9]\)),<a href="guestfs-\1.\2.html">guestfs-\1(\2),g' < "$html_output" > "$html_output".tmp
206 mv "$html_output".tmp "$html_output"