示例#1
0
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

    VERSION = tuple([int(i) for i in getWxRelease().split('.')[:2]])

    if sys.platform.startswith("win"):
        contribDir = os.path.join(wxRootDir, "contrib", "build")

    if sys.platform.startswith("win"):
        toolkit = "msvc"
    else:
        toolkit = "autoconf"

    defJobs = str(numCPUs())
    defFwPrefix = '/Library/Frameworks'

    option_dict = {
        "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"),
        "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"),
        "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."
         ),
        "verbose":
        (False,
         "Print commands as they are run, (to aid with debugging this script)"
         ),
    }

    parser = optparse.OptionParser(usage="usage: %prog [options]",
                                   version="%prog 1.0")

    keys = option_dict.keys()
    keys.sort()
    for opt in keys:
        default = option_dict[opt][0]
        action = "store"
        if type(default) == types.BooleanType:
            action = "store_true"
        parser.add_option("--" + opt,
                          default=default,
                          action=action,
                          dest=opt,
                          help=option_dict[opt][1])

    options, arguments = parser.parse_args(args=args)

    global verbose
    if options.verbose:
        verbose = True

    # compiler / build system specific args
    buildDir = options.builddir
    args = []
    installDir = options.installdir
    prefixDir = options.prefix

    if toolkit == "autoconf":
        if not buildDir:
            buildDir = os.getcwd()
        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:
            configure_opts.append("--with-old_cocoa")

        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",
            "--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")

        # 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"):
            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")

        if not options.mac_framework:
            if installDir and not prefixDir:
                prefixDir = installDir
            if prefixDir:
                prefixDir = os.path.abspath(prefixDir)
                configure_opts.append("--prefix=" + prefixDir)

        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")
                configure_opts.remove("--enable-optimise")

        if options.rebake:
            retval = run("make -f autogen.mk")
            exitIfError(retval, "Error running autogen.mk")

        if options.mac_framework:
            # 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")

            # The --prefix given to configure will be the framework prefix
            # 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")

        print "Configure options: " + ` configure_opts `
        wxBuilder = builder.AutoconfBuilder()
        if not options.no_config and not options.clean:
            olddir = os.getcwd()
            if buildDir:
                os.chdir(buildDir)
            exitIfError(
                wxBuilder.configure(dir=wxRootDir, options=configure_opts),
                "Error running configure")
            os.chdir(olddir)

        if options.config_only:
            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"
        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:
            flags["wxDIALOG_UNIT_COMPATIBILITY "] = "0"
            flags["wxUSE_DEBUGREPORT"] = "0"
            flags["wxUSE_DIALUP_MANAGER"] = "0"
            flags["wxUSE_GRAPHICS_CONTEXT"] = "1"
            flags["wxUSE_DISPLAY"] = "1"
            flags["wxUSE_GLCANVAS"] = "1"
            flags["wxUSE_POSTSCRIPT"] = "1"
            flags["wxUSE_AFM_FOR_POSTSCRIPT"] = "0"
            flags["wxUSE_DATEPICKCTRL_GENERIC"] = "1"

            if VERSION < (2, 9):
                flags["wxUSE_DIB_FOR_BITMAP"] = "1"

            if VERSION >= (2, 9):
                flags["wxUSE_UIACTIONSIMULATOR"] = "1"

        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")

            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'))

            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()

    if not wxBuilder:
        print "Builder not available for your specified platform/compiler."
        sys.exit(1)

    if options.clean:
        print "Performing cleanup."
        wxBuilder.clean(dir=buildDir, options=args)

        sys.exit(0)

    if options.extra_make:
        args.append(options.extra_make)

    if not sys.platform.startswith("win"):
        args.append("--jobs=" + options.jobs)
    exitIfError(wxBuilder.build(dir=buildDir, options=args), "Error building")

    if options.install:
        extra = None
        if installDir:
            extra = ['DESTDIR=' + installDir]
        wxBuilder.install(dir=buildDir, options=extra)

    if options.install and options.mac_framework:

        def renameLibrary(libname, frameworkname):
            reallib = libname
            links = []
            while os.path.islink(reallib):
                links.append(reallib)
                reallib = "lib/" + os.readlink(reallib)

            #print "reallib is %s" % reallib
            run("mv -f %s lib/%s.dylib" % (reallib, frameworkname))

            for link in links:
                run("ln -s -f %s.dylib %s" % (frameworkname, link))

        frameworkRootDir = prefixDir
        if installDir:
            print "installDir = %s" % installDir
            frameworkRootDir = installDir + prefixDir
        os.chdir(frameworkRootDir)
        build_string = ""
        if options.debug:
            build_string = "d"

        fwname = getFrameworkName(options)
        version = commands.getoutput("bin/wx-config --release")
        version_full = commands.getoutput("bin/wx-config --version")
        basename = commands.getoutput("bin/wx-config --basename")
        configname = commands.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 Headers")

        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)
                run("ln -s -f ../../../%s %s/wx%s" %
                    (libfile, frameworkDir, lib))

        for lib in glob.glob("lib/*.dylib"):
            if not os.path.islink(lib):
                corelibname = "lib/lib%s-%s.0.dylib" % (basename, version)
                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))

        os.chdir("include")

        header_template = """        
#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"):
            headers += "#include <wx/" + os.path.basename(include) + ">\n"

        framework_header = open("%s.h" % fwname, "w")
        framework_header.write(header_template % headers)
        framework_header.close()

        run("ln -s -f %s wx" % header_dir)
        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 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))

        # sanity check to ensure the symlink works
        os.chdir("Versions/Current")

        # 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!
        print "wxWidgets framework created at: " + \
              os.path.join( installDir,
                            options.mac_framework_prefix,
                            '%s.framework' % fwname)

    # adjust the install_name if needed
    if sys.platform.startswith("darwin") and \
           options.install and \
           options.installdir and \
           not options.mac_framework and \
           not options.wxpython:  # wxPython's build will do this later if needed
        if not prefixDir:
            prefixDir = '/usr/local'
        macFixupInstallNames(options.installdir, prefixDir)  #, buildDir)

    # make a package if a destdir was set.
    if options.mac_framework and \
            options.install and \
            options.installdir and \
            options.mac_distdir:

        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()
        packageMakerPath = "/Developer/usr/bin/packagemaker "
        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))

        shutil.rmtree(packagedir)
示例#2
0
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

    VERSION = tuple([int(i) for i in getWxRelease().split('.')])

    if sys.platform.startswith("win"):
        contribDir = os.path.join(wxRootDir, "contrib", "build")

    if sys.platform.startswith("win"):
        toolkit = "msvc"
    else:
        toolkit = "autoconf"

    option_dict = {
        "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."
         ),
        "install":
        (False,
         "Install the toolkit to the installdir directory, or the default dir."
         ),
        "installdir": ("",
                       "Directory where built wxWidgets will be installed"),
        "mac_universal_binary": (False,
                                 "Build Mac version as a universal binary"),
        "mac_lipo":
        (False,
         "EXPERIMENTAL: Create a universal binary by merging a PPC and Intel build together."
         ),
        "mac_framework": (False, "Install the Mac build as a framework"),
        "no_config": (False, "Turn off configure step on autoconf builds"),
        "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 Cooca port (Mac only currently)."),
        "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."
         ),
    }

    parser = optparse.OptionParser(usage="usage: %prog [options]",
                                   version="%prog 1.0")

    for opt in option_dict:
        default = option_dict[opt][0]

        action = "store"
        if type(default) == types.BooleanType:
            action = "store_true"
        parser.add_option("--" + opt,
                          default=default,
                          action=action,
                          dest=opt,
                          help=option_dict[opt][1])

    options, arguments = parser.parse_args(args=args)

    # compiler / build system specific args
    buildDir = options.builddir
    args = None
    installDir = options.installdir
    prefixDir = options.prefix

    if toolkit == "autoconf":
        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.mac_universal_binary:
            configure_opts.append("--enable-universal_binary")

        if options.cocoa:
            configure_opts.append("--with-cocoa")

        if options.osx_cocoa:
            configure_opts.append("--with-osx_cocoa")

        wxpy_configure_opts = [
            "--with-opengl",
            "--enable-sound",
            "--enable-graphics_ctx",
            "--enable-mediactrl",
            "--enable-display",
            "--enable-geometry",
            "--enable-debug_flag",
            "--enable-optimise",
            "--disable-debugreport",
        ]

        if sys.platform.startswith("darwin"):
            wxpy_configure_opts.append("--enable-monolithic")
        else:
            wxpy_configure_opts.append("--with-sdl")
            wxpy_configure_opts.append("--with-gnomeprint")

        if not options.mac_framework:
            if installDir and not prefixDir:
                prefixDir = installDir
            if prefixDir:
                configure_opts.append("--prefix=" + prefixDir)

        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")

        if options.rebake:
            retval = os.system("make -f autogen.mk")
            exitIfError(retval, "Error running autogen.mk")

        if options.mac_framework:
            # Framework build is always a universal binary
            options.mac_lipo = True
            name = "wx"
            if options.osx_cocoa:
                name += "OSXCocoa"
            installDir = "/Library/Frameworks/%s.framework/Versions/%s" % (
                name, getWxRelease())
            configure_opts.append("--prefix=" + installDir)
            # framework builds always need to be monolithic
            if not "--enable-monolithic" in configure_opts:
                configure_opts.append("--enable-monolithic")

        print "Configure options: " + ` configure_opts `
        wxBuilder = builder.AutoconfBuilder()
        if not options.no_config and not options.clean and not options.mac_lipo:
            olddir = os.getcwd()
            if buildDir:
                os.chdir(buildDir)
            exitIfError(
                wxBuilder.configure(dir=wxRootDir, options=configure_opts),
                "Error running configure")
            os.chdir(olddir)

    elif toolkit in ["msvc", "msvcProject"]:
        flags = {}
        buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw"))

        if options.unicode:
            flags["wxUSE_UNICODE"] = "1"
            if VERSION < (2, 9):
                flags["wxUSE_UNICODE_MSLU"] = "1"

        if options.cairo:
            flags["wxUSE_CAIRO"] = "1"

        if options.wxpython:
            flags["wxDIALOG_UNIT_COMPATIBILITY "] = "0"
            flags["wxUSE_DEBUG_CONTEXT"] = "1"
            flags["wxUSE_MEMORY_TRACING"] = "1"
            flags["wxUSE_DIALUP_MANAGER"] = "0"
            flags["wxUSE_GLCANVAS"] = "1"
            flags["wxUSE_POSTSCRIPT"] = "1"
            flags["wxUSE_AFM_FOR_POSTSCRIPT"] = "0"
            flags["wxUSE_DISPLAY"] = "1"
            flags["wxUSE_DEBUGREPORT"] = "0"
            flags["wxUSE_GRAPHICS_CONTEXT"] = "1"
            flags["wxUSE_DATEPICKCTRL_GENERIC"] = "1"
            if VERSION < (2, 9):
                flags["wxUSE_DIB_FOR_BITMAP"] = "1"

            # setup the wxPython 'hybrid' build
            if not options.debug:
                flags["wxUSE_MEMORY_TRACING"] = "0"
                flags["wxUSE_DEBUG_CONTEXT"] = "0"

        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")
                args.append("CXXFLAGS=/D__NO_VC_CRTDBG__")

                if not options.debug:
                    # "Hybrid" build, not really release or debug
                    args.append("DEBUG_FLAG=1")
                    args.append("WXDEBUGFLAG=h")
                    args.append("BUILD=release")
                else:
                    args.append("BUILD=debug")

            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()

    if not wxBuilder:
        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")

        sys.exit(0)

    isLipo = False
    if options.mac_lipo:
        if options.mac_universal_binary:
            print "WARNING: Cannot specify both mac_lipo and mac_universal_binary, as they conflict."
            print "         Using mac_universal_binary..."
        else:
            isLipo = True
            # TODO: Add 64-bit when we're building OS X Cocoa

            # 2.8, use gcc 3.3 on PPC for 10.3 support, but only when building ...
            macVersion = platform.mac_ver()[0]
            isLeopard = macVersion.find("10.5") != -1

            if not isLeopard and os.path.exists(
                    os.path.join(wxRootDir, contribDir)):
                # Building wx 2.8 so make the ppc build compatible with Panther
                doMacLipoBuild("ppc",
                               buildDir,
                               installDir,
                               cxxcompiler="g++-3.3",
                               cccompiler="gcc-3.3",
                               target="10.3",
                               flags="-DMAC_OS_X_VERSION_MAX_ALLOWED=1040")
            else:
                doMacLipoBuild("ppc", buildDir, installDir)

            doMacLipoBuild("i386", buildDir, installDir)

            # Change the install_names to not include the arch folder we built
            # in. Do this before the lipo because on Tiger the linker looks at
            # the install_names of the arch-specfic part of the fat dylib...
            doMacFixupInstallName('ppc', installDir + '/ppc/lib', installDir)
            doMacFixupInstallName('i386', installDir + '/i386/lib', installDir)

            # Use lipo to merge together all binaries in the install dirs, and
            # also copies all other files and links it finds to the new destination.
            result = os.system(
                "python %s/distrib/scripts/mac/lipo-dir.py %s %s %s" %
                (wxRootDir, installDir + "/ppc", installDir + "/i386",
                 installDir))

            # tweak the wx-config script
            fname = os.path.abspath(installDir + '/bin/wx-config')
            data = open(fname).read()
            data = data.replace('ppc/', '')
            data = data.replace('i386/', '')
            open(fname, 'w').write(data)

            shutil.rmtree(installDir + "/ppc")
            shutil.rmtree(installDir + "/i386")

    if not isLipo:
        if options.extra_make:
            args.append(options.extra_make)
        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 = ['prefix=' + installDir]
            wxBuilder.install(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")

    if options.mac_framework:

        def renameLibrary(libname, frameworkname):
            reallib = libname
            links = []
            while os.path.islink(reallib):
                links.append(reallib)
                reallib = "lib/" + os.readlink(reallib)

            print "reallib is %s" % reallib
            os.system("mv -f %s lib/%s.dylib" % (reallib, frameworkname))

            for link in links:
                os.system("ln -s -f %s.dylib %s" % (frameworkname, link))

        os.chdir(installDir)
        build_string = ""
        if options.debug:
            build_string = "d"
        version = commands.getoutput("bin/wx-config --release")
        basename = commands.getoutput("bin/wx-config --basename")
        configname = commands.getoutput("bin/wx-config --selected-config")

        os.system("ln -s -f bin Resources")

        # 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), "wx")
        os.system("ln -s -f lib/wx.dylib wx")

        os.system("ln -s -f include/wx Headers")

        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)
                os.system("ln -s -f ../../../%s %s/wx%s" %
                          (libfile, frameworkDir, lib))

        for lib in glob.glob("lib/*.dylib"):
            if not os.path.islink(lib):
                corelibname = "lib/lib%s-%s.0.dylib" % (basename, version)
                os.system("install_name_tool -id %s %s" %
                          (os.path.join(installDir, lib), lib))
                os.system("install_name_tool -change %s %s %s" %
                          (os.path.join(installDir, "i386", corelibname),
                           os.path.join(installDir, corelibname), lib))

        os.chdir("include")

        header_template = """
        
#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"):
            headers += "wx/" + os.path.basename(include) + "\n"

        framework_header = open("wx.h", "w")
        framework_header.write(header_template % headers)
        framework_header.close()

        os.system("ln -s -f %s wx" % header_dir)
        os.system("ln -s -f ../../../lib/wx/include/%s/wx/setup.h wx/setup.h" %
                  configname)

        os.chdir(os.path.join(installDir, "..", ".."))
        os.system("ln -s -f %s Versions/Current" %
                  os.path.basename(installDir))
        os.system("ln -s -f Versions/Current/Headers Headers")
        os.system("ln -s -f Versions/Current/Resources Resources")
        os.system("ln -s -f Versions/Current/wx wx")