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, 2007
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 3 of the License, or
15 # (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
25 # Written by David J. MacKenzie.
26 # Extended and rewritten in Perl by Akim Demaille.
30 my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@';
31 unshift @INC, $datadir;
33 # Override SHELL. On DJGPP SHELL may not be set to a shell
34 # that can handle redirection and quote arguments correctly,
35 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
37 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
40 use Autom4te::ChannelDefs;
41 use Autom4te::Channels;
42 use Autom4te::Configure_ac;
43 use Autom4te::FileUtils;
44 use Autom4te::General;
46 # Do not use Cwd::chdir, since it might hang.
56 $help = "Usage: $0 [OPTION] ... [DIRECTORY] ...
58 Run `autoconf' (and `autoheader', `aclocal', `automake', `autopoint'
59 (formerly `gettextize'), and `libtoolize' where appropriate)
60 repeatedly to remake the GNU Build System files in specified
61 DIRECTORIES and their subdirectories (defaulting to `.').
63 By default, it only remakes those files that are older than their
64 sources. If you install new versions of the GNU Build System,
65 you can make `autoreconf' remake all of the files by giving it the
69 -h, --help print this help, then exit
70 -V, --version print version number, then exit
71 -v, --verbose verbosely report processing
72 -d, --debug don't remove temporary files
73 -f, --force consider all files obsolete
74 -i, --install copy missing auxiliary files
75 --no-recursive don't rebuild sub-packages
76 -s, --symlink with -i, install symbolic links instead of copies
77 -m, --make when applicable, re-run ./configure && make
78 -W, --warnings=CATEGORY report the warnings falling in CATEGORY [syntax]
80 " . Autom4te::ChannelDefs::usage . "
82 The environment variable \`WARNINGS\' is honored. Some subtools might
83 support other warning types, using \`all' is encouraged.
86 -B, --prepend-include=DIR prepend directory DIR to search path
87 -I, --include=DIR append directory DIR to search path
89 The environment variables AUTOCONF, AUTOHEADER, AUTOMAKE, ACLOCAL,
90 AUTOPOINT, LIBTOOLIZE, M4 are honored.
92 Report bugs to <bug-autoconf\@gnu.org>.
97 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
98 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
99 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
100 This is free software: you are free to change and redistribute it.
101 There is NO WARRANTY, to the extent permitted by law.
103 Written by David J. MacKenzie and Akim Demaille.
107 my $autoconf = $ENV{'AUTOCONF'} || '@bindir@/@autoconf-name@';
108 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
109 my $automake = $ENV{'AUTOMAKE'} || 'automake';
110 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
111 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
112 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
114 # --install -- as --add-missing in other tools.
116 # symlink -- when --install, use symlinks instead.
118 # Does aclocal support --force?
119 my $aclocal_supports_force = 0;
120 # Does automake support --force-missing?
121 my $automake_supports_force_missing = 0;
126 # List of command line warning requests.
129 # Rerun `./configure && make'?
132 # Recurse into subpackages
142 # Process any command line arguments.
147 getopt ("W|warnings=s" => \@warning,
148 'I|include=s' => \@include,
149 'B|prepend-include=s' => \@prepend_include,
150 'i|install' => \$install,
151 's|symlink' => \$symlink,
153 'recursive!' => \$recursive);
155 # Split the warnings as a list of elements instead of a list of
157 @warning = map { split /,/ } @warning;
159 parse_warnings '--warnings', @warning;
161 # Even if the user specified a configure.ac, trim to get the
162 # directory, and look for configure.ac again. Because (i) the code
163 # is simpler, and (ii) we are still able to diagnose simultaneous
164 # presence of configure.ac and configure.in.
165 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
166 push @ARGV, '.' unless @ARGV;
168 if ($verbose && $debug)
170 for my $prog ($autoconf, $autoheader,
175 xsystem ("$prog --version | sed 1q >&2");
180 $aclocal_supports_force = `$aclocal --help` =~ /--force/;
181 $automake_supports_force_missing = `$automake --help` =~ /--force-missing/;
183 # Dispatch autoreconf's option to the tools.
185 $autoconf .= join (' --include=', '', @include);
186 $autoconf .= join (' --prepend-include=', '', @prepend_include);
187 $autoheader .= join (' --include=', '', @include);
188 $autoheader .= join (' --prepend-include=', '', @prepend_include);
190 # --install and --symlink;
193 $automake .= ' --add-missing';
194 $automake .= ' --copy' unless $symlink;
195 $libtoolize .= ' --copy' unless $symlink;
200 $aclocal .= ' --force'
201 if $aclocal_supports_force;
202 $autoconf .= ' --force';
203 $autoheader .= ' --force';
204 $automake .= ' --force-missing'
205 if $automake_supports_force_missing;
206 $autopoint .= ' --force';
207 $libtoolize .= ' --force';
211 # The implementation of --no-force is bogus in all implementations
212 # of Automake up to 1.8, so we avoid it in these cases. (Automake
213 # 1.8 is the first version where aclocal supports force, hence
215 $automake .= ' --no-force'
216 if $aclocal_supports_force;
218 # --verbose --verbose or --debug;
219 if ($verbose > 1 || $debug)
221 $autoconf .= ' --verbose';
222 $autoheader .= ' --verbose';
223 $automake .= ' --verbose';
224 $aclocal .= ' --verbose';
228 $autoconf .= ' --debug';
229 $autoheader .= ' --debug';
230 $libtoolize .= ' --debug';
235 my $warn = ' --warnings=' . join (',', @warning);
237 $autoheader .= $warn;
239 if `$automake --help` =~ /--warnings/;
244 # &run_aclocal ($ACLOCAL, $FLAGS)
245 # -------------------------------
246 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
247 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
248 # etc. uselessly. aclocal 1.8+ does not need this.
251 my ($aclocal, $flags) = @_;
253 # aclocal 1.8+ does all this for free. It can be recognized by its
255 if ($aclocal_supports_force)
257 xsystem ("$aclocal $flags");
261 xsystem ("$aclocal $flags --output=aclocal.m4t");
262 # aclocal may produce no output.
263 if (-f 'aclocal.m4t')
265 update_file ('aclocal.m4t', 'aclocal.m4');
266 # Make sure that the local m4 files are older than
269 # Why is not always the case? Because we already run
270 # aclocal at first (before tracing), which, for instance,
271 # can find Gettext's macros in .../share/aclocal, so we may
272 # have had the right aclocal.m4 already. Then autopoint is
273 # run, and installs locally these M4 files. Then
274 # autoreconf, via update_file, sees it is the _same_
275 # aclocal.m4, and doesn't change its timestamp. But later,
276 # Automake's Makefile expresses that aclocal.m4 depends on
277 # these local files, which are newer, so it triggers aclocal
280 # To make sure aclocal.m4 is no older, we change the
281 # modification times of the local M4 files to be not newer
284 # First, where are the local files?
285 my $aclocal_local_dir = '.';
286 if ($flags =~ /-I\s+(\S+)/)
288 $aclocal_local_dir = $1;
290 # All the local files newer than aclocal.m4 are to be
291 # made not newer than it.
292 my $aclocal_m4_mtime = mtime ('aclocal.m4');
293 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
295 if ($aclocal_m4_mtime < mtime ($file))
297 debug "aging $file to be not newer than aclocal.m4";
298 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
305 # &autoreconf_current_directory
306 # -----------------------------
307 sub autoreconf_current_directory ()
309 my $configure_ac = find_configure_ac;
311 # ---------------------- #
312 # Is it using Autoconf? #
313 # ---------------------- #
317 if (-f $configure_ac)
319 my $configure_ac_file = new Autom4te::XFile $configure_ac;
320 while ($_ = $configure_ac_file->getline)
324 $uses_autoconf = 1 if /AC_INIT/;
325 # See below for why we look for gettext here.
326 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
331 verb "$configure_ac: not using Autoconf";
336 # ------------------- #
337 # Running autopoint. #
338 # ------------------- #
340 # Gettext is a bit of a problem: its macros are not necessarily
341 # visible to aclocal, so if we start with a completely striped down
342 # package (think of a fresh CVS checkout), running `aclocal' first
343 # will fail: the Gettext macros are missing.
345 # Therefore, we can't use the traces to decide if we use Gettext or
346 # not. I guess that once Gettext move to 2.5x we will be able to,
347 # but in the meanwhile forget it.
349 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
350 # might think this approach is naive, and indeed it is, as it
351 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
352 # anyway we don't limit the generality, since... that's what
353 # autopoint does. Actually, it is even more restrictive, as it
354 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
355 # scanning configure.ac.
358 verb "$configure_ac: not using Gettext";
362 verb "$configure_ac: not running autopoint: --install not given";
366 xsystem "$autopoint";
370 # ----------------- #
372 # ----------------- #
374 # Run it first: it might discover new macros to add, e.g.,
375 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
378 # Always run it. Tracking its sources for up-to-dateness is too
379 # complex and too error prone. The best we can do is avoiding
380 # nuking the time stamp.
381 my $uses_aclocal = 1;
383 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
388 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
389 $_ = $aclocal_m4->getline;
391 unless defined ($_) && /generated.*by aclocal/;
394 # If there are flags for aclocal in Makefile.am, use them.
395 my $aclocal_flags = '';
396 if ($uses_aclocal && -f 'Makefile.am')
398 my $makefile = new Autom4te::XFile 'Makefile.am';
399 while ($_ = $makefile->getline)
401 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
411 verb "$configure_ac: not using aclocal";
415 # Some file systems have sub-second time stamps, and if so we may
416 # run into trouble later, after we rerun autoconf and set the
417 # time stamps of input files to be no greater than aclocal.m4,
418 # because the time-stamp-setting operation (utime) has a
419 # resolution of only 1 second. Work around the problem by
420 # ensuring that there is at least a one-second window before the
421 # time stamp of aclocal.m4t in which no file time stamps can
425 run_aclocal ($aclocal, $aclocal_flags);
428 # We might have to rerun aclocal if Libtool (or others) imports new
430 my $rerun_aclocal = 0;
434 # ------------------------------- #
435 # See what tools will be needed. #
436 # ------------------------------- #
438 # Perform a single trace reading to avoid --force forcing a rerun
439 # between two --trace, that's useless. If there is no AC_INIT, then
440 # we are not interested: it looks like a Cygnus thingy.
442 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',
460 'LT_CONFIG_LTDL_DIR',
465 while ($_ = $traces->getline)
467 $aux_dir = $1 if /AC_CONFIG_AUX_DIR:(.*)/;
468 $uses_autoconf = 1 if /AC_INIT/;
469 $uses_gettext_via_traces = 1 if /AM_GNU_GETTEXT/;
470 $uses_libtool = 1 if /(AC_PROG_LIBTOOL|LT_INIT)/;
471 $uses_libltdl = 1 if /LT_CONFIG_LTDL_DIR/;
472 $uses_autoheader = 1 if /AC_CONFIG_HEADERS/;
473 $uses_automake = 1 if /AM_INIT_AUTOMAKE/;
474 push @subdir, split (' ', $1) if /AC_CONFIG_SUBDIRS:(.*)/ && $recursive;
477 # The subdirs are *optional*, they may not exist.
482 verb "$configure_ac: adding subdirectory $_ to autoreconf";
487 verb "$configure_ac: subdirectory $_ not present";
491 # Gettext consistency checks...
492 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
493 if $uses_gettext_via_traces && ! $uses_gettext;
494 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
495 if $uses_gettext && ! $uses_gettext_via_traces;
498 # ---------------------------- #
499 # Setting up the source tree. #
500 # ---------------------------- #
502 # libtoolize, automake --add-missing etc. will drop files in the
503 # $AUX_DIR. But these tools fail to install these files if the
504 # directory itself does not exist, which valid: just imagine a CVS
505 # repository with hand written code only (there is not even a need
506 # for a Makefile.am!).
508 if (defined $aux_dir && ! -d $aux_dir)
510 verb "$configure_ac: creating directory $aux_dir";
512 or error "cannot create $aux_dir: $!";
516 # -------------------- #
517 # Running libtoolize. #
518 # -------------------- #
522 verb "$configure_ac: not using Libtool";
528 $libtoolize .= " --ltdl";
530 xsystem ($libtoolize);
535 verb "$configure_ac: not running libtoolize: --install not given";
540 # ------------------- #
541 # Rerunning aclocal. #
542 # ------------------- #
544 # If we re-installed Libtool or Gettext, the macros might have changed.
545 # Automake also needs an up-to-date aclocal.m4.
550 verb "$configure_ac: not using aclocal";
554 run_aclocal ($aclocal, $aclocal_flags);
559 # ------------------ #
560 # Running autoconf. #
561 # ------------------ #
563 # Don't try to be smarter than `autoconf', which does its own up to
566 # We prefer running autoconf before autoheader, because (i) the
567 # latter runs the former, and (ii) autoconf is stricter than
568 # autoheader. So all in all, autoconf should give better error
573 # -------------------- #
574 # Running autoheader. #
575 # -------------------- #
577 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
580 # Just as for autoconf, up to date ness is performed by the tool
583 # Run it before automake, since the latter checks the presence of
584 # config.h.in when it sees an AC_CONFIG_HEADERS.
585 if (!$uses_autoheader)
587 verb "$configure_ac: not using Autoheader";
591 xsystem ($autoheader);
595 # ------------------ #
596 # Running automake. #
597 # ------------------ #
601 verb "$configure_ac: not using Automake";
605 # We should always run automake, and let it decide whether it shall
606 # update the file or not. In fact, the effect of `$force' is already
607 # included in `$automake' via `--no-force'.
618 if (!-f "config.status")
620 verb "no config.status: cannot re-make";
624 xsystem ("./config.status --recheck");
625 xsystem ("./config.status");
628 verb "no Makefile: cannot re-make";
639 # &autoreconf ($DIRECTORY)
640 # ------------------------
641 # Reconf the $DIRECTORY.
644 my ($directory) = @_;
647 # The format for this message is not free: taken from Emacs, itself
648 # using GNU Make's format.
649 verb "Entering directory `$directory'";
651 or error "cannot chdir to $directory: $!";
653 autoreconf_current_directory;
655 # The format is not free: taken from Emacs, itself using GNU Make's
657 verb "Leaving directory `$directory'";
659 or error "cannot chdir to $cwd: $!";
667 # When debugging, it is convenient that all the related temporary
668 # files be at the same place.
670 $ENV{'TMPDIR'} = $tmp;
673 # Autoreconf all the given configure.ac. Unless `--no-recursive' is passed,
674 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
675 for my $directory (@ARGV)
677 require_configure_ac ($directory);
678 autoreconf ($directory);
681 ### Setup "GNU" style for perl-mode and cperl-mode.
683 ## perl-indent-level: 2
684 ## perl-continued-statement-offset: 2
685 ## perl-continued-brace-offset: 0
686 ## perl-brace-offset: 0
687 ## perl-brace-imaginary-offset: 0
688 ## perl-label-offset: -2
689 ## cperl-indent-level: 2
690 ## cperl-brace-offset: 0
691 ## cperl-continued-brace-offset: 0
692 ## cperl-label-offset: -2
693 ## cperl-extra-newline-before-brace: t
694 ## cperl-merge-trailing-else: nil
695 ## cperl-continued-statement-offset: 2