Stage 27: Allow embedded NUL in text processing macros.
[m4.git] / bootstrap
blob7bd9f7ee312f4f15ee9a8798a5d64440c0a8408d
1 #! /bin/sh
3 # bootstrap (GNU M4) version 2008-09-16
4 # Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
6 # This is free software: you are free to change and redistribute it.
7 # There is NO WARRANTY, to the extent permitted by law.
9 # Written by Gary V. Vaughan <gary@gnu.org>
11 # This file is part of GNU M4.
13 # GNU M4 is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
18 # GNU M4 is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 # Usage: $progname [options]
28 # -f --force bootstrap even when sources are not from git
29 # --skip-po skip downloading pofiles
30 # -v --version print version information
31 # -h,-? --help print short or long help message
33 # You can also set the following variables to help $progname
34 # locate the right tools:
35 # AUTOPOINT, AUTORECONF, AWK, GNULIB_TOOL, LIBTOOLIZE, M4, RM, SED
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.62 or better, GNU M4 1.4.5 or better,
40 # the latest git Automake 1.10a or better, Libtool 2.2 or better,
41 # 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 : ${LIBTOOLIZE=libtoolize}
53 : ${M4=m4}
54 : ${RM='rm -f'}
55 : ${SED=sed}
57 # Ensure file names are sorted consistently across platforms.
58 # Also, ensure diagnostics are in English.
59 LC_ALL=C
60 export LC_ALL
62 package=m4
63 ltdldir=ltdl
64 config_aux_dir=build-aux
65 config_macro_dir=$ltdldir/m4
66 bailout_cb=:
68 # List dependencies here too; we don't extract them, otherwise dependent
69 # modules could end up being imported to src/ *and* gnu/!
70 src_modules='getopt version-etc-fsf version-etc xstrtol'
72 dirname="s,/[^/]*$,,"
73 basename="s,^.*/,,g"
75 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
76 # is ksh but when the shell is invoked as "sh" and the current value of
77 # the _XPG environment variable is not equal to 1 (one), the special
78 # positional parameter $0, within a function call, is the name of the
79 # function.
80 progpath="$0"
82 # The name of this program:
83 progname=`echo "$progpath" | $SED "$basename"`
84 PROGRAM=bootstrap
86 # Detect whether this is a version control system checkout or a tarball
87 vcs_only_file=HACKING
89 # func_echo arg...
90 # Echo program name prefixed message.
91 func_echo ()
93 echo $progname: ${1+"$@"}
96 # func_error arg...
97 # Echo program name prefixed message to standard error.
98 func_error ()
100 echo $progname: ${1+"$@"} >&2
103 # func_fatal_error arg...
104 # Echo program name prefixed message to standard error, and exit.
105 func_fatal_error ()
107 func_error ${1+"$@"}
108 exit $EXIT_FAILURE
111 # func_verbose arg...
112 # Echo program name prefixed message in verbose mode only.
113 func_verbose ()
115 $opt_verbose && func_error ${1+"$@"}
118 # func_missing_arg argname
119 # Echo program name prefixed message to standard error and set global
120 # exit_cmd.
121 func_missing_arg ()
123 func_error "missing argument for $1"
124 exit_cmd=exit
127 # func_fatal_help arg...
128 # Echo program name prefixed message to standard error, followed by
129 # a help hint, and exit.
130 func_fatal_help ()
132 func_error ${1+"$@"}
133 func_fatal_error "Try \`$progname --help' for more information."
136 # func_missing_arg argname
137 # Echo program name prefixed message to standard error and set global
138 # exit_cmd.
139 func_missing_arg ()
141 func_error "missing argument for $1"
142 exit_cmd=exit
145 # func_usage
146 # Echo short help message to standard output and exit.
147 func_usage ()
149 $SED '/^# Usage:/,/# -h/ {
150 s/^# //; s/^# *$//;
151 s/\$progname/'$progname'/;
153 }; d' < "$progpath"
154 echo
155 echo "run \`$progname --help | more' for full usage"
156 exit $EXIT_SUCCESS
159 # func_help
160 # Echo long help message to standard output and exit.
161 func_help ()
163 $SED '/^# Usage:/,/# Report bugs to/ {
164 s/^# //; s/^# *$//;
165 s/\$progname/'$progname'/;
167 }; d' < "$progpath"
168 exit $EXIT_SUCCESS
171 # func_version
172 # Echo version message to standard output and exit.
173 func_version ()
175 $SED '/^# '$PROGRAM' (GNU /,/# Written by / {
176 s/^# //;
177 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
179 }; d' < "$progpath"
180 exit $EXIT_SUCCESS
183 # func_update
184 # Copy $1 to $2 if it is newer.
185 func_update ()
187 if test -f "$2" && cmp -s "$1" "$2" ; then
188 func_verbose "$2 is up-to-date"
189 else
190 func_echo "copying $1 -> $2"
191 cp "$1" "$2"
195 # Parse options once, thoroughly. This comes as soon as possible in
196 # the script to make things like `bootstrap --version' happen quickly.
198 # sed scripts:
199 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
200 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
201 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
202 my_sed_long_arg='1s/^--[^=]*=//'
204 # this just eases exit handling
205 while test $# -gt 0; do
206 opt="$1"
207 shift
208 case $opt in
209 -f|--force) vcs_only_file= ;;
210 --skip-po) SKIP_PO=t ;;
211 -\?|-h) func_usage ;;
212 --help) func_help ;;
213 --version) func_version ;;
214 --) break ;;
215 -*) func_fatal_help "unrecognized option \`$opt'" ;;
216 *) set -- "$opt" ${1+"$@"}; break ;;
217 esac
218 done
220 # Bail if the options were screwed
221 $exit_cmd $EXIT_FAILURE
223 if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
224 func_fatal_error \
225 "Bootstrapping from a non-version-control distribution is risky."
229 ## --------------------------------------- ##
230 ## Fetch translations. ##
231 ## (taken from gnulib build-aux/bootstrap) ##
232 ## --------------------------------------- ##
234 # The command to download all .po files for a specified domain into
235 # a specified directory. Fill in the first %s with the domain name,
236 # the second with the destination directory. Use rsync's -L and -r
237 # options because the latest/%s directory and the .po files within
238 # are all symlinks.
239 po_download_command_format=\
240 "rsync -Lrtvz 'translationproject.org::tp/latest/%s/' '%s'"
242 func_get_translations()
244 subdir=$1
245 domain=$2
247 func_echo "getting translations into $subdir for $domain..."
248 cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
249 eval "$cmd"
252 ## --------------------------------------- ##
253 ## Update translations. ##
254 ## (taken from gnulib build-aux/bootstrap) ##
255 ## --------------------------------------- ##
257 func_update_po ()
259 # Directory containing primary .po files.
260 # Overwrite them only when we're sure a .po file is new.
261 po_dir=po
262 domain=$package
264 # Download *.po files into this dir.
265 # Usually contains *.s1 checksum files.
266 ref_po_dir="$po_dir/.reference"
268 test -d $ref_po_dir || mkdir $ref_po_dir || return
270 func_get_translations $ref_po_dir $domain \
271 && ls "$ref_po_dir"/*.po 2>/dev/null \
272 | sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
273 langs=`cd $ref_po_dir && echo *.po | sed 's/\.po//g'`
275 test "$langs" = '*' && langs=x
276 for po in $langs; do
277 case $po in x) continue;; esac
278 new_po="$ref_po_dir/$po.po"
279 cksum_file="$ref_po_dir/$po.s1"
280 if ! test -f "$cksum_file" ||
281 ! test -f "$po_dir/$po.po" ||
282 ! sha1sum -c --status "$cksum_file" < "$new_po" > /dev/null; then
283 echo "updated $po_dir/$po.po..."
284 cp "$new_po" "$po_dir/$po.po" && sha1sum < "$new_po" > "$cksum_file"
286 done
289 case $SKIP_PO in
290 '') func_update_po ;;
291 esac
293 ## ---------------- ##
294 ## Version control. ##
295 ## ---------------- ##
297 # gnulib-tool updates ltdl/m4/.{git,cvs}ignore and gnu/.{git,cvs}ignore, and
298 # keeping generated files under version control does not make sense. Since
299 # gnu is entirely ignored, we only need to prepopulate the ltdl/m4 ignore
300 # files with generated files not tracked by gnulib-tool.
301 if test -f $config_macro_dir/.gitignore ; then
303 else
304 func_echo "creating initial $config_macro_dir/.cvsignore"
305 cat > $config_macro_dir/.cvsignore <<\EOF
306 # files created by gnulib, but that gnulib doesn't track
308 .cvsignore
309 .gitignore
310 gnulib-comp.m4
311 # files manually imported, rather than using gnulib-tool
312 getopt.m4
313 xstrtol.m4
314 # files created by autopoint
315 codeset.m4
316 gettext.m4
317 glibc2.m4
318 glibc21.m4
319 iconv.m4
320 intdiv0.m4
321 intl.m4
322 intldir.m4
323 intmax.m4
324 inttypes-pri.m4
325 inttypes_h.m4
326 lcmessage.m4
327 lib-ld.m4
328 lib-link.m4
329 lib-prefix.m4
330 lock.m4
331 longdouble.m4
332 longlong.m4
333 nls.m4
334 po.m4
335 printf-posix.m4
336 progtest.m4
337 size_max.m4
338 stdint_h.m4
339 uintmax_t.m4
340 ulonglong.m4
341 visibility.m4
342 wchar_t.m4
343 wint_t.m4
344 xsize.m4
345 # files created by libtoolize
346 argz.m4
347 libtool.m4
348 ltdl.m4
349 ltoptions.m4
350 ltsugar.m4
351 ltversion.m4
352 lt~obsolete.m4
353 # gnulib-tool edits below here
355 func_echo "creating initial $config_macro_dir/.gitignore"
356 cp $config_macro_dir/.cvsignore $config_macro_dir/.gitignore
359 # See if we can use gnulib's git-merge-changelog merge driver.
360 if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
361 if git config merge.merge-changelog.driver >/dev/null ; then
363 elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
364 func_echo "initializing git-merge-changelog driver"
365 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
366 git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
367 else
368 func_echo "consider installing git-merge-changelog from gnulib"
370 if git config diff.texinfo.funcname >/dev/null ; then
372 else
373 func_echo "initializing git texinfo diff driver"
374 git config diff.texinfo.funcname '^@node[ ][ ]*\\([^,][^,]*\\)'
378 ## ---------- ##
379 ## Autopoint. ##
380 ## ---------- ##
382 # Released autopoint has the tendency to install macros that have been
383 # obsoleted in current gnulib, so run this before gnulib-tool.
384 func_echo "running: $AUTOPOINT --force"
385 $AUTOPOINT --force
387 ## ----------- ##
388 ## Libtoolize. ##
389 ## ----------- ##
391 # Autoreconf runs aclocal before libtoolize, which causes spurious
392 # warnings if the initial aclocal is confused by the libtoolized
393 # (or worse out-of-date) macro directory.
394 func_echo "running: $LIBTOOLIZE --force --copy --install"
395 ${LIBTOOLIZE} --force --copy --install
397 ## ---------------------------- ##
398 ## Find the gnulib module tree. ##
399 ## ---------------------------- ##
401 case $GNULIB_TOOL in
402 /* ) gnulibdir=$GNULIB_TOOL ;; # absolute
403 */* ) gnulibdir=`pwd`/$GNULIB_TOOL ;; # relative
404 * ) gnulibdir=`which "$GNULIB_TOOL"` ;; # PATH search
405 esac
407 # Follow symlinks
408 while test -h "$gnulibdir"; do
410 # Resolve symbolic link.
411 sedexpr1='s, -> ,#%%#,'
412 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
413 linkval=`ls -l "$gnulibdir" | $SED "$sedexpr1" | $SED -n "$sedexpr2"`
414 test -n "$linkval" || break
416 case "$linkval" in
417 /* ) gnulibdir="$linkval" ;;
418 * ) gnulibdir=`echo "$gnulibdir" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
419 esac
421 done
423 gnulibdir=`echo "$gnulibdir" | $SED "$dirname"`
426 ## ---------------------- ##
427 ## Import Gnulib modules. ##
428 ## ---------------------- ##
430 func_echo "running: ${GNULIB_TOOL} --update"
431 ${GNULIB_TOOL} --update
434 ## --------------------------------- ##
435 ## Copy additional src only modules. ##
436 ## --------------------------------- ##
438 func_echo "fetching modules for src directory"
440 for file in `${GNULIB_TOOL} --extract-filelist $src_modules`; do
442 dest=`echo $file | $SED "$basename"`
443 case $file in
444 lib/*) dest=src/$dest ;;
445 m4/*) dest=$config_macro_dir/$dest ;;
446 *) func_echo "Unknown file: $file"
447 exit 1
449 esac
451 # Be sure to show all copying errors before bailing out
452 if test -f $gnulibdir/$file; then
453 func_echo "copying file \`$dest'"
454 cp $gnulibdir/$file $dest
455 else
456 func_error "$gnulibdir/$file does not exist"
457 bailout_cb="exit 1"
459 done
460 $bailout_cb
463 ## ----------- ##
464 ## Autoreconf. ##
465 ## ----------- ##
467 # Disable autopoint and libtoolize, since they were already done above.
468 func_echo "running: AUTOPOINT=true LIBTOOLIZE=true " \
469 "$AUTORECONF --force --verbose --install --no-recursive"
470 AUTOPOINT=true LIBTOOLIZE=true \
471 $AUTORECONF --force --verbose --install --no-recursive
474 ## ---------------------------------------- ##
475 ## Gnulib is more up-to-date than automake. ##
476 ## ---------------------------------------- ##
478 func_update "$gnulibdir"/build-aux/config.guess $config_aux_dir/config.guess
479 func_update "$gnulibdir"/build-aux/config.sub $config_aux_dir/config.sub
480 func_update "$gnulibdir"/build-aux/depcomp $config_aux_dir/depcomp
481 func_update "$gnulibdir"/build-aux/install-sh $config_aux_dir/install-sh
482 func_update "$gnulibdir"/build-aux/mdate-sh $config_aux_dir/mdate-sh
483 func_update "$gnulibdir"/build-aux/missing $config_aux_dir/missing
484 func_update "$gnulibdir"/build-aux/texinfo.tex $config_aux_dir/texinfo.tex
485 func_update "$gnulibdir"/build-aux/po/Makefile.in.in po/Makefile.in.in
486 func_update "$gnulibdir"/build-aux/po/remove-potcdate.sin po/remove-potcdate.sin
487 func_update "$gnulibdir"/doc/COPYINGv3 COPYING
488 func_update "$gnulibdir"/doc/INSTALL INSTALL
491 ## ------- ##
492 ## Wrapup. ##
493 ## ------- ##
495 if test x"$SKIP_PO" = x; then
496 func_echo "If your pofiles are up-to-date, you can rerun bootstrap"
497 func_echo "as \`$progname --skip-po' to avoid redownloading."
500 exit 0
502 # Local variables:
503 # eval: (add-hook 'write-file-hooks 'time-stamp)
504 # time-stamp-start: "# bootstrap (GNU M4) version "
505 # time-stamp-format: "%:y-%02m-%02d"
506 # time-stamp-end: "$"
507 # End: