genpluginprojects.py 5.99 KB
Newer Older
1 2 3
import mkcwproject
import sys
import os
4
import string
5

6 7
PYTHONDIR = sys.prefix
PROJECTDIR = os.path.join(PYTHONDIR, ":Mac:Build")
8 9 10 11 12 13
MODULEDIRS = [	# Relative to projectdirs
	"::Modules:%s",
	"::Modules",
	":::Modules",
]

14 15 16 17
# Global variable to control forced rebuild (otherwise the project is only rebuilt
# when it is changed)
FORCEREBUILD=0

18 19 20 21 22
def relpath(base, path):
	"""Turn abs path into path relative to another. Only works for 2 abs paths
	both pointing to folders"""
	if not os.path.isabs(base) or not os.path.isabs(path):
		raise 'Absolute paths only'
23 24
	if base[-1] == ':':
		base = base[:-1]
25 26 27 28 29
	basefields = string.split(base, os.sep)
	pathfields = string.split(path, os.sep)
	commonfields = len(os.path.commonprefix((basefields, pathfields)))
	basefields = basefields[commonfields:]
	pathfields = pathfields[commonfields:]
30 31 32
	pathfields = ['']*(len(basefields)+1) + pathfields
	rv = string.join(pathfields, os.sep)
	return rv
33

34
def genpluginproject(architecture, module,
35 36 37
		project=None, projectdir=None,
		sources=[], sourcedirs=[],
		libraries=[], extradirs=[],
38
		extraexportsymbols=[], outputdir=":::Lib:lib-dynload",
39 40
		libraryflags=None, stdlibraryflags=None, prefixname=None,
		initialize=None):
41 42
	if architecture != "carbon":
		raise 'Unsupported architecture: %s'%architecture
43 44 45
	templatename = "template-%s" % architecture
	targetname = "%s.%s" % (module, architecture)
	dllname = "%s.%s.slb" % (module, architecture)
46
	if not project:
47
		project = "%s.%s.mcp"%(module, architecture)
48 49 50 51 52 53 54
	if not projectdir:
		projectdir = PROJECTDIR
	if not sources:
		sources = [module + 'module.c']
	if not sourcedirs:
		for moduledir in MODULEDIRS:
			if '%' in moduledir:
55 56 57 58 59 60 61
				# For historical reasons an initial _ in the modulename
				# is not reflected in the folder name
				if module[0] == '_':
					modulewithout_ = module[1:]
				else:
					modulewithout_ = module
				moduledir = moduledir % modulewithout_
62 63 64
			fn = os.path.join(projectdir, os.path.join(moduledir, sources[0]))
			if os.path.exists(fn):
				moduledir, sourcefile = os.path.split(fn)
65
				sourcedirs = [relpath(projectdir, moduledir)]
66 67 68 69 70
				sources[0] = sourcefile
				break
		else:
			print "Warning: %s: sourcefile not found: %s"%(module, sources[0])
			sourcedirs = []
71 72 73
	if prefixname:
		pass
	elif architecture == "carbon":
74
		prefixname = "mwerks_shcarbon_pch"
75 76
	else:
		prefixname = "mwerks_plugin_config.h"
77
	dict = {
78
		"sysprefix" : relpath(projectdir, sys.prefix),
79 80 81
		"sources" : sources,
		"extrasearchdirs" : sourcedirs + extradirs,
		"libraries": libraries,
82
		"mac_outputdir" : outputdir,
83
		"extraexportsymbols" : extraexportsymbols,
84 85 86
		"mac_targetname" : targetname,
		"mac_dllname" : dllname,
		"prefixname" : prefixname,
87
	}
88 89 90 91
	if libraryflags:
		dict['libraryflags'] = libraryflags
	if stdlibraryflags:
		dict['stdlibraryflags'] = stdlibraryflags
92 93
	if initialize:
		dict['initialize'] = initialize
94 95
	mkcwproject.mkproject(os.path.join(projectdir, project), module, dict, 
			force=FORCEREBUILD, templatename=templatename)
96

97 98 99
def	genallprojects(force=0):
	global FORCEREBUILD
	FORCEREBUILD = force
100
	# Standard Python modules
101 102 103
	genpluginproject("carbon", "pyexpat", 
		sources=["pyexpat.c", "xmlparse.c", "xmlrole.c", "xmltok.c"],
		extradirs=[":::Modules:expat"],
104
		prefixname="mwerks_pyexpat_config.h"
105
		)
106
	genpluginproject("carbon", "zlib", 
107 108
		libraries=["zlib.ppc.Lib"], 
		extradirs=["::::imglibs:zlib:mac", "::::imglibs:zlib"])
109
	genpluginproject("carbon", "gdbm", 
110 111
		libraries=["gdbm.ppc.gusi.lib"], 
		extradirs=["::::gdbm:mac", "::::gdbm"])
112
	genpluginproject("carbon", "_csv", sources=["_csv.c"])
113 114
	genpluginproject("carbon", "_weakref", sources=["_weakref.c"])
	genpluginproject("carbon", "_symtable", sources=["symtablemodule.c"])
115
	# Example/test modules
116 117
	genpluginproject("carbon", "_testcapi")
	genpluginproject("carbon", "xx")
118
	genpluginproject("carbon", "datetime")
119 120
	genpluginproject("carbon", "xxsubtype", sources=["xxsubtype.c"])
	genpluginproject("carbon", "_hotshot", sources=["_hotshot.c"])
121 122
	
	# bgen-generated Toolbox modules
123 124 125 126 127 128 129
	genpluginproject("carbon", "_AE")
	genpluginproject("carbon", "_AH")
	genpluginproject("carbon", "_App")
	genpluginproject("carbon", "_Cm")
	genpluginproject("carbon", "_Ctl")
	genpluginproject("carbon", "_Dlg")
	genpluginproject("carbon", "_Drag")
130
	genpluginproject("carbon", "_Evt", 
131
			stdlibraryflags="Debug, WeakImport")
132
	genpluginproject("carbon", "_File", 
133
			stdlibraryflags="Debug, WeakImport")
134
	genpluginproject("carbon", "_Fm", 
135
			stdlibraryflags="Debug, WeakImport")
136
	genpluginproject("carbon", "_Folder", 
137 138 139 140 141 142
			stdlibraryflags="Debug, WeakImport")
	genpluginproject("carbon", "_Help")
	genpluginproject("carbon", "_IBCarbon", sources=[":ibcarbon:_IBCarbon.c"])
	genpluginproject("carbon", "_Icn")
	genpluginproject("carbon", "_List")
	genpluginproject("carbon", "_Menu")
143
	genpluginproject("carbon", "_Qd", 
144
			stdlibraryflags="Debug, WeakImport")
145
	genpluginproject("carbon", "_Qt", 
146
			libraryflags="Debug, WeakImport")
147
	genpluginproject("carbon", "_Qdoffs", 
148
			stdlibraryflags="Debug, WeakImport")
149
	genpluginproject("carbon", "_Res", 
150 151 152 153 154 155 156 157 158
			stdlibraryflags="Debug, WeakImport")
	genpluginproject("carbon", "_Scrap")
	genpluginproject("carbon", "_Snd")
	genpluginproject("carbon", "_Sndihooks", sources=[":snd:_Sndihooks.c"])
	genpluginproject("carbon", "_TE")
	genpluginproject("carbon", "_Mlte")
	genpluginproject("carbon", "_Win")
	genpluginproject("carbon", "_CF", sources=["_CFmodule.c", "pycfbridge.c"])
	genpluginproject("carbon", "_CarbonEvt")
Jack Jansen's avatar
Jack Jansen committed
159
	genpluginproject("carbon", "hfsplus")
160
	
161
	# Other Mac modules
162 163
	genpluginproject("carbon", "calldll", sources=["calldll.c"])
	genpluginproject("carbon", "ColorPicker")
164 165 166 167 168 169 170 171 172
	genpluginproject("carbon", "waste",
		sources=[
			"wastemodule.c",
			"WEObjectHandlers.c",
			"WETabs.c", "WETabHooks.c"],
		libraries=["WASTE.Carbon.lib"],
		extradirs=[
			'{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
			'{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
173 174
			'::wastemods',
			]
175
		)
176
	genpluginproject("carbon", "icglue", sources=["icgluemodule.c"])
177 178 179 180

if __name__ == '__main__':
	genallprojects()
	
181