5 # aclocal - create aclocal.m4 by scanning configure.in
6 # Copyright (C) 1996 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 # Written by Tom Tromey <tromey@cygnus.com>.
25 eval 'exec @PERL@ -S $0 ${1+"$@"}'
28 # aclocal - scan configure.in and generate aclocal.m4.
31 $VERSION = "@VERSION@";
32 $PACKAGE = "@PACKAGE@";
34 # Note that this isn't pkgdatadir, but a separate directory.
35 $acdir = "@datadir@/aclocal";
46 $output_file = 'aclocal.m4';
48 # Which macros have been seen.
51 # Which files have been seen.
54 # Map macro names to file names.
57 # Map file names to file contents.
80 # Now part of autoconf proper, under a different name.
84 # These aren't quite obsolete.
91 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
93 # Matches a macro definition.
94 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
96 # Matches an AC_REQUIRE line.
97 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
101 &parse_arguments (@ARGV);
102 &scan_m4_files ($acdir);
112 ################################################################
114 # Print usage and exit.
117 local ($status) = @_;
119 print "Usage: aclocal [OPTIONS] ...\n";
121 --acdir=DIR directory holding config files
122 --help print this help, then exit
123 --output=FILE put output in FILE (default aclocal.m4)
124 --verbose don't be silent
125 --version print version number, then exit
127 Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
132 # Parse command line.
135 local (@arglist) = @_;
139 if ($arglist[0] =~ /^--acdir=(.+)$/)
143 elsif ($arglist[0] =~/^--output=(.+)$/)
147 elsif ($arglist[0] eq '--verbose')
151 elsif ($arglist[0] eq '--version')
153 print "aclocal (GNU $PACKAGE) $VERSION\n";
154 print "Copyright (C) 1996 Free Software Foundation, Inc.\n";
155 print "aclocal comes with ABSOLUTELY NO WARRANTY.\n";
156 print "You may redistribute copies of aclocal\n";
157 print "under the terms of the GNU General Public License.\n";
158 print "For more information about these matters, see the file named COPYING.\n";
161 elsif ($arglist[0] eq '--help')
167 die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
174 ################################################################
178 open (CONFIGURE, "configure.in")
179 || die "aclocal: couldn't open \`configure.in': $!\n";
181 # Make sure we include acinclude.m4 if it exists.
182 if (-f 'acinclude.m4')
184 &add_file ('acinclude.m4');
189 # Remove comments from current line.
196 warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
201 # Search for things we know about. The "search" sub is
202 # constructed dynamically, above.
209 ################################################################
211 # Check macros in acinclude.m4. If one is not used, warn.
216 foreach $key (keys %map)
218 next unless $map{$key} eq 'acinclude.m4';
219 if (! $macro_seen{$key})
221 warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
226 ################################################################
228 # Scan all the installed m4 files and construct a map.
233 # First, scan acinclude.m4 if it exists.
234 if (-f 'acinclude.m4')
236 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
239 opendir (DIR, $m4dir)
240 || die "aclocal: couldn't open directory \`$m4dir': $!\n";
241 local ($file, $fullfile, $expr);
242 foreach $file (sort grep (! /^\./, readdir (DIR)))
244 # Only examine .m4 files.
245 next unless $file =~ /\.m4$/;
247 # Skip some files when running out of srcdir.
248 next if $file eq 'aclocal.m4';
250 $fullfile = $m4dir . '/' . $file;
251 $file_contents{$fullfile} = &scan_file ($fullfile);
255 # Construct a new function that does the searching. We use a
256 # function (instead of just evalling $search in the loop) so that
257 # "die" is correctly and easily propagated if run.
258 local ($search, $expr, $key);
259 foreach $key (keys %map)
261 # EXPR is a regexp matching the name of the macro.
262 ($expr = $key) =~ s/(\W)/\\$1/g;
263 $search .= "&add_macro ('" . $key . "') if /" . $expr . "/;\n";
265 eval 'sub search { ' . $search . '};';
266 die "internal error: $@\n search is $search " if $@;
269 ################################################################
271 # Add a macro to the output.
277 return if $macro =~ /^AC_/;
279 if (! defined $map{$macro})
281 warn "aclocal: macro \`$macro' required but not defined\n";
286 print STDERR "saw macro $macro\n" if $verbosity;
287 $macro_seen{$macro} = 1;
288 &add_file ($map{$macro});
291 # Add a file to output.
296 # Only add a file once.
297 return if ($file_seen{$file});
298 $file_seen{$file} = 1;
300 $output .= $file_contents{$file} . "\n";
302 foreach (split ("\n", $file_contents{$file}))
304 if (/$ac_require_rx/g)
309 # This function constructed dynamically.
314 foreach $macro (@rlist)
320 # Scan a single M4 file. Return contents.
326 || die "aclocal: couldn't open \`$file': $!\n";
327 local ($contents) = '';
337 if (defined $map{$1})
339 warn "aclocal: $file: $.: duplicated macro \`$1'\n";
342 print STDERR "Found macro $1 in $file\n" if $verbosity;
351 ################################################################
356 return if ! length ($output);
358 print STDERR "Writing aclocal.m4\n" if $verbosity;
360 open (ACLOCAL, "> aclocal.m4")
361 || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
362 print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
363 print ACLOCAL $output;