src-dep.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/local/bin/perl
  2. # we make up an array of
  3. # $file{function_name}=filename;
  4. # $unres{filename}="func1 func2 ...."
  5. $debug=1;
  6. #$nm_func="parse_linux";
  7. $nm_func="parse_solaris";
  8. foreach (@ARGV)
  9. {
  10. &$nm_func($_);
  11. }
  12. foreach $file (sort keys %unres)
  13. {
  14. @a=split(/\s+/,$unres{$file});
  15. %ff=();
  16. foreach $func (@a)
  17. {
  18. $f=$file{$func};
  19. $ff{$f}=1 if $f ne "";
  20. }
  21. foreach $a (keys %ff)
  22. { $we_need{$file}.="$a "; }
  23. }
  24. foreach $file (sort keys %we_need)
  25. {
  26. # print " $file $we_need{$file}\n";
  27. foreach $bit (split(/\s+/,$we_need{$file}))
  28. { push(@final,&walk($bit)); }
  29. foreach (@final) { $fin{$_}=1; }
  30. @final="";
  31. foreach (sort keys %fin)
  32. { push(@final,$_); }
  33. print "$file: @final\n";
  34. }
  35. sub walk
  36. {
  37. local($f)=@_;
  38. local(@a,%seen,@ret,$r);
  39. @ret="";
  40. $f =~ s/^\s+//;
  41. $f =~ s/\s+$//;
  42. return "" if ($f =~ "^\s*$");
  43. return(split(/\s/,$done{$f})) if defined ($done{$f});
  44. return if $in{$f} > 0;
  45. $in{$f}++;
  46. push(@ret,$f);
  47. foreach $r (split(/\s+/,$we_need{$f}))
  48. {
  49. push(@ret,&walk($r));
  50. }
  51. $in{$f}--;
  52. $done{$f}=join(" ",@ret);
  53. return(@ret);
  54. }
  55. sub parse_linux
  56. {
  57. local($name)=@_;
  58. open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
  59. while (<IN>)
  60. {
  61. chop;
  62. next if /^\s*$/;
  63. if (/^[^[](.*):$/)
  64. {
  65. $file=$1;
  66. $file="$1.c" if /\[(.*).o\]/;
  67. print STDERR "$file\n";
  68. $we_need{$file}=" ";
  69. next;
  70. }
  71. @a=split(/\s*\|\s*/);
  72. next unless $#a == 7;
  73. next unless $a[4] eq "GLOB";
  74. if ($a[6] eq "UNDEF")
  75. {
  76. $unres{$file}.=$a[7]." ";
  77. }
  78. else
  79. {
  80. if ($file{$a[7]} ne "")
  81. {
  82. print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
  83. }
  84. else
  85. {
  86. $file{$a[7]}=$file;
  87. }
  88. }
  89. }
  90. close(IN);
  91. }
  92. sub parse_solaris
  93. {
  94. local($name)=@_;
  95. open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
  96. while (<IN>)
  97. {
  98. chop;
  99. next if /^\s*$/;
  100. if (/^(\S+):$/)
  101. {
  102. $file=$1;
  103. #$file="$1.c" if $file =~ /^(.*).o$/;
  104. print STDERR "$file\n";
  105. $we_need{$file}=" ";
  106. next;
  107. }
  108. @a=split(/\s*\|\s*/);
  109. next unless $#a == 7;
  110. next unless $a[4] eq "GLOB";
  111. if ($a[6] eq "UNDEF")
  112. {
  113. $unres{$file}.=$a[7]." ";
  114. print STDERR "$file needs $a[7]\n" if $debug;
  115. }
  116. else
  117. {
  118. if ($file{$a[7]} ne "")
  119. {
  120. print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
  121. }
  122. else
  123. {
  124. $file{$a[7]}=$file;
  125. print STDERR "$file has $a[7]\n" if $debug;
  126. }
  127. }
  128. }
  129. close(IN);
  130. }