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

Last change on this file since 3148 was 3147, checked in by bird, 18 years ago

automake 1.10

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