diff options
author | rsc <rsc> | 2007-08-27 23:26:33 +0000 |
---|---|---|
committer | rsc <rsc> | 2007-08-27 23:26:33 +0000 |
commit | 558ab49f13634d972e956020a12d14fdb1416b94 (patch) | |
tree | 02a4424e94f3401b8071dbfb2fe50212da17c35c /cuth | |
parent | 99b11b6c64c17b94288c659e9398261e69a0cf75 (diff) | |
download | xv6-labs-558ab49f13634d972e956020a12d14fdb1416b94.tar.gz xv6-labs-558ab49f13634d972e956020a12d14fdb1416b94.tar.bz2 xv6-labs-558ab49f13634d972e956020a12d14fdb1416b94.zip |
delete unnecessary #include lines
Diffstat (limited to 'cuth')
-rwxr-xr-x | cuth | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -0,0 +1,48 @@ +#!/usr/bin/perl + +$| = 1; + +sub writefile($@){ + my ($file, @lines) = @_; + + sleep(1); + open(F, ">$file") || die "open >$file: $!"; + print F @lines; + close(F); +} + +# Cut out #include lines that don't contribute anything. +for($i=0; $i<@ARGV; $i++){ + $file = $ARGV[$i]; + if(!open(F, $file)){ + print STDERR "open $file: $!\n"; + next; + } + @lines = <F>; + close(F); + + $obj = "$file.o"; + $obj =~ s/\.c\.o$/.o/; + system("touch $file"); + + if(system("make CC='gcc -Werror' $obj >/dev/null 2>\&1") != 0){ + print STDERR "make $obj failed: $rv\n"; + next; + } + + system("cp $file =$file"); + for($j=@lines-1; $j>=0; $j--){ + if($lines[$j] =~ /^#include/){ + $old = $lines[$j]; + $lines[$j] = "/* CUT-H */\n"; + writefile($file, @lines); + if(system("make CC='gcc -Werror' $obj >/dev/null 2>\&1") != 0){ + $lines[$j] = $old; + }else{ + print STDERR "$file $old"; + } + } + } + writefile($file, grep {!/CUT-H/} @lines); + system("rm =$file"); +} |