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 # 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 are honored.
94 Report bugs to <bug-autoconf\@gnu.org>.
99 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
100 Written by David J. MacKenzie and Akim Demaille.
102 Copyright (C) 2006 Free Software Foundation, Inc.
103 This is free software; see the source for copying conditions. There is NO
104 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
108 my $autoconf = $ENV{'AUTOCONF'} || '@bindir@/@autoconf-name@';
109 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
110 my $automake = $ENV{'AUTOMAKE'} || 'automake';
111 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
112 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
113 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
115 # --install -- as --add-missing in other tools.
117 # symlink -- when --install, use symlinks instead.
119 # Does aclocal support --force?
120 my $aclocal_supports_force = 0;
121 # Does automake support --force-missing?
122 my $automake_supports_force_missing = 0;
127 # List of command line warning requests.
130 # Rerun `./configure && make'?
133 # Recurse into subpackages
143 # Process any command line arguments.
148 getopt ("W|warnings=s" => \@warning,
149 'I|include=s' => \@include,
150 'B|prepend-include=s' => \@prepend_include,
151 'i|install' => \$install,
152 's|symlink' => \$symlink,
154 'recursive!' => \$recursive);
156 # Split the warnings as a list of elements instead of a list of
158 @warning = map { split /,/ } @warning;
160 parse_warnings '--warnings', @warning;
162 # Even if the user specified a configure.ac, trim to get the
163 # directory, and look for configure.ac again. Because (i) the code
164 # is simpler, and (ii) we are still able to diagnose simultaneous
165 # presence of configure.ac and configure.in.
166 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
167 push @ARGV, '.' unless @ARGV;
169 if ($verbose && $debug)
171 for my $prog ($autoconf, $autoheader,
176 xsystem ("$prog --version | sed 1q >&2");
181 $aclocal_supports_force = `$aclocal --help` =~ /--force/;
182 $automake_supports_force_missing = `$automake --help` =~ /--force-missing/;
184 # Dispatch autoreconf's option to the tools.
186 $autoconf .= join (' --include=', '', @include);
187 $autoconf .= join (' --prepend-include=', '', @prepend_include);
188 $autoheader .= join (' --include=', '', @include);
189 $autoheader .= join (' --prepend-include=', '', @prepend_include);
191 # --install and --symlink;
194 $automake .= ' --add-missing';
195 $automake .= ' --copy' unless $symlink;
196 $libtoolize .= ' --copy' unless $symlink;
201 $aclocal .= ' --force'
202 if $aclocal_supports_force;
203 $autoconf .= ' --force';
204 $autoheader .= ' --force';
205 $automake .= ' --force-missing'
206 if $automake_supports_force_missing;
207 $autopoint .= ' --force';
208 $libtoolize .= ' --force';
212 # The implementation of --no-force is bogus in all implementations
213 # of Automake up to 1.8, so we avoid it in these cases. (Automake
214 # 1.8 is the first version where aclocal supports force, hence
216 $automake .= ' --no-force'
217 if $aclocal_supports_force;
219 # --verbose --verbose or --debug;
220 if ($verbose > 1 || $debug)
222 $autoconf .= ' --verbose';
223 $autoheader .= ' --verbose';
224 $automake .= ' --verbose';
225 $aclocal .= ' --verbose';
229 $autoconf .= ' --debug';
230 $autoheader .= ' --debug';
231 $libtoolize .= ' --debug';
236 my $warn = ' --warnings=' . join (',', @warning);
238 $autoheader .= $warn;
240 if `$automake --help` =~ /--warnings/;
245 # &run_aclocal ($ACLOCAL, $FLAGS)
246 # -------------------------------
247 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
248 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
249 # etc. uselessly. aclocal 1.8+ does not need this.
252 my ($aclocal, $flags) = @_;
254 # aclocal 1.8+ does all this for free. It can be recognized by its
256 if ($aclocal_supports_force)
258 xsystem ("$aclocal $flags");
262 xsystem ("$aclocal $flags --output=aclocal.m4t");
263 # aclocal may produce no output.
264 if (-f 'aclocal.m4t')
266 update_file ('aclocal.m4t', 'aclocal.m4');
267 # Make sure that the local m4 files are older than
270 # Why is not always the case? Because we already run
271 # aclocal at first (before tracing), which, for instance,
272 # can find Gettext's macros in .../share/aclocal, so we may
273 # have had the right aclocal.m4 already. Then autopoint is
274 # run, and installs locally these M4 files. Then
275 # autoreconf, via update_file, sees it is the _same_
276 # aclocal.m4, and doesn't change its timestamp. But later,
277 # Automake's Makefile expresses that aclocal.m4 depends on
278 # these local files, which are newer, so it triggers aclocal
281 # To make sure aclocal.m4 is no older, we change the
282 # modification times of the local M4 files to be not newer
285 # First, where are the local files?
286 my $aclocal_local_dir = '.';
287 if ($flags =~ /-I\s+(\S+)/)
289 $aclocal_local_dir = $1;
291 # All the local files newer than aclocal.m4 are to be
292 # made not newer than it.
293 my $aclocal_m4_mtime = mtime ('aclocal.m4');
294 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
296 if ($aclocal_m4_mtime < mtime ($file))
298 debug "aging $file to be not newer than aclocal.m4";
299 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
306 # &autoreconf_current_directory
307 # -----------------------------
308 sub autoreconf_current_directory ()
310 my $configure_ac = find_configure_ac;
312 # ---------------------- #
313 # Is it using Autoconf? #
314 # ---------------------- #
318 if (-f $configure_ac)
320 my $configure_ac_file = new Autom4te::XFile $configure_ac;
321 while ($_ = $configure_ac_file->getline)
325 $uses_autoconf = 1 if /AC_INIT/;
326 # See below for why we look for gettext here.
327 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
332 verb "$configure_ac: not using Autoconf";
337 # ------------------- #
338 # Running autopoint. #
339 # ------------------- #
341 # Gettext is a bit of a problem: its macros are not necessarily
342 # visible to aclocal, so if we start with a completely striped down
343 # package (think of a fresh CVS checkout), running `aclocal' first
344 # will fail: the Gettext macros are missing.
346 # Therefore, we can't use the traces to decide if we use Gettext or
347 # not. I guess that once Gettext move to 2.5x we will be able to,
348 # but in the meanwhile forget it.
350 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
351 # might think this approach is naive, and indeed it is, as it
352 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
353 # anyway we don't limit the generality, since... that's what
354 # autopoint does. Actually, it is even more restrictive, as it
355 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
356 # scanning configure.ac.
359 verb "$configure_ac: not using Gettext";
363 verb "$configure_ac: not running autopoint: --install not given";
367 xsystem "$autopoint";
371 # ----------------- #
373 # ----------------- #
375 # Run it first: it might discover new macros to add, e.g.,
376 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
379 # Always run it. Tracking its sources for up-to-dateness is too
380 # complex and too error prone. The best we can do is avoiding
381 # nuking the time stamp.
382 my $uses_aclocal = 1;
384 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
389 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
390 $_ = $aclocal_m4->getline;
392 unless defined ($_) && /generated.*by aclocal/;
395 # If there are flags for aclocal in Makefile.am, use them.
396 my $aclocal_flags = '';
397 if ($uses_aclocal && -f 'Makefile.am')
399 my $makefile = new Autom4te::XFile 'Makefile.am';
400 while ($_ = $makefile->getline)
402 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
412 verb "$configure_ac: not using aclocal";
416 # Some file systems have sub-second time stamps, and if so we may
417 # run into trouble later, after we rerun autoconf and set the
418 # time stamps of input files to be no greater than aclocal.m4,
419 # because the time-stamp-setting operation (utime) has a
420 # resolution of only 1 second. Work around the problem by
421 # ensuring that there is at least a one-second window before the
422 # time stamp of aclocal.m4t in which no file time stamps can
426 run_aclocal ($aclocal, $aclocal_flags);
429 # We might have to rerun aclocal if Libtool (or others) imports new
431 my $rerun_aclocal = 0;
435 # ------------------------------- #
436 # See what tools will be needed. #
437 # ------------------------------- #
439 # Perform a single trace reading to avoid --force forcing a rerun
440 # between two --trace, that's useless. If there is no AC_INIT, then
441 # we are not interested: it looks like a Cygnus thingy.
443 my $uses_gettext_via_traces;
448 verb "$configure_ac: tracing";
449 my $traces = new Autom4te::XFile
451 . join (' --trace=', '',
452 # If you change this list, update the
453 # `Autoreconf-preselections' section of autom4te.in.
454 'AC_CONFIG_AUX_DIR:AC_CONFIG_AUX_DIR:\$1',
456 'AC_CONFIG_SUBDIRS:AC_CONFIG_SUBDIRS:\$1',
464 while ($_ = $traces->getline)
466 $aux_dir = $1 if /AC_CONFIG_AUX_DIR:(.*)/;
467 $uses_autoconf = 1 if /AC_INIT/;
468 $uses_gettext_via_traces = 1 if /AM_GNU_GETTEXT/;
469 $uses_libtool = 1 if /(AC_PROG_LIBTOOL|LT_INIT)/;
470 $uses_autoheader = 1 if /AC_CONFIG_HEADERS/;
471 $uses_automake = 1 if /AM_INIT_AUTOMAKE/;
472 push @subdir, split (' ', $1) if /AC_CONFIG_SUBDIRS:(.*)/ && $recursive;
475 # The subdirs are *optional*, they may not exist.
480 verb "$configure_ac: adding subdirectory $_ to autoreconf";
485 verb "$configure_ac: subdirectory $_ not present";
489 # Gettext consistency checks...
490 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
491 if $uses_gettext_via_traces && ! $uses_gettext;
492 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
493 if $uses_gettext && ! $uses_gettext_via_traces;
496 # ---------------------------- #
497 # Setting up the source tree. #
498 # ---------------------------- #
500 # libtoolize, automake --add-missing etc. will drop files in the
501 # $AUX_DIR. But these tools fail to install these files if the
502 # directory itself does not exist, which valid: just imagine a CVS
503 # repository with hand written code only (there is not even a need
504 # for a Makefile.am!).
506 if (defined $aux_dir && ! -d $aux_dir)
508 verb "$configure_ac: creating directory $aux_dir";
510 or error "cannot create $aux_dir: $!";
514 # -------------------- #
515 # Running libtoolize. #
516 # -------------------- #
520 verb "$configure_ac: not using Libtool";
524 xsystem ($libtoolize);
529 verb "$configure_ac: not running libtoolize: --install not given";
534 # ------------------- #
535 # Rerunning aclocal. #
536 # ------------------- #
538 # If we re-installed Libtool or Gettext, the macros might have changed.
539 # Automake also needs an up-to-date aclocal.m4.
544 verb "$configure_ac: not using aclocal";
548 run_aclocal ($aclocal, $aclocal_flags);
553 # ------------------ #
554 # Running autoconf. #
555 # ------------------ #
557 # Don't try to be smarter than `autoconf', which does its own up to
560 # We prefer running autoconf before autoheader, because (i) the
561 # latter runs the former, and (ii) autoconf is stricter than
562 # autoheader. So all in all, autoconf should give better error
567 # -------------------- #
568 # Running autoheader. #
569 # -------------------- #
571 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
574 # Just as for autoconf, up to date ness is performed by the tool
577 # Run it before automake, since the latter checks the presence of
578 # config.h.in when it sees an AC_CONFIG_HEADERS.
579 if (!$uses_autoheader)
581 verb "$configure_ac: not using Autoheader";
585 xsystem ($autoheader);
589 # ------------------ #
590 # Running automake. #
591 # ------------------ #
595 verb "$configure_ac: not using Automake";
599 # We should always run automake, and let it decide whether it shall
600 # update the file or not. In fact, the effect of `$force' is already
601 # included in `$automake' via `--no-force'.
612 if (!-f "config.status")
614 verb "no config.status: cannot re-make";
618 xsystem ("./config.status --recheck");
619 xsystem ("./config.status");
622 verb "no Makefile: cannot re-make";
633 # &autoreconf ($DIRECTORY)
634 # ------------------------
635 # Reconf the $DIRECTORY.
638 my ($directory) = @_;
641 # The format for this message is not free: taken from Emacs, itself
642 # using GNU Make's format.
643 verb "Entering directory `$directory'";
645 or error "cannot chdir to $directory: $!";
647 autoreconf_current_directory;
649 # The format is not free: taken from Emacs, itself using GNU Make's
651 verb "Leaving directory `$directory'";
653 or error "cannot chdir to $cwd: $!";
661 # When debugging, it is convenient that all the related temporary
662 # files be at the same place.
664 $ENV{'TMPDIR'} = $tmp;
667 # Autoreconf all the given configure.ac. Unless `--no-recursive' is passed,
668 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
669 for my $directory (@ARGV)
671 require_configure_ac ($directory);
672 autoreconf ($directory);
675 ### Setup "GNU" style for perl-mode and cperl-mode.
677 ## perl-indent-level: 2
678 ## perl-continued-statement-offset: 2
679 ## perl-continued-brace-offset: 0
680 ## perl-brace-offset: 0
681 ## perl-brace-imaginary-offset: 0
682 ## perl-label-offset: -2
683 ## cperl-indent-level: 2
684 ## cperl-brace-offset: 0
685 ## cperl-continued-brace-offset: 0
686 ## cperl-label-offset: -2
687 ## cperl-extra-newline-before-brace: t
688 ## cperl-merge-trailing-else: nil
689 ## cperl-continued-statement-offset: 2