| 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 | 
|---|
| 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 | $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 | # Map file names to file contents. | 
|---|
| 90 | %file_contents = (); | 
|---|
| 91 |  | 
|---|
| 92 | # Map file names to included files (transitively closed). | 
|---|
| 93 | %file_includes = (); | 
|---|
| 94 |  | 
|---|
| 95 | # How much to say. | 
|---|
| 96 | $verbose = 0; | 
|---|
| 97 |  | 
|---|
| 98 | # Matches a macro definition. | 
|---|
| 99 | #   AC_DEFUN([macroname], ...) | 
|---|
| 100 | # or | 
|---|
| 101 | #   AC_DEFUN(macroname, ...) | 
|---|
| 102 | # When macroname is `['-quoted , we accept any character in the name, | 
|---|
| 103 | # except `]'.  Otherwise macroname stops on the first `]', `,', `)', | 
|---|
| 104 | # or `\n' encountered. | 
|---|
| 105 | $ac_defun_rx = "A[CU]_DEFUN\\((?:\\[([^]]+)\\]|([^],)\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); | 
|---|
| 139 |  | 
|---|
| 140 | # Then, scan acinclude.m4 if it exists. | 
|---|
| 141 | if (-f 'acinclude.m4') | 
|---|
| 142 | { | 
|---|
| 143 | &scan_file ('acinclude.m4'); | 
|---|
| 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 = $m4dir . '/' . $file; | 
|---|
| 168 | &scan_file ($fullfile); | 
|---|
| 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 | # We want to ignore AC_ macros.  However, if an AC_ macro is | 
|---|
| 195 | # defined in (eg) acinclude.m4, then we want to make sure we mark | 
|---|
| 196 | # it as seen. | 
|---|
| 197 | return if $macro =~ /^AC_/ && ! defined $map{$macro}; | 
|---|
| 198 |  | 
|---|
| 199 | if (! defined $map{$macro}) | 
|---|
| 200 | { | 
|---|
| 201 | warn "aclocal: macro `$macro' required but not defined\n"; | 
|---|
| 202 | $exit_code = 1; | 
|---|
| 203 | return; | 
|---|
| 204 | } | 
|---|
| 205 |  | 
|---|
| 206 | print STDERR "aclocal: saw macro $macro\n" if $verbose; | 
|---|
| 207 | $macro_seen{$macro} = 1; | 
|---|
| 208 | &add_file ($map{$macro}); | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | # rel2abs ($file, $directory) | 
|---|
| 212 | # --------------------------- | 
|---|
| 213 | # Similar to File::Spec->rel2abs ($file, $directory), but | 
|---|
| 214 | # work with Perl 5.005.  (File::Spec->rel2abs is available | 
|---|
| 215 | # only in Perl 5.6.) | 
|---|
| 216 | # Remove this once we require 5.6. | 
|---|
| 217 | sub rel2abs ($$) | 
|---|
| 218 | { | 
|---|
| 219 | my ($file, $dir) = @_; | 
|---|
| 220 | if (! File::Spec->file_name_is_absolute ($file)) | 
|---|
| 221 | { | 
|---|
| 222 | $dir = cwd () . "/$dir" | 
|---|
| 223 | unless File::Spec->file_name_is_absolute ($dir); | 
|---|
| 224 | $file = "$dir/$file"; | 
|---|
| 225 | } | 
|---|
| 226 | $file = File::Spec->canonpath ($file); | 
|---|
| 227 | return $file; | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | # scan_configure_dep ($file) | 
|---|
| 231 | # -------------------------- | 
|---|
| 232 | # Scan a configure dependency (configure.ac, or separate m4 files) | 
|---|
| 233 | # for uses of know macros and AC_REQUIREs of possibly unknown macros. | 
|---|
| 234 | # Recursively scan m4_included files. | 
|---|
| 235 | my %scanned_configure_dep = (); | 
|---|
| 236 | sub scan_configure_dep ($) | 
|---|
| 237 | { | 
|---|
| 238 | my ($file) = @_; | 
|---|
| 239 | # Do not scan a file twice. | 
|---|
| 240 | return () | 
|---|
| 241 | if exists $scanned_configure_dep{$file}; | 
|---|
| 242 | $scanned_configure_dep{$file} = 1; | 
|---|
| 243 |  | 
|---|
| 244 | my $mtime = mtime $file; | 
|---|
| 245 | $greatest_mtime = $mtime if $greatest_mtime < $mtime; | 
|---|
| 246 |  | 
|---|
| 247 | my $contents = exists $file_contents{$file} ? | 
|---|
| 248 | $file_contents{$file} : contents $file; | 
|---|
| 249 |  | 
|---|
| 250 | my $line = 0; | 
|---|
| 251 | my @rlist = (); | 
|---|
| 252 | my @ilist = (); | 
|---|
| 253 | foreach (split ("\n", $contents)) | 
|---|
| 254 | { | 
|---|
| 255 | ++$line; | 
|---|
| 256 | # Remove comments from current line. | 
|---|
| 257 | s/\bdnl\b.*$//; | 
|---|
| 258 | s/\#.*$//; | 
|---|
| 259 |  | 
|---|
| 260 | while (/$m4_include_rx/go) | 
|---|
| 261 | { | 
|---|
| 262 | push (@ilist, $1 || $2); | 
|---|
| 263 | } | 
|---|
| 264 |  | 
|---|
| 265 | while (/$ac_require_rx/go) | 
|---|
| 266 | { | 
|---|
| 267 | push (@rlist, $1 || $2); | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | # The search function is constructed dynamically by | 
|---|
| 271 | # scan_m4_files.  The last parenthetical match makes sure we | 
|---|
| 272 | # don't match things that look like macro assignments or | 
|---|
| 273 | # AC_SUBSTs. | 
|---|
| 274 | if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/) | 
|---|
| 275 | { | 
|---|
| 276 | # Macro not found, but AM_ prefix found. | 
|---|
| 277 | warn "aclocal: $file: $line: macro `$2' not found in library\n"; | 
|---|
| 278 | $exit_code = 1; | 
|---|
| 279 | } | 
|---|
| 280 | } | 
|---|
| 281 |  | 
|---|
| 282 | add_macro ($_) foreach (@rlist); | 
|---|
| 283 | my $dirname = dirname $file; | 
|---|
| 284 | &scan_configure_dep (rel2abs ($_, $dirname)) foreach (@ilist); | 
|---|
| 285 | } | 
|---|
| 286 |  | 
|---|
| 287 | # Add a file to output. | 
|---|
| 288 | sub add_file ($) | 
|---|
| 289 | { | 
|---|
| 290 | local ($file) = @_; | 
|---|
| 291 |  | 
|---|
| 292 | # Only add a file once. | 
|---|
| 293 | return if ($file_seen{$file}); | 
|---|
| 294 | $file_seen{$file} = 1; | 
|---|
| 295 |  | 
|---|
| 296 | scan_configure_dep $file; | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | # Point to the documentation for underquoted AC_DEFUN only once. | 
|---|
| 300 | my $underquoted_manual_once = 0; | 
|---|
| 301 |  | 
|---|
| 302 | # Scan a single M4 file, and all files it includes. | 
|---|
| 303 | # Return the list of included files. | 
|---|
| 304 | sub scan_file ($) | 
|---|
| 305 | { | 
|---|
| 306 | my ($file) = @_; | 
|---|
| 307 | my $base = dirname $file; | 
|---|
| 308 |  | 
|---|
| 309 | # Do not scan the same file twice. | 
|---|
| 310 | return @$file_includes{$file} if exists $file_includes{$file}; | 
|---|
| 311 | # Prevent potential infinite recursion (if two files include each other). | 
|---|
| 312 | return () if exists $file_contents{$file}; | 
|---|
| 313 |  | 
|---|
| 314 | unshift @file_order, $file; | 
|---|
| 315 |  | 
|---|
| 316 | my $fh = new Automake::XFile $file; | 
|---|
| 317 | my $contents = ''; | 
|---|
| 318 | my @inc_files = (); | 
|---|
| 319 | while ($_ = $fh->getline) | 
|---|
| 320 | { | 
|---|
| 321 | # Ignore `##' lines. | 
|---|
| 322 | next if /^##/; | 
|---|
| 323 |  | 
|---|
| 324 | $contents .= $_; | 
|---|
| 325 |  | 
|---|
| 326 | while (/$ac_defun_rx/go) | 
|---|
| 327 | { | 
|---|
| 328 | if (! defined $1) | 
|---|
| 329 | { | 
|---|
| 330 | print STDERR "$file:$.: warning: underquoted definition of $2\n"; | 
|---|
| 331 | print STDERR "  run info '(automake)Extending aclocal'\n" | 
|---|
| 332 | . "  or see http://sources.redhat.com/automake/" | 
|---|
| 333 | . "automake.html#Extending%20aclocal\n" | 
|---|
| 334 | unless $underquoted_manual_once; | 
|---|
| 335 | $underquoted_manual_once = 1; | 
|---|
| 336 | } | 
|---|
| 337 | my $macro = $1 || $2; | 
|---|
| 338 | if (! defined $map{$macro}) | 
|---|
| 339 | { | 
|---|
| 340 | print STDERR "aclocal: found macro $macro in $file: $.\n" | 
|---|
| 341 | if $verbose; | 
|---|
| 342 | $map{$macro} = $file; | 
|---|
| 343 | } | 
|---|
| 344 | else | 
|---|
| 345 | { | 
|---|
| 346 | # Note: we used to give an error here if we saw a | 
|---|
| 347 | # duplicated macro.  However, this turns out to be | 
|---|
| 348 | # extremely unpopular.  It causes actual problems which | 
|---|
| 349 | # are hard to work around, especially when you must | 
|---|
| 350 | # mix-and-match tool versions. | 
|---|
| 351 | print STDERR "aclocal: ignoring macro $macro in $file: $.\n" | 
|---|
| 352 | if $verbose; | 
|---|
| 353 | } | 
|---|
| 354 | } | 
|---|
| 355 |  | 
|---|
| 356 | while (/$m4_include_rx/go) | 
|---|
| 357 | { | 
|---|
| 358 | my $ifile = $1 || $2; | 
|---|
| 359 | # m4_include is relative to the directory of the file which | 
|---|
| 360 | # perform the include, but we want paths relative to the | 
|---|
| 361 | # directory where aclocal is run.  Do not use | 
|---|
| 362 | # File::Spec->rel2abs, because we want to store relative | 
|---|
| 363 | # paths (they might be used later of aclocal outputs an | 
|---|
| 364 | # m4_include for this file, or if the user itself includes | 
|---|
| 365 | # this file). | 
|---|
| 366 | $ifile = "$base/$ifile" | 
|---|
| 367 | unless $base eq '.' || File::Spec->file_name_is_absolute ($ifile); | 
|---|
| 368 | push (@inc_files, $ifile); | 
|---|
| 369 | } | 
|---|
| 370 | } | 
|---|
| 371 | $file_contents{$file} = $contents; | 
|---|
| 372 |  | 
|---|
| 373 | # For some reason I don't understand, it does not work | 
|---|
| 374 | # to do `map { scan_file ($_) } @inc_files' below. | 
|---|
| 375 | # With Perl 5.8.2 it undefines @inc_files. | 
|---|
| 376 | my @copy = @inc_files; | 
|---|
| 377 | my @all_inc_files = (@inc_files, map { scan_file ($_) } @copy); | 
|---|
| 378 | $file_includes{$file} = \@all_inc_files; | 
|---|
| 379 | return @all_inc_files; | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 | # strip_redundant_includes (%FILES) | 
|---|
| 383 | # --------------------------------- | 
|---|
| 384 | # Each key in %FILES is a file that must be present in the output. | 
|---|
| 385 | # However some of these files might already include other files in %FILES, | 
|---|
| 386 | # so there is no point in including them another time. | 
|---|
| 387 | # This removes items of %FILES which are already included by another file. | 
|---|
| 388 | sub strip_redundant_includes (%) | 
|---|
| 389 | { | 
|---|
| 390 | my %files = @_; | 
|---|
| 391 | # Files at the end of @file_order should override those at the beginning, | 
|---|
| 392 | # so it is important to preserve these trailing files.  We can remove | 
|---|
| 393 | # a file A if it is going to be output before a file B that includes | 
|---|
| 394 | # file A, not the converse. | 
|---|
| 395 | foreach my $file (reverse @file_order) | 
|---|
| 396 | { | 
|---|
| 397 | next unless exists $files{$file}; | 
|---|
| 398 | foreach my $ifile (@{$file_includes{$file}}) | 
|---|
| 399 | { | 
|---|
| 400 | next unless exists $files{$ifile}; | 
|---|
| 401 | delete $files{$ifile}; | 
|---|
| 402 | print STDERR "$ifile is already included by $file\n" | 
|---|
| 403 | if $verbose; | 
|---|
| 404 | } | 
|---|
| 405 | } | 
|---|
| 406 | return %files; | 
|---|
| 407 | } | 
|---|
| 408 |  | 
|---|
| 409 | sub trace_used_macros () | 
|---|
| 410 | { | 
|---|
| 411 | my %files = map { $map{$_} => 1 } keys %macro_seen; | 
|---|
| 412 | $files{'acinclude.m4'} = 1 if -f 'acinclude.m4'; | 
|---|
| 413 | %files = strip_redundant_includes %files; | 
|---|
| 414 | # configure.ac is implicitly included. | 
|---|
| 415 | delete $files{$configure_ac}; | 
|---|
| 416 |  | 
|---|
| 417 | my $traces = ($ENV{AUTOM4TE} || 'autom4te'); | 
|---|
| 418 | $traces .= " --language Autoconf-without-aclocal-m4 "; | 
|---|
| 419 | # All candidate files. | 
|---|
| 420 | $traces .= join (' ', grep { exists $files{$_} } @file_order) . " "; | 
|---|
| 421 | # All candidate macros. | 
|---|
| 422 | $traces .= join (' ', map { "--trace='$_:\$n'" } (keys %macro_seen)); | 
|---|
| 423 |  | 
|---|
| 424 | print STDERR "aclocal: running $traces $configure_ac\n" if $verbose; | 
|---|
| 425 |  | 
|---|
| 426 | my $tracefh = new Automake::XFile ("$traces $configure_ac |"); | 
|---|
| 427 |  | 
|---|
| 428 | my %traced = (); | 
|---|
| 429 |  | 
|---|
| 430 | while ($_ = $tracefh->getline) | 
|---|
| 431 | { | 
|---|
| 432 | chomp; | 
|---|
| 433 | $traced{$_} = 1 if $macro_seen{$_}; | 
|---|
| 434 | } | 
|---|
| 435 |  | 
|---|
| 436 | $tracefh->close; | 
|---|
| 437 |  | 
|---|
| 438 | return %traced; | 
|---|
| 439 | } | 
|---|
| 440 |  | 
|---|
| 441 | sub scan_configure () | 
|---|
| 442 | { | 
|---|
| 443 | # Make sure we include acinclude.m4 if it exists. | 
|---|
| 444 | if (-f 'acinclude.m4') | 
|---|
| 445 | { | 
|---|
| 446 | add_file ('acinclude.m4'); | 
|---|
| 447 | } | 
|---|
| 448 | scan_configure_dep ($configure_ac); | 
|---|
| 449 | } | 
|---|
| 450 |  | 
|---|
| 451 | ################################################################ | 
|---|
| 452 |  | 
|---|
| 453 | # Write output. | 
|---|
| 454 | sub write_aclocal ($@) | 
|---|
| 455 | { | 
|---|
| 456 | my ($output_file, @macros) = @_; | 
|---|
| 457 | my $output = ''; | 
|---|
| 458 |  | 
|---|
| 459 | my %files = map { $map{$_} => 1 } @macros; | 
|---|
| 460 | $files{'acinclude.m4'} = 1 if -f 'acinclude.m4'; | 
|---|
| 461 | %files = strip_redundant_includes %files; | 
|---|
| 462 | delete $files{$configure_ac}; | 
|---|
| 463 |  | 
|---|
| 464 | for $file (grep { exists $files{$_} } @file_order) | 
|---|
| 465 | { | 
|---|
| 466 | # Check the time stamp of this file, and all files it includes. | 
|---|
| 467 | for my $ifile ($file, @{$file_includes{$file}}) | 
|---|
| 468 | { | 
|---|
| 469 | my $mtime = mtime $ifile; | 
|---|
| 470 | $greatest_mtime = $mtime if $greatest_mtime < $mtime; | 
|---|
| 471 | } | 
|---|
| 472 |  | 
|---|
| 473 | # If the file to add looks like outside the project, copy it | 
|---|
| 474 | # to the output.  The regex catches filenames starting with | 
|---|
| 475 | # things like `/', `\', or `c:\'. | 
|---|
| 476 | if ($file =~ m,^(?:\w:)?[\\/],) | 
|---|
| 477 | { | 
|---|
| 478 | $output .= $file_contents{$file} . "\n"; | 
|---|
| 479 | } | 
|---|
| 480 | else | 
|---|
| 481 | { | 
|---|
| 482 | # Otherwise, simply include the file. | 
|---|
| 483 | $output .= "m4_include([$file])\n"; | 
|---|
| 484 | } | 
|---|
| 485 | } | 
|---|
| 486 |  | 
|---|
| 487 | # Nothing to output?! | 
|---|
| 488 | # FIXME: Shouldn't we diagnose this? | 
|---|
| 489 | return if ! length ($output); | 
|---|
| 490 |  | 
|---|
| 491 | # We used to print `# $output_file generated automatically etc.'  But | 
|---|
| 492 | # this creates spurious differences when using autoreconf.  Autoreconf | 
|---|
| 493 | # creates aclocal.m4t and then rename it to aclocal.m4, but the | 
|---|
| 494 | # rebuild rules generated by Automake create aclocal.m4 directly -- | 
|---|
| 495 | # this would gives two ways to get the same file, with a different | 
|---|
| 496 | # name in the header. | 
|---|
| 497 | $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*- | 
|---|
| 498 |  | 
|---|
| 499 | # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 | 
|---|
| 500 | # Free Software Foundation, Inc. | 
|---|
| 501 | # This file is free software; the Free Software Foundation | 
|---|
| 502 | # gives unlimited permission to copy and/or distribute it, | 
|---|
| 503 | # with or without modifications, as long as this notice is preserved. | 
|---|
| 504 |  | 
|---|
| 505 | # This program is distributed in the hope that it will be useful, | 
|---|
| 506 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without | 
|---|
| 507 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A | 
|---|
| 508 | # PARTICULAR PURPOSE. | 
|---|
| 509 |  | 
|---|
| 510 | $output"; | 
|---|
| 511 |  | 
|---|
| 512 | # We try not to update $output_file unless necessary, because | 
|---|
| 513 | # doing so invalidate Autom4te's cache and therefore slows down | 
|---|
| 514 | # tools called after aclocal. | 
|---|
| 515 | # | 
|---|
| 516 | # We need to overwrite $output_file in the following situations. | 
|---|
| 517 | #   * The --force option is in use. | 
|---|
| 518 | #   * One of the dependencies is younger. | 
|---|
| 519 | #     (Not updating $output_file in this situation would cause | 
|---|
| 520 | #     make to call aclocal in loop.) | 
|---|
| 521 | #   * The contents of the current file are different from what | 
|---|
| 522 | #     we have computed. | 
|---|
| 523 | if (!$force_output | 
|---|
| 524 | && $greatest_mtime < mtime ($output_file) | 
|---|
| 525 | && $output eq contents ($output_file)) | 
|---|
| 526 | { | 
|---|
| 527 | print STDERR "aclocal: $output_file unchanged\n" if $verbose; | 
|---|
| 528 | return; | 
|---|
| 529 | } | 
|---|
| 530 |  | 
|---|
| 531 | print STDERR "aclocal: writing $output_file\n" if $verbose; | 
|---|
| 532 |  | 
|---|
| 533 | my $out = new Automake::XFile "> $output_file"; | 
|---|
| 534 | print $out $output; | 
|---|
| 535 | return; | 
|---|
| 536 | } | 
|---|
| 537 |  | 
|---|
| 538 | ################################################################ | 
|---|
| 539 |  | 
|---|
| 540 | # Print usage and exit. | 
|---|
| 541 | sub usage ($) | 
|---|
| 542 | { | 
|---|
| 543 | local ($status) = @_; | 
|---|
| 544 |  | 
|---|
| 545 | print "Usage: aclocal [OPTIONS] ...\n\n"; | 
|---|
| 546 | print "\ | 
|---|
| 547 | Generate `aclocal.m4' by scanning `configure.ac' or `configure.in' | 
|---|
| 548 |  | 
|---|
| 549 | --acdir=DIR           directory holding config files | 
|---|
| 550 | --help                print this help, then exit | 
|---|
| 551 | -I DIR                add directory to search list for .m4 files | 
|---|
| 552 | --force               always update output file | 
|---|
| 553 | --output=FILE         put output in FILE (default aclocal.m4) | 
|---|
| 554 | --print-ac-dir        print name of directory holding m4 files | 
|---|
| 555 | --verbose             don't be silent | 
|---|
| 556 | --version             print version number, then exit | 
|---|
| 557 |  | 
|---|
| 558 | Report bugs to <bug-automake\@gnu.org>.\n"; | 
|---|
| 559 |  | 
|---|
| 560 | exit $status; | 
|---|
| 561 | } | 
|---|
| 562 |  | 
|---|
| 563 | # Parse command line. | 
|---|
| 564 | sub parse_arguments (@) | 
|---|
| 565 | { | 
|---|
| 566 | local (@arglist) = @_; | 
|---|
| 567 | local (@dirlist); | 
|---|
| 568 | local ($print_and_exit) = 0; | 
|---|
| 569 |  | 
|---|
| 570 | while (@arglist) | 
|---|
| 571 | { | 
|---|
| 572 | if ($arglist[0] =~ /^--acdir=(.+)$/) | 
|---|
| 573 | { | 
|---|
| 574 | $acdir = $1; | 
|---|
| 575 | } | 
|---|
| 576 | elsif ($arglist[0] =~/^--output=(.+)$/) | 
|---|
| 577 | { | 
|---|
| 578 | $output_file = $1; | 
|---|
| 579 | } | 
|---|
| 580 | elsif ($arglist[0] eq '-I') | 
|---|
| 581 | { | 
|---|
| 582 | shift (@arglist); | 
|---|
| 583 | push (@dirlist, $arglist[0]); | 
|---|
| 584 | } | 
|---|
| 585 | elsif ($arglist[0] eq '--print-ac-dir') | 
|---|
| 586 | { | 
|---|
| 587 | $print_and_exit = 1; | 
|---|
| 588 | } | 
|---|
| 589 | elsif ($arglist[0] eq '--force') | 
|---|
| 590 | { | 
|---|
| 591 | $force_output = 1; | 
|---|
| 592 | } | 
|---|
| 593 | elsif ($arglist[0] eq '--verbose') | 
|---|
| 594 | { | 
|---|
| 595 | ++$verbose; | 
|---|
| 596 | } | 
|---|
| 597 | elsif ($arglist[0] eq '--version') | 
|---|
| 598 | { | 
|---|
| 599 | print "aclocal (GNU $PACKAGE) $VERSION\n"; | 
|---|
| 600 | print "Written by Tom Tromey <tromey\@redhat.com>\n\n"; | 
|---|
| 601 | print "Copyright (C) 2004 Free Software Foundation, Inc.\n"; | 
|---|
| 602 | print "This is free software; see the source for copying conditions.  There is NO\n"; | 
|---|
| 603 | print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"; | 
|---|
| 604 | exit 0; | 
|---|
| 605 | } | 
|---|
| 606 | elsif ($arglist[0] eq '--help') | 
|---|
| 607 | { | 
|---|
| 608 | &usage (0); | 
|---|
| 609 | } | 
|---|
| 610 | else | 
|---|
| 611 | { | 
|---|
| 612 | print STDERR "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n"; | 
|---|
| 613 | exit 1; | 
|---|
| 614 | } | 
|---|
| 615 |  | 
|---|
| 616 | shift (@arglist); | 
|---|
| 617 | } | 
|---|
| 618 |  | 
|---|
| 619 | if ($print_and_exit) | 
|---|
| 620 | { | 
|---|
| 621 | print $acdir, "\n"; | 
|---|
| 622 | exit 0; | 
|---|
| 623 | } | 
|---|
| 624 |  | 
|---|
| 625 | $default_dirlist="$acdir/dirlist" | 
|---|
| 626 | if $acdir ne $default_acdir; | 
|---|
| 627 |  | 
|---|
| 628 | # Search the versioned directory near the end, and then the | 
|---|
| 629 | # unversioned directory last.  Only do this if the user didn't | 
|---|
| 630 | # override acdir. | 
|---|
| 631 | push (@dirlist, "$acdir-$APIVERSION") | 
|---|
| 632 | if $acdir eq $default_acdir; | 
|---|
| 633 |  | 
|---|
| 634 | # By default $(datadir)/aclocal doesn't exist.  We don't want to | 
|---|
| 635 | # get an error in the case where we are searching the default | 
|---|
| 636 | # directory and it hasn't been created. | 
|---|
| 637 | push (@dirlist, $acdir) | 
|---|
| 638 | unless $acdir eq $default_acdir && ! -d $acdir; | 
|---|
| 639 |  | 
|---|
| 640 | # Finally, adds any directory listed in the `dirlist' file. | 
|---|
| 641 | if (open (DEFAULT_DIRLIST, $default_dirlist)) | 
|---|
| 642 | { | 
|---|
| 643 | while (<DEFAULT_DIRLIST>) | 
|---|
| 644 | { | 
|---|
| 645 | # Ignore '#' lines. | 
|---|
| 646 | next if /^#/; | 
|---|
| 647 | # strip off newlines and end-of-line comments | 
|---|
| 648 | s/\s*\#.*$//; | 
|---|
| 649 | chomp ($contents=$_); | 
|---|
| 650 | if (-d $contents ) | 
|---|
| 651 | { | 
|---|
| 652 | push (@dirlist, $contents); | 
|---|
| 653 | } | 
|---|
| 654 | } | 
|---|
| 655 | close (DEFAULT_DIRLIST); | 
|---|
| 656 | } | 
|---|
| 657 |  | 
|---|
| 658 | return @dirlist; | 
|---|
| 659 | } | 
|---|
| 660 |  | 
|---|
| 661 | ################################################################ | 
|---|
| 662 |  | 
|---|
| 663 | local (@dirlist) = parse_arguments (@ARGV); | 
|---|
| 664 | $configure_ac = require_configure_ac; | 
|---|
| 665 | scan_m4_files (@dirlist); | 
|---|
| 666 | scan_configure; | 
|---|
| 667 | if (! $exit_code) | 
|---|
| 668 | { | 
|---|
| 669 | my %macro_traced = trace_used_macros; | 
|---|
| 670 | write_aclocal ($output_file, keys %macro_traced); | 
|---|
| 671 | } | 
|---|
| 672 | check_acinclude; | 
|---|
| 673 |  | 
|---|
| 674 | exit $exit_code; | 
|---|
| 675 |  | 
|---|
| 676 | ### Setup "GNU" style for perl-mode and cperl-mode. | 
|---|
| 677 | ## Local Variables: | 
|---|
| 678 | ## perl-indent-level: 2 | 
|---|
| 679 | ## perl-continued-statement-offset: 2 | 
|---|
| 680 | ## perl-continued-brace-offset: 0 | 
|---|
| 681 | ## perl-brace-offset: 0 | 
|---|
| 682 | ## perl-brace-imaginary-offset: 0 | 
|---|
| 683 | ## perl-label-offset: -2 | 
|---|
| 684 | ## cperl-indent-level: 2 | 
|---|
| 685 | ## cperl-brace-offset: 0 | 
|---|
| 686 | ## cperl-continued-brace-offset: 0 | 
|---|
| 687 | ## cperl-label-offset: -2 | 
|---|
| 688 | ## cperl-extra-newline-before-brace: t | 
|---|
| 689 | ## cperl-merge-trailing-else: nil | 
|---|
| 690 | ## cperl-continued-statement-offset: 2 | 
|---|
| 691 | ## End: | 
|---|