blob: 65ff348c7dc9ff8b7b449500b2ae4633a029f630 [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 Jansenc70815a2002-06-26 22:06:08 +0000104 prefixname="mwerks_shcarbon_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")
117 genpluginproject("carbon", "xxsubtype", sources=["xxsubtype.c"])
118 genpluginproject("carbon", "_hotshot", sources=["_hotshot.c"])
Jack Jansen6c502d72000-12-03 22:31:50 +0000119
120 # bgen-generated Toolbox modules
Jack Jansen77105a92001-08-23 13:51:46 +0000121 genpluginproject("carbon", "_AE", outputdir="::Lib:Carbon")
Jack Jansen25a8f0d2002-09-06 22:59:00 +0000122 genpluginproject("carbon", "_AH", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000123 genpluginproject("carbon", "_Alias", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000124 genpluginproject("carbon", "_App", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000125 genpluginproject("carbon", "_Cm", outputdir="::Lib:Carbon")
Just van Rossum11ccf3c2001-12-13 13:21:38 +0000126 # XXX can't work properly because we need to set a custom fragment initializer
127 #genpluginproject("carbon", "_CG",
128 # sources=["_CGModule.c", "CFMLateImport.c"],
129 # libraries=["CGStubLib"],
130 # outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000131 genpluginproject("carbon", "_Ctl", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000132 genpluginproject("carbon", "_Dlg", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000133 genpluginproject("carbon", "_Drag", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000134 genpluginproject("carbon", "_Evt",
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000135 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000136 genpluginproject("carbon", "_File",
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000137 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000138 genpluginproject("carbon", "_Fm",
139 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
140 genpluginproject("carbon", "_Folder",
141 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
142 genpluginproject("carbon", "_Help", outputdir="::Lib:Carbon")
Jack Jansen3bd3fed2002-08-05 14:12:24 +0000143 genpluginproject("carbon", "_IBCarbon", sources=[":ibcarbon:_IBCarbon.c"],
144 outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000145 genpluginproject("carbon", "_Icn", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000146 genpluginproject("carbon", "_List", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000147 genpluginproject("carbon", "_Menu", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000148 genpluginproject("carbon", "_Qd",
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000149 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000150 genpluginproject("carbon", "_Qt",
151 libraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000152 genpluginproject("carbon", "_Qdoffs",
Jack Jansen5ee24ae2002-03-24 22:59:16 +0000153 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000154 genpluginproject("carbon", "_Res",
Jack Jansen9051e0e2002-03-22 14:15:07 +0000155 stdlibraryflags="Debug, WeakImport", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000156 genpluginproject("carbon", "_Scrap", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000157 genpluginproject("carbon", "_Snd", outputdir="::Lib:Carbon")
Jack Jansen9ea729c2002-12-13 23:34:03 +0000158 genpluginproject("carbon", "_Sndihooks", sources=[":snd:_Sndihooks.c"], outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000159 genpluginproject("carbon", "_TE", outputdir="::Lib:Carbon")
Jack Jansen77105a92001-08-23 13:51:46 +0000160 genpluginproject("carbon", "_Mlte", outputdir="::Lib:Carbon")
161 genpluginproject("carbon", "_Win", outputdir="::Lib:Carbon")
Jack Jansen66e794d2002-07-22 12:32:31 +0000162 genpluginproject("carbon", "_CF", sources=["_CFmodule.c", "pycfbridge.c"], outputdir="::Lib:Carbon")
Just van Rossumaa6e83f2001-12-12 22:42:37 +0000163 genpluginproject("carbon", "_CarbonEvt", outputdir="::Lib:Carbon")
Jack Jansendf222d22001-11-06 15:56:56 +0000164 genpluginproject("carbon", "hfsplus")
Jack Jansenf4b9fb72001-06-26 21:52:08 +0000165
Jack Jansen6c502d72000-12-03 22:31:50 +0000166 # Other Mac modules
Jack Jansen9ea729c2002-12-13 23:34:03 +0000167 genpluginproject("carbon", "calldll", sources=["calldll.c"])
168 genpluginproject("carbon", "ColorPicker")
Jack Jansen8c982662001-01-24 16:02:07 +0000169 genpluginproject("carbon", "waste",
170 sources=[
171 "wastemodule.c",
172 "WEObjectHandlers.c",
173 "WETabs.c", "WETabHooks.c"],
174 libraries=["WASTE.Carbon.lib"],
175 extradirs=[
176 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
177 '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
Jack Jansen4a667c72002-01-11 12:39:03 +0000178 '::wastemods',
179 ]
Jack Jansen8c982662001-01-24 16:02:07 +0000180 )
Jack Jansen4a667c72002-01-11 12:39:03 +0000181 genpluginproject("carbon", "icglue", sources=["icgluemodule.c"])
Jack Jansen6c502d72000-12-03 22:31:50 +0000182
183if __name__ == '__main__':
184 genallprojects()
185
Jack Jansen1eda2032001-01-21 22:24:27 +0000186