Add macro name to debugfile messages.
[m4.git] / bootstrap
blob140ed0ed785a33773026dcb2e6bef8905328249e
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 # -p ARG --download-po=ARG whether to download pofiles [yes]
27 # -v --version print version information
28 # -h,-? --help print short or long help message
30 # For --download-po, ARG can also be `no' to skip pofile downloads,
31 # `only' to just update pofiles, or a set of locales to add or update.
33 # You can also set the following variables to help $progname
34 # locate the right tools:
35 # AUTOPOINT, AUTORECONF, AWK, GNULIB_TOOL, M4, RM, SED, WGET
37 # This script bootstraps a git or CVS checkout of GNU M4 by correctly calling
38 # out to parts of the GNU Build Platform. Currently this requires GNU
39 # Gettext 0.16 or better, Autoconf 2.60 or better, GNU M4 1.4.x or
40 # better, a git snapshot of Automake 1.10a or better, a CVS snapshot
41 # of Libtool 2.1a or better, and the latest git or CVS checkout of Gnulib.
42 # Libtool must be installed; either with the same --prefix as
43 # automake, or made accessible to aclocal's search path via
44 # $AUTOMAKE_prefix/share/aclocal/dirlist.
46 # Report bugs to <bug-m4@gnu.org>
48 : ${AUTOPOINT=autopoint}
49 : ${AUTORECONF=autoreconf}
50 : ${AWK=awk}
51 : ${GNULIB_TOOL=gnulib-tool}
52 : ${M4=m4}
53 : ${RM=rm -f}
54 : ${SED=sed}
55 : ${WGET=wget}
56 export WGET
58 : ${DOWNLOAD_PO=yes}
60 # Ensure file names are sorted consistently across platforms.
61 # Also, ensure diagnostics are in English, e.g., "wget --help" below.
62 LC_ALL=C
63 export LC_ALL
65 package=m4
66 ltdldir=ltdl
67 config_aux_dir=build-aux
68 config_macro_dir=$ltdldir/m4
69 bailout_cb=:
71 # List dependencies here too; we don't extract them, otherwise dependent
72 # modules could end up being imported to src/ *and* gnu/!
73 src_modules='getopt version-etc-fsf version-etc xstrtol'
75 dirname="s,/[^/]*$,,"
76 basename="s,^.*/,,g"
78 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
79 # is ksh but when the shell is invoked as "sh" and the current value of
80 # the _XPG environment variable is not equal to 1 (one), the special
81 # positional parameter $0, within a function call, is the name of the
82 # function.
83 progpath="$0"
85 # The name of this program:
86 progname=`echo "$progpath" | $SED "$basename"`
87 PROGRAM=bootstrap
89 # Detect whether this is a version control system checkout or a tarball
90 vcs_only_file=HACKING
92 # func_echo arg...
93 # Echo program name prefixed message.
94 func_echo ()
96 echo $progname: ${1+"$@"}
99 # func_error arg...
100 # Echo program name prefixed message to standard error.
101 func_error ()
103 echo $progname: ${1+"$@"} >&2
106 # func_fatal_error arg...
107 # Echo program name prefixed message to standard error, and exit.
108 func_fatal_error ()
110 func_error ${1+"$@"}
111 exit $EXIT_FAILURE
114 # func_verbose arg...
115 # Echo program name prefixed message in verbose mode only.
116 func_verbose ()
118 $opt_verbose && func_error ${1+"$@"}
121 # func_missing_arg argname
122 # Echo program name prefixed message to standard error and set global
123 # exit_cmd.
124 func_missing_arg ()
126 func_error "missing argument for $1"
127 exit_cmd=exit
130 # func_fatal_help arg...
131 # Echo program name prefixed message to standard error, followed by
132 # a help hint, and exit.
133 func_fatal_help ()
135 func_error ${1+"$@"}
136 func_fatal_error "Try \`$progname --help' for more information."
139 # func_missing_arg argname
140 # Echo program name prefixed message to standard error and set global
141 # exit_cmd.
142 func_missing_arg ()
144 func_error "missing argument for $1"
145 exit_cmd=exit
148 # func_usage
149 # Echo short help message to standard output and exit.
150 func_usage ()
152 $SED '/^# Usage:/,/# -h/ {
153 s/^# //; s/^# *$//;
154 s/\$progname/'$progname'/;
156 }; d' < "$progpath"
157 echo
158 echo "run \`$progname --help | more' for full usage"
159 exit $EXIT_SUCCESS
162 # func_help
163 # Echo long help message to standard output and exit.
164 func_help ()
166 $SED '/^# Usage:/,/# Report bugs to/ {
167 s/^# //; s/^# *$//;
168 s/\$progname/'$progname'/;
170 }; d' < "$progpath"
171 exit $EXIT_SUCCESS
174 # func_version
175 # Echo version message to standard output and exit.
176 func_version ()
178 $SED '/^# '$PROGRAM' (GNU /,/# warranty; / {
179 s/^# //; s/^# *$//;
180 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
182 }; d' < "$progpath"
183 exit $EXIT_SUCCESS
186 # func_update
187 # Copy $1 to $2 if it is newer.
188 func_update ()
190 if test -f "$2" && cmp -s "$1" "$2" ; then
191 func_verbose "$2 is up-to-date"
192 else
193 func_echo "copying $1 -> $2"
194 cp "$1" "$2"
198 # Parse options once, thoroughly. This comes as soon as possible in
199 # the script to make things like `bootstrap --version' happen quickly.
201 # sed scripts:
202 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
203 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
204 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
205 my_sed_long_arg='1s/^--[^=]*=//'
207 # this just eases exit handling
208 while test $# -gt 0; do
209 opt="$1"
210 shift
211 case $opt in
212 -p|--download-po)
213 test $# = 0 && func_missing_arg $opt && break
214 case $1 in
215 0|[Nn]*|[Ff]*) DOWNLOAD_PO=no ;;
216 [Oo]*) DOWNLOAD_PO=only ;;
217 esac
220 # Separate optargs to long options:
221 --download-po=*)
222 arg=`echo "$opt" | $SED "$my_sed_long_arg"`
223 opt=`echo "$opt" | $SED "$my_sed_long_opt"`
224 set -- "$opt" "$arg" ${1+"$@"}
227 # Separate optargs to short options:
228 -p*)
229 arg=`echo "$opt" |$SED "$my_sed_single_rest"`
230 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
231 set -- "$opt" "$arg" ${1+"$@"}
234 -f|--force) vcs_only_file= ;;
235 -\?|-h) func_usage ;;
236 --help) func_help ;;
237 --version) func_version ;;
238 --) break ;;
239 -*) func_fatal_help "unrecognized option \`$opt'" ;;
240 *) set -- "$opt" ${1+"$@"}; break ;;
241 esac
242 done
244 # Bail if the options were screwed
245 $exit_cmd $EXIT_FAILURE
247 if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
248 func_fatal_error \
249 "Bootstrapping from a non-version-control distribution is risky."
253 ## ------------------------------ ##
254 ## Fetch translations. ##
255 ## (taken from GNU tar bootstrap) ##
256 ## ------------------------------ ##
258 func_get_translations()
260 subdir=$1
261 domain=$2
262 po_file=$3
264 url=http://translationproject.org/domain/$2.html
265 baseurl=`expr "$url" : '\(.*\)/.*'`
267 func_echo "getting translations into $subdir for $domain..."
269 case $po_file in
270 '') (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`);;
271 esac &&
273 $WGET -nv --cache=off -O "$subdir/$domain.html" "$url" &&
275 sed -n 's|.*href="\(.*\)/\([^/][^/]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\2:\3:\1|p' <"$subdir/$domain.html" |
276 sort -t: -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
277 $AWK -F: '
278 { if (lang && $1 != lang) print lang, ver, subdir }
279 { lang = $1; ver = $2; subdir = $3 }
280 END { if (lang) print lang, ver, subdir }
281 ' | $AWK -v domain="$domain" -v po_file="$po_file" -v baseurl="$baseurl" -v subdir="$subdir" '
283 lang = $1
284 if (po_file == (lang ".po")) next
286 ver = $2
287 urlfmt = ""
288 printf "$WGET -nv --cache=off -O %s/%s.po %s/%s/%s/%s-%s.%s.po &&\n", subdir, lang, baseurl, $3, lang, domain, ver, lang
290 END { print ":" }
292 sh &&
293 ls "$subdir"/*.po | sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
294 rm "$subdir/$domain.html"
297 ## ------------------------------ ##
298 ## Update translations. ##
299 ## (taken from GNU tar bootstrap) ##
300 ## ------------------------------ ##
302 func_update_po ()
304 if test $# = 1; then
305 case $1 in
306 *.po) POFILE=$1 ;;
307 *) POFILE=$1.po ;;
308 esac
309 func_get_translations ./po $package "$POFILE" &&
310 LANG=`expr $POFILE : '\(.*\)\.po'` &&
311 { grep -q $LANG po/LINGUAS ||
312 (echo $LANG; cat po/LINGUAS) | sort -o po/LINGUAS; }
313 else
314 func_get_translations ./po $package
318 case $DOWNLOAD_PO in
319 no) ;;
320 only) func_update_po; exit 0 ;;
321 yes) func_update_po ;;
322 *) func_update_po $DOWNLOAD_PO ;;
323 esac
325 ## ---------------- ##
326 ## Version control. ##
327 ## ---------------- ##
329 # gnulib-tool updates ltdl/m4/.{git,cvs}ignore and gnu/.{git,cvs}ignore, and
330 # keeping generated files under version control does not make sense. Since
331 # gnu is entirely ignored, we only need to prepopulate the ltdl/m4 ignore
332 # files with generated files not tracked by gnulib-tool.
333 if test -f $config_macro_dir/.gitignore ; then
335 else
336 func_echo "creating initial $config_macro_dir/.cvsignore"
337 cat > $config_macro_dir/.cvsignore <<\EOF
338 # files created by gnulib, but that gnulib doesn't track
340 .cvsignore
341 .gitignore
342 gnulib-comp.m4
343 # files manually imported, rather than using gnulib-tool
344 getopt.m4
345 xstrtol.m4
346 # files created by autopoint
347 codeset.m4
348 gettext.m4
349 glibc2.m4
350 glibc21.m4
351 iconv.m4
352 intdiv0.m4
353 intl.m4
354 intldir.m4
355 intmax.m4
356 inttypes-pri.m4
357 inttypes_h.m4
358 lcmessage.m4
359 lib-ld.m4
360 lib-link.m4
361 lib-prefix.m4
362 lock.m4
363 longdouble.m4
364 longlong.m4
365 nls.m4
366 po.m4
367 printf-posix.m4
368 progtest.m4
369 size_max.m4
370 stdint_h.m4
371 uintmax_t.m4
372 ulonglong.m4
373 visibility.m4
374 wchar_t.m4
375 wint_t.m4
376 xsize.m4
377 # files created by libtoolize
378 argz.m4
379 libtool.m4
380 ltdl.m4
381 ltoptions.m4
382 ltsugar.m4
383 ltversion.m4
384 lt~obsolete.m4
385 # gnulib-tool edits below here
387 func_echo "creating initial $config_macro_dir/.gitignore"
388 cp $config_macro_dir/.cvsignore $config_macro_dir/.gitignore
391 ## ---------- ##
392 ## Autopoint. ##
393 ## ---------- ##
395 # Released autopoint has the tendency to install macros that have been
396 # obsoleted in current gnulib, so run this before gnulib-tool.
397 func_echo "running: $AUTOPOINT --force"
398 $AUTOPOINT --force
400 ## ---------------------------- ##
401 ## Find the gnulib module tree. ##
402 ## ---------------------------- ##
404 case $GNULIB_TOOL in
405 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
406 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
407 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
408 esac
410 # Follow symlinks
411 while test -h "$gnulibdir"; do
413 # Resolve symbolic link.
414 sedexpr1='s, -> ,#%%#,'
415 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
416 linkval=`ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
417 test -n "$linkval" || break
419 case "$linkval" in
420 /* ) gnulibdir="$linkval" ;;
421 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
422 esac
424 done
426 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
429 ## ---------------------- ##
430 ## Import Gnulib modules. ##
431 ## ---------------------- ##
433 func_echo "running: ${GNULIB_TOOL} --update"
434 ${GNULIB_TOOL} --update
437 ## --------------------------------- ##
438 ## Copy additional src only modules. ##
439 ## --------------------------------- ##
441 func_echo "fetching modules for src directory"
443 for file in `${GNULIB_TOOL} --extract-filelist $src_modules`; do
445 dest=`echo $file | $SED "$basename"`
446 case $file in
447 lib/*) dest=src/$dest ;;
448 m4/*) dest=$config_macro_dir/$dest ;;
449 *) func_echo "Unknown file: $file"
450 exit 1
452 esac
454 # Be sure to show all copying errors before bailing out
455 if test -f $gnulibdir/$file; then
456 func_echo "copying file \`$dest'"
457 cp $gnulibdir/$file $dest
458 else
459 func_error "$gnulibdir/$file does not exist"
460 bailout_cb="exit 1"
462 done
463 $bailout_cb
466 ## ----------- ##
467 ## Autoreconf. ##
468 ## ----------- ##
470 # Disable autopoint, since it was already done above.
471 func_echo "running: AUTOPOINT=true" \
472 "$AUTORECONF --force --verbose --install --no-recursive"
473 AUTOPOINT=true $AUTORECONF --force --verbose --install --no-recursive
476 ## ---------------------------------------- ##
477 ## Gnulib is more up-to-date than automake. ##
478 ## ---------------------------------------- ##
480 func_update "$gnulibdir"/build-aux/config.guess $config_aux_dir/config.guess
481 func_update "$gnulibdir"/build-aux/config.sub $config_aux_dir/config.sub
482 func_update "$gnulibdir"/build-aux/depcomp $config_aux_dir/depcomp
483 func_update "$gnulibdir"/build-aux/install-sh $config_aux_dir/install-sh
484 func_update "$gnulibdir"/build-aux/mdate-sh $config_aux_dir/mdate-sh
485 func_update "$gnulibdir"/build-aux/missing $config_aux_dir/missing
486 func_update "$gnulibdir"/build-aux/texinfo.tex $config_aux_dir/texinfo.tex
487 func_update "$gnulibdir"/build-aux/po/Makefile.in.in po/Makefile.in.in
488 func_update "$gnulibdir"/build-aux/po/remove-potcdate.sin po/remove-potcdate.sin
489 func_update "$gnulibdir"/doc/COPYINGv3 COPYING
490 func_update "$gnulibdir"/doc/INSTALL INSTALL
493 ## ------- ##
494 ## Wrapup. ##
495 ## ------- ##
497 if test x"$DOWNLOAD_PO" != xno; then
498 func_echo "If your pofiles are up-to-date, you can rerun bootstrap"
499 func_echo "as \`DOWNLOAD_PO=no $progname' to avoid redownloading."
502 exit 0
504 # Local variables:
505 # eval: (add-hook 'write-file-hooks 'time-stamp)
506 # time-stamp-start: "# bootstrap (GNU M4) version "
507 # time-stamp-format: "%:y-%02m-%02d"
508 # time-stamp-end: "$"
509 # End: