poketcg/tools/scan_includes.py
xCrystal 9ec77a8f48 Don't use the extras submodule
Most tools from pokemon-reverse-engineering-tools are meant for pokecrystal or pokered. Having only the subset of required tools without depending on a submodule makes it easier to submit custom changes exclusive poketcg and its structure. For example, the disasm tool can be made to use poketcg rom/sym files by default, read vram and hram as symbols, and can be modified in the future to for example guess text labels in applicable load instructions or to dump poketcg-specific scripts. gfx.py was also added, but without the not required pokecrystal lz (de)compression support
2018-06-12 14:12:32 +02:00

44 lines
908 B
Python

#!/bin/python
# coding: utf-8
"""
Recursively scan an asm file for dependencies.
"""
import sys
import argparse
import os.path
includes = set()
def scan_file(filename):
for line in open(filename):
if 'INC' not in line:
continue
line = line.split(';')[0]
if 'INCLUDE' in line:
include = line.split('"')[1]
if os.path.exists("src/"):
includes.add("src/" + include)
scan_file("src/" + include)
else:
includes.add(include)
scan_file(include)
elif 'INCBIN' in line:
include = line.split('"')[1]
if 'baserom.gbc' not in line and os.path.exists("src/"):
includes.add("src/" + include)
else:
includes.add(include)
def main():
ap = argparse.ArgumentParser()
ap.add_argument('filenames', nargs='*')
args = ap.parse_args()
for filename in set(args.filenames):
scan_file(filename)
sys.stdout.write(' '.join(includes))
if __name__ == '__main__':
main()