source: vendor/automake/1.4-p6/aclocal.in@ 3124

Last change on this file since 3124 was 3124, checked in by bird, 18 years ago

automake 1.4-p6

File size: 11.1 KB
Line 
1#!@PERL@
2# -*- perl -*-
3# @configure_input@
4
5# aclocal - create aclocal.m4 by scanning configure.ac
6# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
7
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.
12
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.
17
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.
22
23# Written by Tom Tromey <tromey@redhat.com>.
24
25eval 'exec @PERL@ -S $0 ${1+"$@"}'
26 if 0;
27
28# aclocal - scan configure.ac and generate aclocal.m4.
29
30# Some constants.
31$VERSION = "@VERSION@";
32$APIVERSION = "@APIVERSION@";
33$PACKAGE = "@PACKAGE@";
34$prefix = "@prefix@";
35# Note that this isn't pkgdatadir, but a separate directory.
36# Note also that the versioned directory is handled later.
37$acdir = "@datadir@/aclocal";
38$default_acdir = $acdir;
39
40# Some globals.
41
42# Exit status.
43$exit_status = 0;
44
45# Text to output.
46$output = '';
47
48# Output file name.
49$output_file = 'aclocal.m4';
50
51# Which macros have been seen.
52%macro_seen = ();
53
54# Which files have been seen.
55%file_seen = ();
56
57# Map macro names to file names.
58%map = ();
59
60# Map file names to file contents.
61%file_contents = ();
62
63# How much to say.
64$verbosity = 0;
65
66# Name of the top autoconf input: `configure.ac' or `configure.in'
67$configure_ac = '';
68
69@obsolete_macros =
70 (
71 'AC_FEATURE_CTYPE',
72 'AC_FEATURE_ERRNO',
73 'AC_FEATURE_EXIT',
74 'AC_SYSTEM_HEADER',
75 'fp_C_PROTOTYPES',
76 'fp_FUNC_FNMATCH',
77 'fp_PROG_CC_STDC',
78 'fp_PROG_INSTALL',
79 'fp_WITH_DMALLOC',
80 'fp_WITH_REGEX',
81 'gm_PROG_LIBTOOL',
82 'jm_MAINTAINER_MODE',
83 'md_TYPE_PTRDIFF_T',
84 'ud_PATH_LISPDIR',
85 'ud_GNU_GETTEXT',
86
87 # Now part of autoconf proper, under a different name.
88 'AM_FUNC_FNMATCH',
89 'AM_SANITY_CHECK_CC',
90 'AM_PROG_INSTALL',
91 'AM_EXEEXT',
92 'AM_CYGWIN32',
93 'AM_MINGW32',
94
95# These aren't quite obsolete.
96# 'md_PATH_PROG',
97# 'ud_LC_MESSAGES',
98# 'ud_WITH_NLS'
99 );
100
101$obsolete_rx = '\b(' . join ('|', @obsolete_macros) . ')\b';
102
103# Matches a macro definition.
104$ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
105
106# Matches an AC_REQUIRE line.
107$ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
108
109
110
111
112local (@dirlist) = &parse_arguments (@ARGV);
113&scan_m4_files (@dirlist);
114&scan_configure;
115if (! $exit_status)
116{
117 &write_aclocal;
118}
119&check_acinclude;
120
121exit $exit_status;
122
123################################################################
124
125# Print usage and exit.
126sub usage
127{
128 local ($status) = @_;
129
130 print "Usage: aclocal [OPTIONS] ...\n\n";
131 print "Generate aclocal.m4 by scanning configure.ac\n
132 --acdir=DIR directory holding config files
133 --help print this help, then exit
134 -I DIR add directory to search list for .m4 files
135 --output=FILE put output in FILE (default aclocal.m4)
136 --print-ac-dir print name of directory holding m4 files
137 --verbose don't be silent
138 --version print version number, then exit
139
140Report bugs to <bug-automake\@gnu.org>.\n";
141
142 exit $status;
143}
144
145# Parse command line.
146sub parse_arguments
147{
148 local (@arglist) = @_;
149 local (@dirlist);
150 local ($print_and_exit) = 0;
151
152 while (@arglist)
153 {
154 if ($arglist[0] =~ /^--acdir=(.+)$/)
155 {
156 $acdir = $1;
157 }
158 elsif ($arglist[0] =~/^--output=(.+)$/)
159 {
160 $output_file = $1;
161 }
162 elsif ($arglist[0] eq '-I')
163 {
164 shift (@arglist);
165 push (@dirlist, $arglist[0]);
166 }
167 elsif ($arglist[0] eq '--print-ac-dir')
168 {
169 $print_and_exit = 1;
170 }
171 elsif ($arglist[0] eq '--verbose')
172 {
173 ++$verbosity;
174 }
175 elsif ($arglist[0] eq '--version')
176 {
177 print "aclocal (GNU $PACKAGE) $VERSION\n\n";
178 print "Copyright (C) 1999, 2001 Free Software Foundation, Inc.\n";
179 print "This is free software; see the source for copying conditions. There is NO\n";
180 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
181 print "Written by Tom Tromey <tromey\@redhat.com>\n";
182 exit 0;
183 }
184 elsif ($arglist[0] eq '--help')
185 {
186 &usage (0);
187 }
188 else
189 {
190 die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
191 }
192
193 shift (@arglist);
194 }
195
196 if ($print_and_exit)
197 {
198 print $acdir, "\n";
199 exit 0;
200 }
201
202 # Search the versioned directory near the end, and then the
203 # unversioned directory last. Only do this if the user didn't
204 # override acdir.
205 push (@dirlist, "$acdir-$APIVERSION")
206 if $acdir eq $default_acdir;
207
208 # By default $(datadir)/aclocal doesn't exist. We don't want to
209 # get an error in the case where we are searching the default
210 # directory and it hasn't been created.
211 push (@dirlist, $acdir)
212 unless $acdir eq $default_acdir && ! -d $acdir;
213
214 return @dirlist;
215}
216
217################################################################
218
219sub scan_configure
220{
221 warn "aclocal: both `configure.ac' and `configure.in' present:"
222 . " ignoring `configure.in'\n"
223 if -f 'configure.ac' && -f 'configure.in';
224 $configure_ac = 'configure.in'
225 if -f 'configure.in';
226 $configure_ac = 'configure.ac'
227 if -f 'configure.ac';
228 die "aclocal: `configure.ac' or `configure.in' is required\n"
229 if !$configure_ac;
230
231 open (CONFIGURE, $configure_ac)
232 || die "aclocal: couldn't open \`$configure_ac': $!\n";
233
234 # Make sure we include acinclude.m4 if it exists.
235 if (-f 'acinclude.m4')
236 {
237 &add_file ('acinclude.m4');
238 }
239
240 while (<CONFIGURE>)
241 {
242 # Remove comments from current line.
243 s/\bdnl\b.*$//;
244 s/\#.*$//;
245
246 if (/$obsolete_rx/o)
247 {
248 chop;
249 warn "aclocal: $configure_ac: $.: obsolete macro \`$_'\n";
250 $exit_status = 1;
251 next;
252 }
253
254 # Search for things we know about. The "search" sub is
255 # constructed dynamically by scan_m4_files.
256 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)/)
257 {
258 # Macro not found, but AM_ prefix found.
259 warn "aclocal: $configure_ac: $.: macro \`$2' not found in library\n";
260 $exit_status = 1;
261 }
262 }
263
264 close (CONFIGURE);
265}
266
267################################################################
268
269# Check macros in acinclude.m4. If one is not used, warn.
270sub check_acinclude
271{
272 local ($key);
273
274 foreach $key (keys %map)
275 {
276 next unless $map{$key} eq 'acinclude.m4';
277 if (! $macro_seen{$key})
278 {
279 # FIXME: should print line number of acinclude.m4.
280 warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
281 }
282 }
283}
284
285################################################################
286
287# Scan all the installed m4 files and construct a map.
288sub scan_m4_files
289{
290 local (@dirlist) = @_;
291
292 # First, scan acinclude.m4 if it exists.
293 if (-f 'acinclude.m4')
294 {
295 $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
296 }
297
298 local ($m4dir);
299 foreach $m4dir (@dirlist)
300 {
301 opendir (DIR, $m4dir)
302 || die "aclocal: couldn't open directory \`$m4dir': $!\n";
303 local ($file, $fullfile, $expr);
304 foreach $file (sort grep (! /^\./, readdir (DIR)))
305 {
306 # Only examine .m4 files.
307 next unless $file =~ /\.m4$/;
308
309 # Skip some files when running out of srcdir.
310 next if $file eq 'aclocal.m4';
311
312 $fullfile = $m4dir . '/' . $file;
313 $file_contents{$fullfile} = &scan_file ($fullfile);
314 }
315 closedir (DIR);
316 }
317
318 # Construct a new function that does the searching. We use a
319 # function (instead of just evalling $search in the loop) so that
320 # "die" is correctly and easily propagated if run.
321 local ($search, $expr, $key) = '';
322 foreach $key (reverse sort keys %map)
323 {
324 # EXPR is a regexp matching the name of the macro.
325 ($expr = $key) =~ s/(\W)/\\$1/g;
326 $search .= ("if (/" . $expr . "/) { & add_macro (" . $key
327 . "); return 1; }\n");
328 }
329 $search .= "return 0;\n";
330 eval 'sub search { ' . $search . '};';
331 die "internal error: $@\n search is $search " if $@;
332}
333
334################################################################
335
336# Add a macro to the output.
337sub add_macro
338{
339 local ($macro) = @_;
340
341 # We want to ignore AC_ macros. However, if an AC_ macro is
342 # defined in (eg) acinclude.m4, then we want to make sure we mark
343 # it as seen.
344 return if $macro =~ /^AC_/ && ! defined $map{$macro};
345
346 if (! defined $map{$macro})
347 {
348 warn "aclocal: macro \`$macro' required but not defined\n";
349 $exit_status = 1;
350 return;
351 }
352
353 print STDERR "saw macro $macro\n" if $verbosity;
354 $macro_seen{$macro} = 1;
355 &add_file ($map{$macro});
356}
357
358# Add a file to output.
359sub add_file
360{
361 local ($file) = @_;
362
363 # Only add a file once.
364 return if ($file_seen{$file});
365 $file_seen{$file} = 1;
366
367 $output .= $file_contents{$file} . "\n";
368 local ($a, @rlist);
369 foreach (split ("\n", $file_contents{$file}))
370 {
371 # This is a hack for Perl 4.
372 $a = $_;
373 if ($a =~ /$ac_require_rx/g)
374 {
375 push (@rlist, $1);
376 }
377
378 # This function constructed dynamically.
379 if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)/)
380 {
381 # Macro not found, but AM_ prefix found.
382 warn "aclocal: $configure_ac: $.: macro \`$2' not found in library\n";
383 $exit_status = 1;
384 }
385 }
386
387 local ($macro);
388 foreach $macro (@rlist)
389 {
390 &add_macro ($macro);
391 }
392}
393
394# Scan a single M4 file. Return contents.
395sub scan_file
396{
397 local ($file) = @_;
398
399 open (FILE, $file)
400 || die "aclocal: couldn't open \`$file': $!\n";
401 local ($contents) = '';
402 while (<FILE>)
403 {
404 # Ignore `##' lines.
405 next if /^##/;
406
407 $contents .= $_;
408
409 if (/$ac_defun_rx/)
410 {
411 if (!defined $map{$1})
412 {
413 $map{$1} = $file;
414 }
415
416 # Note: we used to give an error here if we saw a
417 # duplicated macro. However, this turns out to be
418 # extremely unpopular. It causes actual problems which
419 # are hard to work around, especially when you must
420 # mix-and-match tool versions.
421
422 print STDERR "Found macro $1 in $file: $.\n" if $verbosity;
423 }
424 }
425 close (FILE);
426
427 return $contents;
428}
429
430################################################################
431
432# Write output.
433sub write_aclocal
434{
435 return if ! length ($output);
436
437 print STDERR "Writing $output_file\n" if $verbosity;
438
439 open (ACLOCAL, "> " . $output_file)
440 || die "aclocal: couldn't open \`$output_file' for writing: $!\n";
441 print ACLOCAL "dnl $output_file generated automatically by aclocal $VERSION\n";
442 print ACLOCAL "\
443dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
444dnl This file is free software; the Free Software Foundation
445dnl gives unlimited permission to copy and/or distribute it,
446dnl with or without modifications, as long as this notice is preserved.
447
448dnl This program is distributed in the hope that it will be useful,
449dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
450dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
451dnl PARTICULAR PURPOSE.
452
453";
454 print ACLOCAL $output;
455 close (ACLOCAL);
456}
Note: See TracBrowser for help on using the repository browser.