5 eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
8 # aclocal - create aclocal.m4 by scanning configure.ac
10 # Copyright (C) 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 # Matches a macro definition.
80 $ac_defun_rx = "A[CU]_DEFUN\\(\\[?([^],)\n]+)\\]?";
82 # Matches an AC_REQUIRE line.
83 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
87 local (@dirlist) = &parse_arguments (@ARGV);
88 &scan_m4_files (@dirlist);
98 ################################################################
100 # Print usage and exit.
103 local ($status) = @_;
105 print "Usage: aclocal [OPTIONS] ...\n\n";
107 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
109 --acdir=DIR directory holding config files
110 --help print this help, then exit
111 -I DIR add directory to search list for .m4 files
112 --output=FILE put output in FILE (default aclocal.m4)
113 --print-ac-dir print name of directory holding m4 files
114 --verbose don't be silent
115 --version print version number, then exit
117 Report bugs to <bug-automake\@gnu.org>.\n";
122 # Parse command line.
125 local (@arglist) = @_;
127 local ($print_and_exit) = 0;
131 if ($arglist[0] =~ /^--acdir=(.+)$/)
135 elsif ($arglist[0] =~/^--output=(.+)$/)
139 elsif ($arglist[0] eq '-I')
142 push (@dirlist, $arglist[0]);
144 elsif ($arglist[0] eq '--print-ac-dir')
148 elsif ($arglist[0] eq '--verbose')
152 elsif ($arglist[0] eq '--version')
154 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
155 print "Copyright 2002 Free Software Foundation, Inc.\n";
156 print "This is free software; see the source for copying conditions. There is NO\n";
157 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
158 print "Written by Tom Tromey <tromey\@redhat.com>\n";
161 elsif ($arglist[0] eq '--help')
167 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
179 # Search the versioned directory near the end, and then the
180 # unversioned directory last. Only do this if the user didn't
182 push (@dirlist, "$acdir-$APIVERSION")
183 if $acdir eq $default_acdir;
185 # By default $(datadir)/aclocal doesn't exist. We don't want to
186 # get an error in the case where we are searching the default
187 # directory and it hasn't been created.
188 push (@dirlist, $acdir)
189 unless $acdir eq $default_acdir && ! -d $acdir;
194 ################################################################
198 die "aclocal: `configure.ac' or `configure.in' is required\n"
201 open (CONFIGURE, $configure_ac)
202 || die "aclocal: couldn't open `$configure_ac': $!\n";
204 # Make sure we include acinclude.m4 if it exists.
205 if (-f 'acinclude.m4')
207 &add_file ('acinclude.m4');
212 # Remove comments from current line.
216 # Search for things we know about. The "search" sub is
217 # constructed dynamically by scan_m4_files. The last
218 # parenthethical match makes sure we don't match things that
219 # look like macro assignments or AC_SUBSTs.
220 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
222 # Macro not found, but AM_ prefix found.
223 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
231 ################################################################
233 # Check macros in acinclude.m4. If one is not used, warn.
238 foreach $key (keys %map)
240 next unless $map{$key} eq 'acinclude.m4';
241 if (! $macro_seen{$key})
243 # FIXME: should print line number of acinclude.m4.
244 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
249 ################################################################
251 # Scan all the installed m4 files and construct a map.
254 local (@dirlist) = @_;
256 # First, scan acinclude.m4 if it exists.
257 if (-f 'acinclude.m4')
259 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
263 foreach $m4dir (@dirlist)
265 opendir (DIR, $m4dir)
266 || die "aclocal: couldn't open directory `$m4dir': $!\n";
267 local ($file, $fullfile);
268 foreach $file (sort grep (! /^\./, readdir (DIR)))
270 # Only examine .m4 files.
271 next unless $file =~ /\.m4$/;
273 # Skip some files when running out of srcdir.
274 next if $file eq 'aclocal.m4';
276 $fullfile = $m4dir . '/' . $file;
277 $file_contents{$fullfile} = &scan_file ($fullfile);
282 # Construct a new function that does the searching. We use a
283 # function (instead of just evalling $search in the loop) so that
284 # "die" is correctly and easily propagated if run.
285 my $search = "sub search {\nmy \$found = 0;\n";
286 foreach my $key (reverse sort keys %map)
288 # EXPR is a regexp matching the name of the macro.
289 (my $expr = $key) =~ s/(\W)/\\$1/g;
290 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
291 . '); $found = 1; }' . "\n");
293 $search .= "return \$found;\n};\n";
295 die "internal error: $@\n search is $search" if $@;
298 ################################################################
300 # Add a macro to the output.
305 # We want to ignore AC_ macros. However, if an AC_ macro is
306 # defined in (eg) acinclude.m4, then we want to make sure we mark
308 return if $macro =~ /^AC_/ && ! defined $map{$macro};
310 if (! defined $map{$macro})
312 warn "aclocal: macro `$macro' required but not defined\n";
317 print STDERR "aclocal: saw macro $macro\n" if $verbose;
318 $macro_seen{$macro} = 1;
319 &add_file ($map{$macro});
322 # Add a file to output.
327 # Only add a file once.
328 return if ($file_seen{$file});
329 $file_seen{$file} = 1;
331 $output .= $file_contents{$file} . "\n";
333 foreach (split ("\n", $file_contents{$file}))
335 # This is a hack for Perl 4.
337 if ($a =~ /$ac_require_rx/g)
342 # Remove comments from current line.
346 # The search function is constructed dynamically by
347 # scan_m4_files. The last parenthethical match makes sure we
348 # don't match things that look like macro assignments or
350 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
352 # Macro not found, but AM_ prefix found.
353 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
359 foreach $macro (@rlist)
365 # Scan a single M4 file. Return contents.
370 my $fh = new Automake::XFile $file;
372 while ($_ = $fh->getline)
381 if (! defined $map{$1})
386 # Note: we used to give an error here if we saw a
387 # duplicated macro. However, this turns out to be
388 # extremely unpopular. It causes actual problems which
389 # are hard to work around, especially when you must
390 # mix-and-match tool versions.
392 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
399 ################################################################
404 return if ! length ($output);
406 print STDERR "aclocal: writing $output_file\n" if $verbose;
408 my $out = new Automake::XFile "> $output_file";
410 # We used to print `# $output_file generated automatically etc.' But
411 # this creates spurious differences when using autoreconf. Autoreconf
412 # creates aclocal.m4t and then rename it to aclocal.m4, but the
413 # rebuild rules generated by Automake create aclocal.m4 directly --
414 # this would gives two ways to get the same file, with a different
415 # name in the header.
417 "# generated automatically by aclocal $VERSION -*- Autoconf -*-
419 # Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
420 # Free Software Foundation, Inc.
421 # This file is free software; the Free Software Foundation
422 # gives unlimited permission to copy and/or distribute it,
423 # with or without modifications, as long as this notice is preserved.
425 # This program is distributed in the hope that it will be useful,
426 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
427 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
428 # PARTICULAR PURPOSE.
433 ### Setup "GNU" style for perl-mode and cperl-mode.
435 ## perl-indent-level: 2
436 ## perl-continued-statement-offset: 2
437 ## perl-continued-brace-offset: 0
438 ## perl-brace-offset: 0
439 ## perl-brace-imaginary-offset: 0
440 ## perl-label-offset: -2
441 ## cperl-indent-level: 2
442 ## cperl-brace-offset: 0
443 ## cperl-continued-brace-offset: 0
444 ## cperl-label-offset: -2
445 ## cperl-extra-newline-before-brace: t
446 ## cperl-merge-trailing-else: nil
447 ## cperl-continued-statement-offset: 2