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.
81 # Now part of autoconf proper, under a different name.
85 # These aren't quite obsolete.
92 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
94 # Matches a macro definition.
95 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
97 # Matches an AC_REQUIRE line.
98 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
102 local (@dirlist) = &parse_arguments (@ARGV);
103 &scan_m4_files ($acdir, @dirlist);
113 ################################################################
115 # Print usage and exit.
118 local ($status) = @_;
120 print "Usage: aclocal [OPTIONS] ...\n";
122 --acdir=DIR directory holding config files
123 --help print this help, then exit
124 -I DIR add directory to search list for .m4 files
125 --output=FILE put output in FILE (default aclocal.m4)
126 --verbose don't be silent
127 --version print version number, then exit
129 Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
134 # Parse command line.
137 local (@arglist) = @_;
142 if ($arglist[0] =~ /^--acdir=(.+)$/)
146 elsif ($arglist[0] =~/^--output=(.+)$/)
150 elsif ($arglist[0] eq '-I')
153 push (@dirlist, $arglist[0]);
155 elsif ($arglist[0] eq '--verbose')
159 elsif ($arglist[0] eq '--version')
161 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
162 print "Copyright (C) 1996, 1997 Free Software Foundation, Inc.\n";
163 print "This is free software; see the source for copying conditions. There is NO\n";
164 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
165 print "Written by Tom Tromey <tromey\@cygnus.com>\n";
168 elsif ($arglist[0] eq '--help')
174 die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
183 ################################################################
187 open (CONFIGURE, "configure.in")
188 || die "aclocal: couldn't open \`configure.in': $!\n";
190 # Make sure we include acinclude.m4 if it exists.
191 if (-f 'acinclude.m4')
193 &add_file ('acinclude.m4');
198 # Remove comments from current line.
205 warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
210 # Search for things we know about. The "search" sub is
211 # constructed dynamically, above.
218 ################################################################
220 # Check macros in acinclude.m4. If one is not used, warn.
225 foreach $key (keys %map)
227 next unless $map{$key} eq 'acinclude.m4';
228 if (! $macro_seen{$key})
230 warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
235 ################################################################
237 # Scan all the installed m4 files and construct a map.
240 local (@dirlist) = @_;
242 # First, scan acinclude.m4 if it exists.
243 if (-f 'acinclude.m4')
245 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
249 foreach $m4dir (@dirlist)
251 opendir (DIR, $m4dir)
252 || die "aclocal: couldn't open directory \`$m4dir': $!\n";
253 local ($file, $fullfile, $expr);
254 foreach $file (sort grep (! /^\./, readdir (DIR)))
256 # Only examine .m4 files.
257 next unless $file =~ /\.m4$/;
259 # Skip some files when running out of srcdir.
260 next if $file eq 'aclocal.m4';
262 $fullfile = $m4dir . '/' . $file;
263 $file_contents{$fullfile} = &scan_file ($fullfile);
268 # Construct a new function that does the searching. We use a
269 # function (instead of just evalling $search in the loop) so that
270 # "die" is correctly and easily propagated if run.
271 local ($search, $expr, $key) = '';
272 foreach $key (keys %map)
274 # EXPR is a regexp matching the name of the macro.
275 ($expr = $key) =~ s/(\W)/\\$1/g;
276 $search .= "&add_macro ('" . $key . "') if /" . $expr . "/;\n";
278 eval 'sub search { ' . $search . '};';
279 die "internal error: $@\n search is $search " if $@;
282 ################################################################
284 # Add a macro to the output.
290 return if $macro =~ /^AC_/;
292 if (! defined $map{$macro})
294 warn "aclocal: macro \`$macro' required but not defined\n";
299 print STDERR "saw macro $macro\n" if $verbosity;
300 $macro_seen{$macro} = 1;
301 &add_file ($map{$macro});
304 # Add a file to output.
309 # Only add a file once.
310 return if ($file_seen{$file});
311 $file_seen{$file} = 1;
313 $output .= $file_contents{$file} . "\n";
315 foreach (split ("\n", $file_contents{$file}))
317 if (/$ac_require_rx/g)
322 # This function constructed dynamically.
327 foreach $macro (@rlist)
333 # Scan a single M4 file. Return contents.
339 || die "aclocal: couldn't open \`$file': $!\n";
340 local ($contents) = '';
350 if (!defined $map{$1})
354 # Allow acinclude.m4 to override other macro files.
355 elsif ($map{$1} ne 'acinclude.m4' || $file eq 'acinclude.m4')
357 warn "aclocal: $file: $.: duplicated macro \`$1'\n";
360 print STDERR "Found macro $1 in $file: $.\n" if $verbosity;
368 ################################################################
373 return if ! length ($output);
375 print STDERR "Writing aclocal.m4\n" if $verbosity;
377 open (ACLOCAL, "> aclocal.m4")
378 || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
379 print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
380 print ACLOCAL $output;