5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
8 # aclocal - scan configure.in and generate aclocal.m4.
11 $VERSION = "@VERSION@";
12 $PACKAGE = "@PACKAGE@";
14 # Note that this isn't pkgdatadir, but a separate directory.
15 $acdir = "@datadir@/aclocal";
26 $output_file = 'aclocal.m4';
28 # Which macros have been seen.
31 # Which files have been seen.
53 # These aren't quite obsolete.
60 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
64 &parse_arguments (@ARGV);
73 ################################################################
75 # Print usage and exit.
80 print "Usage: aclocal [OPTIONS] ...\n";
82 --acdir=DIR directory holding config files
83 --help print this help, then exit
84 --output=FILE put output in FILE (default aclocal.m4)
85 --verbose don't be silent
86 --version print version number, then exit
88 Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
96 local (@arglist) = @_;
100 if ($arglist[0] =~ /^--acdir=(.+)$/)
104 elsif ($arglist[0] =~/^--output=(.+)$/)
108 elsif ($arglist[0] eq '--verbose')
112 elsif ($arglist[0] eq '--version')
114 print "aclocal - GNU $PACKAGE $VERSION\n";
117 elsif ($arglist[0] eq '--help')
130 ################################################################
134 # First, construct list of regexps to match the things we actually
136 opendir (DIR, $acdir)
137 || die "aclocal: couldn't open directory \`$acdir': $!\n";
138 local ($search, $elt);
139 foreach (sort grep (! /^\./, readdir (DIR)))
141 # Only examine .m4 files.
142 next unless s/\.m4$//;
144 # Skip some files when running out of srcdir. Eg "aclocal.m4"
146 next unless /^[A-Za-z]+_[A-Z_]+$/;
148 print STDERR "Finding $_\n" if $verbosity;
149 ($elt = $_) =~ s/(\W)/\\$1/g;
150 $search .= "&add_file (\"$elt\") if /$elt/;\n";
154 # Construct a new function that does the searching. We use a
155 # function (instead of just evalling $search in the loop) so that
156 # "die" is correctly and easily propagated if run.
157 eval 'sub search { ' . $search . '};';
159 open (CONFIGURE, "configure.in")
160 || die "aclocal: couldn't open \`configure.in': $!\n";
164 # Remove comments from current line.
171 warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
176 # Search for things we know about. The "search" sub is
177 # constructed dynamically, above.
183 # Include this file if it exists
184 if (-f 'acinclude.m4')
186 &add_file ('acinclude.m4');
190 ################################################################
192 # Add a file to output.
196 local ($fullfile) = $file;
198 return if ($file_seen{$file});
199 $file_seen{$file} = 1;
203 $fullfile = $acdir . '/' . $file . '.m4';
206 # Maybe the file is an Autoconf built-in. Check the only
207 # way we know how. Suggestions on how to make this better
208 # are welcome. FIXME should give file and line number of
210 return if $file =~ /^AC_[A-Z_]+$/;
211 die "aclocal: file \`$file' not found\n";
215 open (FILE, $fullfile)
216 || die "aclocal: couldn't open \`$fullfile': $!\n";
223 # See if we're defining a macro that was already seen. This
224 # is mostly a special case for `acinclude.m4'.
225 if (/AC_DEFUN\(\[?([^])\n]+)\]?/)
227 if ($1 ne $file && $file_seen{$1})
229 warn "aclocal: $fullfile: $.: duplicated macro \`$1'\n";
235 # See if some other macro is required.
236 if (/AC_REQUIRE\(\[?([^])]*)\]?\)/)
238 push (@rlist, $1) unless defined $macro_seen{$1};
244 foreach $file (@rlist)
250 ################################################################
257 print STDERR "Writing aclocal.m4\n" if $verbosity;
259 open (ACLOCAL, "> aclocal.m4")
260 || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
261 print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
262 print ACLOCAL $output;