Prefer HTTPS to FTP and HTTP
[autoconf.git] / bin / autoreconf.in
blob79ffb9f59939ae3d89d7518839147b74b8ad6183
1 #! @PERL@ -w
2 # -*- perl -*-
3 # @configure_input@
5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
6     if 0;
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 <https://www.gnu.org/licenses/>.
24 # Written by David J. MacKenzie.
25 # Extended and rewritten in Perl by Akim Demaille.
27 BEGIN
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
35   # has detected.
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;
44 use Autom4te::XFile;
45 # Do not use Cwd::chdir, since it might hang.
46 use Cwd 'cwd';
47 use strict;
49 ## ----------- ##
50 ## Variables.  ##
51 ## ----------- ##
53 # $HELP
54 # -----
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
65 '--force' option.
67 Operation modes:
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.
84 Library directories:
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: <https://www.gnu.org/software/autoconf/>.
93 General help using GNU software: <https://www.gnu.org/gethelp/>.
96 # $VERSION
97 # --------
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 <https://gnu.org/licenses/gpl.html>, <https://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.
108 # Lib files.
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.
119 my $install = 0;
120 # symlink -- when --install, use symlinks instead.
121 my $symlink = 0;
122 # Does aclocal support -Wfoo?
123 my $aclocal_supports_warnings = 0;
124 # Does automake support -Wfoo?
125 my $automake_supports_warnings = 0;
127 my @prepend_include;
128 my @include;
130 # List of command line warning requests.
131 my @warning;
133 # Rerun './configure && make'?
134 my $run_make = 0;
136 # Recurse into subpackages
137 my $recursive = 1;
139 ## ---------- ##
140 ## Routines.  ##
141 ## ---------- ##
144 # parse_args ()
145 # -------------
146 # Process any command line arguments.
147 sub parse_args ()
149   my $srcdir;
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
160   # lists.
161   @warning = map { split /,/ } @warning;
162   parse_WARNINGS;
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)
173     {
174       for my $prog ($autoconf, $autoheader,
175                     $automake, $aclocal,
176                     $autopoint,
177                     $libtoolize)
178         {
179           xsystem ("$prog --version | sed 1q >&2");
180           print STDERR "\n";
181         }
182     }
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.
190   # --include;
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;
198   if ($install)
199     {
200       $automake   .= ' --add-missing';
201       $automake   .= ' --copy' unless $symlink;
202       $libtoolize .= ' --copy' unless $symlink;
203     }
204   # --force;
205   if ($force)
206     {
207       $aclocal    .= ' --force';
208       $autoconf   .= ' --force';
209       $autoheader .= ' --force';
210       $automake   .= ' --force-missing';
211       $autopoint  .= ' --force';
212       $libtoolize .= ' --force';
213     }
214   else
215     {
216       $automake .= ' --no-force';
217     }
218   # --verbose --verbose or --debug;
219   if ($verbose > 1 || $debug)
220     {
221       $autoconf   .= ' --verbose';
222       $autoheader .= ' --verbose';
223       $automake   .= ' --verbose';
224       $aclocal    .= ' --verbose';
225     }
226   if ($debug)
227     {
228       $autoconf   .= ' --debug';
229       $autoheader .= ' --debug';
230       $libtoolize .= ' --debug';
231     }
232   # --warnings;
233   if (@warning)
234     {
235       my $warn = ' --warnings=' . join (',', @warning);
236       $autoconf   .= $warn;
237       $autoheader .= $warn;
238       $automake   .= $warn
239         if $automake_supports_warnings;
240       $aclocal    .= $warn
241         if $aclocal_supports_warnings;
242     }
246 # &autoreconf_current_directory
247 # -----------------------------
248 sub autoreconf_current_directory ()
250   my $configure_ac = find_configure_ac;
252   # ---------------------- #
253   # Is it using Autoconf?  #
254   # ---------------------- #
256   my $uses_autoconf;
257   my $uses_gettext;
258   if (-f $configure_ac)
259     {
260       my $configure_ac_file = new Autom4te::XFile ("$configure_ac", "<");
261       while ($_ = $configure_ac_file->getline)
262         {
263           s/#.*//;
264           s/dnl.*//;
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/;
268         }
269     }
270   if (!$uses_autoconf)
271     {
272       verb "$configure_ac: not using Autoconf";
273       return;
274     }
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.
285   #
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.
289   #
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.
297   if (!$uses_gettext)
298     {
299       verb "$configure_ac: not using Gettext";
300     }
301   elsif (!$install)
302     {
303       verb "$configure_ac: not running autopoint: --install not given";
304     }
305   else
306     {
307       xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
308     }
311   # ----------------- #
312   # Running aclocal.  #
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
317   # used.
318   #
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,
325   # don't run aclocal.
327   if (-f 'aclocal.m4')
328     {
329       my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
330       $_ = $aclocal_m4->getline;
331       $uses_aclocal = 0
332         unless defined ($_) && /generated.*by aclocal/;
333     }
335   # If there are flags for aclocal in Makefile.am, use them.
336   my $aclocal_flags = '';
337   if ($uses_aclocal && -f 'Makefile.am')
338     {
339       my $makefile = new Autom4te::XFile 'Makefile.am';
340       while ($_ = $makefile->getline)
341         {
342           if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
343             {
344               $aclocal_flags = $1;
345               last;
346             }
347         }
348     }
350   if (!$uses_aclocal)
351     {
352       verb "$configure_ac: not using aclocal";
353     }
354   else
355     {
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
363       # fall.
364       sleep 1;
366       xsystem ("$aclocal $aclocal_flags");
367     }
369   # We might have to rerun aclocal if Libtool (or others) imports new
370   # macros.
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.
382   my $aux_dir;
383   my $uses_gettext_via_traces;
384   my $uses_libtool;
385   my $uses_libltdl;
386   my $uses_autoheader;
387   my $uses_automake;
388   my @subdir;
389   verb "$configure_ac: tracing";
390   my $traces = new Autom4te::XFile
391     ("$autoconf"
392      . join (' ',
393              map { ' --trace=' . $_ . ':\$n::\${::}%' }
394              # If you change this list, update the
395              # 'Autoreconf-preselections' section of autom4te.in.
396              'AC_CONFIG_AUX_DIR',
397              'AC_CONFIG_HEADERS',
398              'AC_CONFIG_SUBDIRS',
399              'AC_INIT',
400              'AC_PROG_LIBTOOL',
401              'LT_INIT',
402              'LT_CONFIG_LTDL_DIR',
403              'AM_GNU_GETTEXT',
404              'AM_INIT_AUTOMAKE',
405             )
406      . ' |');
407   while ($_ = $traces->getline)
408     {
409       chomp;
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;
421     }
423   # The subdirs are *optional*, they may not exist.
424   foreach (@subdir)
425     {
426       if (-d)
427         {
428           verb "$configure_ac: adding subdirectory $_ to autoreconf";
429           autoreconf ($_);
430         }
431       else
432         {
433           verb "$configure_ac: subdirectory $_ not present";
434         }
435     }
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)
455     {
456       verb "$configure_ac: creating directory $aux_dir";
457       mkdir $aux_dir, 0755
458         or error "cannot create $aux_dir: $!";
459     }
462   # -------------------- #
463   # Running libtoolize.  #
464   # -------------------- #
466   if (!$uses_libtool)
467     {
468       verb "$configure_ac: not using Libtool";
469     }
470   elsif ($install)
471     {
472       if ($uses_libltdl)
473         {
474           $libtoolize .= " --ltdl";
475         }
476       xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
477       $rerun_aclocal = 1;
478     }
479   else
480     {
481       verb "$configure_ac: not running libtoolize: --install not given";
482     }
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.
492   if ($rerun_aclocal)
493     {
494       if (!$uses_aclocal)
495         {
496           verb "$configure_ac: not using aclocal";
497         }
498       else
499         {
500           xsystem ("$aclocal $aclocal_flags");
501         }
502     }
505   # ------------------ #
506   # Running autoconf.  #
507   # ------------------ #
509   # Don't try to be smarter than 'autoconf', which does its own up to
510   # date checks.
511   #
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
515   # messages.
516   xsystem ($autoconf);
519   # -------------------- #
520   # Running autoheader.  #
521   # -------------------- #
523   # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
524   # is used too.
525   #
526   # Just as for autoconf, up to date ness is performed by the tool
527   # itself.
528   #
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)
532     {
533       verb "$configure_ac: not using Autoheader";
534     }
535   else
536     {
537       xsystem ($autoheader);
538     }
541   # ------------------ #
542   # Running automake.  #
543   # ------------------ #
545   if (!$uses_automake)
546     {
547       verb "$configure_ac: not using Automake";
548     }
549   else
550     {
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'.
554       xsystem ($automake);
555     }
558   # -------------- #
559   # Running make.  #
560   # -------------- #
562   if ($run_make)
563     {
564       if (!-f "config.status")
565         {
566           verb "no config.status: cannot re-make";
567         }
568       else
569         {
570           xsystem ("./config.status --recheck");
571           xsystem ("./config.status");
572           if (!-f "Makefile")
573             {
574               verb "no Makefile: cannot re-make";
575             }
576           else
577             {
578               xsystem ("$make");
579             }
580         }
581     }
585 # &autoreconf ($DIRECTORY)
586 # ------------------------
587 # Reconf the $DIRECTORY.
588 sub autoreconf ($)
590   my ($directory) = @_;
591   my $cwd = cwd;
593   # The format for this message is not free: taken from Emacs, itself
594   # using GNU Make's format.
595   verb "Entering directory '$directory'";
596   chdir $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
602   # format.
603   verb "Leaving directory '$directory'";
604   chdir $cwd
605     or error "cannot chdir to $cwd: $!";
609 ## ------ ##
610 ## Main.  ##
611 ## ------ ##
613 # When debugging, it is convenient that all the related temporary
614 # files be at the same place.
615 mktmpdir ('ar');
616 $ENV{'TMPDIR'} = $tmp;
617 parse_args;
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)
623   {
624     require_configure_ac ($directory);
625     autoreconf ($directory);
626   }
628 ### Setup "GNU" style for perl-mode and cperl-mode.
629 ## Local Variables:
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
643 ## End: