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