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, 2020-2024 Free Software Foundation,
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 <https://www.gnu.org/licenses/>.
25 # Written by David J. MacKenzie.
26 # Extended and rewritten in Perl by Akim Demaille.
30 use warnings FATAL => 'all';
35 my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
36 unshift @INC, $pkgdatadir;
38 $buildauxdir = $ENV{'autom4te_buildauxdir'} || $pkgdatadir . '/build-aux';
40 # Override SHELL. On DJGPP SHELL may not be set to a shell
41 # that can handle redirection and quote arguments correctly,
42 # e.g.: COMMAND.COM. For DJGPP always use the shell that configure
44 $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
47 # Do not use Cwd::chdir, since it might hang.
49 use File::Copy qw (copy);
50 use File::Temp qw (tempfile);
52 use Autom4te::ChannelDefs;
53 use Autom4te::Channels;
54 use Autom4te::Configure_ac;
55 use Autom4te::FileUtils;
56 use Autom4te::General;
65 $help = "Usage: $0 [OPTION]... [DIRECTORY]...
67 Run 'autoconf' and, when needed, 'aclocal', 'autoheader', 'automake',
68 'autopoint' (formerly 'gettextize'), 'libtoolize', 'intltoolize', and
69 'gtkdocize' to regenerate the GNU Build System files in specified
70 DIRECTORIES and their subdirectories (defaulting to '.').
72 By default, it only remakes those files that are older than their
73 sources. If you install new versions of the GNU Build System,
74 you can make 'autoreconf' remake all of the files by giving it the
78 -h, --help print this help, then exit
79 -V, --version print version number, then exit
80 -v, --verbose verbosely report processing
81 -d, --debug don't remove temporary files
82 -f, --force consider all generated and standard files obsolete
83 -i, --install copy missing standard auxiliary files
84 --no-recursive don't rebuild sub-packages
85 -s, --symlink with -i, install symbolic links instead of copies
86 -m, --make when applicable, re-run ./configure && make
87 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
88 (comma-separated list accepted)
90 " . Autom4te::ChannelDefs::usage . "
93 -B, --prepend-include=DIR prepend directory DIR to search path
94 -I, --include=DIR append directory DIR to search path
96 The environment variables AUTOCONF, ACLOCAL, AUTOHEADER, AUTOM4TE,
97 AUTOMAKE, AUTOPOINT, GTKDOCIZE, INTLTOOLIZE, LIBTOOLIZE, M4, MAKE,
98 and WARNINGS are honored.
100 Report bugs to <bug-autoconf\@gnu.org>.
102 The full documentation for Autoconf can be read via 'info autoconf',
103 or on the Web at <https://www.gnu.org/software/autoconf/manual/>.
108 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
109 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
110 License GPLv3+/Autoconf: GNU GPL version 3 or later
111 <https://gnu.org/licenses/gpl.html>, <https://gnu.org/licenses/exceptions.html>
112 This is free software: you are free to change and redistribute it.
113 There is NO WARRANTY, to the extent permitted by law.
115 Written by David J. MacKenzie and Akim Demaille.
119 my $autoconf = $ENV{'AUTOCONF'} || '@bindir@/@autoconf-name@';
120 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
121 my $autom4te = $ENV{'AUTOM4TE'} || '@bindir@/@autom4te-name@';
122 my $automake = $ENV{'AUTOMAKE'} || 'automake';
123 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
124 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
125 my $intltoolize = $ENV{'INTLTOOLIZE'} || 'intltoolize';
126 my $gtkdocize = $ENV{'GTKDOCIZE'} || 'gtkdocize';
127 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
128 my $make = $ENV{'MAKE'} || 'make';
130 # --install -- as --add-missing in other tools.
132 # symlink -- when --install, use symlinks instead.
138 # Rerun './configure && make'?
141 # Recurse into subpackages
151 # Process any command line arguments.
156 # List of command line warning requests.
159 getopt ("W|warnings=s" => \@warning,
160 'I|include=s' => \@include,
161 'B|prepend-include=s' => \@prepend_include,
162 'i|install' => \$install,
163 's|symlink' => \$symlink,
164 'm|make' => \$run_make,
165 'recursive!' => \$recursive);
167 # Split the warnings as a list of elements instead of a list of
169 @warning = map { split /,/ } @warning;
171 parse_warnings @warning;
173 # Even if the user specified a configure.ac, trim to get the
174 # directory, and look for configure.ac again. Because (i) the code
175 # is simpler, and (ii) we are still able to diagnose simultaneous
176 # presence of configure.ac and configure.in.
177 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
178 push @ARGV, '.' unless @ARGV;
180 if ($verbose && $debug)
182 for my $prog ($autoconf, $autoheader,
189 xsystem ("$prog --version | sed 1q >&2");
194 # Dispatch autoreconf's option to the tools.
196 $aclocal .= join (' -I ', '', map { shell_quote ($_) } @include);
197 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
198 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
199 $autoheader .= join (' --include=', '', map { shell_quote ($_) } @include);
200 $autoheader .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
202 # --install and --symlink;
205 $automake .= ' --add-missing';
206 $automake .= ' --copy' unless $symlink;
207 $libtoolize .= ' --copy' unless $symlink;
208 $intltoolize .= ' --copy' unless $symlink;
209 $gtkdocize .= ' --copy' unless $symlink;
214 $aclocal .= ' --force';
215 $autoconf .= ' --force';
216 $autoheader .= ' --force';
217 $automake .= ' --force-missing';
218 $autopoint .= ' --force';
219 $libtoolize .= ' --force';
220 $intltoolize .= ' --force';
224 $automake .= ' --no-force';
226 # --verbose --verbose or --debug;
227 if ($verbose > 1 || $debug)
229 $autoconf .= ' --verbose';
230 $autoheader .= ' --verbose';
231 $automake .= ' --verbose';
232 $aclocal .= ' --verbose';
236 $autoconf .= ' --debug';
237 $autoheader .= ' --debug';
238 $libtoolize .= ' --debug';
241 # Pass down warnings via the WARNINGS environment variable, instead
242 # of via --warnings, so that unrecognized warning categories are
243 # silently ignored. We already issued diagnostics about warning
244 # categories *we* don't recognize; older subsidiary tools may not
245 # know all of them, and may treat unrecognized warning categories on
246 # the command line as a fatal error when -Werror is in effect.
247 $ENV{WARNINGS} = merge_WARNINGS @warning;
248 verb "export WARNINGS=$ENV{WARNINGS}";
252 ## ----------------------- ##
253 ## Handling of aux files. ##
254 ## ----------------------- ##
256 # find_missing_aux_files
257 # ----------------------
258 # Look in $aux_dir (or, if that is empty, ., .., and ../..) for all of the
259 # files in @$aux_files; return a list of those that do not exist.
260 sub find_missing_aux_files
262 my ($aux_files, $aux_dir) = @_;
266 push @aux_dirs, $aux_dir;
270 @aux_dirs = qw(. .. ../..);
273 # If we find all the aux files in _some_ directory in @aux_dirs, we're
274 # good. But if we don't find all of them in any directory in @aux_dirs,
275 # return the set of missing files from the _first_ directory in @aux_dirs;
276 # this will be less confusing in the common case where AC_CONFIG_AUX_DIR
277 # wasn't used and the parent directories don't provide any aux files.
278 my @missing_aux_files;
279 my @first_missing_aux_files;
281 for my $dir (@aux_dirs)
283 @missing_aux_files = ();
284 for my $file (@{$aux_files})
286 push @missing_aux_files, $file
287 unless -e "${dir}/${file}";
290 return () if !@missing_aux_files;
292 @first_missing_aux_files = @missing_aux_files
293 unless @first_missing_aux_files;
296 return @first_missing_aux_files;
299 # can_install_aux_files
300 # ---------------------
301 # Report whether all of the files listed in @_ exist in $buildauxdir,
302 # which means we could install them.
303 sub can_install_aux_files
308 return 0 unless -f "${buildauxdir}/$_";
313 # extract_time_stamp ($fname)
314 # ---------------------------
315 # Extract a timestamp line from $fname.
316 # This is hardwired to know what to look for in the files we currently install.
317 sub extract_time_stamp
320 open my $fh, '<', $fname
321 or fatal "opening $fname: $!";
322 while (my $l = <$fh>)
324 if ($l =~ /^(?:scriptversion|timestamp)='?(\d\d\d\d-\d\d-\d\d(?:\.\d\d)?)/)
329 # Old versions of install-sh did not have a timestamp line.
333 # our_aux_file_is_newer ($dest, $src)
334 # -----------------------------------
335 # True if our copy of an aux file ($src) has a newer 'timestamp' line
336 # than the matching line in $dest.
337 sub our_aux_file_is_newer
339 my ($dest, $src) = @_;
340 my $dstamp = extract_time_stamp ($dest);
341 my $sstamp = extract_time_stamp ($src);
342 return $sstamp gt $dstamp;
345 # try_install_aux_files
346 # ---------------------
347 # Install each of the aux files listed in @$auxfiles, that we are able
348 # to install, into $destdir.
349 # Remove the files we were able to install from @$auxfiles.
350 sub try_install_aux_files
352 my ($auxfiles, $destdir) = @_;
354 for my $f (@$auxfiles)
356 my $src = "${buildauxdir}/$f";
359 install_aux_file ($destdir, $f, $src);
366 @$auxfiles = @unable;
371 # Install the file $src as $destdir/$f, honoring --symlink and --force.
374 my ($destdir, $f, $src) = @_;
375 my $dest = "${destdir}/$f";
376 if (-e $dest && ! our_aux_file_is_newer ($dest, $src))
383 if ($force || ! -l $dest || readlink $dest != $src)
388 or fatal "rm -f $dest: $!";
390 verb "linking $dest to $src";
392 or fatal "ln -s $src $dest: $!";
397 if (-e $dest && ! -f $dest)
400 or fatal "rm -f $dest: $!";
402 my ($temp, $tempname) = tempfile (UNLINK => 0, DIR => $destdir);
403 copy ($src, $tempname)
404 or fatal "copying $src to $tempname: $!";
405 make_executable ($tempname) if -x $src;
406 update_file ($tempname, $dest, $force);
412 # Make the file $f be executable by all users it is currently readable by.
416 my $perm = (stat $f)[2] & 07777;
417 $perm |= 0100 if ($perm & 0400);
418 $perm |= 0010 if ($perm & 0040);
419 $perm |= 0001 if ($perm & 0004);
421 or fatal "chmod $f: $!";
425 ## -------------------------- ##
426 ## Per-directory operations. ##
427 ## -------------------------- ##
429 # &autoreconf_current_directory
430 # -----------------------------
431 sub autoreconf_current_directory ($)
433 my ($directory) = @_;
434 my $configure_ac = find_configure_ac;
436 # ---------------------- #
437 # Is it using Autoconf? #
438 # ---------------------- #
442 if (-f $configure_ac)
444 my $configure_ac_file = new Autom4te::XFile ("$configure_ac", "<");
445 while ($_ = $configure_ac_file->getline)
449 $uses_autoconf = 1 if /AC_INIT/;
450 # See below for why we look for gettext here.
451 $uses_gettext = 1 if /^AM_GNU_GETTEXT_(?:REQUIRE_)?VERSION/;
455 error "$configure_ac: AC_INIT not found; not an autoconf script?";
461 verb "neither configure.ac nor configure.in present in $directory";
466 # ------------------- #
467 # Running autopoint. #
468 # ------------------- #
470 # Gettext is a bit of a problem: its macros are not necessarily
471 # visible to aclocal, so if we start with a completely stripped down
472 # package (think of a fresh CVS checkout), running 'aclocal' first
473 # will fail: the Gettext macros are missing.
475 # Therefore, we can't use the traces to decide if we use Gettext or
476 # not. I guess that once Gettext move to 2.5x we will be able to,
477 # but in the meanwhile forget it.
479 # We can only grep for AM_GNU_GETTEXT_(REQUIRE_)?VERSION in configure.ac.
480 # You might think this approach is naive, and indeed it is, as it prevents
481 # one to embed AM_GNU_GETTEXT_(REQUIRE_)?VERSION in another *.m4, but
482 # anyway we don't limit the generality, since... that's what autopoint does.
483 # Actually, it is even more restrictive, as it greps for
484 # '^AM_GNU_GETTEXT_(REQUIRE_)?VERSION('. We did this above, while
485 # scanning configure.ac.
488 verb "$configure_ac: not using Gettext";
492 verb "$configure_ac: not running autopoint: --install not given";
496 xsystem_hint ("autopoint is needed because this package uses Gettext",
501 # ----------------- #
503 # ----------------- #
505 # Run it first: it might discover new macros to add, e.g.,
506 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
509 # Always run it. Tracking its sources for up-to-dateness is too
510 # complex and too error prone. The best we can do is avoiding
511 # nuking the timestamp.
512 my $uses_aclocal = 1;
514 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
519 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
520 $_ = $aclocal_m4->getline;
522 unless defined ($_) && /generated.*by aclocal/;
525 # If there are flags for aclocal in Makefile.am, use them.
526 my $aclocal_flags = '';
527 if ($uses_aclocal && -f 'Makefile.am')
529 my $makefile = new Autom4te::XFile 'Makefile.am';
530 while ($_ = $makefile->getline)
532 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
542 verb "$configure_ac: not using aclocal";
546 # Some file systems have sub-second timestamps, and if so we may
547 # run into trouble later, after we rerun autoconf and set the
548 # timestamps of input files to be no greater than aclocal.m4,
549 # because the time-stamp-setting operation (utime) has a
550 # resolution of only 1 second. Work around the problem by
551 # ensuring that there is at least a one-second window before the
552 # timestamp of aclocal.m4t in which no file timestamps can
556 xsystem ("$aclocal $aclocal_flags");
559 # We might have to rerun aclocal if Libtool (or others) imports new
561 my $rerun_aclocal = 0;
565 # ------------------------------- #
566 # See what tools will be needed. #
567 # ------------------------------- #
569 # Perform a single trace reading to avoid --force forcing a rerun
570 # between two --trace, that's useless. If there is no AC_INIT, then
571 # it's not an Autoconf script; ignore it.
572 # Suppress all warnings from this invocation; they may be spurious
573 # due to out-of-date files, and in any case they'll duplicate warnings
574 # from the final autoconf invocation.
577 my $uses_gettext_via_traces;
586 verb "$configure_ac: tracing";
588 local $ENV{WARNINGS} = 'none';
589 $traces = new Autom4te::XFile
592 map { ' --trace=' . $_ . ':\$n::\${::}%' }
593 # If you change this list, update the
594 # 'Autoreconf-preselections' section of autom4te.in.
599 'AC_REQUIRE_AUX_FILE',
603 'LT_CONFIG_LTDL_DIR',
611 while ($_ = $traces->getline)
614 my ($macro, @args) = split (/::/);
615 $aux_dir = $args[0] if $macro eq "AC_CONFIG_AUX_DIR";
616 push @aux_files, $args[0] if $macro eq "AC_REQUIRE_AUX_FILE";
617 $uses_autoconf = 1 if $macro eq "AC_INIT";
618 $uses_gettext_via_traces = 1 if $macro eq "AM_GNU_GETTEXT";
619 $uses_libtool = 1 if $macro eq "AC_PROG_LIBTOOL"
620 || $macro eq "AM_PROG_LIBTOOL"
621 || $macro eq "LT_INIT";
622 $uses_libltdl = 1 if $macro eq "LT_CONFIG_LTDL_DIR";
623 $uses_autoheader = 1 if $macro eq "AC_CONFIG_HEADERS";
624 $uses_automake = 1 if $macro eq "AM_INIT_AUTOMAKE";
625 $uses_intltool = 1 if $macro eq "IT_PROG_INTLTOOL";
626 $uses_gtkdoc = 1 if $macro eq "GTK_DOC_CHECK";
627 push @subdir, split (' ', $args[0] || '')
628 if $macro eq "AC_CONFIG_SUBDIRS"
633 # The subdirs are *optional*, they may not exist.
638 verb "$configure_ac: adding subdirectory $_ to autoreconf";
643 verb "$configure_ac: subdirectory $_ not present";
647 # Gettext consistency checks.
648 # Some projects intentionally don't call AM_GNU_GETTEXT_(REQUIRE_)VERSION
649 # because they have all of the gettext infrastructure checked into version
650 # control and they want us to _not_ run autopoint. Therefore, these
651 # diagnostics are only warnings.
652 msg('syntax', $configure_ac,
653 "AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
654 . " or AM_GNU_GETTEXT_REQUIRE_VERSION")
655 if $uses_gettext_via_traces && ! $uses_gettext;
656 msg('syntax', $configure_ac,
657 "AM_GNU_GETTEXT_VERSION or AM_GNU_GETTEXT_REQUIRE_VERSION is used,"
658 . " but not AM_GNU_GETTEXT")
659 if $uses_gettext && ! $uses_gettext_via_traces;
662 # ---------------------------- #
663 # Setting up the source tree. #
664 # ---------------------------- #
666 # libtoolize, automake --add-missing etc. will drop files in the
667 # $AUX_DIR. But these tools fail to install these files if the
668 # directory itself does not exist, which valid: just imagine a CVS
669 # repository with hand written code only (there is not even a need
670 # for a Makefile.am!).
672 if ($install && defined $aux_dir && ! -d $aux_dir)
674 verb "$configure_ac: creating directory $aux_dir";
676 or error "cannot create $aux_dir: $!";
680 # -------------------- #
681 # Running libtoolize. #
682 # -------------------- #
686 verb "$configure_ac: not using Libtool";
692 $libtoolize .= " --ltdl";
694 xsystem_hint ("libtoolize is needed because this package uses Libtool",
700 verb "$configure_ac: not running libtoolize: --install not given";
704 # --------------------- #
705 # Running intltoolize. #
706 # --------------------- #
710 verb "$configure_ac: not using Intltool";
714 xsystem_hint ("intltoolize is needed because this package uses Intltool",
719 verb "$configure_ac: not running intltool: --install not given";
723 # ------------------- #
724 # Running gtkdocize. #
725 # ------------------- #
729 verb "$configure_ac: not using Gtkdoc";
733 xsystem_hint ("gtkdocize is needed because this package uses Gtkdoc",
738 verb "$configure_ac: not running gtkdocize: --install not given";
742 # ------------------- #
743 # Rerunning aclocal. #
744 # ------------------- #
746 # If we re-installed Libtool or Gettext, the macros might have changed.
747 # Automake also needs an up-to-date aclocal.m4.
752 verb "$configure_ac: not using aclocal";
756 xsystem ("$aclocal $aclocal_flags");
761 # ------------------ #
762 # Running autoconf. #
763 # ------------------ #
765 # Don't try to be smarter than 'autoconf', which does its own up to
768 # We prefer running autoconf before autoheader, because (i) the
769 # latter runs the former, and (ii) autoconf is stricter than
770 # autoheader. So all in all, autoconf should give better error
775 # -------------------- #
776 # Running autoheader. #
777 # -------------------- #
779 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
782 # Just as for autoconf, up to date ness is performed by the tool
785 # Run it before automake, since the latter checks the presence of
786 # config.h.in when it sees an AC_CONFIG_HEADERS.
787 if (!$uses_autoheader)
789 verb "$configure_ac: not using Autoheader";
793 xsystem ($autoheader);
797 # ------------------ #
798 # Running automake. #
799 # ------------------ #
803 verb "$configure_ac: not using Automake";
807 # We should always run automake, and let it decide whether it shall
808 # update the file or not. In fact, the effect of '$force' is already
809 # included in '$automake' via '--no-force'.
813 # ---------------------------------------------------- #
814 # Installing aux files and checking for missing ones. #
815 # ---------------------------------------------------- #
816 try_install_aux_files (\@aux_files, $aux_dir || '.')
817 if $install && $force;
819 my @missing_aux_files = find_missing_aux_files (\@aux_files, $aux_dir);
820 if (@missing_aux_files)
822 try_install_aux_files (\@missing_aux_files, $aux_dir || '.')
823 if $install && !$force;
825 for (0 .. $#missing_aux_files)
827 my $f = $missing_aux_files[$_];
828 if ($_ == $#missing_aux_files)
830 # Offer some advice if --install wasn't given and has a
833 $trailer = "\n try running autoreconf --install"
839 || can_install_aux_files @missing_aux_files));
841 error $configure_ac, "required file '$f' not found$trailer";
845 error $configure_ac, "required file '$f' not found";
856 if (!-f "config.status")
858 verb "no config.status: cannot re-make";
862 xsystem ("./config.status --recheck");
863 xsystem ("./config.status");
866 verb "no Makefile: cannot re-make";
877 # &autoreconf ($DIRECTORY)
878 # ------------------------
879 # Reconf the $DIRECTORY.
882 my ($directory) = @_;
885 # The format for this message is not free: taken from Emacs, itself
886 # using GNU Make's format.
887 verb "Entering directory '$directory'";
889 or error "cannot chdir to $directory: $!";
891 autoreconf_current_directory ($directory);
893 # The format is not free: taken from Emacs, itself using GNU Make's
895 verb "Leaving directory '$directory'";
897 or error "cannot chdir to $cwd: $!";
905 # When debugging, it is convenient that all the related temporary
906 # files be at the same place.
908 $ENV{'TMPDIR'} = $tmp;
911 # Autoreconf all the given configure.ac. Unless '--no-recursive' is passed,
912 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
913 $ENV{'AUTOM4TE'} = $autom4te;
914 for my $directory (@ARGV)
916 require_configure_ac ($directory);
917 autoreconf ($directory);
922 ### Setup "GNU" style for perl-mode and cperl-mode.
924 ## perl-indent-level: 2
925 ## perl-continued-statement-offset: 2
926 ## perl-continued-brace-offset: 0
927 ## perl-brace-offset: 0
928 ## perl-brace-imaginary-offset: 0
929 ## perl-label-offset: -2
930 ## cperl-indent-level: 2
931 ## cperl-brace-offset: 0
932 ## cperl-continued-brace-offset: 0
933 ## cperl-label-offset: -2
934 ## cperl-extra-newline-before-brace: t
935 ## cperl-merge-trailing-else: nil
936 ## cperl-continued-statement-offset: 2