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, 2010 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 $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
31 unshift @INC, $pkgdatadir;
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, and MAKE are honored.
92 Report bugs to <bug-autoconf\@gnu.org>.
93 GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
94 General help using GNU software: <http://www.gnu.org/gethelp/>.
99 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
100 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
101 License GPLv3+/Autoconf: GNU GPL version 3 or later
102 <http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.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 $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
113 my $automake = $ENV{'AUTOMAKE'} || 'automake';
114 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
115 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
116 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
117 my $make = $ENV{'MAKE'} || 'make';
119 # --install -- as --add-missing in other tools.
121 # symlink -- when --install, use symlinks instead.
123 # Does aclocal support --force?
124 my $aclocal_supports_force = 0;
125 # Does automake support --force-missing?
126 my $automake_supports_force_missing = 0;
131 # List of command line warning requests.
134 # Rerun `./configure && make'?
137 # Recurse into subpackages
147 # Process any command line arguments.
152 getopt ("W|warnings=s" => \@warning,
153 'I|include=s' => \@include,
154 'B|prepend-include=s' => \@prepend_include,
155 'i|install' => \$install,
156 's|symlink' => \$symlink,
157 'm|make' => \$run_make,
158 'recursive!' => \$recursive);
160 # Split the warnings as a list of elements instead of a list of
162 @warning = map { split /,/ } @warning;
164 parse_warnings '--warnings', @warning;
166 # Even if the user specified a configure.ac, trim to get the
167 # directory, and look for configure.ac again. Because (i) the code
168 # is simpler, and (ii) we are still able to diagnose simultaneous
169 # presence of configure.ac and configure.in.
170 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
171 push @ARGV, '.' unless @ARGV;
173 if ($verbose && $debug)
175 for my $prog ($autoconf, $autoheader,
180 xsystem ("$prog --version | sed 1q >&2");
185 $aclocal_supports_force = `$aclocal --help 2>/dev/null` =~ /--force/;
186 $automake_supports_force_missing = `$automake --help 2>/dev/null` =~ /--force-missing/;
188 # Dispatch autoreconf's option to the tools.
190 $aclocal .= join (' -I ', '', map { shell_quote ($_) } @include);
191 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
192 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
193 $autoheader .= join (' --include=', '', map { shell_quote ($_) } @include);
194 $autoheader .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
196 # --install and --symlink;
199 $automake .= ' --add-missing';
200 $automake .= ' --copy' unless $symlink;
201 $libtoolize .= ' --copy' unless $symlink;
206 $aclocal .= ' --force'
207 if $aclocal_supports_force;
208 $autoconf .= ' --force';
209 $autoheader .= ' --force';
210 $automake .= ' --force-missing'
211 if $automake_supports_force_missing;
212 $autopoint .= ' --force';
213 $libtoolize .= ' --force';
217 # The implementation of --no-force is bogus in all implementations
218 # of Automake up to 1.8, so we avoid it in these cases. (Automake
219 # 1.8 is the first version where aclocal supports force, hence
221 $automake .= ' --no-force'
222 if $aclocal_supports_force;
224 # --verbose --verbose or --debug;
225 if ($verbose > 1 || $debug)
227 $autoconf .= ' --verbose';
228 $autoheader .= ' --verbose';
229 $automake .= ' --verbose';
230 $aclocal .= ' --verbose';
234 $autoconf .= ' --debug';
235 $autoheader .= ' --debug';
236 $libtoolize .= ' --debug';
241 my $warn = ' --warnings=' . join (',', @warning);
243 $autoheader .= $warn;
245 if `$automake --help` =~ /--warnings/;
250 # &run_aclocal ($ACLOCAL, $FLAGS)
251 # -------------------------------
252 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
253 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
254 # etc. uselessly. aclocal 1.8+ does not need this.
257 my ($aclocal, $flags) = @_;
259 # aclocal 1.8+ does all this for free. It can be recognized by its
261 if ($aclocal_supports_force)
263 xsystem ("$aclocal $flags");
267 xsystem ("$aclocal $flags --output=aclocal.m4t");
268 # aclocal may produce no output.
269 if (-f 'aclocal.m4t')
271 update_file ('aclocal.m4t', 'aclocal.m4');
272 # Make sure that the local m4 files are older than
275 # Why is not always the case? Because we already run
276 # aclocal at first (before tracing), which, for instance,
277 # can find Gettext's macros in .../share/aclocal, so we may
278 # have had the right aclocal.m4 already. Then autopoint is
279 # run, and installs locally these M4 files. Then
280 # autoreconf, via update_file, sees it is the _same_
281 # aclocal.m4, and doesn't change its timestamp. But later,
282 # Automake's Makefile expresses that aclocal.m4 depends on
283 # these local files, which are newer, so it triggers aclocal
286 # To make sure aclocal.m4 is no older, we change the
287 # modification times of the local M4 files to be not newer
290 # First, where are the local files?
291 my $aclocal_local_dir = '.';
292 if ($flags =~ /-I\s+(\S+)/)
294 $aclocal_local_dir = $1;
296 # All the local files newer than aclocal.m4 are to be
297 # made not newer than it.
298 my $aclocal_m4_mtime = mtime ('aclocal.m4');
299 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
301 if ($aclocal_m4_mtime < mtime ($file))
303 debug "aging $file to be not newer than aclocal.m4";
304 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
311 # &autoreconf_current_directory
312 # -----------------------------
313 sub autoreconf_current_directory ()
315 my $configure_ac = find_configure_ac;
317 # ---------------------- #
318 # Is it using Autoconf? #
319 # ---------------------- #
323 if (-f $configure_ac)
325 my $configure_ac_file = new Autom4te::XFile "< $configure_ac";
326 while ($_ = $configure_ac_file->getline)
330 $uses_autoconf = 1 if /AC_INIT/;
331 # See below for why we look for gettext here.
332 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
337 verb "$configure_ac: not using Autoconf";
342 # ------------------- #
343 # Running autopoint. #
344 # ------------------- #
346 # Gettext is a bit of a problem: its macros are not necessarily
347 # visible to aclocal, so if we start with a completely striped down
348 # package (think of a fresh CVS checkout), running `aclocal' first
349 # will fail: the Gettext macros are missing.
351 # Therefore, we can't use the traces to decide if we use Gettext or
352 # not. I guess that once Gettext move to 2.5x we will be able to,
353 # but in the meanwhile forget it.
355 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
356 # might think this approach is naive, and indeed it is, as it
357 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
358 # anyway we don't limit the generality, since... that's what
359 # autopoint does. Actually, it is even more restrictive, as it
360 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
361 # scanning configure.ac.
364 verb "$configure_ac: not using Gettext";
368 verb "$configure_ac: not running autopoint: --install not given";
372 xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
376 # ----------------- #
378 # ----------------- #
380 # Run it first: it might discover new macros to add, e.g.,
381 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
384 # Always run it. Tracking its sources for up-to-dateness is too
385 # complex and too error prone. The best we can do is avoiding
386 # nuking the time stamp.
387 my $uses_aclocal = 1;
389 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
394 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
395 $_ = $aclocal_m4->getline;
397 unless defined ($_) && /generated.*by aclocal/;
400 # If there are flags for aclocal in Makefile.am, use them.
401 my $aclocal_flags = '';
402 if ($uses_aclocal && -f 'Makefile.am')
404 my $makefile = new Autom4te::XFile 'Makefile.am';
405 while ($_ = $makefile->getline)
407 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
417 verb "$configure_ac: not using aclocal";
421 # Some file systems have sub-second time stamps, and if so we may
422 # run into trouble later, after we rerun autoconf and set the
423 # time stamps of input files to be no greater than aclocal.m4,
424 # because the time-stamp-setting operation (utime) has a
425 # resolution of only 1 second. Work around the problem by
426 # ensuring that there is at least a one-second window before the
427 # time stamp of aclocal.m4t in which no file time stamps can
431 run_aclocal ($aclocal, $aclocal_flags);
434 # We might have to rerun aclocal if Libtool (or others) imports new
436 my $rerun_aclocal = 0;
440 # ------------------------------- #
441 # See what tools will be needed. #
442 # ------------------------------- #
444 # Perform a single trace reading to avoid --force forcing a rerun
445 # between two --trace, that's useless. If there is no AC_INIT, then
446 # we are not interested: it looks like a Cygnus thingy.
448 my $uses_gettext_via_traces;
454 verb "$configure_ac: tracing";
455 my $traces = new Autom4te::XFile
458 map { ' --trace=' . $_ . ':\$n::\${::}%' }
459 # If you change this list, update the
460 # `Autoreconf-preselections' section of autom4te.in.
467 'LT_CONFIG_LTDL_DIR',
472 while ($_ = $traces->getline)
475 my ($macro, @args) = split (/::/);
476 $aux_dir = $args[0] if $macro eq "AC_CONFIG_AUX_DIR";
477 $uses_autoconf = 1 if $macro eq "AC_INIT";
478 $uses_gettext_via_traces = 1 if $macro eq "AM_GNU_GETTEXT";
479 $uses_libtool = 1 if $macro eq "AC_PROG_LIBTOOL"
480 || $macro eq "LT_INIT";
481 $uses_libltdl = 1 if $macro eq "LT_CONFIG_LTDL_DIR";
482 $uses_autoheader = 1 if $macro eq "AC_CONFIG_HEADERS";
483 $uses_automake = 1 if $macro eq "AM_INIT_AUTOMAKE";
484 push @subdir, split (' ', $args[0])
485 if $macro eq "AC_CONFIG_SUBDIRS" && $recursive;
488 # The subdirs are *optional*, they may not exist.
493 verb "$configure_ac: adding subdirectory $_ to autoreconf";
498 verb "$configure_ac: subdirectory $_ not present";
502 # Gettext consistency checks...
503 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
504 if $uses_gettext_via_traces && ! $uses_gettext;
505 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
506 if $uses_gettext && ! $uses_gettext_via_traces;
509 # ---------------------------- #
510 # Setting up the source tree. #
511 # ---------------------------- #
513 # libtoolize, automake --add-missing etc. will drop files in the
514 # $AUX_DIR. But these tools fail to install these files if the
515 # directory itself does not exist, which valid: just imagine a CVS
516 # repository with hand written code only (there is not even a need
517 # for a Makefile.am!).
519 if (defined $aux_dir && ! -d $aux_dir)
521 verb "$configure_ac: creating directory $aux_dir";
523 or error "cannot create $aux_dir: $!";
527 # -------------------- #
528 # Running libtoolize. #
529 # -------------------- #
533 verb "$configure_ac: not using Libtool";
539 $libtoolize .= " --ltdl";
541 xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
546 verb "$configure_ac: not running libtoolize: --install not given";
551 # ------------------- #
552 # Rerunning aclocal. #
553 # ------------------- #
555 # If we re-installed Libtool or Gettext, the macros might have changed.
556 # Automake also needs an up-to-date aclocal.m4.
561 verb "$configure_ac: not using aclocal";
565 run_aclocal ($aclocal, $aclocal_flags);
570 # ------------------ #
571 # Running autoconf. #
572 # ------------------ #
574 # Don't try to be smarter than `autoconf', which does its own up to
577 # We prefer running autoconf before autoheader, because (i) the
578 # latter runs the former, and (ii) autoconf is stricter than
579 # autoheader. So all in all, autoconf should give better error
584 # -------------------- #
585 # Running autoheader. #
586 # -------------------- #
588 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
591 # Just as for autoconf, up to date ness is performed by the tool
594 # Run it before automake, since the latter checks the presence of
595 # config.h.in when it sees an AC_CONFIG_HEADERS.
596 if (!$uses_autoheader)
598 verb "$configure_ac: not using Autoheader";
602 xsystem ($autoheader);
606 # ------------------ #
607 # Running automake. #
608 # ------------------ #
612 verb "$configure_ac: not using Automake";
616 # We should always run automake, and let it decide whether it shall
617 # update the file or not. In fact, the effect of `$force' is already
618 # included in `$automake' via `--no-force'.
629 if (!-f "config.status")
631 verb "no config.status: cannot re-make";
635 xsystem ("./config.status --recheck");
636 xsystem ("./config.status");
639 verb "no Makefile: cannot re-make";
650 # &autoreconf ($DIRECTORY)
651 # ------------------------
652 # Reconf the $DIRECTORY.
655 my ($directory) = @_;
658 # The format for this message is not free: taken from Emacs, itself
659 # using GNU Make's format.
660 verb "Entering directory `$directory'";
662 or error "cannot chdir to $directory: $!";
664 autoreconf_current_directory;
666 # The format is not free: taken from Emacs, itself using GNU Make's
668 verb "Leaving directory `$directory'";
670 or error "cannot chdir to $cwd: $!";
678 # When debugging, it is convenient that all the related temporary
679 # files be at the same place.
681 $ENV{'TMPDIR'} = $tmp;
684 # Autoreconf all the given configure.ac. Unless `--no-recursive' is passed,
685 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
686 $ENV{'AUTOM4TE'} = $autom4te;
687 for my $directory (@ARGV)
689 require_configure_ac ($directory);
690 autoreconf ($directory);
693 ### Setup "GNU" style for perl-mode and cperl-mode.
695 ## perl-indent-level: 2
696 ## perl-continued-statement-offset: 2
697 ## perl-continued-brace-offset: 0
698 ## perl-brace-offset: 0
699 ## perl-brace-imaginary-offset: 0
700 ## perl-label-offset: -2
701 ## cperl-indent-level: 2
702 ## cperl-brace-offset: 0
703 ## cperl-continued-brace-offset: 0
704 ## cperl-label-offset: -2
705 ## cperl-extra-newline-before-brace: t
706 ## cperl-merge-trailing-else: nil
707 ## cperl-continued-statement-offset: 2