fixed output3.test
[automake.git] / aclocal.in
blobffbbbe2b7b06625a4db7f2b7dc300ffc349f674e
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
5 # aclocal - create aclocal.m4 by scanning configure.in
6 # Copyright (C) 1996 Free Software Foundation, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # 02111-1307, USA.
23 # Written by Tom Tromey <tromey@cygnus.com>.
25 eval 'exec @PERL@ -S $0 ${1+"$@"}'
26     if 0;
28 # aclocal - scan configure.in and generate aclocal.m4.
30 # Some constants.
31 $VERSION = "@VERSION@";
32 $PACKAGE = "@PACKAGE@";
33 $prefix = "@prefix@";
34 # Note that this isn't pkgdatadir, but a separate directory.
35 $acdir = "@datadir@/aclocal";
37 # Some globals.
39 # Exit status.
40 $exit_status = 0;
42 # Text to output.
43 $output = '';
45 # Output file name.
46 $output_file = 'aclocal.m4';
48 # Which macros have been seen.
49 %macro_seen = ();
51 # Which files have been seen.
52 %file_seen = ();
54 # Map macro names to file names.
55 %map = ();
57 # Map file names to file contents.
58 %file_contents = ();
60 # How much to say.
61 $verbosity = 0;
63 @obsolete_macros =
64     (
65      'AC_FEATURE_CTYPE',
66      'AC_FEATURE_ERRNO',
67      'AC_FEATURE_EXIT',
68      'AC_SYSTEM_HEADER',
69      'fp_C_PROTOTYPES',
70      'fp_FUNC_FNMATCH',
71      'fp_PROG_CC_STDC',
72      'fp_PROG_INSTALL',
73      'fp_WITH_DMALLOC',
74      'fp_WITH_REGEX',
75      'gm_PROG_LIBTOOL',
76      'jm_MAINTAINER_MODE',
77      'md_TYPE_PTRDIFF_T',
78      'ud_PATH_LISPDIR',
79      'ud_GNU_GETTEXT',
81      # Now part of autoconf proper, under a different name.
82      'AM_FUNC_FNMATCH',
83      'AM_SANITY_CHECK_CC',
85 # These aren't quite obsolete.
86 #      'md_PATH_PROG',
87 #      'ud_GNU_GETTEXT',
88 #      'ud_LC_MESSAGES',
89 #      'ud_WITH_NLS'
90      );
92 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
94 # Matches a macro definition.
95 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
97 # Matches an AC_REQUIRE line.
98 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
102 &parse_arguments (@ARGV);
103 &scan_m4_files ($acdir);
104 &scan_configure;
105 if (! $exit_status)
107     &write_aclocal;
109 &check_acinclude;
111 exit $exit_status;
113 ################################################################
115 # Print usage and exit.
116 sub usage
118     local ($status) = @_;
120     print "Usage: aclocal [OPTIONS] ...\n";
121     print "\
122   --acdir=DIR           directory holding config files
123   --help                print this help, then exit
124   --output=FILE         put output in FILE (default aclocal.m4)
125   --verbose             don't be silent
126   --version             print version number, then exit
128 Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
130     exit $status;
133 # Parse command line.
134 sub parse_arguments
136     local (@arglist) = @_;
138     while (@arglist)
139     {
140         if ($arglist[0] =~ /^--acdir=(.+)$/)
141         {
142             $acdir = $1;
143         }
144         elsif ($arglist[0] =~/^--output=(.+)$/)
145         {
146             $output_file = $1;
147         }
148         elsif ($arglist[0] eq '--verbose')
149         {
150             ++$verbosity;
151         }
152         elsif ($arglist[0] eq '--version')
153         {
154             print "aclocal (GNU $PACKAGE) $VERSION\n";
155             print "Copyright (C) 1996 Free Software Foundation, Inc.\n";
156             print "aclocal comes with ABSOLUTELY NO WARRANTY.\n";
157             print "You may redistribute copies of aclocal\n";
158             print "under the terms of the GNU General Public License.\n";
159             print "For more information about these matters, see the file named COPYING.\n";
160             exit 0;
161         }
162         elsif ($arglist[0] eq '--help')
163         {
164             &usage (0);
165         }
166         else
167         {
168             die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
169         }
171         shift (@arglist);
172     }
175 ################################################################
177 sub scan_configure
179     open (CONFIGURE, "configure.in")
180         || die "aclocal: couldn't open \`configure.in': $!\n";
182     # Make sure we include acinclude.m4 if it exists.
183     if (-f 'acinclude.m4')
184     {
185         &add_file ('acinclude.m4');
186     }
188     while (<CONFIGURE>)
189     {
190         # Remove comments from current line.
191         s/\bdnl\b.*$//;
192         s/\#.*$//;
194         if (/$obsolete_rx/o)
195         {
196             chop;
197             warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
198             $exit_status = 1;
199             next;
200         }
202         # Search for things we know about.  The "search" sub is
203         # constructed dynamically, above.
204         &search;
205     }
207     close (CONFIGURE);
210 ################################################################
212 # Check macros in acinclude.m4.  If one is not used, warn.
213 sub check_acinclude
215     local ($key);
217     foreach $key (keys %map)
218     {
219         next unless $map{$key} eq 'acinclude.m4';
220         if (! $macro_seen{$key})
221         {
222             warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
223         }
224     }
227 ################################################################
229 # Scan all the installed m4 files and construct a map.
230 sub scan_m4_files
232     local ($m4dir) = @_;
234     # First, scan acinclude.m4 if it exists.
235     if (-f 'acinclude.m4')
236     {
237         $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
238     }
240     opendir (DIR, $m4dir)
241         || die "aclocal: couldn't open directory \`$m4dir': $!\n";
242     local ($file, $fullfile, $expr);
243     foreach $file (sort grep (! /^\./, readdir (DIR)))
244     {
245         # Only examine .m4 files.
246         next unless $file =~ /\.m4$/;
248         # Skip some files when running out of srcdir.
249         next if $file eq 'aclocal.m4';
251         $fullfile = $m4dir . '/' . $file;
252         $file_contents{$fullfile} = &scan_file ($fullfile);
253     }
254     closedir (DIR);
256     # Construct a new function that does the searching.  We use a
257     # function (instead of just evalling $search in the loop) so that
258     # "die" is correctly and easily propagated if run.
259     local ($search, $expr, $key);
260     foreach $key (keys %map)
261     {
262         # EXPR is a regexp matching the name of the macro.
263         ($expr = $key) =~ s/(\W)/\\$1/g;
264         $search .= "&add_macro ('" . $key . "') if /" . $expr . "/;\n";
265     }
266     eval 'sub search { ' . $search . '};';
267     die "internal error: $@\n search is $search " if $@;
270 ################################################################
272 # Add a macro to the output.
273 sub add_macro
275     local ($macro) = @_;
277     # Ignore AC_ macros.
278     return if $macro =~ /^AC_/;
280     if (! defined $map{$macro})
281     {
282         warn "aclocal: macro \`$macro' required but not defined\n";
283         $exit_status = 1;
284         return;
285     }
287     print STDERR "saw macro $macro\n" if $verbosity;
288     $macro_seen{$macro} = 1;
289     &add_file ($map{$macro});
292 # Add a file to output.
293 sub add_file
295     local ($file) = @_;
297     # Only add a file once.
298     return if ($file_seen{$file});
299     $file_seen{$file} = 1;
301     $output .= $file_contents{$file} . "\n";
302     local (@rlist);
303     foreach (split ("\n", $file_contents{$file}))
304     {
305         if (/$ac_require_rx/g)
306         {
307             push (@rlist, $1);
308         }
310         # This function constructed dynamically.
311         &search;
312     }
314     local ($macro);
315     foreach $macro (@rlist)
316     {
317         &add_macro ($macro);
318     }
321 # Scan a single M4 file.  Return contents.
322 sub scan_file
324     local ($file) = @_;
326     open (FILE, $file)
327         || die "aclocal: couldn't open \`$file': $!\n";
328     local ($contents) = '';
329     while (<FILE>)
330     {
331         # Ignore `##' lines.
332         next if /^##/;
334         $contents .= $_;
336         if (/$ac_defun_rx/)
337         {
338             if (!defined $map{$1})
339             {
340                 $map{$1} = $file;
341             }
342             # Allow acinclude.m4 to override other macro files.
343             elsif ($map{$1} ne 'acinclude.m4' || $file eq 'acinclude.m4')
344             {
345                 warn "aclocal: $file: $.: duplicated macro \`$1'\n";
346                 $exit_status = 1;
347             }
348             print STDERR "Found macro $1 in $file: $.\n" if $verbosity;
349         }
350     }
351     close (FILE);
353     return $contents;
356 ################################################################
358 # Write output.
359 sub write_aclocal
361     return if ! length ($output);
363     print STDERR "Writing aclocal.m4\n" if $verbosity;
365     open (ACLOCAL, "> aclocal.m4")
366         || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
367     print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
368     print ACLOCAL $output;
369     close (ACLOCAL);