Stage 7: add chained token support to input parser.
[m4/ericb.git] / bootstrap
blob686434c139af0642e0f73f9a13de2c22949b8cb9
1 #! /bin/sh
3 # bootstrap (GNU M4) version 2007-11-05
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 git
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, M4, RM, SED
33 # This script bootstraps a git or 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 # git or 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 # Ensure file names are sorted consistently across platforms.
46 LC_ALL=C
47 export LC_ALL
49 config_macro_dir=m4
51 dirname="s,/[^/]*$,,"
52 basename="s,^.*/,,g"
54 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
55 # is ksh but when the shell is invoked as "sh" and the current value of
56 # the _XPG environment variable is not equal to 1 (one), the special
57 # positional parameter $0, within a function call, is the name of the
58 # function.
59 progpath="$0"
61 # The name of this program:
62 progname=`echo "$progpath" | $SED "$basename"`
63 PROGRAM=bootstrap
65 # Detect whether this is a version control system checkout or a tarball
66 vcs_only_file=HACKING
68 # func_echo arg...
69 # Echo program name prefixed message.
70 func_echo ()
72 echo $progname: ${1+"$@"}
76 # func_error arg...
77 # Echo program name prefixed message to standard error.
78 func_error ()
80 echo $progname: ${1+"$@"} >&2
83 # func_fatal_error arg...
84 # Echo program name prefixed message to standard error, and exit.
85 func_fatal_error ()
87 func_error ${1+"$@"}
88 exit $EXIT_FAILURE
91 # func_verbose arg...
92 # Echo program name prefixed message in verbose mode only.
93 func_verbose ()
95 $opt_verbose && func_error ${1+"$@"}
98 # func_missing_arg argname
99 # Echo program name prefixed message to standard error and set global
100 # exit_cmd.
101 func_missing_arg ()
103 func_error "missing argument for $1"
104 exit_cmd=exit
107 # func_fatal_help arg...
108 # Echo program name prefixed message to standard error, followed by
109 # a help hint, and exit.
110 func_fatal_help ()
112 func_error ${1+"$@"}
113 func_fatal_error "Try \`$progname --help' for more information."
116 # func_missing_arg argname
117 # Echo program name prefixed message to standard error and set global
118 # exit_cmd.
119 func_missing_arg ()
121 func_error "missing argument for $1"
122 exit_cmd=exit
125 # func_usage
126 # Echo short help message to standard output and exit.
127 func_usage ()
129 $SED '/^# Usage:/,/# -h/ {
130 s/^# //; s/^# *$//;
131 s/\$progname/'$progname'/;
133 }; d' < "$progpath"
134 echo
135 echo "run \`$progname --help | more' for full usage"
136 exit $EXIT_SUCCESS
139 # func_help
140 # Echo long help message to standard output and exit.
141 func_help ()
143 $SED '/^# Usage:/,/# Report bugs to/ {
144 s/^# //; s/^# *$//;
145 s/\$progname/'$progname'/;
147 }; d' < "$progpath"
148 exit $EXIT_SUCCESS
151 # func_version
152 # Echo version message to standard output and exit.
153 func_version ()
155 $SED '/^# '$PROGRAM' (GNU /,/# warranty; / {
156 s/^# //; s/^# *$//;
157 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
159 }; d' < "$progpath"
160 exit $EXIT_SUCCESS
163 # func_update
164 # Copy $1 to $2 if it is newer.
165 func_update ()
167 if test -f "$2" && cmp -s "$1" "$2" ; then
168 func_verbose "$2 is up-to-date"
169 else
170 func_echo "copying $1 -> $2"
171 cp "$1" "$2"
175 # Parse options once, thoroughly. This comes as soon as possible in
176 # the script to make things like `bootstrap --version' happen quickly.
178 # sed scripts:
179 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
180 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
181 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
182 my_sed_long_arg='1s/^--[^=]*=//'
184 # this just eases exit handling
185 while test $# -gt 0; do
186 opt="$1"
187 shift
188 case $opt in
189 # Separate optargs to short options:
190 -f|--force) vcs_only_file= ;;
191 -\?|-h) func_usage ;;
192 --help) func_help ;;
193 --version) func_version ;;
194 --) break ;;
195 -*) func_fatal_help "unrecognized option \`$opt'" ;;
196 *) set -- "$opt" ${1+"$@"}; break ;;
197 esac
198 done
200 # Bail if the options were screwed
201 $exit_cmd $EXIT_FAILURE
203 if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
204 func_fatal_error \
205 "Bootstrapping from a non-version-control distribution is risky."
209 ## ---------------- ##
210 ## Version control. ##
211 ## ---------------- ##
213 # gnulib-tool updates m4/.{git,cvs}ignore and lib/.{git,cvs}ignore, and
214 # keeping generated files under version control does not make sense.
215 # Since lib is entirely ignored, we only need to prepopulate the m4 ignore
216 # files with generated files not tracked by gnulib-tool.
217 if test -f $config_macro_dir/.gitignore ; then
219 else
220 func_echo "creating initial $config_macro_dir/.cvsignore"
221 cat > $config_macro_dir/.cvsignore <<\EOF
222 # files created by gnulib, but that gnulib doesn't track
224 .cvsignore
225 .gitignore
226 gnulib-comp.m4
227 # gnulib-tool edits below here
229 func_echo "creating initial $config_macro_dir/.gitignore"
230 cp $config_macro_dir/.cvsignore $config_macro_dir/.gitignore
233 ## ---------------------------- ##
234 ## Find the gnulib module tree. ##
235 ## ---------------------------- ##
237 case $GNULIB_TOOL in
238 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
239 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
240 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
241 esac
243 # Follow symlinks
244 while test -h "$gnulibdir"; do
246 # Resolve symbolic link.
247 sedexpr1='s, -> ,#%%#,'
248 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
249 linkval=`ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
250 test -n "$linkval" || break
252 case "$linkval" in
253 /* ) gnulibdir="$linkval" ;;
254 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
255 esac
257 done
259 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
261 ## ---------------------- ##
262 ## Import Gnulib modules. ##
263 ## ---------------------- ##
265 func_echo "running: $GNULIB_TOOL --update"
266 $GNULIB_TOOL --update || func_fatal_error "gnulib-tool failed"
268 ## ----------- ##
269 ## Autoreconf. ##
270 ## ----------- ##
272 func_echo "running: $AUTORECONF --force --verbose --install"
273 $AUTORECONF --force --verbose --install || func_fatal_error "autoreconf failed"
275 ## ---------------------------------------- ##
276 ## Gnulib is more up-to-date than automake. ##
277 ## ---------------------------------------- ##
279 func_update "$gnulibdir"/build-aux/config.guess build-aux/config.guess
280 func_update "$gnulibdir"/build-aux/config.sub build-aux/config.sub
281 func_update "$gnulibdir"/build-aux/depcomp build-aux/depcomp
282 func_update "$gnulibdir"/build-aux/install-sh build-aux/install-sh
283 func_update "$gnulibdir"/build-aux/mdate-sh build-aux/mdate-sh
284 func_update "$gnulibdir"/build-aux/missing build-aux/missing
285 func_update "$gnulibdir"/build-aux/texinfo.tex build-aux/texinfo.tex
286 func_update "$gnulibdir"/doc/COPYINGv3 COPYING
287 func_update "$gnulibdir"/doc/INSTALL INSTALL
289 exit 0
291 # Local variables:
292 # eval: (add-hook 'write-file-hooks 'time-stamp)
293 # time-stamp-start: "# bootstrap (GNU M4) version "
294 # time-stamp-format: "%:y-%02m-%02d"
295 # time-stamp-end: "$"
296 # End: