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-2011 Free Software Foundation, Inc.
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # Written by David J. MacKenzie.
25 # Extended and rewritten in Perl by Akim Demaille.
29 my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
30 unshift @INC, $pkgdatadir;
32 # Override SHELL. On DJGPP SHELL may not be set to a shell
33 # that can handle redirection and quote arguments correctly,
34 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
36 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
39 use Autom4te::ChannelDefs;
40 use Autom4te::Channels;
41 use Autom4te::Configure_ac;
42 use Autom4te::FileUtils;
43 use Autom4te::General;
45 # Do not use Cwd::chdir, since it might hang.
55 $help = "Usage: $0 [OPTION]... [DIRECTORY]...
57 Run `autoconf' (and `autoheader', `aclocal', `automake', `autopoint'
58 (formerly `gettextize'), and `libtoolize' where appropriate)
59 repeatedly to remake the GNU Build System files in specified
60 DIRECTORIES and their subdirectories (defaulting to `.').
62 By default, it only remakes those files that are older than their
63 sources. If you install new versions of the GNU Build System,
64 you can make `autoreconf' remake all of the files by giving it the
68 -h, --help print this help, then exit
69 -V, --version print version number, then exit
70 -v, --verbose verbosely report processing
71 -d, --debug don't remove temporary files
72 -f, --force consider all files obsolete
73 -i, --install copy missing auxiliary files
74 --no-recursive don't rebuild sub-packages
75 -s, --symlink with -i, install symbolic links instead of copies
76 -m, --make when applicable, re-run ./configure && make
77 -W, --warnings=CATEGORY report the warnings falling in CATEGORY [syntax]
79 " . Autom4te::ChannelDefs::usage . "
81 The environment variable \`WARNINGS\' is honored. Some subtools might
82 support other warning types, using \`all' is encouraged.
85 -B, --prepend-include=DIR prepend directory DIR to search path
86 -I, --include=DIR append directory DIR to search path
88 The environment variables AUTOM4TE, AUTOCONF, AUTOHEADER, AUTOMAKE,
89 ACLOCAL, AUTOPOINT, LIBTOOLIZE, M4, and MAKE are honored.
91 Report bugs to <bug-autoconf\@gnu.org>.
92 GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
93 General help using GNU software: <http://www.gnu.org/gethelp/>.
98 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
99 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
100 License GPLv3+/Autoconf: GNU GPL version 3 or later
101 <http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
102 This is free software: you are free to change and redistribute it.
103 There is NO WARRANTY, to the extent permitted by law.
105 Written by David J. MacKenzie and Akim Demaille.
109 my $autoconf = $ENV{'AUTOCONF'} || '@bindir@/@autoconf-name@';
110 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
111 my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-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 aclocal support -Wfoo?
125 my $aclocal_supports_warnings = 0;
126 # Does automake support --force-missing?
127 my $automake_supports_force_missing = 0;
128 # Does automake support -Wfoo?
129 my $automake_supports_warnings = 0;
134 # List of command line warning requests.
137 # Rerun `./configure && make'?
140 # Recurse into subpackages
150 # Process any command line arguments.
155 getopt ("W|warnings=s" => \@warning,
156 'I|include=s' => \@include,
157 'B|prepend-include=s' => \@prepend_include,
158 'i|install' => \$install,
159 's|symlink' => \$symlink,
160 'm|make' => \$run_make,
161 'recursive!' => \$recursive);
163 # Split the warnings as a list of elements instead of a list of
165 @warning = map { split /,/ } @warning;
167 parse_warnings '--warnings', @warning;
169 # Even if the user specified a configure.ac, trim to get the
170 # directory, and look for configure.ac again. Because (i) the code
171 # is simpler, and (ii) we are still able to diagnose simultaneous
172 # presence of configure.ac and configure.in.
173 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
174 push @ARGV, '.' unless @ARGV;
176 if ($verbose && $debug)
178 for my $prog ($autoconf, $autoheader,
183 xsystem ("$prog --version | sed 1q >&2");
188 my $aclocal_help = `$aclocal --help 2>/dev/null`;
189 my $automake_help = `$automake --help 2>/dev/null`;
190 $aclocal_supports_force = $aclocal_help =~ /--force/;
191 $aclocal_supports_warnings = $aclocal_help =~ /--warnings/;
192 $automake_supports_force_missing = $automake_help =~ /--force-missing/;
193 $automake_supports_warnings = $automake_help =~ /--warnings/;
195 # Dispatch autoreconf's option to the tools.
197 $aclocal .= join (' -I ', '', map { shell_quote ($_) } @include);
198 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
199 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
200 $autoheader .= join (' --include=', '', map { shell_quote ($_) } @include);
201 $autoheader .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
203 # --install and --symlink;
206 $automake .= ' --add-missing';
207 $automake .= ' --copy' unless $symlink;
208 $libtoolize .= ' --copy' unless $symlink;
213 $aclocal .= ' --force'
214 if $aclocal_supports_force;
215 $autoconf .= ' --force';
216 $autoheader .= ' --force';
217 $automake .= ' --force-missing'
218 if $automake_supports_force_missing;
219 $autopoint .= ' --force';
220 $libtoolize .= ' --force';
224 # The implementation of --no-force is bogus in all implementations
225 # of Automake up to 1.8, so we avoid it in these cases. (Automake
226 # 1.8 is the first version where aclocal supports force, hence
228 $automake .= ' --no-force'
229 if $aclocal_supports_force;
231 # --verbose --verbose or --debug;
232 if ($verbose > 1 || $debug)
234 $autoconf .= ' --verbose';
235 $autoheader .= ' --verbose';
236 $automake .= ' --verbose';
237 $aclocal .= ' --verbose';
241 $autoconf .= ' --debug';
242 $autoheader .= ' --debug';
243 $libtoolize .= ' --debug';
248 my $warn = ' --warnings=' . join (',', @warning);
250 $autoheader .= $warn;
252 if $automake_supports_warnings;
254 if $aclocal_supports_warnings;
259 # &run_aclocal ($ACLOCAL, $FLAGS)
260 # -------------------------------
261 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
262 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
263 # etc. uselessly. aclocal 1.8+ does not need this.
266 my ($aclocal, $flags) = @_;
268 # aclocal 1.8+ does all this for free. It can be recognized by its
270 if ($aclocal_supports_force)
272 xsystem ("$aclocal $flags");
276 xsystem ("$aclocal $flags --output=aclocal.m4t");
277 # aclocal may produce no output.
278 if (-f 'aclocal.m4t')
280 update_file ('aclocal.m4t', 'aclocal.m4');
281 # Make sure that the local m4 files are older than
284 # Why is not always the case? Because we already run
285 # aclocal at first (before tracing), which, for instance,
286 # can find Gettext's macros in .../share/aclocal, so we may
287 # have had the right aclocal.m4 already. Then autopoint is
288 # run, and installs locally these M4 files. Then
289 # autoreconf, via update_file, sees it is the _same_
290 # aclocal.m4, and doesn't change its timestamp. But later,
291 # Automake's Makefile expresses that aclocal.m4 depends on
292 # these local files, which are newer, so it triggers aclocal
295 # To make sure aclocal.m4 is no older, we change the
296 # modification times of the local M4 files to be not newer
299 # First, where are the local files?
300 my $aclocal_local_dir = '.';
301 if ($flags =~ /-I\s+(\S+)/)
303 $aclocal_local_dir = $1;
305 # All the local files newer than aclocal.m4 are to be
306 # made not newer than it.
307 my $aclocal_m4_mtime = mtime ('aclocal.m4');
308 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
310 if ($aclocal_m4_mtime < mtime ($file))
312 debug "aging $file to be not newer than aclocal.m4";
313 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
320 # &autoreconf_current_directory
321 # -----------------------------
322 sub autoreconf_current_directory ()
324 my $configure_ac = find_configure_ac;
326 # ---------------------- #
327 # Is it using Autoconf? #
328 # ---------------------- #
332 if (-f $configure_ac)
334 my $configure_ac_file = new Autom4te::XFile "< $configure_ac";
335 while ($_ = $configure_ac_file->getline)
339 $uses_autoconf = 1 if /AC_INIT/;
340 # See below for why we look for gettext here.
341 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
346 verb "$configure_ac: not using Autoconf";
351 # ------------------- #
352 # Running autopoint. #
353 # ------------------- #
355 # Gettext is a bit of a problem: its macros are not necessarily
356 # visible to aclocal, so if we start with a completely striped down
357 # package (think of a fresh CVS checkout), running `aclocal' first
358 # will fail: the Gettext macros are missing.
360 # Therefore, we can't use the traces to decide if we use Gettext or
361 # not. I guess that once Gettext move to 2.5x we will be able to,
362 # but in the meanwhile forget it.
364 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
365 # might think this approach is naive, and indeed it is, as it
366 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
367 # anyway we don't limit the generality, since... that's what
368 # autopoint does. Actually, it is even more restrictive, as it
369 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
370 # scanning configure.ac.
373 verb "$configure_ac: not using Gettext";
377 verb "$configure_ac: not running autopoint: --install not given";
381 xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
385 # ----------------- #
387 # ----------------- #
389 # Run it first: it might discover new macros to add, e.g.,
390 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
393 # Always run it. Tracking its sources for up-to-dateness is too
394 # complex and too error prone. The best we can do is avoiding
395 # nuking the time stamp.
396 my $uses_aclocal = 1;
398 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
403 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
404 $_ = $aclocal_m4->getline;
406 unless defined ($_) && /generated.*by aclocal/;
409 # If there are flags for aclocal in Makefile.am, use them.
410 my $aclocal_flags = '';
411 if ($uses_aclocal && -f 'Makefile.am')
413 my $makefile = new Autom4te::XFile 'Makefile.am';
414 while ($_ = $makefile->getline)
416 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
426 verb "$configure_ac: not using aclocal";
430 # Some file systems have sub-second time stamps, and if so we may
431 # run into trouble later, after we rerun autoconf and set the
432 # time stamps of input files to be no greater than aclocal.m4,
433 # because the time-stamp-setting operation (utime) has a
434 # resolution of only 1 second. Work around the problem by
435 # ensuring that there is at least a one-second window before the
436 # time stamp of aclocal.m4t in which no file time stamps can
440 run_aclocal ($aclocal, $aclocal_flags);
443 # We might have to rerun aclocal if Libtool (or others) imports new
445 my $rerun_aclocal = 0;
449 # ------------------------------- #
450 # See what tools will be needed. #
451 # ------------------------------- #
453 # Perform a single trace reading to avoid --force forcing a rerun
454 # between two --trace, that's useless. If there is no AC_INIT, then
455 # we are not interested: it looks like a Cygnus thingy.
457 my $uses_gettext_via_traces;
463 verb "$configure_ac: tracing";
464 my $traces = new Autom4te::XFile
467 map { ' --trace=' . $_ . ':\$n::\${::}%' }
468 # If you change this list, update the
469 # `Autoreconf-preselections' section of autom4te.in.
476 'LT_CONFIG_LTDL_DIR',
481 while ($_ = $traces->getline)
484 my ($macro, @args) = split (/::/);
485 $aux_dir = $args[0] if $macro eq "AC_CONFIG_AUX_DIR";
486 $uses_autoconf = 1 if $macro eq "AC_INIT";
487 $uses_gettext_via_traces = 1 if $macro eq "AM_GNU_GETTEXT";
488 $uses_libtool = 1 if $macro eq "AC_PROG_LIBTOOL"
489 || $macro eq "LT_INIT";
490 $uses_libltdl = 1 if $macro eq "LT_CONFIG_LTDL_DIR";
491 $uses_autoheader = 1 if $macro eq "AC_CONFIG_HEADERS";
492 $uses_automake = 1 if $macro eq "AM_INIT_AUTOMAKE";
493 push @subdir, split (' ', $args[0])
494 if $macro eq "AC_CONFIG_SUBDIRS" && $recursive;
497 # The subdirs are *optional*, they may not exist.
502 verb "$configure_ac: adding subdirectory $_ to autoreconf";
507 verb "$configure_ac: subdirectory $_ not present";
511 # Gettext consistency checks...
512 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
513 if $uses_gettext_via_traces && ! $uses_gettext;
514 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
515 if $uses_gettext && ! $uses_gettext_via_traces;
518 # ---------------------------- #
519 # Setting up the source tree. #
520 # ---------------------------- #
522 # libtoolize, automake --add-missing etc. will drop files in the
523 # $AUX_DIR. But these tools fail to install these files if the
524 # directory itself does not exist, which valid: just imagine a CVS
525 # repository with hand written code only (there is not even a need
526 # for a Makefile.am!).
528 if (defined $aux_dir && ! -d $aux_dir)
530 verb "$configure_ac: creating directory $aux_dir";
532 or error "cannot create $aux_dir: $!";
536 # -------------------- #
537 # Running libtoolize. #
538 # -------------------- #
542 verb "$configure_ac: not using Libtool";
548 $libtoolize .= " --ltdl";
550 xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
555 verb "$configure_ac: not running libtoolize: --install not given";
560 # ------------------- #
561 # Rerunning aclocal. #
562 # ------------------- #
564 # If we re-installed Libtool or Gettext, the macros might have changed.
565 # Automake also needs an up-to-date aclocal.m4.
570 verb "$configure_ac: not using aclocal";
574 run_aclocal ($aclocal, $aclocal_flags);
579 # ------------------ #
580 # Running autoconf. #
581 # ------------------ #
583 # Don't try to be smarter than `autoconf', which does its own up to
586 # We prefer running autoconf before autoheader, because (i) the
587 # latter runs the former, and (ii) autoconf is stricter than
588 # autoheader. So all in all, autoconf should give better error
593 # -------------------- #
594 # Running autoheader. #
595 # -------------------- #
597 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
600 # Just as for autoconf, up to date ness is performed by the tool
603 # Run it before automake, since the latter checks the presence of
604 # config.h.in when it sees an AC_CONFIG_HEADERS.
605 if (!$uses_autoheader)
607 verb "$configure_ac: not using Autoheader";
611 xsystem ($autoheader);
615 # ------------------ #
616 # Running automake. #
617 # ------------------ #
621 verb "$configure_ac: not using Automake";
625 # We should always run automake, and let it decide whether it shall
626 # update the file or not. In fact, the effect of `$force' is already
627 # included in `$automake' via `--no-force'.
638 if (!-f "config.status")
640 verb "no config.status: cannot re-make";
644 xsystem ("./config.status --recheck");
645 xsystem ("./config.status");
648 verb "no Makefile: cannot re-make";
659 # &autoreconf ($DIRECTORY)
660 # ------------------------
661 # Reconf the $DIRECTORY.
664 my ($directory) = @_;
667 # The format for this message is not free: taken from Emacs, itself
668 # using GNU Make's format.
669 verb "Entering directory `$directory'";
671 or error "cannot chdir to $directory: $!";
673 autoreconf_current_directory;
675 # The format is not free: taken from Emacs, itself using GNU Make's
677 verb "Leaving directory `$directory'";
679 or error "cannot chdir to $cwd: $!";
687 # When debugging, it is convenient that all the related temporary
688 # files be at the same place.
690 $ENV{'TMPDIR'} = $tmp;
693 # Autoreconf all the given configure.ac. Unless `--no-recursive' is passed,
694 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
695 $ENV{'AUTOM4TE'} = $autom4te;
696 for my $directory (@ARGV)
698 require_configure_ac ($directory);
699 autoreconf ($directory);
702 ### Setup "GNU" style for perl-mode and cperl-mode.
704 ## perl-indent-level: 2
705 ## perl-continued-statement-offset: 2
706 ## perl-continued-brace-offset: 0
707 ## perl-brace-offset: 0
708 ## perl-brace-imaginary-offset: 0
709 ## perl-label-offset: -2
710 ## cperl-indent-level: 2
711 ## cperl-brace-offset: 0
712 ## cperl-continued-brace-offset: 0
713 ## cperl-label-offset: -2
714 ## cperl-extra-newline-before-brace: t
715 ## cperl-merge-trailing-else: nil
716 ## cperl-continued-statement-offset: 2