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@";
32 unshift @INC, "$perllibdir";
35 use Automake::General;
39 $VERSION = "@VERSION@";
40 $PACKAGE = "@PACKAGE@";
42 # Note that this isn't pkgdatadir, but a separate directory.
43 $acdir = "@datadir@/aclocal";
50 # Name of the top autoconf input: `configure.ac' or `configure.in'.
51 $configure_ac = find_configure_ac;
57 $output_file = 'aclocal.m4';
59 # Which macros have been seen.
62 # Which files have been seen.
65 # Map macro names to file names.
68 # Map file names to file contents.
74 # Map from obsolete macros to hints for new macros.
75 # If you change this, change the corresponding list in automake.in.
76 # FIXME: should just put this into a single file.
79 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
80 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
81 'AC_FEATURE_EXIT' => '',
82 'AC_SYSTEM_HEADER' => '',
84 # Note that we do not handle this one, because it is still run
85 # from AM_CONFIG_HEADER. So we deal with it specially in
86 # &scan_autoconf_files.
87 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
89 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
90 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
91 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
92 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
93 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
94 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
95 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
96 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
97 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
98 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
100 # Now part of autoconf proper, under a different name.
101 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
102 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
103 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
104 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
105 'AM_EXEEXT' => "automatically done by `AC_PROG_(CC|CXX|F77)'",
106 'AM_CYGWIN32' => "use `AC_CYGWIN'",
107 'AM_MINGW32' => "use `AC_MINGW32'",
108 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
110 # These aren't quite obsolete.
114 # Regexp to match the above macros.
115 $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
117 # Matches a macro definition.
118 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
120 # Matches an AC_REQUIRE line.
121 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
125 local (@dirlist) = &parse_arguments (@ARGV);
126 &scan_m4_files (@dirlist);
136 ################################################################
138 # Print usage and exit.
141 local ($status) = @_;
143 print "Usage: aclocal [OPTIONS] ...\n\n";
145 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
147 --acdir=DIR directory holding config files
148 --help print this help, then exit
149 -I DIR add directory to search list for .m4 files
150 --output=FILE put output in FILE (default aclocal.m4)
151 --print-ac-dir print name of directory holding m4 files
152 --verbose don't be silent
153 --version print version number, then exit
155 Report bugs to <bug-automake\@gnu.org>.\n";
160 # Parse command line.
163 local (@arglist) = @_;
165 local ($print_and_exit) = 0;
169 if ($arglist[0] =~ /^--acdir=(.+)$/)
173 elsif ($arglist[0] =~/^--output=(.+)$/)
177 elsif ($arglist[0] eq '-I')
180 push (@dirlist, $arglist[0]);
182 elsif ($arglist[0] eq '--print-ac-dir')
186 elsif ($arglist[0] eq '--verbose')
190 elsif ($arglist[0] eq '--version')
192 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
193 print "Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.\n";
194 print "This is free software; see the source for copying conditions. There is NO\n";
195 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
196 print "Written by Tom Tromey <tromey\@cygnus.com>\n";
199 elsif ($arglist[0] eq '--help')
205 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
217 # Search our install directory last.
218 push (@dirlist, $acdir);
223 ################################################################
227 die "aclocal: `configure.ac' or `configure.in' is required\n"
230 open (CONFIGURE, $configure_ac)
231 || die "aclocal: couldn't open `$configure_ac': $!\n";
233 # Make sure we include acinclude.m4 if it exists.
234 if (-f 'acinclude.m4')
236 &add_file ('acinclude.m4');
241 # Remove comments from current line.
248 if ($obsolete_macros{$1} ne '')
250 $hint = '; ' . $obsolete_macros{$1};
252 warn "aclocal: $configure_ac: $.: `$1' is obsolete$hint\n";
257 # Search for things we know about. The "search" sub is
258 # constructed dynamically by scan_m4_files. The last
259 # parenthethical match makes sure we don't match things that
260 # look like macro assignments or AC_SUBSTs.
261 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
263 # Macro not found, but AM_ prefix found.
264 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
272 ################################################################
274 # Check macros in acinclude.m4. If one is not used, warn.
279 foreach $key (keys %map)
281 next unless $map{$key} eq 'acinclude.m4';
282 if (! $macro_seen{$key})
284 # FIXME: should print line number of acinclude.m4.
285 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
290 ################################################################
292 # Scan all the installed m4 files and construct a map.
295 local (@dirlist) = @_;
297 # First, scan acinclude.m4 if it exists.
298 if (-f 'acinclude.m4')
300 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
304 foreach $m4dir (@dirlist)
306 opendir (DIR, $m4dir)
307 || die "aclocal: couldn't open directory `$m4dir': $!\n";
308 local ($file, $fullfile);
309 foreach $file (sort grep (! /^\./, readdir (DIR)))
311 # Only examine .m4 files.
312 next unless $file =~ /\.m4$/;
314 # Skip some files when running out of srcdir.
315 next if $file eq 'aclocal.m4';
317 $fullfile = $m4dir . '/' . $file;
318 $file_contents{$fullfile} = &scan_file ($fullfile);
323 # Construct a new function that does the searching. We use a
324 # function (instead of just evalling $search in the loop) so that
325 # "die" is correctly and easily propagated if run.
326 my $search = "sub search {\nmy \$found = 0;\n";
327 foreach my $key (reverse sort keys %map)
329 # EXPR is a regexp matching the name of the macro.
330 (my $expr = $key) =~ s/(\W)/\\$1/g;
331 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
332 . '); $found = 1; }' . "\n");
334 $search .= "return \$found;\n};\n";
336 die "internal error: $@\n search is $search" if $@;
339 ################################################################
341 # Add a macro to the output.
346 # We want to ignore AC_ macros. However, if an AC_ macro is
347 # defined in (eg) acinclude.m4, then we want to make sure we mark
349 return if $macro =~ /^AC_/ && ! defined $map{$macro};
351 if (! defined $map{$macro})
353 warn "aclocal: macro `$macro' required but not defined\n";
358 print STDERR "aclocal: saw macro $macro\n" if $verbose;
359 $macro_seen{$macro} = 1;
360 &add_file ($map{$macro});
363 # Add a file to output.
368 # Only add a file once.
369 return if ($file_seen{$file});
370 $file_seen{$file} = 1;
372 $output .= $file_contents{$file} . "\n";
374 foreach (split ("\n", $file_contents{$file}))
376 # This is a hack for Perl 4.
378 if ($a =~ /$ac_require_rx/g)
383 # Remove comments from current line.
387 # The search function is constructed dynamically by
388 # scan_m4_files. The last parenthethical match makes sure we
389 # don't match things that look like macro assignments or
391 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
393 # Macro not found, but AM_ prefix found.
394 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
400 foreach $macro (@rlist)
406 # Scan a single M4 file. Return contents.
411 my $fh = new Automake::XFile $file;
413 while ($_ = $fh->getline)
422 if (! defined $map{$1})
427 # Note: we used to give an error here if we saw a
428 # duplicated macro. However, this turns out to be
429 # extremely unpopular. It causes actual problems which
430 # are hard to work around, especially when you must
431 # mix-and-match tool versions.
433 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
440 ################################################################
445 return if ! length ($output);
447 print STDERR "aclocal: writing $output_file\n" if $verbose;
449 my $out = new Automake::XFile "> $output_file";
451 "# $output_file generated automatically by aclocal $VERSION -*- Autoconf -*-
453 # Copyright 1996, 1997, 1998, 1999, 2000, 2001
454 # Free Software Foundation, Inc.
455 # This file is free software; the Free Software Foundation
456 # gives unlimited permission to copy and/or distribute it,
457 # with or without modifications, as long as this notice is preserved.
459 # This program is distributed in the hope that it will be useful,
460 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
461 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
462 # PARTICULAR PURPOSE.