Start work on creating tiny builds per driver file included (nw)

This commit is contained in:
Miodrag Milanovic 2015-06-20 12:39:39 +02:00
parent d685805614
commit 88dfb98d23

80
src/build/makedep.py Normal file
View file

@ -0,0 +1,80 @@
#!/usr/bin/python
##
## license:BSD-3-Clause
## copyright-holders:Miodrag Milanovic
from __future__ import with_statement
import sys
## to ignore include of emu.h add it always to list
files_included = ['src/emu/emu.h']
include_dirs = ['src/emu/', 'src/mame/', 'src/mess/']
def file_exists(srcfile, folder):
includes = [ folder ]
includes.extend(include_dirs)
for line in includes:
try:
fp = open(line + srcfile, 'rb')
return line + srcfile
except IOError:
ignore=1
return ''
def parse_file(srcfile, folder):
try:
fp = open(srcfile, 'rb')
except IOError:
sys.stderr.write("Unable to open source file '%s'\n" % srcfile)
return 1
in_comment = 0
linenum = 0
for line in fp.readlines():
content = ''
linenum+=1
srcptr = 0
while srcptr < len(line):
c = line[srcptr]
srcptr+=1
if c==13 or c==10:
if c==13 and line[srcptr]==10:
srcptr+=1
continue
if c==' ' or c==9:
continue
if in_comment==1 and c=='*' and line[srcptr]=='/' :
srcptr+=1
in_comment = 0
continue
if in_comment:
continue
if c=='/' and line[srcptr]=='*' :
srcptr+=1
in_comment = 1
continue
if c=='/' and line[srcptr]=='/' :
break
content += c
content = content.strip()
if len(content)>0:
if content.startswith('#include'):
name = content[8:]
name = name.replace('"','')
fullname = file_exists(name, folder)
if fullname in files_included:
continue
if fullname!='':
sys.stderr.write("Includes '%s'\n" % fullname)
files_included.append(fullname)
newfolder = fullname.rsplit('/', 1)[0] + '/'
parse_file(fullname, newfolder)
continue
return 0
if len(sys.argv) < 2:
print('Usage:')
print(' makedep <source.c>')
sys.exit(0)
parse_file(sys.argv[1],'')