2000-09-15 19:44:08 -03:00
|
|
|
# First attempt at automatically generating CodeWarior projects
|
|
|
|
import os
|
2001-01-23 18:34:50 -04:00
|
|
|
import MacOS
|
2001-01-24 12:04:50 -04:00
|
|
|
import string
|
2000-09-15 19:44:08 -03:00
|
|
|
|
|
|
|
Error="gencwproject.Error"
|
|
|
|
#
|
|
|
|
# These templates are executed in-order.
|
|
|
|
#
|
|
|
|
TEMPLATELIST= [
|
|
|
|
("tmp_allsources", "file", "template-allsources.xml", "sources"),
|
|
|
|
("tmp_linkorder", "file", "template-linkorder.xml", "sources"),
|
|
|
|
("tmp_grouplist", "file", "template-grouplist.xml", "sources"),
|
2000-11-26 19:02:38 -04:00
|
|
|
("tmp_alllibraries", "file", "template-alllibraries.xml", "libraries"),
|
|
|
|
("tmp_linkorderlib", "file", "template-linkorderlib.xml", "libraries"),
|
|
|
|
("tmp_grouplistlib", "file", "template-grouplistlib.xml", "libraries"),
|
2000-09-22 20:26:55 -03:00
|
|
|
("tmp_extrasearchdirs", "file", "template-searchdirs.xml", "extrasearchdirs"),
|
2000-09-15 19:44:08 -03:00
|
|
|
("tmp_projectxmldata", "file", "template.prj.xml", None)
|
|
|
|
]
|
|
|
|
|
|
|
|
class ProjectBuilder:
|
2001-01-23 18:34:50 -04:00
|
|
|
def __init__(self, dict, templatelist=TEMPLATELIST, templatename=None):
|
2001-12-14 10:31:15 -04:00
|
|
|
self._adddefaults(dict)
|
2001-01-23 18:34:50 -04:00
|
|
|
if templatename == None:
|
|
|
|
if hasattr(MacOS, 'runtimemodel'):
|
|
|
|
templatename = 'template-%s'%MacOS.runtimemodel
|
|
|
|
else:
|
|
|
|
templatename = 'template'
|
|
|
|
if os.sep in templatename:
|
|
|
|
templatedir = templatename
|
|
|
|
else:
|
2000-09-15 19:44:08 -03:00
|
|
|
try:
|
|
|
|
packagedir = os.path.split(__file__)[0]
|
|
|
|
except NameError:
|
|
|
|
packagedir = os.curdir
|
2001-01-23 18:34:50 -04:00
|
|
|
templatedir = os.path.join(packagedir, templatename)
|
2000-09-15 19:44:08 -03:00
|
|
|
if not os.path.exists(templatedir):
|
2001-01-23 18:34:50 -04:00
|
|
|
raise Error, "Cannot find templatedir %s"%templatedir
|
2000-09-15 19:44:08 -03:00
|
|
|
self.dict = dict
|
2000-11-26 19:02:38 -04:00
|
|
|
if not dict.has_key('prefixname'):
|
2001-08-11 07:07:23 -03:00
|
|
|
if hasattr(MacOS, 'runtimemodel') and MacOS.runtimemodel == "carbon":
|
|
|
|
dict['prefixname'] = 'mwerks_carbonplugin_config.h'
|
|
|
|
else:
|
|
|
|
dict['prefixname'] = 'mwerks_plugin_config.h'
|
2000-09-15 19:44:08 -03:00
|
|
|
self.templatelist = templatelist
|
|
|
|
self.templatedir = templatedir
|
2001-12-14 10:31:15 -04:00
|
|
|
|
|
|
|
def _adddefaults(self, dict):
|
|
|
|
# Set all suitable defaults set for values which were omitted.
|
|
|
|
if not dict.has_key('mac_outputdir'):
|
|
|
|
dict['mac_outputdir'] = ':lib:'
|
|
|
|
if not dict.has_key('stdlibraryflags'):
|
|
|
|
dict['stdlibraryflags'] = 'Debug'
|
|
|
|
if not dict.has_key('libraryflags'):
|
|
|
|
dict['libraryflags'] = 'Debug'
|
2002-05-23 19:34:18 -03:00
|
|
|
if not dict.has_key('initialize'):
|
|
|
|
dict['initialize'] = '__initialize'
|
2001-12-14 10:31:15 -04:00
|
|
|
if not dict.has_key('mac_sysprefixtype'):
|
|
|
|
if os.path.isabs(dict['sysprefix']):
|
|
|
|
dict['mac_sysprefixtype'] = 'Absolute'
|
|
|
|
else:
|
|
|
|
dict['mac_sysprefixtype'] = 'Project' # XXX not sure this is right...
|
2000-09-15 19:44:08 -03:00
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
for tmpl in self.templatelist:
|
|
|
|
self._generate_one_template(tmpl)
|
|
|
|
|
|
|
|
def _generate_one_template(self, tmpl):
|
|
|
|
resultname, datasource, dataname, key = tmpl
|
|
|
|
result = ''
|
|
|
|
if key:
|
|
|
|
# This is a multi-element rule. Run for every item in dict[key]
|
|
|
|
if self.dict.has_key(key):
|
|
|
|
keyvalues = self.dict[key]
|
|
|
|
try:
|
|
|
|
if not type(keyvalues) in (type(()), type([])):
|
|
|
|
raise Error, "List or tuple expected for %s"%key
|
|
|
|
for curkeyvalue in keyvalues:
|
2001-01-24 12:04:50 -04:00
|
|
|
if string.lower(curkeyvalue[:10]) == '{compiler}':
|
|
|
|
curkeyvalue = curkeyvalue[10:]
|
|
|
|
self.dict['pathtype'] = 'CodeWarrior'
|
|
|
|
elif string.lower(curkeyvalue[:9]) == '{project}':
|
|
|
|
curkeyvalue = curkeyvalue[9:]
|
|
|
|
self.dict['pathtype'] = 'Project'
|
|
|
|
elif curkeyvalue[0] == '{':
|
|
|
|
raise Error, "Unknown {} escape in %s"%curkeyvalue
|
|
|
|
elif os.path.isabs(curkeyvalue):
|
2000-11-26 19:02:38 -04:00
|
|
|
self.dict['pathtype'] = 'Absolute'
|
|
|
|
else:
|
|
|
|
self.dict['pathtype'] = 'Project'
|
2000-12-03 18:38:34 -04:00
|
|
|
if curkeyvalue[-2:] == ':*':
|
|
|
|
curkeyvalue = curkeyvalue[:-2]
|
|
|
|
self.dict['recursive'] = 'true'
|
|
|
|
else:
|
|
|
|
self.dict['recursive'] = 'false'
|
|
|
|
self.dict[key] = curkeyvalue
|
2000-09-15 19:44:08 -03:00
|
|
|
curkeyvalueresult = self._generate_one_value(datasource, dataname)
|
|
|
|
result = result + curkeyvalueresult
|
|
|
|
finally:
|
|
|
|
# Restore the list
|
|
|
|
self.dict[key] = keyvalues
|
2000-11-26 19:02:38 -04:00
|
|
|
self.dict['pathtype'] = None
|
|
|
|
del self.dict['pathtype']
|
2000-12-03 18:38:34 -04:00
|
|
|
self.dict['recursive'] = None
|
|
|
|
del self.dict['recursive']
|
2000-09-15 19:44:08 -03:00
|
|
|
else:
|
|
|
|
# Not a multi-element rule. Simply generate
|
|
|
|
result = self._generate_one_value(datasource, dataname)
|
|
|
|
# And store the result
|
|
|
|
self.dict[resultname] = result
|
|
|
|
|
|
|
|
def _generate_one_value(self, datasource, dataname):
|
|
|
|
if datasource == 'file':
|
|
|
|
filepath = os.path.join(self.templatedir, dataname)
|
|
|
|
fp = open(filepath, "r")
|
|
|
|
format = fp.read()
|
|
|
|
elif datasource == 'string':
|
|
|
|
format = dataname
|
|
|
|
else:
|
|
|
|
raise Error, 'Datasource should be file or string, not %s'%datasource
|
|
|
|
return format % self.dict
|
|
|
|
|
|
|
|
def _test():
|
|
|
|
dict = {
|
2000-09-22 20:26:55 -03:00
|
|
|
"mac_projectxmlname" : "controlstrip.prj.xml", # The XML filename (full path)
|
|
|
|
"mac_exportname" : "controlstrip.prj.exp", # Export file (relative to project)
|
|
|
|
"mac_outputdir" : ":", # The directory where the DLL is put (relative to project)
|
|
|
|
"mac_dllname" : "controlstrip.ppc.slb", # The DLL filename (within outputdir)
|
|
|
|
"mac_targetname" : "controlstrip.ppc", # The targetname within the project
|
|
|
|
"sysprefix" : sys.prefix, # Where the Python sources live
|
|
|
|
"mac_sysprefixtype" : "Absolute", # Type of previous pathname
|
|
|
|
"sources" : ["controlstripmodule.c"],
|
|
|
|
"extrasearchdirs": [], # -I and -L, in unix terms
|
2000-09-15 19:44:08 -03:00
|
|
|
}
|
|
|
|
pb = ProjectBuilder(dict)
|
|
|
|
pb.generate()
|
|
|
|
fp = open(dict["mac_projectxmlname"], "w")
|
|
|
|
fp.write(dict["tmp_projectxmldata"])
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
_test()
|
|
|
|
|