* bootstrap: Enhanced to work more like our other scripts:
[m4/ericb.git] / bootstrap
blobe0040f6bfb79bb57414e78d98672316020ce407b
1 #! /bin/sh
3 # bootstrap (GNU M4) version 2006-07-13
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 # -p ARG --download-po=ARG whether to download pofiles [yes]
29 # -v --version print version information
30 # -h,-? --help print short or long help message
32 # You can also set the following variables to help $progname
33 # locate the right tools:
34 # AUTORECONF, AWK, GNULIB_TOOL, RM, SED, WGET
36 # This script bootstraps a CVS checkout of GNU M4 by correctly
37 # calling out to parts of the GNU Build Platform. Currently this
38 # requires the latest releases of GNU Gettext and Autoconf, and
39 # bleeding edge CVS snapshots of GNU Automake, Libtool & Gnulib.
41 # Report bugs to <bug-m4@gnu.org>
43 : ${AUTORECONF=autoreconf}
44 : ${AWK=awk}
45 : ${GNULIB_TOOL=gnulib-tool}
46 : ${RM=rm -f}
47 : ${SED=sed}
48 : ${WGET=wget}
50 : ${DOWNLOAD_PO=yes}
52 ltdldir=ltdl
53 config_aux_dir=$ltdldir/config
54 config_macro_dir=$ltdldir/m4
55 bailout_cb=:
57 # List dependencies here too; we don't extract them, otherwise dependent
58 # modules could end up being imported to src/ *and* gnu/!
59 src_modules='getopt version-etc-fsf version-etc'
61 dirname="s,/[^/]*$,,"
62 basename="s,^.*/,,g"
64 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
65 # is ksh but when the shell is invoked as "sh" and the current value of
66 # the _XPG environment variable is not equal to 1 (one), the special
67 # positional parameter $0, within a function call, is the name of the
68 # function.
69 progpath="$0"
71 # The name of this program:
72 progname=`echo "$progpath" | $SED "$basename"`
73 PROGRAM=bootstrap
75 # func_echo arg...
76 # Echo program name prefixed message.
77 func_echo ()
79 echo $progname: ${1+"$@"}
82 # func_error arg...
83 # Echo program name prefixed message to standard error.
84 func_error ()
86 echo $progname: ${1+"$@"} >&2
89 # func_fatal_error arg...
90 # Echo program name prefixed message to standard error, and exit.
91 func_fatal_error ()
93 func_error ${1+"$@"}
94 exit $EXIT_FAILURE
97 # func_verbose arg...
98 # Echo program name prefixed message in verbose mode only.
99 func_verbose ()
101 $opt_verbose && func_error ${1+"$@"}
104 # func_missing_arg argname
105 # Echo program name prefixed message to standard error and set global
106 # exit_cmd.
107 func_missing_arg ()
109 func_error "missing argument for $1"
110 exit_cmd=exit
113 # func_fatal_help arg...
114 # Echo program name prefixed message to standard error, followed by
115 # a help hint, and exit.
116 func_fatal_help ()
118 func_error ${1+"$@"}
119 func_fatal_error "Try \`$progname --help' for more information."
122 # func_missing_arg argname
123 # Echo program name prefixed message to standard error and set global
124 # exit_cmd.
125 func_missing_arg ()
127 func_error "missing argument for $1"
128 exit_cmd=exit
131 # func_usage
132 # Echo short help message to standard output and exit.
133 func_usage ()
135 $SED '/^# Usage:/,/# -h/ {
136 s/^# //; s/^# *$//;
137 s/\$progname/'$progname'/;
139 }; d' < "$progpath"
140 echo
141 echo "run \`$progname --help | more' for full usage"
142 exit $EXIT_SUCCESS
145 # func_help
146 # Echo long help message to standard output and exit.
147 func_help ()
149 $SED '/^# Usage:/,/# Report bugs to/ {
150 s/^# //; s/^# *$//;
151 s/\$progname/'$progname'/;
153 }; d' < "$progpath"
154 exit $EXIT_SUCCESS
157 # func_version
158 # Echo version message to standard output and exit.
159 func_version ()
161 $SED '/^# '$PROGRAM' (GNU /,/# warranty; / {
162 s/^# //; s/^# *$//;
163 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
165 }; d' < "$progpath"
166 exit $EXIT_SUCCESS
169 # Parse options once, thoroughly. This comes as soon as possible in
170 # the script to make things like `commit --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 -p|--download-po)
184 test $# = 0 && func_missing_arg $opt && break
185 case $opt in
186 0|[Nn]*|[Ff]*) DOWNLOAD_PO=no ;;
187 [Oo]*) DOWNLOAD_PO=only ;;
188 esac
191 # Separate optargs to long options:
192 --download-po=*)
193 arg=`echo "$opt" | $SED "$my_sed_long_arg"`
194 opt=`echo "$opt" | $SED "$my_sed_long_opt"`
195 set -- "$opt" "$arg" ${1+"$@"}
198 # Separate optargs to short options:
199 -p*)
200 arg=`echo "$opt" |$SED "$my_sed_single_rest"`
201 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
202 set -- "$opt" "$arg" ${1+"$@"}
205 -\?|-h) func_usage ;;
206 --help) func_help ;;
207 --version) func_version ;;
208 --) break ;;
209 -*) func_fatal_help "unrecognized option \`$opt'" ;;
210 *) set -- "$opt" ${1+"$@"}; break ;;
211 esac
212 done
214 if test -z "$sendmail_to"; then
216 # can't have a from address without a destination address
217 test -n "$sendmail_from" &&
218 func_error "can't use --from without --sendmail." && exit_cmd=exit
220 # can't use a signature file without a destination address
221 test -n "$signature_file" &&
222 func_error "can't use --signature without --sendmail." && exit_cmd=exit
225 # Bail if the options were screwed
226 $exit_cmd $EXIT_FAILURE
229 ## ------------------------------ ##
230 ## Fetch translations. ##
231 ## (taken from GNU tar bootstrap) ##
232 ## ------------------------------ ##
234 TP_URL="http://www.iro.umontreal.ca/translation/maint/m4/"
236 func_update_po ()
238 if test $# = 1; then
239 case $1 in
240 *.po) POFILE=$1 ;;
241 *) POFILE=$1.po ;;
242 esac
243 func_echo "getting translation for $1..."
244 $WGET -r --cache=off $TP_URL/$POFILE
245 else
246 func_echo "getting translations into po..."
247 (cd po &&
248 rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'` &&
249 $WGET -nv -nd -r -l 1 -A .po --cache=off $TP_URL &&
250 rm -f index.html index.html.[0-9]*
251 ls *.po | sed 's/\.po$//' > LINGUAS
252 ) || exit
256 case $DOWNLOAD_PO in
257 no) ;;
258 only) func_update_po; exit 0 ;;
259 yes) func_update_po ;;
260 *) func_update_po $DOWNLOAD_PO ;;
261 esac
263 ## ---------------------------- ##
264 ## Find the gnulib module tree. ##
265 ## ---------------------------- ##
267 case $GNULIB_TOOL in
268 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
269 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
270 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
271 esac
273 # Follow symlinks
274 while test -h "$gnulibdir"; do
276 # Resolve symbolic link.
277 sedexpr1='s, -> ,#%%#,'
278 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
279 linkval=`LC_ALL=C ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
280 test -n "$linkval" || break
282 case "$linkval" in
283 /* ) gnulibdir="$linkval" ;;
284 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
285 esac
287 done
289 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
292 ## ---------------------- ##
293 ## Import Gnulib modules. ##
294 ## ---------------------- ##
296 func_echo "running: ${GNULIB_TOOL} --update"
297 ${GNULIB_TOOL} --update
299 func_echo "patching include directories in gnulib regex module"
300 mv $config_macro_dir/regex.m4 $config_macro_dir/regex-m4.old
301 sed 's,lib/regex.c,gnu/regex.c,g' $config_macro_dir/regex-m4.old > $config_macro_dir/regex.m4 && \
302 $RM $config_macro_dir/regex-m4.old
304 func_echo "hiding gnulib jm_\* macros"
305 cat >> $config_macro_dir/gnulib.m4 <<\EOF
306 AC_DEFUN([gl_AC_HEADER_INTTYPES_H], [jm_AC_HEADER_INTTYPES_H])
307 AC_DEFUN([gl_AC_HEADER_STDINT_H], [jm_AC_HEADER_STDINT_H])
308 AC_DEFUN([gl_AC_TYPE_UINTMAX_T], [jm_AC_TYPE_UINTMAX_T])
312 ## --------------------------------- ##
313 ## Copy additional src only modules. ##
314 ## --------------------------------- ##
316 func_echo "fetching modules for src directory"
318 for file in `${GNULIB_TOOL} --extract-filelist $src_modules`; do
320 dest=`echo $file | $SED "$basename"`
321 case $file in
322 lib/*) dest=src/$dest ;;
323 m4/*) dest=$config_macro_dir/$dest ;;
324 *) func_echo "Unknown file: $file"
325 exit 1
327 esac
329 # Be sure to show all copying errors before bailing out
330 if test -f $gnulibdir/$file; then
331 func_echo "copying file \`$dest'"
332 cp $gnulibdir/$file $dest
333 else
334 func_error "$gnulibdir/$file does not exist"
335 bailout_cb="exit 1"
337 done
338 $bailout_cb
341 ## ----------- ##
342 ## Autoreconf. ##
343 ## ----------- ##
345 func_echo "running: $AUTORECONF --force --verbose --install --no-recursive"
346 $AUTORECONF --force --verbose --install --no-recursive
349 ## ---------- ##
350 ## testsuite. ##
351 ## ---------- ##
354 func_echo "generating testsuite"
355 cd tests
356 $AWK -f ./generate.awk ../doc/m4.texinfo > generated.at
359 if test x"$DOWNLOAD_PO" != xno; then
360 func_echo "If your pofiles are uptodate, you can rerun bootstrap"
361 func_echo "as \`DOWNLOAD_PO=no $progname' to avoid redownloading."
364 exit 0
366 # Local variables:
367 # eval: (add-hook 'write-file-hooks 'time-stamp)
368 # time-stamp-start: "# bootstrap (GNU M4) version "
369 # time-stamp-format: "%:y-%02m-%02d"
370 # time-stamp-end: "$"
371 # End: