attribute: Clarify which file to include.
[gnulib.git] / build-aux / x-to-1.in
blob73fbd2c0bc0040e77a4f975ada1189836ab6b08c
1 #! /bin/sh
3 # Copyright (C) 2001-2020 Free Software Foundation, Inc.
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 3 of the License, or
8 # (at your option) any later version.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # This program creates a program's manual from the .x skeleton and its --help
20 # output.
22 # Usage: x-to-1 [OPTIONS] PERL HELP2MAN EXECUTABLE PROGRAM.x PROGRAM.1
23 # where
25 # PERL The file name of the perl program.
26 # HELP2MAN Either the file name of the help2man perl script, or a complete
27 # command such as "$PERL -w -- help2man".
28 # EXECUTABLE The file name of the program to invoke with --help.
29 # PROGRAM The name of the program.
30 # PROGRAM.x The .x skeleton is a file containing manual page text that is
31 # not part of the --help output. It is passed to help2man via
32 # its --include option. Its format is described in the help2man
33 # documentation.
34 # PROGRAM.1 The output file, a manual page in mandoc format.
36 # Options:
37 # --update Don't overwrite the output if nothing would change.
40 update=
41 while true; do
42 case "$1" in
43 --update) update=yes; shift;;
44 *) break;;
45 esac
46 done
48 if test $# != 5; then
49 echo "Usage: x-to-1 [OPTIONS] PERL HELP2MAN executable program.x program.1" 1>&2
50 exit 1
52 PERL="$1"
53 HELP2MAN="$2"
54 executable="$3"
55 aux="$4"
56 output="$5"
58 # Accommodate both possible forms of the HELP2MAN argument.
59 case "$HELP2MAN" in
60 "$PERL "*) ;;
61 *) HELP2MAN="$PERL $HELP2MAN" ;;
62 esac
64 progname=`basename $aux .x`
65 # configure determined whether perl exists.
66 case "$PERL" in
67 *"/missing perl")
68 perlok=no
71 # Determine whether all the perl modules that help2man needs are installed.
72 if $HELP2MAN --help >/dev/null 2>/dev/null; then
73 perlok=yes
74 else
75 perlok=no
78 esac
79 if test @CROSS_COMPILING@ = no && test -f $executable && test $perlok = yes; then
80 echo "Updating man page $output"
81 echo "$HELP2MAN --include=$aux $executable > $output"
82 rm -f t-$progname.1
83 $HELP2MAN --include=$aux $executable > t-$progname.1 || exit 1
84 if test -n "$update"; then
85 # In --update mode, don't overwrite the output if nothing would change.
86 if cmp t-$progname.1 $output >/dev/null 2>&1; then
87 rm -f t-$progname.1
88 else
89 mv t-$progname.1 $output
91 else
92 mv t-$progname.1 $output
94 else
95 echo "WARNING: The man page $output cannot be updated yet."