5 # aclocal - create aclocal.m4 by scanning configure.ac
6 # Copyright 1996, 1997, 1998, 1999, 2000, 2001 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.ac 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";
42 # Name of the top autoconf input: `configure.ac' or `configure.in'.
49 $output_file = 'aclocal.m4';
51 # Which macros have been seen.
54 # Which files have been seen.
57 # Map macro names to file names.
60 # Map file names to file contents.
66 # Map from obsolete macros to hints for new macros.
67 # If you change this, change the corresponding list in automake.in.
68 # FIXME: should just put this into a single file.
71 'AC_FEATURE_CTYPE' => "use `AC_HEADER_STDC'",
72 'AC_FEATURE_ERRNO' => "add `strerror' to `AC_REPLACE_FUNCS(...)'",
73 'AC_FEATURE_EXIT' => '',
74 'AC_SYSTEM_HEADER' => '',
76 # Note that we do not handle this one, because it is still run
77 # from AM_CONFIG_HEADER. So we deal with it specially in
78 # &scan_autoconf_files.
79 # 'AC_CONFIG_HEADER' => "use `AM_CONFIG_HEADER'",
81 'fp_C_PROTOTYPES' => "use `AM_C_PROTOTYPES'",
82 'fp_PROG_CC_STDC' => "use `AM_PROG_CC_STDC'",
83 'fp_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
84 'fp_WITH_DMALLOC' => "use `AM_WITH_DMALLOC'",
85 'fp_WITH_REGEX' => "use `AM_WITH_REGEX'",
86 'gm_PROG_LIBTOOL' => "use `AM_PROG_LIBTOOL'",
87 'jm_MAINTAINER_MODE' => "use `AM_MAINTAINER_MODE'",
88 'md_TYPE_PTRDIFF_T' => "use `AM_TYPE_PTRDIFF_T'",
89 'ud_PATH_LISPDIR' => "use `AM_PATH_LISPDIR'",
90 'ud_GNU_GETTEXT' => "use `AM_GNU_GETTEXT'",
92 # Now part of autoconf proper, under a different name.
93 'AM_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
94 'fp_FUNC_FNMATCH' => "use `AC_FUNC_FNMATCH'",
95 'AM_SANITY_CHECK_CC' => "automatically done by `AC_PROG_CC'",
96 'AM_PROG_INSTALL' => "use `AC_PROG_INSTALL'",
97 'AM_EXEEXT' => "use `AC_EXEEXT'",
98 'AM_CYGWIN32' => "use `AC_CYGWIN'",
99 'AM_MINGW32' => "use `AC_MINGW32'",
100 'AM_FUNC_MKTIME' => "use `AC_FUNC_MKTIME'",
102 # These aren't quite obsolete.
106 # Regexp to match the above macros.
107 $obsolete_rx = '\b(' . join ('|', keys %obsolete_macros) . ')\b';
109 # Matches a macro definition.
110 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
112 # Matches an AC_REQUIRE line.
113 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
117 local (@dirlist) = &parse_arguments (@ARGV);
118 &scan_m4_files (@dirlist);
128 ################################################################
130 # Print usage and exit.
133 local ($status) = @_;
135 print "Usage: aclocal [OPTIONS] ...\n\n";
137 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
139 --acdir=DIR directory holding config files
140 --help print this help, then exit
141 -I DIR add directory to search list for .m4 files
142 --output=FILE put output in FILE (default aclocal.m4)
143 --print-ac-dir print name of directory holding m4 files
144 --verbose don't be silent
145 --version print version number, then exit
147 Report bugs to <bug-automake\@gnu.org>.\n";
152 # Parse command line.
155 local (@arglist) = @_;
157 local ($print_and_exit) = 0;
161 if ($arglist[0] =~ /^--acdir=(.+)$/)
165 elsif ($arglist[0] =~/^--output=(.+)$/)
169 elsif ($arglist[0] eq '-I')
172 push (@dirlist, $arglist[0]);
174 elsif ($arglist[0] eq '--print-ac-dir')
178 elsif ($arglist[0] eq '--verbose')
182 elsif ($arglist[0] eq '--version')
184 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
185 print "Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.\n";
186 print "This is free software; see the source for copying conditions. There is NO\n";
187 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
188 print "Written by Tom Tromey <tromey\@cygnus.com>\n";
191 elsif ($arglist[0] eq '--help')
197 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
209 # Search our install directory last.
210 push (@dirlist, $acdir);
215 ################################################################
219 warn "aclocal: both `configure.ac' and `configure.in' present:"
220 . " ignoring `configure.in'\n"
221 if -f 'configure.ac' && -f 'configure.in';
222 $configure_ac = 'configure.in'
223 if -f 'configure.in';
224 $configure_ac = 'configure.ac'
225 if -f 'configure.ac';
226 die "aclocal: `configure.ac' or `configure.in' is required\n"
229 open (CONFIGURE, $configure_ac)
230 || die "aclocal: couldn't open `$configure_ac': $!\n";
232 # Make sure we include acinclude.m4 if it exists.
233 if (-f 'acinclude.m4')
235 &add_file ('acinclude.m4');
240 # Remove comments from current line.
247 if ($obsolete_macros{$1} ne '')
249 $hint = '; ' . $obsolete_macros{$1};
251 warn "aclocal: $configure_ac: $.: `$1' is obsolete$hint\n";
256 # Search for things we know about. The "search" sub is
257 # constructed dynamically by scan_m4_files. The last
258 # parenthethical match makes sure we don't match things that
259 # look like macro assignments or AC_SUBSTs.
260 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
262 # Macro not found, but AM_ prefix found.
263 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
271 ################################################################
273 # Check macros in acinclude.m4. If one is not used, warn.
278 foreach $key (keys %map)
280 next unless $map{$key} eq 'acinclude.m4';
281 if (! $macro_seen{$key})
283 # FIXME: should print line number of acinclude.m4.
284 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
289 ################################################################
291 # Scan all the installed m4 files and construct a map.
294 local (@dirlist) = @_;
296 # First, scan acinclude.m4 if it exists.
297 if (-f 'acinclude.m4')
299 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
303 foreach $m4dir (@dirlist)
305 opendir (DIR, $m4dir)
306 || die "aclocal: couldn't open directory `$m4dir': $!\n";
307 local ($file, $fullfile);
308 foreach $file (sort grep (! /^\./, readdir (DIR)))
310 # Only examine .m4 files.
311 next unless $file =~ /\.m4$/;
313 # Skip some files when running out of srcdir.
314 next if $file eq 'aclocal.m4';
316 $fullfile = $m4dir . '/' . $file;
317 $file_contents{$fullfile} = &scan_file ($fullfile);
322 # Construct a new function that does the searching. We use a
323 # function (instead of just evalling $search in the loop) so that
324 # "die" is correctly and easily propagated if run.
325 my $search = "sub search {\nmy \$found = 0;\n";
326 foreach my $key (reverse sort keys %map)
328 # EXPR is a regexp matching the name of the macro.
329 (my $expr = $key) =~ s/(\W)/\\$1/g;
330 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
331 . '); $found = 1; }' . "\n");
333 $search .= "return \$found;\n};\n";
335 die "internal error: $@\n search is $search" if $@;
338 ################################################################
340 # Add a macro to the output.
345 # We want to ignore AC_ macros. However, if an AC_ macro is
346 # defined in (eg) acinclude.m4, then we want to make sure we mark
348 return if $macro =~ /^AC_/ && ! defined $map{$macro};
350 if (! defined $map{$macro})
352 warn "aclocal: macro `$macro' required but not defined\n";
357 print STDERR "aclocal: saw macro $macro\n" if $verbose;
358 $macro_seen{$macro} = 1;
359 &add_file ($map{$macro});
362 # Add a file to output.
367 # Only add a file once.
368 return if ($file_seen{$file});
369 $file_seen{$file} = 1;
371 $output .= $file_contents{$file} . "\n";
373 foreach (split ("\n", $file_contents{$file}))
375 # This is a hack for Perl 4.
377 if ($a =~ /$ac_require_rx/g)
382 # Remove comments from current line.
386 # The search function is constructed dynamically by
387 # scan_m4_files. The last parenthethical match makes sure we
388 # don't match things that look like macro assignments or
390 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
392 # Macro not found, but AM_ prefix found.
393 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
399 foreach $macro (@rlist)
405 # Scan a single M4 file. Return contents.
411 || die "aclocal: couldn't open `$file': $!\n";
412 local ($contents) = '';
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;
441 ################################################################
446 return if ! length ($output);
448 print STDERR "aclocal: writing $output_file\n" if $verbose;
450 open (ACLOCAL, "> " . $output_file)
451 || die "aclocal: couldn't open `$output_file' for writing: $!\n";
453 # In case we're running under MSWindows, don't write with CRLF.
454 # (This circumvents a bug in at least Cygwin bash where the shell
455 # parsing fails on lines ending with the continuation character '\'
459 print ACLOCAL "# $output_file generated automatically by aclocal $VERSION\n";
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.
473 print ACLOCAL $output;