2013-08-22 11:49:34 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import cStringIO
|
2013-08-22 16:45:40 +08:00
|
|
|
import re
|
2013-08-22 11:49:34 +08:00
|
|
|
|
2013-10-29 22:53:01 +08:00
|
|
|
def get_cur_dir():
|
|
|
|
path = sys.path[0]
|
|
|
|
if os.path.isdir(path):
|
|
|
|
return path
|
|
|
|
elif os.path.isfile(path):
|
|
|
|
return os.path.dirname(path)
|
|
|
|
|
|
|
|
CUR_DIR = get_cur_dir()
|
|
|
|
COCOS_ROOT = os.path.abspath(os.path.join(CUR_DIR, "../../"))
|
|
|
|
CONFIG = os.path.abspath(os.path.join(CUR_DIR, "./config.py"))
|
2013-10-30 16:44:21 +08:00
|
|
|
# print 'CONFIG:' + CONFIG
|
|
|
|
# print 'COCOS_ROOT:' + COCOS_ROOT
|
2013-10-29 22:53:01 +08:00
|
|
|
|
2013-08-22 13:40:57 +08:00
|
|
|
try:
|
|
|
|
import PathUtils
|
|
|
|
except ImportError, e:
|
2013-10-29 22:53:01 +08:00
|
|
|
sys.path.append(os.path.abspath(os.path.join(CUR_DIR, "../pylib")))
|
2013-08-22 13:40:57 +08:00
|
|
|
import PathUtils
|
2013-08-22 11:49:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-22 16:45:40 +08:00
|
|
|
def gen_android_mk(mkfile, pathes, suffix = ("c", "cpp",), exclude = ()):
|
|
|
|
utils = PathUtils.PathUtils(COCOS_ROOT)
|
2013-08-22 11:49:34 +08:00
|
|
|
filelst = utils.find_files(pathes, suffix, exclude)
|
|
|
|
|
2013-08-22 16:45:40 +08:00
|
|
|
# generate file list string
|
|
|
|
filestrio = cStringIO.StringIO()
|
2013-11-15 18:05:24 +08:00
|
|
|
mkfilepath = os.path.dirname(os.path.join(COCOS_ROOT, mkfile))
|
2013-08-22 11:49:34 +08:00
|
|
|
for filename in filelst:
|
2013-08-22 16:45:40 +08:00
|
|
|
filestrio.write(' \\\n')
|
2013-11-15 18:05:24 +08:00
|
|
|
filepath = os.path.relpath(filename, mkfilepath)
|
|
|
|
filestrio.write(filepath.replace('\\', '/'))
|
2013-08-22 16:45:40 +08:00
|
|
|
filestrio.write('\n')
|
|
|
|
|
|
|
|
# read mk file
|
|
|
|
file = open(os.path.join(COCOS_ROOT, mkfile))
|
|
|
|
mkstrio = cStringIO.StringIO()
|
|
|
|
rep = re.compile("\s*LOCAL_SRC_FILES\s*:=")
|
|
|
|
try:
|
|
|
|
# read lines before encounter "LOCAL_EXPORT_C_INCLUDES"
|
|
|
|
for line in file:
|
|
|
|
if rep.match(line):
|
|
|
|
mkstrio.write("LOCAL_SRC_FILES :=")
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
mkstrio.write(line)
|
|
|
|
#mkstrio.write('\n')
|
|
|
|
|
|
|
|
# write file list
|
|
|
|
mkstrio.write(filestrio.getvalue())
|
|
|
|
|
|
|
|
# write remaining lines
|
|
|
|
delete = True if line[len(line) - 2] == '\\' else False
|
|
|
|
for line in file:
|
|
|
|
if delete:
|
|
|
|
delete = True if line[len(line) - 2] == '\\' else False
|
|
|
|
else:
|
|
|
|
mkstrio.write(line)
|
|
|
|
#mkstrio.write('\n')
|
|
|
|
finally:
|
|
|
|
file.close()
|
|
|
|
|
2013-08-22 11:49:34 +08:00
|
|
|
|
|
|
|
|
2013-08-22 16:45:40 +08:00
|
|
|
file = open(os.path.join(COCOS_ROOT, mkfile), "w")
|
|
|
|
file.write(mkstrio.getvalue())
|
2013-08-22 11:49:34 +08:00
|
|
|
file.close()
|
|
|
|
|
2013-08-22 16:45:40 +08:00
|
|
|
filestrio.close()
|
|
|
|
mkstrio.close()
|
2013-08-22 11:49:34 +08:00
|
|
|
|
|
|
|
def main():
|
2013-10-29 22:53:01 +08:00
|
|
|
config = open(CONFIG)
|
2013-08-22 16:45:40 +08:00
|
|
|
params = eval(config.read())
|
|
|
|
config.close()
|
|
|
|
|
|
|
|
for param in params:
|
|
|
|
gen_android_mk(**param)
|
2013-08-22 11:49:34 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-10-30 16:44:21 +08:00
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
|
|
|
|
parser.add_option('-c', '--config',
|
|
|
|
type='string',
|
|
|
|
dest='config',
|
|
|
|
help="config file path.")
|
|
|
|
|
|
|
|
parser.add_option('-r', '--rootpath',
|
|
|
|
action='store',
|
|
|
|
dest='rootpath',
|
|
|
|
help='class root path for mkfile, pathes, exclude.')
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if options.config:
|
|
|
|
CONFIG = os.path.abspath(os.path.join(os.curdir, options.config))
|
|
|
|
|
|
|
|
if options.rootpath:
|
|
|
|
COCOS_ROOT = os.path.abspath(os.path.join(os.curdir, options.rootpath))
|
|
|
|
|
|
|
|
# print 'CONFIG:', CONFIG
|
|
|
|
# print 'COCOS_ROOT:', COCOS_ROOT
|
|
|
|
|
|
|
|
error = ''
|
|
|
|
if not os.path.isfile(CONFIG):
|
|
|
|
error+='config must be file.\n'
|
|
|
|
|
|
|
|
if not os.path.isdir(COCOS_ROOT):
|
|
|
|
error+='rootpath must be directory.\n'
|
|
|
|
|
|
|
|
if error != '':
|
|
|
|
parser.exit(2, "{exception}".format(exception=error))
|
|
|
|
|
|
|
|
sys.exit(main())
|