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-2017 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 generated and standard files obsolete
73 -i, --install copy missing standard 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 -Wfoo?
123 my $aclocal_supports_warnings = 0;
124 # Does automake support -Wfoo?
125 my $automake_supports_warnings = 0;
130 # List of command line warning requests.
133 # Rerun './configure && make'?
136 # Recurse into subpackages
146 # Process any command line arguments.
151 getopt ("W|warnings=s" => \@warning,
152 'I|include=s' => \@include,
153 'B|prepend-include=s' => \@prepend_include,
154 'i|install' => \$install,
155 's|symlink' => \$symlink,
156 'm|make' => \$run_make,
157 'recursive!' => \$recursive);
159 # Split the warnings as a list of elements instead of a list of
161 @warning = map { split /,/ } @warning;
163 parse_warnings '--warnings', @warning;
165 # Even if the user specified a configure.ac, trim to get the
166 # directory, and look for configure.ac again. Because (i) the code
167 # is simpler, and (ii) we are still able to diagnose simultaneous
168 # presence of configure.ac and configure.in.
169 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
170 push @ARGV, '.' unless @ARGV;
172 if ($verbose && $debug)
174 for my $prog ($autoconf, $autoheader,
179 xsystem ("$prog --version | sed 1q >&2");
184 my $aclocal_help = `$aclocal --help 2>/dev/null`;
185 my $automake_help = `$automake --help 2>/dev/null`;
186 $aclocal_supports_warnings = $aclocal_help =~ /--warnings/;
187 $automake_supports_warnings = $automake_help =~ /--warnings/;
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 $autoconf .= ' --force';
209 $autoheader .= ' --force';
210 $automake .= ' --force-missing';
211 $autopoint .= ' --force';
212 $libtoolize .= ' --force';
216 $automake .= ' --no-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_supports_warnings;
241 if $aclocal_supports_warnings;
246 # &autoreconf_current_directory
247 # -----------------------------
248 sub autoreconf_current_directory ()
250 my $configure_ac = find_configure_ac;
252 # ---------------------- #
253 # Is it using Autoconf? #
254 # ---------------------- #
258 if (-f $configure_ac)
260 my $configure_ac_file = new Autom4te::XFile ("$configure_ac", "<");
261 while ($_ = $configure_ac_file->getline)
265 $uses_autoconf = 1 if /AC_INIT/;
266 # See below for why we look for gettext here.
267 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
272 verb "$configure_ac: not using Autoconf";
277 # ------------------- #
278 # Running autopoint. #
279 # ------------------- #
281 # Gettext is a bit of a problem: its macros are not necessarily
282 # visible to aclocal, so if we start with a completely striped down
283 # package (think of a fresh CVS checkout), running 'aclocal' first
284 # will fail: the Gettext macros are missing.
286 # Therefore, we can't use the traces to decide if we use Gettext or
287 # not. I guess that once Gettext move to 2.5x we will be able to,
288 # but in the meanwhile forget it.
290 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
291 # might think this approach is naive, and indeed it is, as it
292 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
293 # anyway we don't limit the generality, since... that's what
294 # autopoint does. Actually, it is even more restrictive, as it
295 # greps for '^AM_GNU_GETTEXT_VERSION('. We did this above, while
296 # scanning configure.ac.
299 verb "$configure_ac: not using Gettext";
303 verb "$configure_ac: not running autopoint: --install not given";
307 xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
311 # ----------------- #
313 # ----------------- #
315 # Run it first: it might discover new macros to add, e.g.,
316 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
319 # Always run it. Tracking its sources for up-to-dateness is too
320 # complex and too error prone. The best we can do is avoiding
321 # nuking the timestamp.
322 my $uses_aclocal = 1;
324 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
329 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
330 $_ = $aclocal_m4->getline;
332 unless defined ($_) && /generated.*by aclocal/;
335 # If there are flags for aclocal in Makefile.am, use them.
336 my $aclocal_flags = '';
337 if ($uses_aclocal && -f 'Makefile.am')
339 my $makefile = new Autom4te::XFile 'Makefile.am';
340 while ($_ = $makefile->getline)
342 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
352 verb "$configure_ac: not using aclocal";
356 # Some file systems have sub-second timestamps, and if so we may
357 # run into trouble later, after we rerun autoconf and set the
358 # timestamps of input files to be no greater than aclocal.m4,
359 # because the time-stamp-setting operation (utime) has a
360 # resolution of only 1 second. Work around the problem by
361 # ensuring that there is at least a one-second window before the
362 # timestamp of aclocal.m4t in which no file timestamps can
366 xsystem ("$aclocal $aclocal_flags");
369 # We might have to rerun aclocal if Libtool (or others) imports new
371 my $rerun_aclocal = 0;
375 # ------------------------------- #
376 # See what tools will be needed. #
377 # ------------------------------- #
379 # Perform a single trace reading to avoid --force forcing a rerun
380 # between two --trace, that's useless. If there is no AC_INIT, then
381 # we are not interested: it looks like a Cygnus thingy.
383 my $uses_gettext_via_traces;
389 verb "$configure_ac: tracing";
390 my $traces = new Autom4te::XFile
393 map { ' --trace=' . $_ . ':\$n::\${::}%' }
394 # If you change this list, update the
395 # 'Autoreconf-preselections' section of autom4te.in.
402 'LT_CONFIG_LTDL_DIR',
407 while ($_ = $traces->getline)
410 my ($macro, @args) = split (/::/);
411 $aux_dir = $args[0] if $macro eq "AC_CONFIG_AUX_DIR";
412 $uses_autoconf = 1 if $macro eq "AC_INIT";
413 $uses_gettext_via_traces = 1 if $macro eq "AM_GNU_GETTEXT";
414 $uses_libtool = 1 if $macro eq "AC_PROG_LIBTOOL"
415 || $macro eq "LT_INIT";
416 $uses_libltdl = 1 if $macro eq "LT_CONFIG_LTDL_DIR";
417 $uses_autoheader = 1 if $macro eq "AC_CONFIG_HEADERS";
418 $uses_automake = 1 if $macro eq "AM_INIT_AUTOMAKE";
419 push @subdir, split (' ', $args[0])
420 if $macro eq "AC_CONFIG_SUBDIRS" && $recursive;
423 # The subdirs are *optional*, they may not exist.
428 verb "$configure_ac: adding subdirectory $_ to autoreconf";
433 verb "$configure_ac: subdirectory $_ not present";
437 # Gettext consistency checks...
438 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
439 if $uses_gettext_via_traces && ! $uses_gettext;
440 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
441 if $uses_gettext && ! $uses_gettext_via_traces;
444 # ---------------------------- #
445 # Setting up the source tree. #
446 # ---------------------------- #
448 # libtoolize, automake --add-missing etc. will drop files in the
449 # $AUX_DIR. But these tools fail to install these files if the
450 # directory itself does not exist, which valid: just imagine a CVS
451 # repository with hand written code only (there is not even a need
452 # for a Makefile.am!).
454 if (defined $aux_dir && ! -d $aux_dir)
456 verb "$configure_ac: creating directory $aux_dir";
458 or error "cannot create $aux_dir: $!";
462 # -------------------- #
463 # Running libtoolize. #
464 # -------------------- #
468 verb "$configure_ac: not using Libtool";
474 $libtoolize .= " --ltdl";
476 xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
481 verb "$configure_ac: not running libtoolize: --install not given";
486 # ------------------- #
487 # Rerunning aclocal. #
488 # ------------------- #
490 # If we re-installed Libtool or Gettext, the macros might have changed.
491 # Automake also needs an up-to-date aclocal.m4.
496 verb "$configure_ac: not using aclocal";
500 xsystem ("$aclocal $aclocal_flags");
505 # ------------------ #
506 # Running autoconf. #
507 # ------------------ #
509 # Don't try to be smarter than 'autoconf', which does its own up to
512 # We prefer running autoconf before autoheader, because (i) the
513 # latter runs the former, and (ii) autoconf is stricter than
514 # autoheader. So all in all, autoconf should give better error
519 # -------------------- #
520 # Running autoheader. #
521 # -------------------- #
523 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
526 # Just as for autoconf, up to date ness is performed by the tool
529 # Run it before automake, since the latter checks the presence of
530 # config.h.in when it sees an AC_CONFIG_HEADERS.
531 if (!$uses_autoheader)
533 verb "$configure_ac: not using Autoheader";
537 xsystem ($autoheader);
541 # ------------------ #
542 # Running automake. #
543 # ------------------ #
547 verb "$configure_ac: not using Automake";
551 # We should always run automake, and let it decide whether it shall
552 # update the file or not. In fact, the effect of '$force' is already
553 # included in '$automake' via '--no-force'.
564 if (!-f "config.status")
566 verb "no config.status: cannot re-make";
570 xsystem ("./config.status --recheck");
571 xsystem ("./config.status");
574 verb "no Makefile: cannot re-make";
585 # &autoreconf ($DIRECTORY)
586 # ------------------------
587 # Reconf the $DIRECTORY.
590 my ($directory) = @_;
593 # The format for this message is not free: taken from Emacs, itself
594 # using GNU Make's format.
595 verb "Entering directory '$directory'";
597 or error "cannot chdir to $directory: $!";
599 autoreconf_current_directory;
601 # The format is not free: taken from Emacs, itself using GNU Make's
603 verb "Leaving directory '$directory'";
605 or error "cannot chdir to $cwd: $!";
613 # When debugging, it is convenient that all the related temporary
614 # files be at the same place.
616 $ENV{'TMPDIR'} = $tmp;
619 # Autoreconf all the given configure.ac. Unless '--no-recursive' is passed,
620 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
621 $ENV{'AUTOM4TE'} = $autom4te;
622 for my $directory (@ARGV)
624 require_configure_ac ($directory);
625 autoreconf ($directory);
628 ### Setup "GNU" style for perl-mode and cperl-mode.
630 ## perl-indent-level: 2
631 ## perl-continued-statement-offset: 2
632 ## perl-continued-brace-offset: 0
633 ## perl-brace-offset: 0
634 ## perl-brace-imaginary-offset: 0
635 ## perl-label-offset: -2
636 ## cperl-indent-level: 2
637 ## cperl-brace-offset: 0
638 ## cperl-continued-brace-offset: 0
639 ## cperl-label-offset: -2
640 ## cperl-extra-newline-before-brace: t
641 ## cperl-merge-trailing-else: nil
642 ## cperl-continued-statement-offset: 2