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";
55 # configure.ac or configure.in.
56 my $configure_ac = require_configure_ac;
65 $output_file = 'aclocal.m4';
67 # Modification time of the youngest dependency.
73 # Which macros have been seen.
76 # Which files have been seen.
79 # Map macro names to file names.
82 # Map file names to file contents.
88 # Matches a macro definition.
89 # AC_DEFUN([macroname], ...)
91 # AC_DEFUN(macroname, ...)
92 # When macroname is `['-quoted , we accept any character in the name,
93 # except `]'. Otherwise macroname stops on the first `]', `,', `)',
94 # or `\n' encountered.
95 $ac_defun_rx = "A[CU]_DEFUN\\((?:\\[([^]]+)\\]|([^],)\n]+))";
97 # Matches an AC_REQUIRE line.
98 $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
102 local (@dirlist) = &parse_arguments (@ARGV);
103 &scan_m4_files (@dirlist);
113 ################################################################
115 # Print usage and exit.
118 local ($status) = @_;
120 print "Usage: aclocal [OPTIONS] ...\n\n";
122 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
124 --acdir=DIR directory holding config files
125 --help print this help, then exit
126 -I DIR add directory to search list for .m4 files
127 --force always update output file
128 --output=FILE put output in FILE (default aclocal.m4)
129 --print-ac-dir print name of directory holding m4 files
130 --verbose don't be silent
131 --version print version number, then exit
133 Report bugs to <bug-automake\@gnu.org>.\n";
138 # Parse command line.
139 sub parse_arguments (@)
141 local (@arglist) = @_;
143 local ($print_and_exit) = 0;
147 if ($arglist[0] =~ /^--acdir=(.+)$/)
151 elsif ($arglist[0] =~/^--output=(.+)$/)
155 elsif ($arglist[0] eq '-I')
158 push (@dirlist, $arglist[0]);
160 elsif ($arglist[0] eq '--print-ac-dir')
164 elsif ($arglist[0] eq '--force')
168 elsif ($arglist[0] eq '--verbose')
172 elsif ($arglist[0] eq '--version')
174 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
175 print "Copyright (C) 2003 Free Software Foundation, Inc.\n";
176 print "This is free software; see the source for copying conditions. There is NO\n";
177 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
178 print "Written by Tom Tromey <tromey\@redhat.com>\n";
181 elsif ($arglist[0] eq '--help')
187 print STDERR "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
200 $default_dirlist="$acdir/dirlist"
201 if $acdir ne $default_acdir;
203 # Search the versioned directory near the end, and then the
204 # unversioned directory last. Only do this if the user didn't
206 push (@dirlist, "$acdir-$APIVERSION")
207 if $acdir eq $default_acdir;
209 # By default $(datadir)/aclocal doesn't exist. We don't want to
210 # get an error in the case where we are searching the default
211 # directory and it hasn't been created.
212 push (@dirlist, $acdir)
213 unless $acdir eq $default_acdir && ! -d $acdir;
215 # Finally, adds any directory listed in the `dirlist' file.
216 if (open (DEFAULT_DIRLIST, $default_dirlist))
218 while (<DEFAULT_DIRLIST>)
222 # strip off newlines and end-of-line comments
224 chomp ($contents=$_);
227 push (@dirlist, $contents);
230 close (DEFAULT_DIRLIST);
237 ################################################################
239 sub scan_configure ()
241 if (! open (CONFIGURE, $configure_ac))
243 print STDERR "aclocal: couldn't open `$configure_ac': $!\n";
247 my $mtime = mtime $configure_ac;
248 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
250 # Make sure we include acinclude.m4 if it exists.
251 if (-f 'acinclude.m4')
253 &add_file ('acinclude.m4');
258 # Remove comments from current line.
262 # Search for things we know about. The "search" sub is
263 # constructed dynamically by scan_m4_files. The last
264 # parenthethical match makes sure we don't match things that
265 # look like macro assignments or AC_SUBSTs.
266 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
268 # Macro not found, but AM_ prefix found.
269 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
277 ################################################################
279 # Check macros in acinclude.m4. If one is not used, warn.
280 sub check_acinclude ()
284 foreach $key (keys %map)
286 next unless $map{$key} eq 'acinclude.m4';
287 if (! $macro_seen{$key})
289 # FIXME: should print line number of acinclude.m4.
290 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
295 ################################################################
297 # Scan all the installed m4 files and construct a map.
298 sub scan_m4_files (@)
300 local (@dirlist) = @_;
302 # First, scan acinclude.m4 if it exists.
303 if (-f 'acinclude.m4')
305 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
309 foreach $m4dir (@dirlist)
311 if (! opendir (DIR, $m4dir))
313 print STDERR "aclocal: couldn't open directory `$m4dir': $!\n";
317 local ($file, $fullfile);
318 foreach $file (sort grep (! /^\./, readdir (DIR)))
320 # Only examine .m4 files.
321 next unless $file =~ /\.m4$/;
323 # Skip some files when running out of srcdir.
324 next if $file eq 'aclocal.m4';
326 $fullfile = $m4dir . '/' . $file;
327 $file_contents{$fullfile} = &scan_file ($fullfile);
332 # Construct a new function that does the searching. We use a
333 # function (instead of just evalling $search in the loop) so that
334 # "die" is correctly and easily propagated if run.
335 my $search = "sub search {\nmy \$found = 0;\n";
336 foreach my $key (reverse sort keys %map)
338 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
339 . '"); $found = 1; }' . "\n");
341 $search .= "return \$found;\n};\n";
343 die "internal error: $@\n search is $search" if $@;
346 ################################################################
348 # Add a macro to the output.
353 # We want to ignore AC_ macros. However, if an AC_ macro is
354 # defined in (eg) acinclude.m4, then we want to make sure we mark
356 return if $macro =~ /^AC_/ && ! defined $map{$macro};
358 if (! defined $map{$macro})
360 warn "aclocal: macro `$macro' required but not defined\n";
365 print STDERR "aclocal: saw macro $macro\n" if $verbose;
366 $macro_seen{$macro} = 1;
367 &add_file ($map{$macro});
370 # Add a file to output.
375 # Only add a file once.
376 return if ($file_seen{$file});
377 $file_seen{$file} = 1;
379 my $mtime = mtime $file;
380 $greatest_mtime = $mtime if $greatest_mtime < $mtime;
382 # If the file to add looks like path outside the project,
383 # copy it to the output.
384 # The regex catches filenames starting with things like
385 # / \ c:\ ../ ./../ etc.
386 if ($file =~ m,^(?:(?:\w:)?[\\/]|(?:\.[\\/]+)*\.\.[\\/]),)
388 $output .= $file_contents{$file} . "\n";
392 # Otherwise, simply include the file.
393 $output .= "m4_include([$file])\n";
396 foreach (split ("\n", $file_contents{$file}))
398 # Remove comments from current line.
402 if (/$ac_require_rx/g)
404 push (@rlist, $1 || $2);
407 # The search function is constructed dynamically by
408 # scan_m4_files. The last parenthethical match makes sure we
409 # don't match things that look like macro assignments or
411 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
413 # Macro not found, but AM_ prefix found.
414 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
420 foreach $macro (@rlist)
426 # Scan a single M4 file. Return contents.
431 my $fh = new Automake::XFile $file;
433 while ($_ = $fh->getline)
442 if (! defined $map{$1 || $2})
444 $map{$1 || $2} = $file;
447 # Note: we used to give an error here if we saw a
448 # duplicated macro. However, this turns out to be
449 # extremely unpopular. It causes actual problems which
450 # are hard to work around, especially when you must
451 # mix-and-match tool versions.
453 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
460 ################################################################
465 # Nothing to output?!
466 # FIXME: Shouldn't we diagnose this?
467 return if ! length ($output);
469 # We used to print `# $output_file generated automatically etc.' But
470 # this creates spurious differences when using autoreconf. Autoreconf
471 # creates aclocal.m4t and then rename it to aclocal.m4, but the
472 # rebuild rules generated by Automake create aclocal.m4 directly --
473 # this would gives two ways to get the same file, with a different
474 # name in the header.
475 $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
477 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
478 # Free Software Foundation, Inc.
479 # This file is free software; the Free Software Foundation
480 # gives unlimited permission to copy and/or distribute it,
481 # with or without modifications, as long as this notice is preserved.
483 # This program is distributed in the hope that it will be useful,
484 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
485 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
486 # PARTICULAR PURPOSE.
490 # We try not to update $output_file unless necessary, because
491 # doing so invalidate Autom4te's cache and therefore slows down
492 # tools called after aclocal.
494 # We need to overwrite $output_file in the following situations.
495 # * The --force option is in use.
496 # * One of the dependencies is younger.
497 # (Not updating $output_file in this situation would cause
498 # make to call aclocal in loop.)
499 # * The contents of the current file are different from what
502 && $greatest_mtime < mtime ($output_file)
503 && $output eq contents ($output_file))
505 print STDERR "aclocal: $output_file unchanged\n" if $verbose;
509 print STDERR "aclocal: writing $output_file\n" if $verbose;
511 my $out = new Automake::XFile "> $output_file";
515 ### Setup "GNU" style for perl-mode and cperl-mode.
517 ## perl-indent-level: 2
518 ## perl-continued-statement-offset: 2
519 ## perl-continued-brace-offset: 0
520 ## perl-brace-offset: 0
521 ## perl-brace-imaginary-offset: 0
522 ## perl-label-offset: -2
523 ## cperl-indent-level: 2
524 ## cperl-brace-offset: 0
525 ## cperl-continued-brace-offset: 0
526 ## cperl-label-offset: -2
527 ## cperl-extra-newline-before-brace: t
528 ## cperl-merge-trailing-else: nil
529 ## cperl-continued-statement-offset: 2