gnu-web-doc-update: check the requirements.
[gnulib.git] / build-aux / gnu-web-doc-update
1 #!/bin/sh
2 # Run this after each non-alpha release, to update the web documentation at
3 # http://www.gnu.org/software/$pkg/manual/
4 # This script must be run from the top-level directory,
5 # assumes you're using git for revision control,
6 # and requires a .prev-version file as well as a Makefile,
7 # from which it extracts the version number and package name, respectively.
8 # Also, it assumes all documentation is in the doc/ sub-directory.
9
10 VERSION=2009-07-21.16; # UTC
11
12 # Copyright (C) 2009-2012 Free Software Foundation, Inc.
13
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
18
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27 ME=$(basename "$0")
28 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
29 die() { warn "$*"; exit 1; }
30
31 help()
32 {
33   cat <<EOF
34 Usage: $ME
35
36 Run this script from top_srcdir (no options or arguments) after each
37 non-alpha release, to update the web documentation at
38 http://www.gnu.org/software/\$pkg/manual/ Run it from your project's
39 the top-level directory.
40
41 Options:
42   -C, --builddir=DIR  location of (configured) Makefile (default: .)
43   --help              print this help, then exit
44   --version           print version number, then exit
45
46 Report bugs and patches to <bug-gnulib@gnu.org>.
47 EOF
48   exit
49 }
50
51 version()
52 {
53   year=$(echo "$VERSION" | sed 's/[^0-9].*//')
54   cat <<EOF
55 $ME $VERSION
56 Copyright (C) $year Free Software Foundation, Inc,
57 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
58 This is free software: you are free to change and redistribute it.
59 There is NO WARRANTY, to the extent permitted by law.
60 EOF
61   exit
62 }
63
64 # find_tool ENVVAR NAMES...
65 # -------------------------
66 # Search for a required program.  Use the value of ENVVAR, if set,
67 # otherwise find the first of the NAMES that can be run (i.e.,
68 # supports --version).  If found, set ENVVAR to the program name,
69 # die otherwise.
70 #
71 # FIXME: code duplication, see also bootstrap.
72 find_tool ()
73 {
74   find_tool_envvar=$1
75   shift
76   find_tool_names=$@
77   eval "find_tool_res=\$$find_tool_envvar"
78   if test x"$find_tool_res" = x; then
79     for i
80     do
81       if ($i --version </dev/null) >/dev/null 2>&1; then
82        find_tool_res=$i
83        break
84       fi
85     done
86   else
87     find_tool_error_prefix="\$$find_tool_envvar: "
88   fi
89   test x"$find_tool_res" != x \
90     || die "one of these is required: $find_tool_names"
91   ($find_tool_res --version </dev/null) >/dev/null 2>&1 \
92     || die "${find_tool_error_prefix}cannot run $find_tool_res --version"
93   eval "$find_tool_envvar=\$find_tool_res"
94   eval "export $find_tool_envvar"
95 }
96
97 ## ------ ##
98 ## Main.  ##
99 ## ------ ##
100
101 # Requirements: everything required to bootstrap your package, plus
102 # these.
103 find_tool CVS cvs
104 find_tool CVSU cvsu
105 find_tool GIT git
106 find_tool RSYNC rsync
107 find_tool XARGS gxargs xargs
108
109 builddir=.
110 while test $# != 0
111 do
112   # Handle --option=value by splitting apart and putting back on argv.
113   case $1 in
114     --*=*)
115       opt=$(echo "$1" | sed -e 's/=.*//')
116       val=$(echo "$1" | sed -e 's/[^=]*=//')
117       shift
118       set dummy "$opt" "$val" ${1+"$@"}; shift
119       ;;
120   esac
121
122   case $1 in
123     --help|--version) ${1#--};;
124     -C|--builddir) shift; builddir=$1; shift ;;
125     --*) die "unrecognized option: $1";;
126     *) break;;
127   esac
128 done
129
130 test $# = 0 \
131   || die "$ME: too many arguments"
132
133 prev=.prev-version
134 version=$(cat $prev) || die "$ME: no $prev file?"
135 pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' $builddir/Makefile) \
136   || die "$ME: no Makefile?"
137 tmp_branch=web-doc-$version-$$
138 current_branch=$($GIT branch | sed -ne '/^\* /{s///;p;q;}')
139
140 cleanup()
141 {
142   __st=$?
143   rm -rf "$tmp"
144   $GIT checkout "$current_branch"
145   $GIT submodule update --recursive
146   $GIT branch -d $tmp_branch
147   exit $__st
148 }
149 trap cleanup 0
150 trap 'exit $?' 1 2 13 15
151
152 # We must build using sources for which --version reports the
153 # just-released version number, not some string like 7.6.18-20761.
154 # That version string propagates into all documentation.
155 set -e
156 $GIT checkout -b $tmp_branch v$version
157 $GIT submodule update --recursive
158 ./bootstrap
159 srcdir=$(pwd)
160 cd "$builddir"
161   ./config.status --recheck
162   ./config.status
163   make
164   make web-manual
165 cd "$srcdir"
166 set +e
167
168 tmp=$(mktemp -d web-doc-update.XXXXXX) || exit 1
169 ( cd $tmp \
170     && $CVS -d $USER@cvs.sv.gnu.org:/webcvs/$pkg co $pkg )
171 $RSYNC -avP "$builddir"/doc/manual/ $tmp/$pkg/manual
172
173 (
174   cd $tmp/$pkg/manual
175
176   # Add any new files:
177   $CVSU --types='?'                             \
178     | sed s/..//                                \
179     | $XARGS --no-run-if-empty -- $CVS add -ko
180
181   $CVS ci -m $version
182 )
183
184 # Local variables:
185 # eval: (add-hook 'write-file-hooks 'time-stamp)
186 # time-stamp-start: "VERSION="
187 # time-stamp-format: "%:y-%02m-%02d.%02H"
188 # time-stamp-time-zone: "UTC"
189 # time-stamp-end: "; # UTC"
190 # End: