5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # autoreconf - install the GNU Build System in a directory tree
9 # Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
10 # 2007, 2008 Free Software Foundation, Inc.
12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # Written by David J. MacKenzie.
28 # Extended and rewritten in Perl by Akim Demaille.
32 my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@';
33 unshift @INC, $datadir;
35 # Override SHELL. On DJGPP SHELL may not be set to a shell
36 # that can handle redirection and quote arguments correctly,
37 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
39 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
42 use Autom4te::ChannelDefs;
43 use Autom4te::Channels;
44 use Autom4te::Configure_ac;
45 use Autom4te::FileUtils;
46 use Autom4te::General;
48 # Do not use Cwd::chdir, since it might hang.
58 $help = "Usage: $0 [OPTION] ... [DIRECTORY] ...
60 Run `autoconf' (and `autoheader', `aclocal', `automake', `autopoint'
61 (formerly `gettextize'), and `libtoolize' where appropriate)
62 repeatedly to remake the GNU Build System files in specified
63 DIRECTORIES and their subdirectories (defaulting to `.').
65 By default, it only remakes those files that are older than their
66 sources. If you install new versions of the GNU Build System,
67 you can make `autoreconf' remake all of the files by giving it the
71 -h, --help print this help, then exit
72 -V, --version print version number, then exit
73 -v, --verbose verbosely report processing
74 -d, --debug don't remove temporary files
75 -f, --force consider all files obsolete
76 -i, --install copy missing auxiliary files
77 --no-recursive don't rebuild sub-packages
78 -s, --symlink with -i, install symbolic links instead of copies
79 -m, --make when applicable, re-run ./configure && make
80 -W, --warnings=CATEGORY report the warnings falling in CATEGORY [syntax]
82 " . Autom4te::ChannelDefs::usage . "
84 The environment variable \`WARNINGS\' is honored. Some subtools might
85 support other warning types, using \`all' is encouraged.
88 -B, --prepend-include=DIR prepend directory DIR to search path
89 -I, --include=DIR append directory DIR to search path
91 The environment variables AUTOCONF, AUTOHEADER, AUTOMAKE, ACLOCAL,
92 AUTOPOINT, LIBTOOLIZE, M4, and MAKE are honored.
94 Report bugs to <bug-autoconf\@gnu.org>.
99 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
100 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
101 License GPLv2+: GNU GPL version 2 or later
102 <http://gnu.org/licenses/old-licenses/gpl-2.0.html>
103 This is free software: you are free to change and redistribute it.
104 There is NO WARRANTY, to the extent permitted by law.
106 Written by David J. MacKenzie and Akim Demaille.
110 my $autoconf = $ENV{'AUTOCONF'} || '@bindir@/@autoconf-name@';
111 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
112 my $automake = $ENV{'AUTOMAKE'} || 'automake';
113 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
114 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
115 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
116 my $make = $ENV{'MAKE'} || 'make';
118 # --install -- as --add-missing in other tools.
120 # symlink -- when --install, use symlinks instead.
122 # Does aclocal support --force?
123 my $aclocal_supports_force = 0;
124 # Does automake support --force-missing?
125 my $automake_supports_force_missing = 0;
130 # List of command line warning requests.
133 # Rerun `./configure && make'?
136 # Recurse into subpackages
146 # Process any command line arguments.
151 getopt ("W|warnings=s" => \@warning,
152 'I|include=s' => \@include,
153 'B|prepend-include=s' => \@prepend_include,
154 'i|install' => \$install,
155 's|symlink' => \$symlink,
156 'm|make' => \$run_make,
157 'recursive!' => \$recursive);
159 # Split the warnings as a list of elements instead of a list of
161 @warning = map { split /,/ } @warning;
163 parse_warnings '--warnings', @warning;
165 # Even if the user specified a configure.ac, trim to get the
166 # directory, and look for configure.ac again. Because (i) the code
167 # is simpler, and (ii) we are still able to diagnose simultaneous
168 # presence of configure.ac and configure.in.
169 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
170 push @ARGV, '.' unless @ARGV;
172 if ($verbose && $debug)
174 for my $prog ($autoconf, $autoheader,
179 xsystem ("$prog --version | sed 1q >&2");
184 $aclocal_supports_force = `$aclocal --help 2>/dev/null` =~ /--force/;
185 $automake_supports_force_missing = `$automake --help 2>/dev/null` =~ /--force-missing/;
187 # Dispatch autoreconf's option to the tools.
189 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
190 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
191 $autoheader .= join (' --include=', '', map { shell_quote ($_) } @include);
192 $autoheader .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
194 # --install and --symlink;
197 $automake .= ' --add-missing';
198 $automake .= ' --copy' unless $symlink;
199 $libtoolize .= ' --copy' unless $symlink;
204 $aclocal .= ' --force'
205 if $aclocal_supports_force;
206 $autoconf .= ' --force';
207 $autoheader .= ' --force';
208 $automake .= ' --force-missing'
209 if $automake_supports_force_missing;
210 $autopoint .= ' --force';
211 $libtoolize .= ' --force';
215 # The implementation of --no-force is bogus in all implementations
216 # of Automake up to 1.8, so we avoid it in these cases. (Automake
217 # 1.8 is the first version where aclocal supports force, hence
219 $automake .= ' --no-force'
220 if $aclocal_supports_force;
222 # --verbose --verbose or --debug;
223 if ($verbose > 1 || $debug)
225 $autoconf .= ' --verbose';
226 $autoheader .= ' --verbose';
227 $automake .= ' --verbose';
228 $aclocal .= ' --verbose';
232 $autoconf .= ' --debug';
233 $autoheader .= ' --debug';
234 $libtoolize .= ' --debug';
239 my $warn = ' --warnings=' . join (',', @warning);
241 $autoheader .= $warn;
243 if `$automake --help` =~ /--warnings/;
248 # &run_aclocal ($ACLOCAL, $FLAGS)
249 # -------------------------------
250 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
251 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
252 # etc. uselessly. aclocal 1.8+ does not need this.
255 my ($aclocal, $flags) = @_;
257 # aclocal 1.8+ does all this for free. It can be recognized by its
259 if ($aclocal_supports_force)
261 xsystem ("$aclocal $flags");
265 xsystem ("$aclocal $flags --output=aclocal.m4t");
266 # aclocal may produce no output.
267 if (-f 'aclocal.m4t')
269 update_file ('aclocal.m4t', 'aclocal.m4');
270 # Make sure that the local m4 files are older than
273 # Why is not always the case? Because we already run
274 # aclocal at first (before tracing), which, for instance,
275 # can find Gettext's macros in .../share/aclocal, so we may
276 # have had the right aclocal.m4 already. Then autopoint is
277 # run, and installs locally these M4 files. Then
278 # autoreconf, via update_file, sees it is the _same_
279 # aclocal.m4, and doesn't change its timestamp. But later,
280 # Automake's Makefile expresses that aclocal.m4 depends on
281 # these local files, which are newer, so it triggers aclocal
284 # To make sure aclocal.m4 is no older, we change the
285 # modification times of the local M4 files to be not newer
288 # First, where are the local files?
289 my $aclocal_local_dir = '.';
290 if ($flags =~ /-I\s+(\S+)/)
292 $aclocal_local_dir = $1;
294 # All the local files newer than aclocal.m4 are to be
295 # made not newer than it.
296 my $aclocal_m4_mtime = mtime ('aclocal.m4');
297 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
299 if ($aclocal_m4_mtime < mtime ($file))
301 debug "aging $file to be not newer than aclocal.m4";
302 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
309 # &autoreconf_current_directory
310 # -----------------------------
311 sub autoreconf_current_directory ()
313 my $configure_ac = find_configure_ac;
315 # ---------------------- #
316 # Is it using Autoconf? #
317 # ---------------------- #
321 if (-f $configure_ac)
323 my $configure_ac_file = new Autom4te::XFile "< $configure_ac";
324 while ($_ = $configure_ac_file->getline)
328 $uses_autoconf = 1 if /AC_INIT/;
329 # See below for why we look for gettext here.
330 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
335 verb "$configure_ac: not using Autoconf";
340 # ------------------- #
341 # Running autopoint. #
342 # ------------------- #
344 # Gettext is a bit of a problem: its macros are not necessarily
345 # visible to aclocal, so if we start with a completely striped down
346 # package (think of a fresh CVS checkout), running `aclocal' first
347 # will fail: the Gettext macros are missing.
349 # Therefore, we can't use the traces to decide if we use Gettext or
350 # not. I guess that once Gettext move to 2.5x we will be able to,
351 # but in the meanwhile forget it.
353 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
354 # might think this approach is naive, and indeed it is, as it
355 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
356 # anyway we don't limit the generality, since... that's what
357 # autopoint does. Actually, it is even more restrictive, as it
358 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
359 # scanning configure.ac.
362 verb "$configure_ac: not using Gettext";
366 verb "$configure_ac: not running autopoint: --install not given";
370 xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
374 # ----------------- #
376 # ----------------- #
378 # Run it first: it might discover new macros to add, e.g.,
379 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
382 # Always run it. Tracking its sources for up-to-dateness is too
383 # complex and too error prone. The best we can do is avoiding
384 # nuking the time stamp.
385 my $uses_aclocal = 1;
387 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
392 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
393 $_ = $aclocal_m4->getline;
395 unless defined ($_) && /generated.*by aclocal/;
398 # If there are flags for aclocal in Makefile.am, use them.
399 my $aclocal_flags = '';
400 if ($uses_aclocal && -f 'Makefile.am')
402 my $makefile = new Autom4te::XFile 'Makefile.am';
403 while ($_ = $makefile->getline)
405 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
415 verb "$configure_ac: not using aclocal";
419 # Some file systems have sub-second time stamps, and if so we may
420 # run into trouble later, after we rerun autoconf and set the
421 # time stamps of input files to be no greater than aclocal.m4,
422 # because the time-stamp-setting operation (utime) has a
423 # resolution of only 1 second. Work around the problem by
424 # ensuring that there is at least a one-second window before the
425 # time stamp of aclocal.m4t in which no file time stamps can
429 run_aclocal ($aclocal, $aclocal_flags);
432 # We might have to rerun aclocal if Libtool (or others) imports new
434 my $rerun_aclocal = 0;
438 # ------------------------------- #
439 # See what tools will be needed. #
440 # ------------------------------- #
442 # Perform a single trace reading to avoid --force forcing a rerun
443 # between two --trace, that's useless. If there is no AC_INIT, then
444 # we are not interested: it looks like a Cygnus thingy.
446 my $uses_gettext_via_traces;
452 verb "$configure_ac: tracing";
453 my $traces = new Autom4te::XFile
455 . join (' --trace=', '',
456 # If you change this list, update the
457 # `Autoreconf-preselections' section of autom4te.in.
458 'AC_CONFIG_AUX_DIR:AC_CONFIG_AUX_DIR:\$1',
460 'AC_CONFIG_SUBDIRS:AC_CONFIG_SUBDIRS:\$1',
464 'LT_CONFIG_LTDL_DIR',
469 while ($_ = $traces->getline)
471 $aux_dir = $1 if /AC_CONFIG_AUX_DIR:(.*)/;
472 $uses_autoconf = 1 if /AC_INIT/;
473 $uses_gettext_via_traces = 1 if /AM_GNU_GETTEXT/;
474 $uses_libtool = 1 if /(AC_PROG_LIBTOOL|LT_INIT)/;
475 $uses_libltdl = 1 if /LT_CONFIG_LTDL_DIR/;
476 $uses_autoheader = 1 if /AC_CONFIG_HEADERS/;
477 $uses_automake = 1 if /AM_INIT_AUTOMAKE/;
478 push @subdir, split (' ', $1) if /AC_CONFIG_SUBDIRS:(.*)/ && $recursive;
481 # The subdirs are *optional*, they may not exist.
486 verb "$configure_ac: adding subdirectory $_ to autoreconf";
491 verb "$configure_ac: subdirectory $_ not present";
495 # Gettext consistency checks...
496 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
497 if $uses_gettext_via_traces && ! $uses_gettext;
498 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
499 if $uses_gettext && ! $uses_gettext_via_traces;
502 # ---------------------------- #
503 # Setting up the source tree. #
504 # ---------------------------- #
506 # libtoolize, automake --add-missing etc. will drop files in the
507 # $AUX_DIR. But these tools fail to install these files if the
508 # directory itself does not exist, which valid: just imagine a CVS
509 # repository with hand written code only (there is not even a need
510 # for a Makefile.am!).
512 if (defined $aux_dir && ! -d $aux_dir)
514 verb "$configure_ac: creating directory $aux_dir";
516 or error "cannot create $aux_dir: $!";
520 # -------------------- #
521 # Running libtoolize. #
522 # -------------------- #
526 verb "$configure_ac: not using Libtool";
532 $libtoolize .= " --ltdl";
534 xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
539 verb "$configure_ac: not running libtoolize: --install not given";
544 # ------------------- #
545 # Rerunning aclocal. #
546 # ------------------- #
548 # If we re-installed Libtool or Gettext, the macros might have changed.
549 # Automake also needs an up-to-date aclocal.m4.
554 verb "$configure_ac: not using aclocal";
558 run_aclocal ($aclocal, $aclocal_flags);
563 # ------------------ #
564 # Running autoconf. #
565 # ------------------ #
567 # Don't try to be smarter than `autoconf', which does its own up to
570 # We prefer running autoconf before autoheader, because (i) the
571 # latter runs the former, and (ii) autoconf is stricter than
572 # autoheader. So all in all, autoconf should give better error
577 # -------------------- #
578 # Running autoheader. #
579 # -------------------- #
581 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
584 # Just as for autoconf, up to date ness is performed by the tool
587 # Run it before automake, since the latter checks the presence of
588 # config.h.in when it sees an AC_CONFIG_HEADERS.
589 if (!$uses_autoheader)
591 verb "$configure_ac: not using Autoheader";
595 xsystem ($autoheader);
599 # ------------------ #
600 # Running automake. #
601 # ------------------ #
605 verb "$configure_ac: not using Automake";
609 # We should always run automake, and let it decide whether it shall
610 # update the file or not. In fact, the effect of `$force' is already
611 # included in `$automake' via `--no-force'.
622 if (!-f "config.status")
624 verb "no config.status: cannot re-make";
628 xsystem ("./config.status --recheck");
629 xsystem ("./config.status");
632 verb "no Makefile: cannot re-make";
643 # &autoreconf ($DIRECTORY)
644 # ------------------------
645 # Reconf the $DIRECTORY.
648 my ($directory) = @_;
651 # The format for this message is not free: taken from Emacs, itself
652 # using GNU Make's format.
653 verb "Entering directory `$directory'";
655 or error "cannot chdir to $directory: $!";
657 autoreconf_current_directory;
659 # The format is not free: taken from Emacs, itself using GNU Make's
661 verb "Leaving directory `$directory'";
663 or error "cannot chdir to $cwd: $!";
671 # When debugging, it is convenient that all the related temporary
672 # files be at the same place.
674 $ENV{'TMPDIR'} = $tmp;
677 # Autoreconf all the given configure.ac. Unless `--no-recursive' is passed,
678 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
679 for my $directory (@ARGV)
681 require_configure_ac ($directory);
682 autoreconf ($directory);
685 ### Setup "GNU" style for perl-mode and cperl-mode.
687 ## perl-indent-level: 2
688 ## perl-continued-statement-offset: 2
689 ## perl-continued-brace-offset: 0
690 ## perl-brace-offset: 0
691 ## perl-brace-imaginary-offset: 0
692 ## perl-label-offset: -2
693 ## cperl-indent-level: 2
694 ## cperl-brace-offset: 0
695 ## cperl-continued-brace-offset: 0
696 ## cperl-label-offset: -2
697 ## cperl-extra-newline-before-brace: t
698 ## cperl-merge-trailing-else: nil
699 ## cperl-continued-statement-offset: 2