Avoid pointer arithmetic on `void *'.
[m4.git] / bootstrap
blob628b4bd43ea4d4063f26a3984d50f8d7389491b3
1 #! /bin/sh
3 # bootstrap (GNU M4) version 2009-05-04
4 # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software
5 # Foundation, Inc.
6 # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
7 # This is free software: you are free to change and redistribute it.
8 # There is NO WARRANTY, to the extent permitted by law.
10 # Written by Gary V. Vaughan <gary@gnu.org>
12 # This file is part of GNU M4.
14 # GNU M4 is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
19 # GNU M4 is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 # Usage: $progname [options]
29 # -f --force bootstrap even when sources are not from git
30 # --skip-po skip downloading pofiles
31 # -v --version print version information
32 # -h,-? --help print short or long help message
34 # You can also set the following variables to help $progname
35 # locate the right tools:
36 # AUTOPOINT, AUTORECONF, AWK, CONFIG_SHELL, GNULIB_SRCDIR, LIBTOOLIZE,
37 # M4, RM, SED
39 # This script bootstraps a git or CVS checkout of GNU M4 by correctly calling
40 # out to parts of the GNU Build Platform. Currently this requires GNU
41 # Gettext 0.16 or better, the latest git Autoconf 2.63b-41 or better,
42 # GNU M4 1.4.5 or better, Automake 1.10b or better, Libtool 2.2 or better,
43 # and the latest git or CVS checkout of Gnulib.
44 # Libtool must be installed; either with the same --prefix as
45 # automake, or made accessible to aclocal's search path via
46 # $AUTOMAKE_prefix/share/aclocal/dirlist.
48 # Report bugs to <bug-m4@gnu.org>
50 : ${AUTOPOINT=autopoint}
51 : ${AUTORECONF=autoreconf}
52 : ${AWK=awk}
53 : ${CONFIG_SHELL=/bin/sh}
54 : ${LIBTOOLIZE=libtoolize}
55 : ${M4=m4}
56 : ${RM='rm -f'}
57 : ${SED=sed}
59 # Ensure file names are sorted consistently across platforms.
60 # Also, ensure diagnostics are in English.
61 LC_ALL=C
62 export LC_ALL
64 package=m4
65 ltdldir=ltdl
66 config_aux_dir=build-aux
67 config_macro_dir=$ltdldir/m4
68 bailout_cb=:
70 # List dependencies here too; we don't extract them, otherwise dependent
71 # modules could end up being imported to src/ *and* gnu/!
72 src_modules='getopt version-etc-fsf version-etc xstrtol'
74 dirname="s,/[^/]*$,,"
75 basename="s,^.*/,,g"
77 # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
78 # is ksh but when the shell is invoked as "sh" and the current value of
79 # the _XPG environment variable is not equal to 1 (one), the special
80 # positional parameter $0, within a function call, is the name of the
81 # function.
82 progpath="$0"
84 # The name of this program:
85 progname=`echo "$progpath" | $SED "$basename"`
86 PROGRAM=bootstrap
88 # Detect whether this is a version control system checkout or a tarball
89 vcs_only_file=HACKING
91 # func_echo arg...
92 # Echo program name prefixed message.
93 func_echo ()
95 echo $progname: ${1+"$@"}
98 # func_error arg...
99 # Echo program name prefixed message to standard error.
100 func_error ()
102 echo $progname: ${1+"$@"} >&2
105 # func_fatal_error arg...
106 # Echo program name prefixed message to standard error, and exit.
107 func_fatal_error ()
109 func_error ${1+"$@"}
110 exit $EXIT_FAILURE
113 # func_verbose arg...
114 # Echo program name prefixed message in verbose mode only.
115 func_verbose ()
117 $opt_verbose && func_error ${1+"$@"}
120 # func_missing_arg argname
121 # Echo program name prefixed message to standard error and set global
122 # exit_cmd.
123 func_missing_arg ()
125 func_error "missing argument for $1"
126 exit_cmd=exit
129 # func_fatal_help arg...
130 # Echo program name prefixed message to standard error, followed by
131 # a help hint, and exit.
132 func_fatal_help ()
134 func_error ${1+"$@"}
135 func_fatal_error "Try \`$progname --help' for more information."
138 # func_missing_arg argname
139 # Echo program name prefixed message to standard error and set global
140 # exit_cmd.
141 func_missing_arg ()
143 func_error "missing argument for $1"
144 exit_cmd=exit
147 # func_usage
148 # Echo short help message to standard output and exit.
149 func_usage ()
151 $SED '/^# Usage:/,/# -h/ {
152 s/^# //; s/^# *$//;
153 s/\$progname/'$progname'/;
155 }; d' < "$progpath"
156 echo
157 echo "run \`$progname --help | more' for full usage"
158 exit $EXIT_SUCCESS
161 # func_help
162 # Echo long help message to standard output and exit.
163 func_help ()
165 $SED '/^# Usage:/,/# Report bugs to/ {
166 s/^# //; s/^# *$//;
167 s/\$progname/'$progname'/;
169 }; d' < "$progpath"
170 exit $EXIT_SUCCESS
173 # func_version
174 # Echo version message to standard output and exit.
175 func_version ()
177 $SED '/^# '$PROGRAM' (GNU /,/# Written by / {
178 s/^# //;
179 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
181 }; d' < "$progpath"
182 exit $EXIT_SUCCESS
185 # func_update
186 # Copy $1 to $2 if it is newer.
187 func_update ()
189 if test -f "$2" && cmp -s "$1" "$2" ; then
190 func_verbose "$2 is up-to-date"
191 else
192 func_echo "copying $1 -> $2"
193 cp "$1" "$2"
197 # Parse options once, thoroughly. This comes as soon as possible in
198 # the script to make things like `bootstrap --version' happen quickly.
200 # sed scripts:
201 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
202 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
203 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
204 my_sed_long_arg='1s/^--[^=]*=//'
206 # this just eases exit handling
207 while test $# -gt 0; do
208 opt="$1"
209 shift
210 case $opt in
211 -f|--force) vcs_only_file= ;;
212 --skip-po) SKIP_PO=t ;;
213 -\?|-h) func_usage ;;
214 --help) func_help ;;
215 --version) func_version ;;
216 --) break ;;
217 -*) func_fatal_help "unrecognized option \`$opt'" ;;
218 *) set -- "$opt" ${1+"$@"}; break ;;
219 esac
220 done
222 # Bail if the options were screwed
223 $exit_cmd $EXIT_FAILURE
225 if test -n "$vcs_only_file" && test ! -r "$vcs_only_file"; then
226 func_fatal_error \
227 "Bootstrapping from a non-version-control distribution is risky."
231 ## --------------------------------------- ##
232 ## Fetch translations. ##
233 ## (taken from gnulib build-aux/bootstrap) ##
234 ## --------------------------------------- ##
236 # The command to download all .po files for a specified domain into
237 # a specified directory. Fill in the first %s with the domain name,
238 # the second with the destination directory. Use rsync's -L and -r
239 # options because the latest/%s directory and the .po files within
240 # are all symlinks.
241 po_download_command_format=\
242 "rsync -Lrtvz 'translationproject.org::tp/latest/%s/' '%s'"
244 func_get_translations()
246 subdir=$1
247 domain=$2
249 func_echo "getting translations into $subdir for $domain..."
250 cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
251 eval "$cmd"
254 ## --------------------------------------- ##
255 ## Update translations. ##
256 ## (taken from gnulib build-aux/bootstrap) ##
257 ## --------------------------------------- ##
259 func_update_po ()
261 # Directory containing primary .po files.
262 # Overwrite them only when we're sure a .po file is new.
263 po_dir=po
264 domain=$package
266 # Download *.po files into this dir.
267 # Usually contains *.s1 checksum files.
268 ref_po_dir="$po_dir/.reference"
270 test -d $ref_po_dir || mkdir $ref_po_dir || return
272 func_get_translations $ref_po_dir $domain \
273 && ls "$ref_po_dir"/*.po 2>/dev/null \
274 | sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
275 langs=`cd $ref_po_dir && echo *.po | sed 's/\.po//g'`
277 test "$langs" = '*' && langs=x
278 for po in $langs; do
279 case $po in x) continue;; esac
280 new_po="$ref_po_dir/$po.po"
281 cksum_file="$ref_po_dir/$po.s1"
282 if ! test -f "$cksum_file" ||
283 ! test -f "$po_dir/$po.po" ||
284 ! sha1sum -c --status "$cksum_file" < "$new_po" > /dev/null; then
285 echo "updated $po_dir/$po.po..."
286 cp "$new_po" "$po_dir/$po.po" && sha1sum < "$new_po" > "$cksum_file"
288 done
291 case $SKIP_PO in
292 '') func_update_po ;;
293 esac
295 ## ---------------- ##
296 ## Version control. ##
297 ## ---------------- ##
299 # gnulib-tool updates ltdl/m4/.{git,cvs}ignore and gnu/.{git,cvs}ignore, and
300 # keeping generated files under version control does not make sense. Since
301 # gnu is entirely ignored, we only need to prepopulate the ltdl/m4 ignore
302 # files with generated files not tracked by gnulib-tool.
303 if test -f $config_macro_dir/.gitignore ; then
305 else
306 func_echo "creating initial $config_macro_dir/.cvsignore"
307 cat > $config_macro_dir/.cvsignore <<\EOF
308 # files created by gnulib, but that gnulib doesn't track
310 .cvsignore
311 .gitignore
312 gnulib-comp.m4
313 # files manually imported, rather than using gnulib-tool
314 getopt.m4
315 xstrtol.m4
316 # files created by autopoint
317 codeset.m4
318 gettext.m4
319 glibc2.m4
320 glibc21.m4
321 iconv.m4
322 intdiv0.m4
323 intl.m4
324 intldir.m4
325 intmax.m4
326 inttypes-pri.m4
327 inttypes_h.m4
328 lcmessage.m4
329 lib-ld.m4
330 lib-link.m4
331 lib-prefix.m4
332 lock.m4
333 longdouble.m4
334 longlong.m4
335 nls.m4
336 po.m4
337 printf-posix.m4
338 progtest.m4
339 size_max.m4
340 stdint_h.m4
341 uintmax_t.m4
342 ulonglong.m4
343 visibility.m4
344 wchar_t.m4
345 wint_t.m4
346 xsize.m4
347 # files created by libtoolize
348 argz.m4
349 libtool.m4
350 ltdl.m4
351 ltoptions.m4
352 ltsugar.m4
353 ltversion.m4
354 lt~obsolete.m4
355 # gnulib-tool edits below here
357 func_echo "creating initial $config_macro_dir/.gitignore"
358 cp $config_macro_dir/.cvsignore $config_macro_dir/.gitignore
361 # See if we can use gnulib's git-merge-changelog merge driver.
362 if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
363 if git config merge.merge-changelog.driver >/dev/null ; then
365 elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
366 func_echo "initializing git-merge-changelog driver"
367 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
368 git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
369 else
370 func_echo "consider installing git-merge-changelog from gnulib"
372 if git config diff.texinfo.funcname >/dev/null ; then
374 else
375 func_echo "initializing git texinfo diff driver"
376 git config diff.texinfo.funcname '^@node[ ][ ]*\\([^,][^,]*\\)'
380 ## ---------- ##
381 ## Autopoint. ##
382 ## ---------- ##
384 # Released autopoint has the tendency to install macros that have been
385 # obsoleted in current gnulib, so run this before gnulib-tool.
386 func_echo "running: $AUTOPOINT --force"
387 $AUTOPOINT --force
389 ## ----------- ##
390 ## Libtoolize. ##
391 ## ----------- ##
393 # Autoreconf runs aclocal before libtoolize, which causes spurious
394 # warnings if the initial aclocal is confused by the libtoolized
395 # (or worse out-of-date) macro directory.
396 func_echo "running: $LIBTOOLIZE --copy --install"
397 ${LIBTOOLIZE} --copy --install
399 ## ------------------------------ ##
400 ## Update the gnulib module tree. ##
401 ## ------------------------------ ##
403 if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
404 if test -f gnulib/gnulib-tool ; then
405 func_echo "updating gnulib submodule"
406 git submodule update \
407 || func_fatal_error "Unable to update gnulib"
408 else
409 # A fresh checkout creates an empty subdirectory gnulib. However,
410 # older git didn't know how to clone into an empty subdir. If the
411 # user provided GNULIB_SRCDIR, then make the initial clone refer
412 # to the existing checkout, to save network traffic.
413 func_echo "importing gnulib submodule"
414 if test -d "$GNULIB_SRCDIR" ; then
415 rmdir gnulib 2>/dev/null
416 git clone --reference "$GNULIB_SRCDIR" git://git.sv.gnu.org/gnulib.git \
417 && git submodule init && git submodule update \
418 || func_fatal_error "Unable to update gnulib"
419 else
420 git submodule update --init \
421 || func_fatal_error "Unable to update gnulib"
424 else
425 func_echo "git not detected. If needed, update gnulib subdirectory manually"
429 ## ---------------------- ##
430 ## Import Gnulib modules. ##
431 ## ---------------------- ##
433 func_echo "running: $CONFIG_SHELL gnulib/gnulib-tool --update"
434 $CONFIG_SHELL gnulib/gnulib-tool --update \
435 || func_fatal_error "gnulib-tool failed"
437 ## --------------------------------- ##
438 ## Copy additional src only modules. ##
439 ## --------------------------------- ##
441 func_echo "fetching modules for src directory"
443 for file in `$CONFIG_SHELL gnulib/gnulib-tool --extract-filelist $src_modules`
446 dest=`echo $file | $SED "$basename"`
447 case $file in
448 lib/*) dest=src/$dest ;;
449 m4/*) dest=$config_macro_dir/$dest ;;
450 *) func_echo "Unknown file: $file"
451 exit 1
453 esac
455 # Be sure to show all copying errors before bailing out
456 if test -f gnulib/$file; then
457 func_echo "copying file \`$dest'"
458 cp gnulib/$file $dest
459 else
460 func_error "gnulib/$file does not exist"
461 bailout_cb="exit 1"
463 done
464 $bailout_cb
467 ## ----------- ##
468 ## Autoreconf. ##
469 ## ----------- ##
471 # Disable autopoint and libtoolize, since they were already done above.
472 func_echo "running: AUTOPOINT=true LIBTOOLIZE=true " \
473 "$AUTORECONF --verbose --install --no-recursive"
474 AUTOPOINT=true LIBTOOLIZE=true \
475 $AUTORECONF --verbose --install --no-recursive \
476 || func_fatal_error "autoreconf failed"
478 ## ------- ##
479 ## Wrapup. ##
480 ## ------- ##
482 if test x"$SKIP_PO" = x; then
483 func_echo "If your pofiles are up-to-date, you can rerun bootstrap"
484 func_echo "as \`$progname --skip-po' to avoid redownloading."
487 exit 0
489 # Local variables:
490 # eval: (add-hook 'write-file-hooks 'time-stamp)
491 # time-stamp-start: "# bootstrap (GNU M4) version "
492 # time-stamp-format: "%:y-%02m-%02d"
493 # time-stamp-end: "$"
494 # End: