2015-06-20 12:39:39 +02:00
|
|
|
#!/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
|
2015-06-20 16:35:49 +02:00
|
|
|
|
2015-06-20 12:39:39 +02:00
|
|
|
files_included = ['src/emu/emu.h']
|
|
|
|
|
2016-08-12 18:27:54 +02:00
|
|
|
include_dirs = ['src/emu/', 'src/devices/', 'src/mame/', 'src/lib/']
|
2015-06-20 12:39:39 +02:00
|
|
|
|
2015-06-20 13:41:55 +02:00
|
|
|
mappings = dict()
|
|
|
|
|
2015-06-20 16:35:49 +02:00
|
|
|
deps_files_included = [ ]
|
|
|
|
|
2015-09-30 17:21:14 +02:00
|
|
|
deps_include_dirs = ['src/mame/']
|
2015-06-20 16:35:49 +02:00
|
|
|
|
|
|
|
components = [ ]
|
2015-06-20 13:41:55 +02:00
|
|
|
|
2015-06-20 16:35:49 +02:00
|
|
|
drivers = [ ]
|
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
def file_exists(root, srcfile, folder, inc_dir):
|
2015-06-20 12:39:39 +02:00
|
|
|
includes = [ folder ]
|
2015-06-20 16:35:49 +02:00
|
|
|
includes.extend(inc_dir)
|
2015-06-20 12:39:39 +02:00
|
|
|
for line in includes:
|
|
|
|
try:
|
2016-01-03 11:09:35 +01:00
|
|
|
fp = open(root + line + srcfile, 'r')
|
2015-07-04 02:37:32 +02:00
|
|
|
fp.close()
|
2015-06-20 12:39:39 +02:00
|
|
|
return line + srcfile
|
|
|
|
except IOError:
|
2015-07-03 23:45:36 +02:00
|
|
|
pass
|
2015-06-20 12:39:39 +02:00
|
|
|
return ''
|
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
def add_c_if_exists(root, fullname):
|
2015-06-20 16:35:49 +02:00
|
|
|
try:
|
2016-01-03 11:09:35 +01:00
|
|
|
fp = open(root + fullname, 'r')
|
2015-07-04 02:37:32 +02:00
|
|
|
fp.close()
|
2015-06-20 16:35:49 +02:00
|
|
|
deps_files_included.append(fullname)
|
|
|
|
except IOError:
|
2015-07-03 23:45:36 +02:00
|
|
|
pass
|
2015-06-20 16:35:49 +02:00
|
|
|
|
2015-06-21 08:59:21 +02:00
|
|
|
def add_rest_if_exists(root, srcfile,folder):
|
2015-06-20 16:35:49 +02:00
|
|
|
t = srcfile.rsplit('/', 2)
|
|
|
|
if t[1]=='includes':
|
2015-11-08 13:44:34 +01:00
|
|
|
t[2] = t[2].replace('.h','.cpp')
|
2015-06-20 16:35:49 +02:00
|
|
|
t[1] = 'drivers'
|
2015-06-20 18:20:10 +02:00
|
|
|
add_c_if_exists(root,"/".join(t))
|
2015-06-21 08:59:21 +02:00
|
|
|
parse_file_for_deps(root, "/".join(t), folder)
|
2015-06-20 16:35:49 +02:00
|
|
|
t[1] = 'machine'
|
2015-06-20 18:20:10 +02:00
|
|
|
add_c_if_exists(root,"/".join(t))
|
2015-06-21 08:59:21 +02:00
|
|
|
parse_file_for_deps(root, "/".join(t), folder)
|
2015-06-20 16:35:49 +02:00
|
|
|
t[1] = 'video'
|
2015-06-20 18:20:10 +02:00
|
|
|
add_c_if_exists(root,"/".join(t))
|
2015-06-21 08:59:21 +02:00
|
|
|
parse_file_for_deps(root, "/".join(t), folder)
|
2015-06-20 16:35:49 +02:00
|
|
|
t[1] = 'audio'
|
2015-06-20 18:20:10 +02:00
|
|
|
add_c_if_exists(root,"/".join(t))
|
2015-06-21 08:59:21 +02:00
|
|
|
parse_file_for_deps(root, "/".join(t), folder)
|
2015-06-20 16:35:49 +02:00
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
def parse_file_for_deps(root, srcfile, folder):
|
2015-06-20 16:35:49 +02:00
|
|
|
try:
|
2016-01-03 11:09:35 +01:00
|
|
|
fp = open(root + srcfile, 'r')
|
2015-06-20 16:35:49 +02:00
|
|
|
except IOError:
|
|
|
|
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
|
2016-01-03 11:09:35 +01:00
|
|
|
if ord(c)==13 or ord(c)==10:
|
|
|
|
if ord(c)==13 and ord(line[srcptr])==10:
|
2015-06-20 16:35:49 +02:00
|
|
|
srcptr+=1
|
|
|
|
continue
|
2016-01-03 11:09:35 +01:00
|
|
|
if c==' ' or ord(c)==9:
|
2015-06-20 16:35:49 +02:00
|
|
|
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('"','')
|
2015-06-20 18:20:10 +02:00
|
|
|
fullname = file_exists(root, name, folder,deps_include_dirs)
|
2015-06-20 16:35:49 +02:00
|
|
|
if fullname in deps_files_included:
|
|
|
|
continue
|
|
|
|
if fullname!='':
|
|
|
|
deps_files_included.append(fullname)
|
2015-11-08 13:44:34 +01:00
|
|
|
add_c_if_exists(root, fullname.replace('.h','.cpp'))
|
2015-06-21 08:59:21 +02:00
|
|
|
add_rest_if_exists(root, fullname,folder)
|
2015-06-20 16:35:49 +02:00
|
|
|
newfolder = fullname.rsplit('/', 1)[0] + '/'
|
2015-06-20 18:20:10 +02:00
|
|
|
parse_file_for_deps(root, fullname, newfolder)
|
2015-06-20 16:35:49 +02:00
|
|
|
continue
|
2015-07-04 02:37:32 +02:00
|
|
|
fp.close()
|
2015-06-20 16:35:49 +02:00
|
|
|
return 0
|
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
def parse_file(root, srcfile, folder):
|
2015-06-20 12:39:39 +02:00
|
|
|
try:
|
2016-01-03 11:09:35 +01:00
|
|
|
fp = open(root + srcfile, 'r')
|
2015-06-20 12:39:39 +02:00
|
|
|
except IOError:
|
|
|
|
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
|
2016-01-03 11:09:35 +01:00
|
|
|
if ord(c)==13 or ord(c)==10:
|
|
|
|
if ord(c)==13 and ord(line[srcptr])==10:
|
2015-06-20 12:39:39 +02:00
|
|
|
srcptr+=1
|
|
|
|
continue
|
2016-01-03 11:09:35 +01:00
|
|
|
if c==' ' or ord(c)==9:
|
2015-06-20 12:39:39 +02:00
|
|
|
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('"','')
|
2015-06-20 18:20:10 +02:00
|
|
|
fullname = file_exists(root, name, folder,include_dirs)
|
2015-06-20 12:39:39 +02:00
|
|
|
if fullname in files_included:
|
|
|
|
continue
|
2015-09-12 10:12:14 +02:00
|
|
|
if "src/lib/netlist/" in fullname:
|
2015-06-21 08:44:45 +02:00
|
|
|
continue
|
2015-06-20 12:39:39 +02:00
|
|
|
if fullname!='':
|
2015-06-20 13:41:55 +02:00
|
|
|
if fullname in mappings.keys():
|
|
|
|
if not(mappings[fullname] in components):
|
|
|
|
components.append(mappings[fullname])
|
2015-06-20 12:39:39 +02:00
|
|
|
files_included.append(fullname)
|
|
|
|
newfolder = fullname.rsplit('/', 1)[0] + '/'
|
2015-06-20 18:20:10 +02:00
|
|
|
parse_file(root, fullname, newfolder)
|
2016-05-01 11:01:27 +02:00
|
|
|
if (fullname.endswith('.h') and not("src/emu" in fullname) and not("src/devices" in fullname) and not("src/lib" in fullname) and not("src/osd" in fullname)):
|
|
|
|
parse_file_for_deps(root, fullname.replace('.h','.cpp'), newfolder)
|
|
|
|
elif fullname.endswith('.h'):
|
2015-11-08 13:44:34 +01:00
|
|
|
parse_file(root, fullname.replace('.h','.cpp'), newfolder)
|
2015-06-20 12:39:39 +02:00
|
|
|
continue
|
2015-07-04 02:37:32 +02:00
|
|
|
fp.close()
|
2015-06-20 12:39:39 +02:00
|
|
|
return 0
|
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
def parse_file_for_drivers(root, srcfile):
|
2016-03-02 14:21:26 +01:00
|
|
|
srcfile = srcfile.replace('\\','/')
|
|
|
|
if srcfile.startswith('src/mame/drivers'):
|
|
|
|
splitname = srcfile.split('/', 4)
|
|
|
|
drivers.append(splitname[3])
|
2015-06-20 16:35:49 +02:00
|
|
|
return 0
|
|
|
|
|
2015-06-20 13:41:55 +02:00
|
|
|
def parse_lua_file(srcfile):
|
|
|
|
try:
|
2016-01-03 11:09:35 +01:00
|
|
|
fp = open(srcfile, 'r')
|
2015-06-20 13:41:55 +02:00
|
|
|
except IOError:
|
|
|
|
sys.stderr.write("Unable to open source file '%s'\n" % srcfile)
|
|
|
|
return 1
|
|
|
|
for line in fp.readlines():
|
|
|
|
content = line.strip()
|
|
|
|
if len(content)>0:
|
|
|
|
if content.startswith('--@'):
|
|
|
|
name = content[3:]
|
|
|
|
mappings[name.rsplit(',', 1)[0]] = name.rsplit(',', 1)[1]
|
|
|
|
return 0
|
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
if len(sys.argv) < 5:
|
2015-06-20 12:39:39 +02:00
|
|
|
print('Usage:')
|
2015-06-20 18:20:10 +02:00
|
|
|
print(' makedep <root> <source.c> <type> <target>')
|
2015-06-20 12:39:39 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
root = sys.argv[1] + '/'
|
2015-06-20 13:41:55 +02:00
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
parse_lua_file(root +'scripts/src/bus.lua')
|
|
|
|
parse_lua_file(root +'scripts/src/cpu.lua')
|
|
|
|
parse_lua_file(root +'scripts/src/machine.lua')
|
|
|
|
parse_lua_file(root +'scripts/src/sound.lua')
|
|
|
|
parse_lua_file(root +'scripts/src/video.lua')
|
2016-08-12 18:27:54 +02:00
|
|
|
parse_lua_file(root +'scripts/src/formats.lua')
|
2015-06-20 18:20:10 +02:00
|
|
|
|
|
|
|
for filename in sys.argv[2].rsplit(',') :
|
2015-06-20 16:35:49 +02:00
|
|
|
deps_files_included.append(filename.replace('\\','/'))
|
2015-06-20 18:20:10 +02:00
|
|
|
parse_file_for_deps(root,filename,'')
|
2015-06-20 16:35:49 +02:00
|
|
|
|
2015-06-20 16:40:08 +02:00
|
|
|
for filename in deps_files_included:
|
2015-06-20 18:20:10 +02:00
|
|
|
parse_file(root,filename,'')
|
2015-06-20 13:41:55 +02:00
|
|
|
|
2015-06-20 18:20:10 +02:00
|
|
|
for filename in sys.argv[2].rsplit(',') :
|
|
|
|
parse_file_for_drivers(root,filename)
|
2015-06-20 16:35:49 +02:00
|
|
|
|
|
|
|
# display output
|
2015-06-20 18:20:10 +02:00
|
|
|
if sys.argv[3]=='drivers':
|
2015-09-13 19:10:32 +02:00
|
|
|
#output the list of externs first
|
|
|
|
for drv in sorted(drivers):
|
2016-03-02 14:21:26 +01:00
|
|
|
print(drv)
|
2015-09-13 19:10:32 +02:00
|
|
|
print("")
|
2015-06-20 18:20:10 +02:00
|
|
|
|
|
|
|
if sys.argv[3]=='target':
|
2015-06-20 16:35:49 +02:00
|
|
|
for line in components:
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write("%s\n" % line)
|
2015-07-03 23:13:01 +02:00
|
|
|
sys.stdout.write('\n')
|
|
|
|
sys.stdout.write('function createProjects_mame_%s(_target, _subtarget)\n' % sys.argv[4])
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' project ("mame_%s")\n' % sys.argv[4])
|
|
|
|
sys.stdout.write(' targetsubdir(_target .."_" .. _subtarget)\n')
|
|
|
|
sys.stdout.write(' kind (LIBTYPE)\n')
|
|
|
|
sys.stdout.write(' uuid (os.uuid("drv-mame-%s"))\n' % sys.argv[4])
|
2018-03-15 16:53:23 +01:00
|
|
|
sys.stdout.write(' addprojectflags()\n')
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' \n')
|
|
|
|
sys.stdout.write(' includedirs {\n')
|
|
|
|
sys.stdout.write(' MAME_DIR .. "src/osd",\n')
|
|
|
|
sys.stdout.write(' MAME_DIR .. "src/emu",\n')
|
|
|
|
sys.stdout.write(' MAME_DIR .. "src/devices",\n')
|
|
|
|
sys.stdout.write(' MAME_DIR .. "src/mame",\n')
|
|
|
|
sys.stdout.write(' MAME_DIR .. "src/lib",\n')
|
|
|
|
sys.stdout.write(' MAME_DIR .. "src/lib/util",\n')
|
2016-01-06 10:40:43 +01:00
|
|
|
sys.stdout.write(' MAME_DIR .. "src/lib/netlist",\n')
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' MAME_DIR .. "3rdparty",\n')
|
2016-03-29 15:48:24 +02:00
|
|
|
sys.stdout.write(' GEN_DIR .. "mame/layout",\n')
|
2016-03-29 10:58:01 +02:00
|
|
|
sys.stdout.write(' ext_includedir("flac"),\n')
|
2018-02-10 22:58:29 +01:00
|
|
|
sys.stdout.write(' ext_includedir("glm"),\n')
|
|
|
|
sys.stdout.write(' ext_includedir("jpeg"),\n')
|
|
|
|
sys.stdout.write(' ext_includedir("rapidjson"),\n')
|
|
|
|
sys.stdout.write(' ext_includedir("zlib"),\n')
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' }\n')
|
2015-07-03 23:13:01 +02:00
|
|
|
sys.stdout.write('\n')
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' files{\n')
|
2015-06-20 16:35:49 +02:00
|
|
|
for line in deps_files_included:
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' MAME_DIR .. "%s",\n' % line)
|
|
|
|
sys.stdout.write(' }\n')
|
2015-07-03 23:13:01 +02:00
|
|
|
sys.stdout.write('end\n')
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
sys.stdout.write('function linkProjects_mame_%s(_target, _subtarget)\n' % sys.argv[4])
|
2015-09-13 19:10:32 +02:00
|
|
|
sys.stdout.write(' links {\n')
|
|
|
|
sys.stdout.write(' "mame_%s",\n' % sys.argv[4])
|
|
|
|
sys.stdout.write(' }\n')
|
2015-07-03 23:13:01 +02:00
|
|
|
sys.stdout.write('end\n')
|