2
0

clean-depend.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/local/bin/perl -w
  2. # Clean the dependency list in a makefile of standard includes...
  3. # Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
  4. use strict;
  5. while(<STDIN>) {
  6. print;
  7. last if /^# DO NOT DELETE THIS LINE/;
  8. }
  9. my %files;
  10. my $thisfile="";
  11. while(<STDIN>) {
  12. my ($dummy, $file,$deps)=/^((.*):)? (.*)$/;
  13. my $origfile="";
  14. $thisfile=$file if defined $file;
  15. next if !defined $deps;
  16. $origfile=$thisfile;
  17. $origfile=~s/\.o$/.c/;
  18. my @deps=split ' ',$deps;
  19. @deps=grep(!/^\//,@deps);
  20. @deps=grep(!/^\\$/,@deps);
  21. @deps=grep(!/^$origfile$/,@deps);
  22. # pull out the kludged kerberos header (if present).
  23. @deps=grep(!/^[.\/]+\/krb5.h/,@deps);
  24. push @{$files{$thisfile}},@deps;
  25. }
  26. my $file;
  27. foreach $file (sort keys %files) {
  28. my $len=0;
  29. my $dep;
  30. my $origfile=$file;
  31. $origfile=~s/\.o$/.c/;
  32. $file=~s/^\.\///;
  33. push @{$files{$file}},$origfile;
  34. my $prevdep="";
  35. # Remove leading ./ before sorting
  36. my @deps = map { $_ =~ s/^\.\///; $_ } @{$files{$file}};
  37. foreach $dep (sort @deps) {
  38. $dep=~s/^\.\///;
  39. next if $prevdep eq $dep; # to exterminate duplicates...
  40. $prevdep = $dep;
  41. $len=0 if $len+length($dep)+1 >= 80;
  42. if($len == 0) {
  43. print "\n$file:";
  44. $len=length($file)+1;
  45. }
  46. print " $dep";
  47. $len+=length($dep)+1;
  48. }
  49. }
  50. print "\n";