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@-@VERSION@";
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 # Note also that the versioned directory is handled later.
44 $acdir = "@datadir@/aclocal";
45 $default_acdir = $acdir;
52 # Name of the top autoconf input: `configure.ac' or `configure.in'.
53 $configure_ac = find_configure_ac;
59 $output_file = 'aclocal.m4';
61 # Which macros have been seen.
64 # Which files have been seen.
67 # Map macro names to file names.
70 # Map file names to file contents.
76 # Map from obsolete macros to hints for new macros.
77 # If you change this, change the corresponding list in automake.in.
78 # FIXME: should just put this into a single file.
81 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
82 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
83 'AC_FEATURE_EXIT' => '',
84 'AC_SYSTEM_HEADER' => '',
86 # Note that we do not handle this one, because it is still run
87 # from AM_CONFIG_HEADER. So we deal with it specially in
88 # &scan_autoconf_files.
89 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
91 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
92 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
93 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
94 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
95 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
96 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
97 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
98 'md_TYPE_PTRDIFF_T' => "add `ptrdiff_t' to `AC_CHECK_TYPES(...)'",
99 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
100 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
102 # Now part of autoconf proper, under a different name.
103 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
104 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
105 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
106 'AM_EXEEXT' => "automatically done by `AC_PROG_(CC|CXX|F77)'",
107 'AM_CYGWIN32' => "use `AC_CYGWIN'",
108 'AM_MINGW32' => "use `AC_MINGW32'",
109 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
112 # Regexp to match the above macros.
113 $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
115 # Matches a macro definition.
116 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
118 # Matches an AC_REQUIRE line.
119 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
123 local (@dirlist) = &parse_arguments (@ARGV);
124 &scan_m4_files (@dirlist);
134 ################################################################
136 # Print usage and exit.
139 local ($status) = @_;
141 print "Usage: aclocal [OPTIONS] ...\n\n";
143 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
145 --acdir=DIR directory holding config files
146 --help print this help, then exit
147 -I DIR add directory to search list for .m4 files
148 --output=FILE put output in FILE (default aclocal.m4)
149 --print-ac-dir print name of directory holding m4 files
150 --verbose don't be silent
151 --version print version number, then exit
153 Report bugs to <bug-automake\@gnu.org>.\n";
158 # Parse command line.
161 local (@arglist) = @_;
163 local ($print_and_exit) = 0;
167 if ($arglist[0] =~ /^--acdir=(.+)$/)
171 elsif ($arglist[0] =~/^--output=(.+)$/)
175 elsif ($arglist[0] eq '-I')
178 push (@dirlist, $arglist[0]);
180 elsif ($arglist[0] eq '--print-ac-dir')
184 elsif ($arglist[0] eq '--verbose')
188 elsif ($arglist[0] eq '--version')
190 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
191 print "Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.\n";
192 print "This is free software; see the source for copying conditions. There is NO\n";
193 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
194 print "Written by Tom Tromey <tromey\@cygnus.com>\n";
197 elsif ($arglist[0] eq '--help')
203 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
215 # Search the versioned directory near the end, and then the
216 # unversioned directory last. Only do this if the user didn't
218 push (@dirlist, "$acdir-$VERSION")
219 if $acdir eq $default_acdir;
221 # By default $(datadir)/aclocal doesn't exist. We don't want to
222 # get an error in the case where we are searching the default
223 # directory and it hasn't been created.
224 push (@dirlist, $acdir)
225 unless $acdir eq $default_acdir && ! -d $acdir;
230 ################################################################
234 die "aclocal: `configure.ac' or `configure.in' is required\n"
237 open (CONFIGURE, $configure_ac)
238 || die "aclocal: couldn't open `$configure_ac': $!\n";
240 # Make sure we include acinclude.m4 if it exists.
241 if (-f 'acinclude.m4')
243 &add_file ('acinclude.m4');
248 # Remove comments from current line.
255 if ($obsolete_macros{$1} ne '')
257 $hint = '; ' . $obsolete_macros{$1};
259 warn "aclocal: $configure_ac: $.: `$1' is obsolete$hint\n";
264 # Search for things we know about. The "search" sub is
265 # constructed dynamically by scan_m4_files. The last
266 # parenthethical match makes sure we don't match things that
267 # look like macro assignments or AC_SUBSTs.
268 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
270 # Macro not found, but AM_ prefix found.
271 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
279 ################################################################
281 # Check macros in acinclude.m4. If one is not used, warn.
286 foreach $key (keys %map)
288 next unless $map{$key} eq 'acinclude.m4';
289 if (! $macro_seen{$key})
291 # FIXME: should print line number of acinclude.m4.
292 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
297 ################################################################
299 # Scan all the installed m4 files and construct a map.
302 local (@dirlist) = @_;
304 # First, scan acinclude.m4 if it exists.
305 if (-f 'acinclude.m4')
307 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
311 foreach $m4dir (@dirlist)
313 opendir (DIR, $m4dir)
314 || die "aclocal: couldn't open directory `$m4dir': $!\n";
315 local ($file, $fullfile);
316 foreach $file (sort grep (! /^\./, readdir (DIR)))
318 # Only examine .m4 files.
319 next unless $file =~ /\.m4$/;
321 # Skip some files when running out of srcdir.
322 next if $file eq 'aclocal.m4';
324 $fullfile = $m4dir . '/' . $file;
325 $file_contents{$fullfile} = &scan_file ($fullfile);
330 # Construct a new function that does the searching. We use a
331 # function (instead of just evalling $search in the loop) so that
332 # "die" is correctly and easily propagated if run.
333 my $search = "sub search {\nmy \$found = 0;\n";
334 foreach my $key (reverse sort keys %map)
336 # EXPR is a regexp matching the name of the macro.
337 (my $expr = $key) =~ s/(\W)/\\$1/g;
338 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
339 . '); $found = 1; }' . "\n");
341 $search .= "return \$found;\n};\n";
343 die "internal error: $@\n search is $search" if $@;
346 ################################################################
348 # Add a macro to the output.
353 # We want to ignore AC_ macros. However, if an AC_ macro is
354 # defined in (eg) acinclude.m4, then we want to make sure we mark
356 return if $macro =~ /^AC_/ && ! defined $map{$macro};
358 if (! defined $map{$macro})
360 warn "aclocal: macro `$macro' required but not defined\n";
365 print STDERR "aclocal: saw macro $macro\n" if $verbose;
366 $macro_seen{$macro} = 1;
367 &add_file ($map{$macro});
370 # Add a file to output.
375 # Only add a file once.
376 return if ($file_seen{$file});
377 $file_seen{$file} = 1;
379 $output .= $file_contents{$file} . "\n";
381 foreach (split ("\n", $file_contents{$file}))
383 # This is a hack for Perl 4.
385 if ($a =~ /$ac_require_rx/g)
390 # Remove comments from current line.
394 # The search function is constructed dynamically by
395 # scan_m4_files. The last parenthethical match makes sure we
396 # don't match things that look like macro assignments or
398 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
400 # Macro not found, but AM_ prefix found.
401 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
407 foreach $macro (@rlist)
413 # Scan a single M4 file. Return contents.
418 my $fh = new Automake::XFile $file;
420 while ($_ = $fh->getline)
429 if (! defined $map{$1})
434 # Note: we used to give an error here if we saw a
435 # duplicated macro. However, this turns out to be
436 # extremely unpopular. It causes actual problems which
437 # are hard to work around, especially when you must
438 # mix-and-match tool versions.
440 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
447 ################################################################
452 return if ! length ($output);
454 print STDERR "aclocal: writing $output_file\n" if $verbose;
456 my $out = new Automake::XFile "> $output_file";
458 "# $output_file generated automatically by aclocal $VERSION -*- Autoconf -*-
460 # Copyright 1996, 1997, 1998, 1999, 2000, 2001
461 # Free Software Foundation, Inc.
462 # This file is free software; the Free Software Foundation
463 # gives unlimited permission to copy and/or distribute it,
464 # with or without modifications, as long as this notice is preserved.
466 # This program is distributed in the hope that it will be useful,
467 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
468 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
469 # PARTICULAR PURPOSE.