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-2012 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 my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
31 unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
37 use Automake::General;
38 use Automake::Configure_ac;
39 use Automake::Channels;
40 use Automake::ChannelDefs;
42 use Automake::FileUtils;
48 # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
49 # FIXME: To be removed in Automake 1.14, once we can assume autoconf
51 # FIXME: keep in sync with 'internal/ac-config-macro-dirs.m4'.
52 my $ac_config_macro_dirs_fallback =
53 'm4_ifndef([AC_CONFIG_MACRO_DIRS], [' .
54 'm4_defun([_AM_CONFIG_MACRO_DIRS], [])' .
55 'm4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])' .
58 # We do not operate in threaded mode.
61 # Include paths for searching macros. We search macros in this order:
62 # user-supplied directories first, then the directory containing the
63 # automake macros, and finally the system-wide directories for
65 # @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIRS.
66 # @automake_includes can be reset with the '--automake-acdir' option.
67 # @system_includes can be augmented with the 'dirlist' file or the
68 # ACLOCAL_PATH environment variable, and reset with the '--system-acdir'
70 my @user_includes = ();
71 my @automake_includes = ("@datadir@/aclocal-$APIVERSION");
72 my @system_includes = ('@datadir@/aclocal');
74 # Whether we should copy M4 file in $user_includes[0].
83 # configure.ac or configure.in.
87 my $output_file = 'aclocal.m4';
92 # Modification time of the youngest dependency.
93 my $greatest_mtime = 0;
95 # Which macros have been seen.
98 # Remember the order into which we scanned the files.
99 # It's important to output the contents of aclocal.m4 in the opposite order.
100 # (Definitions in first files we have scanned should override those from
101 # later files. So they must appear last in the output.)
104 # Map macro names to file names.
107 # Ditto, but records the last definition of each macro as returned by --trace.
108 my %map_traced_defs = ();
110 # Map basenames to macro names.
113 # Map file names to file contents.
114 my %file_contents = ();
116 # Map file names to file types.
118 use constant FT_USER => 1;
119 use constant FT_AUTOMAKE => 2;
120 use constant FT_SYSTEM => 3;
122 # Map file names to included files (transitively closed).
123 my %file_includes = ();
125 # Files which have already been added.
128 # Files that have already been scanned.
129 my %scanned_configure_dep = ();
131 # Serial numbers, for files that have one.
132 # The key is the basename of the file,
133 # the value is the serial number represented as a list.
136 # Matches a macro definition.
137 # AC_DEFUN([macroname], ...)
139 # AC_DEFUN(macroname, ...)
140 # When macroname is '['-quoted , we accept any character in the name,
141 # except ']'. Otherwise macroname stops on the first ']', ',', ')',
142 # or '\n' encountered.
144 "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
146 # Matches an AC_REQUIRE line.
147 my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
149 # Matches an m4_include line.
150 my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
152 # Match a serial number.
153 my $serial_line_rx = '^#\s*serial\s+(\S*)';
154 my $serial_number_rx = '^\d+(?:\.\d+)*$';
156 # Autoconf version. This variable is set by 'trace_used_macros'.
159 # User directory containing extra m4 files for macros definition,
160 # as extracted from calls to the macro AC_CONFIG_MACRO_DIRS.
161 # This variable is updated by 'trace_used_macros'.
162 my @ac_config_macro_dirs;
164 # If set, names a temporary file that must be erased on abnormal exit.
167 ################################################################
169 # Prototypes for all subroutines.
173 sub check_acinclude ();
175 sub install_file ($$);
176 sub list_compare (\@\@);
177 sub scan_m4_dirs ($$@);
178 sub scan_m4_files ();
180 sub scan_configure_dep ($);
183 sub strip_redundant_includes (%);
184 sub trace_used_macros ();
185 sub scan_configure ();
186 sub write_aclocal ($@);
189 sub handle_acdir_option ($$);
190 sub parse_arguments ();
191 sub parse_ACLOCAL_PATH ();
193 ################################################################
195 # Erase temporary file ERASE_ME. Handle signals.
202 verb "caught SIG$sig, bailing out";
204 if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
206 fatal "could not remove '$erase_me': $!";
210 # reraise default handler.
213 $SIG{$sig} = 'DEFAULT';
218 $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
226 if -d $dir or eval { File::Path::mkpath $dir };
228 $@ =~ s/\s+at\s.*\bline\s\d+.*$//;
229 fatal "could not create directory '$dir': $@";
232 # Check macros in acinclude.m4. If one is not used, warn.
233 sub check_acinclude ()
235 foreach my $key (keys %map)
237 # FIXME: should print line number of acinclude.m4.
238 msg ('syntax', "macro '$key' defined in acinclude.m4 but never used")
239 if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
249 %map_traced_defs = ();
254 %scanned_configure_dep = ();
260 # install_file ($SRC, $DESTDIR)
261 sub install_file ($$)
263 my ($src, $destdir) = @_;
264 my $dest = $destdir . "/" . basename ($src);
267 verb "installing $src to $dest";
270 || !exists $file_contents{$dest}
271 || $file_contents{$src} ne $file_contents{$dest})
275 msg 'note', "overwriting '$dest' with '$src'";
280 msg 'note', "installing '$dest' from '$src'";
285 if (! defined $diff_dest)
287 # $dest does not exist. We create an empty one just to
288 # run diff, and we erase it afterward. Using the real
289 # the destination file (rather than a temporary file) is
290 # good when diff is run with options that display the
293 # If creating $dest fails, fall back to /dev/null. At
294 # least one diff implementation (Tru64's) cannot deal
295 # with /dev/null. However working around this is not
296 # worth the trouble since nobody run aclocal on a
297 # read-only tree anyway.
299 my $f = new IO::File "> $dest";
303 $diff_dest = '/dev/null';
311 my @cmd = (@diff_command, $diff_dest, $src);
313 verb "running: @cmd";
314 my $res = system (@cmd);
315 Automake::FileUtils::handle_exec_errors "@cmd", 1
322 xsystem ('cp', $src, $dest);
327 # Compare two lists of numbers.
328 sub list_compare (\@\@)
336 return (0 == @r) ? 0 : -1;
342 elsif ($l[0] < $r[0])
346 elsif ($l[0] > $r[0])
355 ################################################################
357 # scan_m4_dirs($TYPE, $ERR_ON_NONEXISTING, @DIRS)
358 # -----------------------------------------------
359 # Scan all M4 files installed in @DIRS for new macro definitions.
360 # Register each file as of type $TYPE (one of the FT_* constants).
361 sub scan_m4_dirs ($$@)
363 my ($type, $err_on_nonexisting, @dirlist) = @_;
365 foreach my $m4dir (@dirlist)
367 if (! opendir (DIR, $m4dir))
369 # TODO: maybe avoid complaining only if errno == ENONENT?
370 next unless $err_on_nonexisting;
371 fatal "couldn't open directory '$m4dir': $!";
374 # We reverse the directory contents so that foo2.m4 gets
375 # used in preference to foo1.m4.
376 foreach my $file (reverse sort grep (! /^\./, readdir (DIR)))
378 # Only examine .m4 files.
379 next unless $file =~ /\.m4$/;
381 # Skip some files when running out of srcdir.
382 next if $file eq 'aclocal.m4';
384 my $fullfile = File::Spec->canonpath ("$m4dir/$file");
385 scan_file ($type, $fullfile, 'aclocal');
391 # Scan all the installed m4 files and construct a map.
394 # First, scan configure.ac. It may contain macro definitions,
395 # or may include other files that define macros.
396 scan_file (FT_USER, $configure_ac, 'aclocal');
398 # Then, scan acinclude.m4 if it exists.
399 if (-f 'acinclude.m4')
401 scan_file (FT_USER, 'acinclude.m4', 'aclocal');
404 # Finally, scan all files in our search paths.
408 # Don't complain if the first user directory doesn't exist, in case
409 # we need to create it later (can happen if '--install' was given).
410 scan_m4_dirs (FT_USER, !$install, $user_includes[0]);
411 scan_m4_dirs (FT_USER, 1, @user_includes[1..$#user_includes]);
413 scan_m4_dirs (FT_AUTOMAKE, 1, @automake_includes);
414 scan_m4_dirs (FT_SYSTEM, 1, @system_includes);
416 # Construct a new function that does the searching. We use a
417 # function (instead of just evaluating $search in the loop) so that
418 # "die" is correctly and easily propagated if run.
419 my $search = "sub search {\nmy \$found = 0;\n";
420 foreach my $key (reverse sort keys %map)
422 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { add_macro ("' . $key
423 . '"); $found = 1; }' . "\n");
425 $search .= "return \$found;\n};\n";
427 prog_error "$@\n search is $search" if $@;
430 ################################################################
432 # Add a macro to the output.
437 # Ignore unknown required macros. Either they are not really
438 # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
439 # should be quiet, or they are needed and Autoconf itself will
440 # complain when we trace for macro usage later.
441 return unless defined $map{$macro};
443 verb "saw macro $macro";
444 $macro_seen{$macro} = 1;
445 add_file ($map{$macro});
448 # scan_configure_dep ($file)
449 # --------------------------
450 # Scan a configure dependency (configure.ac, or separate m4 files)
451 # for uses of known macros and AC_REQUIREs of possibly unknown macros.
452 # Recursively scan m4_included files.
453 sub scan_configure_dep ($)
456 # Do not scan a file twice.
458 if exists $scanned_configure_dep{$file};
459 $scanned_configure_dep{$file} = 1;
461 my $mtime = mtime $file;
462 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
464 my $contents = exists $file_contents{$file} ?
465 $file_contents{$file} : contents $file;
470 foreach (split ("\n", $contents))
473 # Remove comments from current line.
476 # Avoid running all the following regexes on white lines.
479 while (/$m4_include_rx/go)
481 my $ifile = $2 || $3;
482 # Skip missing 'sinclude'd files.
483 next if $1 ne 'm4_' && ! -f $ifile;
487 while (/$ac_require_rx/go)
489 push (@rlist, $1 || $2);
492 # The search function is constructed dynamically by
493 # scan_m4_files. The last parenthetical match makes sure we
494 # don't match things that look like macro assignments or
496 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
498 # Macro not found, but AM_ prefix found.
499 # Make this just a warning, because we do not know whether
500 # the macro is actually used (it could be called conditionally).
501 msg ('unsupported', "$file:$line",
502 "macro '$2' not found in library");
506 add_macro ($_) foreach (@rlist);
507 scan_configure_dep ($_) foreach @ilist;
512 # Add $FILE to output.
517 # Only add a file once.
518 return if ($file_added{$file});
519 $file_added{$file} = 1;
521 scan_configure_dep $file;
524 # Point to the documentation for underquoted AC_DEFUN only once.
525 my $underquoted_manual_once = 0;
527 # scan_file ($TYPE, $FILE, $WHERE)
528 # --------------------------------
529 # Scan a single M4 file ($FILE), and all files it includes.
530 # Return the list of included files.
531 # $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending
532 # on where the file comes from.
533 # $WHERE is the location to use in the diagnostic if the file
537 my ($type, $file, $where) = @_;
538 my $basename = basename $file;
540 # Do not scan the same file twice.
541 return @{$file_includes{$file}} if exists $file_includes{$file};
542 # Prevent potential infinite recursion (if two files include each other).
543 return () if exists $file_contents{$file};
545 unshift @file_order, $file;
547 $file_type{$file} = $type;
549 fatal "$where: file '$file' does not exist" if ! -e $file;
551 my $fh = new Automake::XFile $file;
558 my $serial_older = 0;
560 while ($_ = $fh->getline)
568 if ($line =~ /$serial_line_rx/go)
571 if ($number !~ /$serial_number_rx/go)
573 msg ('syntax', "$file:$.",
574 "ill-formed serial number '$number', "
575 . "expecting a version string with only digits and dots");
579 # aclocal removes all definitions from M4 file with the
580 # same basename if a greater serial number is found.
581 # Encountering a serial after some macros will undefine
583 msg ('syntax', "$file:$.",
584 'the serial number must appear before any macro definition');
586 # We really care about serials only for non-automake macros
587 # and when --install is used. But the above diagnostics are
588 # made regardless of this, because not using --install is
589 # not a reason not the fix macro files.
590 elsif ($install && $type != FT_AUTOMAKE)
593 my @new = split (/\./, $number);
595 verb "$file:$.: serial $number";
597 if (!exists $serial{$basename}
598 || list_compare (@new, @{$serial{$basename}}) > 0)
600 # Delete any definition we knew from the old macro.
601 foreach my $def (@{$invmap{$basename}})
603 verb "$file:$.: ignoring previous definition of $def";
606 $invmap{$basename} = [];
607 $serial{$basename} = \@new;
616 # Remove comments from current line.
617 # Do not do it earlier, because the serial line is a comment.
618 $line =~ s/\bdnl\b.*$//;
621 while ($line =~ /$ac_defun_rx/go)
626 msg ('syntax', "$file:$.", "underquoted definition of $2"
627 . "\n run info Automake 'Extending aclocal'\n"
628 . " or see http://www.gnu.org/software/automake/manual/"
629 . "automake.html#Extending-aclocal")
630 unless $underquoted_manual_once;
631 $underquoted_manual_once = 1;
634 # If this macro does not have a serial and we have already
635 # seen a macro with the same basename earlier, we should
636 # ignore the macro (don't exit immediately so we can still
637 # diagnose later #serial numbers and underquoted macros).
638 $serial_older ||= ($type != FT_AUTOMAKE
639 && !$serial_seen && exists $serial{$basename});
641 my $macro = $1 || $2;
642 if (!$serial_older && !defined $map{$macro})
644 verb "found macro $macro in $file: $.";
645 $map{$macro} = $file;
646 push @{$invmap{$basename}}, $macro;
650 # Note: we used to give an error here if we saw a
651 # duplicated macro. However, this turns out to be
652 # extremely unpopular. It causes actual problems which
653 # are hard to work around, especially when you must
654 # mix-and-match tool versions.
655 verb "ignoring macro $macro in $file: $.";
659 while ($line =~ /$m4_include_rx/go)
661 my $ifile = $2 || $3;
662 # Skip missing 'sinclude'd files.
663 next if $1 ne 'm4_' && ! -f $ifile;
664 push (@inc_files, $ifile);
665 $inc_lines{$ifile} = $.;
669 # Ignore any file that has an old serial (or no serial if we know
670 # another one with a serial).
673 ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
675 $file_contents{$file} = $contents;
677 # For some reason I don't understand, it does not work
678 # to do "map { scan_file ($_, ...) } @inc_files" below.
679 # With Perl 5.8.2 it undefines @inc_files.
680 my @copy = @inc_files;
681 my @all_inc_files = (@inc_files,
682 map { scan_file ($type, $_,
683 "$file:$inc_lines{$_}") } @copy);
684 $file_includes{$file} = \@all_inc_files;
685 return @all_inc_files;
688 # strip_redundant_includes (%FILES)
689 # ---------------------------------
690 # Each key in %FILES is a file that must be present in the output.
691 # However some of these files might already include other files in %FILES,
692 # so there is no point in including them another time.
693 # This removes items of %FILES which are already included by another file.
694 sub strip_redundant_includes (%)
698 # Always include acinclude.m4, even if it does not appear to be used.
699 $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
700 # File included by $configure_ac are redundant.
701 $files{$configure_ac} = 1;
703 # Files at the end of @file_order should override those at the beginning,
704 # so it is important to preserve these trailing files. We can remove
705 # a file A if it is going to be output before a file B that includes
706 # file A, not the converse.
707 foreach my $file (reverse @file_order)
709 next unless exists $files{$file};
710 foreach my $ifile (@{$file_includes{$file}})
712 next unless exists $files{$ifile};
713 delete $files{$ifile};
714 verb "$ifile is already included by $file";
718 # configure.ac is implicitly included.
719 delete $files{$configure_ac};
724 sub trace_used_macros ()
726 my %files = map { $map{$_} => 1 } keys %macro_seen;
727 %files = strip_redundant_includes %files;
729 # When AC_CONFIG_MACRO_DIRS is used, avoid possible spurious warnings
730 # from autom4te about macros being "m4_require'd but not m4_defun'd";
731 # for more background, see:
732 # http://lists.gnu.org/archive/html/autoconf-patches/2012-11/msg00004.html
733 # as well as autoconf commit 'v2.69-44-g1ed0548', "warn: allow aclocal
734 # to silence m4_require warnings".
735 my $early_m4_code .= "m4_define([m4_require_silent_probe], [-])";
737 my $traces = ($ENV{AUTOM4TE} || '@am_AUTOM4TE@');
738 $traces .= " --language Autoconf-without-aclocal-m4 ";
739 $traces = "echo '$early_m4_code' | $traces - ";
741 # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
742 # Note that we can't use '$ac_config_macro_dirs_fallback' here, because
743 # a bug in option parsing code of autom4te 2.68 and earlier will cause
744 # it to read standard input last, even if the "-" argument is specified
746 # FIXME: To be removed in Automake 1.14, once we can assume autoconf
748 $traces .= "$automake_includes[0]/internal/ac-config-macro-dirs.m4 ";
750 # All candidate files.
751 $traces .= join (' ',
753 (grep { exists $files{$_} } @file_order))) . " ";
755 # All candidate macros.
756 $traces .= join (' ',
757 (map { "--trace='$_:\$f::\$n::\${::}%'" }
761 '_AM_AUTOCONF_VERSION',
762 'AC_CONFIG_MACRO_DIR_TRACE',
763 # FIXME: Tracing the next two macros is a hack for
764 # compatibility with older autoconf. Remove this in
765 # Automake 1.14, when we can assume Autoconf 2.70 or
767 'AC_CONFIG_MACRO_DIR',
768 '_AM_CONFIG_MACRO_DIRS')),
769 # Do not trace $1 for all other macros as we do
770 # not need it and it might contains harmful
771 # characters (like newlines).
772 (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
774 verb "running $traces $configure_ac";
776 my $tracefh = new Automake::XFile ("$traces $configure_ac |");
778 @ac_config_macro_dirs = ();
782 while ($_ = $tracefh->getline)
785 my ($file, $macro, $arg1) = split (/::/);
787 $traced{$macro} = 1 if exists $macro_seen{$macro};
789 if ($macro eq 'AC_DEFUN' || $macro eq 'AC_DEFUN_ONCE'
790 || $macro eq 'AU_DEFUN')
792 $map_traced_defs{$arg1} = $file;
794 elsif ($macro eq '_AM_AUTOCONF_VERSION')
798 elsif ($macro eq 'AC_CONFIG_MACRO_DIR_TRACE')
800 push @ac_config_macro_dirs, $arg1;
802 # FIXME: We still need to trace AC_CONFIG_MACRO_DIR
803 # for compatibility with older autoconf. Remove this
804 # once we can assume Autoconf 2.70 or later.
805 elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
807 @ac_config_macro_dirs = ($arg1);
809 # FIXME:This is an hack for compatibility with older autoconf.
810 # Remove this once we can assume Autoconf 2.70 or later.
811 elsif ($macro eq '_AM_CONFIG_MACRO_DIRS')
813 # Empty leading/trailing fields might be produced by split,
814 # hence the grep is really needed.
815 push @ac_config_macro_dirs, grep (/./, (split /\s+/, $arg1));
819 # FIXME: in Autoconf >= 2.70, AC_CONFIG_MACRO_DIR calls
820 # AC_CONFIG_MACRO_DIR_TRACE behind the scenes, which could
821 # leave unwanted duplicates in @ac_config_macro_dirs.
822 # Remove this in Automake 1.14, when we'll stop tracing
823 # AC_CONFIG_MACRO_DIR explicitly.
824 @ac_config_macro_dirs = uniq @ac_config_macro_dirs;
831 sub scan_configure ()
833 # Make sure we include acinclude.m4 if it exists.
834 if (-f 'acinclude.m4')
836 add_file ('acinclude.m4');
838 scan_configure_dep ($configure_ac);
841 ################################################################
844 # Return 0 iff some files were installed locally.
845 sub write_aclocal ($@)
847 my ($output_file, @macros) = @_;
851 # Get the list of files containing definitions for the macros used.
852 # (Filter out unused macro definitions with $map_traced_defs. This
853 # can happen when an Autoconf macro is conditionally defined:
854 # aclocal sees the potential definition, but this definition is
855 # actually never processed and the Autoconf implementation is used
860 if (exists $map_traced_defs{$m}
861 && $map{$m} eq $map_traced_defs{$m});
863 # Do not explicitly include a file that is already indirectly included.
864 %files = strip_redundant_includes %files;
868 for my $file (grep { exists $files{$_} } @file_order)
870 # Check the time stamp of this file, and of all files it includes.
871 for my $ifile ($file, @{$file_includes{$file}})
873 my $mtime = mtime $ifile;
874 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
877 # If the file to add looks like outside the project, copy it
878 # to the output. The regex catches filenames starting with
879 # things like '/', '\', or 'c:\'.
880 if ($file_type{$file} != FT_USER
881 || $file =~ m,^(?:\w:)?[\\/],)
883 if (!$install || $file_type{$file} != FT_SYSTEM)
885 # Copy the file into aclocal.m4.
886 $output .= $file_contents{$file} . "\n";
890 # Install the file (and any file it includes).
892 for my $ifile (@{$file_includes{$file}}, $file)
894 install_file ($ifile, $user_includes[0]);
901 # Otherwise, simply include the file.
902 $output .= "m4_include([$file])\n";
908 verb "running aclocal anew, because some files were installed locally";
912 # Nothing to output?!
913 # FIXME: Shouldn't we diagnose this?
914 return 1 if ! length ($output);
918 # Do not use "$output_file" here for the same reason we do not
919 # use it in the header below. autom4te will output the name of
920 # the file in the diagnostic anyway.
921 $output = "m4_ifndef([AC_AUTOCONF_VERSION],
922 [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
923 m4_if(m4_defn([AC_AUTOCONF_VERSION]), [$ac_version],,
924 [m4_warning([this file was generated for autoconf $ac_version.
925 You have another version of autoconf. It may work, but is not guaranteed to.
926 If you have problems, you may need to regenerate the build system entirely.
927 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
932 # We used to print "# $output_file generated automatically etc." But
933 # this creates spurious differences when using autoreconf. Autoreconf
934 # creates aclocal.m4t and then rename it to aclocal.m4, but the
935 # rebuild rules generated by Automake create aclocal.m4 directly --
936 # this would gives two ways to get the same file, with a different
937 # name in the header.
938 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
940 # Copyright (C) 1996-$RELEASE_YEAR Free Software Foundation, Inc.
942 # This file is free software; the Free Software Foundation
943 # gives unlimited permission to copy and/or distribute it,
944 # with or without modifications, as long as this notice is preserved.
946 # This program is distributed in the hope that it will be useful,
947 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
948 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
949 # PARTICULAR PURPOSE.
951 $ac_config_macro_dirs_fallback
954 # We try not to update $output_file unless necessary, because
955 # doing so invalidate Autom4te's cache and therefore slows down
956 # tools called after aclocal.
958 # We need to overwrite $output_file in the following situations.
959 # * The --force option is in use.
960 # * One of the dependencies is younger.
961 # (Not updating $output_file in this situation would cause
962 # make to call aclocal in loop.)
963 # * The contents of the current file are different from what
966 && $greatest_mtime < mtime ($output_file)
967 && $output eq contents ($output_file))
969 verb "$output_file unchanged";
973 verb "writing $output_file";
977 if (-e $output_file && !unlink $output_file)
979 fatal "could not remove '$output_file': $!";
981 my $out = new Automake::XFile "> $output_file";
987 ################################################################
989 # Print usage and exit.
995 Usage: aclocal [OPTION]...
997 Generate 'aclocal.m4' by scanning 'configure.ac' or 'configure.in'
1000 --automake-acdir=DIR directory holding automake-provided m4 files
1001 --system-acdir=DIR directory holding third-party system-wide files
1002 --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be
1003 changed (implies --install and --dry-run)
1004 --dry-run pretend to, but do not actually update any file
1005 --force always update output file
1006 --help print this help, then exit
1007 -I DIR add directory to search list for .m4 files
1008 --install copy third-party files to the first -I directory
1009 --output=FILE put output in FILE (default aclocal.m4)
1010 --print-ac-dir print name of directory holding system-wide
1011 third-party m4 files, then exit
1012 --verbose don't be silent
1013 --version print version number, then exit
1014 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
1016 Warning categories include:
1017 syntax dubious syntactic constructs (default)
1018 unsupported unknown macros (default)
1019 all all the warnings (default)
1020 no-CATEGORY turn off warnings in CATEGORY
1021 none turn off all the warnings
1022 error treat warnings as errors
1024 Report bugs to <@PACKAGE_BUGREPORT@>.
1025 GNU Automake home page: <@PACKAGE_URL@>.
1026 General help using GNU software: <http://www.gnu.org/gethelp/>.
1031 # Print version and exit.
1035 aclocal (GNU $PACKAGE) $VERSION
1036 Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
1037 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
1038 This is free software: you are free to change and redistribute it.
1039 There is NO WARRANTY, to the extent permitted by law.
1041 Written by Tom Tromey <tromey\@redhat.com>
1042 and Alexandre Duret-Lutz <adl\@gnu.org>.
1047 # Parse command line.
1048 sub parse_arguments ()
1050 my $print_and_exit = 0;
1055 'help' => sub { usage(0); },
1056 'version' => \&version,
1057 'system-acdir=s' => sub { shift; @system_includes = @_; },
1058 'automake-acdir=s' => sub { shift; @automake_includes = @_; },
1059 'diff:s' => \$diff_command,
1060 'dry-run' => \$dry_run,
1061 'force' => \$force_output,
1062 'I=s' => \@user_includes,
1063 'install' => \$install,
1064 'output=s' => \$output_file,
1065 'print-ac-dir' => \$print_and_exit,
1066 'verbose' => sub { setup_channel 'verb', silent => 0; },
1067 'W|warnings=s' => \&parse_warnings,
1070 use Automake::Getopt ();
1071 Automake::Getopt::parse_options %cli_options;
1075 fatal ("non-option arguments are not accepted: '$ARGV[0]'.\n"
1076 . "Try '$0 --help' for more information.");
1079 if ($print_and_exit)
1081 print "@system_includes\n";
1085 if (defined $diff_command)
1087 $diff_command = 'diff -u' if $diff_command eq '';
1088 @diff_command = split (' ', $diff_command);
1093 # Finally, adds any directory listed in the 'dirlist' file.
1094 if (open (DIRLIST, "$system_includes[0]/dirlist"))
1100 # strip off newlines and end-of-line comments
1103 foreach my $dir (glob)
1105 push (@system_includes, $dir) if -d $dir;
1112 # Add any directory listed in the 'ACLOCAL_PATH' environment variable
1113 # to the list of system include directories.
1114 sub parse_ACLOCAL_PATH ()
1116 return if not defined $ENV{"ACLOCAL_PATH"};
1117 # Directories in ACLOCAL_PATH should take precedence over system
1118 # directories, so we use unshift. However, directories that
1119 # come first in ACLOCAL_PATH take precedence over directories
1120 # coming later, which is why the result of split is reversed.
1121 foreach my $dir (reverse split /:/, $ENV{"ACLOCAL_PATH"})
1123 unshift (@system_includes, $dir) if $dir ne '' && -d $dir;
1127 ################################################################
1129 parse_WARNINGS; # Parse the WARNINGS environment variable.
1132 $configure_ac = require_configure_ac;
1134 # We may have to rerun aclocal if some file have been installed, but
1135 # it should not happen more than once. The reason we must run again
1136 # is that once the file has been moved from /usr/share/aclocal/ to the
1137 # local m4/ directory it appears at a new place in the search path,
1138 # hence it should be output at a different position in aclocal.m4. If
1139 # we did not rerun aclocal, the next run of aclocal would produce a
1140 # different aclocal.m4.
1142 my $rerun_due_to_macrodir = 0;
1146 prog_error "too many loops" if $loop > 2 + $rerun_due_to_macrodir;
1152 my %macro_traced = trace_used_macros;
1154 if (!$rerun_due_to_macrodir && @ac_config_macro_dirs)
1156 # The directory specified in calls to the AC_CONFIG_MACRO_DIRS
1157 # m4 macro (if any) must go after the user includes specified
1158 # explicitly with the '-I' option.
1159 push @user_includes, @ac_config_macro_dirs;
1160 # We might have to scan some new directory of .m4 files.
1161 $rerun_due_to_macrodir++;
1165 if ($install && !@user_includes)
1167 fatal "installation of third-party macros impossible without " .
1168 "-I options nor AC_CONFIG_MACRO_DIR{,S} m4 macro(s)";
1171 last if write_aclocal ($output_file, keys %macro_traced);
1178 ### Setup "GNU" style for perl-mode and cperl-mode.
1180 ## perl-indent-level: 2
1181 ## perl-continued-statement-offset: 2
1182 ## perl-continued-brace-offset: 0
1183 ## perl-brace-offset: 0
1184 ## perl-brace-imaginary-offset: 0
1185 ## perl-label-offset: -2
1186 ## cperl-indent-level: 2
1187 ## cperl-brace-offset: 0
1188 ## cperl-continued-brace-offset: 0
1189 ## cperl-label-offset: -2
1190 ## cperl-extra-newline-before-brace: t
1191 ## cperl-merge-trailing-else: nil
1192 ## cperl-continued-statement-offset: 2