maint: update copyright year
[autoconf.git] / bin / autoreconf.in
blob03f9ecd1a028d7f4b368e5e6b01b7a5b37628464
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-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.
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 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.
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: <http://www.gnu.org/software/autoconf/>.
93 General help using GNU software: <http://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 <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.
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 --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;
131 my @prepend_include;
132 my @include;
134 # List of command line warning requests.
135 my @warning;
137 # Rerun `./configure && make'?
138 my $run_make = 0;
140 # Recurse into subpackages
141 my $recursive = 1;
143 ## ---------- ##
144 ## Routines.  ##
145 ## ---------- ##
148 # parse_args ()
149 # -------------
150 # Process any command line arguments.
151 sub parse_args ()
153   my $srcdir;
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
164   # lists.
165   @warning = map { split /,/ } @warning;
166   parse_WARNINGS;
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)
177     {
178       for my $prog ($autoconf, $autoheader,
179                     $automake, $aclocal,
180                     $autopoint,
181                     $libtoolize)
182         {
183           xsystem ("$prog --version | sed 1q >&2");
184           print STDERR "\n";
185         }
186     }
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.
196   # --include;
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;
204   if ($install)
205     {
206       $automake   .= ' --add-missing';
207       $automake   .= ' --copy' unless $symlink;
208       $libtoolize .= ' --copy' unless $symlink;
209     }
210   # --force;
211   if ($force)
212     {
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';
221     }
222   else
223     {
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
227       # the condition.)
228       $automake .= ' --no-force'
229         if $aclocal_supports_force;
230     }
231   # --verbose --verbose or --debug;
232   if ($verbose > 1 || $debug)
233     {
234       $autoconf   .= ' --verbose';
235       $autoheader .= ' --verbose';
236       $automake   .= ' --verbose';
237       $aclocal    .= ' --verbose';
238     }
239   if ($debug)
240     {
241       $autoconf   .= ' --debug';
242       $autoheader .= ' --debug';
243       $libtoolize .= ' --debug';
244     }
245   # --warnings;
246   if (@warning)
247     {
248       my $warn = ' --warnings=' . join (',', @warning);
249       $autoconf   .= $warn;
250       $autoheader .= $warn;
251       $automake   .= $warn
252         if $automake_supports_warnings;
253       $aclocal    .= $warn
254         if $aclocal_supports_warnings;
255     }
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.
264 sub run_aclocal ($$)
266   my ($aclocal, $flags) = @_;
268   # aclocal 1.8+ does all this for free.  It can be recognized by its
269   # --force support.
270   if ($aclocal_supports_force)
271     {
272       xsystem ("$aclocal $flags");
273     }
274   else
275     {
276       xsystem ("$aclocal $flags --output=aclocal.m4t");
277       # aclocal may produce no output.
278       if (-f 'aclocal.m4t')
279         {
280           update_file ('aclocal.m4t', 'aclocal.m4');
281           # Make sure that the local m4 files are older than
282           # aclocal.m4.
283           #
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
293           # again.
294           #
295           # To make sure aclocal.m4 is no older, we change the
296           # modification times of the local M4 files to be not newer
297           # than it.
298           #
299           # First, where are the local files?
300           my $aclocal_local_dir = '.';
301           if ($flags =~ /-I\s+(\S+)/)
302             {
303               $aclocal_local_dir = $1;
304             }
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')
309             {
310               if ($aclocal_m4_mtime < mtime ($file))
311                 {
312                   debug "aging $file to be not newer than aclocal.m4";
313                   utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
314                 }
315             }
316         }
317     }
320 # &autoreconf_current_directory
321 # -----------------------------
322 sub autoreconf_current_directory ()
324   my $configure_ac = find_configure_ac;
326   # ---------------------- #
327   # Is it using Autoconf?  #
328   # ---------------------- #
330   my $uses_autoconf;
331   my $uses_gettext;
332   if (-f $configure_ac)
333     {
334       my $configure_ac_file = new Autom4te::XFile "< $configure_ac";
335       while ($_ = $configure_ac_file->getline)
336         {
337           s/#.*//;
338           s/dnl.*//;
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/;
342         }
343     }
344   if (!$uses_autoconf)
345     {
346       verb "$configure_ac: not using Autoconf";
347       return;
348     }
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.
359   #
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.
363   #
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.
371   if (!$uses_gettext)
372     {
373       verb "$configure_ac: not using Gettext";
374     }
375   elsif (!$install)
376     {
377       verb "$configure_ac: not running autopoint: --install not given";
378     }
379   else
380     {
381       xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
382     }
385   # ----------------- #
386   # Running aclocal.  #
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
391   # used.
392   #
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,
399   # don't run aclocal.
401   if (-f 'aclocal.m4')
402     {
403       my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
404       $_ = $aclocal_m4->getline;
405       $uses_aclocal = 0
406         unless defined ($_) && /generated.*by aclocal/;
407     }
409   # If there are flags for aclocal in Makefile.am, use them.
410   my $aclocal_flags = '';
411   if ($uses_aclocal && -f 'Makefile.am')
412     {
413       my $makefile = new Autom4te::XFile 'Makefile.am';
414       while ($_ = $makefile->getline)
415         {
416           if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
417             {
418               $aclocal_flags = $1;
419               last;
420             }
421         }
422     }
424   if (!$uses_aclocal)
425     {
426       verb "$configure_ac: not using aclocal";
427     }
428   else
429     {
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
437       # fall.
438       sleep 1;
440       run_aclocal ($aclocal, $aclocal_flags);
441     }
443   # We might have to rerun aclocal if Libtool (or others) imports new
444   # macros.
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.
456   my $aux_dir;
457   my $uses_gettext_via_traces;
458   my $uses_libtool;
459   my $uses_libltdl;
460   my $uses_autoheader;
461   my $uses_automake;
462   my @subdir;
463   verb "$configure_ac: tracing";
464   my $traces = new Autom4te::XFile
465     ("$autoconf"
466      . join (' ',
467              map { ' --trace=' . $_ . ':\$n::\${::}%' }
468              # If you change this list, update the
469              # `Autoreconf-preselections' section of autom4te.in.
470              'AC_CONFIG_AUX_DIR',
471              'AC_CONFIG_HEADERS',
472              'AC_CONFIG_SUBDIRS',
473              'AC_INIT',
474              'AC_PROG_LIBTOOL',
475              'LT_INIT',
476              'LT_CONFIG_LTDL_DIR',
477              'AM_GNU_GETTEXT',
478              'AM_INIT_AUTOMAKE',
479             )
480      . ' |');
481   while ($_ = $traces->getline)
482     {
483       chomp;
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;
495     }
497   # The subdirs are *optional*, they may not exist.
498   foreach (@subdir)
499     {
500       if (-d)
501         {
502           verb "$configure_ac: adding subdirectory $_ to autoreconf";
503           autoreconf ($_);
504         }
505       else
506         {
507           verb "$configure_ac: subdirectory $_ not present";
508         }
509     }
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)
529     {
530       verb "$configure_ac: creating directory $aux_dir";
531       mkdir $aux_dir, 0755
532         or error "cannot create $aux_dir: $!";
533     }
536   # -------------------- #
537   # Running libtoolize.  #
538   # -------------------- #
540   if (!$uses_libtool)
541     {
542       verb "$configure_ac: not using Libtool";
543     }
544   elsif ($install)
545     {
546       if ($uses_libltdl)
547         {
548           $libtoolize .= " --ltdl";
549         }
550       xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
551       $rerun_aclocal = 1;
552     }
553   else
554     {
555       verb "$configure_ac: not running libtoolize: --install not given";
556     }
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.
566   if ($rerun_aclocal)
567     {
568       if (!$uses_aclocal)
569         {
570           verb "$configure_ac: not using aclocal";
571         }
572       else
573         {
574           run_aclocal ($aclocal, $aclocal_flags);
575         }
576     }
579   # ------------------ #
580   # Running autoconf.  #
581   # ------------------ #
583   # Don't try to be smarter than `autoconf', which does its own up to
584   # date checks.
585   #
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
589   # messages.
590   xsystem ($autoconf);
593   # -------------------- #
594   # Running autoheader.  #
595   # -------------------- #
597   # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
598   # is used too.
599   #
600   # Just as for autoconf, up to date ness is performed by the tool
601   # itself.
602   #
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)
606     {
607       verb "$configure_ac: not using Autoheader";
608     }
609   else
610     {
611       xsystem ($autoheader);
612     }
615   # ------------------ #
616   # Running automake.  #
617   # ------------------ #
619   if (!$uses_automake)
620     {
621       verb "$configure_ac: not using Automake";
622     }
623   else
624     {
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'.
628       xsystem ($automake);
629     }
632   # -------------- #
633   # Running make.  #
634   # -------------- #
636   if ($run_make)
637     {
638       if (!-f "config.status")
639         {
640           verb "no config.status: cannot re-make";
641         }
642       else
643         {
644           xsystem ("./config.status --recheck");
645           xsystem ("./config.status");
646           if (!-f "Makefile")
647             {
648               verb "no Makefile: cannot re-make";
649             }
650           else
651             {
652               xsystem ("$make");
653             }
654         }
655     }
659 # &autoreconf ($DIRECTORY)
660 # ------------------------
661 # Reconf the $DIRECTORY.
662 sub autoreconf ($)
664   my ($directory) = @_;
665   my $cwd = cwd;
667   # The format for this message is not free: taken from Emacs, itself
668   # using GNU Make's format.
669   verb "Entering directory `$directory'";
670   chdir $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
676   # format.
677   verb "Leaving directory `$directory'";
678   chdir $cwd
679     or error "cannot chdir to $cwd: $!";
683 ## ------ ##
684 ## Main.  ##
685 ## ------ ##
687 # When debugging, it is convenient that all the related temporary
688 # files be at the same place.
689 mktmpdir ('ar');
690 $ENV{'TMPDIR'} = $tmp;
691 parse_args;
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)
697   {
698     require_configure_ac ($directory);
699     autoreconf ($directory);
700   }
702 ### Setup "GNU" style for perl-mode and cperl-mode.
703 ## Local Variables:
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
717 ## End: