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, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
11 # 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2, or (at your option)
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 # Written by Tom Tromey <tromey@redhat.com>, and
28 # Alexandre Duret-Lutz <adl@gnu.org>.
32 my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
33 unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
39 use Automake::General;
40 use Automake::Configure_ac;
41 use Automake::Channels;
42 use Automake::ChannelDefs;
44 use Automake::FileUtils;
51 # We do not operate in threaded mode.
54 # Include paths for searching macros. We search macros in this order:
55 # user-supplied directories first, then the directory containing the
56 # automake macros, and finally the system-wide directories for
58 # @user_includes can be augmented with -I.
59 # @automake_includes can be reset with the `--automake-acdir' option.
60 # @system_includes can be augmented with the `dirlist' file or the
61 # ACLOCAL_PATH environment variable, and reset with the `--system-acdir'
63 my @user_includes = ();
64 my @automake_includes = ("@datadir@/aclocal-$APIVERSION");
65 my @system_includes = ('@datadir@/aclocal');
67 # Whether we should copy M4 file in $user_includes[0].
76 # configure.ac or configure.in.
80 my $output_file = 'aclocal.m4';
85 # Modification time of the youngest dependency.
86 my $greatest_mtime = 0;
88 # Which macros have been seen.
91 # Remember the order into which we scanned the files.
92 # It's important to output the contents of aclocal.m4 in the opposite order.
93 # (Definitions in first files we have scanned should override those from
94 # later files. So they must appear last in the output.)
97 # Map macro names to file names.
100 # Ditto, but records the last definition of each macro as returned by --trace.
101 my %map_traced_defs = ();
103 # Map basenames to macro names.
106 # Map file names to file contents.
107 my %file_contents = ();
109 # Map file names to file types.
111 use constant FT_USER => 1;
112 use constant FT_AUTOMAKE => 2;
113 use constant FT_SYSTEM => 3;
115 # Map file names to included files (transitively closed).
116 my %file_includes = ();
118 # Files which have already been added.
121 # Files that have already been scanned.
122 my %scanned_configure_dep = ();
124 # Serial numbers, for files that have one.
125 # The key is the basename of the file,
126 # the value is the serial number represented as a list.
129 # Matches a macro definition.
130 # AC_DEFUN([macroname], ...)
132 # AC_DEFUN(macroname, ...)
133 # When macroname is `['-quoted , we accept any character in the name,
134 # except `]'. Otherwise macroname stops on the first `]', `,', `)',
135 # or `\n' encountered.
137 "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
139 # Matches an AC_REQUIRE line.
140 my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
142 # Matches an m4_include line.
143 my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
145 # Match a serial number.
146 my $serial_line_rx = '^#\s*serial\s+(\S*)';
147 my $serial_number_rx = '^\d+(?:\.\d+)*$';
150 # Set by trace_used_macros.
153 # If set, names a temporary file that must be erased on abnormal exit.
156 ################################################################
158 # Erase temporary file ERASE_ME. Handle signals.
165 verb "caught SIG$sig, bailing out";
167 if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
169 fatal "could not remove `$erase_me': $!";
173 # reraise default handler.
176 $SIG{$sig} = 'DEFAULT';
181 $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
184 # Check macros in acinclude.m4. If one is not used, warn.
185 sub check_acinclude ()
187 foreach my $key (keys %map)
189 # FIXME: should print line number of acinclude.m4.
190 msg ('syntax', "macro `$key' defined in acinclude.m4 but never used")
191 if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
201 %map_traced_defs = ();
206 %scanned_configure_dep = ();
212 # install_file ($SRC, $DEST)
213 sub install_file ($$)
215 my ($src, $dest) = @_;
219 || !exists $file_contents{$dest}
220 || $file_contents{$src} ne $file_contents{$dest})
224 msg 'note', "overwriting `$dest' with `$src'";
229 msg 'note', "installing `$dest' from `$src'";
234 if (! defined $diff_dest)
236 # $dest does not exist. We create an empty one just to
237 # run diff, and we erase it afterward. Using the real
238 # the destination file (rather than a temporary file) is
239 # good when diff is run with options that display the
242 # If creating $dest fails, fall back to /dev/null. At
243 # least one diff implementation (Tru64's) cannot deal
244 # with /dev/null. However working around this is not
245 # worth the trouble since nobody run aclocal on a
246 # read-only tree anyway.
248 my $f = new IO::File "> $dest";
252 $diff_dest = '/dev/null';
260 my @cmd = (@diff_command, $diff_dest, $src);
262 verb "running: @cmd";
263 my $res = system (@cmd);
264 Automake::FileUtils::handle_exec_errors "@cmd", 1
270 xsystem ('cp', $src, $dest);
275 # Compare two lists of numbers.
276 sub list_compare (\@\@)
284 return (0 == @r) ? 0 : -1;
290 elsif ($l[0] < $r[0])
294 elsif ($l[0] > $r[0])
303 ################################################################
305 # scan_m4_dirs($TYPE, @DIRS)
306 # --------------------------
307 # Scan all M4 files installed in @DIRS for new macro definitions.
308 # Register each file as of type $TYPE (one of the FT_* constants).
309 sub scan_m4_dirs ($@)
311 my ($type, @dirlist) = @_;
313 foreach my $m4dir (@dirlist)
315 if (! opendir (DIR, $m4dir))
317 fatal "couldn't open directory `$m4dir': $!";
320 # We reverse the directory contents so that foo2.m4 gets
321 # used in preference to foo1.m4.
322 foreach my $file (reverse sort grep (! /^\./, readdir (DIR)))
324 # Only examine .m4 files.
325 next unless $file =~ /\.m4$/;
327 # Skip some files when running out of srcdir.
328 next if $file eq 'aclocal.m4';
330 my $fullfile = File::Spec->canonpath ("$m4dir/$file");
331 &scan_file ($type, $fullfile, 'aclocal');
337 # Scan all the installed m4 files and construct a map.
340 # First, scan configure.ac. It may contain macro definitions,
341 # or may include other files that define macros.
342 &scan_file (FT_USER, $configure_ac, 'aclocal');
344 # Then, scan acinclude.m4 if it exists.
345 if (-f 'acinclude.m4')
347 &scan_file (FT_USER, 'acinclude.m4', 'aclocal');
350 # Finally, scan all files in our search paths.
351 scan_m4_dirs (FT_USER, @user_includes);
352 scan_m4_dirs (FT_AUTOMAKE, @automake_includes);
353 scan_m4_dirs (FT_SYSTEM, @system_includes);
355 # Construct a new function that does the searching. We use a
356 # function (instead of just evaluating $search in the loop) so that
357 # "die" is correctly and easily propagated if run.
358 my $search = "sub search {\nmy \$found = 0;\n";
359 foreach my $key (reverse sort keys %map)
361 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
362 . '"); $found = 1; }' . "\n");
364 $search .= "return \$found;\n};\n";
366 prog_error "$@\n search is $search" if $@;
369 ################################################################
371 # Add a macro to the output.
376 # Ignore unknown required macros. Either they are not really
377 # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
378 # should be quiet, or they are needed and Autoconf itself will
379 # complain when we trace for macro usage later.
380 return unless defined $map{$macro};
382 verb "saw macro $macro";
383 $macro_seen{$macro} = 1;
384 &add_file ($map{$macro});
387 # scan_configure_dep ($file)
388 # --------------------------
389 # Scan a configure dependency (configure.ac, or separate m4 files)
390 # for uses of known macros and AC_REQUIREs of possibly unknown macros.
391 # Recursively scan m4_included files.
392 sub scan_configure_dep ($)
395 # Do not scan a file twice.
397 if exists $scanned_configure_dep{$file};
398 $scanned_configure_dep{$file} = 1;
400 my $mtime = mtime $file;
401 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
403 my $contents = exists $file_contents{$file} ?
404 $file_contents{$file} : contents $file;
409 foreach (split ("\n", $contents))
412 # Remove comments from current line.
415 # Avoid running all the following regexes on white lines.
418 while (/$m4_include_rx/go)
420 my $ifile = $2 || $3;
421 # Skip missing `sinclude'd files.
422 next if $1 ne 'm4_' && ! -f $ifile;
426 while (/$ac_require_rx/go)
428 push (@rlist, $1 || $2);
431 # The search function is constructed dynamically by
432 # scan_m4_files. The last parenthetical match makes sure we
433 # don't match things that look like macro assignments or
435 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
437 # Macro not found, but AM_ prefix found.
438 # Make this just a warning, because we do not know whether
439 # the macro is actually used (it could be called conditionally).
440 msg ('unsupported', "$file:$line",
441 "macro `$2' not found in library");
445 add_macro ($_) foreach (@rlist);
446 &scan_configure_dep ($_) foreach @ilist;
451 # Add $FILE to output.
456 # Only add a file once.
457 return if ($file_added{$file});
458 $file_added{$file} = 1;
460 scan_configure_dep $file;
463 # Point to the documentation for underquoted AC_DEFUN only once.
464 my $underquoted_manual_once = 0;
466 # scan_file ($TYPE, $FILE, $WHERE)
467 # --------------------------------
468 # Scan a single M4 file ($FILE), and all files it includes.
469 # Return the list of included files.
470 # $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending
471 # on where the file comes from.
472 # $WHERE is the location to use in the diagnostic if the file
476 my ($type, $file, $where) = @_;
477 my $basename = basename $file;
479 # Do not scan the same file twice.
480 return @{$file_includes{$file}} if exists $file_includes{$file};
481 # Prevent potential infinite recursion (if two files include each other).
482 return () if exists $file_contents{$file};
484 unshift @file_order, $file;
486 $file_type{$file} = $type;
488 fatal "$where: file `$file' does not exist" if ! -e $file;
490 my $fh = new Automake::XFile $file;
497 my $serial_older = 0;
499 while ($_ = $fh->getline)
507 if ($line =~ /$serial_line_rx/go)
510 if ($number !~ /$serial_number_rx/go)
512 msg ('syntax', "$file:$.",
513 "ill-formed serial number `$number', "
514 . "expecting a version string with only digits and dots");
518 # aclocal removes all definitions from M4 file with the
519 # same basename if a greater serial number is found.
520 # Encountering a serial after some macros will undefine
522 msg ('syntax', "$file:$.",
523 'the serial number must appear before any macro definition');
525 # We really care about serials only for non-automake macros
526 # and when --install is used. But the above diagnostics are
527 # made regardless of this, because not using --install is
528 # not a reason not the fix macro files.
529 elsif ($install && $type != FT_AUTOMAKE)
532 my @new = split (/\./, $number);
534 verb "$file:$.: serial $number";
536 if (!exists $serial{$basename}
537 || list_compare (@new, @{$serial{$basename}}) > 0)
539 # Delete any definition we knew from the old macro.
540 foreach my $def (@{$invmap{$basename}})
542 verb "$file:$.: ignoring previous definition of $def";
545 $invmap{$basename} = [];
546 $serial{$basename} = \@new;
555 # Remove comments from current line.
556 # Do not do it earlier, because the serial line is a comment.
557 $line =~ s/\bdnl\b.*$//;
560 while ($line =~ /$ac_defun_rx/go)
565 msg ('syntax', "$file:$.", "underquoted definition of $2"
566 . "\n run info Automake 'Extending aclocal'\n"
567 . " or see http://www.gnu.org/software/automake/manual/"
568 . "automake.html#Extending-aclocal")
569 unless $underquoted_manual_once;
570 $underquoted_manual_once = 1;
573 # If this macro does not have a serial and we have already
574 # seen a macro with the same basename earlier, we should
575 # ignore the macro (don't exit immediately so we can still
576 # diagnose later #serial numbers and underquoted macros).
577 $serial_older ||= ($type != FT_AUTOMAKE
578 && !$serial_seen && exists $serial{$basename});
580 my $macro = $1 || $2;
581 if (!$serial_older && !defined $map{$macro})
583 verb "found macro $macro in $file: $.";
584 $map{$macro} = $file;
585 push @{$invmap{$basename}}, $macro;
589 # Note: we used to give an error here if we saw a
590 # duplicated macro. However, this turns out to be
591 # extremely unpopular. It causes actual problems which
592 # are hard to work around, especially when you must
593 # mix-and-match tool versions.
594 verb "ignoring macro $macro in $file: $.";
598 while ($line =~ /$m4_include_rx/go)
600 my $ifile = $2 || $3;
601 # Skip missing `sinclude'd files.
602 next if $1 ne 'm4_' && ! -f $ifile;
603 push (@inc_files, $ifile);
604 $inc_lines{$ifile} = $.;
608 # Ignore any file that has an old serial (or no serial if we know
609 # another one with a serial).
612 ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
614 $file_contents{$file} = $contents;
616 # For some reason I don't understand, it does not work
617 # to do `map { scan_file ($_, ...) } @inc_files' below.
618 # With Perl 5.8.2 it undefines @inc_files.
619 my @copy = @inc_files;
620 my @all_inc_files = (@inc_files,
621 map { scan_file ($type, $_,
622 "$file:$inc_lines{$_}") } @copy);
623 $file_includes{$file} = \@all_inc_files;
624 return @all_inc_files;
627 # strip_redundant_includes (%FILES)
628 # ---------------------------------
629 # Each key in %FILES is a file that must be present in the output.
630 # However some of these files might already include other files in %FILES,
631 # so there is no point in including them another time.
632 # This removes items of %FILES which are already included by another file.
633 sub strip_redundant_includes (%)
637 # Always include acinclude.m4, even if it does not appear to be used.
638 $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
639 # File included by $configure_ac are redundant.
640 $files{$configure_ac} = 1;
642 # Files at the end of @file_order should override those at the beginning,
643 # so it is important to preserve these trailing files. We can remove
644 # a file A if it is going to be output before a file B that includes
645 # file A, not the converse.
646 foreach my $file (reverse @file_order)
648 next unless exists $files{$file};
649 foreach my $ifile (@{$file_includes{$file}})
651 next unless exists $files{$ifile};
652 delete $files{$ifile};
653 verb "$ifile is already included by $file";
657 # configure.ac is implicitly included.
658 delete $files{$configure_ac};
663 sub trace_used_macros ()
665 my %files = map { $map{$_} => 1 } keys %macro_seen;
666 %files = strip_redundant_includes %files;
668 my $traces = ($ENV{AUTOM4TE} || '@am_AUTOM4TE@');
669 $traces .= " --language Autoconf-without-aclocal-m4 ";
670 # All candidate files.
671 $traces .= join (' ',
673 (grep { exists $files{$_} } @file_order))) . " ";
674 # All candidate macros.
675 $traces .= join (' ',
676 (map { "--trace='$_:\$f::\$n::\$1'" }
680 '_AM_AUTOCONF_VERSION')),
681 # Do not trace $1 for all other macros as we do
682 # not need it and it might contains harmful
683 # characters (like newlines).
684 (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
686 verb "running $traces $configure_ac";
688 my $tracefh = new Automake::XFile ("$traces $configure_ac |");
692 while ($_ = $tracefh->getline)
695 my ($file, $macro, $arg1) = split (/::/);
697 $traced{$macro} = 1 if exists $macro_seen{$macro};
699 $map_traced_defs{$arg1} = $file
700 if ($macro eq 'AC_DEFUN'
701 || $macro eq 'AC_DEFUN_ONCE'
702 || $macro eq 'AU_DEFUN');
704 $ac_version = $arg1 if $macro eq '_AM_AUTOCONF_VERSION';
712 sub scan_configure ()
714 # Make sure we include acinclude.m4 if it exists.
715 if (-f 'acinclude.m4')
717 add_file ('acinclude.m4');
719 scan_configure_dep ($configure_ac);
722 ################################################################
725 # Return 0 iff some files were installed locally.
726 sub write_aclocal ($@)
728 my ($output_file, @macros) = @_;
732 # Get the list of files containing definitions for the macros used.
733 # (Filter out unused macro definitions with $map_traced_defs. This
734 # can happen when an Autoconf macro is conditionally defined:
735 # aclocal sees the potential definition, but this definition is
736 # actually never processed and the Autoconf implementation is used
741 if (exists $map_traced_defs{$m}
742 && $map{$m} eq $map_traced_defs{$m});
744 # Do not explicitly include a file that is already indirectly included.
745 %files = strip_redundant_includes %files;
749 for my $file (grep { exists $files{$_} } @file_order)
751 # Check the time stamp of this file, and of all files it includes.
752 for my $ifile ($file, @{$file_includes{$file}})
754 my $mtime = mtime $ifile;
755 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
758 # If the file to add looks like outside the project, copy it
759 # to the output. The regex catches filenames starting with
760 # things like `/', `\', or `c:\'.
761 if ($file_type{$file} != FT_USER
762 || $file =~ m,^(?:\w:)?[\\/],)
764 if (!$install || $file_type{$file} != FT_SYSTEM)
766 # Copy the file into aclocal.m4.
767 $output .= $file_contents{$file} . "\n";
771 # Install the file (and any file it includes).
773 for my $ifile (@{$file_includes{$file}}, $file)
775 $dest = "$user_includes[0]/" . basename $ifile;
776 verb "installing $ifile to $dest";
777 install_file ($ifile, $dest);
784 # Otherwise, simply include the file.
785 $output .= "m4_include([$file])\n";
791 verb "running aclocal anew, because some files were installed locally";
795 # Nothing to output?!
796 # FIXME: Shouldn't we diagnose this?
797 return 1 if ! length ($output);
801 # Do not use "$output_file" here for the same reason we do not
802 # use it in the header below. autom4te will output the name of
803 # the file in the diagnostic anyway.
804 $output = "m4_ifndef([AC_AUTOCONF_VERSION],
805 [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
806 m4_if(m4_defn([AC_AUTOCONF_VERSION]), [$ac_version],,
807 [m4_warning([this file was generated for autoconf $ac_version.
808 You have another version of autoconf. It may work, but is not guaranteed to.
809 If you have problems, you may need to regenerate the build system entirely.
810 To do so, use the procedure documented by the package, typically `autoreconf'.])])
815 # We used to print `# $output_file generated automatically etc.' But
816 # this creates spurious differences when using autoreconf. Autoreconf
817 # creates aclocal.m4t and then rename it to aclocal.m4, but the
818 # rebuild rules generated by Automake create aclocal.m4 directly --
819 # this would gives two ways to get the same file, with a different
820 # name in the header.
821 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
823 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
824 # 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
826 # This file is free software; the Free Software Foundation
827 # gives unlimited permission to copy and/or distribute it,
828 # with or without modifications, as long as this notice is preserved.
830 # This program is distributed in the hope that it will be useful,
831 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
832 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
833 # PARTICULAR PURPOSE.
837 # We try not to update $output_file unless necessary, because
838 # doing so invalidate Autom4te's cache and therefore slows down
839 # tools called after aclocal.
841 # We need to overwrite $output_file in the following situations.
842 # * The --force option is in use.
843 # * One of the dependencies is younger.
844 # (Not updating $output_file in this situation would cause
845 # make to call aclocal in loop.)
846 # * The contents of the current file are different from what
849 && $greatest_mtime < mtime ($output_file)
850 && $output eq contents ($output_file))
852 verb "$output_file unchanged";
856 verb "writing $output_file";
860 if (-e $output_file && !unlink $output_file)
862 fatal "could not remove `$output_file': $!";
864 my $out = new Automake::XFile "> $output_file";
870 ################################################################
872 # Print usage and exit.
877 print "Usage: aclocal [OPTION]...
879 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
882 --automake-acdir=DIR directory holding automake-provided m4 files
883 --system-acdir=DIR directory holding third-party system-wide files
884 --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be
885 changed (implies --install and --dry-run)
886 --dry-run pretend to, but do not actually update any file
887 --force always update output file
888 --help print this help, then exit
889 -I DIR add directory to search list for .m4 files
890 --install copy third-party files to the first -I directory
891 --output=FILE put output in FILE (default aclocal.m4)
892 --print-ac-dir print name of directory holding system-wide
893 third-party m4 files, then exit
894 --verbose don't be silent
895 --version print version number, then exit
896 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
898 Warning categories include:
899 `syntax' dubious syntactic constructs (default)
900 `unsupported' unknown macros (default)
901 `all' all the warnings (default)
902 `no-CATEGORY' turn off warnings in CATEGORY
903 `none' turn off all the warnings
904 `error' treat warnings as errors
906 " . 'Report bugs to <@PACKAGE_BUGREPORT@>.
907 GNU Automake home page: <@PACKAGE_URL@>.
908 General help using GNU software: <http://www.gnu.org/gethelp/>.
914 # Print version and exit.
918 aclocal (GNU $PACKAGE) $VERSION
919 Copyright (C) 2011 Free Software Foundation, Inc.
920 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
921 This is free software: you are free to change and redistribute it.
922 There is NO WARRANTY, to the extent permitted by law.
924 Written by Tom Tromey <tromey\@redhat.com>
925 and Alexandre Duret-Lutz <adl\@gnu.org>.
930 # Using --acdir overrides both the automake (versioned) directory and
931 # the public (unversioned) system directory. This usage is obsolete.
932 sub handle_acdir_option ($$)
934 msg 'obsolete', '', "`--acdir' is deprecated\n";
935 @system_includes = ($_[1]);
936 @automake_includes = ();
939 # Parse command line.
940 sub parse_arguments ()
942 my $print_and_exit = 0;
947 'acdir=s' => \&handle_acdir_option,
948 'system-acdir=s' => sub { shift; @system_includes = @_; },
949 'automake-acdir=s' => sub { shift; @automake_includes = @_; },
950 'diff:s' => \$diff_command,
951 'dry-run' => \$dry_run,
952 'force' => \$force_output,
953 'I=s' => \@user_includes,
954 'install' => \$install,
955 'output=s' => \$output_file,
956 'print-ac-dir' => \$print_and_exit,
957 'verbose' => sub { setup_channel 'verb', silent => 0; },
958 'W|warnings=s' => \&parse_warnings,
961 Getopt::Long::config ("bundling", "pass_through");
963 # See if --version or --help is used. We want to process these before
964 # anything else because the GNU Coding Standards require us to
965 # `exit 0' after processing these options, and we can't guarantee this
966 # if we treat other options first. (Handling other options first
967 # could produce error diagnostics, and in this condition it is
968 # confusing if aclocal does `exit 0'.)
969 my %cli_options_1st_pass =
971 'version' => \&version,
972 'help' => sub { usage(0); },
973 # Recognize all other options (and their arguments) but do nothing.
974 map { $_ => sub {} } (keys %cli_options)
976 my @ARGV_backup = @ARGV;
977 Getopt::Long::GetOptions %cli_options_1st_pass
979 @ARGV = @ARGV_backup;
981 # Now *really* process the options. This time we know that --help
982 # and --version are not present, but we specify them nonetheless so
983 # that ambiguous abbreviation are diagnosed.
984 Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {}
990 for my $k (keys %cli_options)
994 map { $argopts{(length ($_) == 1)
995 ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
998 if (exists $argopts{$ARGV[0]})
1000 fatal ("option `$ARGV[0]' requires an argument.\n"
1001 . "Try `$0 --help' for more information");
1005 fatal ("unrecognized option `$ARGV[0]'\n"
1006 . "Try `$0 --help' for more information");
1010 if ($print_and_exit)
1012 print "@system_includes\n";
1016 if (defined $diff_command)
1018 $diff_command = 'diff -u' if $diff_command eq '';
1019 @diff_command = split (' ', $diff_command);
1024 if ($install && !@user_includes)
1026 fatal ("--install should copy macros in the directory indicated by the"
1027 . "\nfirst -I option, but no -I was supplied");
1030 # Finally, adds any directory listed in the `dirlist' file.
1031 if (open (DIRLIST, "$system_includes[0]/dirlist"))
1037 # strip off newlines and end-of-line comments
1040 foreach my $dir (glob)
1042 push (@system_includes, $dir) if -d $dir;
1049 # Add any directory listed in the `ACLOCAL_PATH' environment variable
1050 # to the list of system include directories.
1051 sub parse_ACLOCAL_PATH ()
1053 return if not defined $ENV{"ACLOCAL_PATH"};
1054 # Directories in ACLOCAL_PATH should take precedence over system
1055 # directories, so we use unshift. However, directories that
1056 # come first in ACLOCAL_PATH take precedence over directories
1057 # coming later, which is why the result of split is reversed.
1058 foreach my $dir (reverse split /:/, $ENV{"ACLOCAL_PATH"})
1060 unshift (@system_includes, $dir) if $dir ne '' && -d $dir;
1064 ################################################################
1066 parse_WARNINGS; # Parse the WARNINGS environment variable.
1069 $configure_ac = require_configure_ac;
1071 # We may have to rerun aclocal if some file have been installed, but
1072 # it should not happen more than once. The reason we must run again
1073 # is that once the file has been moved from /usr/share/aclocal/ to the
1074 # local m4/ directory it appears at a new place in the search path,
1075 # hence it should be output at a different position in aclocal.m4. If
1076 # we did not rerun aclocal, the next run of aclocal would produce a
1077 # different aclocal.m4.
1082 prog_error "too many loops" if $loop > 2;
1088 my %macro_traced = trace_used_macros;
1089 last if write_aclocal ($output_file, keys %macro_traced);
1096 ### Setup "GNU" style for perl-mode and cperl-mode.
1098 ## perl-indent-level: 2
1099 ## perl-continued-statement-offset: 2
1100 ## perl-continued-brace-offset: 0
1101 ## perl-brace-offset: 0
1102 ## perl-brace-imaginary-offset: 0
1103 ## perl-label-offset: -2
1104 ## cperl-indent-level: 2
1105 ## cperl-brace-offset: 0
1106 ## cperl-continued-brace-offset: 0
1107 ## cperl-label-offset: -2
1108 ## cperl-extra-newline-before-brace: t
1109 ## cperl-merge-trailing-else: nil
1110 ## cperl-continued-statement-offset: 2