blob: 03ce54f65dd5a4713ae6bf35fd3de89c6bdcaca2 [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 Jansene791a642001-08-16 20:39:17 +00006PYTHONDIR = sys.prefix
7PROJECTDIR = os.path.join(PYTHONDIR, ":Mac:Build")
Jack Jansen6c502d72000-12-03 22:31:50 +00008MODULEDIRS = [ # Relative to projectdirs
9 "::Modules:%s",
10 "::Modules",
11 ":::Modules",
12]
13
Jack Jansen1eda2032001-01-21 22:24:27 +000014# Global variable to control forced rebuild (otherwise the project is only rebuilt
15# when it is changed)
16FORCEREBUILD=0
17
Jack Jansenb55b7bb2001-01-03 16:44:56 +000018def relpath(base, path):
19 """Turn abs path into path relative to another. Only works for 2 abs paths
20 both pointing to folders"""
21 if not os.path.isabs(base) or not os.path.isabs(path):
22 raise 'Absolute paths only'
Jack Jansen1eda2032001-01-21 22:24:27 +000023 if base[-1] == ':':
24 base = base[:-1]
Jack Jansenb55b7bb2001-01-03 16:44:56 +000025 basefields = string.split(base, os.sep)
26 pathfields = string.split(path, os.sep)
27 commonfields = len(os.path.commonprefix((basefields, pathfields)))
28 basefields = basefields[commonfields:]
29 pathfields = pathfields[commonfields:]
Jack Jansen1eda2032001-01-21 22:24:27 +000030 pathfields = ['']*(len(basefields)+1) + pathfields
31 rv = string.join(pathfields, os.sep)
32 return rv
Jack Jansenb55b7bb2001-01-03 16:44:56 +000033
Jack Jansen8c19b882001-01-23 22:36:26 +000034def genpluginproject(architecture, module,
Jack Jansen6c502d72000-12-03 22:31:50 +000035 project=None, projectdir=None,
36 sources=[], sourcedirs=[],
37 libraries=[], extradirs=[],
Jack Jansenb3be2162001-11-30 14:16:36 +000038 extraexportsymbols=[], outputdir=":::Lib:lib-dynload",
Jack Jansenb66e1a32002-05-23 22:34:18 +000039 libraryflags=None, stdlibraryflags=None, prefixname=None,
40 initialize=None):
Jack Jansen9ea729c2002-12-13 23:34:03 +000041 if architecture != "carbon":
42 raise 'Unsupported architecture: %s'%architecture
Jack Jansen8c19b882001-01-23 22:36:26 +000043 templatename = "template-%s" % architecture
44 targetname = "%s.%s" % (module, architecture)
45 dllname = "%s.%s.slb" % (module, architecture)
Jack Jansen6c502d72000-12-03 22:31:50 +000046 if not project:
Jack Jansen9ea729c2002-12-13 23:34:03 +000047 project = "%s.%s.mcp"%(module, architecture)
Jack Jansen6c502d72000-12-03 22:31:50 +000048 if not projectdir:
49 projectdir = PROJECTDIR
50 if not sources:
51 sources = [module + 'module.c']
52 if not sourcedirs:
53 for moduledir in MODULEDIRS:
54 if '%' in moduledir:
Jack Jansen77105a92001-08-23 13:51:46 +000055 # For historical reasons an initial _ in the modulename
56 # is not reflected in the folder name
57 if module[0] == '_':
58 modulewithout_ = module[1:]
59 else:
60 modulewithout_ = module
61 moduledir = moduledir % modulewithout_
Jack Jansen6c502d72000-12-03 22:31:50 +000062 fn = os.path.join(projectdir, os.path.join(moduledir, sources[0]))
63 if os.path.exists(fn):
64 moduledir, sourcefile = os.path.split(fn)
Jack Jansen1eda2032001-01-21 22:24:27 +000065 sourcedirs = [relpath(projectdir, moduledir)]
Jack Jansen6c502d72000-12-03 22:31:50 +000066 sources[0] = sourcefile
67 break
68 else:
69 print "Warning: %s: sourcefile not found: %s"%(module, sources[0])
70 sourcedirs = []
Jack Jansen86c4d642002-03-14 23:14:43 +000071 if prefixname:
72 pass
73 elif architecture == "carbon":
Jack Jansenc70815a2002-06-26 22:06:08 +000074 prefixname = "mwerks_shcarbon_pch"
Jack Jansen8c19b882001-01-23 22:36:26 +000075 else:
76 prefixname = "mwerks_plugin_config.h"
Jack Jansen6c502d72000-12-03 22:31:50 +000077 dict = {
Jack Jansen1eda2032001-01-21 22:24:27 +000078 "sysprefix" : relpath(projectdir, sys.prefix),
Jack Jansen6c502d72000-12-03 22:31:50 +000079 "sources" : sources,
80 "extrasearchdirs" : sourcedirs + extradirs,
81 "libraries": libraries,
Jack Jansend39c2462001-08-19 22:29:57 +000082 "mac_outputdir" : outputdir,
Jack Jansen6c502d72000-12-03 22:31:50 +000083 "extraexportsymbols" : extraexportsymbols,
Jack Jansen8c19b882001-01-23 22:36:26 +000084 "mac_targetname" : targetname,
85 "mac_dllname" : dllname,
86 "prefixname" : prefixname,
Jack Jansen6c502d72000-12-03 22:31:50 +000087 }
Jack Jansenb3be2162001-11-30 14:16:36 +000088 if libraryflags:
89 dict['libraryflags'] = libraryflags
90 if stdlibraryflags:
91 dict['stdlibraryflags'] = stdlibraryflags
Jack Jansenb66e1a32002-05-23 22:34:18 +000092 if initialize:
93 dict['initialize'] = initialize
Jack Jansen8c19b882001-01-23 22:36:26 +000094 mkcwproject.mkproject(os.path.join(projectdir, project), module, dict,
95 force=FORCEREBUILD, templatename=templatename)
Jack Jansen6c502d72000-12-03 22:31:50 +000096
Jack Jansen1eda2032001-01-21 22:24:27 +000097def genallprojects(force=0):
98 global FORCEREBUILD
99 FORCEREBUILD = force
Jack Jansen6c502d72000-12-03 22:31:50 +0000100 # Standard Python modules
Jack Jansen86c4d642002-03-14 23:14:43 +0000101 genpluginproject("carbon", "pyexpat",
102 sources=["pyexpat.c", "xmlparse.c", "xmlrole.c", "xmltok.c"],
103 extradirs=[":::Modules:expat"],
Jack Jansen5bb97e62003-02-21 22:33:55 +0000104 prefixname="mwerks_pyexpat_config.h"
Jack Jansen86c4d642002-03-14 23:14:43 +0000105 )
Jack Jansen9ea729c2002-12-13 23:34:03 +0000106 genpluginproject("carbon", "zlib",
Jack Jansen6c502d72000-12-03 22:31:50 +0000107 libraries=["zlib.ppc.Lib"],
108 extradirs=["::::imglibs:zlib:mac", "::::imglibs:zlib"])
Jack Jansen9ea729c2002-12-13 23:34:03 +0000109 genpluginproject("carbon", "gdbm",
Jack Jansen6c502d72000-12-03 22:31:50 +0000110 libraries=["gdbm.ppc.gusi.lib"],
111 extradirs=["::::gdbm:mac", "::::gdbm"])
Jack Jansen9ea729c2002-12-13 23:34:03 +0000112 genpluginproject("carbon", "_weakref", sources=["_weakref.c"])
113 genpluginproject("carbon", "_symtable", sources=["symtablemodule.c"])
Jack Jansen7c100082001-08-29 22:08:06 +0000114 # Example/test modules
Jack Jansen9ea729c2002-12-13 23:34:03 +0000115 genpluginproject("carbon", "_testcapi")
116 genpluginproject("carbon", "xx")
Jack Jansen3e828722003-01-08 16:27:44 +0000117 genpluginproject("carbon", "datetime")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000118 genpluginproject("carbon", "xxsubtype", sources=["xxsubtype.c"])
119 genpluginproject("carbon", "_hotshot", sources=["_hotshot.c"])
Jack Jansen6c502d72000-12-03 22:31:50 +0000120
121 # bgen-generated Toolbox modules
Jack Jansen3e828722003-01-08 16:27:44 +0000122 genpluginproject("carbon", "_AE")
123 genpluginproject("carbon", "_AH")
124 genpluginproject("carbon", "_App")
125 genpluginproject("carbon", "_Cm")
126 genpluginproject("carbon", "_Ctl")
127 genpluginproject("carbon", "_Dlg")
128 genpluginproject("carbon", "_Drag")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000129 genpluginproject("carbon", "_Evt",
Jack Jansen3e828722003-01-08 16:27:44 +0000130 stdlibraryflags="Debug, WeakImport")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000131 genpluginproject("carbon", "_File",
Jack Jansen3e828722003-01-08 16:27:44 +0000132 stdlibraryflags="Debug, WeakImport")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000133 genpluginproject("carbon", "_Fm",
Jack Jansen3e828722003-01-08 16:27:44 +0000134 stdlibraryflags="Debug, WeakImport")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000135 genpluginproject("carbon", "_Folder",
Jack Jansen3e828722003-01-08 16:27:44 +0000136 stdlibraryflags="Debug, WeakImport")
137 genpluginproject("carbon", "_Help")
138 genpluginproject("carbon", "_IBCarbon", sources=[":ibcarbon:_IBCarbon.c"])
139 genpluginproject("carbon", "_Icn")
140 genpluginproject("carbon", "_List")
141 genpluginproject("carbon", "_Menu")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000142 genpluginproject("carbon", "_Qd",
Jack Jansen3e828722003-01-08 16:27:44 +0000143 stdlibraryflags="Debug, WeakImport")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000144 genpluginproject("carbon", "_Qt",
Jack Jansen3e828722003-01-08 16:27:44 +0000145 libraryflags="Debug, WeakImport")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000146 genpluginproject("carbon", "_Qdoffs",
Jack Jansen3e828722003-01-08 16:27:44 +0000147 stdlibraryflags="Debug, WeakImport")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000148 genpluginproject("carbon", "_Res",
Jack Jansen3e828722003-01-08 16:27:44 +0000149 stdlibraryflags="Debug, WeakImport")
150 genpluginproject("carbon", "_Scrap")
151 genpluginproject("carbon", "_Snd")
152 genpluginproject("carbon", "_Sndihooks", sources=[":snd:_Sndihooks.c"])
153 genpluginproject("carbon", "_TE")
154 genpluginproject("carbon", "_Mlte")
155 genpluginproject("carbon", "_Win")
156 genpluginproject("carbon", "_CF", sources=["_CFmodule.c", "pycfbridge.c"])
157 genpluginproject("carbon", "_CarbonEvt")
Jack Jansendf222d22001-11-06 15:56:56 +0000158 genpluginproject("carbon", "hfsplus")
Jack Jansenf4b9fb72001-06-26 21:52:08 +0000159
Jack Jansen6c502d72000-12-03 22:31:50 +0000160 # Other Mac modules
Jack Jansen9ea729c2002-12-13 23:34:03 +0000161 genpluginproject("carbon", "calldll", sources=["calldll.c"])
162 genpluginproject("carbon", "ColorPicker")
Jack Jansen8c982662001-01-24 16:02:07 +0000163 genpluginproject("carbon", "waste",
164 sources=[
165 "wastemodule.c",
166 "WEObjectHandlers.c",
167 "WETabs.c", "WETabHooks.c"],
168 libraries=["WASTE.Carbon.lib"],
169 extradirs=[
170 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
171 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
Jack Jansen4a667c72002-01-11 12:39:03 +0000172 '::wastemods',
173 ]
Jack Jansen8c982662001-01-24 16:02:07 +0000174 )
Jack Jansen4a667c72002-01-11 12:39:03 +0000175 genpluginproject("carbon", "icglue", sources=["icgluemodule.c"])
Jack Jansen6c502d72000-12-03 22:31:50 +0000176
177if __name__ == '__main__':
178 genallprojects()
179
Jack Jansen1eda2032001-01-21 22:24:27 +0000180