summaryrefslogtreecommitdiff
path: root/scan_includes.py
blob: 0abd3084a62207776f5422f786a2f6772f7faec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8

"""
Recursively scan an asm file for rgbasm INCLUDEs and INCBINs.
This is used to generate dependencies for each rgbasm object file.
"""

import os
import sys

def scan_for_includes(filename):
	filenames = []
	if os.path.exists(filename):
		for line in open(filename, 'r').readlines():
			if 'INCLUDE' in line or 'INCBIN' in line:
				line = line.split(';')[0]
				if 'INCLUDE' in line or 'INCBIN' in line:
					filenames += [line.split('"')[1]]
	return filenames

def recursive_scan_for_includes(filename):
	filenames = []
	if '.asm' in filename or '.tx' in filename:
		for include in scan_for_includes(filename):
			filenames += [include] + recursive_scan_for_includes(include)
	return filenames

if len(sys.argv) > 1:
	for arg in sys.argv[1:]:
		sys.stdout.write(' '.join(recursive_scan_for_includes(arg)))