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 $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
33 unshift @INC, $perllibdir;
36 use Automake::General;
40 $VERSION = '@VERSION@';
41 $APIVERSION = '@APIVERSION@';
42 $PACKAGE = '@PACKAGE@';
43 # Note that this isn't pkgdatadir, but a separate directory.
44 # Note also that the versioned directory is handled later.
45 $acdir = '@datadir@/aclocal';
46 $default_acdir = $acdir;
47 # contains a list of directories, one per line, to be added
48 # to the dirlist in addition to $acdir, as if -I had been
49 # added to the command line. If acdir has been redirected,
50 # we will also check the specified acdir (this is done later).
51 $default_dirlist = "$default_acdir/dirlist";
58 # Name of the top autoconf input: `configure.ac' or `configure.in'.
59 $configure_ac = find_configure_ac;
65 $output_file = 'aclocal.m4';
67 # Which macros have been seen.
70 # Which files have been seen.
73 # Map macro names to file names.
76 # Map file names to file contents.
82 # Matches a macro definition.
83 $ac_defun_rx = "A[CU]_DEFUN\\(\\[?([^],)\n]+)\\]?";
85 # Matches an AC_REQUIRE line.
86 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
90 local (@dirlist) = &parse_arguments (@ARGV);
91 &scan_m4_files (@dirlist);
101 ################################################################
103 # Print usage and exit.
106 local ($status) = @_;
108 print "Usage: aclocal [OPTIONS] ...\n\n";
110 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
112 --acdir=DIR directory holding config files
113 --help print this help, then exit
114 -I DIR add directory to search list for .m4 files
115 --output=FILE put output in FILE (default aclocal.m4)
116 --print-ac-dir print name of directory holding m4 files
117 --verbose don't be silent
118 --version print version number, then exit
120 Report bugs to <bug-automake\@gnu.org>.\n";
125 # Parse command line.
126 sub parse_arguments (@)
128 local (@arglist) = @_;
130 local ($print_and_exit) = 0;
134 if ($arglist[0] =~ /^--acdir=(.+)$/)
138 elsif ($arglist[0] =~/^--output=(.+)$/)
142 elsif ($arglist[0] eq '-I')
145 push (@dirlist, $arglist[0]);
147 elsif ($arglist[0] eq '--print-ac-dir')
151 elsif ($arglist[0] eq '--verbose')
155 elsif ($arglist[0] eq '--version')
157 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
158 print "Copyright (C) 2002 Free Software Foundation, Inc.\n";
159 print "This is free software; see the source for copying conditions. There is NO\n";
160 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
161 print "Written by Tom Tromey <tromey\@redhat.com>\n";
164 elsif ($arglist[0] eq '--help')
170 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
182 $default_dirlist="$acdir/dirlist"
183 if $acdir ne $default_acdir;
185 # Search the versioned directory near the end, and then the
186 # unversioned directory last. Only do this if the user didn't
188 push (@dirlist, "$acdir-$APIVERSION")
189 if $acdir eq $default_acdir;
191 # By default $(datadir)/aclocal doesn't exist. We don't want to
192 # get an error in the case where we are searching the default
193 # directory and it hasn't been created.
194 push (@dirlist, $acdir)
195 unless $acdir eq $default_acdir && ! -d $acdir;
197 # Finally, adds any directory listed in the `dirlist' file.
198 if (open (DEFAULT_DIRLIST, $default_dirlist))
200 while (<DEFAULT_DIRLIST>)
204 # strip off newlines and end-of-line comments
206 chomp ($contents=$_);
209 push (@dirlist, $contents);
212 close (DEFAULT_DIRLIST);
219 ################################################################
221 sub scan_configure ()
223 die "aclocal: `configure.ac' or `configure.in' is required\n"
226 open (CONFIGURE, $configure_ac)
227 || die "aclocal: couldn't open `$configure_ac': $!\n";
229 # Make sure we include acinclude.m4 if it exists.
230 if (-f 'acinclude.m4')
232 &add_file ('acinclude.m4');
237 # Remove comments from current line.
241 # Search for things we know about. The "search" sub is
242 # constructed dynamically by scan_m4_files. The last
243 # parenthethical match makes sure we don't match things that
244 # look like macro assignments or AC_SUBSTs.
245 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
247 # Macro not found, but AM_ prefix found.
248 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
256 ################################################################
258 # Check macros in acinclude.m4. If one is not used, warn.
259 sub check_acinclude ()
263 foreach $key (keys %map)
265 next unless $map{$key} eq 'acinclude.m4';
266 if (! $macro_seen{$key})
268 # FIXME: should print line number of acinclude.m4.
269 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
274 ################################################################
276 # Scan all the installed m4 files and construct a map.
277 sub scan_m4_files (@)
279 local (@dirlist) = @_;
281 # First, scan acinclude.m4 if it exists.
282 if (-f 'acinclude.m4')
284 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
288 foreach $m4dir (@dirlist)
290 opendir (DIR, $m4dir)
291 || die "aclocal: couldn't open directory `$m4dir': $!\n";
292 local ($file, $fullfile);
293 foreach $file (sort grep (! /^\./, readdir (DIR)))
295 # Only examine .m4 files.
296 next unless $file =~ /\.m4$/;
298 # Skip some files when running out of srcdir.
299 next if $file eq 'aclocal.m4';
301 $fullfile = $m4dir . '/' . $file;
302 $file_contents{$fullfile} = &scan_file ($fullfile);
307 # Construct a new function that does the searching. We use a
308 # function (instead of just evalling $search in the loop) so that
309 # "die" is correctly and easily propagated if run.
310 my $search = "sub search {\nmy \$found = 0;\n";
311 foreach my $key (reverse sort keys %map)
313 # EXPR is a regexp matching the name of the macro.
314 (my $expr = $key) =~ s/(\W)/\\$1/g;
315 $search .= ('if (/\b' . $key . '\b/) { & add_macro (' . $key
316 . '); $found = 1; }' . "\n");
318 $search .= "return \$found;\n};\n";
320 die "internal error: $@\n search is $search" if $@;
323 ################################################################
325 # Add a macro to the output.
330 # We want to ignore AC_ macros. However, if an AC_ macro is
331 # defined in (eg) acinclude.m4, then we want to make sure we mark
333 return if $macro =~ /^AC_/ && ! defined $map{$macro};
335 if (! defined $map{$macro})
337 warn "aclocal: macro `$macro' required but not defined\n";
342 print STDERR "aclocal: saw macro $macro\n" if $verbose;
343 $macro_seen{$macro} = 1;
344 &add_file ($map{$macro});
347 # Add a file to output.
352 # Only add a file once.
353 return if ($file_seen{$file});
354 $file_seen{$file} = 1;
356 $output .= $file_contents{$file} . "\n";
358 foreach (split ("\n", $file_contents{$file}))
360 # Remove comments from current line.
364 if (/$ac_require_rx/g)
369 # The search function is constructed dynamically by
370 # scan_m4_files. The last parenthethical match makes sure we
371 # don't match things that look like macro assignments or
373 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
375 # Macro not found, but AM_ prefix found.
376 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
382 foreach $macro (@rlist)
388 # Scan a single M4 file. Return contents.
393 my $fh = new Automake::XFile $file;
395 while ($_ = $fh->getline)
404 if (! defined $map{$1})
409 # Note: we used to give an error here if we saw a
410 # duplicated macro. However, this turns out to be
411 # extremely unpopular. It causes actual problems which
412 # are hard to work around, especially when you must
413 # mix-and-match tool versions.
415 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
422 ################################################################
427 return if ! length ($output);
429 print STDERR "aclocal: writing $output_file\n" if $verbose;
431 my $out = new Automake::XFile "> $output_file";
433 # We used to print `# $output_file generated automatically etc.' But
434 # this creates spurious differences when using autoreconf. Autoreconf
435 # creates aclocal.m4t and then rename it to aclocal.m4, but the
436 # rebuild rules generated by Automake create aclocal.m4 directly --
437 # this would gives two ways to get the same file, with a different
438 # name in the header.
440 "# generated automatically by aclocal $VERSION -*- Autoconf -*-
442 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
443 # Free Software Foundation, Inc.
444 # This file is free software; the Free Software Foundation
445 # gives unlimited permission to copy and/or distribute it,
446 # with or without modifications, as long as this notice is preserved.
448 # This program is distributed in the hope that it will be useful,
449 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
450 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
451 # PARTICULAR PURPOSE.
456 ### Setup "GNU" style for perl-mode and cperl-mode.
458 ## perl-indent-level: 2
459 ## perl-continued-statement-offset: 2
460 ## perl-continued-brace-offset: 0
461 ## perl-brace-offset: 0
462 ## perl-brace-imaginary-offset: 0
463 ## perl-label-offset: -2
464 ## cperl-indent-level: 2
465 ## cperl-brace-offset: 0
466 ## cperl-continued-brace-offset: 0
467 ## cperl-label-offset: -2
468 ## cperl-extra-newline-before-brace: t
469 ## cperl-merge-trailing-else: nil
470 ## cperl-continued-statement-offset: 2