* src/builtin.c (substitute): Avoid core dump when accessing
[m4/ericb.git] / bootstrap
blobec705e2ce9d54dde2479a00a6352ce277193c047
1 #! /bin/sh
3 # bootstrap (GNU M4) version 2006-07-15
4 # Written by Gary V. Vaughan <gary@gnu.org>
6 # Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
7 # This is free software; see the source for copying conditions. There is NO
8 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # This program 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 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # 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, a copy can be downloaded from
22 # http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
23 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 # MA 02110-1301, USA.
26 # Usage: $progname [options]
28 # -v --version print version information
29 # -h,-? --help print short or long help message
31 # You can also set the following variables to help $progname
32 # locate the right tools:
33 # AUTORECONF, GNULIB_TOOL, RM, SED
35 # This script bootstraps a CVS checkout of GNU M4 by correctly
36 # calling out to parts of the GNU Build Platform. Currently this
37 # requires GNU Autoconf 2.60, GNU Automake 1.9.6, and bleeding edge
38 # CVS snapshots of GNU Gnulib.
40 # Report bugs to <bug-m4@gnu.org>
42 : ${AUTORECONF=autoreconf}
43 : ${GNULIB_TOOL=gnulib-tool}
44 : ${RM=rm -f}
45 : ${SED=sed}
47 dirname="s,/[^/]*$,,"
48 basename="s,^.*/,,g"
50 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
51 # is ksh but when the shell is invoked as "sh" and the current value of
52 # the _XPG environment variable is not equal to 1 (one), the special
53 # positional parameter $0, within a function call, is the name of the
54 # function.
55 progpath="$0"
57 # The name of this program:
58 progname=`echo "$progpath" | $SED "$basename"`
59 PROGRAM=bootstrap
61 # func_echo arg...
62 # Echo program name prefixed message.
63 func_echo ()
65 echo $progname: ${1+"$@"}
69 # func_error arg...
70 # Echo program name prefixed message to standard error.
71 func_error ()
73 echo $progname: ${1+"$@"} >&2
76 # func_fatal_error arg...
77 # Echo program name prefixed message to standard error, and exit.
78 func_fatal_error ()
80 func_error ${1+"$@"}
81 exit $EXIT_FAILURE
84 # func_verbose arg...
85 # Echo program name prefixed message in verbose mode only.
86 func_verbose ()
88 $opt_verbose && func_error ${1+"$@"}
91 # func_missing_arg argname
92 # Echo program name prefixed message to standard error and set global
93 # exit_cmd.
94 func_missing_arg ()
96 func_error "missing argument for $1"
97 exit_cmd=exit
100 # func_fatal_help arg...
101 # Echo program name prefixed message to standard error, followed by
102 # a help hint, and exit.
103 func_fatal_help ()
105 func_error ${1+"$@"}
106 func_fatal_error "Try \`$progname --help' for more information."
109 # func_missing_arg argname
110 # Echo program name prefixed message to standard error and set global
111 # exit_cmd.
112 func_missing_arg ()
114 func_error "missing argument for $1"
115 exit_cmd=exit
118 # func_usage
119 # Echo short help message to standard output and exit.
120 func_usage ()
122 $SED '/^# Usage:/,/# -h/ {
123 s/^# //; s/^# *$//;
124 s/\$progname/'$progname'/;
126 }; d' < "$progpath"
127 echo
128 echo "run \`$progname --help | more' for full usage"
129 exit $EXIT_SUCCESS
132 # func_help
133 # Echo long help message to standard output and exit.
134 func_help ()
136 $SED '/^# Usage:/,/# Report bugs to/ {
137 s/^# //; s/^# *$//;
138 s/\$progname/'$progname'/;
140 }; d' < "$progpath"
141 exit $EXIT_SUCCESS
144 # func_version
145 # Echo version message to standard output and exit.
146 func_version ()
148 $SED '/^# '$PROGRAM' (GNU /,/# warranty; / {
149 s/^# //; s/^# *$//;
150 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
152 }; d' < "$progpath"
153 exit $EXIT_SUCCESS
156 # func_update
157 # Copy $1 to $2 if it is newer.
158 func_update ()
160 if test -f "$2" && cmp -s "$1" "$2" ; then
161 func_verbose "$2 is up-to-date"
162 else
163 func_echo "copying $1 -> $2"
164 cp "$1" "$2"
168 # Parse options once, thoroughly. This comes as soon as possible in
169 # the script to make things like `bootstrap --version' happen quickly.
171 # sed scripts:
172 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
173 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
174 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
175 my_sed_long_arg='1s/^--[^=]*=//'
177 # this just eases exit handling
178 while test $# -gt 0; do
179 opt="$1"
180 shift
181 case $opt in
182 # Separate optargs to short options:
183 -\?|-h) func_usage ;;
184 --help) func_help ;;
185 --version) func_version ;;
186 --) break ;;
187 -*) func_fatal_help "unrecognized option \`$opt'" ;;
188 *) set -- "$opt" ${1+"$@"}; break ;;
189 esac
190 done
192 # Bail if the options were screwed
193 $exit_cmd $EXIT_FAILURE
196 ## ---------------------------- ##
197 ## Find the gnulib module tree. ##
198 ## ---------------------------- ##
200 case $GNULIB_TOOL in
201 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
202 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
203 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
204 esac
206 # Follow symlinks
207 while test -h "$gnulibdir"; do
209 # Resolve symbolic link.
210 sedexpr1='s, -> ,#%%#,'
211 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
212 linkval=`LC_ALL=C ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
213 test -n "$linkval" || break
215 case "$linkval" in
216 /* ) gnulibdir="$linkval" ;;
217 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
218 esac
220 done
222 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
224 ## ---------------------- ##
225 ## Import Gnulib modules. ##
226 ## ---------------------- ##
228 func_echo "running: $GNULIB_TOOL --update"
229 $GNULIB_TOOL --update || func_fatal_error "gnulib-tool failed"
231 ## ----------- ##
232 ## Autoreconf. ##
233 ## ----------- ##
235 func_echo "running: $AUTORECONF --force --verbose --install"
236 $AUTORECONF --force --verbose --install || func_fatal_error "autoreconf failed"
238 ## ---------------------------------------- ##
239 ## Gnulib is more up-to-date than automake. ##
240 ## ---------------------------------------- ##
242 func_update "$gnulibdir"/build-aux/config.guess config.guess
243 func_update "$gnulibdir"/build-aux/config.sub config.sub
244 func_update "$gnulibdir"/build-aux/depcomp depcomp
245 func_update "$gnulibdir"/build-aux/install-sh install-sh
246 func_update "$gnulibdir"/build-aux/mdate-sh doc/mdate-sh
247 func_update "$gnulibdir"/build-aux/missing missing
248 func_update "$gnulibdir"/build-aux/texinfo.tex doc/texinfo.tex
249 func_update "$gnulibdir"/doc/COPYING COPYING
250 func_update "$gnulibdir"/doc/INSTALL INSTALL
252 exit 0
254 # Local variables:
255 # eval: (add-hook 'write-file-hooks 'time-stamp)
256 # time-stamp-start: "# bootstrap (GNU M4) version "
257 # time-stamp-format: "%:y-%02m-%02d"
258 # time-stamp-end: "$"
259 # End: