| 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, 2003, 2004, 2005
|
|---|
| 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., 51 Franklin Street, Fifth Floor, Boston, MA
|
|---|
| 26 | # 02110-1301, USA.
|
|---|
| 27 |
|
|---|
| 28 | # Written by Tom Tromey <tromey@redhat.com>.
|
|---|
| 29 |
|
|---|
| 30 | BEGIN
|
|---|
| 31 | {
|
|---|
| 32 | my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
|
|---|
| 33 | unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | use Automake::Config;
|
|---|
| 37 | use Automake::General;
|
|---|
| 38 | use Automake::Configure_ac;
|
|---|
| 39 | use Automake::Channels;
|
|---|
| 40 | use Automake::XFile;
|
|---|
| 41 | use Automake::FileUtils;
|
|---|
| 42 | use File::Basename;
|
|---|
| 43 | use File::stat;
|
|---|
| 44 | use Cwd;
|
|---|
| 45 |
|
|---|
| 46 | # Note that this isn't pkgdatadir, but a separate directory.
|
|---|
| 47 | # Note also that the versioned directory is handled later.
|
|---|
| 48 | $acdir = '@datadir@/aclocal';
|
|---|
| 49 | $default_acdir = $acdir;
|
|---|
| 50 | # contains a list of directories, one per line, to be added
|
|---|
| 51 | # to the dirlist in addition to $acdir, as if -I had been
|
|---|
| 52 | # added to the command line. If acdir has been redirected,
|
|---|
| 53 | # we will also check the specified acdir (this is done later).
|
|---|
| 54 | $default_dirlist = "$default_acdir/dirlist";
|
|---|
| 55 |
|
|---|
| 56 | # Some globals.
|
|---|
| 57 |
|
|---|
| 58 | # configure.ac or configure.in.
|
|---|
| 59 | my $configure_ac;
|
|---|
| 60 |
|
|---|
| 61 | # Output file name.
|
|---|
| 62 | $output_file = 'aclocal.m4';
|
|---|
| 63 |
|
|---|
| 64 | # Modification time of the youngest dependency.
|
|---|
| 65 | $greatest_mtime = 0;
|
|---|
| 66 |
|
|---|
| 67 | # Option --force.
|
|---|
| 68 | $force_output = 0;
|
|---|
| 69 |
|
|---|
| 70 | # Which macros have been seen.
|
|---|
| 71 | %macro_seen = ();
|
|---|
| 72 |
|
|---|
| 73 | # Which files have been seen.
|
|---|
| 74 | %file_seen = ();
|
|---|
| 75 |
|
|---|
| 76 | # Remember the order into which we scanned the files.
|
|---|
| 77 | # It's important to output the contents of aclocal.m4 in the opposite order.
|
|---|
| 78 | # (Definitions in first files we have scanned should override those from
|
|---|
| 79 | # later files. So they must appear last in the output.)
|
|---|
| 80 | @file_order = ();
|
|---|
| 81 |
|
|---|
| 82 | # Map macro names to file names.
|
|---|
| 83 | %map = ();
|
|---|
| 84 |
|
|---|
| 85 | # Ditto, but records the last definition of each macro as returned by --trace.
|
|---|
| 86 | %map_traced_defs = ();
|
|---|
| 87 |
|
|---|
| 88 | # Map file names to file contents.
|
|---|
| 89 | %file_contents = ();
|
|---|
| 90 |
|
|---|
| 91 | # Map file names to included files (transitively closed).
|
|---|
| 92 | %file_includes = ();
|
|---|
| 93 |
|
|---|
| 94 | # How much to say.
|
|---|
| 95 | $verbose = 0;
|
|---|
| 96 |
|
|---|
| 97 | # Matches a macro definition.
|
|---|
| 98 | # AC_DEFUN([macroname], ...)
|
|---|
| 99 | # or
|
|---|
| 100 | # AC_DEFUN(macroname, ...)
|
|---|
| 101 | # When macroname is `['-quoted , we accept any character in the name,
|
|---|
| 102 | # except `]'. Otherwise macroname stops on the first `]', `,', `)',
|
|---|
| 103 | # or `\n' encountered.
|
|---|
| 104 | $ac_defun_rx =
|
|---|
| 105 | "(?:AU_ALIAS|A[CU]_DEFUN|AC_DEFUN_ONCE)\\((?:\\[([^]]+)\\]|([^],)\n]+))";
|
|---|
| 106 |
|
|---|
| 107 | # Matches an AC_REQUIRE line.
|
|---|
| 108 | $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
|
|---|
| 109 |
|
|---|
| 110 | # Matches an m4_include line
|
|---|
| 111 | $m4_include_rx = "(?:m4_)?(s?)include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
|
|---|
| 112 |
|
|---|
| 113 | |
|---|
| 114 |
|
|---|
| 115 | ################################################################
|
|---|
| 116 |
|
|---|
| 117 | # Check macros in acinclude.m4. If one is not used, warn.
|
|---|
| 118 | sub check_acinclude ()
|
|---|
| 119 | {
|
|---|
| 120 | foreach my $key (keys %map)
|
|---|
| 121 | {
|
|---|
| 122 | # FIXME: should print line number of acinclude.m4.
|
|---|
| 123 | warn ("aclocal: warning: macro `$key' defined in "
|
|---|
| 124 | . "acinclude.m4 but never used\n")
|
|---|
| 125 | if $map{$key} eq 'acinclude.m4' && ! $macro_seen{$key};
|
|---|
| 126 | }
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | ################################################################
|
|---|
| 130 |
|
|---|
| 131 | # Scan all the installed m4 files and construct a map.
|
|---|
| 132 | sub scan_m4_files (@)
|
|---|
| 133 | {
|
|---|
| 134 | local (@dirlist) = @_;
|
|---|
| 135 |
|
|---|
| 136 | # First, scan configure.ac. It may contain macro definitions,
|
|---|
| 137 | # or may include other files that define macros.
|
|---|
| 138 | &scan_file ($configure_ac, 'aclocal');
|
|---|
| 139 |
|
|---|
| 140 | # Then, scan acinclude.m4 if it exists.
|
|---|
| 141 | if (-f 'acinclude.m4')
|
|---|
| 142 | {
|
|---|
| 143 | &scan_file ('acinclude.m4', 'aclocal');
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | # Finally, scan all files in our search path.
|
|---|
| 147 | local ($m4dir);
|
|---|
| 148 | foreach $m4dir (@dirlist)
|
|---|
| 149 | {
|
|---|
| 150 | if (! opendir (DIR, $m4dir))
|
|---|
| 151 | {
|
|---|
| 152 | print STDERR "aclocal: couldn't open directory `$m4dir': $!\n";
|
|---|
| 153 | exit 1;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | local ($file, $fullfile);
|
|---|
| 157 | # We reverse the directory contents so that foo2.m4 gets
|
|---|
| 158 | # used in preference to foo1.m4.
|
|---|
| 159 | foreach $file (reverse sort grep (! /^\./, readdir (DIR)))
|
|---|
| 160 | {
|
|---|
| 161 | # Only examine .m4 files.
|
|---|
| 162 | next unless $file =~ /\.m4$/;
|
|---|
| 163 |
|
|---|
| 164 | # Skip some files when running out of srcdir.
|
|---|
| 165 | next if $file eq 'aclocal.m4';
|
|---|
| 166 |
|
|---|
| 167 | $fullfile = File::Spec->canonpath ("$m4dir/$file");
|
|---|
| 168 | &scan_file ($fullfile, 'aclocal');
|
|---|
| 169 | }
|
|---|
| 170 | closedir (DIR);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | # Construct a new function that does the searching. We use a
|
|---|
| 174 | # function (instead of just evaluating $search in the loop) so that
|
|---|
| 175 | # "die" is correctly and easily propagated if run.
|
|---|
| 176 | my $search = "sub search {\nmy \$found = 0;\n";
|
|---|
| 177 | foreach my $key (reverse sort keys %map)
|
|---|
| 178 | {
|
|---|
| 179 | $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
|
|---|
| 180 | . '"); $found = 1; }' . "\n");
|
|---|
| 181 | }
|
|---|
| 182 | $search .= "return \$found;\n};\n";
|
|---|
| 183 | eval $search;
|
|---|
| 184 | die "internal error: $@\n search is $search" if $@;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | ################################################################
|
|---|
| 188 |
|
|---|
| 189 | # Add a macro to the output.
|
|---|
| 190 | sub add_macro ($)
|
|---|
| 191 | {
|
|---|
| 192 | local ($macro) = @_;
|
|---|
| 193 |
|
|---|
| 194 | # Ignore unknown required macros. Either they are not really
|
|---|
| 195 | # needed (e.g., a conditional AC_REQUIRE), in which case aclocal
|
|---|
| 196 | # should be quiet, or they are needed and Autoconf itself will
|
|---|
| 197 | # complain when we trace for macro usage later.
|
|---|
| 198 | return unless defined $map{$macro};
|
|---|
| 199 |
|
|---|
| 200 | print STDERR "aclocal: saw macro $macro\n" if $verbose;
|
|---|
| 201 | $macro_seen{$macro} = 1;
|
|---|
| 202 | &add_file ($map{$macro});
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | # scan_configure_dep ($file)
|
|---|
| 206 | # --------------------------
|
|---|
| 207 | # Scan a configure dependency (configure.ac, or separate m4 files)
|
|---|
| 208 | # for uses of known macros and AC_REQUIREs of possibly unknown macros.
|
|---|
| 209 | # Recursively scan m4_included files.
|
|---|
| 210 | my %scanned_configure_dep = ();
|
|---|
| 211 | sub scan_configure_dep ($)
|
|---|
| 212 | {
|
|---|
| 213 | my ($file) = @_;
|
|---|
| 214 | # Do not scan a file twice.
|
|---|
| 215 | return ()
|
|---|
| 216 | if exists $scanned_configure_dep{$file};
|
|---|
| 217 | $scanned_configure_dep{$file} = 1;
|
|---|
| 218 |
|
|---|
| 219 | my $mtime = mtime $file;
|
|---|
| 220 | $greatest_mtime = $mtime if $greatest_mtime < $mtime;
|
|---|
| 221 |
|
|---|
| 222 | my $contents = exists $file_contents{$file} ?
|
|---|
| 223 | $file_contents{$file} : contents $file;
|
|---|
| 224 |
|
|---|
| 225 | my $line = 0;
|
|---|
| 226 | my @rlist = ();
|
|---|
| 227 | my @ilist = ();
|
|---|
| 228 | foreach (split ("\n", $contents))
|
|---|
| 229 | {
|
|---|
| 230 | ++$line;
|
|---|
| 231 | # Remove comments from current line.
|
|---|
| 232 | s/\bdnl\b.*$//;
|
|---|
| 233 | s/\#.*$//;
|
|---|
| 234 |
|
|---|
| 235 | while (/$m4_include_rx/go)
|
|---|
| 236 | {
|
|---|
| 237 | my $ifile = $2 || $3;
|
|---|
| 238 | # Skip missing `sinclude'd files.
|
|---|
| 239 | next if $1 eq 's' && ! -f $ifile;
|
|---|
| 240 | push @ilist, $ifile;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | while (/$ac_require_rx/go)
|
|---|
| 244 | {
|
|---|
| 245 | push (@rlist, $1 || $2);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | # The search function is constructed dynamically by
|
|---|
| 249 | # scan_m4_files. The last parenthetical match makes sure we
|
|---|
| 250 | # don't match things that look like macro assignments or
|
|---|
| 251 | # AC_SUBSTs.
|
|---|
| 252 | if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
|
|---|
| 253 | {
|
|---|
| 254 | # Macro not found, but AM_ prefix found.
|
|---|
| 255 | # Make this just a warning, because we do not know whether
|
|---|
| 256 | # the macro is actually used (it could be called conditionally).
|
|---|
| 257 | warn ("aclocal:$file:$line: warning: "
|
|---|
| 258 | . "macro `$2' not found in library\n");
|
|---|
| 259 | }
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | add_macro ($_) foreach (@rlist);
|
|---|
| 263 | &scan_configure_dep ($_) foreach (@ilist);
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | # Add a file to output.
|
|---|
| 267 | sub add_file ($)
|
|---|
| 268 | {
|
|---|
| 269 | local ($file) = @_;
|
|---|
| 270 |
|
|---|
| 271 | # Only add a file once.
|
|---|
| 272 | return if ($file_seen{$file});
|
|---|
| 273 | $file_seen{$file} = 1;
|
|---|
| 274 |
|
|---|
| 275 | scan_configure_dep $file;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | # Point to the documentation for underquoted AC_DEFUN only once.
|
|---|
| 279 | my $underquoted_manual_once = 0;
|
|---|
| 280 |
|
|---|
| 281 | # scan_file ($FILE, $WHERE)
|
|---|
| 282 | # -------------------------
|
|---|
| 283 | # Scan a single M4 file ($FILE), and all files it includes.
|
|---|
| 284 | # Return the list of included files.
|
|---|
| 285 | # $WHERE is the location to use in the diagnostic if the file
|
|---|
| 286 | # does not exist.
|
|---|
| 287 | sub scan_file ($$)
|
|---|
| 288 | {
|
|---|
| 289 | my ($file, $where) = @_;
|
|---|
| 290 |
|
|---|
| 291 | # Do not scan the same file twice.
|
|---|
| 292 | return @$file_includes{$file} if exists $file_includes{$file};
|
|---|
| 293 | # Prevent potential infinite recursion (if two files include each other).
|
|---|
| 294 | return () if exists $file_contents{$file};
|
|---|
| 295 |
|
|---|
| 296 | unshift @file_order, $file;
|
|---|
| 297 |
|
|---|
| 298 | if (! -e $file)
|
|---|
| 299 | {
|
|---|
| 300 | print STDERR "$where: file `$file' does not exist\n";
|
|---|
| 301 | exit 1;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | my $fh = new Automake::XFile $file;
|
|---|
| 305 | my $contents = '';
|
|---|
| 306 | my @inc_files = ();
|
|---|
| 307 | my %inc_lines = ();
|
|---|
| 308 | while ($_ = $fh->getline)
|
|---|
| 309 | {
|
|---|
| 310 | # Ignore `##' lines.
|
|---|
| 311 | next if /^##/;
|
|---|
| 312 |
|
|---|
| 313 | $contents .= $_;
|
|---|
| 314 |
|
|---|
| 315 | while (/$ac_defun_rx/go)
|
|---|
| 316 | {
|
|---|
| 317 | if (! defined $1)
|
|---|
| 318 | {
|
|---|
| 319 | print STDERR "$file:$.: warning: underquoted definition of $2\n";
|
|---|
| 320 | print STDERR " run info '(automake)Extending aclocal'\n"
|
|---|
| 321 | . " or see http://sources.redhat.com/automake/"
|
|---|
| 322 | . "automake.html#Extending-aclocal\n"
|
|---|
| 323 | unless $underquoted_manual_once;
|
|---|
| 324 | $underquoted_manual_once = 1;
|
|---|
| 325 | }
|
|---|
| 326 | my $macro = $1 || $2;
|
|---|
| 327 | if (! defined $map{$macro})
|
|---|
| 328 | {
|
|---|
| 329 | print STDERR "aclocal: found macro $macro in $file: $.\n"
|
|---|
| 330 | if $verbose;
|
|---|
| 331 | $map{$macro} = $file;
|
|---|
| 332 | }
|
|---|
| 333 | else
|
|---|
| 334 | {
|
|---|
| 335 | # Note: we used to give an error here if we saw a
|
|---|
| 336 | # duplicated macro. However, this turns out to be
|
|---|
| 337 | # extremely unpopular. It causes actual problems which
|
|---|
| 338 | # are hard to work around, especially when you must
|
|---|
| 339 | # mix-and-match tool versions.
|
|---|
| 340 | print STDERR "aclocal: ignoring macro $macro in $file: $.\n"
|
|---|
| 341 | if $verbose;
|
|---|
| 342 | }
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | while (/$m4_include_rx/go)
|
|---|
| 346 | {
|
|---|
| 347 | my $ifile = $2 || $3;
|
|---|
| 348 | # Skip missing `sinclude'd files.
|
|---|
| 349 | next if $1 eq 's' && ! -f $ifile;
|
|---|
| 350 | push (@inc_files, $ifile);
|
|---|
| 351 | $inc_lines{$ifile} = $.;
|
|---|
| 352 | }
|
|---|
| 353 | }
|
|---|
| 354 | $file_contents{$file} = $contents;
|
|---|
| 355 |
|
|---|
| 356 | # For some reason I don't understand, it does not work
|
|---|
| 357 | # to do `map { scan_file ($_, ...) } @inc_files' below.
|
|---|
| 358 | # With Perl 5.8.2 it undefines @inc_files.
|
|---|
| 359 | my @copy = @inc_files;
|
|---|
| 360 | my @all_inc_files = (@inc_files,
|
|---|
| 361 | map { scan_file ($_, "$file:$inc_lines{$_}") } @copy);
|
|---|
| 362 | $file_includes{$file} = \@all_inc_files;
|
|---|
| 363 | return @all_inc_files;
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | # strip_redundant_includes (%FILES)
|
|---|
| 367 | # ---------------------------------
|
|---|
| 368 | # Each key in %FILES is a file that must be present in the output.
|
|---|
| 369 | # However some of these files might already include other files in %FILES,
|
|---|
| 370 | # so there is no point in including them another time.
|
|---|
| 371 | # This removes items of %FILES which are already included by another file.
|
|---|
| 372 | sub strip_redundant_includes (%)
|
|---|
| 373 | {
|
|---|
| 374 | my %files = @_;
|
|---|
| 375 |
|
|---|
| 376 | # Always include acinclude.m4, even if it does not appear to be used.
|
|---|
| 377 | $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
|
|---|
| 378 | # File included by $configure_ac are redundant.
|
|---|
| 379 | $files{$configure_ac} = 1;
|
|---|
| 380 |
|
|---|
| 381 | # Files at the end of @file_order should override those at the beginning,
|
|---|
| 382 | # so it is important to preserve these trailing files. We can remove
|
|---|
| 383 | # a file A if it is going to be output before a file B that includes
|
|---|
| 384 | # file A, not the converse.
|
|---|
| 385 | foreach my $file (reverse @file_order)
|
|---|
| 386 | {
|
|---|
| 387 | next unless exists $files{$file};
|
|---|
| 388 | foreach my $ifile (@{$file_includes{$file}})
|
|---|
| 389 | {
|
|---|
| 390 | next unless exists $files{$ifile};
|
|---|
| 391 | delete $files{$ifile};
|
|---|
| 392 | print STDERR "$ifile is already included by $file\n"
|
|---|
| 393 | if $verbose;
|
|---|
| 394 | }
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | # configure.ac is implicitly included.
|
|---|
| 398 | delete $files{$configure_ac};
|
|---|
| 399 |
|
|---|
| 400 | return %files;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | sub trace_used_macros ()
|
|---|
| 404 | {
|
|---|
| 405 | my %files = map { $map{$_} => 1 } keys %macro_seen;
|
|---|
| 406 | %files = strip_redundant_includes %files;
|
|---|
| 407 |
|
|---|
| 408 | my $traces = ($ENV{AUTOM4TE} || 'autom4te');
|
|---|
| 409 | $traces .= " --language Autoconf-without-aclocal-m4 ";
|
|---|
| 410 | # All candidate files.
|
|---|
| 411 | $traces .= join (' ', grep { exists $files{$_} } @file_order) . " ";
|
|---|
| 412 | # All candidate macros.
|
|---|
| 413 | $traces .= join (' ', map { "--trace='$_:\$f:\$n:\$1'" } ('AC_DEFUN',
|
|---|
| 414 | 'AC_DEFUN_ONCE',
|
|---|
| 415 | 'AU_DEFUN',
|
|---|
| 416 | keys %macro_seen));
|
|---|
| 417 |
|
|---|
| 418 | print STDERR "aclocal: running $traces $configure_ac\n" if $verbose;
|
|---|
| 419 |
|
|---|
| 420 | my $tracefh = new Automake::XFile ("$traces $configure_ac |");
|
|---|
| 421 |
|
|---|
| 422 | my %traced = ();
|
|---|
| 423 |
|
|---|
| 424 | while ($_ = $tracefh->getline)
|
|---|
| 425 | {
|
|---|
| 426 | chomp;
|
|---|
| 427 | my ($file, $macro, $arg1) = split (/:/);
|
|---|
| 428 |
|
|---|
| 429 | $traced{$macro} = 1 if $macro_seen{$macro};
|
|---|
| 430 |
|
|---|
| 431 | $map_traced_defs{$arg1} = $file
|
|---|
| 432 | if ($macro eq 'AC_DEFUN'
|
|---|
| 433 | || $macro eq 'AC_DEFUN_ONCE'
|
|---|
| 434 | || $macro eq 'AU_DEFUN');
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | $tracefh->close;
|
|---|
| 438 |
|
|---|
| 439 | return %traced;
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | sub scan_configure ()
|
|---|
| 443 | {
|
|---|
| 444 | # Make sure we include acinclude.m4 if it exists.
|
|---|
| 445 | if (-f 'acinclude.m4')
|
|---|
| 446 | {
|
|---|
| 447 | add_file ('acinclude.m4');
|
|---|
| 448 | }
|
|---|
| 449 | scan_configure_dep ($configure_ac);
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | ################################################################
|
|---|
| 453 |
|
|---|
| 454 | # Write output.
|
|---|
| 455 | sub write_aclocal ($@)
|
|---|
| 456 | {
|
|---|
| 457 | my ($output_file, @macros) = @_;
|
|---|
| 458 | my $output = '';
|
|---|
| 459 |
|
|---|
| 460 | my %files = ();
|
|---|
| 461 | # Get the list of files containing definitions for the macros used.
|
|---|
| 462 | # (Filter out unused macro definitions with $map_traced_defs. This
|
|---|
| 463 | # can happen when an Autoconf macro is conditionally defined:
|
|---|
| 464 | # aclocal sees the potential definition, but this definition is
|
|---|
| 465 | # actually never processed and the Autoconf implementation is used
|
|---|
| 466 | # instead.)
|
|---|
| 467 | for my $m (@macros)
|
|---|
| 468 | {
|
|---|
| 469 | $files{$map{$m}} = 1 if $map{$m} eq $map_traced_defs{$m};
|
|---|
| 470 | }
|
|---|
| 471 | %files = strip_redundant_includes %files;
|
|---|
| 472 |
|
|---|
| 473 | for $file (grep { exists $files{$_} } @file_order)
|
|---|
| 474 | {
|
|---|
| 475 | # Check the time stamp of this file, and all files it includes.
|
|---|
| 476 | for my $ifile ($file, @{$file_includes{$file}})
|
|---|
| 477 | {
|
|---|
| 478 | my $mtime = mtime $ifile;
|
|---|
| 479 | $greatest_mtime = $mtime if $greatest_mtime < $mtime;
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | # If the file to add looks like outside the project, copy it
|
|---|
| 483 | # to the output. The regex catches filenames starting with
|
|---|
| 484 | # things like `/', `\', or `c:\'.
|
|---|
| 485 | if ($file =~ m,^(?:\w:)?[\\/],)
|
|---|
| 486 | {
|
|---|
| 487 | $output .= $file_contents{$file} . "\n";
|
|---|
| 488 | }
|
|---|
| 489 | else
|
|---|
| 490 | {
|
|---|
| 491 | # Otherwise, simply include the file.
|
|---|
| 492 | $output .= "m4_include([$file])\n";
|
|---|
| 493 | }
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | # Nothing to output?!
|
|---|
| 497 | # FIXME: Shouldn't we diagnose this?
|
|---|
| 498 | return if ! length ($output);
|
|---|
| 499 |
|
|---|
| 500 | # We used to print `# $output_file generated automatically etc.' But
|
|---|
| 501 | # this creates spurious differences when using autoreconf. Autoreconf
|
|---|
| 502 | # creates aclocal.m4t and then rename it to aclocal.m4, but the
|
|---|
| 503 | # rebuild rules generated by Automake create aclocal.m4 directly --
|
|---|
| 504 | # this would gives two ways to get the same file, with a different
|
|---|
| 505 | # name in the header.
|
|---|
| 506 | $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
|
|---|
| 507 |
|
|---|
| 508 | # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|---|
| 509 | # 2005 Free Software Foundation, Inc.
|
|---|
| 510 | # This file is free software; the Free Software Foundation
|
|---|
| 511 | # gives unlimited permission to copy and/or distribute it,
|
|---|
| 512 | # with or without modifications, as long as this notice is preserved.
|
|---|
| 513 |
|
|---|
| 514 | # This program is distributed in the hope that it will be useful,
|
|---|
| 515 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
|---|
| 516 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|---|
| 517 | # PARTICULAR PURPOSE.
|
|---|
| 518 |
|
|---|
| 519 | $output";
|
|---|
| 520 |
|
|---|
| 521 | # We try not to update $output_file unless necessary, because
|
|---|
| 522 | # doing so invalidate Autom4te's cache and therefore slows down
|
|---|
| 523 | # tools called after aclocal.
|
|---|
| 524 | #
|
|---|
| 525 | # We need to overwrite $output_file in the following situations.
|
|---|
| 526 | # * The --force option is in use.
|
|---|
| 527 | # * One of the dependencies is younger.
|
|---|
| 528 | # (Not updating $output_file in this situation would cause
|
|---|
| 529 | # make to call aclocal in loop.)
|
|---|
| 530 | # * The contents of the current file are different from what
|
|---|
| 531 | # we have computed.
|
|---|
| 532 | if (!$force_output
|
|---|
| 533 | && $greatest_mtime < mtime ($output_file)
|
|---|
| 534 | && $output eq contents ($output_file))
|
|---|
| 535 | {
|
|---|
| 536 | print STDERR "aclocal: $output_file unchanged\n" if $verbose;
|
|---|
| 537 | return;
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | print STDERR "aclocal: writing $output_file\n" if $verbose;
|
|---|
| 541 |
|
|---|
| 542 | my $out = new Automake::XFile "> $output_file";
|
|---|
| 543 | print $out $output;
|
|---|
| 544 | return;
|
|---|
| 545 | }
|
|---|
| 546 |
|
|---|
| 547 | ################################################################
|
|---|
| 548 |
|
|---|
| 549 | # Print usage and exit.
|
|---|
| 550 | sub usage ($)
|
|---|
| 551 | {
|
|---|
| 552 | local ($status) = @_;
|
|---|
| 553 |
|
|---|
| 554 | print "Usage: aclocal [OPTIONS] ...\n\n";
|
|---|
| 555 | print "\
|
|---|
| 556 | Generate `aclocal.m4' by scanning `configure.ac' or `configure.in'
|
|---|
| 557 |
|
|---|
| 558 | --acdir=DIR directory holding config files
|
|---|
| 559 | --help print this help, then exit
|
|---|
| 560 | -I DIR add directory to search list for .m4 files
|
|---|
| 561 | --force always update output file
|
|---|
| 562 | --output=FILE put output in FILE (default aclocal.m4)
|
|---|
| 563 | --print-ac-dir print name of directory holding m4 files
|
|---|
| 564 | --verbose don't be silent
|
|---|
| 565 | --version print version number, then exit
|
|---|
| 566 |
|
|---|
| 567 | Report bugs to <bug-automake\@gnu.org>.\n";
|
|---|
| 568 |
|
|---|
| 569 | exit $status;
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | # Parse command line.
|
|---|
| 573 | sub parse_arguments (@)
|
|---|
| 574 | {
|
|---|
| 575 | local (@arglist) = @_;
|
|---|
| 576 | local (@dirlist);
|
|---|
| 577 | local ($print_and_exit) = 0;
|
|---|
| 578 |
|
|---|
| 579 | while (@arglist)
|
|---|
| 580 | {
|
|---|
| 581 | if ($arglist[0] =~ /^--acdir=(.+)$/)
|
|---|
| 582 | {
|
|---|
| 583 | $acdir = $1;
|
|---|
| 584 | }
|
|---|
| 585 | elsif ($arglist[0] =~/^--output=(.+)$/)
|
|---|
| 586 | {
|
|---|
| 587 | $output_file = $1;
|
|---|
| 588 | }
|
|---|
| 589 | elsif ($arglist[0] eq '-I')
|
|---|
| 590 | {
|
|---|
| 591 | shift (@arglist);
|
|---|
| 592 | push (@dirlist, $arglist[0]);
|
|---|
| 593 | }
|
|---|
| 594 | elsif ($arglist[0] eq '--print-ac-dir')
|
|---|
| 595 | {
|
|---|
| 596 | $print_and_exit = 1;
|
|---|
| 597 | }
|
|---|
| 598 | elsif ($arglist[0] eq '--force')
|
|---|
| 599 | {
|
|---|
| 600 | $force_output = 1;
|
|---|
| 601 | }
|
|---|
| 602 | elsif ($arglist[0] eq '--verbose')
|
|---|
| 603 | {
|
|---|
| 604 | ++$verbose;
|
|---|
| 605 | }
|
|---|
| 606 | elsif ($arglist[0] eq '--version')
|
|---|
| 607 | {
|
|---|
| 608 | print "aclocal (GNU $PACKAGE) $VERSION\n";
|
|---|
| 609 | print "Written by Tom Tromey <tromey\@redhat.com>\n\n";
|
|---|
| 610 | print "Copyright (C) 2005 Free Software Foundation, Inc.\n";
|
|---|
| 611 | print "This is free software; see the source for copying conditions. There is NO\n";
|
|---|
| 612 | print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
|
|---|
| 613 | exit 0;
|
|---|
| 614 | }
|
|---|
| 615 | elsif ($arglist[0] eq '--help')
|
|---|
| 616 | {
|
|---|
| 617 | &usage (0);
|
|---|
| 618 | }
|
|---|
| 619 | else
|
|---|
| 620 | {
|
|---|
| 621 | print STDERR "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n";
|
|---|
| 622 | exit 1;
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 | shift (@arglist);
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | if ($print_and_exit)
|
|---|
| 629 | {
|
|---|
| 630 | print $acdir, "\n";
|
|---|
| 631 | exit 0;
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | $default_dirlist="$acdir/dirlist"
|
|---|
| 635 | if $acdir ne $default_acdir;
|
|---|
| 636 |
|
|---|
| 637 | # Search the versioned directory near the end, and then the
|
|---|
| 638 | # unversioned directory last. Only do this if the user didn't
|
|---|
| 639 | # override acdir.
|
|---|
| 640 | push (@dirlist, "$acdir-$APIVERSION")
|
|---|
| 641 | if $acdir eq $default_acdir;
|
|---|
| 642 |
|
|---|
| 643 | # By default $(datadir)/aclocal doesn't exist. We don't want to
|
|---|
| 644 | # get an error in the case where we are searching the default
|
|---|
| 645 | # directory and it hasn't been created.
|
|---|
| 646 | push (@dirlist, $acdir)
|
|---|
| 647 | unless $acdir eq $default_acdir && ! -d $acdir;
|
|---|
| 648 |
|
|---|
| 649 | # Finally, adds any directory listed in the `dirlist' file.
|
|---|
| 650 | if (open (DEFAULT_DIRLIST, $default_dirlist))
|
|---|
| 651 | {
|
|---|
| 652 | while (<DEFAULT_DIRLIST>)
|
|---|
| 653 | {
|
|---|
| 654 | # Ignore '#' lines.
|
|---|
| 655 | next if /^#/;
|
|---|
| 656 | # strip off newlines and end-of-line comments
|
|---|
| 657 | s/\s*\#.*$//;
|
|---|
| 658 | chomp ($contents=$_);
|
|---|
| 659 | if (-d $contents )
|
|---|
| 660 | {
|
|---|
| 661 | push (@dirlist, $contents);
|
|---|
| 662 | }
|
|---|
| 663 | }
|
|---|
| 664 | close (DEFAULT_DIRLIST);
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | return @dirlist;
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 | ################################################################
|
|---|
| 671 |
|
|---|
| 672 | local (@dirlist) = parse_arguments (@ARGV);
|
|---|
| 673 | $configure_ac = require_configure_ac;
|
|---|
| 674 | scan_m4_files (@dirlist);
|
|---|
| 675 | scan_configure;
|
|---|
| 676 | if (! $exit_code)
|
|---|
| 677 | {
|
|---|
| 678 | my %macro_traced = trace_used_macros;
|
|---|
| 679 | write_aclocal ($output_file, keys %macro_traced);
|
|---|
| 680 | }
|
|---|
| 681 | check_acinclude;
|
|---|
| 682 |
|
|---|
| 683 | exit $exit_code;
|
|---|
| 684 |
|
|---|
| 685 | ### Setup "GNU" style for perl-mode and cperl-mode.
|
|---|
| 686 | ## Local Variables:
|
|---|
| 687 | ## perl-indent-level: 2
|
|---|
| 688 | ## perl-continued-statement-offset: 2
|
|---|
| 689 | ## perl-continued-brace-offset: 0
|
|---|
| 690 | ## perl-brace-offset: 0
|
|---|
| 691 | ## perl-brace-imaginary-offset: 0
|
|---|
| 692 | ## perl-label-offset: -2
|
|---|
| 693 | ## cperl-indent-level: 2
|
|---|
| 694 | ## cperl-brace-offset: 0
|
|---|
| 695 | ## cperl-continued-brace-offset: 0
|
|---|
| 696 | ## cperl-label-offset: -2
|
|---|
| 697 | ## cperl-extra-newline-before-brace: t
|
|---|
| 698 | ## cperl-merge-trailing-else: nil
|
|---|
| 699 | ## cperl-continued-statement-offset: 2
|
|---|
| 700 | ## End:
|
|---|