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, 2009 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 $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
33 unshift @INC, $pkgdatadir;
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>.
95 GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
96 General help using GNU software: <http://www.gnu.org/gethelp/>.
101 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
102 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
103 License GPLv2+: GNU GPL version 2 or later
104 <http://gnu.org/licenses/old-licenses/gpl-2.0.html>
105 This is free software: you are free to change and redistribute it.
106 There is NO WARRANTY, to the extent permitted by law.
108 Written by David J. MacKenzie and Akim Demaille.
112 my $autoconf = $ENV{'AUTOCONF'} || '@bindir@/@autoconf-name@';
113 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
114 my $automake = $ENV{'AUTOMAKE'} || 'automake';
115 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
116 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
117 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
118 my $make = $ENV{'MAKE'} || 'make';
120 # --install -- as --add-missing in other tools.
122 # symlink -- when --install, use symlinks instead.
124 # Does aclocal support --force?
125 my $aclocal_supports_force = 0;
126 # Does automake support --force-missing?
127 my $automake_supports_force_missing = 0;
132 # List of command line warning requests.
135 # Rerun `./configure && make'?
138 # Recurse into subpackages
148 # Process any command line arguments.
153 getopt ("W|warnings=s" => \@warning,
154 'I|include=s' => \@include,
155 'B|prepend-include=s' => \@prepend_include,
156 'i|install' => \$install,
157 's|symlink' => \$symlink,
158 'm|make' => \$run_make,
159 'recursive!' => \$recursive);
161 # Split the warnings as a list of elements instead of a list of
163 @warning = map { split /,/ } @warning;
165 parse_warnings '--warnings', @warning;
167 # Even if the user specified a configure.ac, trim to get the
168 # directory, and look for configure.ac again. Because (i) the code
169 # is simpler, and (ii) we are still able to diagnose simultaneous
170 # presence of configure.ac and configure.in.
171 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
172 push @ARGV, '.' unless @ARGV;
174 if ($verbose && $debug)
176 for my $prog ($autoconf, $autoheader,
181 xsystem ("$prog --version | sed 1q >&2");
186 $aclocal_supports_force = `$aclocal --help 2>/dev/null` =~ /--force/;
187 $automake_supports_force_missing = `$automake --help 2>/dev/null` =~ /--force-missing/;
189 # Dispatch autoreconf's option to the tools.
191 $aclocal .= join (' -I ', '', map { shell_quote ($_) } @include);
192 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
193 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
194 $autoheader .= join (' --include=', '', map { shell_quote ($_) } @include);
195 $autoheader .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
197 # --install and --symlink;
200 $automake .= ' --add-missing';
201 $automake .= ' --copy' unless $symlink;
202 $libtoolize .= ' --copy' unless $symlink;
207 $aclocal .= ' --force'
208 if $aclocal_supports_force;
209 $autoconf .= ' --force';
210 $autoheader .= ' --force';
211 $automake .= ' --force-missing'
212 if $automake_supports_force_missing;
213 $autopoint .= ' --force';
214 $libtoolize .= ' --force';
218 # The implementation of --no-force is bogus in all implementations
219 # of Automake up to 1.8, so we avoid it in these cases. (Automake
220 # 1.8 is the first version where aclocal supports force, hence
222 $automake .= ' --no-force'
223 if $aclocal_supports_force;
225 # --verbose --verbose or --debug;
226 if ($verbose > 1 || $debug)
228 $autoconf .= ' --verbose';
229 $autoheader .= ' --verbose';
230 $automake .= ' --verbose';
231 $aclocal .= ' --verbose';
235 $autoconf .= ' --debug';
236 $autoheader .= ' --debug';
237 $libtoolize .= ' --debug';
242 my $warn = ' --warnings=' . join (',', @warning);
244 $autoheader .= $warn;
246 if `$automake --help` =~ /--warnings/;
251 # &run_aclocal ($ACLOCAL, $FLAGS)
252 # -------------------------------
253 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
254 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
255 # etc. uselessly. aclocal 1.8+ does not need this.
258 my ($aclocal, $flags) = @_;
260 # aclocal 1.8+ does all this for free. It can be recognized by its
262 if ($aclocal_supports_force)
264 xsystem ("$aclocal $flags");
268 xsystem ("$aclocal $flags --output=aclocal.m4t");
269 # aclocal may produce no output.
270 if (-f 'aclocal.m4t')
272 update_file ('aclocal.m4t', 'aclocal.m4');
273 # Make sure that the local m4 files are older than
276 # Why is not always the case? Because we already run
277 # aclocal at first (before tracing), which, for instance,
278 # can find Gettext's macros in .../share/aclocal, so we may
279 # have had the right aclocal.m4 already. Then autopoint is
280 # run, and installs locally these M4 files. Then
281 # autoreconf, via update_file, sees it is the _same_
282 # aclocal.m4, and doesn't change its timestamp. But later,
283 # Automake's Makefile expresses that aclocal.m4 depends on
284 # these local files, which are newer, so it triggers aclocal
287 # To make sure aclocal.m4 is no older, we change the
288 # modification times of the local M4 files to be not newer
291 # First, where are the local files?
292 my $aclocal_local_dir = '.';
293 if ($flags =~ /-I\s+(\S+)/)
295 $aclocal_local_dir = $1;
297 # All the local files newer than aclocal.m4 are to be
298 # made not newer than it.
299 my $aclocal_m4_mtime = mtime ('aclocal.m4');
300 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
302 if ($aclocal_m4_mtime < mtime ($file))
304 debug "aging $file to be not newer than aclocal.m4";
305 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
312 # &autoreconf_current_directory
313 # -----------------------------
314 sub autoreconf_current_directory ()
316 my $configure_ac = find_configure_ac;
318 # ---------------------- #
319 # Is it using Autoconf? #
320 # ---------------------- #
324 if (-f $configure_ac)
326 my $configure_ac_file = new Autom4te::XFile "< $configure_ac";
327 while ($_ = $configure_ac_file->getline)
331 $uses_autoconf = 1 if /AC_INIT/;
332 # See below for why we look for gettext here.
333 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
338 verb "$configure_ac: not using Autoconf";
343 # ------------------- #
344 # Running autopoint. #
345 # ------------------- #
347 # Gettext is a bit of a problem: its macros are not necessarily
348 # visible to aclocal, so if we start with a completely striped down
349 # package (think of a fresh CVS checkout), running `aclocal' first
350 # will fail: the Gettext macros are missing.
352 # Therefore, we can't use the traces to decide if we use Gettext or
353 # not. I guess that once Gettext move to 2.5x we will be able to,
354 # but in the meanwhile forget it.
356 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
357 # might think this approach is naive, and indeed it is, as it
358 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
359 # anyway we don't limit the generality, since... that's what
360 # autopoint does. Actually, it is even more restrictive, as it
361 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
362 # scanning configure.ac.
365 verb "$configure_ac: not using Gettext";
369 verb "$configure_ac: not running autopoint: --install not given";
373 xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
377 # ----------------- #
379 # ----------------- #
381 # Run it first: it might discover new macros to add, e.g.,
382 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
385 # Always run it. Tracking its sources for up-to-dateness is too
386 # complex and too error prone. The best we can do is avoiding
387 # nuking the time stamp.
388 my $uses_aclocal = 1;
390 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
395 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
396 $_ = $aclocal_m4->getline;
398 unless defined ($_) && /generated.*by aclocal/;
401 # If there are flags for aclocal in Makefile.am, use them.
402 my $aclocal_flags = '';
403 if ($uses_aclocal && -f 'Makefile.am')
405 my $makefile = new Autom4te::XFile 'Makefile.am';
406 while ($_ = $makefile->getline)
408 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
418 verb "$configure_ac: not using aclocal";
422 # Some file systems have sub-second time stamps, and if so we may
423 # run into trouble later, after we rerun autoconf and set the
424 # time stamps of input files to be no greater than aclocal.m4,
425 # because the time-stamp-setting operation (utime) has a
426 # resolution of only 1 second. Work around the problem by
427 # ensuring that there is at least a one-second window before the
428 # time stamp of aclocal.m4t in which no file time stamps can
432 run_aclocal ($aclocal, $aclocal_flags);
435 # We might have to rerun aclocal if Libtool (or others) imports new
437 my $rerun_aclocal = 0;
441 # ------------------------------- #
442 # See what tools will be needed. #
443 # ------------------------------- #
445 # Perform a single trace reading to avoid --force forcing a rerun
446 # between two --trace, that's useless. If there is no AC_INIT, then
447 # we are not interested: it looks like a Cygnus thingy.
449 my $uses_gettext_via_traces;
455 verb "$configure_ac: tracing";
456 my $traces = new Autom4te::XFile
458 . join (' --trace=', '',
459 # If you change this list, update the
460 # `Autoreconf-preselections' section of autom4te.in.
461 'AC_CONFIG_AUX_DIR:AC_CONFIG_AUX_DIR:\$1',
463 'AC_CONFIG_SUBDIRS:AC_CONFIG_SUBDIRS:\$1',
467 'LT_CONFIG_LTDL_DIR',
472 while ($_ = $traces->getline)
474 $aux_dir = $1 if /AC_CONFIG_AUX_DIR:(.*)/;
475 $uses_autoconf = 1 if /AC_INIT/;
476 $uses_gettext_via_traces = 1 if /AM_GNU_GETTEXT/;
477 $uses_libtool = 1 if /(AC_PROG_LIBTOOL|LT_INIT)/;
478 $uses_libltdl = 1 if /LT_CONFIG_LTDL_DIR/;
479 $uses_autoheader = 1 if /AC_CONFIG_HEADERS/;
480 $uses_automake = 1 if /AM_INIT_AUTOMAKE/;
481 push @subdir, split (' ', $1) if /AC_CONFIG_SUBDIRS:(.*)/ && $recursive;
484 # The subdirs are *optional*, they may not exist.
489 verb "$configure_ac: adding subdirectory $_ to autoreconf";
494 verb "$configure_ac: subdirectory $_ not present";
498 # Gettext consistency checks...
499 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
500 if $uses_gettext_via_traces && ! $uses_gettext;
501 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
502 if $uses_gettext && ! $uses_gettext_via_traces;
505 # ---------------------------- #
506 # Setting up the source tree. #
507 # ---------------------------- #
509 # libtoolize, automake --add-missing etc. will drop files in the
510 # $AUX_DIR. But these tools fail to install these files if the
511 # directory itself does not exist, which valid: just imagine a CVS
512 # repository with hand written code only (there is not even a need
513 # for a Makefile.am!).
515 if (defined $aux_dir && ! -d $aux_dir)
517 verb "$configure_ac: creating directory $aux_dir";
519 or error "cannot create $aux_dir: $!";
523 # -------------------- #
524 # Running libtoolize. #
525 # -------------------- #
529 verb "$configure_ac: not using Libtool";
535 $libtoolize .= " --ltdl";
537 xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
542 verb "$configure_ac: not running libtoolize: --install not given";
547 # ------------------- #
548 # Rerunning aclocal. #
549 # ------------------- #
551 # If we re-installed Libtool or Gettext, the macros might have changed.
552 # Automake also needs an up-to-date aclocal.m4.
557 verb "$configure_ac: not using aclocal";
561 run_aclocal ($aclocal, $aclocal_flags);
566 # ------------------ #
567 # Running autoconf. #
568 # ------------------ #
570 # Don't try to be smarter than `autoconf', which does its own up to
573 # We prefer running autoconf before autoheader, because (i) the
574 # latter runs the former, and (ii) autoconf is stricter than
575 # autoheader. So all in all, autoconf should give better error
580 # -------------------- #
581 # Running autoheader. #
582 # -------------------- #
584 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
587 # Just as for autoconf, up to date ness is performed by the tool
590 # Run it before automake, since the latter checks the presence of
591 # config.h.in when it sees an AC_CONFIG_HEADERS.
592 if (!$uses_autoheader)
594 verb "$configure_ac: not using Autoheader";
598 xsystem ($autoheader);
602 # ------------------ #
603 # Running automake. #
604 # ------------------ #
608 verb "$configure_ac: not using Automake";
612 # We should always run automake, and let it decide whether it shall
613 # update the file or not. In fact, the effect of `$force' is already
614 # included in `$automake' via `--no-force'.
625 if (!-f "config.status")
627 verb "no config.status: cannot re-make";
631 xsystem ("./config.status --recheck");
632 xsystem ("./config.status");
635 verb "no Makefile: cannot re-make";
646 # &autoreconf ($DIRECTORY)
647 # ------------------------
648 # Reconf the $DIRECTORY.
651 my ($directory) = @_;
654 # The format for this message is not free: taken from Emacs, itself
655 # using GNU Make's format.
656 verb "Entering directory `$directory'";
658 or error "cannot chdir to $directory: $!";
660 autoreconf_current_directory;
662 # The format is not free: taken from Emacs, itself using GNU Make's
664 verb "Leaving directory `$directory'";
666 or error "cannot chdir to $cwd: $!";
674 # When debugging, it is convenient that all the related temporary
675 # files be at the same place.
677 $ENV{'TMPDIR'} = $tmp;
680 # Autoreconf all the given configure.ac. Unless `--no-recursive' is passed,
681 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
682 for my $directory (@ARGV)
684 require_configure_ac ($directory);
685 autoreconf ($directory);
688 ### Setup "GNU" style for perl-mode and cperl-mode.
690 ## perl-indent-level: 2
691 ## perl-continued-statement-offset: 2
692 ## perl-continued-brace-offset: 0
693 ## perl-brace-offset: 0
694 ## perl-brace-imaginary-offset: 0
695 ## perl-label-offset: -2
696 ## cperl-indent-level: 2
697 ## cperl-brace-offset: 0
698 ## cperl-continued-brace-offset: 0
699 ## cperl-label-offset: -2
700 ## cperl-extra-newline-before-brace: t
701 ## cperl-merge-trailing-else: nil
702 ## cperl-continued-statement-offset: 2