8e27aaae5e85d81eb4de2fabcbc6d93bc322042c
[openssl.git] / util / clean-depend.pl
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
5 use strict;
6
7 while(<STDIN>) {
8     print;
9     last if /^# DO NOT DELETE THIS LINE/;
10 }
11
12 my %files;
13
14 my $thisfile="";
15 while(<STDIN>) {
16     my ($dummy, $file,$deps)=/^((.*):)? (.*)$/;
17     my $origfile="";
18     $thisfile=$file if defined $file;
19     next if !defined $deps;
20     $origfile=$thisfile;
21     $origfile=~s/\.o$/.c/;
22     my @deps=split ' ',$deps;
23     @deps=grep(!/^\//,@deps);
24     @deps=grep(!/^\\$/,@deps);
25     @deps=grep(!/^$origfile$/,@deps);
26 # pull out the kludged kerberos header (if present).
27     @deps=grep(!/^[.\/]+\/krb5.h/,@deps);
28     push @{$files{$thisfile}},@deps;
29 }
30
31 my $file;
32 foreach $file (sort keys %files) {
33     my $len=0;
34     my $dep;
35     my $origfile=$file;
36     $origfile=~s/\.o$/.c/;
37     push @{$files{$file}},$origfile;
38     foreach $dep (sort @{$files{$file}}) {
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
49 print "\n";