blob: 964b69372a31217a77faa209bdd869df7931fa4d [file] [log] [blame]
Jack Jansen6c502d72000-12-03 22:31:50 +00001import mkcwproject
2import sys
3import os
Jack Jansenb55b7bb2001-01-03 16:44:56 +00004import string
Jack Jansen6c502d72000-12-03 22:31:50 +00005
Jack Jansenc70815a2002-06-26 22:06:08 +00006CARBON_ONLY=1
7
Jack Jansene791a642001-08-16 20:39:17 +00008PYTHONDIR = sys.prefix
9PROJECTDIR = os.path.join(PYTHONDIR, ":Mac:Build")
Jack Jansen6c502d72000-12-03 22:31:50 +000010MODULEDIRS = [ # Relative to projectdirs
11 "::Modules:%s",
12 "::Modules",
13 ":::Modules",
14]
15
Jack Jansen1eda2032001-01-21 22:24:27 +000016# Global variable to control forced rebuild (otherwise the project is only rebuilt
17# when it is changed)
18FORCEREBUILD=0
19
Jack Jansenb55b7bb2001-01-03 16:44:56 +000020def relpath(base, path):
21 """Turn abs path into path relative to another. Only works for 2 abs paths
22 both pointing to folders"""
23 if not os.path.isabs(base) or not os.path.isabs(path):
24 raise 'Absolute paths only'
Jack Jansen1eda2032001-01-21 22:24:27 +000025 if base[-1] == ':':
26 base = base[:-1]
Jack Jansenb55b7bb2001-01-03 16:44:56 +000027 basefields = string.split(base, os.sep)
28 pathfields = string.split(path, os.sep)
29 commonfields = len(os.path.commonprefix((basefields, pathfields)))
30 basefields = basefields[commonfields:]
31 pathfields = pathfields[commonfields:]
Jack Jansen1eda2032001-01-21 22:24:27 +000032 pathfields = ['']*(len(basefields)+1) + pathfields
33 rv = string.join(pathfields, os.sep)
34 return rv
Jack Jansenb55b7bb2001-01-03 16:44:56 +000035
Jack Jansen8c19b882001-01-23 22:36:26 +000036def genpluginproject(architecture, module,
Jack Jansen6c502d72000-12-03 22:31:50 +000037 project=None, projectdir=None,
38 sources=[], sourcedirs=[],
39 libraries=[], extradirs=[],
Jack Jansenb3be2162001-11-30 14:16:36 +000040 extraexportsymbols=[], outputdir=":::Lib:lib-dynload",
Jack Jansenb66e1a32002-05-23 22:34:18 +000041 libraryflags=None, stdlibraryflags=None, prefixname=None,
42 initialize=None):
Jack Jansenc70815a2002-06-26 22:06:08 +000043 if CARBON_ONLY and architecture == "ppc":
44 return
Jack Jansen8c19b882001-01-23 22:36:26 +000045 if architecture == "all":
46 # For the time being we generate two project files. Not as nice as
47 # a single multitarget project, but easier to implement for now.
48 genpluginproject("ppc", module, project, projectdir, sources, sourcedirs,
Jack Jansen9051e0e2002-03-22 14:15:07 +000049 libraries, extradirs, extraexportsymbols, outputdir, libraryflags,
Jack Jansenb66e1a32002-05-23 22:34:18 +000050 stdlibraryflags, prefixname, initialize)
Jack Jansen8c19b882001-01-23 22:36:26 +000051 genpluginproject("carbon", module, project, projectdir, sources, sourcedirs,
Jack Jansen9051e0e2002-03-22 14:15:07 +000052 libraries, extradirs, extraexportsymbols, outputdir, libraryflags,
Jack Jansenb66e1a32002-05-23 22:34:18 +000053 stdlibraryflags, prefixname, initialize)
Jack Jansen8c19b882001-01-23 22:36:26 +000054 return
55 templatename = "template-%s" % architecture
56 targetname = "%s.%s" % (module, architecture)
57 dllname = "%s.%s.slb" % (module, architecture)
Jack Jansen6c502d72000-12-03 22:31:50 +000058 if not project:
Jack Jansen8c19b882001-01-23 22:36:26 +000059 if architecture != "ppc":
60 project = "%s.%s.mcp"%(module, architecture)
61 else:
62 project = "%s.mcp"%module
Jack Jansen6c502d72000-12-03 22:31:50 +000063 if not projectdir:
64 projectdir = PROJECTDIR
65 if not sources:
66 sources = [module + 'module.c']
67 if not sourcedirs:
68 for moduledir in MODULEDIRS:
69 if '%' in moduledir:
Jack Jansen77105a92001-08-23 13:51:46 +000070 # For historical reasons an initial _ in the modulename
71 # is not reflected in the folder name
72 if module[0] == '_':
73 modulewithout_ = module[1:]
74 else:
75 modulewithout_ = module
76 moduledir = moduledir % modulewithout_
Jack Jansen6c502d72000-12-03 22:31:50 +000077 fn = os.path.join(projectdir, os.path.join(moduledir, sources[0]))
78 if os.path.exists(fn):
79 moduledir, sourcefile = os.path.split(fn)
Jack Jansen1eda2032001-01-21 22:24:27 +000080 sourcedirs = [relpath(projectdir, moduledir)]
Jack Jansen6c502d72000-12-03 22:31:50 +000081 sources[0] = sourcefile
82 break
83 else:
84 print "Warning: %s: sourcefile not found: %s"%(module, sources[0])
85 sourcedirs = []
Jack Jansen86c4d642002-03-14 23:14:43 +000086 if prefixname:
87 pass
88 elif architecture == "carbon":
Jack Jansenc70815a2002-06-26 22:06:08 +000089 prefixname = "mwerks_shcarbon_pch"
Jack Jansen8c19b882001-01-23 22:36:26 +000090 else:
91 prefixname = "mwerks_plugin_config.h"
Jack Jansen6c502d72000-12-03 22:31:50 +000092 dict = {
Jack Jansen1eda2032001-01-21 22:24:27 +000093 "sysprefix" : relpath(projectdir, sys.prefix),
Jack Jansen6c502d72000-12-03 22:31:50 +000094 "sources" : sources,
95 "extrasearchdirs" : sourcedirs + extradirs,
96 "libraries": libraries,
Jack Jansend39c2462001-08-19 22:29:57 +000097 "mac_outputdir" : outputdir,
Jack Jansen6c502d72000-12-03 22:31:50 +000098 "extraexportsymbols" : extraexportsymbols,
Jack Jansen8c19b882001-01-23 22:36:26 +000099 "mac_targetname" : targetname,
100 "mac_dllname" : dllname,
101 "prefixname" : prefixname,
Jack Jansen6c502d72000-12-03 22:31:50 +0000102 }
Jack Jansenb3be2162001-11-30 14:16:36 +0000103 if libraryflags:
104 dict['libraryflags'] = libraryflags
105 if stdlibraryflags:
106 dict['stdlibraryflags'] = stdlibraryflags
Jack Jansenb66e1a32002-05-23 22:34:18 +0000107 if initialize:
108 dict['initialize'] = initialize
Jack Jansen8c19b882001-01-23 22:36:26 +0000109 mkcwproject.mkproject(os.path.join(projectdir, project), module, dict,
110 force=FORCEREBUILD, templatename=templatename)
Jack Jansen6c502d72000-12-03 22:31:50 +0000111
Jack Jansen1eda2032001-01-21 22:24:27 +0000112def genallprojects(force=0):
113 global FORCEREBUILD
114 FORCEREBUILD = force
Jack Jansen6c502d72000-12-03 22:31:50 +0000115 # Standard Python modules
Jack Jansen86c4d642002-03-14 23:14:43 +0000116 genpluginproject("ppc", "pyexpat",
117 sources=["pyexpat.c", "xmlparse.c", "xmlrole.c", "xmltok.c"],
118 extradirs=[":::Modules:expat"],
Jack Jansenc70815a2002-06-26 22:06:08 +0000119 prefixname="mwerks_shared_config.h"
Jack Jansen86c4d642002-03-14 23:14:43 +0000120 )
121 genpluginproject("carbon", "pyexpat",
122 sources=["pyexpat.c", "xmlparse.c", "xmlrole.c", "xmltok.c"],
123 extradirs=[":::Modules:expat"],
Jack Jansenc70815a2002-06-26 22:06:08 +0000124 prefixname="mwerks_shcarbon_config.h"
Jack Jansen86c4d642002-03-14 23:14:43 +0000125 )
Jack Jansen8c19b882001-01-23 22:36:26 +0000126 genpluginproject("all", "zlib",
Jack Jansen6c502d72000-12-03 22:31:50 +0000127 libraries=["zlib.ppc.Lib"],
128 extradirs=["::::imglibs:zlib:mac", "::::imglibs:zlib"])
Jack Jansen8c19b882001-01-23 22:36:26 +0000129 genpluginproject("all", "gdbm",
Jack Jansen6c502d72000-12-03 22:31:50 +0000130 libraries=["gdbm.ppc.gusi.lib"],
131 extradirs=["::::gdbm:mac", "::::gdbm"])
Jack Jansen6e271182001-02-12 14:50:52 +0000132 genpluginproject("all", "_weakref", sources=["_weakref.c"])
133 genpluginproject("all", "_symtable", sources=["symtablemodule.c"])
Jack Jansen7c100082001-08-29 22:08:06 +0000134 # Example/test modules
Jack Jansen6e271182001-02-12 14:50:52 +0000135 genpluginproject("all", "_testcapi")
Jack Jansen7c100082001-08-29 22:08:06 +0000136 genpluginproject("all", "xx")
137 genpluginproject("all", "xxsubtype", sources=["xxsubtype.c"])
Jack Jansen6f1da002001-10-23 22:23:44 +0000138 genpluginproject("all", "_hotshot", sources=["_hotshot.c"])
Jack Jansen6c502d72000-12-03 22:31:50 +0000139
140 # bgen-generated Toolbox modules
Jack Jansen77105a92001-08-23 13:51:46 +0000141 genpluginproject("carbon", "_AE", outputdir="::Lib:Carbon")
Jack Jansen25a8f0d2002-09-06 22:59:00 +0000142 genpluginproject("carbon", "_AH", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000143 genpluginproject("ppc", "_AE", libraries=["ObjectSupportLib"],
144 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansena7594db2001-12-05 22:46:23 +0000145 genpluginproject("ppc", "_App", libraries=["CarbonAccessors.o", "AppearanceLib"],
146 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000147 genpluginproject("carbon", "_App", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000148 genpluginproject("ppc", "_Cm", libraries=["QuickTimeLib"],
149 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000150 genpluginproject("carbon", "_Cm", outputdir="::Lib:Carbon")
Just van Rossum11ccf3c2001-12-13 13:21:38 +0000151 # XXX can't work properly because we need to set a custom fragment initializer
152 #genpluginproject("carbon", "_CG",
153 # sources=["_CGModule.c", "CFMLateImport.c"],
154 # libraries=["CGStubLib"],
155 # outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000156 genpluginproject("carbon", "_Ctl", outputdir="::Lib:Carbon")
Jack Jansena7594db2001-12-05 22:46:23 +0000157 genpluginproject("ppc", "_Ctl", libraries=["CarbonAccessors.o", "ControlsLib", "AppearanceLib"],
Jack Jansenb3be2162001-11-30 14:16:36 +0000158 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000159 genpluginproject("carbon", "_Dlg", outputdir="::Lib:Carbon")
Jack Jansena7594db2001-12-05 22:46:23 +0000160 genpluginproject("ppc", "_Dlg", libraries=["CarbonAccessors.o", "DialogsLib", "AppearanceLib"],
Jack Jansenb3be2162001-11-30 14:16:36 +0000161 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000162 genpluginproject("carbon", "_Drag", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000163 genpluginproject("ppc", "_Drag", libraries=["DragLib"],
164 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
165 genpluginproject("all", "_Evt",
166 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
167 genpluginproject("all", "_Fm",
168 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen25a8f0d2002-09-06 22:59:00 +0000169 genpluginproject("ppc", "_Help", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000170 genpluginproject("ppc", "_Icn", libraries=["IconServicesLib"],
171 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen3bd3fed2002-08-05 14:12:24 +0000172 genpluginproject("carbon", "_IBCarbon", sources=[":ibcarbon:_IBCarbon.c"],
173 outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000174 genpluginproject("carbon", "_Icn", outputdir="::Lib:Carbon")
175 genpluginproject("all", "_List", outputdir="::Lib:Carbon")
176 genpluginproject("carbon", "_Menu", outputdir="::Lib:Carbon")
Jack Jansena7594db2001-12-05 22:46:23 +0000177 genpluginproject("ppc", "_Menu", libraries=["CarbonAccessors.o", "MenusLib", "ContextualMenu", "AppearanceLib"],
Jack Jansenb3be2162001-11-30 14:16:36 +0000178 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000179 genpluginproject("all", "_Qd",
180 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
181 genpluginproject("ppc", "_Qt", libraries=["QuickTimeLib"],
182 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
183 genpluginproject("carbon", "_Qt",
184 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
185 genpluginproject("all", "_Qdoffs",
186 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen9051e0e2002-03-22 14:15:07 +0000187 genpluginproject("all", "_Res",
188 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000189 genpluginproject("all", "_Scrap", outputdir="::Lib:Carbon")
Jack Jansena7594db2001-12-05 22:46:23 +0000190 genpluginproject("ppc", "_Snd", libraries=["CarbonAccessors.o", "SoundLib"], outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000191 genpluginproject("carbon", "_Snd", outputdir="::Lib:Carbon")
192 genpluginproject("all", "_Sndihooks", sources=[":snd:_Sndihooks.c"], outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000193 genpluginproject("ppc", "_TE", libraries=["CarbonAccessors.o", "DragLib"],
194 stdlibraryflags="Debug, WeakImport",
195 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000196 genpluginproject("carbon", "_TE", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000197 genpluginproject("ppc", "_Mlte", libraries=["Textension"],
198 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000199 genpluginproject("carbon", "_Mlte", outputdir="::Lib:Carbon")
200 genpluginproject("carbon", "_Win", outputdir="::Lib:Carbon")
Jack Jansenb3be2162001-11-30 14:16:36 +0000201 genpluginproject("ppc", "_Win", libraries=["CarbonAccessors.o", "WindowsLib", "AppearanceLib"],
202 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen19864122001-07-13 20:57:47 +0000203 # Carbon Only?
Jack Jansen66e794d2002-07-22 12:32:31 +0000204 genpluginproject("carbon", "_CF", sources=["_CFmodule.c", "pycfbridge.c"], outputdir="::Lib:Carbon")
Just van Rossumaa6e83f2001-12-12 22:42:37 +0000205 genpluginproject("carbon", "_CarbonEvt", outputdir="::Lib:Carbon")
Jack Jansendf222d22001-11-06 15:56:56 +0000206 genpluginproject("carbon", "hfsplus")
Jack Jansenf4b9fb72001-06-26 21:52:08 +0000207
Jack Jansen6c502d72000-12-03 22:31:50 +0000208 # Other Mac modules
Jack Jansen8c19b882001-01-23 22:36:26 +0000209 genpluginproject("all", "calldll", sources=["calldll.c"])
210 genpluginproject("all", "ColorPicker")
211 genpluginproject("ppc", "Printing")
Jack Jansen4a667c72002-01-11 12:39:03 +0000212## genpluginproject("ppc", "waste",
213## sources=[
214## "wastemodule.c",
215## 'WEAccessors.c', 'WEBirthDeath.c', 'WEDebug.c',
216## 'WEDrawing.c', 'WEFontTables.c', 'WEHighLevelEditing.c',
217## 'WEICGlue.c', 'WEInlineInput.c', 'WELineLayout.c', 'WELongCoords.c',
218## 'WELowLevelEditing.c', 'WEMouse.c', 'WEObjects.c', 'WEScraps.c',
219## 'WESelecting.c', 'WESelectors.c', 'WEUserSelectors.c', 'WEUtilities.c',
220## 'WEObjectHandlers.c',
221## 'WETabs.c',
222## 'WETabHooks.c'],
223## libraries=['DragLib'],
224## extradirs=[
225## '::::Waste 1.3 Distribution:*',
226## '::::ICProgKit1.4:APIs']
227## )
228 # This is a hack, combining parts of Waste 2.0 with parts of 1.3
Jack Jansen8c19b882001-01-23 22:36:26 +0000229 genpluginproject("ppc", "waste",
Jack Jansen6c502d72000-12-03 22:31:50 +0000230 sources=[
231 "wastemodule.c",
Jack Jansen4a667c72002-01-11 12:39:03 +0000232 "WEObjectHandlers.c",
233 "WETabs.c", "WETabHooks.c"],
234 libraries=[
235 "WASTE.PPC.lib",
236 "TextCommon",
237 "UnicodeConverter",
238 "DragLib",
239 ],
Jack Jansen0e1c24a2001-01-22 14:50:05 +0000240 extradirs=[
Jack Jansen4a667c72002-01-11 12:39:03 +0000241 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
242 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
243 '::wastemods',
244 ]
Jack Jansen6c502d72000-12-03 22:31:50 +0000245 )
Jack Jansen8c982662001-01-24 16:02:07 +0000246 genpluginproject("carbon", "waste",
247 sources=[
248 "wastemodule.c",
249 "WEObjectHandlers.c",
250 "WETabs.c", "WETabHooks.c"],
251 libraries=["WASTE.Carbon.lib"],
252 extradirs=[
253 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
254 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
Jack Jansen4a667c72002-01-11 12:39:03 +0000255 '::wastemods',
256 ]
Jack Jansen8c982662001-01-24 16:02:07 +0000257 )
Jack Jansen4a667c72002-01-11 12:39:03 +0000258## '::::Waste 1.3 Distribution:Extras:Sample Object Handlers',
259## '::::Waste 1.3 Distribution:Extras:Waste Tabs 1.3.2']
Jack Jansen8c19b882001-01-23 22:36:26 +0000260 genpluginproject("ppc", "ctb")
261 genpluginproject("ppc", "icglue", sources=["icgluemodule.c"],
Jack Jansen4a667c72002-01-11 12:39:03 +0000262 libraries=["InternetConfigLib"])
263 genpluginproject("carbon", "icglue", sources=["icgluemodule.c"])
Jack Jansen8c19b882001-01-23 22:36:26 +0000264 genpluginproject("ppc", "macspeech", libraries=["SpeechLib"])
Jack Jansen6c502d72000-12-03 22:31:50 +0000265
266if __name__ == '__main__':
267 genallprojects()
268
Jack Jansen1eda2032001-01-21 22:24:27 +0000269