source: trunk/essentials/sys-devel/automake-1.10/aclocal.in@ 3183

Last change on this file since 3183 was 3150, checked in by bird, 18 years ago

Unixroot and the drive letter fix.

File size: 30.6 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# aclocal - create aclocal.m4 by scanning configure.ac
9
10# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
11# 2005, 2006 Free Software Foundation, Inc.
12
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2, or (at your option)
16# any later version.
17
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26# 02110-1301, USA.
27
28# Written by Tom Tromey <tromey@redhat.com>, and
29# Alexandre Duret-Lutz <adl@gnu.org>.
30
31BEGIN
32{
33 my $perllibdir = $ENV{'perllibdir'} || $ENV{'UNIXROOT'}.'@datadir@/@PACKAGE@-@APIVERSION@';
34 $perllibdir =~ s/$ENV{'UNIXROOT'}\/\@unixroot/$ENV{'UNIXROOT'}/; # The EMX built perl doesn't know @unixroot.
35 $perllibdir =~ s/\/\@unixroot/$ENV{'UNIXROOT'}/; # The EMX built perl doesn't know @unixroot.
36 unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
37}
38
39use strict;
40
41use Automake::Config;
42use Automake::General;
43use Automake::Configure_ac;
44use Automake::Channels;
45use Automake::ChannelDefs;
46use Automake::XFile;
47use Automake::FileUtils;
48use File::Basename;
49use File::stat;
50use Cwd;
51
52# Some globals.
53
54# Include paths for searching macros. We search macros in this order:
55# user-supplied directories first, then the directory containing the
56# automake macros, and finally the system-wide directories for
57# third-party macro. @user_includes can be augmented with -I.
58# @system_includes can be augmented with the `dirlist' file. Also
59# --acdir will reset both @automake_includes and @system_includes.
60my @user_includes = ();
61my $my_acdir = $ENV{'UNIXROOT'}.'@datadir@/aclocal';
62$my_acdir =~ s/$ENV{'UNIXROOT'}\/\@unixroot/$ENV{'UNIXROOT'}/; # The EMX built perl doesn't know @unixroot.
63$my_acdir =~ s/\/\@unixroot/$ENV{'UNIXROOT'}/; # The EMX built perl doesn't know @unixroot.
64my @automake_includes = ("$my_acdir-$APIVERSION");
65my @system_includes = ("$my_acdir");
66
67# Whether we should copy M4 file in $user_includes[0].
68my $install = 0;
69
70# --diff
71my @diff_command;
72
73# --dry-run
74my $dry_run = 0;
75
76# configure.ac or configure.in.
77my $configure_ac;
78
79# Output file name.
80my $output_file = 'aclocal.m4';
81
82# Option --force.
83my $force_output = 0;
84
85# Modification time of the youngest dependency.
86my $greatest_mtime = 0;
87
88# Which macros have been seen.
89my %macro_seen = ();
90
91# Remember the order into which we scanned the files.
92# It's important to output the contents of aclocal.m4 in the opposite order.
93# (Definitions in first files we have scanned should override those from
94# later files. So they must appear last in the output.)
95my @file_order = ();
96
97# Map macro names to file names.
98my %map = ();
99
100# Ditto, but records the last definition of each macro as returned by --trace.
101my %map_traced_defs = ();
102
103# Map basenames to macro names.
104my %invmap = ();
105
106# Map file names to file contents.
107my %file_contents = ();
108
109# Map file names to file types.
110my %file_type = ();
111use constant FT_USER => 1;
112use constant FT_AUTOMAKE => 2;
113use constant FT_SYSTEM => 3;
114
115# Map file names to included files (transitively closed).
116my %file_includes = ();
117
118# Files which have already been added.
119my %file_added = ();
120
121# Files that have already been scanned.
122my %scanned_configure_dep = ();
123
124# Serial numbers, for files that have one.
125# The key is the basename of the file,
126# the value is the serial number represented as a list.
127my %serial = ();
128
129# Matches a macro definition.
130# AC_DEFUN([macroname], ...)
131# or
132# AC_DEFUN(macroname, ...)
133# When macroname is `['-quoted , we accept any character in the name,
134# except `]'. Otherwise macroname stops on the first `]', `,', `)',
135# or `\n' encountered.
136my $ac_defun_rx =
137 "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
138
139# Matches an AC_REQUIRE line.
140my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
141
142# Matches an m4_include line.
143my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
144
145# Match a serial number.
146my $serial_line_rx = '^#\s*serial\s+(\S*)';
147my $serial_number_rx = '^\d+(?:\.\d+)*$';
148
149# Autoconf version
150# Set by trace_used_macros.
151my $ac_version;
152
153# If set, names a temporary file that must be erased on abnormal exit.
154my $erase_me;
155
156
157################################################################
158
159# Erase temporary file ERASE_ME.
160sub unlink_tmp
161{
162 if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
163 {
164 fatal "could not remove `$erase_me': $!";
165 }
166 undef $erase_me;
167}
168
169$SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
170END { unlink_tmp }
171
172# Check macros in acinclude.m4. If one is not used, warn.
173sub check_acinclude ()
174{
175 foreach my $key (keys %map)
176 {
177 # FIXME: should print line number of acinclude.m4.
178 msg ('syntax', "warning: macro `$key' defined in "
179 . "acinclude.m4 but never used")
180 if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
181 }
182}
183
184sub reset_maps ()
185{
186 $greatest_mtime = 0;
187 %macro_seen = ();
188 @file_order = ();
189 %map = ();
190 %map_traced_defs = ();
191 %file_contents = ();
192 %file_type = ();
193 %file_includes = ();
194 %file_added = ();
195 %scanned_configure_dep = ();
196 %invmap = ();
197 %serial = ();
198 undef &search;
199}
200
201# install_file ($SRC, $DEST)
202sub install_file ($$)
203{
204 my ($src, $dest) = @_;
205 my $diff_dest;
206
207 if ($force_output
208 || !exists $file_contents{$dest}
209 || $file_contents{$src} ne $file_contents{$dest})
210 {
211 if (-e $dest)
212 {
213 msg 'note', "overwriting `$dest' with `$src'";
214 $diff_dest = $dest;
215 }
216 else
217 {
218 msg 'note', "installing `$dest' from `$src'";
219 }
220
221 if (@diff_command)
222 {
223 if (! defined $diff_dest)
224 {
225 # $dest does not exist. We create an empty one just to
226 # run diff, and we erase it afterward. Using the real
227 # the destination file (rather than a temporary file) is
228 # good when diff is run with options that display the
229 # file name.
230 #
231 # If creating $dest fails, fall back to /dev/null. At
232 # least one diff implementation (Tru64's) cannot deal
233 # with /dev/null. However working around this is not
234 # worth the trouble since nobody run aclocal on a
235 # read-only tree anyway.
236 $erase_me = $dest;
237 my $f = new IO::File "> $dest";
238 if (! defined $f)
239 {
240 undef $erase_me;
241 $diff_dest = '/dev/null';
242 }
243 else
244 {
245 $diff_dest = $dest;
246 $f->close;
247 }
248 }
249 my @cmd = (@diff_command, $diff_dest, $src);
250 $! = 0;
251 verb "running: @cmd";
252 my $res = system (@cmd);
253 Automake::FileUtils::handle_exec_errors "@cmd", 1
254 if $res;
255 unlink_tmp;
256 }
257 elsif (!$dry_run)
258 {
259 xsystem ('cp', $src, $dest);
260 }
261 }
262}
263
264# Compare two lists of numbers.
265sub list_compare (\@\@)
266{
267 my @l = @{$_[0]};
268 my @r = @{$_[1]};
269 while (1)
270 {
271 if (0 == @l)
272 {
273 return (0 == @r) ? 0 : -1;
274 }
275 elsif (0 == @r)
276 {
277 return 1;
278 }
279 elsif ($l[0] < $r[0])
280 {
281 return -1;
282 }
283 elsif ($l[0] > $r[0])
284 {
285 return 1;
286 }
287 shift @l;
288 shift @r;
289 }
290}
291
292################################################################
293
294# scan_m4_dirs($TYPE, @DIRS)
295# --------------------------
296# Scan all M4 files installed in @DIRS for new macro definitions.
297# Register each file as of type $TYPE (one of the FT_* constants).
298sub scan_m4_dirs ($@)
299{
300 my ($type, @dirlist) = @_;
301
302 foreach my $m4dir (@dirlist)
303 {
304 if (! opendir (DIR, $m4dir))
305 {
306 fatal "couldn't open directory `$m4dir': $!";
307 }
308
309 # We reverse the directory contents so that foo2.m4 gets
310 # used in preference to foo1.m4.
311 foreach my $file (reverse sort grep (! /^\./, readdir (DIR)))
312 {
313 # Only examine .m4 files.
314 next unless $file =~ /\.m4$/;
315
316 # Skip some files when running out of srcdir.
317 next if $file eq 'aclocal.m4';
318
319 my $fullfile = File::Spec->canonpath ("$m4dir/$file");
320 &scan_file ($type, $fullfile, 'aclocal');
321 }
322 closedir (DIR);
323 }
324}
325
326# Scan all the installed m4 files and construct a map.
327sub scan_m4_files ()
328{
329 # First, scan configure.ac. It may contain macro definitions,
330 # or may include other files that define macros.
331 &scan_file (FT_USER, $configure_ac, 'aclocal');
332
333 # Then, scan acinclude.m4 if it exists.
334 if (-f 'acinclude.m4')
335 {
336 &scan_file (FT_USER, 'acinclude.m4', 'aclocal');
337 }
338
339 # Finally, scan all files in our search paths.
340 scan_m4_dirs (FT_USER, @user_includes);
341 scan_m4_dirs (FT_AUTOMAKE, @automake_includes);
342 scan_m4_dirs (FT_SYSTEM, @system_includes);
343
344 # Construct a new function that does the searching. We use a
345 # function (instead of just evaluating $search in the loop) so that
346 # "die" is correctly and easily propagated if run.
347 my $search = "sub search {\nmy \$found = 0;\n";
348 foreach my $key (reverse sort keys %map)
349 {
350 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
351 . '"); $found = 1; }' . "\n");
352 }
353 $search .= "return \$found;\n};\n";
354 eval $search;
355 prog_error "$@\n search is $search" if $@;
356}
357
358################################################################
359
360# Add a macro to the output.
361sub add_macro ($)
362{
363 my ($macro) = @_;
364
365 # Ignore unknown required macros. Either they are not really
366 # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
367 # should be quiet, or they are needed and Autoconf itself will
368 # complain when we trace for macro usage later.
369 return unless defined $map{$macro};
370
371 verb "saw macro $macro";
372 $macro_seen{$macro} = 1;
373 &add_file ($map{$macro});
374}
375
376# scan_configure_dep ($file)
377# --------------------------
378# Scan a configure dependency (configure.ac, or separate m4 files)
379# for uses of known macros and AC_REQUIREs of possibly unknown macros.
380# Recursively scan m4_included files.
381sub scan_configure_dep ($)
382{
383 my ($file) = @_;
384 # Do not scan a file twice.
385 return ()
386 if exists $scanned_configure_dep{$file};
387 $scanned_configure_dep{$file} = 1;
388
389 my $mtime = mtime $file;
390 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
391
392 my $contents = exists $file_contents{$file} ?
393 $file_contents{$file} : contents $file;
394
395 my $line = 0;
396 my @rlist = ();
397 my @ilist = ();
398 foreach (split ("\n", $contents))
399 {
400 ++$line;
401 # Remove comments from current line.
402 s/\bdnl\b.*$//;
403 s/\#.*$//;
404 # Avoid running all the following regexes on white lines.
405 next if /^\s*$/;
406
407 while (/$m4_include_rx/go)
408 {
409 my $ifile = $2 || $3;
410 # Skip missing `sinclude'd files.
411 next if $1 ne 'm4_' && ! -f $ifile;
412 push @ilist, $ifile;
413 }
414
415 while (/$ac_require_rx/go)
416 {
417 push (@rlist, $1 || $2);
418 }
419
420 # The search function is constructed dynamically by
421 # scan_m4_files. The last parenthetical match makes sure we
422 # don't match things that look like macro assignments or
423 # AC_SUBSTs.
424 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
425 {
426 # Macro not found, but AM_ prefix found.
427 # Make this just a warning, because we do not know whether
428 # the macro is actually used (it could be called conditionally).
429 msg ('unsupported', "$file:$line",
430 "warning: macro `$2' not found in library");
431 }
432 }
433
434 add_macro ($_) foreach (@rlist);
435 &scan_configure_dep ($_) foreach @ilist;
436}
437
438# add_file ($FILE)
439# ----------------
440# Add $FILE to output.
441sub add_file ($)
442{
443 my ($file) = @_;
444
445 # Only add a file once.
446 return if ($file_added{$file});
447 $file_added{$file} = 1;
448
449 scan_configure_dep $file;
450}
451
452# Point to the documentation for underquoted AC_DEFUN only once.
453my $underquoted_manual_once = 0;
454
455# scan_file ($TYPE, $FILE, $WHERE)
456# --------------------------------
457# Scan a single M4 file ($FILE), and all files it includes.
458# Return the list of included files.
459# $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending
460# on where the file comes from.
461# $WHERE is the location to use in the diagnostic if the file
462# does not exist.
463sub scan_file ($$$)
464{
465 my ($type, $file, $where) = @_;
466 my $basename = basename $file;
467
468 # Do not scan the same file twice.
469 return @{$file_includes{$file}} if exists $file_includes{$file};
470 # Prevent potential infinite recursion (if two files include each other).
471 return () if exists $file_contents{$file};
472
473 unshift @file_order, $file;
474
475 $file_type{$file} = $type;
476
477 fatal "$where: file `$file' does not exist" if ! -e $file;
478
479 my $fh = new Automake::XFile $file;
480 my $contents = '';
481 my @inc_files = ();
482 my %inc_lines = ();
483
484 my $defun_seen = 0;
485 my $serial_seen = 0;
486 my $serial_older = 0;
487
488 while ($_ = $fh->getline)
489 {
490 # Ignore `##' lines.
491 next if /^##/;
492
493 $contents .= $_;
494 my $line = $_;
495
496 if ($line =~ /$serial_line_rx/go)
497 {
498 my $number = $1;
499 if ($number !~ /$serial_number_rx/go)
500 {
501 msg ('syntax', "$file:$.",
502 "warning: ill-formed serial number `$number', "
503 . "expecting a version string with only digits and dots");
504 }
505 elsif ($defun_seen)
506 {
507 # aclocal removes all definitions from M4 file with the
508 # same basename if a greater serial number is found.
509 # Encountering a serial after some macros will undefine
510 # these macros...
511 msg ('syntax', "$file:$.",
512 'the serial number must appear before any macro definition');
513 }
514 # We really care about serials only for non-automake macros
515 # and when --install is used. But the above diagnostics are
516 # made regardless of this, because not using --install is
517 # not a reason not the fix macro files.
518 elsif ($install && $type != FT_AUTOMAKE)
519 {
520 $serial_seen = 1;
521 my @new = split (/\./, $number);
522
523 verb "$file:$.: serial $number";
524
525 if (!exists $serial{$basename}
526 || list_compare (@new, @{$serial{$basename}}) > 0)
527 {
528 # Delete any definition we knew from the old macro.
529 foreach my $def (@{$invmap{$basename}})
530 {
531 verb "$file:$.: ignoring previous definition of $def";
532 delete $map{$def};
533 }
534 $invmap{$basename} = [];
535 $serial{$basename} = \@new;
536 }
537 else
538 {
539 $serial_older = 1;
540 }
541 }
542 }
543
544 # Remove comments from current line.
545 # Do not do it earlier, because the serial line is a comment.
546 $line =~ s/\bdnl\b.*$//;
547 $line =~ s/\#.*$//;
548
549 while ($line =~ /$ac_defun_rx/go)
550 {
551 $defun_seen = 1;
552 if (! defined $1)
553 {
554 msg ('syntax', "$file:$.", "warning: underquoted definition of $2"
555 . "\n run info '(automake)Extending aclocal'\n"
556 . " or see http://sources.redhat.com/automake/"
557 . "automake.html#Extending-aclocal")
558 unless $underquoted_manual_once;
559 $underquoted_manual_once = 1;
560 }
561
562 # If this macro does not have a serial and we have already
563 # seen a macro with the same basename earlier, we should
564 # ignore the macro (don't exit immediately so we can still
565 # diagnose later #serial numbers and underquoted macros).
566 $serial_older ||= ($type != FT_AUTOMAKE
567 && !$serial_seen && exists $serial{$basename});
568
569 my $macro = $1 || $2;
570 if (!$serial_older && !defined $map{$macro})
571 {
572 verb "found macro $macro in $file: $.";
573 $map{$macro} = $file;
574 push @{$invmap{$basename}}, $macro;
575 }
576 else
577 {
578 # Note: we used to give an error here if we saw a
579 # duplicated macro. However, this turns out to be
580 # extremely unpopular. It causes actual problems which
581 # are hard to work around, especially when you must
582 # mix-and-match tool versions.
583 verb "ignoring macro $macro in $file: $.";
584 }
585 }
586
587 while ($line =~ /$m4_include_rx/go)
588 {
589 my $ifile = $2 || $3;
590 # Skip missing `sinclude'd files.
591 next if $1 ne 'm4_' && ! -f $ifile;
592 push (@inc_files, $ifile);
593 $inc_lines{$ifile} = $.;
594 }
595 }
596
597 # Ignore any file that has an old serial (or no serial if we know
598 # another one with a serial).
599 return ()
600 if ($serial_older ||
601 ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
602
603 $file_contents{$file} = $contents;
604
605 # For some reason I don't understand, it does not work
606 # to do `map { scan_file ($_, ...) } @inc_files' below.
607 # With Perl 5.8.2 it undefines @inc_files.
608 my @copy = @inc_files;
609 my @all_inc_files = (@inc_files,
610 map { scan_file ($type, $_,
611 "$file:$inc_lines{$_}") } @copy);
612 $file_includes{$file} = \@all_inc_files;
613 return @all_inc_files;
614}
615
616# strip_redundant_includes (%FILES)
617# ---------------------------------
618# Each key in %FILES is a file that must be present in the output.
619# However some of these files might already include other files in %FILES,
620# so there is no point in including them another time.
621# This removes items of %FILES which are already included by another file.
622sub strip_redundant_includes (%)
623{
624 my %files = @_;
625
626 # Always include acinclude.m4, even if it does not appear to be used.
627 $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
628 # File included by $configure_ac are redundant.
629 $files{$configure_ac} = 1;
630
631 # Files at the end of @file_order should override those at the beginning,
632 # so it is important to preserve these trailing files. We can remove
633 # a file A if it is going to be output before a file B that includes
634 # file A, not the converse.
635 foreach my $file (reverse @file_order)
636 {
637 next unless exists $files{$file};
638 foreach my $ifile (@{$file_includes{$file}})
639 {
640 next unless exists $files{$ifile};
641 delete $files{$ifile};
642 verb "$ifile is already included by $file";
643 }
644 }
645
646 # configure.ac is implicitly included.
647 delete $files{$configure_ac};
648
649 return %files;
650}
651
652sub trace_used_macros ()
653{
654 my %files = map { $map{$_} => 1 } keys %macro_seen;
655 %files = strip_redundant_includes %files;
656
657 my $traces = ($ENV{AUTOM4TE} || 'autom4te');
658 $traces .= " --language Autoconf-without-aclocal-m4 ";
659 # All candidate files.
660 $traces .= join (' ', grep { exists $files{$_} } @file_order) . " ";
661 # All candidate macros.
662 $traces .= join (' ',
663 (map { "--trace='$_:\$f::\$n::\$1'" }
664 ('AC_DEFUN',
665 'AC_DEFUN_ONCE',
666 'AU_DEFUN',
667 '_AM_AUTOCONF_VERSION')),
668 # Do not trace $1 for all other macros as we do
669 # not need it and it might contains harmful
670 # characters (like newlines).
671 (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
672
673 verb "running $traces $configure_ac";
674
675 my $tracefh = new Automake::XFile ("$traces $configure_ac |");
676
677 my %traced = ();
678
679 while ($_ = $tracefh->getline)
680 {
681 chomp;
682 # Stupid, stupid unix guys.
683 #my ($file, $macro, $arg1) = split (/:/);
684 my ($file, $macro, $arg1, $dos) = split (/:/);
685 if (length($file) == 1 && $dos ne '')
686 {
687 $file = $file.":".$macro;
688 $macro = $arg1;
689 $arg1 = $dos;
690 }
691
692 $traced{$macro} = 1 if exists $macro_seen{$macro};
693
694 $map_traced_defs{$arg1} = $file
695 if ($macro eq 'AC_DEFUN'
696 || $macro eq 'AC_DEFUN_ONCE'
697 || $macro eq 'AU_DEFUN');
698
699 $ac_version = $arg1 if $macro eq '_AM_AUTOCONF_VERSION';
700 }
701
702 $tracefh->close;
703
704 return %traced;
705}
706
707sub scan_configure ()
708{
709 # Make sure we include acinclude.m4 if it exists.
710 if (-f 'acinclude.m4')
711 {
712 add_file ('acinclude.m4');
713 }
714 scan_configure_dep ($configure_ac);
715}
716
717################################################################
718
719# Write output.
720# Return 0 iff some files were installed locally.
721sub write_aclocal ($@)
722{
723 my ($output_file, @macros) = @_;
724 my $output = '';
725
726 my %files = ();
727 # Get the list of files containing definitions for the macros used.
728 # (Filter out unused macro definitions with $map_traced_defs. This
729 # can happen when an Autoconf macro is conditionally defined:
730 # aclocal sees the potential definition, but this definition is
731 # actually never processed and the Autoconf implementation is used
732 # instead.)
733 for my $m (@macros)
734 {
735 $files{$map{$m}} = 1
736 if (exists $map_traced_defs{$m}
737 && $map{$m} eq $map_traced_defs{$m});
738 }
739 # Do not explicitly include a file that is already indirectly included.
740 %files = strip_redundant_includes %files;
741
742 my $installed = 0;
743
744 for my $file (grep { exists $files{$_} } @file_order)
745 {
746 # Check the time stamp of this file, and of all files it includes.
747 for my $ifile ($file, @{$file_includes{$file}})
748 {
749 my $mtime = mtime $ifile;
750 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
751 }
752
753 # If the file to add looks like outside the project, copy it
754 # to the output. The regex catches filenames starting with
755 # things like `/', `\', or `c:\'.
756 if ($file_type{$file} != FT_USER
757 || $file =~ m,^(?:\w:)?[\\/],)
758 {
759 if (!$install || $file_type{$file} != FT_SYSTEM)
760 {
761 # Copy the file into aclocal.m4.
762 $output .= $file_contents{$file} . "\n";
763 }
764 else
765 {
766 # Install the file (and any file it includes).
767 my $dest;
768 for my $ifile (@{$file_includes{$file}}, $file)
769 {
770 $dest = "$user_includes[0]/" . basename $ifile;
771 verb "installing $ifile to $dest";
772 install_file ($ifile, $dest);
773 }
774 $installed = 1;
775 }
776 }
777 else
778 {
779 # Otherwise, simply include the file.
780 $output .= "m4_include([$file])\n";
781 }
782 }
783
784 if ($installed)
785 {
786 verb "running aclocal anew, because some files were installed locally";
787 return 0;
788 }
789
790 # Nothing to output?!
791 # FIXME: Shouldn't we diagnose this?
792 return 1 if ! length ($output);
793
794 if ($ac_version)
795 {
796 # Do not use "$output_file" here for the same reason we do not
797 # use it in the header below. autom4te will output the name of
798 # the file in the diagnostic anyway.
799 $output = "m4_if(m4_PACKAGE_VERSION, [$ac_version],,
800[m4_fatal([this file was generated for autoconf $ac_version.
801You have another version of autoconf. If you want to use that,
802you should regenerate the build system entirely.], [63])])
803
804$output";
805 }
806
807 # We used to print `# $output_file generated automatically etc.' But
808 # this creates spurious differences when using autoreconf. Autoreconf
809 # creates aclocal.m4t and then rename it to aclocal.m4, but the
810 # rebuild rules generated by Automake create aclocal.m4 directly --
811 # this would gives two ways to get the same file, with a different
812 # name in the header.
813 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
814
815# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
816# 2005, 2006 Free Software Foundation, Inc.
817# This file is free software; the Free Software Foundation
818# gives unlimited permission to copy and/or distribute it,
819# with or without modifications, as long as this notice is preserved.
820
821# This program is distributed in the hope that it will be useful,
822# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
823# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
824# PARTICULAR PURPOSE.
825
826$output";
827
828 # We try not to update $output_file unless necessary, because
829 # doing so invalidate Autom4te's cache and therefore slows down
830 # tools called after aclocal.
831 #
832 # We need to overwrite $output_file in the following situations.
833 # * The --force option is in use.
834 # * One of the dependencies is younger.
835 # (Not updating $output_file in this situation would cause
836 # make to call aclocal in loop.)
837 # * The contents of the current file are different from what
838 # we have computed.
839 if (!$force_output
840 && $greatest_mtime < mtime ($output_file)
841 && $output eq contents ($output_file))
842 {
843 verb "$output_file unchanged";
844 return 1;
845 }
846
847 verb "writing $output_file";
848
849 if (!$dry_run)
850 {
851 if (-e $output_file && !unlink $output_file)
852 {
853 fatal "could not remove `$output_file': $!";
854 }
855 my $out = new Automake::XFile "> $output_file";
856 print $out $output;
857 }
858 return 1;
859}
860
861################################################################
862
863# Print usage and exit.
864sub usage ($)
865{
866 my ($status) = @_;
867
868 print "Usage: aclocal [OPTIONS] ...
869
870Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
871
872Options:
873 --acdir=DIR directory holding config files (for debugging)
874 --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be
875 changed (implies --install and --dry-run)
876 --dry-run pretend to, but do not actually update any file
877 --force always update output file
878 --help print this help, then exit
879 -I DIR add directory to search list for .m4 files
880 --install copy third-party files to the first -I directory
881 --output=FILE put output in FILE (default aclocal.m4)
882 --print-ac-dir print name of directory holding m4 files, then exit
883 --verbose don't be silent
884 --version print version number, then exit
885 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
886
887Warning categories include:
888 `syntax' dubious syntactic constructs (default)
889 `unsupported' unknown macros (default)
890 `all' all the warnings (default)
891 `no-CATEGORY' turn off warnings in CATEGORY
892 `none' turn off all the warnings
893 `error' treat warnings as errors
894
895Report bugs to <bug-automake\@gnu.org>.\n";
896
897 exit $status;
898}
899
900# Print version and exit.
901sub version()
902{
903 print <<EOF;
904aclocal (GNU $PACKAGE) $VERSION
905Written by Tom Tromey <tromey\@redhat.com>
906 and Alexandre Duret-Lutz <adl\@gnu.org>.
907
908Copyright (C) 2006 Free Software Foundation, Inc.
909This is free software; see the source for copying conditions. There is NO
910warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
911EOF
912 exit 0;
913}
914
915# Parse command line.
916sub parse_arguments ()
917{
918 my $print_and_exit = 0;
919 my $diff_command;
920
921 my %cli_options =
922 (
923 'acdir=s' => sub # Setting --acdir overrides both the
924 { # automake (versioned) directory and the
925 # public (unversioned) system directory.
926 @automake_includes = ();
927 @system_includes = ($_[1])
928 },
929 'diff:s' => \$diff_command,
930 'dry-run' => \$dry_run,
931 'force' => \$force_output,
932 'I=s' => \@user_includes,
933 'install' => \$install,
934 'output=s' => \$output_file,
935 'print-ac-dir' => \$print_and_exit,
936 'verbose' => sub { setup_channel 'verb', silent => 0; },
937 'W|warnings=s' => \&parse_warnings,
938 );
939 use Getopt::Long;
940 Getopt::Long::config ("bundling", "pass_through");
941
942 # See if --version or --help is used. We want to process these before
943 # anything else because the GNU Coding Standards require us to
944 # `exit 0' after processing these options, and we can't guarantee this
945 # if we treat other options first. (Handling other options first
946 # could produce error diagnostics, and in this condition it is
947 # confusing if aclocal does `exit 0'.)
948 my %cli_options_1st_pass =
949 (
950 'version' => \&version,
951 'help' => sub { usage(0); },
952 # Recognize all other options (and their arguments) but do nothing.
953 map { $_ => sub {} } (keys %cli_options)
954 );
955 my @ARGV_backup = @ARGV;
956 Getopt::Long::GetOptions %cli_options_1st_pass
957 or exit 1;
958 @ARGV = @ARGV_backup;
959
960 # Now *really* process the options. This time we know that --help
961 # and --version are not present, but we specify them nonetheless so
962 # that ambiguous abbreviation are diagnosed.
963 Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {}
964 or exit 1;
965
966 if (@ARGV)
967 {
968 my %argopts;
969 for my $k (keys %cli_options)
970 {
971 if ($k =~ /(.*)=s$/)
972 {
973 map { $argopts{(length ($_) == 1)
974 ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
975 }
976 }
977 if (exists $argopts{$ARGV[0]})
978 {
979 fatal ("option `$ARGV[0]' requires an argument\n"
980 . "Try `$0 --help' for more information.");
981 }
982 else
983 {
984 fatal ("unrecognized option `$ARGV[0]'\n"
985 . "Try `$0 --help' for more information.");
986 }
987 }
988
989 if ($print_and_exit)
990 {
991 print "@system_includes\n";
992 exit 0;
993 }
994
995 if (defined $diff_command)
996 {
997 $diff_command = 'diff -u' if $diff_command eq '';
998 @diff_command = split (' ', $diff_command);
999 $install = 1;
1000 $dry_run = 1;
1001 }
1002
1003 if ($install && !@user_includes)
1004 {
1005 fatal ("--install should copy macros in the directory indicated by the"
1006 . "\nfirst -I option, but no -I was supplied.");
1007 }
1008
1009 if (! -d $system_includes[0])
1010 {
1011 # By default $(datadir)/aclocal doesn't exist. We don't want to
1012 # get an error in the case where we are searching the default
1013 # directory and it hasn't been created. (We know
1014 # @system_includes has its default value if @automake_includes
1015 # is not empty, because --acdir is the only way to change this.)
1016 @system_includes = () if @automake_includes;
1017 }
1018 else
1019 {
1020 # Finally, adds any directory listed in the `dirlist' file.
1021 if (open (DIRLIST, "$system_includes[0]/dirlist"))
1022 {
1023 while (<DIRLIST>)
1024 {
1025 # Ignore '#' lines.
1026 next if /^#/;
1027 # strip off newlines and end-of-line comments
1028 s/\s*\#.*$//;
1029 chomp;
1030 foreach my $dir (glob)
1031 {
1032 push (@system_includes, $dir) if -d $dir;
1033 }
1034 }
1035 close (DIRLIST);
1036 }
1037 }
1038}
1039
1040################################################################
1041
1042parse_WARNINGS; # Parse the WARNINGS environment variable.
1043parse_arguments;
1044$configure_ac = require_configure_ac;
1045
1046# We may have to rerun aclocal if some file have been installed, but
1047# it should not happen more than once. The reason we must run again
1048# is that once the file has been moved from /usr/share/aclocal/ to the
1049# local m4/ directory it appears at a new place in the search path,
1050# hence it should be output at a different position in aclocal.m4. If
1051# we did not rerun aclocal, the next run of aclocal would produce a
1052# different aclocal.m4.
1053my $loop = 0;
1054while (1)
1055 {
1056 ++$loop;
1057 prog_error "Too many loops." if $loop > 2;
1058
1059 reset_maps;
1060 scan_m4_files;
1061 scan_configure;
1062 last if $exit_code;
1063 my %macro_traced = trace_used_macros;
1064 last if write_aclocal ($output_file, keys %macro_traced);
1065 last if $dry_run;
1066 }
1067check_acinclude;
1068
1069exit $exit_code;
1070
1071### Setup "GNU" style for perl-mode and cperl-mode.
1072## Local Variables:
1073## perl-indent-level: 2
1074## perl-continued-statement-offset: 2
1075## perl-continued-brace-offset: 0
1076## perl-brace-offset: 0
1077## perl-brace-imaginary-offset: 0
1078## perl-label-offset: -2
1079## cperl-indent-level: 2
1080## cperl-brace-offset: 0
1081## cperl-continued-brace-offset: 0
1082## cperl-label-offset: -2
1083## cperl-extra-newline-before-brace: t
1084## cperl-merge-trailing-else: nil
1085## cperl-continued-statement-offset: 2
1086## End:
Note: See TracBrowser for help on using the repository browser.