5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
8 # aclocal - create aclocal.m4 by scanning configure.ac
9 # Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 # Written by Tom Tromey <tromey@cygnus.com>.
30 my $prefix = "@prefix@";
31 my $perllibdir = $ENV{'perllibdir'} || "@datadir@/@PACKAGE@-@APIVERSION@";
32 unshift @INC, "$perllibdir";
35 use Automake::General;
39 $VERSION = "@VERSION@";
40 $APIVERSION = "@APIVERSION@";
41 $PACKAGE = "@PACKAGE@";
43 # Note that this isn't pkgdatadir, but a separate directory.
44 # Note also that the versioned directory is handled later.
45 $acdir = "@datadir@/aclocal";
46 $default_acdir = $acdir;
53 # Name of the top autoconf input: `configure.ac' or `configure.in'.
54 $configure_ac = find_configure_ac;
60 $output_file = 'aclocal.m4';
62 # Which macros have been seen.
65 # Which files have been seen.
68 # Map macro names to file names.
71 # Map file names to file contents.
77 # Map from obsolete macros to hints for new macros.
78 # If you change this, change the corresponding list in automake.in.
79 # FIXME: should just put this into a single file.
82 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
83 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
84 'AC_FEATURE_EXIT' => '',
85 'AC_SYSTEM_HEADER' => '',
87 # Note that we do not handle this one, because it is still run
88 # from AM_CONFIG_HEADER. So we deal with it specially in
89 # &scan_autoconf_files.
90 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
92 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
93 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
94 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
95 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
96 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
97 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
98 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
99 'md_TYPE_PTRDIFF_T' => "add `ptrdiff_t' to `AC_CHECK_TYPES(...)'",
100 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
101 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
103 # Now part of autoconf proper, under a different name.
104 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
105 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
106 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
107 'AM_EXEEXT' => "automatically done by `AC_PROG_(CC|CXX|F77)'",
108 'AM_CYGWIN32' => "use `AC_CYGWIN'",
109 'AM_MINGW32' => "use `AC_MINGW32'",
110 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
113 # Regexp to match the above macros.
114 $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
116 # Matches a macro definition.
117 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
119 # Matches an AC_REQUIRE line.
120 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
124 local (@dirlist) = &parse_arguments (@ARGV);
125 &scan_m4_files (@dirlist);
135 ################################################################
137 # Print usage and exit.
140 local ($status) = @_;
142 print "Usage: aclocal [OPTIONS] ...\n\n";
144 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
146 --acdir=DIR directory holding config files
147 --help print this help, then exit
148 -I DIR add directory to search list for .m4 files
149 --output=FILE put output in FILE (default aclocal.m4)
150 --print-ac-dir print name of directory holding m4 files
151 --verbose don't be silent
152 --version print version number, then exit
154 Report bugs to <bug-automake\@gnu.org>.\n";
159 # Parse command line.
162 local (@arglist) = @_;
164 local ($print_and_exit) = 0;
168 if ($arglist[0] =~ /^--acdir=(.+)$/)
172 elsif ($arglist[0] =~/^--output=(.+)$/)
176 elsif ($arglist[0] eq '-I')
179 push (@dirlist, $arglist[0]);
181 elsif ($arglist[0] eq '--print-ac-dir')
185 elsif ($arglist[0] eq '--verbose')
189 elsif ($arglist[0] eq '--version')
191 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
192 print "Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.\n";
193 print "This is free software; see the source for copying conditions. There is NO\n";
194 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
195 print "Written by Tom Tromey <tromey\@cygnus.com>\n";
198 elsif ($arglist[0] eq '--help')
204 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
216 # Search the versioned directory near the end, and then the
217 # unversioned directory last. Only do this if the user didn't
219 push (@dirlist, "$acdir-$APIVERSION")
220 if $acdir eq $default_acdir;
222 # By default $(datadir)/aclocal doesn't exist. We don't want to
223 # get an error in the case where we are searching the default
224 # directory and it hasn't been created.
225 push (@dirlist, $acdir)
226 unless $acdir eq $default_acdir && ! -d $acdir;
231 ################################################################
235 die "aclocal: `configure.ac' or `configure.in' is required\n"
238 open (CONFIGURE, $configure_ac)
239 || die "aclocal: couldn't open `$configure_ac': $!\n";
241 # Make sure we include acinclude.m4 if it exists.
242 if (-f 'acinclude.m4')
244 &add_file ('acinclude.m4');
249 # Remove comments from current line.
256 if ($obsolete_macros{$1} ne '')
258 $hint = '; ' . $obsolete_macros{$1};
260 warn "aclocal: $configure_ac: $.: `$1' is obsolete$hint\n";
265 # Search for things we know about. The "search" sub is
266 # constructed dynamically by scan_m4_files. The last
267 # parenthethical match makes sure we don't match things that
268 # look like macro assignments or AC_SUBSTs.
269 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
271 # Macro not found, but AM_ prefix found.
272 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
280 ################################################################
282 # Check macros in acinclude.m4. If one is not used, warn.
287 foreach $key (keys %map)
289 next unless $map{$key} eq 'acinclude.m4';
290 if (! $macro_seen{$key})
292 # FIXME: should print line number of acinclude.m4.
293 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
298 ################################################################
300 # Scan all the installed m4 files and construct a map.
303 local (@dirlist) = @_;
305 # First, scan acinclude.m4 if it exists.
306 if (-f 'acinclude.m4')
308 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
312 foreach $m4dir (@dirlist)
314 opendir (DIR, $m4dir)
315 || die "aclocal: couldn't open directory `$m4dir': $!\n";
316 local ($file, $fullfile);
317 foreach $file (sort grep (! /^\./, readdir (DIR)))
319 # Only examine .m4 files.
320 next unless $file =~ /\.m4$/;
322 # Skip some files when running out of srcdir.
323 next if $file eq 'aclocal.m4';
325 $fullfile = $m4dir . '/' . $file;
326 $file_contents{$fullfile} = &scan_file ($fullfile);
331 # Construct a new function that does the searching. We use a
332 # function (instead of just evalling $search in the loop) so that
333 # "die" is correctly and easily propagated if run.
334 my $search = "sub search {\nmy \$found = 0;\n";
335 foreach my $key (reverse sort keys %map)
337 # EXPR is a regexp matching the name of the macro.
338 (my $expr = $key) =~ s/(\W)/\\$1/g;
339 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
340 . '); $found = 1; }' . "\n");
342 $search .= "return \$found;\n};\n";
344 die "internal error: $@\n search is $search" if $@;
347 ################################################################
349 # Add a macro to the output.
354 # We want to ignore AC_ macros. However, if an AC_ macro is
355 # defined in (eg) acinclude.m4, then we want to make sure we mark
357 return if $macro =~ /^AC_/ && ! defined $map{$macro};
359 if (! defined $map{$macro})
361 warn "aclocal: macro `$macro' required but not defined\n";
366 print STDERR "aclocal: saw macro $macro\n" if $verbose;
367 $macro_seen{$macro} = 1;
368 &add_file ($map{$macro});
371 # Add a file to output.
376 # Only add a file once.
377 return if ($file_seen{$file});
378 $file_seen{$file} = 1;
380 $output .= $file_contents{$file} . "\n";
382 foreach (split ("\n", $file_contents{$file}))
384 # This is a hack for Perl 4.
386 if ($a =~ /$ac_require_rx/g)
391 # Remove comments from current line.
395 # The search function is constructed dynamically by
396 # scan_m4_files. The last parenthethical match makes sure we
397 # don't match things that look like macro assignments or
399 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
401 # Macro not found, but AM_ prefix found.
402 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
408 foreach $macro (@rlist)
414 # Scan a single M4 file. Return contents.
419 my $fh = new Automake::XFile $file;
421 while ($_ = $fh->getline)
430 if (! defined $map{$1})
435 # Note: we used to give an error here if we saw a
436 # duplicated macro. However, this turns out to be
437 # extremely unpopular. It causes actual problems which
438 # are hard to work around, especially when you must
439 # mix-and-match tool versions.
441 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
448 ################################################################
453 return if ! length ($output);
455 print STDERR "aclocal: writing $output_file\n" if $verbose;
457 my $out = new Automake::XFile "> $output_file";
459 "# $output_file generated automatically by aclocal $VERSION -*- Autoconf -*-
461 # Copyright 1996, 1997, 1998, 1999, 2000, 2001
462 # Free Software Foundation, Inc.
463 # This file is free software; the Free Software Foundation
464 # gives unlimited permission to copy and/or distribute it,
465 # with or without modifications, as long as this notice is preserved.
467 # This program is distributed in the hope that it will be useful,
468 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
469 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
470 # PARTICULAR PURPOSE.