2010-06-25 16:53:39 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# Author: Kevin Ollivier
|
2010-07-13 09:29:13 -04:00
|
|
|
# Licence: wxWindows licence
|
2010-06-25 16:53:39 -04:00
|
|
|
###################################
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import builder
|
|
|
|
import commands
|
|
|
|
import glob
|
|
|
|
import optparse
|
|
|
|
import platform
|
|
|
|
import shutil
|
|
|
|
import types
|
2011-04-29 16:03:45 -04:00
|
|
|
import subprocess
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
# builder object
|
|
|
|
wxBuilder = None
|
|
|
|
|
|
|
|
# other globals
|
|
|
|
scriptDir = None
|
|
|
|
wxRootDir = None
|
|
|
|
contribDir = None
|
|
|
|
options = None
|
|
|
|
configure_opts = None
|
|
|
|
exitWithException = True
|
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
verbose = False
|
|
|
|
|
|
|
|
|
|
|
|
def numCPUs():
|
2011-04-28 02:08:47 -04:00
|
|
|
"""
|
|
|
|
Detects the number of CPUs on a system.
|
|
|
|
This approach is from detectCPUs here: http://www.artima.com/weblogs/viewpost.jsp?thread=230001
|
|
|
|
"""
|
|
|
|
# Linux, Unix and MacOS:
|
|
|
|
if hasattr(os, "sysconf"):
|
|
|
|
if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
|
|
|
|
# Linux & Unix:
|
|
|
|
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
|
|
|
|
if isinstance(ncpus, int) and ncpus > 0:
|
|
|
|
return ncpus
|
|
|
|
else: # OSX:
|
2011-04-29 16:03:45 -04:00
|
|
|
p = subprocess.Popen("sysctl -n hw.ncpu", shell=True, stdout=subprocess.PIPE)
|
|
|
|
return p.stdout.read()
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
# Windows:
|
|
|
|
if os.environ.has_key("NUMBER_OF_PROCESSORS"):
|
|
|
|
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
|
|
|
|
if ncpus > 0:
|
|
|
|
return ncpus
|
|
|
|
return 1 # Default
|
2011-04-26 13:39:53 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2012-02-07 18:57:00 -05:00
|
|
|
def getXcodePath():
|
|
|
|
p = subprocess.Popen("xcode-select -print-path", shell=True, stdout=subprocess.PIPE)
|
|
|
|
output = p.stdout.read()
|
|
|
|
return output.strip()
|
|
|
|
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
def exitIfError(code, msg):
|
|
|
|
if code != 0:
|
|
|
|
print msg
|
|
|
|
if exitWithException:
|
|
|
|
raise builder.BuildError, msg
|
|
|
|
else:
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
def getWxRelease(wxRoot=None):
|
|
|
|
if not wxRoot:
|
|
|
|
global wxRootDir
|
|
|
|
wxRoot = wxRootDir
|
|
|
|
|
|
|
|
configureText = open(os.path.join(wxRoot, "configure.in"), "r").read()
|
2010-06-25 16:53:39 -04:00
|
|
|
majorVersion = re.search("wx_major_version_number=(\d+)", configureText).group(1)
|
|
|
|
minorVersion = re.search("wx_minor_version_number=(\d+)", configureText).group(1)
|
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
versionText = "%s.%s" % (majorVersion, minorVersion)
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
if int(minorVersion) % 2:
|
|
|
|
releaseVersion = re.search("wx_release_number=(\d+)", configureText).group(1)
|
|
|
|
versionText += ".%s" % (releaseVersion)
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
return versionText
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
def getFrameworkName(options):
|
|
|
|
# the name of the framework is based on the wx port being built
|
|
|
|
name = "wxOSX"
|
|
|
|
if options.osx_cocoa:
|
|
|
|
name += "Cocoa"
|
|
|
|
else:
|
|
|
|
name += "Carbon"
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
|
def getPrefixInFramework(options, wxRoot=None):
|
|
|
|
# the path inside the framework that is the wx --prefix
|
|
|
|
fwPrefix = os.path.join(
|
|
|
|
os.path.abspath(options.mac_framework_prefix),
|
|
|
|
"%s.framework/Versions/%s" % (getFrameworkName(options), getWxRelease(wxRoot)))
|
|
|
|
return fwPrefix
|
|
|
|
|
|
|
|
|
2010-09-23 17:05:30 -04:00
|
|
|
def macFixupInstallNames(destdir, prefix, buildDir=None):
|
2010-06-25 16:53:39 -04:00
|
|
|
# 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.
|
2010-09-23 17:05:30 -04:00
|
|
|
print "**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir)
|
2010-06-25 16:53:39 -04:00
|
|
|
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
|
2011-04-26 13:39:53 -04:00
|
|
|
run(cmd)
|
2010-06-25 16:53:39 -04:00
|
|
|
for dep in dylibs:
|
2010-09-23 17:05:30 -04:00
|
|
|
if buildDir is not None:
|
|
|
|
cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
|
|
|
|
(buildDir,dep, prefix,dep, destdir+prefix,lib)
|
|
|
|
else:
|
|
|
|
cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
|
|
|
|
(destdir+prefix,dep, prefix,dep, destdir+prefix,lib)
|
2010-06-25 16:53:39 -04:00
|
|
|
print cmd
|
2011-04-26 13:39:53 -04:00
|
|
|
run(cmd)
|
2010-06-25 16:53:39 -04:00
|
|
|
os.chdir(pwd)
|
|
|
|
|
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
def run(cmd):
|
|
|
|
global verbose
|
|
|
|
if verbose:
|
|
|
|
print "Running %s" % cmd
|
|
|
|
return exitIfError(os.system(cmd), "Error running %s" % cmd)
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
def main(scriptName, args):
|
|
|
|
global scriptDir
|
|
|
|
global wxRootDir
|
|
|
|
global contribDir
|
|
|
|
global options
|
|
|
|
global configure_opts
|
|
|
|
global wxBuilder
|
|
|
|
|
|
|
|
scriptDir = os.path.dirname(os.path.abspath(scriptName))
|
|
|
|
wxRootDir = os.path.abspath(os.path.join(scriptDir, "..", ".."))
|
|
|
|
|
|
|
|
contribDir = os.path.join("contrib", "src")
|
|
|
|
installDir = None
|
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
VERSION = tuple([int(i) for i in getWxRelease().split('.')[:2]])
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
if sys.platform.startswith("win"):
|
|
|
|
contribDir = os.path.join(wxRootDir, "contrib", "build")
|
|
|
|
|
|
|
|
if sys.platform.startswith("win"):
|
|
|
|
toolkit = "msvc"
|
|
|
|
else:
|
|
|
|
toolkit = "autoconf"
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
defJobs = str(numCPUs())
|
|
|
|
defFwPrefix = '/Library/Frameworks'
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
option_dict = {
|
2011-04-28 02:08:47 -04:00
|
|
|
"clean" : (False, "Clean all files from the build directory"),
|
|
|
|
"debug" : (False, "Build the library in debug symbols"),
|
|
|
|
"builddir" : ("", "Directory where the build will be performed for autoconf builds."),
|
|
|
|
"prefix" : ("", "Configured prefix to use for autoconf builds. Defaults to installdir if set. Ignored for framework builds."),
|
|
|
|
"jobs" : (defJobs, "Number of jobs to run at one time in make. Default: %s" % defJobs),
|
|
|
|
"install" : (False, "Install the toolkit to the installdir directory, or the default dir."),
|
|
|
|
"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"),
|
2010-06-25 16:53:39 -04:00
|
|
|
"mac_framework" : (False, "Install the Mac build as a framework"),
|
2011-04-28 02:08:47 -04:00
|
|
|
"mac_framework_prefix"
|
|
|
|
: (defFwPrefix, "Prefix where the framework should be installed. Default: %s" % defFwPrefix),
|
2011-08-27 19:26:53 -04:00
|
|
|
"cairo" : (False, "Enable dynamicly loading the Cairo lib for wxGraphicsContext on MSW"),
|
2011-04-28 02:08:47 -04:00
|
|
|
"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"),
|
|
|
|
"unicode" : (False, "Build the library with unicode support"),
|
|
|
|
"wxpython" : (False, "Build the wxWidgets library with all options needed by wxPython"),
|
|
|
|
"cocoa" : (False, "Build the old Mac Cooca port."),
|
|
|
|
"osx_cocoa" : (False, "Build the new Cocoa port"),
|
|
|
|
"shared" : (False, "Build wx as a dynamic library"),
|
|
|
|
"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."),
|
2011-04-29 16:03:45 -04:00
|
|
|
"verbose" : (False, "Print commands as they are run, (to aid with debugging this script)"),
|
2010-06-25 16:53:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
|
2011-04-28 02:08:47 -04:00
|
|
|
|
|
|
|
keys = option_dict.keys()
|
|
|
|
keys.sort()
|
|
|
|
for opt in keys:
|
2010-06-25 16:53:39 -04:00
|
|
|
default = option_dict[opt][0]
|
|
|
|
action = "store"
|
|
|
|
if type(default) == types.BooleanType:
|
|
|
|
action = "store_true"
|
2011-04-28 02:08:47 -04:00
|
|
|
parser.add_option("--" + opt, default=default, action=action, dest=opt,
|
|
|
|
help=option_dict[opt][1])
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
options, arguments = parser.parse_args(args=args)
|
2011-04-29 16:03:45 -04:00
|
|
|
|
|
|
|
global verbose
|
|
|
|
if options.verbose:
|
|
|
|
verbose = True
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
# compiler / build system specific args
|
|
|
|
buildDir = options.builddir
|
2011-04-26 13:39:53 -04:00
|
|
|
args = []
|
2010-06-25 16:53:39 -04:00
|
|
|
installDir = options.installdir
|
|
|
|
prefixDir = options.prefix
|
|
|
|
|
|
|
|
if toolkit == "autoconf":
|
2010-09-23 17:05:30 -04:00
|
|
|
if not buildDir:
|
|
|
|
buildDir = os.getcwd()
|
2010-06-25 16:53:39 -04:00
|
|
|
configure_opts = []
|
|
|
|
if options.features != "":
|
|
|
|
configure_opts.extend(options.features.split(" "))
|
|
|
|
|
|
|
|
if options.unicode:
|
|
|
|
configure_opts.append("--enable-unicode")
|
|
|
|
|
|
|
|
if options.debug:
|
|
|
|
configure_opts.append("--enable-debug")
|
|
|
|
|
|
|
|
if options.cocoa:
|
2010-09-23 17:05:30 -04:00
|
|
|
configure_opts.append("--with-old_cocoa")
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
if options.osx_cocoa:
|
|
|
|
configure_opts.append("--with-osx_cocoa")
|
2010-09-23 17:05:30 -04:00
|
|
|
|
|
|
|
if options.mac_arch:
|
|
|
|
configure_opts.append("--enable-macosx_arch=%s" % options.mac_arch)
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
wxpy_configure_opts = [
|
|
|
|
"--with-opengl",
|
|
|
|
"--enable-sound",
|
|
|
|
"--enable-graphics_ctx",
|
|
|
|
"--enable-mediactrl",
|
|
|
|
"--enable-display",
|
|
|
|
"--enable-geometry",
|
|
|
|
"--enable-debug_flag",
|
|
|
|
"--enable-optimise",
|
|
|
|
"--disable-debugreport",
|
|
|
|
"--enable-uiactionsim",
|
|
|
|
]
|
|
|
|
|
|
|
|
if sys.platform.startswith("darwin"):
|
|
|
|
wxpy_configure_opts.append("--enable-monolithic")
|
|
|
|
else:
|
|
|
|
wxpy_configure_opts.append("--with-sdl")
|
|
|
|
wxpy_configure_opts.append("--with-gnomeprint")
|
|
|
|
|
2011-04-22 15:18:47 -04:00
|
|
|
# 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...
|
|
|
|
if sys.platform.startswith("darwin"):
|
2012-02-07 18:57:00 -05:00
|
|
|
xcodePath = getXcodePath()
|
2012-01-02 17:28:51 -05:00
|
|
|
sdks = [
|
2012-02-07 18:57:00 -05:00
|
|
|
xcodePath+"/SDKs/MacOSX10.5.sdk",
|
|
|
|
xcodePath+"/SDKs/MacOSX10.6.sdk",
|
|
|
|
xcodePath+"/SDKs/MacOSX10.7.sdk",
|
2012-01-02 17:28:51 -05:00
|
|
|
]
|
2011-04-22 15:18:47 -04:00
|
|
|
if not options.osx_cocoa:
|
2012-02-07 18:57:00 -05:00
|
|
|
sdks.insert(0, xcodePath+"/SDKs/MacOSX10.4u.sdk")
|
2012-01-02 17:28:51 -05:00
|
|
|
|
|
|
|
# use the lowest available sdk
|
|
|
|
for sdk in sdks:
|
|
|
|
if os.path.exists(sdk):
|
|
|
|
wxpy_configure_opts.append(
|
|
|
|
"--with-macosx-sdk=%s" % sdk)
|
|
|
|
break
|
2011-04-22 15:18:47 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
if not options.mac_framework:
|
|
|
|
if installDir and not prefixDir:
|
|
|
|
prefixDir = installDir
|
|
|
|
if prefixDir:
|
2011-04-28 02:08:47 -04:00
|
|
|
prefixDir = os.path.abspath(prefixDir)
|
2010-06-25 16:53:39 -04:00
|
|
|
configure_opts.append("--prefix=" + prefixDir)
|
2011-04-28 02:08:47 -04:00
|
|
|
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
if options.wxpython:
|
|
|
|
configure_opts.extend(wxpy_configure_opts)
|
|
|
|
if options.debug:
|
|
|
|
# wxPython likes adding these debug options too
|
|
|
|
configure_opts.append("--enable-debug_gdb")
|
|
|
|
configure_opts.append("--disable-optimise")
|
2011-04-28 02:08:47 -04:00
|
|
|
configure_opts.remove("--enable-optimise")
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
if options.rebake:
|
2011-04-26 13:39:53 -04:00
|
|
|
retval = run("make -f autogen.mk")
|
2010-06-25 16:53:39 -04:00
|
|
|
exitIfError(retval, "Error running autogen.mk")
|
|
|
|
|
|
|
|
if options.mac_framework:
|
2011-04-28 02:08:47 -04:00
|
|
|
# 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
|
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
# framework builds always need to be monolithic
|
|
|
|
if not "--enable-monolithic" in configure_opts:
|
|
|
|
configure_opts.append("--enable-monolithic")
|
2011-04-26 13:39:53 -04:00
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
# The --prefix given to configure will be the framework prefix
|
|
|
|
# plus the framework specific dir structure.
|
|
|
|
prefixDir = getPrefixInFramework(options)
|
2011-04-26 13:39:53 -04:00
|
|
|
configure_opts.append("--prefix=" + prefixDir)
|
2011-05-03 20:40:36 -04:00
|
|
|
|
|
|
|
# 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)
|
2011-04-26 13:39:53 -04:00
|
|
|
|
|
|
|
if options.mac_universal_binary:
|
|
|
|
configure_opts.append("--enable-universal_binary")
|
2011-04-28 02:08:47 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
print "Configure options: " + `configure_opts`
|
|
|
|
wxBuilder = builder.AutoconfBuilder()
|
2011-04-26 13:39:53 -04:00
|
|
|
if not options.no_config and not options.clean:
|
2010-06-25 16:53:39 -04:00
|
|
|
olddir = os.getcwd()
|
|
|
|
if buildDir:
|
|
|
|
os.chdir(buildDir)
|
|
|
|
exitIfError(wxBuilder.configure(dir=wxRootDir, options=configure_opts),
|
|
|
|
"Error running configure")
|
|
|
|
os.chdir(olddir)
|
2010-09-23 17:05:30 -04:00
|
|
|
|
|
|
|
if options.config_only:
|
|
|
|
print "Exiting after configure"
|
|
|
|
return
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
elif toolkit in ["msvc", "msvcProject"]:
|
|
|
|
flags = {}
|
|
|
|
buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw"))
|
2010-09-23 17:05:30 -04:00
|
|
|
|
|
|
|
print "creating wx/msw/setup.h from setup0.h"
|
2010-06-25 16:53:39 -04:00
|
|
|
if options.unicode:
|
|
|
|
flags["wxUSE_UNICODE"] = "1"
|
|
|
|
if VERSION < (2,9):
|
|
|
|
flags["wxUSE_UNICODE_MSLU"] = "1"
|
|
|
|
|
|
|
|
if options.cairo:
|
2011-08-27 19:26:53 -04:00
|
|
|
if not os.environ.get("CAIRO_ROOT"):
|
|
|
|
print "WARNING: Expected CAIRO_ROOT set in the environment!"
|
2010-06-25 16:53:39 -04:00
|
|
|
flags["wxUSE_CAIRO"] = "1"
|
|
|
|
|
|
|
|
if options.wxpython:
|
|
|
|
flags["wxDIALOG_UNIT_COMPATIBILITY "] = "0"
|
2010-09-23 17:05:30 -04:00
|
|
|
flags["wxUSE_DEBUGREPORT"] = "0"
|
2010-06-25 16:53:39 -04:00
|
|
|
flags["wxUSE_DIALUP_MANAGER"] = "0"
|
2010-09-23 17:05:30 -04:00
|
|
|
flags["wxUSE_GRAPHICS_CONTEXT"] = "1"
|
|
|
|
flags["wxUSE_DISPLAY"] = "1"
|
2010-06-25 16:53:39 -04:00
|
|
|
flags["wxUSE_GLCANVAS"] = "1"
|
|
|
|
flags["wxUSE_POSTSCRIPT"] = "1"
|
|
|
|
flags["wxUSE_AFM_FOR_POSTSCRIPT"] = "0"
|
|
|
|
flags["wxUSE_DATEPICKCTRL_GENERIC"] = "1"
|
2010-09-23 17:05:30 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
if VERSION < (2,9):
|
|
|
|
flags["wxUSE_DIB_FOR_BITMAP"] = "1"
|
|
|
|
|
|
|
|
if VERSION >= (2,9):
|
|
|
|
flags["wxUSE_UIACTIONSIMULATOR"] = "1"
|
2011-08-27 19:26:53 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
mswIncludeDir = os.path.join(wxRootDir, "include", "wx", "msw")
|
|
|
|
setup0File = os.path.join(mswIncludeDir, "setup0.h")
|
|
|
|
setupText = open(setup0File, "rb").read()
|
|
|
|
|
|
|
|
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
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
setupFile = open(os.path.join(mswIncludeDir, "setup.h"), "wb")
|
|
|
|
setupFile.write(setupText)
|
|
|
|
setupFile.close()
|
|
|
|
args = []
|
|
|
|
if toolkit == "msvc":
|
|
|
|
print "setting build options..."
|
|
|
|
args.append("-f makefile.vc")
|
|
|
|
if options.unicode:
|
|
|
|
args.append("UNICODE=1")
|
|
|
|
if VERSION < (2,9):
|
|
|
|
args.append("MSLU=1")
|
|
|
|
|
|
|
|
if options.wxpython:
|
|
|
|
args.append("OFFICIAL_BUILD=1")
|
|
|
|
args.append("SHARED=1")
|
|
|
|
args.append("MONOLITHIC=0")
|
|
|
|
args.append("USE_OPENGL=1")
|
|
|
|
args.append("USE_GDIPLUS=1")
|
|
|
|
|
|
|
|
if not options.debug:
|
|
|
|
args.append("BUILD=release")
|
|
|
|
else:
|
|
|
|
args.append("BUILD=debug")
|
2011-05-31 15:16:55 -04:00
|
|
|
|
|
|
|
if options.shared:
|
|
|
|
args.append("SHARED=1")
|
2011-08-27 19:26:53 -04:00
|
|
|
|
2011-05-31 15:16:55 -04:00
|
|
|
if options.cairo:
|
2011-08-27 19:26:53 -04:00
|
|
|
args.append(
|
|
|
|
"CPPFLAGS=/I%s" %
|
|
|
|
os.path.join(os.environ.get("CAIRO_ROOT", ""), 'include\\cairo'))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
wxBuilder = builder.MSVCBuilder()
|
|
|
|
|
|
|
|
if toolkit == "msvcProject":
|
|
|
|
args = []
|
|
|
|
if options.shared or options.wxpython:
|
|
|
|
args.append("wx_dll.dsw")
|
|
|
|
else:
|
|
|
|
args.append("wx.dsw")
|
|
|
|
|
|
|
|
# TODO:
|
|
|
|
wxBuilder = builder.MSVCProjectBuilder()
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
if not wxBuilder:
|
|
|
|
print "Builder not available for your specified platform/compiler."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if options.clean:
|
|
|
|
print "Performing cleanup."
|
2011-05-31 15:16:55 -04:00
|
|
|
wxBuilder.clean(dir=buildDir, options=args)
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
sys.exit(0)
|
2011-04-26 13:39:53 -04:00
|
|
|
|
|
|
|
if options.extra_make:
|
|
|
|
args.append(options.extra_make)
|
2011-04-28 02:08:47 -04:00
|
|
|
|
2011-05-03 20:40:36 -04:00
|
|
|
if not sys.platform.startswith("win"):
|
|
|
|
args.append("--jobs=" + options.jobs)
|
2011-04-26 13:39:53 -04:00
|
|
|
exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building")
|
|
|
|
|
|
|
|
if options.install:
|
|
|
|
extra=None
|
|
|
|
if installDir:
|
|
|
|
extra = ['DESTDIR='+installDir]
|
2011-05-31 15:16:55 -04:00
|
|
|
wxBuilder.install(dir=buildDir, options=extra)
|
2011-04-28 02:08:47 -04:00
|
|
|
|
|
|
|
if options.install and options.mac_framework:
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
def renameLibrary(libname, frameworkname):
|
|
|
|
reallib = libname
|
|
|
|
links = []
|
|
|
|
while os.path.islink(reallib):
|
|
|
|
links.append(reallib)
|
|
|
|
reallib = "lib/" + os.readlink(reallib)
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
#print "reallib is %s" % reallib
|
2011-04-26 13:39:53 -04:00
|
|
|
run("mv -f %s lib/%s.dylib" % (reallib, frameworkname))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
for link in links:
|
2011-04-26 13:39:53 -04:00
|
|
|
run("ln -s -f %s.dylib %s" % (frameworkname, link))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
frameworkRootDir = prefixDir
|
|
|
|
if installDir:
|
|
|
|
print "installDir = %s" % installDir
|
|
|
|
frameworkRootDir = installDir + prefixDir
|
|
|
|
os.chdir(frameworkRootDir)
|
2010-06-25 16:53:39 -04:00
|
|
|
build_string = ""
|
|
|
|
if options.debug:
|
|
|
|
build_string = "d"
|
2011-04-26 13:39:53 -04:00
|
|
|
|
2011-04-29 16:03:45 -04:00
|
|
|
fwname = getFrameworkName(options)
|
2010-06-25 16:53:39 -04:00
|
|
|
version = commands.getoutput("bin/wx-config --release")
|
2011-05-03 20:40:36 -04:00
|
|
|
version_full = commands.getoutput("bin/wx-config --version")
|
2010-06-25 16:53:39 -04:00
|
|
|
basename = commands.getoutput("bin/wx-config --basename")
|
|
|
|
configname = commands.getoutput("bin/wx-config --selected-config")
|
2011-05-03 20:40:36 -04:00
|
|
|
|
|
|
|
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"))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
# 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
|
2011-04-29 16:03:45 -04:00
|
|
|
renameLibrary("lib/lib%s-%s.dylib" % (basename, version), fwname)
|
|
|
|
run("ln -s -f lib/%s.dylib %s" % (fwname, fwname))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-05-03 20:40:36 -04:00
|
|
|
run("ln -s -f include Headers")
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
for lib in ["GL", "STC", "Gizmos", "Gizmos_xrc"]:
|
|
|
|
libfile = "lib/lib%s_%s-%s.dylib" % (basename, lib.lower(), version)
|
|
|
|
if os.path.exists(libfile):
|
|
|
|
frameworkDir = "framework/wx%s/%s" % (lib, version)
|
|
|
|
if not os.path.exists(frameworkDir):
|
|
|
|
os.makedirs(frameworkDir)
|
|
|
|
renameLibrary(libfile, "wx" + lib)
|
2011-04-26 13:39:53 -04:00
|
|
|
run("ln -s -f ../../../%s %s/wx%s" % (libfile, frameworkDir, lib))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
for lib in glob.glob("lib/*.dylib"):
|
|
|
|
if not os.path.islink(lib):
|
|
|
|
corelibname = "lib/lib%s-%s.0.dylib" % (basename, version)
|
2011-04-26 13:39:53 -04:00
|
|
|
run("install_name_tool -id %s %s" % (os.path.join(prefixDir, lib), lib))
|
|
|
|
run("install_name_tool -change %s %s %s" % (os.path.join(frameworkRootDir, corelibname), os.path.join(prefixDir, corelibname), lib))
|
2011-04-29 16:03:45 -04:00
|
|
|
|
2010-06-25 16:53:39 -04:00
|
|
|
os.chdir("include")
|
|
|
|
|
2011-04-28 02:08:47 -04:00
|
|
|
header_template = """
|
2010-06-25 16:53:39 -04:00
|
|
|
#ifndef __WX_FRAMEWORK_HEADER__
|
|
|
|
#define __WX_FRAMEWORK_HEADER__
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
#endif // __WX_FRAMEWORK_HEADER__
|
|
|
|
"""
|
|
|
|
headers = ""
|
|
|
|
header_dir = "wx-%s/wx" % version
|
|
|
|
for include in glob.glob(header_dir + "/*.h"):
|
2011-05-03 20:40:36 -04:00
|
|
|
headers += "#include <wx/" + os.path.basename(include) + ">\n"
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-05-03 20:40:36 -04:00
|
|
|
framework_header = open("%s.h" % fwname, "w")
|
2010-06-25 16:53:39 -04:00
|
|
|
framework_header.write(header_template % headers)
|
|
|
|
framework_header.close()
|
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
run("ln -s -f %s wx" % header_dir)
|
2011-05-03 20:40:36 -04:00
|
|
|
os.chdir("wx-%s/wx" % version)
|
|
|
|
run("ln -s -f ../../../lib/wx/include/%s/wx/setup.h setup.h" % configname)
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-05-03 20:40:36 -04:00
|
|
|
os.chdir(os.path.join(frameworkRootDir, ".."))
|
|
|
|
run("ln -s -f %s Current" % getWxRelease())
|
|
|
|
os.chdir("..")
|
2011-04-26 13:39:53 -04:00
|
|
|
run("ln -s -f Versions/Current/Headers Headers")
|
|
|
|
run("ln -s -f Versions/Current/Resources Resources")
|
2011-04-29 16:03:45 -04:00
|
|
|
run("ln -s -f Versions/Current/%s %s" % (fwname, fwname))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
# sanity check to ensure the symlink works
|
2011-04-28 02:08:47 -04:00
|
|
|
os.chdir("Versions/Current")
|
2011-04-29 16:03:45 -04:00
|
|
|
|
|
|
|
# put info about the framework into wx-config
|
|
|
|
os.chdir(frameworkRootDir)
|
|
|
|
text = file('lib/wx/config/%s' % configname).read()
|
|
|
|
text = text.replace("MAC_FRAMEWORK=", "MAC_FRAMEWORK=%s" % getFrameworkName(options))
|
|
|
|
if options.mac_framework_prefix not in ['/Library/Frameworks',
|
|
|
|
'/System/Library/Frameworks']:
|
|
|
|
text = text.replace("MAC_FRAMEWORK_PREFIX=",
|
|
|
|
"MAC_FRAMEWORK_PREFIX=%s" % options.mac_framework_prefix)
|
|
|
|
file('lib/wx/config/%s' % configname, 'w').write(text)
|
|
|
|
|
|
|
|
# The framework is finished!
|
2011-04-28 02:08:47 -04:00
|
|
|
print "wxWidgets framework created at: " + \
|
|
|
|
os.path.join( installDir,
|
|
|
|
options.mac_framework_prefix,
|
2011-04-29 16:03:45 -04:00
|
|
|
'%s.framework' % fwname)
|
2011-04-28 02:08:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
# adjust the install_name if needed
|
2010-06-25 16:53:39 -04:00
|
|
|
if sys.platform.startswith("darwin") and \
|
|
|
|
options.install and \
|
|
|
|
options.installdir and \
|
2011-04-28 02:08:47 -04:00
|
|
|
not options.mac_framework and \
|
2010-06-25 16:53:39 -04:00
|
|
|
not options.wxpython: # wxPython's build will do this later if needed
|
2011-04-26 13:39:53 -04:00
|
|
|
if not prefixDir:
|
|
|
|
prefixDir = '/usr/local'
|
|
|
|
macFixupInstallNames(options.installdir, prefixDir)#, buildDir)
|
|
|
|
|
|
|
|
# make a package if a destdir was set.
|
|
|
|
if options.mac_framework and \
|
2011-04-28 02:08:47 -04:00
|
|
|
options.install and \
|
2011-04-26 13:39:53 -04:00
|
|
|
options.installdir and \
|
|
|
|
options.mac_distdir:
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
if os.path.exists(options.mac_distdir):
|
|
|
|
shutil.rmtree(options.mac_distdir)
|
|
|
|
|
|
|
|
packagedir = os.path.join(options.mac_distdir, "packages")
|
|
|
|
os.makedirs(packagedir)
|
|
|
|
basename = os.path.basename(prefixDir.split(".")[0])
|
|
|
|
packageName = basename + "-" + getWxRelease()
|
2012-02-07 18:57:00 -05:00
|
|
|
packageMakerPath = getXcodePath()+"/usr/bin/packagemaker "
|
2011-04-26 13:39:53 -04:00
|
|
|
args = []
|
|
|
|
args.append("--root %s" % options.installdir)
|
|
|
|
args.append("--id org.wxwidgets.%s" % basename.lower())
|
|
|
|
args.append("--title %s" % packageName)
|
|
|
|
args.append("--version %s" % getWxRelease())
|
|
|
|
args.append("--out %s" % os.path.join(packagedir, packageName + ".pkg"))
|
|
|
|
cmd = packageMakerPath + ' '.join(args)
|
|
|
|
print "cmd = %s" % cmd
|
|
|
|
run(cmd)
|
|
|
|
|
|
|
|
os.chdir(options.mac_distdir)
|
|
|
|
|
|
|
|
run('hdiutil create -srcfolder %s -volname "%s" -imagekey zlib-level=9 %s.dmg' % (packagedir, packageName, packageName))
|
2010-06-25 16:53:39 -04:00
|
|
|
|
2011-04-26 13:39:53 -04:00
|
|
|
shutil.rmtree(packagedir)
|
2010-06-25 16:53:39 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
exitWithException = False # use sys.exit instead
|
|
|
|
main(sys.argv[0], sys.argv[1:])
|
|
|
|
|