Avoid using variable size arrays if gcc does not allow them.
[gnulib.git] / build-aux / x-to-1.in
1 #! /bin/sh
2 #
3 # Copyright (C) 2001, 2003, 2006 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19
20 # This program creates a program's manual from the .x skeleton and its --help
21 # output.
22 # The .x skeleton is a file containing manual page text that is not part of the
23 # --help output. It is passed to help2man via its --include option. Its format
24 # is described in the help2man documentation.
25
26 update=
27 while true; do
28   case "$1" in
29     --update) update=yes; shift;;
30     *) break;;
31   esac
32 done
33
34 if test $# != 5; then
35   echo "Usage: x-to-1 [OPTIONS] PERL HELP2MAN executable program.x program.1" 1>&2
36   exit 1
37 fi
38 PERL="$1"
39 HELP2MAN="$2"
40 executable="$3"
41 aux="$4"
42 output="$5"
43
44 progname=`basename $aux .x`
45 case "$PERL" in *"/missing perl") perlok=no;; *) perlok=yes;; esac
46 if test @CROSS_COMPILING@ = no && test -f $executable && test $perlok = yes; then
47   echo "Updating man page $output"
48   echo "$HELP2MAN --include=$aux $executable > $output"
49   rm -f t-$progname.1
50   $HELP2MAN --include=$aux $executable > t-$progname.1 || exit 1
51   if test -n "$update"; then
52     # In --update mode, don't overwrite the output if nothing would change.
53     if cmp t-$progname.1 $output >/dev/null 2>&1; then
54       rm -f t-$progname.1
55     else
56       mv t-$progname.1 $output
57     fi
58   else
59     mv t-$progname.1 $output
60   fi
61 else
62   echo "WARNING: The man page $output cannot be updated yet."
63 fi