5 eval 'exec @PERL@ -S $0 ${1+"$@"}'
8 # aclocal - create aclocal.m4 by scanning configure.ac
10 # Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
11 # Free Software Foundation, Inc.
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 # Written by Tom Tromey <tromey@redhat.com>.
32 my $prefix = "@prefix@";
33 my $perllibdir = $ENV{'perllibdir'} || "@datadir@/@PACKAGE@-@APIVERSION@";
34 unshift @INC, "$perllibdir";
37 use Automake::General;
41 $VERSION = "@VERSION@";
42 $APIVERSION = "@APIVERSION@";
43 $PACKAGE = "@PACKAGE@";
45 # Note that this isn't pkgdatadir, but a separate directory.
46 # Note also that the versioned directory is handled later.
47 $acdir = "@datadir@/aclocal";
48 $default_acdir = $acdir;
55 # Name of the top autoconf input: `configure.ac' or `configure.in'.
56 $configure_ac = find_configure_ac;
62 $output_file = 'aclocal.m4';
64 # Which macros have been seen.
67 # Which files have been seen.
70 # Map macro names to file names.
73 # Map file names to file contents.
79 # Map from obsolete macros to hints for new macros.
80 # If you change this, change the corresponding list in automake.in.
81 # FIXME: should just put this into a single file.
84 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
85 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
86 'AC_FEATURE_EXIT' => '',
87 'AC_SYSTEM_HEADER' => '',
89 # Note that we do not handle this one, because it is still run
90 # from AM_CONFIG_HEADER. So we deal with it specially in
91 # &scan_autoconf_files.
92 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
94 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
95 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
96 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
97 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
98 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
99 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
100 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
101 'md_TYPE_PTRDIFF_T' => "add `ptrdiff_t' to `AC_CHECK_TYPES(...)'",
102 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
103 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
105 # Now part of autoconf proper, under a different name.
106 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
107 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
108 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
109 'AM_EXEEXT' => "automatically done by `AC_PROG_(CC|CXX|F77)'",
110 'AM_CYGWIN32' => "use `AC_CYGWIN'",
111 'AM_MINGW32' => "use `AC_MINGW32'",
112 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
115 # Regexp to match the above macros.
116 $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
118 # Matches a macro definition.
119 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
121 # Matches an AC_REQUIRE line.
122 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
126 local (@dirlist) = &parse_arguments (@ARGV);
127 &scan_m4_files (@dirlist);
137 ################################################################
139 # Print usage and exit.
142 local ($status) = @_;
144 print "Usage: aclocal [OPTIONS] ...\n\n";
146 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
148 --acdir=DIR directory holding config files
149 --help print this help, then exit
150 -I DIR add directory to search list for .m4 files
151 --output=FILE put output in FILE (default aclocal.m4)
152 --print-ac-dir print name of directory holding m4 files
153 --verbose don't be silent
154 --version print version number, then exit
156 Report bugs to <bug-automake\@gnu.org>.\n";
161 # Parse command line.
164 local (@arglist) = @_;
166 local ($print_and_exit) = 0;
170 if ($arglist[0] =~ /^--acdir=(.+)$/)
174 elsif ($arglist[0] =~/^--output=(.+)$/)
178 elsif ($arglist[0] eq '-I')
181 push (@dirlist, $arglist[0]);
183 elsif ($arglist[0] eq '--print-ac-dir')
187 elsif ($arglist[0] eq '--verbose')
191 elsif ($arglist[0] eq '--version')
193 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
194 print "Copyright 2002 Free Software Foundation, Inc.\n";
195 print "This is free software; see the source for copying conditions. There is NO\n";
196 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
197 print "Written by Tom Tromey <tromey\@redhat.com>\n";
200 elsif ($arglist[0] eq '--help')
206 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
218 # Search the versioned directory near the end, and then the
219 # unversioned directory last. Only do this if the user didn't
221 push (@dirlist, "$acdir-$APIVERSION")
222 if $acdir eq $default_acdir;
224 # By default $(datadir)/aclocal doesn't exist. We don't want to
225 # get an error in the case where we are searching the default
226 # directory and it hasn't been created.
227 push (@dirlist, $acdir)
228 unless $acdir eq $default_acdir && ! -d $acdir;
233 ################################################################
237 die "aclocal: `configure.ac' or `configure.in' is required\n"
240 open (CONFIGURE, $configure_ac)
241 || die "aclocal: couldn't open `$configure_ac': $!\n";
243 # Make sure we include acinclude.m4 if it exists.
244 if (-f 'acinclude.m4')
246 &add_file ('acinclude.m4');
251 # Remove comments from current line.
258 if ($obsolete_macros{$1} ne '')
260 $hint = '; ' . $obsolete_macros{$1};
262 warn "aclocal: $configure_ac: $.: `$1' is obsolete$hint\n";
267 # Search for things we know about. The "search" sub is
268 # constructed dynamically by scan_m4_files. The last
269 # parenthethical match makes sure we don't match things that
270 # look like macro assignments or AC_SUBSTs.
271 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
273 # Macro not found, but AM_ prefix found.
274 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
282 ################################################################
284 # Check macros in acinclude.m4. If one is not used, warn.
289 foreach $key (keys %map)
291 next unless $map{$key} eq 'acinclude.m4';
292 if (! $macro_seen{$key})
294 # FIXME: should print line number of acinclude.m4.
295 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
300 ################################################################
302 # Scan all the installed m4 files and construct a map.
305 local (@dirlist) = @_;
307 # First, scan acinclude.m4 if it exists.
308 if (-f 'acinclude.m4')
310 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
314 foreach $m4dir (@dirlist)
316 opendir (DIR, $m4dir)
317 || die "aclocal: couldn't open directory `$m4dir': $!\n";
318 local ($file, $fullfile);
319 foreach $file (sort grep (! /^\./, readdir (DIR)))
321 # Only examine .m4 files.
322 next unless $file =~ /\.m4$/;
324 # Skip some files when running out of srcdir.
325 next if $file eq 'aclocal.m4';
327 $fullfile = $m4dir . '/' . $file;
328 $file_contents{$fullfile} = &scan_file ($fullfile);
333 # Construct a new function that does the searching. We use a
334 # function (instead of just evalling $search in the loop) so that
335 # "die" is correctly and easily propagated if run.
336 my $search = "sub search {\nmy \$found = 0;\n";
337 foreach my $key (reverse sort keys %map)
339 # EXPR is a regexp matching the name of the macro.
340 (my $expr = $key) =~ s/(\W)/\\$1/g;
341 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
342 . '); $found = 1; }' . "\n");
344 $search .= "return \$found;\n};\n";
346 die "internal error: $@\n search is $search" if $@;
349 ################################################################
351 # Add a macro to the output.
356 # We want to ignore AC_ macros. However, if an AC_ macro is
357 # defined in (eg) acinclude.m4, then we want to make sure we mark
359 return if $macro =~ /^AC_/ && ! defined $map{$macro};
361 if (! defined $map{$macro})
363 warn "aclocal: macro `$macro' required but not defined\n";
368 print STDERR "aclocal: saw macro $macro\n" if $verbose;
369 $macro_seen{$macro} = 1;
370 &add_file ($map{$macro});
373 # Add a file to output.
378 # Only add a file once.
379 return if ($file_seen{$file});
380 $file_seen{$file} = 1;
382 $output .= $file_contents{$file} . "\n";
384 foreach (split ("\n", $file_contents{$file}))
386 # This is a hack for Perl 4.
388 if ($a =~ /$ac_require_rx/g)
393 # Remove comments from current line.
397 # The search function is constructed dynamically by
398 # scan_m4_files. The last parenthethical match makes sure we
399 # don't match things that look like macro assignments or
401 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
403 # Macro not found, but AM_ prefix found.
404 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
410 foreach $macro (@rlist)
416 # Scan a single M4 file. Return contents.
421 my $fh = new Automake::XFile $file;
423 while ($_ = $fh->getline)
432 if (! defined $map{$1})
437 # Note: we used to give an error here if we saw a
438 # duplicated macro. However, this turns out to be
439 # extremely unpopular. It causes actual problems which
440 # are hard to work around, especially when you must
441 # mix-and-match tool versions.
443 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
450 ################################################################
455 return if ! length ($output);
457 print STDERR "aclocal: writing $output_file\n" if $verbose;
459 my $out = new Automake::XFile "> $output_file";
461 "# $output_file generated automatically by aclocal $VERSION -*- Autoconf -*-
463 # Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
464 # Free Software Foundation, Inc.
465 # This file is free software; the Free Software Foundation
466 # gives unlimited permission to copy and/or distribute it,
467 # with or without modifications, as long as this notice is preserved.
469 # This program is distributed in the hope that it will be useful,
470 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
471 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
472 # PARTICULAR PURPOSE.