Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / bin / autoreconf
blob767ba7fcbc3303ec95e5ecbbab3a5b69ac036c9b
1 #! /bin/perl -w
2 # -*- perl -*-
3 # @configure_input@
5 eval 'case $# in 0) exec /bin/perl -S "$0";; *) exec /bin/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 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 2, or (at your option)
14 # 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, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 # 02111-1307, USA.
26 # Written by David J. MacKenzie.
27 # Extended and rewritten in Perl by Akim Demaille.
29 BEGIN
31 my $perllibdir = $ENV{'autom4te_perllibdir'} || '/usr/share/autoconf';
32 unshift @INC, "$perllibdir";
35 use Autom4te::General;
36 use Autom4te::XFile;
37 # Do not use Cwd::chdir, since it might hang.
38 use Cwd 'cwd';
39 use strict;
41 ## ----------- ##
42 ## Variables. ##
43 ## ----------- ##
45 # $HELP
46 # -----
47 $help = "Usage: $0 [OPTION] ... [CONFIGURE-AC or DIRECTORY] ...
49 Run `autoconf' (and `autoheader', `aclocal', `automake', `autopoint'
50 (formerly `gettextize'), and `libtoolize' where appropriate)
51 repeatedly to remake the GNU Build System files in the DIRECTORIES or
52 the directory trees driven by CONFIGURE-AC (defaulting to `.').
54 By default, it only remakes those files that are older than their
55 predecessors. If you install new versions of the GNU Build System,
56 running `autoreconf' remakes all of the files by giving it the
57 `--force' option.
59 Operation modes:
60 -h, --help print this help, then exit
61 -V, --version print version number, then exit
62 -v, --verbose verbosely report processing
63 -d, --debug don't remove temporary files
64 -f, --force consider all files obsolete
65 -i, --install copy missing auxiliary files
66 -s, --symlink with -i, install symbolic links instead of copies
67 -m, --make when applicable, re-run ./configure && make
68 -W, --warnings=CATEGORY report the warnings falling in CATEGORY [syntax]
70 Warning categories include:
71 \`cross\' cross compilation issues
72 \`obsolete\' obsolete constructs
73 \`portability\' portability issues
74 \`syntax\' dubious syntactic constructs
75 \`all\' all the warnings
76 \`no-CATEGORY\' turn off the warnings on CATEGORY
77 \`none\' turn off all the warnings
78 \`error\' warnings are error
80 The environment variable \`WARNINGS\' is honored. Some subtools might
81 support other warning types, using \`all' is encouraged.
83 Library directories:
84 -B, --prepend-include=DIR prepend directory DIR to search path
85 -I, --include=DIR append directory DIR to search path
87 The environment variables AUTOCONF, AUTOHEADER, AUTOMAKE, ACLOCAL,
88 AUTOPOINT, LIBTOOLIZE are honored.
90 Report bugs to <bug-autoconf\@gnu.org>.
93 # $VERSION
94 # --------
95 $version = "autoreconf (GNU Autoconf) 2.56
96 Written by David J. MacKenzie and Akim Demaille.
98 Copyright 2002 Free Software Foundation, Inc.
99 This is free software; see the source for copying conditions. There is NO
100 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
103 # Lib files.
104 my $autoconf = $ENV{'AUTOCONF'} || '/usr/bin/autoconf';
105 my $autoheader = $ENV{'AUTOHEADER'} || '/usr/bin/autoheader';
106 my $automake = $ENV{'AUTOMAKE'} || 'automake';
107 my $aclocal = $ENV{'ACLOCAL'} || 'aclocal';
108 my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
109 my $autopoint = $ENV{'AUTOPOINT'} || 'autopoint';
111 # --install -- as --add-missing in other tools.
112 my $install = 0;
113 # symlink -- when --install, use symlinks instead.
114 my $symlink = 0;
116 my @prepend_include;
117 my @include;
119 # List of warnings.
120 my @warning;
122 # Rerun `./configure && make'?
123 my $make = 0;
125 ## ---------- ##
126 ## Routines. ##
127 ## ---------- ##
130 # parse_args ()
131 # -------------
132 # Process any command line arguments.
133 sub parse_args ()
135 my $srcdir;
137 getopt ("W|warnings=s" => \@warning,
138 'I|include=s' => \@include,
139 'B|prepend-include=s' => \@prepend_include,
140 'i|install' => \$install,
141 's|symlink' => \$symlink,
142 'm|make' => \$make);
144 # Split the warnings as a list of elements instead of a list of
145 # lists.
146 @warning = map { split /,/ } @warning;
148 # Even if the user specified a configure.ac, trim to get the
149 # directory, and look for configure.ac again. Because (i) the code
150 # is simpler, and (ii) we are still able to diagnose simultaneous
151 # presence of configure.ac and configure.in.
152 @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
153 push @ARGV, '.' unless @ARGV;
155 if ($verbose && $debug)
157 for my $prog ($autoconf, $autoheader,
158 $automake, $aclocal,
159 $autopoint,
160 $libtoolize)
162 xsystem ("$prog --version | sed 1q >&2");
163 print STDERR "\n";
167 # Dispatch autoreconf's option to the tools.
168 # --include;
169 $autoconf .= join (' --include=', '', @include);
170 $autoconf .= join (' --prepend-include=', '', @prepend_include);
171 $autoheader .= join (' --include=', '', @include);
172 $autoheader .= join (' --prepend-include=', '', @prepend_include);
174 # --install and --symlink;
175 if ($install)
177 $automake .= ' --add-missing';
178 $automake .= ' --copy' unless $symlink;
179 $libtoolize .= ' --copy' unless $symlink;
181 # --force;
182 if ($force)
184 $autoconf .= ' --force';
185 $autoheader .= ' --force';
186 $automake .= ' --force-missing';
187 $autopoint .= ' --force';
188 $libtoolize .= ' --force';
190 else
192 $automake .= ' --no-force';
194 # --debug;
195 if ($debug)
197 $autoconf .= ' --verbose --debug';
198 $autoheader .= ' --verbose --debug';
199 $automake .= ' --verbose';
200 $aclocal .= ' --verbose';
201 $libtoolize .= ' --debug';
203 # --warnings;
204 if (@warning)
206 $autoconf .= ' --warnings=' . join (',', @warning);
207 $autoheader .= ' --warnings=' . join (',', @warning);
208 $automake .= ' --warnings=' . join (',', @warning)
209 if `$automake --help` =~ /--warnings/;
214 # &autoreconf_current_directory
215 # -----------------------------
216 sub autoreconf_current_directory ()
218 my $configure_ac = find_configure_ac;
219 error "cannot find `configure.ac'"
220 unless $configure_ac;
222 # ---------------------- #
223 # Is it using Autoconf? #
224 # ---------------------- #
226 my $uses_autoconf;
227 my $uses_gettext;
228 my $configure_ac_file = new Autom4te::XFile $configure_ac;
229 while ($_ = $configure_ac_file->getline)
231 s/#.*//;
232 s/dnl.*//;
233 $uses_autoconf = 1 if /AC_INIT/;
234 # See below for why we look for gettext here.
235 $uses_gettext = 1 if /^AM_GNU_GETTEXT_VERSION/;
238 if (!$uses_autoconf)
240 verbose "$configure_ac: not using Autoconf";
241 return;
245 # ------------------- #
246 # Running autopoint. #
247 # ------------------- #
249 # Gettext is a bit of a problem: its macros are not necessarily
250 # visible to aclocal, so if we start with a completely striped down
251 # package (think of a fresh CVS checkout), running `aclocal' first
252 # will fail: the Gettext macros are missing.
254 # Therefore, we can't use the traces to decide if we use Gettext or
255 # not. I guess that once Gettext move to 2.5x we will be able to,
256 # but in the meanwhile forget it.
258 # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac. You
259 # might think this approach is naive, and indeed it is, as it
260 # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
261 # anyway we don't limit the generality, since... that's what
262 # autopoint does. Actually, it is even more restrictive, as it
263 # greps for `^AM_GNU_GETTEXT_VERSION('. We did this above, while
264 # scanning configure.ac.
265 if (!$uses_gettext)
267 verbose "$configure_ac: not using Gettext";
269 elsif (!$install)
271 verbose "$configure_ac: not running autopoint: --install not given";
273 else
275 xsystem "$autopoint";
279 # ----------------- #
280 # Running aclocal. #
281 # ----------------- #
283 # Run it first: it might discover new macros to add, e.g.,
284 # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
285 # used.
287 # Always run it. Tracking its sources for up-to-dateness is too
288 # complex and too error prone. The best we can do is avoiding
289 # nuking the time stamp.
290 my $uses_aclocal = 1;
292 # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
293 # don't run aclocal.
295 if (-f 'aclocal.m4')
297 my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
298 $_ = $aclocal_m4->getline;
299 $uses_aclocal = 0
300 unless /generated.*by aclocal/;
303 # If there are flags for aclocal in Makefile.am, use them.
304 my $aclocal_flags = '';
305 if ($uses_aclocal && -f 'Makefile.am')
307 my $makefile = new Autom4te::XFile 'Makefile.am';
308 while ($_ = $makefile->getline)
310 if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
312 $aclocal_flags = $1;
313 last;
318 if (!$uses_aclocal)
320 verbose "$configure_ac: not using aclocal";
322 else
324 # Some filesystems have sub-second time stamps, and if so we may
325 # run into trouble later, after we rerun autoconf and set the
326 # time stamps of input files to be no greater than aclocal.m4,
327 # because the time-stamp-setting operation (utime) has a
328 # resolution of only 1 second. Work around the problem by
329 # ensuring that there is at least a one-second window before the
330 # time stamp of aclocal.m4t in which no file time stamps can
331 # fall.
332 sleep 1;
334 xsystem ("$aclocal $aclocal_flags --output=aclocal.m4t");
335 # aclocal may produce no output.
336 update_file ('aclocal.m4t', 'aclocal.m4')
337 if -f 'aclocal.m4t';
340 # We might have to rerun aclocal if Libtool (or others) imports new
341 # macros.
342 my $rerun_aclocal = 0;
346 # ------------------------------- #
347 # See what tools will be needed. #
348 # ------------------------------- #
350 # Perform a single trace reading to avoid --force forcing a rerun
351 # between two --trace, that's useless. If there is no AC_INIT, then
352 # we are not interested: it looks like a Cygnus thingy.
353 my $uses_gettext_via_traces;
354 my $uses_libtool;
355 my $uses_autoheader;
356 my @subdir;
357 verbose "$configure_ac: tracing";
358 my $traces = new Autom4te::XFile
359 ("$autoconf"
360 . join (' --trace=', '',
361 # If you change this list, update the
362 # `Autoreconf-preselections' section of autom4te.in.
363 'AC_CONFIG_HEADERS',
364 'AC_CONFIG_SUBDIRS:AC_CONFIG_SUBDIRS:\$1',
365 'AC_INIT',
366 'AC_PROG_LIBTOOL',
367 'AM_GNU_GETTEXT',
369 . ' |');
370 while ($_ = $traces->getline)
372 $uses_autoconf = 1 if /AC_INIT/;
373 $uses_gettext_via_traces = 1 if /AM_GNU_GETTEXT/;
374 $uses_libtool = 1 if /AC_PROG_LIBTOOL/;
375 $uses_autoheader = 1 if /AC_CONFIG_HEADERS/;
376 push @subdir, split (' ', $1) if /AC_CONFIG_SUBDIRS:(.*)/;
379 # The subdirs are *optional*, they may not exist.
380 foreach (@subdir)
382 if (-d)
384 verbose "$configure_ac: subdirectory $_ to autoreconf";
385 autoreconf ($_);
387 else
389 verbose "$configure_ac: subdirectory $_ not present";
393 # Gettext consistency checks...
394 error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
395 if $uses_gettext_via_traces && ! $uses_gettext;
396 error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
397 if $uses_gettext && ! $uses_gettext_via_traces;
400 # -------------------- #
401 # Running libtoolize. #
402 # -------------------- #
404 if (!$uses_libtool)
406 verbose "$configure_ac: not using Libtool";
408 elsif ($install)
410 xsystem ($libtoolize);
411 $rerun_aclocal = 1;
413 else
415 verbose "$configure_ac: not running libtoolize: --install not given";
420 # ------------------- #
421 # Rerunning aclocal. #
422 # ------------------- #
424 # If we re-installed Libtool or Gettext, the macros might have changed.
425 # Automake also needs an up-to-date aclocal.m4.
426 if ($rerun_aclocal)
428 if (!$uses_aclocal)
430 verbose "$configure_ac: not using aclocal";
432 else
434 xsystem ("$aclocal $aclocal_flags --output=aclocal.m4t");
435 # aclocal may produce no output.
436 if (-f 'aclocal.m4t')
438 update_file ('aclocal.m4t', 'aclocal.m4');
439 # Make sure that the local m4 files are older than
440 # aclocal.m4.
442 # Why is not always the case? Because we already run
443 # aclocal at first (before tracing), which, for instance,
444 # can find Gettext's macros in .../share/aclocal, so we
445 # may have had the right aclocal.m4 already. Then
446 # autopoint is run, and installs locally these M4
447 # files. Then autoreconf, via update_file, sees it is
448 # the _same_ aclocal.m4, and doesn't change its
449 # timestamp. But later, Automake's Makefile expresses
450 # that aclocal.m4 depends on these local files, which
451 # are newer, so it triggers aclocal again.
453 # To make sure aclocal.m4 is no older, we change the
454 # modification times of the local M4 files to be
455 # not newer than it.
457 # First, where are the local files?
458 my $aclocal_local_dir = '.';
459 if ($aclocal_flags =~ /-I\s+(\S+)/)
461 $aclocal_local_dir = $1;
463 # All the local files newer than aclocal.m4 are to be
464 # made not newer than it.
465 my $aclocal_m4_mtime = mtime ('aclocal.m4');
466 for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
468 if ($aclocal_m4_mtime < mtime ($file))
470 debug "aging $file to be not newer than aclocal.m4";
471 utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
479 # ------------------ #
480 # Running autoconf. #
481 # ------------------ #
483 # Don't try to be smarter than `autoconf', which does its own up to
484 # date checks.
486 # We prefer running autoconf before autoheader, because (i) the
487 # latter runs the former, and (ii) autoconf is stricter than
488 # autoheader. So all in all, autoconf should give better error
489 # messages.
490 xsystem ($autoconf);
493 # -------------------- #
494 # Running autoheader. #
495 # -------------------- #
497 # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
498 # is used too.
500 # Just as for autoconf, up to date ness is performed by the tool
501 # itself.
503 # Run it before automake, since the latter checks the presence of
504 # config.h.in when it sees an AC_CONFIG_HEADERS.
505 if (!$uses_autoheader)
507 verbose "$configure_ac: not using Autoheader";
509 else
511 xsystem ($autoheader);
515 # ------------------ #
516 # Running automake. #
517 # ------------------ #
519 # Assumes that there is a Makefile.am in the topmost directory.
520 if (!-f 'Makefile.am')
522 verbose "$configure_ac: not using Automake";
524 else
526 # We should always run automake, and let it decide whether it shall
527 # update the file or not. In fact, the effect of `$force' is already
528 # included in `$automake' via `--no-force'.
529 xsystem ($automake);
533 # -------------- #
534 # Running make. #
535 # -------------- #
537 if ($make)
539 if (!-f "config.status")
541 verbose "no config.status: cannot re-make";
543 else
545 xsystem ("./config.status --recheck");
546 xsystem ("./config.status");
547 if (!-f "Makefile")
549 verbose "no Makefile: cannot re-make";
551 else
553 xsystem ("make");
560 # &autoreconf ($DIRECTORY)
561 # ------------------------
562 # Reconf the $DIRECTORY.
563 sub autoreconf ($)
565 my ($directory) = @_;
566 my $cwd = cwd;
568 # The format for this message is not free: taken from Emacs, itself
569 # using GNU Make's format.
570 verbose "Entering directory `$directory'";
571 chdir $directory
572 or error "cannot chdir to $directory: $!";
574 autoreconf_current_directory;
576 # The format is not free: taken from Emacs, itself using GNU Make's
577 # format.
578 verbose "Leaving directory `$directory'";
579 chdir $cwd
580 or error "cannot chdir to $cwd: $!";
584 ## ------ ##
585 ## Main. ##
586 ## ------ ##
588 # When debugging, it is convenient that all the related temporary
589 # files be at the same place.
590 mktmpdir ('ar');
591 $ENV{'TMPDIR'} = $tmp;
592 parse_args;
594 # Autoreconf all the given configure.ac. A while loop, not a for,
595 # since the list can change at runtime because of AC_CONFIG_SUBDIRS.
596 for my $directory (@ARGV)
598 autoreconf ($directory);
601 ### Setup "GNU" style for perl-mode and cperl-mode.
602 ## Local Variables:
603 ## perl-indent-level: 2
604 ## perl-continued-statement-offset: 2
605 ## perl-continued-brace-offset: 0
606 ## perl-brace-offset: 0
607 ## perl-brace-imaginary-offset: 0
608 ## perl-label-offset: -2
609 ## cperl-indent-level: 2
610 ## cperl-brace-offset: 0
611 ## cperl-continued-brace-offset: 0
612 ## cperl-label-offset: -2
613 ## cperl-extra-newline-before-brace: t
614 ## cperl-merge-trailing-else: nil
615 ## cperl-continued-statement-offset: 2
616 ## End: