5 # aclocal - create aclocal.m4 by scanning configure.in
6 # Copyright (C) 1996, 1997, 1998 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.
81 # Now part of autoconf proper, under a different name.
85 # 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 local (@dirlist) = &parse_arguments (@ARGV);
102 &scan_m4_files ($acdir, @dirlist);
112 ################################################################
114 # Print usage and exit.
117 local ($status) = @_;
119 print "Usage: aclocal [OPTIONS] ...\n\n";
120 print "Generate aclocal.m4 by scanning configure.in\n
121 --acdir=DIR directory holding config files
122 --help print this help, then exit
123 -I DIR add directory to search list for .m4 files
124 --output=FILE put output in FILE (default aclocal.m4)
125 --print-ac-dir print name of directory holding m4 files
126 --verbose don't be silent
127 --version print version number, then exit
129 Report bugs to <bug-automake\@gnu.org>.\n";
134 # Parse command line.
137 local (@arglist) = @_;
139 local ($print_and_exit) = 0;
143 if ($arglist[0] =~ /^--acdir=(.+)$/)
147 elsif ($arglist[0] =~/^--output=(.+)$/)
151 elsif ($arglist[0] eq '-I')
154 push (@dirlist, $arglist[0]);
156 elsif ($arglist[0] eq '--print-ac-dir')
160 elsif ($arglist[0] eq '--verbose')
164 elsif ($arglist[0] eq '--version')
166 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
167 print "Copyright (C) 1998 Free Software Foundation, Inc.\n";
168 print "This is free software; see the source for copying conditions. There is NO\n";
169 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
170 print "Written by Tom Tromey <tromey\@cygnus.com>\n";
173 elsif ($arglist[0] eq '--help')
179 die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
194 ################################################################
198 open (CONFIGURE, "configure.in")
199 || die "aclocal: couldn't open \`configure.in': $!\n";
201 # Make sure we include acinclude.m4 if it exists.
202 if (-f 'acinclude.m4')
204 &add_file ('acinclude.m4');
209 # Remove comments from current line.
216 warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
221 # Search for things we know about. The "search" sub is
222 # constructed dynamically by scan_m4_files.
223 if (! &search && /(^|\s+)(AM_[A-Z_]+)/)
225 # Macro not found, but AM_ prefix found.
226 warn "aclocal: configure.in: $.: macro \`$2' not found in library\n";
234 ################################################################
236 # Check macros in acinclude.m4. If one is not used, warn.
241 foreach $key (keys %map)
243 next unless $map{$key} eq 'acinclude.m4';
244 if (! $macro_seen{$key})
246 # FIXME: should print line number of acinclude.m4.
247 warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
252 ################################################################
254 # Scan all the installed m4 files and construct a map.
257 local (@dirlist) = @_;
259 # First, scan acinclude.m4 if it exists.
260 if (-f 'acinclude.m4')
262 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
266 foreach $m4dir (@dirlist)
268 opendir (DIR, $m4dir)
269 || die "aclocal: couldn't open directory \`$m4dir': $!\n";
270 local ($file, $fullfile, $expr);
271 foreach $file (sort grep (! /^\./, readdir (DIR)))
273 # Only examine .m4 files.
274 next unless $file =~ /\.m4$/;
276 # Skip some files when running out of srcdir.
277 next if $file eq 'aclocal.m4';
279 $fullfile = $m4dir . '/' . $file;
280 $file_contents{$fullfile} = &scan_file ($fullfile);
285 # Construct a new function that does the searching. We use a
286 # function (instead of just evalling $search in the loop) so that
287 # "die" is correctly and easily propagated if run.
288 local ($search, $expr, $key) = '';
289 foreach $key (reverse sort keys %map)
291 # EXPR is a regexp matching the name of the macro.
292 ($expr = $key) =~ s/(\W)/\\$1/g;
293 $search .= ("if (/" . $expr . "/) { & add_macro (" . $key
294 . "); return 1; }\n");
296 $search .= "return 0;\n";
297 eval 'sub search { ' . $search . '};';
298 die "internal error: $@\n search is $search " if $@;
301 ################################################################
303 # Add a macro to the output.
308 # We want to ignore AC_ macros. However, if an AC_ macro is
309 # defined in (eg) acinclude.m4, then we want to make sure we mark
311 return if $macro =~ /^AC_/ && ! defined $map{$macro};
313 if (! defined $map{$macro})
315 warn "aclocal: macro \`$macro' required but not defined\n";
320 print STDERR "saw macro $macro\n" if $verbosity;
321 $macro_seen{$macro} = 1;
322 &add_file ($map{$macro});
325 # Add a file to output.
330 # Only add a file once.
331 return if ($file_seen{$file});
332 $file_seen{$file} = 1;
334 $output .= $file_contents{$file} . "\n";
336 foreach (split ("\n", $file_contents{$file}))
338 # This is a hack for Perl 4.
340 if ($a =~ /$ac_require_rx/g)
345 # This function constructed dynamically.
346 if (! &search && /(^|\s+)(AM_[A-Z_]+)/)
348 # Macro not found, but AM_ prefix found.
349 warn "aclocal: configure.in: $.: macro \`$2' not found in library\n";
355 foreach $macro (@rlist)
361 # Scan a single M4 file. Return contents.
367 || die "aclocal: couldn't open \`$file': $!\n";
368 local ($contents) = '';
378 if (!defined $map{$1})
382 # Allow acinclude.m4 to override other macro files.
383 elsif ($map{$1} ne 'acinclude.m4' || $file eq 'acinclude.m4')
385 warn "aclocal: $file: $.: duplicated macro \`$1'\n";
388 print STDERR "Found macro $1 in $file: $.\n" if $verbosity;
396 ################################################################
401 return if ! length ($output);
403 print STDERR "Writing $output_file\n" if $verbosity;
405 open (ACLOCAL, "> " . $output_file)
406 || die "aclocal: couldn't open \`$output_file' for writing: $!\n";
407 print ACLOCAL "dnl $output_file generated automatically by aclocal $VERSION\n";
409 dnl Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
410 dnl This file is free software; the Free Software Foundation
411 dnl gives unlimited permission to copy and/or distribute it,
412 dnl with or without modifications, as long as this notice is preserved.
414 dnl This program is distributed in the hope that it will be useful,
415 dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
416 dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
417 dnl PARTICULAR PURPOSE.
420 print ACLOCAL $output;