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 # We do not operate in threaded mode.
51 # Include paths for searching macros. We search macros in this order:
52 # user-supplied directories first, then the directory containing the
53 # automake macros, and finally the system-wide directories for
55 # @user_includes can be augmented with -I or AC_CONFIG_MACRO_DIR.
56 # @automake_includes can be reset with the '--automake-acdir' option.
57 # @system_includes can be augmented with the 'dirlist' file or the
58 # ACLOCAL_PATH environment variable, and reset with the '--system-acdir'
60 my @user_includes = ();
61 my @automake_includes = ("@datadir@/aclocal-$APIVERSION");
62 my @system_includes = ('@datadir@/aclocal');
64 # Whether we should copy M4 file in $user_includes[0].
73 # configure.ac or configure.in.
77 my $output_file = 'aclocal.m4';
82 # Modification time of the youngest dependency.
83 my $greatest_mtime = 0;
85 # Which macros have been seen.
88 # Remember the order into which we scanned the files.
89 # It's important to output the contents of aclocal.m4 in the opposite order.
90 # (Definitions in first files we have scanned should override those from
91 # later files. So they must appear last in the output.)
94 # Map macro names to file names.
97 # Ditto, but records the last definition of each macro as returned by --trace.
98 my %map_traced_defs = ();
100 # Map basenames to macro names.
103 # Map file names to file contents.
104 my %file_contents = ();
106 # Map file names to file types.
108 use constant FT_USER => 1;
109 use constant FT_AUTOMAKE => 2;
110 use constant FT_SYSTEM => 3;
112 # Map file names to included files (transitively closed).
113 my %file_includes = ();
115 # Files which have already been added.
118 # Files that have already been scanned.
119 my %scanned_configure_dep = ();
121 # Serial numbers, for files that have one.
122 # The key is the basename of the file,
123 # the value is the serial number represented as a list.
126 # Matches a macro definition.
127 # AC_DEFUN([macroname], ...)
129 # AC_DEFUN(macroname, ...)
130 # When macroname is '['-quoted , we accept any character in the name,
131 # except ']'. Otherwise macroname stops on the first ']', ',', ')',
132 # or '\n' encountered.
134 "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
136 # Matches an AC_REQUIRE line.
137 my $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
139 # Matches an m4_include line.
140 my $m4_include_rx = "(m4_|m4_s|s)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
142 # Match a serial number.
143 my $serial_line_rx = '^#\s*serial\s+(\S*)';
144 my $serial_number_rx = '^\d+(?:\.\d+)*$';
146 # Autoconf version. This variable is set by 'trace_used_macros'.
149 # Primary user directory containing extra m4 files for macros
150 # definition, as extracted from call to macro AC_CONFIG_MACRO_DIR.
151 # This variable is set by 'trace_used_macros'.
152 my $ac_config_macro_dir;
154 # If set, names a temporary file that must be erased on abnormal exit.
157 ################################################################
159 # Prototypes for all subroutines.
163 sub check_acinclude ();
165 sub install_file ($$);
166 sub list_compare (\@\@);
167 sub scan_m4_dirs ($@);
168 sub scan_m4_files ();
170 sub scan_configure_dep ($);
173 sub strip_redundant_includes (%);
174 sub trace_used_macros ();
175 sub scan_configure ();
176 sub write_aclocal ($@);
179 sub handle_acdir_option ($$);
180 sub parse_arguments ();
181 sub parse_ACLOCAL_PATH ();
183 ################################################################
185 # Erase temporary file ERASE_ME. Handle signals.
192 verb "caught SIG$sig, bailing out";
194 if (defined $erase_me && -e $erase_me && !unlink ($erase_me))
196 fatal "could not remove '$erase_me': $!";
200 # reraise default handler.
203 $SIG{$sig} = 'DEFAULT';
208 $SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
216 if -d $dir or eval { File::Path::mkpath $dir };
218 $@ =~ s/\s+at\s.*\bline\s\d+.*$//;
219 fatal "could not create directory '$dir': $@";
222 # Check macros in acinclude.m4. If one is not used, warn.
223 sub check_acinclude ()
225 foreach my $key (keys %map)
227 # FIXME: should print line number of acinclude.m4.
228 msg ('syntax', "macro '$key' defined in acinclude.m4 but never used")
229 if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key};
239 %map_traced_defs = ();
244 %scanned_configure_dep = ();
250 # install_file ($SRC, $DESTDIR)
251 sub install_file ($$)
253 my ($src, $destdir) = @_;
254 my $dest = $destdir . "/" . basename ($src);
257 verb "installing $src to $dest";
260 || !exists $file_contents{$dest}
261 || $file_contents{$src} ne $file_contents{$dest})
265 msg 'note', "overwriting '$dest' with '$src'";
270 msg 'note', "installing '$dest' from '$src'";
275 if (! defined $diff_dest)
277 # $dest does not exist. We create an empty one just to
278 # run diff, and we erase it afterward. Using the real
279 # the destination file (rather than a temporary file) is
280 # good when diff is run with options that display the
283 # If creating $dest fails, fall back to /dev/null. At
284 # least one diff implementation (Tru64's) cannot deal
285 # with /dev/null. However working around this is not
286 # worth the trouble since nobody run aclocal on a
287 # read-only tree anyway.
289 my $f = new IO::File "> $dest";
293 $diff_dest = '/dev/null';
301 my @cmd = (@diff_command, $diff_dest, $src);
303 verb "running: @cmd";
304 my $res = system (@cmd);
305 Automake::FileUtils::handle_exec_errors "@cmd", 1
312 xsystem ('cp', $src, $dest);
317 # Compare two lists of numbers.
318 sub list_compare (\@\@)
326 return (0 == @r) ? 0 : -1;
332 elsif ($l[0] < $r[0])
336 elsif ($l[0] > $r[0])
345 ################################################################
347 # scan_m4_dirs($TYPE, @DIRS)
348 # --------------------------
349 # Scan all M4 files installed in @DIRS for new macro definitions.
350 # Register each file as of type $TYPE (one of the FT_* constants).
351 my $first_user_m4dir = 1;
352 sub scan_m4_dirs ($@)
354 my ($type, @dirlist) = @_;
356 foreach my $m4dir (@dirlist)
358 if (! opendir (DIR, $m4dir))
360 if ($install && $type == FT_USER && $first_user_m4dir)
362 # We will try to create this directory later, so don't
363 # complain if it doesn't exist.
364 # TODO: maybe we should avoid complaining only if errno
366 $first_user_m4dir = 0;
369 fatal "couldn't open directory '$m4dir': $!";
372 # We reverse the directory contents so that foo2.m4 gets
373 # used in preference to foo1.m4.
374 foreach my $file (reverse sort grep (! /^\./, readdir (DIR)))
376 # Only examine .m4 files.
377 next unless $file =~ /\.m4$/;
379 # Skip some files when running out of srcdir.
380 next if $file eq 'aclocal.m4';
382 my $fullfile = File::Spec->canonpath ("$m4dir/$file");
383 scan_file ($type, $fullfile, 'aclocal');
389 # Scan all the installed m4 files and construct a map.
392 # First, scan configure.ac. It may contain macro definitions,
393 # or may include other files that define macros.
394 scan_file (FT_USER, $configure_ac, 'aclocal');
396 # Then, scan acinclude.m4 if it exists.
397 if (-f 'acinclude.m4')
399 scan_file (FT_USER, 'acinclude.m4', 'aclocal');
402 # Finally, scan all files in our search paths.
403 scan_m4_dirs (FT_USER, @user_includes);
404 scan_m4_dirs (FT_AUTOMAKE, @automake_includes);
405 scan_m4_dirs (FT_SYSTEM, @system_includes);
407 # Construct a new function that does the searching. We use a
408 # function (instead of just evaluating $search in the loop) so that
409 # "die" is correctly and easily propagated if run.
410 my $search = "sub search {\nmy \$found = 0;\n";
411 foreach my $key (reverse sort keys %map)
413 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { add_macro ("' . $key
414 . '"); $found = 1; }' . "\n");
416 $search .= "return \$found;\n};\n";
418 prog_error "$@\n search is $search" if $@;
421 ################################################################
423 # Add a macro to the output.
428 # Ignore unknown required macros. Either they are not really
429 # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
430 # should be quiet, or they are needed and Autoconf itself will
431 # complain when we trace for macro usage later.
432 return unless defined $map{$macro};
434 verb "saw macro $macro";
435 $macro_seen{$macro} = 1;
436 add_file ($map{$macro});
439 # scan_configure_dep ($file)
440 # --------------------------
441 # Scan a configure dependency (configure.ac, or separate m4 files)
442 # for uses of known macros and AC_REQUIREs of possibly unknown macros.
443 # Recursively scan m4_included files.
444 sub scan_configure_dep ($)
447 # Do not scan a file twice.
449 if exists $scanned_configure_dep{$file};
450 $scanned_configure_dep{$file} = 1;
452 my $mtime = mtime $file;
453 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
455 my $contents = exists $file_contents{$file} ?
456 $file_contents{$file} : contents $file;
461 foreach (split ("\n", $contents))
464 # Remove comments from current line.
467 # Avoid running all the following regexes on white lines.
470 while (/$m4_include_rx/go)
472 my $ifile = $2 || $3;
473 # Skip missing 'sinclude'd files.
474 next if $1 ne 'm4_' && ! -f $ifile;
478 while (/$ac_require_rx/go)
480 push (@rlist, $1 || $2);
483 # The search function is constructed dynamically by
484 # scan_m4_files. The last parenthetical match makes sure we
485 # don't match things that look like macro assignments or
487 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
489 # Macro not found, but AM_ prefix found.
490 # Make this just a warning, because we do not know whether
491 # the macro is actually used (it could be called conditionally).
492 msg ('unsupported', "$file:$line",
493 "macro '$2' not found in library");
497 add_macro ($_) foreach (@rlist);
498 scan_configure_dep ($_) foreach @ilist;
503 # Add $FILE to output.
508 # Only add a file once.
509 return if ($file_added{$file});
510 $file_added{$file} = 1;
512 scan_configure_dep $file;
515 # Point to the documentation for underquoted AC_DEFUN only once.
516 my $underquoted_manual_once = 0;
518 # scan_file ($TYPE, $FILE, $WHERE)
519 # --------------------------------
520 # Scan a single M4 file ($FILE), and all files it includes.
521 # Return the list of included files.
522 # $TYPE is one of FT_USER, FT_AUTOMAKE, or FT_SYSTEM, depending
523 # on where the file comes from.
524 # $WHERE is the location to use in the diagnostic if the file
528 my ($type, $file, $where) = @_;
529 my $basename = basename $file;
531 # Do not scan the same file twice.
532 return @{$file_includes{$file}} if exists $file_includes{$file};
533 # Prevent potential infinite recursion (if two files include each other).
534 return () if exists $file_contents{$file};
536 unshift @file_order, $file;
538 $file_type{$file} = $type;
540 fatal "$where: file '$file' does not exist" if ! -e $file;
542 my $fh = new Automake::XFile $file;
549 my $serial_older = 0;
551 while ($_ = $fh->getline)
559 if ($line =~ /$serial_line_rx/go)
562 if ($number !~ /$serial_number_rx/go)
564 msg ('syntax', "$file:$.",
565 "ill-formed serial number '$number', "
566 . "expecting a version string with only digits and dots");
570 # aclocal removes all definitions from M4 file with the
571 # same basename if a greater serial number is found.
572 # Encountering a serial after some macros will undefine
574 msg ('syntax', "$file:$.",
575 'the serial number must appear before any macro definition');
577 # We really care about serials only for non-automake macros
578 # and when --install is used. But the above diagnostics are
579 # made regardless of this, because not using --install is
580 # not a reason not the fix macro files.
581 elsif ($install && $type != FT_AUTOMAKE)
584 my @new = split (/\./, $number);
586 verb "$file:$.: serial $number";
588 if (!exists $serial{$basename}
589 || list_compare (@new, @{$serial{$basename}}) > 0)
591 # Delete any definition we knew from the old macro.
592 foreach my $def (@{$invmap{$basename}})
594 verb "$file:$.: ignoring previous definition of $def";
597 $invmap{$basename} = [];
598 $serial{$basename} = \@new;
607 # Remove comments from current line.
608 # Do not do it earlier, because the serial line is a comment.
609 $line =~ s/\bdnl\b.*$//;
612 while ($line =~ /$ac_defun_rx/go)
617 msg ('syntax', "$file:$.", "underquoted definition of $2"
618 . "\n run info Automake 'Extending aclocal'\n"
619 . " or see http://www.gnu.org/software/automake/manual/"
620 . "automake.html#Extending-aclocal")
621 unless $underquoted_manual_once;
622 $underquoted_manual_once = 1;
625 # If this macro does not have a serial and we have already
626 # seen a macro with the same basename earlier, we should
627 # ignore the macro (don't exit immediately so we can still
628 # diagnose later #serial numbers and underquoted macros).
629 $serial_older ||= ($type != FT_AUTOMAKE
630 && !$serial_seen && exists $serial{$basename});
632 my $macro = $1 || $2;
633 if (!$serial_older && !defined $map{$macro})
635 verb "found macro $macro in $file: $.";
636 $map{$macro} = $file;
637 push @{$invmap{$basename}}, $macro;
641 # Note: we used to give an error here if we saw a
642 # duplicated macro. However, this turns out to be
643 # extremely unpopular. It causes actual problems which
644 # are hard to work around, especially when you must
645 # mix-and-match tool versions.
646 verb "ignoring macro $macro in $file: $.";
650 while ($line =~ /$m4_include_rx/go)
652 my $ifile = $2 || $3;
653 # Skip missing 'sinclude'd files.
654 next if $1 ne 'm4_' && ! -f $ifile;
655 push (@inc_files, $ifile);
656 $inc_lines{$ifile} = $.;
660 # Ignore any file that has an old serial (or no serial if we know
661 # another one with a serial).
664 ($type != FT_AUTOMAKE && !$serial_seen && exists $serial{$basename}));
666 $file_contents{$file} = $contents;
668 # For some reason I don't understand, it does not work
669 # to do "map { scan_file ($_, ...) } @inc_files" below.
670 # With Perl 5.8.2 it undefines @inc_files.
671 my @copy = @inc_files;
672 my @all_inc_files = (@inc_files,
673 map { scan_file ($type, $_,
674 "$file:$inc_lines{$_}") } @copy);
675 $file_includes{$file} = \@all_inc_files;
676 return @all_inc_files;
679 # strip_redundant_includes (%FILES)
680 # ---------------------------------
681 # Each key in %FILES is a file that must be present in the output.
682 # However some of these files might already include other files in %FILES,
683 # so there is no point in including them another time.
684 # This removes items of %FILES which are already included by another file.
685 sub strip_redundant_includes (%)
689 # Always include acinclude.m4, even if it does not appear to be used.
690 $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
691 # File included by $configure_ac are redundant.
692 $files{$configure_ac} = 1;
694 # Files at the end of @file_order should override those at the beginning,
695 # so it is important to preserve these trailing files. We can remove
696 # a file A if it is going to be output before a file B that includes
697 # file A, not the converse.
698 foreach my $file (reverse @file_order)
700 next unless exists $files{$file};
701 foreach my $ifile (@{$file_includes{$file}})
703 next unless exists $files{$ifile};
704 delete $files{$ifile};
705 verb "$ifile is already included by $file";
709 # configure.ac is implicitly included.
710 delete $files{$configure_ac};
715 sub trace_used_macros ()
717 my %files = map { $map{$_} => 1 } keys %macro_seen;
718 %files = strip_redundant_includes %files;
720 my $traces = ($ENV{AUTOM4TE} || '@am_AUTOM4TE@');
721 $traces .= " --language Autoconf-without-aclocal-m4 ";
722 # All candidate files.
723 $traces .= join (' ',
725 (grep { exists $files{$_} } @file_order))) . " ";
727 # All candidate macros.
728 $traces .= join (' ',
729 (map { "--trace='$_:\$f::\$n::\$1'" }
733 '_AM_AUTOCONF_VERSION',
734 'AC_CONFIG_MACRO_DIR')),
735 # Do not trace $1 for all other macros as we do
736 # not need it and it might contains harmful
737 # characters (like newlines).
738 (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
740 verb "running $traces $configure_ac";
742 my $tracefh = new Automake::XFile ("$traces $configure_ac |");
744 $ac_config_macro_dir = undef;
748 while ($_ = $tracefh->getline)
751 my ($file, $macro, $arg1) = split (/::/);
753 $traced{$macro} = 1 if exists $macro_seen{$macro};
755 if ($macro eq 'AC_DEFUN' || $macro eq 'AC_DEFUN_ONCE'
756 || $macro eq 'AU_DEFUN')
758 $map_traced_defs{$arg1} = $file;
760 elsif ($macro eq '_AM_AUTOCONF_VERSION')
764 elsif ($macro eq 'AC_CONFIG_MACRO_DIR')
766 $ac_config_macro_dir = $arg1;
775 sub scan_configure ()
777 # Make sure we include acinclude.m4 if it exists.
778 if (-f 'acinclude.m4')
780 add_file ('acinclude.m4');
782 scan_configure_dep ($configure_ac);
785 ################################################################
788 # Return 0 iff some files were installed locally.
789 sub write_aclocal ($@)
791 my ($output_file, @macros) = @_;
795 # Get the list of files containing definitions for the macros used.
796 # (Filter out unused macro definitions with $map_traced_defs. This
797 # can happen when an Autoconf macro is conditionally defined:
798 # aclocal sees the potential definition, but this definition is
799 # actually never processed and the Autoconf implementation is used
804 if (exists $map_traced_defs{$m}
805 && $map{$m} eq $map_traced_defs{$m});
807 # Do not explicitly include a file that is already indirectly included.
808 %files = strip_redundant_includes %files;
812 for my $file (grep { exists $files{$_} } @file_order)
814 # Check the time stamp of this file, and of all files it includes.
815 for my $ifile ($file, @{$file_includes{$file}})
817 my $mtime = mtime $ifile;
818 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
821 # If the file to add looks like outside the project, copy it
822 # to the output. The regex catches filenames starting with
823 # things like '/', '\', or 'c:\'.
824 if ($file_type{$file} != FT_USER
825 || $file =~ m,^(?:\w:)?[\\/],)
827 if (!$install || $file_type{$file} != FT_SYSTEM)
829 # Copy the file into aclocal.m4.
830 $output .= $file_contents{$file} . "\n";
834 # Install the file (and any file it includes).
836 for my $ifile (@{$file_includes{$file}}, $file)
838 install_file ($ifile, $user_includes[0]);
845 # Otherwise, simply include the file.
846 $output .= "m4_include([$file])\n";
852 verb "running aclocal anew, because some files were installed locally";
856 # Nothing to output?!
857 # FIXME: Shouldn't we diagnose this?
858 return 1 if ! length ($output);
862 # Do not use "$output_file" here for the same reason we do not
863 # use it in the header below. autom4te will output the name of
864 # the file in the diagnostic anyway.
865 $output = "m4_ifndef([AC_AUTOCONF_VERSION],
866 [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
867 m4_if(m4_defn([AC_AUTOCONF_VERSION]), [$ac_version],,
868 [m4_warning([this file was generated for autoconf $ac_version.
869 You have another version of autoconf. It may work, but is not guaranteed to.
870 If you have problems, you may need to regenerate the build system entirely.
871 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
876 # We used to print "# $output_file generated automatically etc." But
877 # this creates spurious differences when using autoreconf. Autoreconf
878 # creates aclocal.m4t and then rename it to aclocal.m4, but the
879 # rebuild rules generated by Automake create aclocal.m4 directly --
880 # this would gives two ways to get the same file, with a different
881 # name in the header.
882 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
884 # Copyright (C) 1996-$RELEASE_YEAR Free Software Foundation, Inc.
886 # This file is free software; the Free Software Foundation
887 # gives unlimited permission to copy and/or distribute it,
888 # with or without modifications, as long as this notice is preserved.
890 # This program is distributed in the hope that it will be useful,
891 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
892 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
893 # PARTICULAR PURPOSE.
897 # We try not to update $output_file unless necessary, because
898 # doing so invalidate Autom4te's cache and therefore slows down
899 # tools called after aclocal.
901 # We need to overwrite $output_file in the following situations.
902 # * The --force option is in use.
903 # * One of the dependencies is younger.
904 # (Not updating $output_file in this situation would cause
905 # make to call aclocal in loop.)
906 # * The contents of the current file are different from what
909 && $greatest_mtime < mtime ($output_file)
910 && $output eq contents ($output_file))
912 verb "$output_file unchanged";
916 verb "writing $output_file";
920 if (-e $output_file && !unlink $output_file)
922 fatal "could not remove '$output_file': $!";
924 my $out = new Automake::XFile "> $output_file";
930 ################################################################
932 # Print usage and exit.
938 Usage: aclocal [OPTION]...
940 Generate 'aclocal.m4' by scanning 'configure.ac' or 'configure.in'
943 --automake-acdir=DIR directory holding automake-provided m4 files
944 --system-acdir=DIR directory holding third-party system-wide files
945 --diff[=COMMAND] run COMMAND [diff -u] on M4 files that would be
946 changed (implies --install and --dry-run)
947 --dry-run pretend to, but do not actually update any file
948 --force always update output file
949 --help print this help, then exit
950 -I DIR add directory to search list for .m4 files
951 --install copy third-party files to the first -I directory
952 --output=FILE put output in FILE (default aclocal.m4)
953 --print-ac-dir print name of directory holding system-wide
954 third-party m4 files, then exit
955 --verbose don't be silent
956 --version print version number, then exit
957 -W, --warnings=CATEGORY report the warnings falling in CATEGORY
959 Warning categories include:
960 syntax dubious syntactic constructs (default)
961 unsupported unknown macros (default)
962 all all the warnings (default)
963 no-CATEGORY turn off warnings in CATEGORY
964 none turn off all the warnings
965 error treat warnings as errors
967 Report bugs to <@PACKAGE_BUGREPORT@>.
968 GNU Automake home page: <@PACKAGE_URL@>.
969 General help using GNU software: <http://www.gnu.org/gethelp/>.
974 # Print version and exit.
978 aclocal (GNU $PACKAGE) $VERSION
979 Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
980 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
981 This is free software: you are free to change and redistribute it.
982 There is NO WARRANTY, to the extent permitted by law.
984 Written by Tom Tromey <tromey\@redhat.com>
985 and Alexandre Duret-Lutz <adl\@gnu.org>.
990 # Parse command line.
991 sub parse_arguments ()
993 my $print_and_exit = 0;
998 'help' => sub { usage(0); },
999 'version' => \&version,
1000 'system-acdir=s' => sub { shift; @system_includes = @_; },
1001 'automake-acdir=s' => sub { shift; @automake_includes = @_; },
1002 'diff:s' => \$diff_command,
1003 'dry-run' => \$dry_run,
1004 'force' => \$force_output,
1005 'I=s' => \@user_includes,
1006 'install' => \$install,
1007 'output=s' => \$output_file,
1008 'print-ac-dir' => \$print_and_exit,
1009 'verbose' => sub { setup_channel 'verb', silent => 0; },
1010 'W|warnings=s' => \&parse_warnings,
1013 use Automake::Getopt ();
1014 Automake::Getopt::parse_options %cli_options;
1018 fatal ("non-option arguments are not accepted: '$ARGV[0]'.\n"
1019 . "Try '$0 --help' for more information.");
1022 if ($print_and_exit)
1024 print "@system_includes\n";
1028 if (defined $diff_command)
1030 $diff_command = 'diff -u' if $diff_command eq '';
1031 @diff_command = split (' ', $diff_command);
1036 # Finally, adds any directory listed in the 'dirlist' file.
1037 if (open (DIRLIST, "$system_includes[0]/dirlist"))
1043 # strip off newlines and end-of-line comments
1046 foreach my $dir (glob)
1048 push (@system_includes, $dir) if -d $dir;
1055 # Add any directory listed in the 'ACLOCAL_PATH' environment variable
1056 # to the list of system include directories.
1057 sub parse_ACLOCAL_PATH ()
1059 return if not defined $ENV{"ACLOCAL_PATH"};
1060 # Directories in ACLOCAL_PATH should take precedence over system
1061 # directories, so we use unshift. However, directories that
1062 # come first in ACLOCAL_PATH take precedence over directories
1063 # coming later, which is why the result of split is reversed.
1064 foreach my $dir (reverse split /:/, $ENV{"ACLOCAL_PATH"})
1066 unshift (@system_includes, $dir) if $dir ne '' && -d $dir;
1070 ################################################################
1072 parse_WARNINGS; # Parse the WARNINGS environment variable.
1075 $configure_ac = require_configure_ac;
1077 # We may have to rerun aclocal if some file have been installed, but
1078 # it should not happen more than once. The reason we must run again
1079 # is that once the file has been moved from /usr/share/aclocal/ to the
1080 # local m4/ directory it appears at a new place in the search path,
1081 # hence it should be output at a different position in aclocal.m4. If
1082 # we did not rerun aclocal, the next run of aclocal would produce a
1083 # different aclocal.m4.
1085 my $rerun_due_to_macrodir = 0;
1089 prog_error "too many loops" if $loop > 2 + $rerun_due_to_macrodir;
1095 my %macro_traced = trace_used_macros;
1097 if (!$rerun_due_to_macrodir && defined $ac_config_macro_dir)
1099 # The directory specified by the AC_CONFIG_MACRO_DIR m4 macro
1100 # (if any) must after the user includes specified explicitly
1101 # with the '-I' option.
1102 push @user_includes, $ac_config_macro_dir
1103 if defined $ac_config_macro_dir;
1104 # We might have to scan some new directory of .m4 files.
1105 $rerun_due_to_macrodir++;
1109 if ($install && !@user_includes)
1111 fatal "installation of third-party macros impossible without " .
1112 "-I options nor AC_CONFIG_MACRO_DIR m4 macro";
1115 last if write_aclocal ($output_file, keys %macro_traced);
1122 ### Setup "GNU" style for perl-mode and cperl-mode.
1124 ## perl-indent-level: 2
1125 ## perl-continued-statement-offset: 2
1126 ## perl-continued-brace-offset: 0
1127 ## perl-brace-offset: 0
1128 ## perl-brace-imaginary-offset: 0
1129 ## perl-label-offset: -2
1130 ## cperl-indent-level: 2
1131 ## cperl-brace-offset: 0
1132 ## cperl-continued-brace-offset: 0
1133 ## cperl-label-offset: -2
1134 ## cperl-extra-newline-before-brace: t
1135 ## cperl-merge-trailing-else: nil
1136 ## cperl-continued-statement-offset: 2