Activate tab completion for git commands by default
[msysgit/historical-msysgit.git] / bin / aclocal-1.7
blobea2a104fba038d9736fbcf96a2d2e6d8305bd580
1 #!/bin/perl
2 # -*- perl -*-
3 # Makefile. Generated from Makefile.in by configure.
5 eval 'case $# in 0) exec /bin/perl -S "$0";; *) exec /bin/perl -S "$0" "$@";; esac'
6 if 0;
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)
16 # any later version.
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
26 # 02111-1307, USA.
28 # Written by Tom Tromey <tromey@redhat.com>.
30 BEGIN
32 my $perllibdir = $ENV{'perllibdir'} || '/usr/share/automake-1.7';
33 unshift @INC, $perllibdir;
36 use Automake::General;
37 use Automake::XFile;
39 # Some constants.
40 $VERSION = '1.7.1';
41 $APIVERSION = '1.7';
42 $PACKAGE = 'automake';
43 # Note that this isn't pkgdatadir, but a separate directory.
44 # Note also that the versioned directory is handled later.
45 $acdir = '/usr/share/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";
53 # Some globals.
55 # Exit status.
56 $exit_status = 0;
58 # Name of the top autoconf input: `configure.ac' or `configure.in'.
59 $configure_ac = find_configure_ac;
61 # Text to output.
62 $output = '';
64 # Output file name.
65 $output_file = 'aclocal.m4';
67 # Which macros have been seen.
68 %macro_seen = ();
70 # Which files have been seen.
71 %file_seen = ();
73 # Map macro names to file names.
74 %map = ();
76 # Map file names to file contents.
77 %file_contents = ();
79 # How much to say.
80 $verbose = 0;
82 # Matches a macro definition.
83 # AC_DEFUN([macroname], ...)
84 # or
85 # AC_DEFUN(macroname, ...)
86 # When macroname is `['-quoted , we accept any character in the name,
87 # except `]'. Otherwise macroname stops on the first `]', `,', `)',
88 # or `\n' encountered.
89 $ac_defun_rx = "A[CU]_DEFUN\\((?:\\[([^]]+)\\]|([^],)\n]+))";
91 # Matches an AC_REQUIRE line.
92 $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
96 local (@dirlist) = &parse_arguments (@ARGV);
97 &scan_m4_files (@dirlist);
98 &scan_configure;
99 if (! $exit_status)
101 &write_aclocal;
103 &check_acinclude;
105 exit $exit_status;
107 ################################################################
109 # Print usage and exit.
110 sub usage ($)
112 local ($status) = @_;
114 print "Usage: aclocal [OPTIONS] ...\n\n";
115 print "\
116 Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
118 --acdir=DIR directory holding config files
119 --help print this help, then exit
120 -I DIR add directory to search list for .m4 files
121 --output=FILE put output in FILE (default aclocal.m4)
122 --print-ac-dir print name of directory holding m4 files
123 --verbose don't be silent
124 --version print version number, then exit
126 Report bugs to <bug-automake\@gnu.org>.\n";
128 exit $status;
131 # Parse command line.
132 sub parse_arguments (@)
134 local (@arglist) = @_;
135 local (@dirlist);
136 local ($print_and_exit) = 0;
138 while (@arglist)
140 if ($arglist[0] =~ /^--acdir=(.+)$/)
142 $acdir = $1;
144 elsif ($arglist[0] =~/^--output=(.+)$/)
146 $output_file = $1;
148 elsif ($arglist[0] eq '-I')
150 shift (@arglist);
151 push (@dirlist, $arglist[0]);
153 elsif ($arglist[0] eq '--print-ac-dir')
155 $print_and_exit = 1;
157 elsif ($arglist[0] eq '--verbose')
159 ++$verbose;
161 elsif ($arglist[0] eq '--version')
163 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
164 print "Copyright (C) 2002 Free Software Foundation, Inc.\n";
165 print "This is free software; see the source for copying conditions. There is NO\n";
166 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
167 print "Written by Tom Tromey <tromey\@redhat.com>\n";
168 exit 0;
170 elsif ($arglist[0] eq '--help')
172 &usage (0);
174 else
176 die "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
179 shift (@arglist);
182 if ($print_and_exit)
184 print $acdir, "\n";
185 exit 0;
188 $default_dirlist="$acdir/dirlist"
189 if $acdir ne $default_acdir;
191 # Search the versioned directory near the end, and then the
192 # unversioned directory last. Only do this if the user didn't
193 # override acdir.
194 push (@dirlist, "$acdir-$APIVERSION")
195 if $acdir eq $default_acdir;
197 # By default $(datadir)/aclocal doesn't exist. We don't want to
198 # get an error in the case where we are searching the default
199 # directory and it hasn't been created.
200 push (@dirlist, $acdir)
201 unless $acdir eq $default_acdir && ! -d $acdir;
203 # Finally, adds any directory listed in the `dirlist' file.
204 if (open (DEFAULT_DIRLIST, $default_dirlist))
206 while (<DEFAULT_DIRLIST>)
208 # Ignore '#' lines.
209 next if /^#/;
210 # strip off newlines and end-of-line comments
211 s/\s*\#.*$//;
212 chomp ($contents=$_);
213 if (-d $contents )
215 push (@dirlist, $contents);
218 close (DEFAULT_DIRLIST);
222 return @dirlist;
225 ################################################################
227 sub scan_configure ()
229 die "aclocal: `configure.ac' or `configure.in' is required\n"
230 if !$configure_ac;
232 open (CONFIGURE, $configure_ac)
233 || die "aclocal: couldn't open `$configure_ac': $!\n";
235 # Make sure we include acinclude.m4 if it exists.
236 if (-f 'acinclude.m4')
238 &add_file ('acinclude.m4');
241 while (<CONFIGURE>)
243 # Remove comments from current line.
244 s/\bdnl\b.*$//;
245 s/\#.*$//;
247 # Search for things we know about. The "search" sub is
248 # constructed dynamically by scan_m4_files. The last
249 # parenthethical match makes sure we don't match things that
250 # look like macro assignments or AC_SUBSTs.
251 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
253 # Macro not found, but AM_ prefix found.
254 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
255 $exit_status = 1;
259 close (CONFIGURE);
262 ################################################################
264 # Check macros in acinclude.m4. If one is not used, warn.
265 sub check_acinclude ()
267 local ($key);
269 foreach $key (keys %map)
271 next unless $map{$key} eq 'acinclude.m4';
272 if (! $macro_seen{$key})
274 # FIXME: should print line number of acinclude.m4.
275 warn "aclocal: macro `$key' defined in acinclude.m4 but never used\n";
280 ################################################################
282 # Scan all the installed m4 files and construct a map.
283 sub scan_m4_files (@)
285 local (@dirlist) = @_;
287 # First, scan acinclude.m4 if it exists.
288 if (-f 'acinclude.m4')
290 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
293 local ($m4dir);
294 foreach $m4dir (@dirlist)
296 opendir (DIR, $m4dir)
297 || die "aclocal: couldn't open directory `$m4dir': $!\n";
298 local ($file, $fullfile);
299 foreach $file (sort grep (! /^\./, readdir (DIR)))
301 # Only examine .m4 files.
302 next unless $file =~ /\.m4$/;
304 # Skip some files when running out of srcdir.
305 next if $file eq 'aclocal.m4';
307 $fullfile = $m4dir . '/' . $file;
308 $file_contents{$fullfile} = &scan_file ($fullfile);
310 closedir (DIR);
313 # Construct a new function that does the searching. We use a
314 # function (instead of just evalling $search in the loop) so that
315 # "die" is correctly and easily propagated if run.
316 my $search = "sub search {\nmy \$found = 0;\n";
317 foreach my $key (reverse sort keys %map)
319 $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
320 . '"); $found = 1; }' . "\n");
322 $search .= "return \$found;\n};\n";
323 eval $search;
324 die "internal error: $@\n search is $search" if $@;
327 ################################################################
329 # Add a macro to the output.
330 sub add_macro ($)
332 local ($macro) = @_;
334 # We want to ignore AC_ macros. However, if an AC_ macro is
335 # defined in (eg) acinclude.m4, then we want to make sure we mark
336 # it as seen.
337 return if $macro =~ /^AC_/ && ! defined $map{$macro};
339 if (! defined $map{$macro})
341 warn "aclocal: macro `$macro' required but not defined\n";
342 $exit_status = 1;
343 return;
346 print STDERR "aclocal: saw macro $macro\n" if $verbose;
347 $macro_seen{$macro} = 1;
348 &add_file ($map{$macro});
351 # Add a file to output.
352 sub add_file ($)
354 local ($file) = @_;
356 # Only add a file once.
357 return if ($file_seen{$file});
358 $file_seen{$file} = 1;
360 $output .= $file_contents{$file} . "\n";
361 my (@rlist);
362 foreach (split ("\n", $file_contents{$file}))
364 # Remove comments from current line.
365 s/\bdnl\b.*$//;
366 s/\#.*$//;
368 if (/$ac_require_rx/g)
370 push (@rlist, $1 || $2);
373 # The search function is constructed dynamically by
374 # scan_m4_files. The last parenthethical match makes sure we
375 # don't match things that look like macro assignments or
376 # AC_SUBSTs.
377 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
379 # Macro not found, but AM_ prefix found.
380 warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
381 $exit_status = 1;
385 local ($macro);
386 foreach $macro (@rlist)
388 &add_macro ($macro);
392 # Scan a single M4 file. Return contents.
393 sub scan_file ($)
395 local ($file) = @_;
397 my $fh = new Automake::XFile $file;
398 my $contents = '';
399 while ($_ = $fh->getline)
401 # Ignore `##' lines.
402 next if /^##/;
404 $contents .= $_;
406 if (/$ac_defun_rx/)
408 if (! defined $map{$1 || $2})
410 $map{$1 || $2} = $file;
413 # Note: we used to give an error here if we saw a
414 # duplicated macro. However, this turns out to be
415 # extremely unpopular. It causes actual problems which
416 # are hard to work around, especially when you must
417 # mix-and-match tool versions.
419 print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
423 return $contents;
426 ################################################################
428 # Write output.
429 sub write_aclocal ()
431 return if ! length ($output);
433 print STDERR "aclocal: writing $output_file\n" if $verbose;
435 my $out = new Automake::XFile "> $output_file";
437 # We used to print `# $output_file generated automatically etc.' But
438 # this creates spurious differences when using autoreconf. Autoreconf
439 # creates aclocal.m4t and then rename it to aclocal.m4, but the
440 # rebuild rules generated by Automake create aclocal.m4 directly --
441 # this would gives two ways to get the same file, with a different
442 # name in the header.
443 print $out
444 "# generated automatically by aclocal $VERSION -*- Autoconf -*-
446 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
447 # Free Software Foundation, Inc.
448 # This file is free software; the Free Software Foundation
449 # gives unlimited permission to copy and/or distribute it,
450 # with or without modifications, as long as this notice is preserved.
452 # This program is distributed in the hope that it will be useful,
453 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
454 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
455 # PARTICULAR PURPOSE.
457 $output";
460 ### Setup "GNU" style for perl-mode and cperl-mode.
461 ## Local Variables:
462 ## perl-indent-level: 2
463 ## perl-continued-statement-offset: 2
464 ## perl-continued-brace-offset: 0
465 ## perl-brace-offset: 0
466 ## perl-brace-imaginary-offset: 0
467 ## perl-label-offset: -2
468 ## cperl-indent-level: 2
469 ## cperl-brace-offset: 0
470 ## cperl-continued-brace-offset: 0
471 ## cperl-label-offset: -2
472 ## cperl-extra-newline-before-brace: t
473 ## cperl-merge-trailing-else: nil
474 ## cperl-continued-statement-offset: 2
475 ## End: