summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2013-12-05 20:33:43 -0500
committeryenatch <yenatch@gmail.com>2013-12-05 21:21:08 -0500
commit806fd657c2424a7328c21a4246da038a6dafed0e (patch)
tree71d987a15c4e4b4a1d3c3d683d3b00cd2f192f85
parent0fd121a81e1cbbf1a42e72a5d7c9e8099ef59f97 (diff)
use file includes in rgbasm objects to generate dependencies
-rw-r--r--pokemontools/scan_includes.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/pokemontools/scan_includes.py b/pokemontools/scan_includes.py
new file mode 100644
index 0000000..138f011
--- /dev/null
+++ b/pokemontools/scan_includes.py
@@ -0,0 +1,34 @@
+# coding: utf-8
+
+"""
+Recursively scan an asm file for rgbasm INCLUDEs and INCBINs.
+Used to generate dependencies for each rgbasm object.
+"""
+
+import os
+import sys
+
+import configuration
+conf = configuration.Config()
+
+def recursive_scan(filename, includes = []):
+ if (filename[-4:] == '.asm' or filename[-3] == '.tx') and os.path.exists(filename):
+ lines = open(filename).readlines()
+ for line in lines:
+ for directive in ('INCLUDE', 'INCBIN'):
+ if directive in line:
+ line = line[:line.find(';')]
+ if directive in line:
+ include = line.split('"')[1]
+ if include not in includes:
+ includes += [include]
+ includes = recursive_scan(include, includes)
+ break
+ return includes
+
+if __name__ == '__main__':
+ filenames = sys.argv[1:]
+ for filename in filenames:
+ dependencies = recursive_scan(os.path.join(conf.path, filename))
+ sys.stdout.write(' '.join(dependencies))
+