Badguy and graphic upgrades to level 'The Shattered Bridge'
[supertux.git] / tools / include_optimize.rb
1 #!/usr/bin/ruby -w
2
3 def write_file_without_lines(source, lines, without_lines)
4   out = File.new(source, 'w')
5   lines.each_with_index { |v, i|
6     if without_lines.member? i then
7       out.print "//", v
8     else
9       out.print v
10     end
11   }
12   out.close()
13 end
14
15 def optimize(source, target)
16   lines = File.new(source).readlines()
17   includes = []
18   lines.each_with_index { |v, i|
19     if v =~ /^#include/ then
20       # puts v
21       includes << i
22     end
23   }
24
25   unneeded_includes = []
26
27   includes.each{|i|
28     # puts i
29     write_file_without_lines(source, lines, [i])
30
31     ret = system("scons", "-u", target)
32     if ret then
33       puts "INCUNNEEDED #{source} #{lines[i].chop}" 
34       unneeded_includes << i
35     end
36   }
37
38   write_file_without_lines(source, lines, unneeded_includes)
39 end
40
41 ARGV.each{ |filename|
42   source = filename
43   target = "build/#{filename.gsub(/\..pp$/, '.o')}"
44   puts "#{source} => #{target}"
45
46   optimize(source, target)
47 }
48
49 # EOF #