source: trunk/essentials/sys-devel/autoconf/bin/autoreconf.in

Last change on this file was 3095, checked in by bird, 18 years ago

unixroot changes.

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