5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # aclocal - create aclocal.m4 by scanning configure.ac
10 # Copyright (C) 1996-2013 Free Software Foundation, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # Written by Tom Tromey <tromey@redhat.com>, and
26 # Alexandre Duret-Lutz <adl@gnu.org>.
30 @Aclocal::perl_libdirs = ('@datadir@/@PACKAGE@-@APIVERSION@')
31 unless @Aclocal::perl_libdirs;
32 unshift @INC, @Aclocal::perl_libdirs;
38 use Automake::General;
39 use Automake::Configure_ac;
40 use Automake::Channels;
41 use Automake::ChannelDefs;
43 use Automake::FileUtils;
49 # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
50 # FIXME: To be removed in Automake 2.0, once we can assume autoconf
52 # FIXME: keep in sync with 'internal/ac-config-macro-dirs.m4'.
53 my $ac_config_macro_dirs_fallback =
54 'm4_ifndef([AC_CONFIG_MACRO_DIRS], [' .
55 'm4_defun([_AM_CONFIG_MACRO_DIRS], [])' .
56 'm4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])' .
59 # We do not operate in threaded mode.
62 # Include paths for searching macros. We search macros in this order:
63 # user-supplied directories first, then the directory containing the
64 # automake macros, and finally the system-wide directories for
66 # @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIRS.
67 # @automake_includes can be reset with the '--automake-acdir' option.
68 # @system_includes can be augmented with the 'dirlist' file or the
69 # ACLOCAL_PATH environment variable, and reset with the '--system-acdir'
71 my @user_includes = ();
72 my @automake_includes = ("@datadir@/aclocal-$APIVERSION");
73 my @system_includes = ('@datadir@/aclocal');
75 # Whether we should copy M4 file in $user_includes[0].
84 # configure.ac or configure.in.
88 my $output_file = 'aclocal.m4';
93 # Modification time of the youngest dependency.
94 my $greatest_mtime = 0;
96 # Which macros have been seen.
99 # Remember the order into which we scanned the files.
100 # It's important to output the contents of aclocal.m4 in the opposite order.
101 # (Definitions in first files we have scanned should override those from
102 # later files. So they must appear last in the output.)
105 # Map macro names to file names.
108 # Ditto, but records the last definition of each macro as returned by --trace.
109 my %map_traced_defs = ();
111 # Map basenames to macro names.
114 # Map file names to file contents.
115 my %file_contents = ();
117 # Map file names to file types.
119 use constant FT_USER => 1;
120 use constant FT_AUTOMAKE => 2;
121 use constant FT_SYSTEM => 3;
123 # Map file names to included files (transitively closed).
124 my %file_includes = ();
126 # Files which have already been added.
129 # Files that have already been scanned.
130 my %scanned_configure_dep = ();
132 # Serial numbers, for files that have one.
133 # The key is the basename of the file,
134 # the value is the serial number represented as a list.
137 # Matches a macro definition.
138 # AC_DEFUN([macroname], ...)
140 # AC_DEFUN(macroname, ...)
141 # When macroname is '['-quoted , we accept any character in the name,
142 # except ']'. Otherwise macroname stops on the first ']', ',', ')',
143 # or '\n' encountered.
145 "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
147 # Matches an AC_REQUIRE line.
148 my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
150 # Matches an m4_include line.
151 my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
153 # Match a serial number.
154 my $serial_line_rx = '^#\s*serial\s+(\S*)';
155 my $serial_number_rx = '^\d+(?:\.\d+)*$';
157 # Autoconf version. This variable is set by 'trace_used_macros'.
160 # User directory containing extra m4 files for macros definition,
161 # as extracted from calls to the macro AC_CONFIG_MACRO_DIRS.
162 # This variable is updated by 'trace_used_macros'.
163 my @ac_config_macro_dirs;
165 # If set, names a temporary file that must be erased on abnormal exit.
168 # Constants for the $ERR_LEVEL parameter of the 'scan_m4_dirs' function.
169 use constant SCAN_M4_DIRS_SILENT => 0;
170 use constant SCAN_M4_DIRS_WARN => 1;
171 use constant SCAN_M4_DIRS_ERROR => 2;
173 ################################################################
175 # Prototypes for all subroutines.
179 sub check_acinclude ();
181 sub install_file ($$);
182 sub list_compare (\@\@);
183 sub scan_m4_dirs ($$@);
184 sub scan_m4_files ();
186 sub scan_configure_dep ($);
189 sub strip_redundant_includes (%);
190 sub trace_used_macros ();
191 sub scan_configure ();
192 sub write_aclocal ($@);
195 sub handle_acdir_option ($$);
196 sub parse_arguments ();
197 sub parse_ACLOCAL_PATH ();
199 ################################################################
201 # Erase temporary file ERASE_ME. Handle signals.
208 verb "caught SIG$sig, bailing out";
210 if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
212 fatal "could not remove '$erase_me': $!";
216 # reraise default handler.
219 $SIG{$sig} = 'DEFAULT';
224 $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
232 if -d $dir or eval { File::Path::mkpath $dir };
234 $@ =~ s/\s+at\s.*\bline\s\d+.*$//;
235 fatal "could not create directory '$dir': $@";
238 # Check macros in acinclude.m4. If one is not used, warn.
239 sub check_acinclude ()
241 foreach my $key (keys %map)
243 # FIXME: should print line number of acinclude.m4.
244 msg ('syntax', "macro '$key' defined in acinclude.m4 but never used")
245 if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
255 %map_traced_defs = ();
260 %scanned_configure_dep = ();
266 # install_file ($SRC, $DESTDIR)
267 sub install_file ($$)
269 my ($src, $destdir) = @_;
270 my $dest = $destdir . "/" . basename ($src);
273 verb "installing $src to $dest";
276 || !exists $file_contents{$dest}
277 || $file_contents{$src} ne $file_contents{$dest})
281 msg 'note', "overwriting '$dest' with '$src'";
286 msg 'note', "installing '$dest' from '$src'";
291 if (! defined $diff_dest)
293 # $dest does not exist. We create an empty one just to
294 # run diff, and we erase it afterward. Using the real
295 # the destination file (rather than a temporary file) is
296 # good when diff is run with options that display the
299 # If creating $dest fails, fall back to /dev/null. At
300 # least one diff implementation (Tru64's) cannot deal
301 # with /dev/null. However working around this is not
302 # worth the trouble since nobody run aclocal on a
303 # read-only tree anyway.
305 my $f = new IO::File "> $dest";
309 $diff_dest = '/dev/null';
317 my @cmd = (@diff_command, $diff_dest, $src);
319 verb "running: @cmd";
320 my $res = system (@cmd);
321 Automake::FileUtils::handle_exec_errors "@cmd", 1
328 xsystem ('cp', $src, $dest);
333 # Compare two lists of numbers.
334 sub list_compare (\@\@)
342 return (0 == @r) ? 0 : -1;
348 elsif ($l[0] < $r[0])
352 elsif ($l[0] > $r[0])
361 ################################################################
363 # scan_m4_dirs($TYPE, $ERR_LEVEL, @DIRS)
364 # -----------------------------------------------
365 # Scan all M4 files installed in @DIRS for new macro definitions.
366 # Register each file as of type $TYPE (one of the FT_* constants).
367 # If a directory in @DIRS cannot be read:
368 # - fail hard if $ERR_LEVEL == SCAN_M4_DIRS_ERROR
369 # - just print a warning if $ERR_LEVEL == SCAN_M4_DIRS_WA
370 # - continue silently if $ERR_LEVEL == SCAN_M4_DIRS_SILENT
371 sub scan_m4_dirs ($$@)
373 my ($type, $err_level, @dirlist) = @_;
375 foreach my $m4dir (@dirlist)
377 if (! opendir (DIR, $m4dir))
379 # TODO: maybe avoid complaining only if errno == ENONENT?
380 my $message = "couldn't open directory '$m4dir': $!";
382 if ($err_level == SCAN_M4_DIRS_ERROR)
386 elsif ($err_level == SCAN_M4_DIRS_WARN)
388 msg ('unsupported', $message);
391 elsif ($err_level == SCAN_M4_DIRS_SILENT)
393 next; # Silently ignore.
397 prog_error "invalid \$err_level value '$err_level'";
401 # We reverse the directory contents so that foo2.m4 gets
402 # used in preference to foo1.m4.
403 foreach my $file (reverse sort grep (! /^\./, readdir (DIR)))
405 # Only examine .m4 files.
406 next unless $file =~ /\.m4$/;
408 # Skip some files when running out of srcdir.
409 next if $file eq 'aclocal.m4';
411 my $fullfile = File::Spec->canonpath ("$m4dir/$file");
412 scan_file ($type, $fullfile, 'aclocal');
418 # Scan all the installed m4 files and construct a map.
421 # First, scan configure.ac. It may contain macro definitions,
422 # or may include other files that define macros.
423 scan_file (FT_USER, $configure_ac, 'aclocal');
425 # Then, scan acinclude.m4 if it exists.
426 if (-f 'acinclude.m4')
428 scan_file (FT_USER, 'acinclude.m4', 'aclocal');
431 # Finally, scan all files in our search paths.
435 # Don't explore the same directory multiple times. This is here not
436 # only for speedup purposes. We need this when the user has e.g.
437 # specified 'ACLOCAL_AMFLAGS = -I m4' and has also set
438 # AC_CONFIG_MACRO_DIR[S]([m4]) in configure.ac. This makes the 'm4'
439 # directory to occur twice here and fail on the second call to
440 # scan_m4_dirs([m4]) when the 'm4' directory doesn't exist.
441 # TODO: Shouldn't there be rather a check in scan_m4_dirs for
443 @user_includes = uniq @user_includes;
445 # Don't complain if the first user directory doesn't exist, in case
446 # we need to create it later (can happen if '--install' was given).
447 scan_m4_dirs (FT_USER,
448 $install ? SCAN_M4_DIRS_SILENT : SCAN_M4_DIRS_WARN,
450 scan_m4_dirs (FT_USER,
452 @user_includes[1..$#user_includes]);
454 scan_m4_dirs (FT_AUTOMAKE, SCAN_M4_DIRS_ERROR, @automake_includes);
455 scan_m4_dirs (FT_SYSTEM, SCAN_M4_DIRS_ERROR, @system_includes);
457 # Construct a new function that does the searching. We use a
458 # function (instead of just evaluating $search in the loop) so that
459 # "die" is correctly and easily propagated if run.
460 my $search = "sub search {\nmy \$found = 0;\n";
461 foreach my $key (reverse sort keys %map)
463 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { add_macro ("' . $key
464 . '"); $found = 1; }' . "\n");
466 $search .= "return \$found;\n};\n";
468 prog_error "$@\n search is $search" if $@;
471 ################################################################
473 # Add a macro to the output.
478 # Ignore unknown required macros. Either they are not really
479 # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
480 # should be quiet, or they are needed and Autoconf itself will
481 # complain when we trace for macro usage later.
482 return unless defined $map{$macro};
484 verb "saw macro $macro";
485 $macro_seen{$macro} = 1;
486 add_file ($map{$macro});
489 # scan_configure_dep ($file)
490 # --------------------------
491 # Scan a configure dependency (configure.ac, or separate m4 files)
492 # for uses of known macros and AC_REQUIREs of possibly unknown macros.
493 # Recursively scan m4_included files.
494 sub scan_configure_dep ($)
497 # Do not scan a file twice.
499 if exists $scanned_configure_dep{$file};
500 $scanned_configure_dep{$file} = 1;
502 my $mtime = mtime $file;
503 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
505 my $contents = exists $file_contents{$file} ?
506 $file_contents{$file} : contents $file;
511 foreach (split ("\n", $contents))
514 # Remove comments from current line.
517 # Avoid running all the following regexes on white lines.
520 while (/$m4_include_rx/go)
522 my $ifile = $2 || $3;
523 # Skip missing 'sinclude'd files.
524 next if $1 ne 'm4_' && ! -f $ifile;
528 while (/$ac_require_rx/go)
530 push (@rlist, $1 || $2);
533 # The search function is constructed dynamically by
534 # scan_m4_files. The last parenthetical match makes sure we
535 # don't match things that look like macro assignments or
537 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
539 # Macro not found, but AM_ prefix found.
540 # Make this just a warning, because we do not know whether
541 # the macro is actually used (it could be called conditionally).
542 msg ('unsupported', "$file:$line",
543 "macro '$2' not found in library");
547 add_macro ($_) foreach (@rlist);
548 scan_configure_dep ($_) foreach @ilist;
553 # Add $FILE to output.
558 # Only add a file once.
559 return if ($file_added{$file});
560 $file_added{$file} = 1;
562 scan_configure_dep $file;
565 # Point to the documentation for underquoted AC_DEFUN only once.
566 my $underquoted_manual_once = 0;
568 # scan_file ($TYPE, $FILE, $WHERE)
569 # --------------------------------
570 # Scan a single M4 file ($FILE), and all files it includes.
571 # Return the list of included files.
572 # $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending
573 # on where the file comes from.
574 # $WHERE is the location to use in the diagnostic if the file
578 my ($type, $file, $where) = @_;
579 my $basename = basename $file;
581 # Do not scan the same file twice.
582 return @{$file_includes{$file}} if exists $file_includes{$file};
583 # Prevent potential infinite recursion (if two files include each other).
584 return () if exists $file_contents{$file};
586 unshift @file_order, $file;
588 $file_type{$file} = $type;
590 fatal "$where: file '$file' does not exist" if ! -e $file;
592 my $fh = new Automake::XFile $file;
599 my $serial_older = 0;
601 while ($_ = $fh->getline)
609 if ($line =~ /$serial_line_rx/go)
612 if ($number !~ /$serial_number_rx/go)
614 msg ('syntax', "$file:$.",
615 "ill-formed serial number '$number', "
616 . "expecting a version string with only digits and dots");
620 # aclocal removes all definitions from M4 file with the
621 # same basename if a greater serial number is found.
622 # Encountering a serial after some macros will undefine
624 msg ('syntax', "$file:$.",
625 'the serial number must appear before any macro definition');
627 # We really care about serials only for non-automake macros
628 # and when --install is used. But the above diagnostics are
629 # made regardless of this, because not using --install is
630 # not a reason not the fix macro files.
631 elsif ($install && $type != FT_AUTOMAKE)
634 my @new = split (/\./, $number);
636 verb "$file:$.: serial $number";
638 if (!exists $serial{$basename}
639 || list_compare (@new, @{$serial{$basename}}) > 0)
641 # Delete any definition we knew from the old macro.
642 foreach my $def (@{$invmap{$basename}})
644 verb "$file:$.: ignoring previous definition of $def";
647 $invmap{$basename} = [];
648 $serial{$basename} = \@new;
657 # Remove comments from current line.
658 # Do not do it earlier, because the serial line is a comment.
659 $line =~ s/\bdnl\b.*$//;
662 while ($line =~ /$ac_defun_rx/go)
667 msg ('syntax', "$file:$.", "underquoted definition of $2"
668 . "\n run info Automake 'Extending aclocal'\n"
669 . " or see http://www.gnu.org/software/automake/manual/"
670 . "automake.html#Extending-aclocal")
671 unless $underquoted_manual_once;
672 $underquoted_manual_once = 1;
675 # If this macro does not have a serial and we have already
676 # seen a macro with the same basename earlier, we should
677 # ignore the macro (don't exit immediately so we can still
678 # diagnose later #serial numbers and underquoted macros).
679 $serial_older ||= ($type != FT_AUTOMAKE
680 && !$serial_seen && exists $serial{$basename});
682 my $macro = $1 || $2;
683 if (!$serial_older && !defined $map{$macro})
685 verb "found macro $macro in $file: $.";
686 $map{$macro} = $file;
687 push @{$invmap{$basename}}, $macro;
691 # Note: we used to give an error here if we saw a
692 # duplicated macro. However, this turns out to be
693 # extremely unpopular. It causes actual problems which
694 # are hard to work around, especially when you must
695 # mix-and-match tool versions.
696 verb "ignoring macro $macro in $file: $.";
700 while ($line =~ /$m4_include_rx/go)
702 my $ifile = $2 || $3;
703 # Skip missing 'sinclude'd files.
704 next if $1 ne 'm4_' && ! -f $ifile;
705 push (@inc_files, $ifile);
706 $inc_lines{$ifile} = $.;
710 # Ignore any file that has an old serial (or no serial if we know
711 # another one with a serial).
714 ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
716 $file_contents{$file} = $contents;
718 # For some reason I don't understand, it does not work
719 # to do "map { scan_file ($_, ...) } @inc_files" below.
720 # With Perl 5.8.2 it undefines @inc_files.
721 my @copy = @inc_files;
722 my @all_inc_files = (@inc_files,
723 map { scan_file ($type, $_,
724 "$file:$inc_lines{$_}") } @copy);
725 $file_includes{$file} = \@all_inc_files;
726 return @all_inc_files;
729 # strip_redundant_includes (%FILES)
730 # ---------------------------------
731 # Each key in %FILES is a file that must be present in the output.
732 # However some of these files might already include other files in %FILES,
733 # so there is no point in including them another time.
734 # This removes items of %FILES which are already included by another file.
735 sub strip_redundant_includes (%)
739 # Always include acinclude.m4, even if it does not appear to be used.
740 $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
741 # File included by $configure_ac are redundant.
742 $files{$configure_ac} = 1;
744 # Files at the end of @file_order should override those at the beginning,
745 # so it is important to preserve these trailing files. We can remove
746 # a file A if it is going to be output before a file B that includes
747 # file A, not the converse.
748 foreach my $file (reverse @file_order)
750 next unless exists $files{$file};
751 foreach my $ifile (@{$file_includes{$file}})
753 next unless exists $files{$ifile};
754 delete $files{$ifile};
755 verb "$ifile is already included by $file";
759 # configure.ac is implicitly included.
760 delete $files{$configure_ac};
765 sub trace_used_macros ()
767 my %files = map { $map{$_} => 1 } keys %macro_seen;
768 %files = strip_redundant_includes %files;
770 # When AC_CONFIG_MACRO_DIRS is used, avoid possible spurious warnings
771 # from autom4te about macros being "m4_require'd but not m4_defun'd";
772 # for more background, see:
773 # http://lists.gnu.org/archive/html/autoconf-patches/2012-11/msg00004.html
774 # as well as autoconf commit 'v2.69-44-g1ed0548', "warn: allow aclocal
775 # to silence m4_require warnings".
776 my $early_m4_code .= "m4_define([m4_require_silent_probe], [-])";
778 my $traces = ($ENV{AUTOM4TE} || '@am_AUTOM4TE@');
779 $traces .= " --language Autoconf-without-aclocal-m4 ";
780 $traces = "echo '$early_m4_code' | $traces - ";
782 # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
783 # Note that we can't use '$ac_config_macro_dirs_fallback' here, because
784 # a bug in option parsing code of autom4te 2.68 and earlier will cause
785 # it to read standard input last, even if the "-" argument is specified
787 # FIXME: To be removed in Automake 2.0, once we can assume autoconf
789 $traces .= "$automake_includes[0]/internal/ac-config-macro-dirs.m4 ";
791 # All candidate files.
792 $traces .= join (' ',
794 (grep { exists $files{$_} } @file_order))) . " ";
796 # All candidate macros.
797 $traces .= join (' ',
798 (map { "--trace='$_:\$f::\$n::\${::}%'" }
802 '_AM_AUTOCONF_VERSION',
803 'AC_CONFIG_MACRO_DIR_TRACE',
804 # FIXME: Tracing the next two macros is a hack for
805 # compatibility with older autoconf. Remove this in
806 # Automake 2.0, when we can assume Autoconf 2.70 or
808 'AC_CONFIG_MACRO_DIR',
809 '_AM_CONFIG_MACRO_DIRS')),
810 # Do not trace $1 for all other macros as we do
811 # not need it and it might contains harmful
812 # characters (like newlines).
813 (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
815 verb "running $traces $configure_ac";
817 my $tracefh = new Automake::XFile ("$traces $configure_ac |");
819 @ac_config_macro_dirs = ();
823 while ($_ = $tracefh->getline)
826 my ($file, $macro, $arg1) = split (/::/);
828 $traced{$macro} = 1 if exists $macro_seen{$macro};
830 if ($macro eq 'AC_DEFUN' || $macro eq 'AC_DEFUN_ONCE'
831 || $macro eq 'AU_DEFUN')
833 $map_traced_defs{$arg1} = $file;
835 elsif ($macro eq '_AM_AUTOCONF_VERSION')
839 elsif ($macro eq 'AC_CONFIG_MACRO_DIR_TRACE')
841 push @ac_config_macro_dirs, $arg1;
843 # FIXME: We still need to trace AC_CONFIG_MACRO_DIR
844 # for compatibility with older autoconf. Remove this
845 # once we can assume Autoconf 2.70 or later.
846 elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
848 @ac_config_macro_dirs = ($arg1);
850 # FIXME:This is an hack for compatibility with older autoconf.
851 # Remove this once we can assume Autoconf 2.70 or later.
852 elsif ($macro eq '_AM_CONFIG_MACRO_DIRS')
854 # Empty leading/trailing fields might be produced by split,
855 # hence the grep is really needed.
856 push @ac_config_macro_dirs, grep (/./, (split /\s+/, $arg1));
860 # FIXME: in Autoconf >= 2.70, AC_CONFIG_MACRO_DIR calls
861 # AC_CONFIG_MACRO_DIR_TRACE behind the scenes, which could
862 # leave unwanted duplicates in @ac_config_macro_dirs.
863 # Remove this in Automake 2.0, when we'll stop tracing
864 # AC_CONFIG_MACRO_DIR explicitly.
865 @ac_config_macro_dirs = uniq @ac_config_macro_dirs;
872 sub scan_configure ()
874 # Make sure we include acinclude.m4 if it exists.
875 if (-f 'acinclude.m4')
877 add_file ('acinclude.m4');
879 scan_configure_dep ($configure_ac);
882 ################################################################
885 # Return 0 iff some files were installed locally.
886 sub write_aclocal ($@)
888 my ($output_file, @macros) = @_;
892 # Get the list of files containing definitions for the macros used.
893 # (Filter out unused macro definitions with $map_traced_defs. This
894 # can happen when an Autoconf macro is conditionally defined:
895 # aclocal sees the potential definition, but this definition is
896 # actually never processed and the Autoconf implementation is used
901 if (exists $map_traced_defs{$m}
902 && $map{$m} eq $map_traced_defs{$m});
904 # Do not explicitly include a file that is already indirectly included.
905 %files = strip_redundant_includes %files;
909 for my $file (grep { exists $files{$_} } @file_order)
911 # Check the time stamp of this file, and of all files it includes.
912 for my $ifile ($file, @{$file_includes{$file}})
914 my $mtime = mtime $ifile;
915 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
918 # If the file to add looks like outside the project, copy it
919 # to the output. The regex catches filenames starting with
920 # things like '/', '\', or 'c:\'.
921 if ($file_type{$file} != FT_USER
922 || $file =~ m,^(?:\w:)?[\\/],)
924 if (!$install || $file_type{$file} != FT_SYSTEM)
926 # Copy the file into aclocal.m4.
927 $output .= $file_contents{$file} . "\n";
931 # Install the file (and any file it includes).
933 for my $ifile (@{$file_includes{$file}}, $file)
935 install_file ($ifile, $user_includes[0]);
942 # Otherwise, simply include the file.
943 $output .= "m4_include([$file])\n";
949 verb "running aclocal anew, because some files were installed locally";
953 # Nothing to output?!
954 # FIXME: Shouldn't we diagnose this?
955 return 1 if ! length ($output);
959 # Do not use "$output_file" here for the same reason we do not
960 # use it in the header below. autom4te will output the name of
961 # the file in the diagnostic anyway.
962 $output = "m4_ifndef([AC_AUTOCONF_VERSION],
963 [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
964 m4_if(m4_defn([AC_AUTOCONF_VERSION]), [$ac_version],,
965 [m4_warning([this file was generated for autoconf $ac_version.
966 You have another version of autoconf. It may work, but is not guaranteed to.
967 If you have problems, you may need to regenerate the build system entirely.
968 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
973 # We used to print "# $output_file generated automatically etc." But
974 # this creates spurious differences when using autoreconf. Autoreconf
975 # creates aclocal.m4t and then rename it to aclocal.m4, but the
976 # rebuild rules generated by Automake create aclocal.m4 directly --
977 # this would gives two ways to get the same file, with a different
978 # name in the header.
979 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
981 # Copyright (C) 1996-$RELEASE_YEAR Free Software Foundation, Inc.
983 # This file is free software; the Free Software Foundation
984 # gives unlimited permission to copy and/or distribute it,
985 # with or without modifications, as long as this notice is preserved.
987 # This program is distributed in the hope that it will be useful,
988 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
989 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
990 # PARTICULAR PURPOSE.
992 $ac_config_macro_dirs_fallback
995 # We try not to update $output_file unless necessary, because
996 # doing so invalidate Autom4te's cache and therefore slows down
997 # tools called after aclocal.
999 # We need to overwrite $output_file in the following situations.
1000 # * The --force option is in use.
1001 # * One of the dependencies is younger.
1002 # (Not updating $output_file in this situation would cause
1003 # make to call aclocal in loop.)
1004 # * The contents of the current file are different from what
1007 && $greatest_mtime < mtime ($output_file)
1008 && $output eq contents ($output_file))
1010 verb "$output_file unchanged";
1014 verb "writing $output_file";
1018 if (-e $output_file && !unlink $output_file)
1020 fatal "could not remove '$output_file': $!";
1022 my $out = new Automake::XFile "> $output_file";
1028 ################################################################
1030 # Print usage and exit.
1036 Usage: aclocal [OPTION]...
1038 Generate 'aclocal.m4' by scanning 'configure.ac' or 'configure.in'
1041 --automake-acdir=DIR directory holding automake-provided m4 files
1042 --system-acdir=DIR directory holding third-party system-wide files
1043 --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be
1044 changed (implies --install and --dry-run)
1045 --dry-run pretend to, but do not actually update any file
1046 --force always update output file
1047 --help print this help, then exit
1048 -I DIR add directory to search list for .m4 files
1049 --install copy third-party files to the first -I directory
1050 --output=FILE put output in FILE (default aclocal.m4)
1051 --print-ac-dir print name of directory holding system-wide
1052 third-party m4 files, then exit
1053 --verbose don't be silent
1054 --version print version number, then exit
1055 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
1057 Warning categories include:
1058 syntax dubious syntactic constructs (default)
1059 unsupported unknown macros (default)
1060 all all the warnings (default)
1061 no-CATEGORY turn off warnings in CATEGORY
1062 none turn off all the warnings
1063 error treat warnings as errors
1065 Report bugs to <@PACKAGE_BUGREPORT@>.
1066 GNU Automake home page: <@PACKAGE_URL@>.
1067 General help using GNU software: <http://www.gnu.org/gethelp/>.
1072 # Print version and exit.
1076 aclocal (GNU $PACKAGE) $VERSION
1077 Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
1078 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
1079 This is free software: you are free to change and redistribute it.
1080 There is NO WARRANTY, to the extent permitted by law.
1082 Written by Tom Tromey <tromey\@redhat.com>
1083 and Alexandre Duret-Lutz <adl\@gnu.org>.
1088 # Parse command line.
1089 sub parse_arguments ()
1091 my $print_and_exit = 0;
1096 'help' => sub { usage(0); },
1097 'version' => \&version,
1098 'system-acdir=s' => sub { shift; @system_includes = @_; },
1099 'automake-acdir=s' => sub { shift; @automake_includes = @_; },
1100 'diff:s' => \$diff_command,
1101 'dry-run' => \$dry_run,
1102 'force' => \$force_output,
1103 'I=s' => \@user_includes,
1104 'install' => \$install,
1105 'output=s' => \$output_file,
1106 'print-ac-dir' => \$print_and_exit,
1107 'verbose' => sub { setup_channel 'verb', silent => 0; },
1108 'W|warnings=s' => \&parse_warnings,
1111 use Automake::Getopt ();
1112 Automake::Getopt::parse_options %cli_options;
1116 fatal ("non-option arguments are not accepted: '$ARGV[0]'.\n"
1117 . "Try '$0 --help' for more information.");
1120 if ($print_and_exit)
1122 print "@system_includes\n";
1126 if (defined $diff_command)
1128 $diff_command = 'diff -u' if $diff_command eq '';
1129 @diff_command = split (' ', $diff_command);
1134 # Finally, adds any directory listed in the 'dirlist' file.
1135 if (open (DIRLIST, "$system_includes[0]/dirlist"))
1141 # strip off newlines and end-of-line comments
1144 foreach my $dir (glob)
1146 push (@system_includes, $dir) if -d $dir;
1153 # Add any directory listed in the 'ACLOCAL_PATH' environment variable
1154 # to the list of system include directories.
1155 sub parse_ACLOCAL_PATH ()
1157 return if not defined $ENV{"ACLOCAL_PATH"};
1158 # Directories in ACLOCAL_PATH should take precedence over system
1159 # directories, so we use unshift. However, directories that
1160 # come first in ACLOCAL_PATH take precedence over directories
1161 # coming later, which is why the result of split is reversed.
1162 foreach my $dir (reverse split /:/, $ENV{"ACLOCAL_PATH"})
1164 unshift (@system_includes, $dir) if $dir ne '' && -d $dir;
1168 ################################################################
1170 parse_WARNINGS; # Parse the WARNINGS environment variable.
1173 $configure_ac = require_configure_ac;
1175 # We may have to rerun aclocal if some file have been installed, but
1176 # it should not happen more than once. The reason we must run again
1177 # is that once the file has been moved from /usr/share/aclocal/ to the
1178 # local m4/ directory it appears at a new place in the search path,
1179 # hence it should be output at a different position in aclocal.m4. If
1180 # we did not rerun aclocal, the next run of aclocal would produce a
1181 # different aclocal.m4.
1183 my $rerun_due_to_macrodir = 0;
1187 prog_error "too many loops" if $loop > 2 + $rerun_due_to_macrodir;
1193 my %macro_traced = trace_used_macros;
1195 if (!$rerun_due_to_macrodir && @ac_config_macro_dirs)
1197 # The directory specified in calls to the AC_CONFIG_MACRO_DIRS
1198 # m4 macro (if any) must go after the user includes specified
1199 # explicitly with the '-I' option.
1200 push @user_includes, @ac_config_macro_dirs;
1201 # We might have to scan some new directory of .m4 files.
1202 $rerun_due_to_macrodir++;
1206 if ($install && !@user_includes)
1208 fatal "installation of third-party macros impossible without " .
1209 "-I options nor AC_CONFIG_MACRO_DIR{,S} m4 macro(s)";
1212 last if write_aclocal ($output_file, keys %macro_traced);
1219 ### Setup "GNU" style for perl-mode and cperl-mode.
1221 ## perl-indent-level: 2
1222 ## perl-continued-statement-offset: 2
1223 ## perl-continued-brace-offset: 0
1224 ## perl-brace-offset: 0
1225 ## perl-brace-imaginary-offset: 0
1226 ## perl-label-offset: -2
1227 ## cperl-indent-level: 2
1228 ## cperl-brace-offset: 0
1229 ## cperl-continued-brace-offset: 0
1230 ## cperl-label-offset: -2
1231 ## cperl-extra-newline-before-brace: t
1232 ## cperl-merge-trailing-else: nil
1233 ## cperl-continued-statement-offset: 2