2
0

clean-depend.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. next if $prevdep eq $dep; # to exterminate duplicates...
  39. $prevdep = $dep;
  40. $len=0 if $len+length($dep)+1 >= 80;
  41. if($len == 0) {
  42. print "\n$file:";
  43. $len=length($file)+1;
  44. }
  45. print " $dep";
  46. $len+=length($dep)+1;
  47. }
  48. }
  49. print "\n";