Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.0 KiB

  1. #!../perl
  2. $M = '-M';
  3. $M = '-m' if -d '/usr/uts' && -f '/etc/master';
  4. do 'getopt.pl';
  5. do Getopt('f');
  6. if ($opt_f) {
  7. $makefile = $opt_f;
  8. }
  9. elsif (-f 'makefile') {
  10. $makefile = 'makefile';
  11. }
  12. elsif (-f 'Makefile') {
  13. $makefile = 'Makefile';
  14. }
  15. else {
  16. die "No makefile\n";
  17. }
  18. $MF = 'mf00';
  19. while(($key,$val) = each(ENV)) {
  20. $mac{$key} = $val;
  21. }
  22. do scan($makefile);
  23. $co = $action{'.c.o'};
  24. $co = ' ' unless $co;
  25. $missing = "Missing dependencies:\n";
  26. foreach $key (sort keys(o)) {
  27. if ($oc{$key}) {
  28. $src = $oc{$key};
  29. $action = $action{$key};
  30. }
  31. else {
  32. $action = '';
  33. }
  34. if (!$action) {
  35. if ($co && ($c = $key) =~ s/\.o$/.c/ && -f $c) {
  36. $src = $c;
  37. $action = $co;
  38. }
  39. else {
  40. print "No source found for $key $c\n";
  41. next;
  42. }
  43. }
  44. $I = '';
  45. $D = '';
  46. $I .= $1 while $action =~ s/(-I\S+\s*)//;
  47. $D .= $1 . ' ' while $action =~ s/(-D\w+)//;
  48. if ($opt_v) {
  49. $cmd = "Checking $key: cc $M $D $I $src";
  50. $cmd =~ s/\s\s+/ /g;
  51. print stderr $cmd,"\n";
  52. }
  53. open(CPP,"cc $M $D $I $src|") || die "Can't run C preprocessor: $!";
  54. while (<CPP>) {
  55. ($name,$dep) = split;
  56. $dep =~ s|^\./||;
  57. (print $missing,"$key: $dep\n"),($missing='')
  58. unless ($dep{"$key: $dep"} += 2) > 2;
  59. }
  60. }
  61. $extra = "\nExtraneous dependencies:\n";
  62. foreach $key (sort keys(dep)) {
  63. if ($key =~ /\.o: .*\.h$/ && $dep{$key} == 1) {
  64. print $extra,$key,"\n";
  65. $extra = '';
  66. }
  67. }
  68. sub scan {
  69. local($makefile) = @_;
  70. local($MF) = $MF;
  71. print stderr "Analyzing $makefile.\n" if $opt_v;
  72. $MF++;
  73. open($MF,$makefile) || die "Can't open $makefile: $!";
  74. while (<$MF>) {
  75. chop;
  76. chop($_ = $_ . <$MF>) while s/\\$//;
  77. next if /^#/;
  78. next if /^$/;
  79. s/\$\((\w+):([^=)]*)=([^)]*)\)/do subst("$1","$2","$3")/eg;
  80. s/\$\((\w+)\)/$mac{$1}/eg;
  81. $mac{$1} = $2, next if /^(\w+)\s*=\s*(.*)/;
  82. if (/^include\s+(.*)/) {
  83. do scan($1);
  84. print stderr "Continuing $makefile.\n" if $opt_v;
  85. next;
  86. }
  87. if (/^([^:]+):\s*(.*)/) {
  88. $left = $1;
  89. $right = $2;
  90. if ($right =~ /^([^;]*);(.*)/) {
  91. $right = $1;
  92. $action = $2;
  93. }
  94. else {
  95. $action = '';
  96. }
  97. while (<$MF>) {
  98. last unless /^\t/;
  99. chop;
  100. chop($_ = $_ . <$MF>) while s/\\$//;
  101. next if /^#/;
  102. last if /^$/;
  103. s/\$\((\w+):([^=)]*)=([^)]*)\)/do subst("$1","$2","$3")/eg;
  104. s/\$\((\w+)\)/$mac{$1}/eg;
  105. $action .= $_;
  106. }
  107. foreach $targ (split(' ',$left)) {
  108. $targ =~ s|^\./||;
  109. foreach $src (split(' ',$right)) {
  110. $src =~ s|^\./||;
  111. $deplist{$targ} .= ' ' . $src;
  112. $dep{"$targ: $src"} = 1;
  113. $o{$src} = 1 if $src =~ /\.o$/;
  114. $oc{$targ} = $src if $targ =~ /\.o$/ && $src =~ /\.[yc]$/;
  115. }
  116. $action{$targ} .= $action;
  117. }
  118. redo if $_;
  119. }
  120. }
  121. close($MF);
  122. }
  123. sub subst {
  124. local($foo,$from,$to) = @_;
  125. $foo = $mac{$foo};
  126. $from =~ s/\./[.]/;
  127. y/a/a/;
  128. $foo =~ s/\b$from\b/$to/g;
  129. $foo;
  130. }