* doc/m4.texinfo (Compatibility): Sync with head.
[m4/ericb.git] / bootstrap
blobb68f338a3f5750d078b94c26a90c7642111b4624
1 #! /bin/sh
3 # bootstrap (GNU M4) version 2007-07-24
4 # Written by Gary V. Vaughan <gary@gnu.org>
6 # Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
8 # This file is part of GNU M4.
10 # GNU M4 is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # GNU M4 is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # Usage: $progname [options]
25 # -f --force bootstrap even when sources are not from CVS
26 # -v --version print version information
27 # -h,-? --help print short or long help message
29 # You can also set the following variables to help $progname
30 # locate the right tools:
31 # AUTORECONF, GNULIB_TOOL, RM, SED
33 # This script bootstraps a CVS checkout of GNU M4 by correctly
34 # calling out to parts of the GNU Build Platform. Currently this
35 # requires GNU Autoconf 2.60, GNU Automake 1.9.6, and bleeding edge
36 # CVS snapshots of GNU Gnulib.
38 # Report bugs to <bug-m4@gnu.org>
40 : ${AUTORECONF=autoreconf}
41 : ${GNULIB_TOOL=gnulib-tool}
42 : ${RM=rm -f}
43 : ${SED=sed}
45 dirname="s,/[^/]*$,,"
46 basename="s,^.*/,,g"
48 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
49 # is ksh but when the shell is invoked as "sh" and the current value of
50 # the _XPG environment variable is not equal to 1 (one), the special
51 # positional parameter $0, within a function call, is the name of the
52 # function.
53 progpath="$0"
55 # The name of this program:
56 progname=`echo "$progpath" | $SED "$basename"`
57 PROGRAM=bootstrap
59 # Detect whether this is a CVS checkout or a tarball
60 CVS_only_file=HACKING
62 # func_echo arg...
63 # Echo program name prefixed message.
64 func_echo ()
66 echo $progname: ${1+"$@"}
70 # func_error arg...
71 # Echo program name prefixed message to standard error.
72 func_error ()
74 echo $progname: ${1+"$@"} >&2
77 # func_fatal_error arg...
78 # Echo program name prefixed message to standard error, and exit.
79 func_fatal_error ()
81 func_error ${1+"$@"}
82 exit $EXIT_FAILURE
85 # func_verbose arg...
86 # Echo program name prefixed message in verbose mode only.
87 func_verbose ()
89 $opt_verbose && func_error ${1+"$@"}
92 # func_missing_arg argname
93 # Echo program name prefixed message to standard error and set global
94 # exit_cmd.
95 func_missing_arg ()
97 func_error "missing argument for $1"
98 exit_cmd=exit
101 # func_fatal_help arg...
102 # Echo program name prefixed message to standard error, followed by
103 # a help hint, and exit.
104 func_fatal_help ()
106 func_error ${1+"$@"}
107 func_fatal_error "Try \`$progname --help' for more information."
110 # func_missing_arg argname
111 # Echo program name prefixed message to standard error and set global
112 # exit_cmd.
113 func_missing_arg ()
115 func_error "missing argument for $1"
116 exit_cmd=exit
119 # func_usage
120 # Echo short help message to standard output and exit.
121 func_usage ()
123 $SED '/^# Usage:/,/# -h/ {
124 s/^# //; s/^# *$//;
125 s/\$progname/'$progname'/;
127 }; d' < "$progpath"
128 echo
129 echo "run \`$progname --help | more' for full usage"
130 exit $EXIT_SUCCESS
133 # func_help
134 # Echo long help message to standard output and exit.
135 func_help ()
137 $SED '/^# Usage:/,/# Report bugs to/ {
138 s/^# //; s/^# *$//;
139 s/\$progname/'$progname'/;
141 }; d' < "$progpath"
142 exit $EXIT_SUCCESS
145 # func_version
146 # Echo version message to standard output and exit.
147 func_version ()
149 $SED '/^# '$PROGRAM' (GNU /,/# warranty; / {
150 s/^# //; s/^# *$//;
151 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
153 }; d' < "$progpath"
154 exit $EXIT_SUCCESS
157 # func_update
158 # Copy $1 to $2 if it is newer.
159 func_update ()
161 if test -f "$2" && cmp -s "$1" "$2" ; then
162 func_verbose "$2 is up-to-date"
163 else
164 func_echo "copying $1 -> $2"
165 cp "$1" "$2"
169 # Parse options once, thoroughly. This comes as soon as possible in
170 # the script to make things like `bootstrap --version' happen quickly.
172 # sed scripts:
173 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
174 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
175 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
176 my_sed_long_arg='1s/^--[^=]*=//'
178 # this just eases exit handling
179 while test $# -gt 0; do
180 opt="$1"
181 shift
182 case $opt in
183 # Separate optargs to short options:
184 -f|--force) CVS_only_file= ;;
185 -\?|-h) func_usage ;;
186 --help) func_help ;;
187 --version) func_version ;;
188 --) break ;;
189 -*) func_fatal_help "unrecognized option \`$opt'" ;;
190 *) set -- "$opt" ${1+"$@"}; break ;;
191 esac
192 done
194 # Bail if the options were screwed
195 $exit_cmd $EXIT_FAILURE
197 if test -n "$CVS_only_file" && test ! -r "$CVS_only_file"; then
198 func_fatal_error "Bootstrapping from a non-CVS distribution is risky."
202 ## ---------------------------- ##
203 ## Find the gnulib module tree. ##
204 ## ---------------------------- ##
206 case $GNULIB_TOOL in
207 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
208 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
209 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
210 esac
212 # Follow symlinks
213 while test -h "$gnulibdir"; do
215 # Resolve symbolic link.
216 sedexpr1='s, -> ,#%%#,'
217 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
218 linkval=`LC_ALL=C ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
219 test -n "$linkval" || break
221 case "$linkval" in
222 /* ) gnulibdir="$linkval" ;;
223 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
224 esac
226 done
228 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
230 ## ---------------------- ##
231 ## Import Gnulib modules. ##
232 ## ---------------------- ##
234 func_echo "running: $GNULIB_TOOL --update"
235 $GNULIB_TOOL --update || func_fatal_error "gnulib-tool failed"
237 ## ----------- ##
238 ## Autoreconf. ##
239 ## ----------- ##
241 func_echo "running: $AUTORECONF --force --verbose --install"
242 $AUTORECONF --force --verbose --install || func_fatal_error "autoreconf failed"
244 ## ---------------------------------------- ##
245 ## Gnulib is more up-to-date than automake. ##
246 ## ---------------------------------------- ##
248 func_update "$gnulibdir"/build-aux/config.guess config.guess
249 func_update "$gnulibdir"/build-aux/config.sub config.sub
250 func_update "$gnulibdir"/build-aux/depcomp depcomp
251 func_update "$gnulibdir"/build-aux/install-sh install-sh
252 func_update "$gnulibdir"/build-aux/mdate-sh doc/mdate-sh
253 func_update "$gnulibdir"/build-aux/missing missing
254 func_update "$gnulibdir"/build-aux/texinfo.tex doc/texinfo.tex
255 func_update "$gnulibdir"/doc/COPYINGv3 COPYING
256 func_update "$gnulibdir"/doc/INSTALL INSTALL
258 exit 0
260 # Local variables:
261 # eval: (add-hook 'write-file-hooks 'time-stamp)
262 # time-stamp-start: "# bootstrap (GNU M4) version "
263 # time-stamp-format: "%:y-%02m-%02d"
264 # time-stamp-end: "$"
265 # End: