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;
49 # contains a list of directories, one per line, to be added
50 # to the dirlist in addition to $acdir, as if -I had been
51 # added to the command line. If acdir has been redirected,
52 # we will also check the specified acdir (this is done later).
53 $default_dirlist = "$default_acdir/dirlist";
60 # Name of the top autoconf input: `configure.ac' or `configure.in'.
61 $configure_ac = find_configure_ac;
67 $output_file = 'aclocal.m4';
69 # Which macros have been seen.
72 # Which files have been seen.
75 # Map macro names to file names.
78 # Map file names to file contents.
84 # Matches a macro definition.
85 $ac_defun_rx = "A[CU]_DEFUN\\(\\[?([^],)\n]+)\\]?";
87 # Matches an AC_REQUIRE line.
88 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
92 local (@dirlist) = &parse_arguments (@ARGV);
93 &scan_m4_files (@dirlist);
103 ################################################################
105 # Print usage and exit.
108 local ($status) = @_;
110 print "Usage: aclocal [OPTIONS] ...\n\n";
112 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
114 --acdir=DIR directory holding config files
115 --help print this help, then exit
116 -I DIR add directory to search list for .m4 files
117 --output=FILE put output in FILE (default aclocal.m4)
118 --print-ac-dir print name of directory holding m4 files
119 --verbose don't be silent
120 --version print version number, then exit
122 Report bugs to <bug-automake\@gnu.org>.\n";
127 # Parse command line.
128 sub parse_arguments (@)
130 local (@arglist) = @_;
132 local ($print_and_exit) = 0;
136 if ($arglist[0] =~ /^--acdir=(.+)$/)
140 elsif ($arglist[0] =~/^--output=(.+)$/)
144 elsif ($arglist[0] eq '-I')
147 push (@dirlist, $arglist[0]);
149 elsif ($arglist[0] eq '--print-ac-dir')
153 elsif ($arglist[0] eq '--verbose')
157 elsif ($arglist[0] eq '--version')
159 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
160 print "Copyright (C) 2002 Free Software Foundation, Inc.\n";
161 print "This is free software; see the source for copying conditions. There is NO\n";
162 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
163 print "Written by Tom Tromey <tromey\@redhat.com>\n";
166 elsif ($arglist[0] eq '--help')
172 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
184 $default_dirlist="$acdir/dirlist"
185 if $acdir ne $default_acdir;
187 # Search the versioned directory near the end, and then the
188 # unversioned directory last. Only do this if the user didn't
190 push (@dirlist, "$acdir-$APIVERSION")
191 if $acdir eq $default_acdir;
193 # By default $(datadir)/aclocal doesn't exist. We don't want to
194 # get an error in the case where we are searching the default
195 # directory and it hasn't been created.
196 push (@dirlist, $acdir)
197 unless $acdir eq $default_acdir && ! -d $acdir;
199 # Finally, adds any directory listed in the `dirlist' file.
200 if (open (DEFAULT_DIRLIST, $default_dirlist))
202 while (<DEFAULT_DIRLIST>)
206 # strip off newlines and end-of-line comments
208 chomp ($contents=$_);
211 push (@dirlist, $contents);
214 close (DEFAULT_DIRLIST);
221 ################################################################
223 sub scan_configure ()
225 die "aclocal: `configure.ac' or `configure.in' is required\n"
228 open (CONFIGURE, $configure_ac)
229 || die "aclocal: couldn't open `$configure_ac': $!\n";
231 # Make sure we include acinclude.m4 if it exists.
232 if (-f 'acinclude.m4')
234 &add_file ('acinclude.m4');
239 # Remove comments from current line.
243 # Search for things we know about. The "search" sub is
244 # constructed dynamically by scan_m4_files. The last
245 # parenthethical match makes sure we don't match things that
246 # look like macro assignments or AC_SUBSTs.
247 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
249 # Macro not found, but AM_ prefix found.
250 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
258 ################################################################
260 # Check macros in acinclude.m4. If one is not used, warn.
261 sub check_acinclude ()
265 foreach $key (keys %map)
267 next unless $map{$key} eq 'acinclude.m4';
268 if (! $macro_seen{$key})
270 # FIXME: should print line number of acinclude.m4.
271 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
276 ################################################################
278 # Scan all the installed m4 files and construct a map.
279 sub scan_m4_files (@)
281 local (@dirlist) = @_;
283 # First, scan acinclude.m4 if it exists.
284 if (-f 'acinclude.m4')
286 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
290 foreach $m4dir (@dirlist)
292 opendir (DIR, $m4dir)
293 || die "aclocal: couldn't open directory `$m4dir': $!\n";
294 local ($file, $fullfile);
295 foreach $file (sort grep (! /^\./, readdir (DIR)))
297 # Only examine .m4 files.
298 next unless $file =~ /\.m4$/;
300 # Skip some files when running out of srcdir.
301 next if $file eq 'aclocal.m4';
303 $fullfile = $m4dir . '/' . $file;
304 $file_contents{$fullfile} = &scan_file ($fullfile);
309 # Construct a new function that does the searching. We use a
310 # function (instead of just evalling $search in the loop) so that
311 # "die" is correctly and easily propagated if run.
312 my $search = "sub search {\nmy \$found = 0;\n";
313 foreach my $key (reverse sort keys %map)
315 # EXPR is a regexp matching the name of the macro.
316 (my $expr = $key) =~ s/(\W)/\\$1/g;
317 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
318 . '); $found = 1; }' . "\n");
320 $search .= "return \$found;\n};\n";
322 die "internal error: $@\n search is $search" if $@;
325 ################################################################
327 # Add a macro to the output.
332 # We want to ignore AC_ macros. However, if an AC_ macro is
333 # defined in (eg) acinclude.m4, then we want to make sure we mark
335 return if $macro =~ /^AC_/ && ! defined $map{$macro};
337 if (! defined $map{$macro})
339 warn "aclocal: macro `$macro' required but not defined\n";
344 print STDERR "aclocal: saw macro $macro\n" if $verbose;
345 $macro_seen{$macro} = 1;
346 &add_file ($map{$macro});
349 # Add a file to output.
354 # Only add a file once.
355 return if ($file_seen{$file});
356 $file_seen{$file} = 1;
358 $output .= $file_contents{$file} . "\n";
360 foreach (split ("\n", $file_contents{$file}))
362 # Remove comments from current line.
366 if (/$ac_require_rx/g)
371 # The search function is constructed dynamically by
372 # scan_m4_files. The last parenthethical match makes sure we
373 # don't match things that look like macro assignments or
375 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
377 # Macro not found, but AM_ prefix found.
378 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
384 foreach $macro (@rlist)
390 # Scan a single M4 file. Return contents.
395 my $fh = new Automake::XFile $file;
397 while ($_ = $fh->getline)
406 if (! defined $map{$1})
411 # Note: we used to give an error here if we saw a
412 # duplicated macro. However, this turns out to be
413 # extremely unpopular. It causes actual problems which
414 # are hard to work around, especially when you must
415 # mix-and-match tool versions.
417 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
424 ################################################################
429 return if ! length ($output);
431 print STDERR "aclocal: writing $output_file\n" if $verbose;
433 my $out = new Automake::XFile "> $output_file";
435 # We used to print `# $output_file generated automatically etc.' But
436 # this creates spurious differences when using autoreconf. Autoreconf
437 # creates aclocal.m4t and then rename it to aclocal.m4, but the
438 # rebuild rules generated by Automake create aclocal.m4 directly --
439 # this would gives two ways to get the same file, with a different
440 # name in the header.
442 "# generated automatically by aclocal $VERSION -*- Autoconf -*-
444 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
445 # Free Software Foundation, Inc.
446 # This file is free software; the Free Software Foundation
447 # gives unlimited permission to copy and/or distribute it,
448 # with or without modifications, as long as this notice is preserved.
450 # This program is distributed in the hope that it will be useful,
451 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
452 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
453 # PARTICULAR PURPOSE.
458 ### Setup "GNU" style for perl-mode and cperl-mode.
460 ## perl-indent-level: 2
461 ## perl-continued-statement-offset: 2
462 ## perl-continued-brace-offset: 0
463 ## perl-brace-offset: 0
464 ## perl-brace-imaginary-offset: 0
465 ## perl-label-offset: -2
466 ## cperl-indent-level: 2
467 ## cperl-brace-offset: 0
468 ## cperl-continued-brace-offset: 0
469 ## cperl-label-offset: -2
470 ## cperl-extra-newline-before-brace: t
471 ## cperl-merge-trailing-else: nil
472 ## cperl-continued-statement-offset: 2