1 # First attempt at automatically generating CodeWarior projects
6 Error
="gencwproject.Error"
8 # These templates are executed in-order.
11 ("tmp_allsources", "file", "template-allsources.xml", "sources"),
12 ("tmp_linkorder", "file", "template-linkorder.xml", "sources"),
13 ("tmp_grouplist", "file", "template-grouplist.xml", "sources"),
14 ("tmp_alllibraries", "file", "template-alllibraries.xml", "libraries"),
15 ("tmp_linkorderlib", "file", "template-linkorderlib.xml", "libraries"),
16 ("tmp_grouplistlib", "file", "template-grouplistlib.xml", "libraries"),
17 ("tmp_extrasearchdirs", "file", "template-searchdirs.xml", "extrasearchdirs"),
18 ("tmp_projectxmldata", "file", "template.prj.xml", None)
22 def __init__(self
, dict, templatelist
=TEMPLATELIST
, templatename
=None):
23 self
._adddefaults
(dict)
24 if templatename
== None:
25 if hasattr(MacOS
, 'runtimemodel'):
26 templatename
= 'template-%s'%MacOS
.runtimemodel
28 templatename
= 'template'
29 if os
.sep
in templatename
:
30 templatedir
= templatename
33 packagedir
= os
.path
.split(__file__
)[0]
35 packagedir
= os
.curdir
36 templatedir
= os
.path
.join(packagedir
, templatename
)
37 if not os
.path
.exists(templatedir
):
38 raise Error
, "Cannot find templatedir %s"%templatedir
40 if not dict.has_key('prefixname'):
41 if hasattr(MacOS
, 'runtimemodel') and MacOS
.runtimemodel
== "carbon":
42 dict['prefixname'] = 'mwerks_carbonplugin_config.h'
44 dict['prefixname'] = 'mwerks_plugin_config.h'
45 self
.templatelist
= templatelist
46 self
.templatedir
= templatedir
48 def _adddefaults(self
, dict):
49 # Set all suitable defaults set for values which were omitted.
50 if not dict.has_key('mac_outputdir'):
51 dict['mac_outputdir'] = ':lib:'
52 if not dict.has_key('stdlibraryflags'):
53 dict['stdlibraryflags'] = 'Debug'
54 if not dict.has_key('libraryflags'):
55 dict['libraryflags'] = 'Debug'
56 if not dict.has_key('mac_sysprefixtype'):
57 if os
.path
.isabs(dict['sysprefix']):
58 dict['mac_sysprefixtype'] = 'Absolute'
60 dict['mac_sysprefixtype'] = 'Project' # XXX not sure this is right...
63 for tmpl
in self
.templatelist
:
64 self
._generate
_one
_template
(tmpl
)
66 def _generate_one_template(self
, tmpl
):
67 resultname
, datasource
, dataname
, key
= tmpl
70 # This is a multi-element rule. Run for every item in dict[key]
71 if self
.dict.has_key(key
):
72 keyvalues
= self
.dict[key
]
74 if not type(keyvalues
) in (type(()), type([])):
75 raise Error
, "List or tuple expected for %s"%key
76 for curkeyvalue
in keyvalues
:
77 if string
.lower(curkeyvalue
[:10]) == '{compiler}':
78 curkeyvalue
= curkeyvalue
[10:]
79 self
.dict['pathtype'] = 'CodeWarrior'
80 elif string
.lower(curkeyvalue
[:9]) == '{project}':
81 curkeyvalue
= curkeyvalue
[9:]
82 self
.dict['pathtype'] = 'Project'
83 elif curkeyvalue
[0] == '{':
84 raise Error
, "Unknown {} escape in %s"%curkeyvalue
85 elif os
.path
.isabs(curkeyvalue
):
86 self
.dict['pathtype'] = 'Absolute'
88 self
.dict['pathtype'] = 'Project'
89 if curkeyvalue
[-2:] == ':*':
90 curkeyvalue
= curkeyvalue
[:-2]
91 self
.dict['recursive'] = 'true'
93 self
.dict['recursive'] = 'false'
94 self
.dict[key
] = curkeyvalue
95 curkeyvalueresult
= self
._generate
_one
_value
(datasource
, dataname
)
96 result
= result
+ curkeyvalueresult
99 self
.dict[key
] = keyvalues
100 self
.dict['pathtype'] = None
101 del self
.dict['pathtype']
102 self
.dict['recursive'] = None
103 del self
.dict['recursive']
105 # Not a multi-element rule. Simply generate
106 result
= self
._generate
_one
_value
(datasource
, dataname
)
107 # And store the result
108 self
.dict[resultname
] = result
110 def _generate_one_value(self
, datasource
, dataname
):
111 if datasource
== 'file':
112 filepath
= os
.path
.join(self
.templatedir
, dataname
)
113 fp
= open(filepath
, "r")
115 elif datasource
== 'string':
118 raise Error
, 'Datasource should be file or string, not %s'%datasource
119 return format
% self
.dict
123 "mac_projectxmlname" : "controlstrip.prj.xml", # The XML filename (full path)
124 "mac_exportname" : "controlstrip.prj.exp", # Export file (relative to project)
125 "mac_outputdir" : ":", # The directory where the DLL is put (relative to project)
126 "mac_dllname" : "controlstrip.ppc.slb", # The DLL filename (within outputdir)
127 "mac_targetname" : "controlstrip.ppc", # The targetname within the project
128 "sysprefix" : sys
.prefix
, # Where the Python sources live
129 "mac_sysprefixtype" : "Absolute", # Type of previous pathname
130 "sources" : ["controlstripmodule.c"],
131 "extrasearchdirs": [], # -I and -L, in unix terms
133 pb
= ProjectBuilder(dict)
135 fp
= open(dict["mac_projectxmlname"], "w")
136 fp
.write(dict["tmp_projectxmldata"])
138 if __name__
== '__main__':