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, $perllibdir;
36 use Automake::General;
37 use Automake::Configure_ac;
42 $VERSION = '@VERSION@';
43 $APIVERSION = '@APIVERSION@';
44 $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";
64 $output_file = 'aclocal.m4';
66 # Modification time of the youngest dependency.
72 # Which macros have been seen.
75 # Which files have been seen.
78 # Map macro names to file names.
81 # Map file names to file contents.
87 # Matches a macro definition.
88 # AC_DEFUN([macroname], ...)
90 # AC_DEFUN(macroname, ...)
91 # When macroname is `['-quoted , we accept any character in the name,
92 # except `]'. Otherwise macroname stops on the first `]', `,', `)',
93 # or `\n' encountered.
94 $ac_defun_rx = "A[CU]_DEFUN\\((?:\\[([^]]+)\\]|([^],)\n]+))";
96 # Matches an AC_REQUIRE line.
97 $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
101 local (@dirlist) = &parse_arguments (@ARGV);
102 &scan_m4_files (@dirlist);
112 ################################################################
114 # Print usage and exit.
117 local ($status) = @_;
119 print "Usage: aclocal [OPTIONS] ...\n\n";
121 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
123 --acdir=DIR directory holding config files
124 --help print this help, then exit
125 -I DIR add directory to search list for .m4 files
126 --force always update output file
127 --output=FILE put output in FILE (default aclocal.m4)
128 --print-ac-dir print name of directory holding m4 files
129 --verbose don't be silent
130 --version print version number, then exit
132 Report bugs to <bug-automake\@gnu.org>.\n";
137 # Parse command line.
138 sub parse_arguments (@)
140 local (@arglist) = @_;
142 local ($print_and_exit) = 0;
146 if ($arglist[0] =~ /^--acdir=(.+)$/)
150 elsif ($arglist[0] =~/^--output=(.+)$/)
154 elsif ($arglist[0] eq '-I')
157 push (@dirlist, $arglist[0]);
159 elsif ($arglist[0] eq '--print-ac-dir')
163 elsif ($arglist[0] eq '--force')
167 elsif ($arglist[0] eq '--verbose')
171 elsif ($arglist[0] eq '--version')
173 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
174 print "Copyright (C) 2003 Free Software Foundation, Inc.\n";
175 print "This is free software; see the source for copying conditions. There is NO\n";
176 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
177 print "Written by Tom Tromey <tromey\@redhat.com>\n";
180 elsif ($arglist[0] eq '--help')
186 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
198 $default_dirlist="$acdir/dirlist"
199 if $acdir ne $default_acdir;
201 # Search the versioned directory near the end, and then the
202 # unversioned directory last. Only do this if the user didn't
204 push (@dirlist, "$acdir-$APIVERSION")
205 if $acdir eq $default_acdir;
207 # By default $(datadir)/aclocal doesn't exist. We don't want to
208 # get an error in the case where we are searching the default
209 # directory and it hasn't been created.
210 push (@dirlist, $acdir)
211 unless $acdir eq $default_acdir && ! -d $acdir;
213 # Finally, adds any directory listed in the `dirlist' file.
214 if (open (DEFAULT_DIRLIST, $default_dirlist))
216 while (<DEFAULT_DIRLIST>)
220 # strip off newlines and end-of-line comments
222 chomp ($contents=$_);
225 push (@dirlist, $contents);
228 close (DEFAULT_DIRLIST);
235 ################################################################
237 sub scan_configure ()
239 require_configure_ac;
241 open (CONFIGURE, $configure_ac)
242 || die "aclocal: couldn't open `$configure_ac': $!\n";
244 my $mtime = mtime $configure_ac;
245 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
247 # Make sure we include acinclude.m4 if it exists.
248 if (-f 'acinclude.m4')
250 &add_file ('acinclude.m4');
255 # Remove comments from current line.
259 # Search for things we know about. The "search" sub is
260 # constructed dynamically by scan_m4_files. The last
261 # parenthethical match makes sure we don't match things that
262 # look like macro assignments or AC_SUBSTs.
263 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
265 # Macro not found, but AM_ prefix found.
266 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
274 ################################################################
276 # Check macros in acinclude.m4. If one is not used, warn.
277 sub check_acinclude ()
281 foreach $key (keys %map)
283 next unless $map{$key} eq 'acinclude.m4';
284 if (! $macro_seen{$key})
286 # FIXME: should print line number of acinclude.m4.
287 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
292 ################################################################
294 # Scan all the installed m4 files and construct a map.
295 sub scan_m4_files (@)
297 local (@dirlist) = @_;
299 # First, scan acinclude.m4 if it exists.
300 if (-f 'acinclude.m4')
302 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
306 foreach $m4dir (@dirlist)
308 opendir (DIR, $m4dir)
309 || die "aclocal: couldn't open directory `$m4dir': $!\n";
310 local ($file, $fullfile);
311 foreach $file (sort grep (! /^\./, readdir (DIR)))
313 # Only examine .m4 files.
314 next unless $file =~ /\.m4$/;
316 # Skip some files when running out of srcdir.
317 next if $file eq 'aclocal.m4';
319 $fullfile = $m4dir . '/' . $file;
320 $file_contents{$fullfile} = &scan_file ($fullfile);
325 # Construct a new function that does the searching. We use a
326 # function (instead of just evalling $search in the loop) so that
327 # "die" is correctly and easily propagated if run.
328 my $search = "sub search {\nmy \$found = 0;\n";
329 foreach my $key (reverse sort keys %map)
331 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
332 . '"); $found = 1; }' . "\n");
334 $search .= "return \$found;\n};\n";
336 die "internal error: $@\n search is $search" if $@;
339 ################################################################
341 # Add a macro to the output.
346 # We want to ignore AC_ macros. However, if an AC_ macro is
347 # defined in (eg) acinclude.m4, then we want to make sure we mark
349 return if $macro =~ /^AC_/ && ! defined $map{$macro};
351 if (! defined $map{$macro})
353 warn "aclocal: macro `$macro' required but not defined\n";
358 print STDERR "aclocal: saw macro $macro\n" if $verbose;
359 $macro_seen{$macro} = 1;
360 &add_file ($map{$macro});
363 # Add a file to output.
368 # Only add a file once.
369 return if ($file_seen{$file});
370 $file_seen{$file} = 1;
372 my $mtime = mtime $file;
373 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
375 # If the file to add looks like path outside the project,
376 # copy it to the output.
377 # The regex catches filenames starting with things like
378 # / \ c:\ ../ ./../ etc.
379 if ($file =~ m,^(?:(?:\w:)?[\\/]|(?:\.[\\/]+)*\.\.[\\/]),)
381 $output .= $file_contents{$file} . "\n";
385 # Otherwise, simply include the file.
386 $output .= "m4_include([$file])\n";
389 foreach (split ("\n", $file_contents{$file}))
391 # Remove comments from current line.
395 if (/$ac_require_rx/g)
397 push (@rlist, $1 || $2);
400 # The search function is constructed dynamically by
401 # scan_m4_files. The last parenthethical match makes sure we
402 # don't match things that look like macro assignments or
404 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
406 # Macro not found, but AM_ prefix found.
407 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
413 foreach $macro (@rlist)
419 # Scan a single M4 file. Return contents.
424 my $fh = new Automake::XFile $file;
426 while ($_ = $fh->getline)
435 if (! defined $map{$1 || $2})
437 $map{$1 || $2} = $file;
440 # Note: we used to give an error here if we saw a
441 # duplicated macro. However, this turns out to be
442 # extremely unpopular. It causes actual problems which
443 # are hard to work around, especially when you must
444 # mix-and-match tool versions.
446 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
453 ################################################################
458 # Nothing to output?!
459 # FIXME: Shouldn't we diagnose this?
460 return if ! length ($output);
462 # We used to print `# $output_file generated automatically etc.' But
463 # this creates spurious differences when using autoreconf. Autoreconf
464 # creates aclocal.m4t and then rename it to aclocal.m4, but the
465 # rebuild rules generated by Automake create aclocal.m4 directly --
466 # this would gives two ways to get the same file, with a different
467 # name in the header.
468 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
470 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
471 # Free Software Foundation, Inc.
472 # This file is free software; the Free Software Foundation
473 # gives unlimited permission to copy and/or distribute it,
474 # with or without modifications, as long as this notice is preserved.
476 # This program is distributed in the hope that it will be useful,
477 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
478 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
479 # PARTICULAR PURPOSE.
483 # We try not to update $output_file unless necessary, because
484 # doing so invalidate Autom4te's cache and therefore slows down
485 # tools called after aclocal.
487 # We need to overwrite $output_file in the following situations.
488 # * The --force option is in use.
489 # * One of the dependencies is younger.
490 # (Not updating $output_file in this situation would cause
491 # make to call aclocal in loop.)
492 # * The contents of the current file are different from what
495 && $greatest_mtime < mtime ($output_file)
496 && $output eq contents ($output_file))
498 print STDERR "aclocal: $output_file unchanged\n" if $verbose;
502 print STDERR "aclocal: writing $output_file\n" if $verbose;
504 my $out = new Automake::XFile "> $output_file";
508 ### Setup "GNU" style for perl-mode and cperl-mode.
510 ## perl-indent-level: 2
511 ## perl-continued-statement-offset: 2
512 ## perl-continued-brace-offset: 0
513 ## perl-brace-offset: 0
514 ## perl-brace-imaginary-offset: 0
515 ## perl-label-offset: -2
516 ## cperl-indent-level: 2
517 ## cperl-brace-offset: 0
518 ## cperl-continued-brace-offset: 0
519 ## cperl-label-offset: -2
520 ## cperl-extra-newline-before-brace: t
521 ## cperl-merge-trailing-else: nil
522 ## cperl-continued-statement-offset: 2