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