Removed old macro
[platform/upstream/automake.git] / aclocal.in
1 #!@PERL@
2 # -*- perl -*-
3 # @configure_input@
4
5 # aclocal - create aclocal.m4 by scanning configure.in
6 # Copyright (C) 1996 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@cygnus.com>.
24
25 eval 'exec @PERL@ -S $0 ${1+"$@"}'
26     if 0;
27
28 # aclocal - scan configure.in and generate aclocal.m4.
29
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";
36
37 # Some globals.
38
39 # Exit status.
40 $exit_status = 0;
41
42 # Text to output.
43 $output = '';
44
45 # Output file name.
46 $output_file = 'aclocal.m4';
47
48 # Which macros have been seen.
49 %macro_seen = ();
50
51 # Which files have been seen.
52 %file_seen = ();
53
54 # Map macro names to file names.
55 %map = ();
56
57 # Map file names to file contents.
58 %file_contents = ();
59
60 # How much to say.
61 $verbosity = 0;
62
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
80      # Now part of autoconf proper, under a different name.
81      'AM_FUNC_FNMATCH',
82      'AM_SANITY_CHECK_CC',
83
84 # These aren't quite obsolete.
85 #      'md_PATH_PROG',
86 #      'ud_GNU_GETTEXT',
87 #      'ud_LC_MESSAGES',
88 #      'ud_WITH_NLS'
89      );
90
91 $obsolete_rx = '(' . join ('|', @obsolete_macros) . ')';
92
93 # Matches a macro definition.
94 $ac_defun_rx = "AC_DEFUN\\(\\[?([^],)\n]+)\\]?";
95
96 # Matches an AC_REQUIRE line.
97 $ac_require_rx = "AC_REQUIRE\\(\\[?([^])]*)\\]?\\)";
98
99 \f
100
101 &parse_arguments (@ARGV);
102 &scan_m4_files ($acdir);
103 &scan_configure;
104 if (! $exit_status)
105 {
106     &write_aclocal;
107 }
108 &check_acinclude;
109
110 exit $exit_status;
111
112 ################################################################
113
114 # Print usage and exit.
115 sub usage
116 {
117     local ($status) = @_;
118
119     print "Usage: aclocal [OPTIONS] ...\n";
120     print "\
121   --acdir=DIR           directory holding config files
122   --help                print this help, then exit
123   --output=FILE         put output in FILE (default aclocal.m4)
124   --verbose             don't be silent
125   --version             print version number, then exit
126
127 Report bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";
128
129     exit $status;
130 }
131
132 # Parse command line.
133 sub parse_arguments
134 {
135     local (@arglist) = @_;
136
137     while (@arglist)
138     {
139         if ($arglist[0] =~ /^--acdir=(.+)$/)
140         {
141             $acdir = $1;
142         }
143         elsif ($arglist[0] =~/^--output=(.+)$/)
144         {
145             $output_file = $1;
146         }
147         elsif ($arglist[0] eq '--verbose')
148         {
149             ++$verbosity;
150         }
151         elsif ($arglist[0] eq '--version')
152         {
153             print "aclocal (GNU $PACKAGE) $VERSION\n";
154             print "Copyright (C) 1996 Free Software Foundation, Inc.\n";
155             print "aclocal comes with ABSOLUTELY NO WARRANTY.\n";
156             print "You may redistribute copies of aclocal\n";
157             print "under the terms of the GNU General Public License.\n";
158             print "For more information about these matters, see the file named COPYING.\n";
159             exit 0;
160         }
161         elsif ($arglist[0] eq '--help')
162         {
163             &usage (0);
164         }
165         else
166         {
167             die "aclocal: unrecognized option -- \`$arglist[0]'\nTry \`aclocal --help' for more information.\n";
168         }
169
170         shift (@arglist);
171     }
172 }
173
174 ################################################################
175
176 sub scan_configure
177 {
178     open (CONFIGURE, "configure.in")
179         || die "aclocal: couldn't open \`configure.in': $!\n";
180
181     # Make sure we include acinclude.m4 if it exists.
182     if (-f 'acinclude.m4')
183     {
184         &add_file ('acinclude.m4');
185     }
186
187     while (<CONFIGURE>)
188     {
189         # Remove comments from current line.
190         s/\bdnl\b.*$//;
191         s/\#.*$//;
192
193         if (/$obsolete_rx/o)
194         {
195             chop;
196             warn "aclocal: configure.in: $.: obsolete macro \`$_'\n";
197             $exit_status = 1;
198             next;
199         }
200
201         # Search for things we know about.  The "search" sub is
202         # constructed dynamically, above.
203         &search;
204     }
205
206     close (CONFIGURE);
207 }
208
209 ################################################################
210
211 # Check macros in acinclude.m4.  If one is not used, warn.
212 sub check_acinclude
213 {
214     local ($key);
215
216     foreach $key (keys %map)
217     {
218         next unless $map{$key} eq 'acinclude.m4';
219         if (! $macro_seen{$key})
220         {
221             warn "aclocal: macro \`$key' defined in acinclude.m4 but never used\n";
222         }
223     }
224 }
225
226 ################################################################
227
228 # Scan all the installed m4 files and construct a map.
229 sub scan_m4_files
230 {
231     local ($m4dir) = @_;
232
233     # First, scan acinclude.m4 if it exists.
234     if (-f 'acinclude.m4')
235     {
236         $file_contents{'acinclude.m4'} = &scan_file ('acinclude.m4');
237     }
238
239     opendir (DIR, $m4dir)
240         || die "aclocal: couldn't open directory \`$m4dir': $!\n";
241     local ($file, $fullfile, $expr);
242     foreach $file (sort grep (! /^\./, readdir (DIR)))
243     {
244         # Only examine .m4 files.
245         next unless $file =~ /\.m4$/;
246
247         # Skip some files when running out of srcdir.
248         next if $file eq 'aclocal.m4';
249
250         $fullfile = $m4dir . '/' . $file;
251         $file_contents{$fullfile} = &scan_file ($fullfile);
252     }
253     closedir (DIR);
254
255     # Construct a new function that does the searching.  We use a
256     # function (instead of just evalling $search in the loop) so that
257     # "die" is correctly and easily propagated if run.
258     local ($search, $expr, $key);
259     foreach $key (keys %map)
260     {
261         # EXPR is a regexp matching the name of the macro.
262         ($expr = $key) =~ s/(\W)/\\$1/g;
263         $search .= "&add_macro ('" . $key . "') if /" . $expr . "/;\n";
264     }
265     eval 'sub search { ' . $search . '};';
266     die "internal error: $@\n search is $search " if $@;
267 }
268
269 ################################################################
270
271 # Add a macro to the output.
272 sub add_macro
273 {
274     local ($macro) = @_;
275
276     # Ignore AC_ macros.
277     return if $macro =~ /^AC_/;
278
279     if (! defined $map{$macro})
280     {
281         warn "aclocal: macro \`$macro' required but not defined\n";
282         $exit_status = 1;
283         return;
284     }
285
286     print STDERR "saw macro $macro\n" if $verbosity;
287     $macro_seen{$macro} = 1;
288     &add_file ($map{$macro});
289 }
290
291 # Add a file to output.
292 sub add_file
293 {
294     local ($file) = @_;
295
296     # Only add a file once.
297     return if ($file_seen{$file});
298     $file_seen{$file} = 1;
299
300     $output .= $file_contents{$file} . "\n";
301     local (@rlist);
302     foreach (split ("\n", $file_contents{$file}))
303     {
304         if (/$ac_require_rx/g)
305         {
306             push (@rlist, $1);
307         }
308
309         # This function constructed dynamically.
310         &search;
311     }
312
313     local ($macro);
314     foreach $macro (@rlist)
315     {
316         &add_macro ($macro);
317     }
318 }
319
320 # Scan a single M4 file.  Return contents.
321 sub scan_file
322 {
323     local ($file) = @_;
324
325     open (FILE, $file)
326         || die "aclocal: couldn't open \`$file': $!\n";
327     local ($contents) = '';
328     while (<FILE>)
329     {
330         # Ignore `##' lines.
331         next if /^##/;
332
333         $contents .= $_;
334
335         if (/$ac_defun_rx/)
336         {
337             if (defined $map{$1})
338             {
339                 warn "aclocal: $file: $.: duplicated macro \`$1'\n";
340                 $exit_status = 1;
341             }
342             print STDERR "Found macro $1 in $file\n" if $verbosity;
343             $map{$1} = $file;
344         }
345     }
346     close (FILE);
347
348     return $contents;
349 }
350
351 ################################################################
352
353 # Write output.
354 sub write_aclocal
355 {
356     return if ! length ($output);
357
358     print STDERR "Writing aclocal.m4\n" if $verbosity;
359
360     open (ACLOCAL, "> aclocal.m4")
361         || die "aclocal: couldn't open \`aclocal.m4' for writing: $!\n";
362     print ACLOCAL "dnl aclocal.m4 generated automatically by aclocal $VERSION\n\n";
363     print ACLOCAL $output;
364     close (ACLOCAL);
365 }