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, 2003
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, (split ':', $perllibdir);
37 use Automake::General;
38 use Automake::Configure_ac;
40 use Automake::FileUtils;
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";
62 $output_file = 'aclocal.m4';
64 # Modification time of the youngest dependency.
70 # Which macros have been seen.
73 # Which files have been seen.
76 # Map macro names to file names.
79 # Map file names to file contents.
85 # Matches a macro definition.
86 # AC_DEFUN([macroname], ...)
88 # AC_DEFUN(macroname, ...)
89 # When macroname is `['-quoted , we accept any character in the name,
90 # except `]'. Otherwise macroname stops on the first `]', `,', `)',
91 # or `\n' encountered.
92 $ac_defun_rx = "A[CU]_DEFUN\\((?:\\[([^]]+)\\]|([^],)\n]+))";
94 # Matches an AC_REQUIRE line.
95 $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
99 local (@dirlist) = &parse_arguments (@ARGV);
100 &scan_m4_files (@dirlist);
110 ################################################################
112 # Print usage and exit.
115 local ($status) = @_;
117 print "Usage: aclocal [OPTIONS] ...\n\n";
119 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
121 --acdir=DIR directory holding config files
122 --help print this help, then exit
123 -I DIR add directory to search list for .m4 files
124 --force always update output file
125 --output=FILE put output in FILE (default aclocal.m4)
126 --print-ac-dir print name of directory holding m4 files
127 --verbose don't be silent
128 --version print version number, then exit
130 Report bugs to <bug-automake\@gnu.org>.\n";
135 # Parse command line.
136 sub parse_arguments (@)
138 local (@arglist) = @_;
140 local ($print_and_exit) = 0;
144 if ($arglist[0] =~ /^--acdir=(.+)$/)
148 elsif ($arglist[0] =~/^--output=(.+)$/)
152 elsif ($arglist[0] eq '-I')
155 push (@dirlist, $arglist[0]);
157 elsif ($arglist[0] eq '--print-ac-dir')
161 elsif ($arglist[0] eq '--force')
165 elsif ($arglist[0] eq '--verbose')
169 elsif ($arglist[0] eq '--version')
171 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
172 print "Copyright (C) 2003 Free Software Foundation, Inc.\n";
173 print "This is free software; see the source for copying conditions. There is NO\n";
174 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
175 print "Written by Tom Tromey <tromey\@redhat.com>\n";
178 elsif ($arglist[0] eq '--help')
184 print STDERR "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
197 $default_dirlist="$acdir/dirlist"
198 if $acdir ne $default_acdir;
200 # Search the versioned directory near the end, and then the
201 # unversioned directory last. Only do this if the user didn't
203 push (@dirlist, "$acdir-$APIVERSION")
204 if $acdir eq $default_acdir;
206 # By default $(datadir)/aclocal doesn't exist. We don't want to
207 # get an error in the case where we are searching the default
208 # directory and it hasn't been created.
209 push (@dirlist, $acdir)
210 unless $acdir eq $default_acdir && ! -d $acdir;
212 # Finally, adds any directory listed in the `dirlist' file.
213 if (open (DEFAULT_DIRLIST, $default_dirlist))
215 while (<DEFAULT_DIRLIST>)
219 # strip off newlines and end-of-line comments
221 chomp ($contents=$_);
224 push (@dirlist, $contents);
227 close (DEFAULT_DIRLIST);
234 ################################################################
236 sub scan_configure ()
238 require_configure_ac;
240 if (! open (CONFIGURE, $configure_ac))
242 print STDERR "aclocal: couldn't open `$configure_ac': $!\n";
246 my $mtime = mtime $configure_ac;
247 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
249 # Make sure we include acinclude.m4 if it exists.
250 if (-f 'acinclude.m4')
252 &add_file ('acinclude.m4');
257 # Remove comments from current line.
261 # Search for things we know about. The "search" sub is
262 # constructed dynamically by scan_m4_files. The last
263 # parenthethical match makes sure we don't match things that
264 # look like macro assignments or AC_SUBSTs.
265 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
267 # Macro not found, but AM_ prefix found.
268 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
276 ################################################################
278 # Check macros in acinclude.m4. If one is not used, warn.
279 sub check_acinclude ()
283 foreach $key (keys %map)
285 next unless $map{$key} eq 'acinclude.m4';
286 if (! $macro_seen{$key})
288 # FIXME: should print line number of acinclude.m4.
289 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
294 ################################################################
296 # Scan all the installed m4 files and construct a map.
297 sub scan_m4_files (@)
299 local (@dirlist) = @_;
301 # First, scan acinclude.m4 if it exists.
302 if (-f 'acinclude.m4')
304 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
308 foreach $m4dir (@dirlist)
310 if (! opendir (DIR, $m4dir))
312 print STDERR "aclocal: couldn't open directory `$m4dir': $!\n";
316 local ($file, $fullfile);
317 foreach $file (sort grep (! /^\./, readdir (DIR)))
319 # Only examine .m4 files.
320 next unless $file =~ /\.m4$/;
322 # Skip some files when running out of srcdir.
323 next if $file eq 'aclocal.m4';
325 $fullfile = $m4dir . '/' . $file;
326 $file_contents{$fullfile} = &scan_file ($fullfile);
331 # Construct a new function that does the searching. We use a
332 # function (instead of just evalling $search in the loop) so that
333 # "die" is correctly and easily propagated if run.
334 my $search = "sub search {\nmy \$found = 0;\n";
335 foreach my $key (reverse sort keys %map)
337 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
338 . '"); $found = 1; }' . "\n");
340 $search .= "return \$found;\n};\n";
342 die "internal error: $@\n search is $search" if $@;
345 ################################################################
347 # Add a macro to the output.
352 # We want to ignore AC_ macros. However, if an AC_ macro is
353 # defined in (eg) acinclude.m4, then we want to make sure we mark
355 return if $macro =~ /^AC_/ && ! defined $map{$macro};
357 if (! defined $map{$macro})
359 warn "aclocal: macro `$macro' required but not defined\n";
364 print STDERR "aclocal: saw macro $macro\n" if $verbose;
365 $macro_seen{$macro} = 1;
366 &add_file ($map{$macro});
369 # Add a file to output.
374 # Only add a file once.
375 return if ($file_seen{$file});
376 $file_seen{$file} = 1;
378 my $mtime = mtime $file;
379 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
381 # If the file to add looks like path outside the project,
382 # copy it to the output.
383 # The regex catches filenames starting with things like
384 # / \ c:\ ../ ./../ etc.
385 if ($file =~ m,^(?:(?:\w:)?[\\/]|(?:\.[\\/]+)*\.\.[\\/]),)
387 $output .= $file_contents{$file} . "\n";
391 # Otherwise, simply include the file.
392 $output .= "m4_include([$file])\n";
395 foreach (split ("\n", $file_contents{$file}))
397 # Remove comments from current line.
401 if (/$ac_require_rx/g)
403 push (@rlist, $1 || $2);
406 # The search function is constructed dynamically by
407 # scan_m4_files. The last parenthethical match makes sure we
408 # don't match things that look like macro assignments or
410 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
412 # Macro not found, but AM_ prefix found.
413 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
419 foreach $macro (@rlist)
425 # Scan a single M4 file. Return contents.
430 my $fh = new Automake::XFile $file;
432 while ($_ = $fh->getline)
441 if (! defined $map{$1 || $2})
443 $map{$1 || $2} = $file;
446 # Note: we used to give an error here if we saw a
447 # duplicated macro. However, this turns out to be
448 # extremely unpopular. It causes actual problems which
449 # are hard to work around, especially when you must
450 # mix-and-match tool versions.
452 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
459 ################################################################
464 # Nothing to output?!
465 # FIXME: Shouldn't we diagnose this?
466 return if ! length ($output);
468 # We used to print `# $output_file generated automatically etc.' But
469 # this creates spurious differences when using autoreconf. Autoreconf
470 # creates aclocal.m4t and then rename it to aclocal.m4, but the
471 # rebuild rules generated by Automake create aclocal.m4 directly --
472 # this would gives two ways to get the same file, with a different
473 # name in the header.
474 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
476 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
477 # Free Software Foundation, Inc.
478 # This file is free software; the Free Software Foundation
479 # gives unlimited permission to copy and/or distribute it,
480 # with or without modifications, as long as this notice is preserved.
482 # This program is distributed in the hope that it will be useful,
483 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
484 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
485 # PARTICULAR PURPOSE.
489 # We try not to update $output_file unless necessary, because
490 # doing so invalidate Autom4te's cache and therefore slows down
491 # tools called after aclocal.
493 # We need to overwrite $output_file in the following situations.
494 # * The --force option is in use.
495 # * One of the dependencies is younger.
496 # (Not updating $output_file in this situation would cause
497 # make to call aclocal in loop.)
498 # * The contents of the current file are different from what
501 && $greatest_mtime < mtime ($output_file)
502 && $output eq contents ($output_file))
504 print STDERR "aclocal: $output_file unchanged\n" if $verbose;
508 print STDERR "aclocal: writing $output_file\n" if $verbose;
510 my $out = new Automake::XFile "> $output_file";
514 ### Setup "GNU" style for perl-mode and cperl-mode.
516 ## perl-indent-level: 2
517 ## perl-continued-statement-offset: 2
518 ## perl-continued-brace-offset: 0
519 ## perl-brace-offset: 0
520 ## perl-brace-imaginary-offset: 0
521 ## perl-label-offset: -2
522 ## cperl-indent-level: 2
523 ## cperl-brace-offset: 0
524 ## cperl-continued-brace-offset: 0
525 ## cperl-label-offset: -2
526 ## cperl-extra-newline-before-brace: t
527 ## cperl-merge-trailing-else: nil
528 ## cperl-continued-statement-offset: 2