PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/build/unix/mddepend.pl

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Perl | 165 lines | 94 code | 19 blank | 52 comment | 21 complexity | 8a7229bb726443de06e2d697f8269452 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. #!/usr/bin/env perl
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. #
  5. # The contents of this file are subject to the Mozilla Public License Version
  6. # 1.1 (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. # http://www.mozilla.org/MPL/
  9. #
  10. # Software distributed under the License is distributed on an "AS IS" basis,
  11. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. # for the specific language governing rights and limitations under the
  13. # License.
  14. #
  15. # The Original Code is this file as it was released upon March 8, 1999.
  16. #
  17. # The Initial Developer of the Original Code is
  18. # Netscape Communications Corporation.
  19. # Portions created by the Initial Developer are Copyright (C) 1999
  20. # the Initial Developer. All Rights Reserved.
  21. #
  22. # Contributor(s):
  23. #
  24. # Alternatively, the contents of this file may be used under the terms of
  25. # either of the GNU General Public License Version 2 or later (the "GPL"),
  26. # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. # in which case the provisions of the GPL or the LGPL are applicable instead
  28. # of those above. If you wish to allow use of your version of this file only
  29. # under the terms of either the GPL or the LGPL, and not to allow others to
  30. # use your version of this file under the terms of the MPL, indicate your
  31. # decision by deleting the provisions above and replace them with the notice
  32. # and other provisions required by the GPL or the LGPL. If you do not delete
  33. # the provisions above, a recipient may use your version of this file under
  34. # the terms of any one of the MPL, the GPL or the LGPL.
  35. #
  36. # ***** END LICENSE BLOCK *****
  37. # mddepend.pl - Reads in dependencies generated my -MD flag. Prints list
  38. # of objects that need to be rebuilt. These can then be added to the
  39. # PHONY target. Using this script copes with the problem of header
  40. # files that have been removed from the build.
  41. #
  42. # Usage:
  43. # mddepend.pl <output_file> <dependency_files...>
  44. #
  45. # Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
  46. use strict;
  47. use constant DEBUG => 0;
  48. my $outfile = shift @ARGV;
  49. my $silent = $ENV{MAKEFLAGS} =~ /^\w*s|\s-s/;
  50. my $line = '';
  51. my %alldeps;
  52. # Parse dependency files
  53. while (<>) {
  54. s/\r?\n$//; # Handle both unix and DOS line endings
  55. $line .= $_;
  56. if ($line =~ /\\$/) {
  57. chop $line;
  58. next;
  59. }
  60. my ($obj,$rest) = split /\s*:\s+/, $line, 2;
  61. $line = '';
  62. next if !$obj || !$rest;
  63. my @deps = split /\s+/, $rest;
  64. push @{$alldeps{$obj}}, @deps;
  65. if (DEBUG >= 2) {
  66. foreach my $dep (@deps) { print "add $obj $dep\n"; }
  67. }
  68. }
  69. # Test dependencies
  70. my %modtimes; # cache
  71. my @objs; # force rebuild on these
  72. OBJ_LOOP: foreach my $obj (keys %alldeps) {
  73. my $mtime = (stat $obj)[9] or next;
  74. my %not_in_cache;
  75. my $deps = $alldeps{$obj};
  76. foreach my $dep_file (@{$deps}) {
  77. my $dep_mtime = $modtimes{$dep_file};
  78. if (not defined $dep_mtime) {
  79. print "Skipping $dep_file for $obj, will stat() later\n" if DEBUG >= 2;
  80. $not_in_cache{$dep_file} = 1;
  81. next;
  82. }
  83. print "Found $dep_file in cache\n" if DEBUG >= 2;
  84. if ($dep_mtime > $mtime) {
  85. print "$dep_file($dep_mtime) newer than $obj($mtime)\n" if DEBUG;
  86. }
  87. elsif ($dep_mtime == -1) {
  88. print "Couldn't stat $dep_file for $obj\n" if DEBUG;
  89. }
  90. else {
  91. print "$dep_file($dep_mtime) older than $obj($mtime)\n" if DEBUG >= 2;
  92. next;
  93. }
  94. push @objs, $obj; # dependency is missing or newer
  95. next OBJ_LOOP; # skip checking the rest of the dependencies
  96. }
  97. foreach my $dep_file (keys %not_in_cache) {
  98. print "STAT $dep_file for $obj\n" if DEBUG >= 2;
  99. my $dep_mtime = $modtimes{$dep_file} = (stat $dep_file)[9] || -1;
  100. if ($dep_mtime > $mtime) {
  101. print "$dep_file($dep_mtime) newer than $obj($mtime)\n" if DEBUG;
  102. }
  103. elsif ($dep_mtime == -1) {
  104. print "Couldn't stat $dep_file for $obj\n" if DEBUG;
  105. }
  106. else {
  107. print "$dep_file($dep_mtime) older than $obj($mtime)\n" if DEBUG >= 2;
  108. next;
  109. }
  110. push @objs, $obj; # dependency is missing or newer
  111. next OBJ_LOOP; # skip checking the rest of the dependencies
  112. }
  113. # If we get here it means nothing needs to be done for $obj
  114. }
  115. # Output objects to rebuild (if needed).
  116. if (@objs) {
  117. my $old_output;
  118. my $new_output = "@objs: FORCE\n";
  119. # Read in the current dependencies file.
  120. open(OLD, "<$outfile")
  121. and $old_output = <OLD>;
  122. close(OLD);
  123. # Only write out the dependencies if they are different.
  124. if ($new_output ne $old_output) {
  125. open(OUT, ">$outfile") and print OUT "$new_output";
  126. print "Updating dependencies file, $outfile\n" unless $silent;
  127. if (DEBUG) {
  128. print "new: $new_output\n";
  129. print "was: $old_output\n" if $old_output ne '';
  130. }
  131. }
  132. } elsif (-s $outfile) {
  133. # Remove the old dependencies because all objects are up to date.
  134. print "Removing old dependencies file, $outfile\n" unless $silent;
  135. if (DEBUG) {
  136. my $old_output;
  137. open(OLD, "<$outfile")
  138. and $old_output = <OLD>;
  139. close(OLD);
  140. print "was: $old_output\n";
  141. }
  142. unlink $outfile;
  143. }