Added scripts for source code maintainance
authorgrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 19 Nov 2009 04:37:32 +0000 (04:37 +0000)
committergrumbel <grumbel@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 19 Nov 2009 04:37:32 +0000 (04:37 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6042 837edb03-e0f3-0310-88ca-d4d4e8b29345

tools/fix_include_guards.sh [new file with mode: 0755]
tools/include_optimize.rb [new file with mode: 0755]

diff --git a/tools/fix_include_guards.sh b/tools/fix_include_guards.sh
new file mode 100755 (executable)
index 0000000..d8ecafa
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+for i in "$@"; do
+    echo $i
+    NAME=$(echo $i | sed "s/[\/\.]/_/g;s/^/HEADER_SUPERTUX_/" | tr [a-z] [A-Z])
+    sed  -i "s/^#ifndef .*_H_\$/#ifndef $NAME/" $i; 
+    sed  -i "s/^#define .*_H_\$/#define $NAME/" $i; 
+done
+
+# EOF #
diff --git a/tools/include_optimize.rb b/tools/include_optimize.rb
new file mode 100755 (executable)
index 0000000..5183da9
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/ruby -w
+
+def write_file_without_lines(source, lines, without_lines)
+  out = File.new(source, 'w')
+  lines.each_with_index { |v, i|
+    if without_lines.member? i then
+      out.print "//", v
+    else
+      out.print v
+    end
+  }
+  out.close()
+end
+
+def optimize(source, target)
+  lines = File.new(source).readlines()
+  includes = []
+  lines.each_with_index { |v, i|
+    if v =~ /^#include/ then
+      # puts v
+      includes << i
+    end
+  }
+
+  unneeded_includes = []
+
+  includes.each{|i|
+    # puts i
+    write_file_without_lines(source, lines, [i])
+
+    ret = system("scons", "-u", target)
+    if ret then
+      puts "INCUNNEEDED #{source} #{lines[i].chop}" 
+      unneeded_includes << i
+    end
+  }
+
+  write_file_without_lines(source, lines, unneeded_includes)
+end
+
+ARGV.each{ |filename|
+  source = filename
+  target = "build/#{filename.gsub(/\..pp$/, '.o')}"
+  puts "#{source} => #{target}"
+
+  optimize(source, target)
+}
+
+# EOF #