typo
[autoconf.git] / bin / autoreconf.in
blobc224d9396d54182d559b36315e2a300859228d40
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, 2000, 2001, 2002, 2003, 2004, 2005, 2006
10 # Free Software Foundation, Inc.
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 2, or (at your option)
15 # 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, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 # 02110-1301, USA.
27 # Written by David J. MacKenzie.
28 # Extended and rewritten in Perl by Akim Demaille.
30 BEGIN
32   my $datadir = $ENV{'autom4te_perllibdir'} || '@datadir@';
33   unshift @INC, $datadir;
35   # Override SHELL.  On DJGPP SHELL may not be set to a shell
36   # that can handle redirection and quote arguments correctly,
37   # e.g.: COMMAND.COM.  For DJGPP always use the shell that configure
38   # has detected.
39   $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
42 use Autom4te::ChannelDefs;
43 use Autom4te::Channels;
44 use Autom4te::Configure_ac;
45 use Autom4te::FileUtils;
46 use Autom4te::General;
47 use Autom4te::XFile;
48 # Do not use Cwd::chdir, since it might hang.
49 use Cwd 'cwd';
50 use strict;
52 ## ----------- ##
53 ## Variables.  ##
54 ## ----------- ##
56 # $HELP
57 # -----
58 $help = "Usage: $0 [OPTION] ... [DIRECTORY] ...
60 Run `autoconf' (and `autoheader', `aclocal', `automake', `autopoint'
61 (formerly `gettextize'), and `libtoolize' where appropriate)
62 repeatedly to remake the GNU Build System files in specified
63 DIRECTORIES and their subdirectories (defaulting to `.').
65 By default, it only remakes those files that are older than their
66 sources.  If you install new versions of the GNU Build System,
67 you can make `autoreconf' remake all of the files by giving it the
68 `--force' option.
70 Operation modes:
71   -h, --help               print this help, then exit
72   -V, --version            print version number, then exit
73   -v, --verbose            verbosely report processing
74   -d, --debug              don't remove temporary files
75   -f, --force              consider all files obsolete
76   -i, --install            copy missing auxiliary files
77       --no-recursive       don't rebuild sub-packages
78   -s, --symlink            with -i, install symbolic links instead of copies
79   -m, --make               when applicable, re-run ./configure && make
80   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [syntax]
82 " . Autom4te::ChannelDefs::usage . "
84 The environment variable \`WARNINGS\' is honored.  Some subtools might
85 support other warning types, using \`all' is encouraged.
87 Library directories:
88   -B, --prepend-include=DIR  prepend directory DIR to search path
89   -I, --include=DIR          append directory DIR to search path
91 The environment variables AUTOCONF, AUTOHEADER, AUTOMAKE, ACLOCAL,
92 AUTOPOINT, LIBTOOLIZE, M4 are honored.
94 Report bugs to <bug-autoconf\@gnu.org>.
97 # $VERSION
98 # --------
99 $version = "autoreconf (@PACKAGE_NAME@) @VERSION@
100 Written by David J. MacKenzie and Akim Demaille.
102 Copyright (C) 2006 Free Software Foundation, Inc.
103 This is free software; see the source for copying conditions.  There is NO
104 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
107 # Lib files.
108 my $autoconf   = $ENV{'AUTOCONF'}   || '@bindir@/@autoconf-name@';
109 my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
110 my $automake   = $ENV{'AUTOMAKE'}   || 'automake';
111 my $aclocal    = $ENV{'ACLOCAL'}    || 'aclocal';
112 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
113 my $autopoint  = $ENV{'AUTOPOINT'}  || 'autopoint';
115 # --install -- as --add-missing in other tools.
116 my $install = 0;
117 # symlink -- when --install, use symlinks instead.
118 my $symlink = 0;
119 # Does aclocal support --force?
120 my $aclocal_supports_force = 0;
121 # Does automake support --force-missing?
122 my $automake_supports_force_missing = 0;
124 my @prepend_include;
125 my @include;
127 # List of command line warning requests.
128 my @warning;
130 # Rerun `./configure && make'?
131 my $make = 0;
133 # Recurse into subpackages
134 my $recursive = 1;
136 ## ---------- ##
137 ## Routines.  ##
138 ## ---------- ##
141 # parse_args ()
142 # -------------
143 # Process any command line arguments.
144 sub parse_args ()
146   my $srcdir;
148   getopt ("W|warnings=s"         => \@warning,
149           'I|include=s'          => \@include,
150           'B|prepend-include=s'  => \@prepend_include,
151           'i|install'            => \$install,
152           's|symlink'            => \$symlink,
153           'm|make'               => \$make,
154           'recursive!'           => \$recursive);
156   # Split the warnings as a list of elements instead of a list of
157   # lists.
158   @warning = map { split /,/ } @warning;
159   parse_WARNINGS;
160   parse_warnings '--warnings', @warning;
162   # Even if the user specified a configure.ac, trim to get the
163   # directory, and look for configure.ac again.  Because (i) the code
164   # is simpler, and (ii) we are still able to diagnose simultaneous
165   # presence of configure.ac and configure.in.
166   @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
167   push @ARGV, '.' unless @ARGV;
169   if ($verbose && $debug)
170     {
171       for my $prog ($autoconf, $autoheader,
172                     $automake, $aclocal,
173                     $autopoint,
174                     $libtoolize)
175         {
176           xsystem ("$prog --version | sed 1q >&2");
177           print STDERR "\n";
178         }
179     }
181   $aclocal_supports_force = `$aclocal --help` =~ /--force/;
182   $automake_supports_force_missing = `$automake --help` =~ /--force-missing/;
184   # Dispatch autoreconf's option to the tools.
185   # --include;
186   $autoconf   .= join (' --include=', '', @include);
187   $autoconf   .= join (' --prepend-include=', '', @prepend_include);
188   $autoheader .= join (' --include=', '', @include);
189   $autoheader .= join (' --prepend-include=', '', @prepend_include);
191   # --install and --symlink;
192   if ($install)
193     {
194       $automake   .= ' --add-missing';
195       $automake   .= ' --copy' unless $symlink;
196       $libtoolize .= ' --copy' unless $symlink;
197     }
198   # --force;
199   if ($force)
200     {
201       $aclocal    .= ' --force'
202         if $aclocal_supports_force;
203       $autoconf   .= ' --force';
204       $autoheader .= ' --force';
205       $automake   .= ' --force-missing'
206         if $automake_supports_force_missing;
207       $autopoint  .= ' --force';
208       $libtoolize .= ' --force';
209     }
210   else
211     {
212       # The implementation of --no-force is bogus in all implementations
213       # of Automake up to 1.8, so we avoid it in these cases.  (Automake
214       # 1.8 is the first version where aclocal supports force, hence
215       # the condition.)
216       $automake .= ' --no-force'
217         if $aclocal_supports_force;
218     }
219   # --verbose --verbose or --debug;
220   if ($verbose > 1 || $debug)
221     {
222       $autoconf   .= ' --verbose';
223       $autoheader .= ' --verbose';
224       $automake   .= ' --verbose';
225       $aclocal    .= ' --verbose';
226     }
227   if ($debug)
228     {
229       $autoconf   .= ' --debug';
230       $autoheader .= ' --debug';
231       $libtoolize .= ' --debug';
232     }
233   # --warnings;
234   if (@warning)
235     {
236       my $warn = ' --warnings=' . join (',', @warning);
237       $autoconf   .= $warn;
238       $autoheader .= $warn;
239       $automake   .= $warn
240         if `$automake --help` =~ /--warnings/;
241     }
245 # &run_aclocal ($ACLOCAL, $FLAGS)
246 # -------------------------------
247 # Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
248 # overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
249 # etc. uselessly.  aclocal 1.8+ does not need this.
250 sub run_aclocal ($$)
252   my ($aclocal, $flags) = @_;
254   # aclocal 1.8+ does all this for free.  It can be recognized by its
255   # --force support.
256   if ($aclocal_supports_force)
257     {
258       xsystem ("$aclocal $flags");
259     }
260   else
261     {
262       xsystem ("$aclocal $flags --output=aclocal.m4t");
263       # aclocal may produce no output.
264       if (-f 'aclocal.m4t')
265         {
266           update_file ('aclocal.m4t', 'aclocal.m4');
267           # Make sure that the local m4 files are older than
268           # aclocal.m4.
269           #
270           # Why is not always the case?  Because we already run
271           # aclocal at first (before tracing), which, for instance,
272           # can find Gettext's macros in .../share/aclocal, so we may
273           # have had the right aclocal.m4 already.  Then autopoint is
274           # run, and installs locally these M4 files.  Then
275           # autoreconf, via update_file, sees it is the _same_
276           # aclocal.m4, and doesn't change its timestamp.  But later,
277           # Automake's Makefile expresses that aclocal.m4 depends on
278           # these local files, which are newer, so it triggers aclocal
279           # again.
280           #
281           # To make sure aclocal.m4 is no older, we change the
282           # modification times of the local M4 files to be not newer
283           # than it.
284           #
285           # First, where are the local files?
286           my $aclocal_local_dir = '.';
287           if ($flags =~ /-I\s+(\S+)/)
288             {
289               $aclocal_local_dir = $1;
290             }
291           # All the local files newer than aclocal.m4 are to be
292           # made not newer than it.
293           my $aclocal_m4_mtime = mtime ('aclocal.m4');
294           for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
295             {
296               if ($aclocal_m4_mtime < mtime ($file))
297                 {
298                   debug "aging $file to be not newer than aclocal.m4";
299                   utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
300                 }
301             }
302         }
303     }
306 # &autoreconf_current_directory
307 # -----------------------------
308 sub autoreconf_current_directory ()
310   my $configure_ac = find_configure_ac;
312   # ---------------------- #
313   # Is it using Autoconf?  #
314   # ---------------------- #
316   my $uses_autoconf;
317   my $uses_gettext;
318   if (-f $configure_ac)
319     {
320       my $configure_ac_file = new Autom4te::XFile $configure_ac;
321       while ($_ = $configure_ac_file->getline)
322         {
323           s/#.*//;
324           s/dnl.*//;
325           $uses_autoconf = 1 if /AC_INIT/;
326           # See below for why we look for gettext here.
327           $uses_gettext = 1  if /^AM_GNU_GETTEXT_VERSION/;
328         }
329     }
330   if (!$uses_autoconf)
331     {
332       verb "$configure_ac: not using Autoconf";
333       return;
334     }
337   # ------------------- #
338   # Running autopoint.  #
339   # ------------------- #
341   # Gettext is a bit of a problem: its macros are not necessarily
342   # visible to aclocal, so if we start with a completely striped down
343   # package (think of a fresh CVS checkout), running `aclocal' first
344   # will fail: the Gettext macros are missing.
345   #
346   # Therefore, we can't use the traces to decide if we use Gettext or
347   # not.  I guess that once Gettext move to 2.5x we will be able to,
348   # but in the meanwhile forget it.
349   #
350   # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac.  You
351   # might think this approach is naive, and indeed it is, as it
352   # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
353   # anyway we don't limit the generality, since... that's what
354   # autopoint does.  Actually, it is even more restrictive, as it
355   # greps for `^AM_GNU_GETTEXT_VERSION('.  We did this above, while
356   # scanning configure.ac.
357   if (!$uses_gettext)
358     {
359       verb "$configure_ac: not using Gettext";
360     }
361   elsif (!$install)
362     {
363       verb "$configure_ac: not running autopoint: --install not given";
364     }
365   else
366     {
367       xsystem "$autopoint";
368     }
371   # ----------------- #
372   # Running aclocal.  #
373   # ----------------- #
375   # Run it first: it might discover new macros to add, e.g.,
376   # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
377   # used.
378   #
379   # Always run it.  Tracking its sources for up-to-dateness is too
380   # complex and too error prone.  The best we can do is avoiding
381   # nuking the time stamp.
382   my $uses_aclocal = 1;
384   # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
385   # don't run aclocal.
387   if (-f 'aclocal.m4')
388     {
389       my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
390       $_ = $aclocal_m4->getline;
391       $uses_aclocal = 0
392         unless defined ($_) && /generated.*by aclocal/;
393     }
395   # If there are flags for aclocal in Makefile.am, use them.
396   my $aclocal_flags = '';
397   if ($uses_aclocal && -f 'Makefile.am')
398     {
399       my $makefile = new Autom4te::XFile 'Makefile.am';
400       while ($_ = $makefile->getline)
401         {
402           if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
403             {
404               $aclocal_flags = $1;
405               last;
406             }
407         }
408     }
410   if (!$uses_aclocal)
411     {
412       verb "$configure_ac: not using aclocal";
413     }
414   else
415     {
416       # Some file systems have sub-second time stamps, and if so we may
417       # run into trouble later, after we rerun autoconf and set the
418       # time stamps of input files to be no greater than aclocal.m4,
419       # because the time-stamp-setting operation (utime) has a
420       # resolution of only 1 second.  Work around the problem by
421       # ensuring that there is at least a one-second window before the
422       # time stamp of aclocal.m4t in which no file time stamps can
423       # fall.
424       sleep 1;
426       run_aclocal ($aclocal, $aclocal_flags);
427     }
429   # We might have to rerun aclocal if Libtool (or others) imports new
430   # macros.
431   my $rerun_aclocal = 0;
435   # ------------------------------- #
436   # See what tools will be needed.  #
437   # ------------------------------- #
439   # Perform a single trace reading to avoid --force forcing a rerun
440   # between two --trace, that's useless.  If there is no AC_INIT, then
441   # we are not interested: it looks like a Cygnus thingy.
442   my $aux_dir;
443   my $uses_gettext_via_traces;
444   my $uses_libtool;
445   my $uses_libltdl;
446   my $uses_autoheader;
447   my $uses_automake;
448   my @subdir;
449   verb "$configure_ac: tracing";
450   my $traces = new Autom4te::XFile
451     ("$autoconf"
452      . join (' --trace=', '',
453              # If you change this list, update the
454              # `Autoreconf-preselections' section of autom4te.in.
455              'AC_CONFIG_AUX_DIR:AC_CONFIG_AUX_DIR:\$1',
456              'AC_CONFIG_HEADERS',
457              'AC_CONFIG_SUBDIRS:AC_CONFIG_SUBDIRS:\$1',
458              'AC_INIT',
459              'AC_PROG_LIBTOOL',
460              'LT_INIT',
461              'LT_CONFIG_LTDL_DIR',
462              'AM_GNU_GETTEXT',
463              'AM_INIT_AUTOMAKE',
464             )
465      . ' |');
466   while ($_ = $traces->getline)
467     {
468       $aux_dir = $1                 if /AC_CONFIG_AUX_DIR:(.*)/;
469       $uses_autoconf = 1            if /AC_INIT/;
470       $uses_gettext_via_traces = 1  if /AM_GNU_GETTEXT/;
471       $uses_libtool = 1             if /(AC_PROG_LIBTOOL|LT_INIT)/;
472       $uses_libltdl = 1             if /LT_CONFIG_LTDL_DIR/;
473       $uses_autoheader = 1          if /AC_CONFIG_HEADERS/;
474       $uses_automake = 1            if /AM_INIT_AUTOMAKE/;
475       push @subdir, split (' ', $1) if /AC_CONFIG_SUBDIRS:(.*)/ && $recursive;
476     }
478   # The subdirs are *optional*, they may not exist.
479   foreach (@subdir)
480     {
481       if (-d)
482         {
483           verb "$configure_ac: adding subdirectory $_ to autoreconf";
484           autoreconf ($_);
485         }
486       else
487         {
488           verb "$configure_ac: subdirectory $_ not present";
489         }
490     }
492   # Gettext consistency checks...
493   error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
494     if $uses_gettext_via_traces && ! $uses_gettext;
495   error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
496     if $uses_gettext && ! $uses_gettext_via_traces;
499   # ---------------------------- #
500   # Setting up the source tree.  #
501   # ---------------------------- #
503   # libtoolize, automake --add-missing etc. will drop files in the
504   # $AUX_DIR.  But these tools fail to install these files if the
505   # directory itself does not exist, which valid: just imagine a CVS
506   # repository with hand written code only (there is not even a need
507   # for a Makefile.am!).
509   if (defined $aux_dir && ! -d $aux_dir)
510     {
511       verb "$configure_ac: creating directory $aux_dir";
512       mkdir $aux_dir, 0755
513         or error "cannot create $aux_dir: $!";
514     }
517   # -------------------- #
518   # Running libtoolize.  #
519   # -------------------- #
521   if (!$uses_libtool)
522     {
523       verb "$configure_ac: not using Libtool";
524     }
525   elsif ($install)
526     {
527       if ($uses_libltdl)
528         {
529           $libtoolize .= " --ltdl";
530         }
531       xsystem ($libtoolize);
532       $rerun_aclocal = 1;
533     }
534   else
535     {
536       verb "$configure_ac: not running libtoolize: --install not given";
537     }
541   # ------------------- #
542   # Rerunning aclocal.  #
543   # ------------------- #
545   # If we re-installed Libtool or Gettext, the macros might have changed.
546   # Automake also needs an up-to-date aclocal.m4.
547   if ($rerun_aclocal)
548     {
549       if (!$uses_aclocal)
550         {
551           verb "$configure_ac: not using aclocal";
552         }
553       else
554         {
555           run_aclocal ($aclocal, $aclocal_flags);
556         }
557     }
560   # ------------------ #
561   # Running autoconf.  #
562   # ------------------ #
564   # Don't try to be smarter than `autoconf', which does its own up to
565   # date checks.
566   #
567   # We prefer running autoconf before autoheader, because (i) the
568   # latter runs the former, and (ii) autoconf is stricter than
569   # autoheader.  So all in all, autoconf should give better error
570   # messages.
571   xsystem ($autoconf);
574   # -------------------- #
575   # Running autoheader.  #
576   # -------------------- #
578   # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
579   # is used too.
580   #
581   # Just as for autoconf, up to date ness is performed by the tool
582   # itself.
583   #
584   # Run it before automake, since the latter checks the presence of
585   # config.h.in when it sees an AC_CONFIG_HEADERS.
586   if (!$uses_autoheader)
587     {
588       verb "$configure_ac: not using Autoheader";
589     }
590   else
591     {
592       xsystem ($autoheader);
593     }
596   # ------------------ #
597   # Running automake.  #
598   # ------------------ #
600   if (!$uses_automake)
601     {
602       verb "$configure_ac: not using Automake";
603     }
604   else
605     {
606       # We should always run automake, and let it decide whether it shall
607       # update the file or not.  In fact, the effect of `$force' is already
608       # included in `$automake' via `--no-force'.
609       xsystem ($automake);
610     }
613   # -------------- #
614   # Running make.  #
615   # -------------- #
617   if ($make)
618     {
619       if (!-f "config.status")
620         {
621           verb "no config.status: cannot re-make";
622         }
623       else
624         {
625           xsystem ("./config.status --recheck");
626           xsystem ("./config.status");
627           if (!-f "Makefile")
628             {
629               verb "no Makefile: cannot re-make";
630             }
631           else
632             {
633               xsystem ("make");
634             }
635         }
636     }
640 # &autoreconf ($DIRECTORY)
641 # ------------------------
642 # Reconf the $DIRECTORY.
643 sub autoreconf ($)
645   my ($directory) = @_;
646   my $cwd = cwd;
648   # The format for this message is not free: taken from Emacs, itself
649   # using GNU Make's format.
650   verb "Entering directory `$directory'";
651   chdir $directory
652     or error "cannot chdir to $directory: $!";
654   autoreconf_current_directory;
656   # The format is not free: taken from Emacs, itself using GNU Make's
657   # format.
658   verb "Leaving directory `$directory'";
659   chdir $cwd
660     or error "cannot chdir to $cwd: $!";
664 ## ------ ##
665 ## Main.  ##
666 ## ------ ##
668 # When debugging, it is convenient that all the related temporary
669 # files be at the same place.
670 mktmpdir ('ar');
671 $ENV{'TMPDIR'} = $tmp;
672 parse_args;
674 # Autoreconf all the given configure.ac.  Unless `--no-recursive' is passed,
675 # AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
676 for my $directory (@ARGV)
677   {
678     require_configure_ac ($directory);
679     autoreconf ($directory);
680   }
682 ### Setup "GNU" style for perl-mode and cperl-mode.
683 ## Local Variables:
684 ## perl-indent-level: 2
685 ## perl-continued-statement-offset: 2
686 ## perl-continued-brace-offset: 0
687 ## perl-brace-offset: 0
688 ## perl-brace-imaginary-offset: 0
689 ## perl-label-offset: -2
690 ## cperl-indent-level: 2
691 ## cperl-brace-offset: 0
692 ## cperl-continued-brace-offset: 0
693 ## cperl-label-offset: -2
694 ## cperl-extra-newline-before-brace: t
695 ## cperl-merge-trailing-else: nil
696 ## cperl-continued-statement-offset: 2
697 ## End: