import re
import sys
import builder
-import commands
import glob
import optparse
import platform
options = None
configure_opts = None
exitWithException = True
+nmakeCommand = 'nmake.exe'
verbose = False
"""
# Linux, Unix and MacOS:
if hasattr(os, "sysconf"):
- if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
+ if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
# Linux & Unix:
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(ncpus, int) and ncpus > 0:
return p.stdout.read()
# Windows:
- if os.environ.has_key("NUMBER_OF_PROCESSORS"):
+ if "NUMBER_OF_PROCESSORS" in os.environ:
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
if ncpus > 0:
return ncpus
return 1 # Default
+def getXcodePaths():
+ base = getoutput("xcode-select -print-path")
+ return [base, base+"/Platforms/MacOSX.platform/Developer"]
+
+
+def getVisCVersion():
+ text = getoutput("cl.exe")
+ if 'Version 13' in text:
+ return '71'
+ if 'Version 15' in text:
+ return '90'
+ if 'Version 16' in text:
+ return '100'
+ # TODO: Add more tests to get the other versions...
+ else:
+ return 'FIXME'
+
+
def exitIfError(code, msg):
if code != 0:
- print msg
+ print(msg)
if exitWithException:
- raise builder.BuildError, msg
+ raise builder.BuildError(msg)
else:
sys.exit(1)
# When an installdir is used then the install_names embedded in
# the dylibs are not correct. Reset the IDs and the dependencies
# to use just the prefix.
- print "**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir)
+ print("**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir))
pwd = os.getcwd()
os.chdir(destdir+prefix+'/lib')
dylibs = glob.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib')
for lib in dylibs:
cmd = 'install_name_tool -id %s/lib/%s %s/lib/%s' % \
(prefix,lib, destdir+prefix,lib)
- print cmd
+ print(cmd)
run(cmd)
for dep in dylibs:
if buildDir is not None:
else:
cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
(destdir+prefix,dep, prefix,dep, destdir+prefix,lib)
- print cmd
+ print(cmd)
run(cmd)
os.chdir(pwd)
def run(cmd):
global verbose
if verbose:
- print "Running %s" % cmd
+ print("Running %s" % cmd)
return exitIfError(os.system(cmd), "Error running %s" % cmd)
+def getoutput(cmd):
+ sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ output = None
+ output = sp.stdout.read()
+ if sys.version_info > (3,):
+ output = output.decode('utf-8') # TODO: is utf-8 okay here?
+ output = output.rstrip()
+ rval = sp.wait()
+ if rval:
+ # Failed!
+ print("Command '%s' failed with exit code %d." % (cmd, rval))
+ sys.exit(rval)
+ return output
+
+
def main(scriptName, args):
global scriptDir
global wxRootDir
global options
global configure_opts
global wxBuilder
+ global nmakeCommand
scriptDir = os.path.dirname(os.path.abspath(scriptName))
wxRootDir = os.path.abspath(os.path.join(scriptDir, "..", ".."))
"installdir" : ("", "Directory where built wxWidgets will be installed"),
"mac_distdir" : (None, "If set on Mac, will create an installer package in the specified dir."),
"mac_universal_binary"
- : (False, "Build Mac version as a universal binary"),
- "mac_arch" : ("", "Build just the specified architecture on Mac"),
+ : ("", "Comma separated list of architectures to include in the Mac universal binary"),
"mac_framework" : (False, "Install the Mac build as a framework"),
"mac_framework_prefix"
: (defFwPrefix, "Prefix where the framework should be installed. Default: %s" % defFwPrefix),
+ "cairo" : (False, "Enable dynamicly loading the Cairo lib for wxGraphicsContext on MSW"),
"no_config" : (False, "Turn off configure step on autoconf builds"),
"config_only" : (False, "Only run the configure step and then exit"),
"rebake" : (False, "Regenerate Bakefile and autoconf files"),
"cocoa" : (False, "Build the old Mac Cooca port."),
"osx_cocoa" : (False, "Build the new Cocoa port"),
"shared" : (False, "Build wx as a dynamic library"),
- "cairo" : (False, "Build support for wxCairoContext (always true on GTK+)"),
"extra_make" : ("", "Extra args to pass on [n]make's command line."),
"features" : ("", "A comma-separated list of wxUSE_XYZ defines on Win, or a list of configure flags on unix."),
"verbose" : (False, "Print commands as they are run, (to aid with debugging this script)"),
+ "jom" : (False, "Use jom.exe instead of nmake for MSW builds."),
}
parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
keys = option_dict.keys()
- keys.sort()
- for opt in keys:
+ for opt in sorted(keys):
default = option_dict[opt][0]
action = "store"
- if type(default) == types.BooleanType:
+ if type(default) == bool:
action = "store_true"
parser.add_option("--" + opt, default=default, action=action, dest=opt,
help=option_dict[opt][1])
if options.osx_cocoa:
configure_opts.append("--with-osx_cocoa")
- if options.mac_arch:
- configure_opts.append("--enable-macosx_arch=%s" % options.mac_arch)
-
wxpy_configure_opts = [
"--with-opengl",
"--enable-sound",
wxpy_configure_opts.append("--with-sdl")
wxpy_configure_opts.append("--with-gnomeprint")
- # Ensure that the Carbon build stays compatible back to 10.4 and
- # for the Cocoa build allow running on 10.5 and newer. We only add
- # them to the wxpy options because this is a hard-requirement for
- # wxPython, but other cases it is optional and is left up to the
- # developer. TODO: there should be a command line option to set
- # the SDK...
+ # Try to use use lowest available SDK back to 10.5. Both Carbon and
+ # Cocoa builds require at least the 10.5 SDK now. We only add it to
+ # the wxpy options because this is a hard-requirement for wxPython,
+ # but other cases it is optional and is left up to the developer.
+ # TODO: there should be a command line option to set the SDK...
if sys.platform.startswith("darwin"):
- if not options.osx_cocoa:
- wxpy_configure_opts.append(
- "--with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk")
- else:
- wxpy_configure_opts.append(
- "--with-macosx-sdk=/Developer/SDKs/MacOSX10.5.sdk")
-
+ for xcodePath in getXcodePaths():
+ sdks = [
+ xcodePath+"/SDKs/MacOSX10.5.sdk",
+ xcodePath+"/SDKs/MacOSX10.6.sdk",
+ xcodePath+"/SDKs/MacOSX10.7.sdk",
+ xcodePath+"/SDKs/MacOSX10.8.sdk",
+ ]
+
+ # use the lowest available sdk
+ for sdk in sdks:
+ if os.path.exists(sdk):
+ wxpy_configure_opts.append(
+ "--with-macosx-sdk=%s" % sdk)
+ break
if not options.mac_framework:
if installDir and not prefixDir:
# TODO: Should options.install be automatically turned on if the
# mac_framework flag is given?
- # The framework build is always a universal binary, unless we are
- # explicitly told to build only one architecture
- if not options.mac_arch:
- options.mac_universal_binary = True
-
# framework builds always need to be monolithic
if not "--enable-monolithic" in configure_opts:
configure_opts.append("--enable-monolithic")
# plus the framework specific dir structure.
prefixDir = getPrefixInFramework(options)
configure_opts.append("--prefix=" + prefixDir)
+
+ # the framework build adds symlinks above the installDir + prefixDir folder
+ # so we need to wipe from the framework root instead of inside the prefixDir.
+ frameworkRootDir = os.path.abspath(os.path.join(installDir + prefixDir, "..", ".."))
+ if os.path.exists(frameworkRootDir):
+ if os.path.exists(frameworkRootDir):
+ shutil.rmtree(frameworkRootDir)
if options.mac_universal_binary:
- configure_opts.append("--enable-universal_binary")
+ if options.mac_universal_binary == 'default':
+ if options.osx_cocoa:
+ configure_opts.append("--enable-universal_binary=i386,x86_64")
+ else:
+ configure_opts.append("--enable-universal_binary")
+ else:
+ configure_opts.append("--enable-universal_binary=%s" % options.mac_universal_binary)
- print "Configure options: " + `configure_opts`
+ print("Configure options: " + repr(configure_opts))
wxBuilder = builder.AutoconfBuilder()
if not options.no_config and not options.clean:
olddir = os.getcwd()
os.chdir(olddir)
if options.config_only:
- print "Exiting after configure"
+ print("Exiting after configure")
return
elif toolkit in ["msvc", "msvcProject"]:
flags = {}
buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw"))
- print "creating wx/msw/setup.h from setup0.h"
+ print("creating wx/msw/setup.h from setup0.h")
if options.unicode:
flags["wxUSE_UNICODE"] = "1"
if VERSION < (2,9):
flags["wxUSE_UNICODE_MSLU"] = "1"
if options.cairo:
+ if not os.environ.get("CAIRO_ROOT"):
+ print("WARNING: Expected CAIRO_ROOT set in the environment!")
flags["wxUSE_CAIRO"] = "1"
if options.wxpython:
if VERSION >= (2,9):
flags["wxUSE_UIACTIONSIMULATOR"] = "1"
-
+
mswIncludeDir = os.path.join(wxRootDir, "include", "wx", "msw")
setup0File = os.path.join(mswIncludeDir, "setup0.h")
for flag in flags:
setupText, subsMade = re.subn(flag + "\s+?\d", "%s %s" % (flag, flags[flag]), setupText)
if subsMade == 0:
- print "Flag %s wasn't found in setup0.h!" % flag
+ print("Flag %s wasn't found in setup0.h!" % flag)
sys.exit(1)
setupFile = open(os.path.join(mswIncludeDir, "setup.h"), "wb")
setupFile.close()
args = []
if toolkit == "msvc":
- print "setting build options..."
+ print("setting build options...")
args.append("-f makefile.vc")
if options.unicode:
args.append("UNICODE=1")
if options.wxpython:
args.append("OFFICIAL_BUILD=1")
+ args.append("COMPILER_VERSION=%s" % getVisCVersion())
args.append("SHARED=1")
args.append("MONOLITHIC=0")
args.append("USE_OPENGL=1")
args.append("BUILD=release")
else:
args.append("BUILD=debug")
+
+ if options.shared:
+ args.append("SHARED=1")
+
+ if options.cairo:
+ args.append(
+ "CPPFLAGS=/I%s" %
+ os.path.join(os.environ.get("CAIRO_ROOT", ""), 'include\\cairo'))
+
+ if options.jom:
+ nmakeCommand = 'jom.exe'
- wxBuilder = builder.MSVCBuilder()
+ wxBuilder = builder.MSVCBuilder(commandName=nmakeCommand)
if toolkit == "msvcProject":
args = []
if not wxBuilder:
- print "Builder not available for your specified platform/compiler."
+ print("Builder not available for your specified platform/compiler.")
sys.exit(1)
if options.clean:
- print "Performing cleanup."
- wxBuilder.clean()
-
- if options.wxpython:
- exitIfError(wxBuilder.clean(os.path.join(contribDir, "gizmos")), "Error building gizmos")
- exitIfError(wxBuilder.clean(os.path.join(contribDir, "stc")), "Error building stc")
+ print("Performing cleanup.")
+ wxBuilder.clean(dir=buildDir, options=args)
sys.exit(0)
if options.extra_make:
args.append(options.extra_make)
- args.append("--jobs=" + options.jobs)
+ if not sys.platform.startswith("win"):
+ args.append("--jobs=" + options.jobs)
exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building")
-
- if options.wxpython and os.path.exists(contribDir):
- exitIfError(wxBuilder.build(os.path.join(contribDir, "gizmos"), options=args), "Error building gizmos")
- exitIfError(wxBuilder.build(os.path.join(contribDir, "stc"),options=args), "Error building stc")
if options.install:
extra=None
if installDir:
extra = ['DESTDIR='+installDir]
- wxBuilder.install(dir=buildDir, options=extra)
-
- if options.wxpython and os.path.exists(contribDir):
- exitIfError(wxBuilder.install(os.path.join(contribDir, "gizmos"), options=extra), "Error building gizmos")
- exitIfError(wxBuilder.install(os.path.join(contribDir, "stc"), options=extra), "Error building stc")
-
+ wxBuilder.install(dir=buildDir, options=extra)
if options.install and options.mac_framework:
links.append(reallib)
reallib = "lib/" + os.readlink(reallib)
- #print "reallib is %s" % reallib
+ #print("reallib is %s" % reallib)
run("mv -f %s lib/%s.dylib" % (reallib, frameworkname))
for link in links:
frameworkRootDir = prefixDir
if installDir:
- print "installDir = %s" % installDir
+ print("installDir = %s" % installDir)
frameworkRootDir = installDir + prefixDir
os.chdir(frameworkRootDir)
build_string = ""
build_string = "d"
fwname = getFrameworkName(options)
- version = commands.getoutput("bin/wx-config --release")
- basename = commands.getoutput("bin/wx-config --basename")
- configname = commands.getoutput("bin/wx-config --selected-config")
-
- run("ln -s -f bin Resources")
+ version = getoutput("bin/wx-config --release")
+ version_full = getoutput("bin/wx-config --version")
+ basename = getoutput("bin/wx-config --basename")
+ configname = getoutput("bin/wx-config --selected-config")
+
+ os.makedirs("Resources")
+ wxplist = dict(
+ CFBundleDevelopmentRegion="English",
+ CFBundleIdentifier='org.wxwidgets.wxosxcocoa',
+ CFBundleName=fwname,
+ CFBundleVersion=version_full,
+ CFBundleExecutable=fwname,
+ CFBundleGetInfoString="%s %s" % (fwname, version_full),
+ CFBundlePackageType="FMWK",
+ CFBundleSignature="WXCO",
+ CFBundleShortVersionString=version_full,
+ CFBundleInfoDictionaryVersion="6.0",
+ )
+
+ import plistlib
+ plistlib.writePlist(wxplist, os.path.join(frameworkRootDir, "Resources", "Info.plist"))
# we make wx the "actual" library file and link to it from libwhatever.dylib
# so that things can link to wx and survive minor version changes
renameLibrary("lib/lib%s-%s.dylib" % (basename, version), fwname)
run("ln -s -f lib/%s.dylib %s" % (fwname, fwname))
- run("ln -s -f include/wx Headers")
+ run("ln -s -f include Headers")
for lib in ["GL", "STC", "Gizmos", "Gizmos_xrc"]:
libfile = "lib/lib%s_%s-%s.dylib" % (basename, lib.lower(), version)
headers = ""
header_dir = "wx-%s/wx" % version
for include in glob.glob(header_dir + "/*.h"):
- headers += "wx/" + os.path.basename(include) + "\n"
+ headers += "#include <wx/" + os.path.basename(include) + ">\n"
- framework_header = open("wx.h", "w")
+ framework_header = open("%s.h" % fwname, "w")
framework_header.write(header_template % headers)
framework_header.close()
run("ln -s -f %s wx" % header_dir)
- run("ln -s -f ../../../lib/wx/include/%s/wx/setup.h wx/setup.h" % configname)
+ os.chdir("wx-%s/wx" % version)
+ run("ln -s -f ../../../lib/wx/include/%s/wx/setup.h setup.h" % configname)
- os.chdir(os.path.join(frameworkRootDir, "..", ".."))
- run("ln -s -f %s Versions/Current" % getWxRelease())
+ os.chdir(os.path.join(frameworkRootDir, ".."))
+ run("ln -s -f %s Current" % getWxRelease())
+ os.chdir("..")
run("ln -s -f Versions/Current/Headers Headers")
run("ln -s -f Versions/Current/Resources Resources")
run("ln -s -f Versions/Current/%s %s" % (fwname, fwname))
file('lib/wx/config/%s' % configname, 'w').write(text)
# The framework is finished!
- print "wxWidgets framework created at: " + \
+ print("wxWidgets framework created at: " +
os.path.join( installDir,
options.mac_framework_prefix,
- '%s.framework' % fwname)
+ '%s.framework' % fwname))
# adjust the install_name if needed
os.makedirs(packagedir)
basename = os.path.basename(prefixDir.split(".")[0])
packageName = basename + "-" + getWxRelease()
- packageMakerPath = "/Developer/usr/bin/packagemaker "
+ packageMakerPath = getXcodePaths()[0]+"/usr/bin/packagemaker "
args = []
args.append("--root %s" % options.installdir)
args.append("--id org.wxwidgets.%s" % basename.lower())
args.append("--version %s" % getWxRelease())
args.append("--out %s" % os.path.join(packagedir, packageName + ".pkg"))
cmd = packageMakerPath + ' '.join(args)
- print "cmd = %s" % cmd
+ print("cmd = %s" % cmd)
run(cmd)
os.chdir(options.mac_distdir)
shutil.rmtree(packagedir)
-
-
if __name__ == '__main__':
exitWithException = False # use sys.exit instead
main(sys.argv[0], sys.argv[1:])