]> git.saurik.com Git - wxWidgets.git/blame - build/tools/build-wxwidgets.py
Add a simple unit test for wxRegion::Intersect().
[wxWidgets.git] / build / tools / build-wxwidgets.py
CommitLineData
3b2c81c7
RD
1#!/usr/bin/env python
2
3###################################
4# Author: Kevin Ollivier
526954c5 5# Licence: wxWindows licence
3b2c81c7
RD
6###################################
7
8import os
9import re
10import sys
11import builder
3b2c81c7
RD
12import glob
13import optparse
14import platform
15import shutil
16import types
b4f28d1e 17import subprocess
3b2c81c7
RD
18
19# builder object
20wxBuilder = None
21
22# other globals
23scriptDir = None
24wxRootDir = None
25contribDir = None
26options = None
27configure_opts = None
28exitWithException = True
29
6d6f2e7c
RD
30verbose = False
31
32
33def numCPUs():
e2db04f8
RD
34 """
35 Detects the number of CPUs on a system.
36 This approach is from detectCPUs here: http://www.artima.com/weblogs/viewpost.jsp?thread=230001
37 """
38 # Linux, Unix and MacOS:
39 if hasattr(os, "sysconf"):
016a3d4c 40 if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
e2db04f8
RD
41 # Linux & Unix:
42 ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
43 if isinstance(ncpus, int) and ncpus > 0:
44 return ncpus
45 else: # OSX:
b4f28d1e
RD
46 p = subprocess.Popen("sysctl -n hw.ncpu", shell=True, stdout=subprocess.PIPE)
47 return p.stdout.read()
48
e2db04f8 49 # Windows:
016a3d4c 50 if "NUMBER_OF_PROCESSORS" in os.environ:
e2db04f8
RD
51 ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
52 if ncpus > 0:
53 return ncpus
54 return 1 # Default
6d6f2e7c 55
3b2c81c7 56
1ffe914a 57def getXcodePath():
016a3d4c 58 return getoutput("xcode-select -print-path")
1ffe914a
RD
59
60
5208671f
RD
61def getVisCVersion():
62 text = getoutput("cl.exe")
63 if 'Version 15' in text:
64 return '90'
65 # TODO: Add more tests to get the other versions...
66 else:
67 return 'FIXME'
68
69
3b2c81c7
RD
70def exitIfError(code, msg):
71 if code != 0:
016a3d4c 72 print(msg)
3b2c81c7 73 if exitWithException:
016a3d4c 74 raise builder.BuildError(msg)
3b2c81c7
RD
75 else:
76 sys.exit(1)
77
78
e2db04f8
RD
79def getWxRelease(wxRoot=None):
80 if not wxRoot:
81 global wxRootDir
82 wxRoot = wxRootDir
83
84 configureText = open(os.path.join(wxRoot, "configure.in"), "r").read()
3b2c81c7
RD
85 majorVersion = re.search("wx_major_version_number=(\d+)", configureText).group(1)
86 minorVersion = re.search("wx_minor_version_number=(\d+)", configureText).group(1)
87
6d6f2e7c 88 versionText = "%s.%s" % (majorVersion, minorVersion)
3b2c81c7 89
6d6f2e7c
RD
90 if int(minorVersion) % 2:
91 releaseVersion = re.search("wx_release_number=(\d+)", configureText).group(1)
92 versionText += ".%s" % (releaseVersion)
3b2c81c7 93
6d6f2e7c 94 return versionText
3b2c81c7
RD
95
96
e2db04f8
RD
97def getFrameworkName(options):
98 # the name of the framework is based on the wx port being built
99 name = "wxOSX"
100 if options.osx_cocoa:
101 name += "Cocoa"
102 else:
103 name += "Carbon"
104 return name
105
106
107def getPrefixInFramework(options, wxRoot=None):
108 # the path inside the framework that is the wx --prefix
109 fwPrefix = os.path.join(
110 os.path.abspath(options.mac_framework_prefix),
111 "%s.framework/Versions/%s" % (getFrameworkName(options), getWxRelease(wxRoot)))
112 return fwPrefix
113
114
e5ad1e9d 115def macFixupInstallNames(destdir, prefix, buildDir=None):
3b2c81c7
RD
116 # When an installdir is used then the install_names embedded in
117 # the dylibs are not correct. Reset the IDs and the dependencies
118 # to use just the prefix.
016a3d4c 119 print("**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir))
3b2c81c7
RD
120 pwd = os.getcwd()
121 os.chdir(destdir+prefix+'/lib')
122 dylibs = glob.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib')
123 for lib in dylibs:
124 cmd = 'install_name_tool -id %s/lib/%s %s/lib/%s' % \
125 (prefix,lib, destdir+prefix,lib)
016a3d4c 126 print(cmd)
6d6f2e7c 127 run(cmd)
3b2c81c7 128 for dep in dylibs:
e5ad1e9d
RD
129 if buildDir is not None:
130 cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
131 (buildDir,dep, prefix,dep, destdir+prefix,lib)
132 else:
133 cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
134 (destdir+prefix,dep, prefix,dep, destdir+prefix,lib)
016a3d4c 135 print(cmd)
6d6f2e7c 136 run(cmd)
3b2c81c7
RD
137 os.chdir(pwd)
138
139
6d6f2e7c
RD
140def run(cmd):
141 global verbose
142 if verbose:
016a3d4c 143 print("Running %s" % cmd)
6d6f2e7c 144 return exitIfError(os.system(cmd), "Error running %s" % cmd)
3b2c81c7 145
e2db04f8 146
016a3d4c
RD
147def getoutput(cmd):
148 sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
149 output = None
150 output = sp.stdout.read()
151 if sys.version_info > (3,):
152 output = output.decode('utf-8') # TODO: is utf-8 okay here?
153 output = output.rstrip()
154 rval = sp.wait()
155 if rval:
156 # Failed!
157 print("Command '%s' failed with exit code %d." % (cmd, rval))
158 sys.exit(rval)
159 return output
160
161
3b2c81c7
RD
162def main(scriptName, args):
163 global scriptDir
164 global wxRootDir
165 global contribDir
166 global options
167 global configure_opts
168 global wxBuilder
169
170 scriptDir = os.path.dirname(os.path.abspath(scriptName))
171 wxRootDir = os.path.abspath(os.path.join(scriptDir, "..", ".."))
172
173 contribDir = os.path.join("contrib", "src")
174 installDir = None
175
6d6f2e7c 176 VERSION = tuple([int(i) for i in getWxRelease().split('.')[:2]])
3b2c81c7
RD
177
178 if sys.platform.startswith("win"):
179 contribDir = os.path.join(wxRootDir, "contrib", "build")
180
181 if sys.platform.startswith("win"):
182 toolkit = "msvc"
183 else:
184 toolkit = "autoconf"
185
e2db04f8
RD
186 defJobs = str(numCPUs())
187 defFwPrefix = '/Library/Frameworks'
188
3b2c81c7 189 option_dict = {
e2db04f8
RD
190 "clean" : (False, "Clean all files from the build directory"),
191 "debug" : (False, "Build the library in debug symbols"),
192 "builddir" : ("", "Directory where the build will be performed for autoconf builds."),
193 "prefix" : ("", "Configured prefix to use for autoconf builds. Defaults to installdir if set. Ignored for framework builds."),
194 "jobs" : (defJobs, "Number of jobs to run at one time in make. Default: %s" % defJobs),
195 "install" : (False, "Install the toolkit to the installdir directory, or the default dir."),
196 "installdir" : ("", "Directory where built wxWidgets will be installed"),
197 "mac_distdir" : (None, "If set on Mac, will create an installer package in the specified dir."),
198 "mac_universal_binary"
508c5afe 199 : ("", "Comma separated list of architectures to include in the Mac universal binary"),
3b2c81c7 200 "mac_framework" : (False, "Install the Mac build as a framework"),
e2db04f8
RD
201 "mac_framework_prefix"
202 : (defFwPrefix, "Prefix where the framework should be installed. Default: %s" % defFwPrefix),
932d0768 203 "cairo" : (False, "Enable dynamicly loading the Cairo lib for wxGraphicsContext on MSW"),
e2db04f8
RD
204 "no_config" : (False, "Turn off configure step on autoconf builds"),
205 "config_only" : (False, "Only run the configure step and then exit"),
206 "rebake" : (False, "Regenerate Bakefile and autoconf files"),
207 "unicode" : (False, "Build the library with unicode support"),
208 "wxpython" : (False, "Build the wxWidgets library with all options needed by wxPython"),
209 "cocoa" : (False, "Build the old Mac Cooca port."),
210 "osx_cocoa" : (False, "Build the new Cocoa port"),
211 "shared" : (False, "Build wx as a dynamic library"),
e2db04f8
RD
212 "extra_make" : ("", "Extra args to pass on [n]make's command line."),
213 "features" : ("", "A comma-separated list of wxUSE_XYZ defines on Win, or a list of configure flags on unix."),
b4f28d1e 214 "verbose" : (False, "Print commands as they are run, (to aid with debugging this script)"),
3b2c81c7
RD
215 }
216
217 parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
e2db04f8
RD
218
219 keys = option_dict.keys()
016a3d4c 220 for opt in sorted(keys):
3b2c81c7 221 default = option_dict[opt][0]
3b2c81c7 222 action = "store"
016a3d4c 223 if type(default) == bool:
3b2c81c7 224 action = "store_true"
e2db04f8
RD
225 parser.add_option("--" + opt, default=default, action=action, dest=opt,
226 help=option_dict[opt][1])
3b2c81c7
RD
227
228 options, arguments = parser.parse_args(args=args)
b4f28d1e
RD
229
230 global verbose
231 if options.verbose:
232 verbose = True
233
3b2c81c7
RD
234 # compiler / build system specific args
235 buildDir = options.builddir
6d6f2e7c 236 args = []
3b2c81c7
RD
237 installDir = options.installdir
238 prefixDir = options.prefix
239
240 if toolkit == "autoconf":
e5ad1e9d
RD
241 if not buildDir:
242 buildDir = os.getcwd()
3b2c81c7
RD
243 configure_opts = []
244 if options.features != "":
245 configure_opts.extend(options.features.split(" "))
246
247 if options.unicode:
248 configure_opts.append("--enable-unicode")
249
250 if options.debug:
251 configure_opts.append("--enable-debug")
252
3b2c81c7 253 if options.cocoa:
e5ad1e9d 254 configure_opts.append("--with-old_cocoa")
3b2c81c7
RD
255
256 if options.osx_cocoa:
257 configure_opts.append("--with-osx_cocoa")
e5ad1e9d 258
3b2c81c7
RD
259 wxpy_configure_opts = [
260 "--with-opengl",
261 "--enable-sound",
262 "--enable-graphics_ctx",
263 "--enable-mediactrl",
264 "--enable-display",
265 "--enable-geometry",
266 "--enable-debug_flag",
267 "--enable-optimise",
268 "--disable-debugreport",
269 "--enable-uiactionsim",
270 ]
271
272 if sys.platform.startswith("darwin"):
273 wxpy_configure_opts.append("--enable-monolithic")
274 else:
275 wxpy_configure_opts.append("--with-sdl")
276 wxpy_configure_opts.append("--with-gnomeprint")
277
119d50a8
RD
278 # Try to use use lowest available SDK back to 10.5. Both Carbon and
279 # Cocoa builds require at least the 10.5 SDK now. We only add it to
280 # the wxpy options because this is a hard-requirement for wxPython,
281 # but other cases it is optional and is left up to the developer.
282 # TODO: there should be a command line option to set the SDK...
be7a5775 283 if sys.platform.startswith("darwin"):
1ffe914a 284 xcodePath = getXcodePath()
68a1c7d3 285 sdks = [
1ffe914a
RD
286 xcodePath+"/SDKs/MacOSX10.5.sdk",
287 xcodePath+"/SDKs/MacOSX10.6.sdk",
288 xcodePath+"/SDKs/MacOSX10.7.sdk",
68a1c7d3 289 ]
68a1c7d3
RD
290
291 # use the lowest available sdk
292 for sdk in sdks:
293 if os.path.exists(sdk):
294 wxpy_configure_opts.append(
295 "--with-macosx-sdk=%s" % sdk)
296 break
be7a5775 297
3b2c81c7
RD
298 if not options.mac_framework:
299 if installDir and not prefixDir:
300 prefixDir = installDir
301 if prefixDir:
e2db04f8 302 prefixDir = os.path.abspath(prefixDir)
3b2c81c7 303 configure_opts.append("--prefix=" + prefixDir)
e2db04f8
RD
304
305
3b2c81c7
RD
306 if options.wxpython:
307 configure_opts.extend(wxpy_configure_opts)
308 if options.debug:
309 # wxPython likes adding these debug options too
310 configure_opts.append("--enable-debug_gdb")
311 configure_opts.append("--disable-optimise")
e2db04f8
RD
312 configure_opts.remove("--enable-optimise")
313
3b2c81c7
RD
314
315 if options.rebake:
6d6f2e7c 316 retval = run("make -f autogen.mk")
3b2c81c7
RD
317 exitIfError(retval, "Error running autogen.mk")
318
319 if options.mac_framework:
e2db04f8
RD
320 # TODO: Should options.install be automatically turned on if the
321 # mac_framework flag is given?
322
3b2c81c7
RD
323 # framework builds always need to be monolithic
324 if not "--enable-monolithic" in configure_opts:
325 configure_opts.append("--enable-monolithic")
6d6f2e7c 326
e2db04f8
RD
327 # The --prefix given to configure will be the framework prefix
328 # plus the framework specific dir structure.
329 prefixDir = getPrefixInFramework(options)
6d6f2e7c 330 configure_opts.append("--prefix=" + prefixDir)
5be89298
RD
331
332 # the framework build adds symlinks above the installDir + prefixDir folder
333 # so we need to wipe from the framework root instead of inside the prefixDir.
334 frameworkRootDir = os.path.abspath(os.path.join(installDir + prefixDir, "..", ".."))
335 if os.path.exists(frameworkRootDir):
336 if os.path.exists(frameworkRootDir):
337 shutil.rmtree(frameworkRootDir)
6d6f2e7c
RD
338
339 if options.mac_universal_binary:
403c71da
RD
340 if options.mac_universal_binary == 'default':
341 if options.osx_cocoa:
342 configure_opts.append("--enable-universal_binary=i386,x86_64")
343 else:
344 configure_opts.append("--enable-universal_binary")
345 else:
346 configure_opts.append("--enable-universal_binary=%s" % options.mac_universal_binary)
e2db04f8 347
3b2c81c7 348
016a3d4c 349 print("Configure options: " + repr(configure_opts))
3b2c81c7 350 wxBuilder = builder.AutoconfBuilder()
6d6f2e7c 351 if not options.no_config and not options.clean:
3b2c81c7
RD
352 olddir = os.getcwd()
353 if buildDir:
354 os.chdir(buildDir)
355 exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),
356 "Error running configure")
357 os.chdir(olddir)
e5ad1e9d
RD
358
359 if options.config_only:
016a3d4c 360 print("Exiting after configure")
e5ad1e9d 361 return
3b2c81c7
RD
362
363 elif toolkit in ["msvc", "msvcProject"]:
364 flags = {}
365 buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw"))
e5ad1e9d 366
016a3d4c 367 print("creating wx/msw/setup.h from setup0.h")
3b2c81c7
RD
368 if options.unicode:
369 flags["wxUSE_UNICODE"] = "1"
370 if VERSION < (2,9):
371 flags["wxUSE_UNICODE_MSLU"] = "1"
372
373 if options.cairo:
932d0768 374 if not os.environ.get("CAIRO_ROOT"):
016a3d4c 375 print("WARNING: Expected CAIRO_ROOT set in the environment!")
3b2c81c7
RD
376 flags["wxUSE_CAIRO"] = "1"
377
378 if options.wxpython:
379 flags["wxDIALOG_UNIT_COMPATIBILITY "] = "0"
e5ad1e9d 380 flags["wxUSE_DEBUGREPORT"] = "0"
3b2c81c7 381 flags["wxUSE_DIALUP_MANAGER"] = "0"
e5ad1e9d
RD
382 flags["wxUSE_GRAPHICS_CONTEXT"] = "1"
383 flags["wxUSE_DISPLAY"] = "1"
3b2c81c7
RD
384 flags["wxUSE_GLCANVAS"] = "1"
385 flags["wxUSE_POSTSCRIPT"] = "1"
386 flags["wxUSE_AFM_FOR_POSTSCRIPT"] = "0"
3b2c81c7 387 flags["wxUSE_DATEPICKCTRL_GENERIC"] = "1"
e5ad1e9d 388
3b2c81c7
RD
389 if VERSION < (2,9):
390 flags["wxUSE_DIB_FOR_BITMAP"] = "1"
391
392 if VERSION >= (2,9):
393 flags["wxUSE_UIACTIONSIMULATOR"] = "1"
932d0768 394
3b2c81c7
RD
395
396 mswIncludeDir = os.path.join(wxRootDir, "include", "wx", "msw")
397 setup0File = os.path.join(mswIncludeDir, "setup0.h")
398 setupText = open(setup0File, "rb").read()
399
400 for flag in flags:
401 setupText, subsMade = re.subn(flag + "\s+?\d", "%s %s" % (flag, flags[flag]), setupText)
402 if subsMade == 0:
016a3d4c 403 print("Flag %s wasn't found in setup0.h!" % flag)
3b2c81c7
RD
404 sys.exit(1)
405
406 setupFile = open(os.path.join(mswIncludeDir, "setup.h"), "wb")
407 setupFile.write(setupText)
408 setupFile.close()
409 args = []
410 if toolkit == "msvc":
016a3d4c 411 print("setting build options...")
3b2c81c7
RD
412 args.append("-f makefile.vc")
413 if options.unicode:
414 args.append("UNICODE=1")
415 if VERSION < (2,9):
416 args.append("MSLU=1")
417
418 if options.wxpython:
419 args.append("OFFICIAL_BUILD=1")
5208671f 420 args.append("COMPILER_VERSION=%s" % getVisCVersion())
3b2c81c7
RD
421 args.append("SHARED=1")
422 args.append("MONOLITHIC=0")
423 args.append("USE_OPENGL=1")
424 args.append("USE_GDIPLUS=1")
3b2c81c7
RD
425
426 if not options.debug:
3b2c81c7
RD
427 args.append("BUILD=release")
428 else:
429 args.append("BUILD=debug")
9f2b6b31
RD
430
431 if options.shared:
432 args.append("SHARED=1")
932d0768 433
9f2b6b31 434 if options.cairo:
932d0768
RD
435 args.append(
436 "CPPFLAGS=/I%s" %
437 os.path.join(os.environ.get("CAIRO_ROOT", ""), 'include\\cairo'))
3b2c81c7
RD
438
439 wxBuilder = builder.MSVCBuilder()
440
441 if toolkit == "msvcProject":
442 args = []
443 if options.shared or options.wxpython:
444 args.append("wx_dll.dsw")
445 else:
446 args.append("wx.dsw")
447
448 # TODO:
449 wxBuilder = builder.MSVCProjectBuilder()
450
e2db04f8 451
3b2c81c7 452 if not wxBuilder:
016a3d4c 453 print("Builder not available for your specified platform/compiler.")
3b2c81c7
RD
454 sys.exit(1)
455
456 if options.clean:
016a3d4c 457 print("Performing cleanup.")
9f2b6b31 458 wxBuilder.clean(dir=buildDir, options=args)
3b2c81c7
RD
459
460 sys.exit(0)
6d6f2e7c
RD
461
462 if options.extra_make:
463 args.append(options.extra_make)
e2db04f8 464
5be89298
RD
465 if not sys.platform.startswith("win"):
466 args.append("--jobs=" + options.jobs)
6d6f2e7c 467 exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building")
6d6f2e7c
RD
468
469 if options.install:
470 extra=None
471 if installDir:
472 extra = ['DESTDIR='+installDir]
9f2b6b31 473 wxBuilder.install(dir=buildDir, options=extra)
e2db04f8
RD
474
475 if options.install and options.mac_framework:
3b2c81c7
RD
476
477 def renameLibrary(libname, frameworkname):
478 reallib = libname
479 links = []
480 while os.path.islink(reallib):
481 links.append(reallib)
482 reallib = "lib/" + os.readlink(reallib)
483
016a3d4c 484 #print("reallib is %s" % reallib)
6d6f2e7c 485 run("mv -f %s lib/%s.dylib" % (reallib, frameworkname))
3b2c81c7
RD
486
487 for link in links:
6d6f2e7c 488 run("ln -s -f %s.dylib %s" % (frameworkname, link))
3b2c81c7 489
6d6f2e7c
RD
490 frameworkRootDir = prefixDir
491 if installDir:
016a3d4c 492 print("installDir = %s" % installDir)
6d6f2e7c
RD
493 frameworkRootDir = installDir + prefixDir
494 os.chdir(frameworkRootDir)
3b2c81c7
RD
495 build_string = ""
496 if options.debug:
497 build_string = "d"
6d6f2e7c 498
b4f28d1e 499 fwname = getFrameworkName(options)
016a3d4c
RD
500 version = getoutput("bin/wx-config --release")
501 version_full = getoutput("bin/wx-config --version")
502 basename = getoutput("bin/wx-config --basename")
503 configname = getoutput("bin/wx-config --selected-config")
5be89298
RD
504
505 os.makedirs("Resources")
506 wxplist = dict(
507 CFBundleDevelopmentRegion="English",
508 CFBundleIdentifier='org.wxwidgets.wxosxcocoa',
509 CFBundleName=fwname,
510 CFBundleVersion=version_full,
511 CFBundleExecutable=fwname,
512 CFBundleGetInfoString="%s %s" % (fwname, version_full),
513 CFBundlePackageType="FMWK",
514 CFBundleSignature="WXCO",
515 CFBundleShortVersionString=version_full,
516 CFBundleInfoDictionaryVersion="6.0",
517 )
518
519 import plistlib
520 plistlib.writePlist(wxplist, os.path.join(frameworkRootDir, "Resources", "Info.plist"))
3b2c81c7
RD
521
522 # we make wx the "actual" library file and link to it from libwhatever.dylib
523 # so that things can link to wx and survive minor version changes
b4f28d1e
RD
524 renameLibrary("lib/lib%s-%s.dylib" % (basename, version), fwname)
525 run("ln -s -f lib/%s.dylib %s" % (fwname, fwname))
3b2c81c7 526
5be89298 527 run("ln -s -f include Headers")
3b2c81c7
RD
528
529 for lib in ["GL", "STC", "Gizmos", "Gizmos_xrc"]:
530 libfile = "lib/lib%s_%s-%s.dylib" % (basename, lib.lower(), version)
531 if os.path.exists(libfile):
532 frameworkDir = "framework/wx%s/%s" % (lib, version)
533 if not os.path.exists(frameworkDir):
534 os.makedirs(frameworkDir)
535 renameLibrary(libfile, "wx" + lib)
6d6f2e7c 536 run("ln -s -f ../../../%s %s/wx%s" % (libfile, frameworkDir, lib))
3b2c81c7
RD
537
538 for lib in glob.glob("lib/*.dylib"):
539 if not os.path.islink(lib):
540 corelibname = "lib/lib%s-%s.0.dylib" % (basename, version)
6d6f2e7c
RD
541 run("install_name_tool -id %s %s" % (os.path.join(prefixDir, lib), lib))
542 run("install_name_tool -change %s %s %s" % (os.path.join(frameworkRootDir, corelibname), os.path.join(prefixDir, corelibname), lib))
b4f28d1e 543
3b2c81c7
RD
544 os.chdir("include")
545
e2db04f8 546 header_template = """
3b2c81c7
RD
547#ifndef __WX_FRAMEWORK_HEADER__
548#define __WX_FRAMEWORK_HEADER__
549
550%s
551
552#endif // __WX_FRAMEWORK_HEADER__
553"""
554 headers = ""
555 header_dir = "wx-%s/wx" % version
556 for include in glob.glob(header_dir + "/*.h"):
5be89298 557 headers += "#include <wx/" + os.path.basename(include) + ">\n"
3b2c81c7 558
5be89298 559 framework_header = open("%s.h" % fwname, "w")
3b2c81c7
RD
560 framework_header.write(header_template % headers)
561 framework_header.close()
562
6d6f2e7c 563 run("ln -s -f %s wx" % header_dir)
5be89298
RD
564 os.chdir("wx-%s/wx" % version)
565 run("ln -s -f ../../../lib/wx/include/%s/wx/setup.h setup.h" % configname)
3b2c81c7 566
5be89298
RD
567 os.chdir(os.path.join(frameworkRootDir, ".."))
568 run("ln -s -f %s Current" % getWxRelease())
569 os.chdir("..")
6d6f2e7c
RD
570 run("ln -s -f Versions/Current/Headers Headers")
571 run("ln -s -f Versions/Current/Resources Resources")
b4f28d1e 572 run("ln -s -f Versions/Current/%s %s" % (fwname, fwname))
3b2c81c7 573
6d6f2e7c 574 # sanity check to ensure the symlink works
e2db04f8 575 os.chdir("Versions/Current")
b4f28d1e
RD
576
577 # put info about the framework into wx-config
578 os.chdir(frameworkRootDir)
579 text = file('lib/wx/config/%s' % configname).read()
580 text = text.replace("MAC_FRAMEWORK=", "MAC_FRAMEWORK=%s" % getFrameworkName(options))
581 if options.mac_framework_prefix not in ['/Library/Frameworks',
582 '/System/Library/Frameworks']:
583 text = text.replace("MAC_FRAMEWORK_PREFIX=",
584 "MAC_FRAMEWORK_PREFIX=%s" % options.mac_framework_prefix)
585 file('lib/wx/config/%s' % configname, 'w').write(text)
586
587 # The framework is finished!
016a3d4c 588 print("wxWidgets framework created at: " +
e2db04f8
RD
589 os.path.join( installDir,
590 options.mac_framework_prefix,
016a3d4c 591 '%s.framework' % fwname))
e2db04f8
RD
592
593
594 # adjust the install_name if needed
3b2c81c7
RD
595 if sys.platform.startswith("darwin") and \
596 options.install and \
597 options.installdir and \
e2db04f8 598 not options.mac_framework and \
3b2c81c7 599 not options.wxpython: # wxPython's build will do this later if needed
6d6f2e7c
RD
600 if not prefixDir:
601 prefixDir = '/usr/local'
602 macFixupInstallNames(options.installdir, prefixDir)#, buildDir)
603
604 # make a package if a destdir was set.
605 if options.mac_framework and \
e2db04f8 606 options.install and \
6d6f2e7c
RD
607 options.installdir and \
608 options.mac_distdir:
3b2c81c7 609
6d6f2e7c
RD
610 if os.path.exists(options.mac_distdir):
611 shutil.rmtree(options.mac_distdir)
612
613 packagedir = os.path.join(options.mac_distdir, "packages")
614 os.makedirs(packagedir)
615 basename = os.path.basename(prefixDir.split(".")[0])
616 packageName = basename + "-" + getWxRelease()
1ffe914a 617 packageMakerPath = getXcodePath()+"/usr/bin/packagemaker "
6d6f2e7c
RD
618 args = []
619 args.append("--root %s" % options.installdir)
620 args.append("--id org.wxwidgets.%s" % basename.lower())
621 args.append("--title %s" % packageName)
622 args.append("--version %s" % getWxRelease())
623 args.append("--out %s" % os.path.join(packagedir, packageName + ".pkg"))
624 cmd = packageMakerPath + ' '.join(args)
016a3d4c 625 print("cmd = %s" % cmd)
6d6f2e7c
RD
626 run(cmd)
627
628 os.chdir(options.mac_distdir)
629
630 run('hdiutil create -srcfolder %s -volname "%s" -imagekey zlib-level=9 %s.dmg' % (packagedir, packageName, packageName))
3b2c81c7 631
6d6f2e7c 632 shutil.rmtree(packagedir)
3b2c81c7
RD
633
634if __name__ == '__main__':
635 exitWithException = False # use sys.exit instead
636 main(sys.argv[0], sys.argv[1:])
637