2
0

clean-depend.pl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. foreach $dep (sort @{$files{$file}}) {
  36. $dep=~s/^\.\///;
  37. next if $prevdep eq $dep; # to exterminate duplicates...
  38. $prevdep = $dep;
  39. $len=0 if $len+length($dep)+1 >= 80;
  40. if($len == 0) {
  41. print "\n$file:";
  42. $len=length($file)+1;
  43. }
  44. print " $dep";
  45. $len+=length($dep)+1;
  46. }
  47. }
  48. print "\n";