]> git.saurik.com Git - wxWidgets.git/blobdiff - build/tools/build-wxwidgets.py
Minor fixes to wxDateTime documentation.
[wxWidgets.git] / build / tools / build-wxwidgets.py
index ed00782626aafaa95b2fda33238e1deb8ea61807..a0866e4b2cc02f4547cb546c64a5be4c7ad13caa 100755 (executable)
@@ -15,6 +15,7 @@ import optparse
 import platform
 import shutil
 import types
+import subprocess
 
 # builder object
 wxBuilder = None
@@ -31,25 +32,33 @@ verbose = False
 
 
 def numCPUs():
- """
- 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:
-         return int(os.popen2("sysctl -n hw.ncpu")[1].read())
- # Windows:
- if os.environ.has_key("NUMBER_OF_PROCESSORS"):
-         ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
-         if ncpus > 0:
-             return ncpus
- return 1 # Default
+    """
+    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:
+            p = subprocess.Popen("sysctl -n hw.ncpu", shell=True, stdout=subprocess.PIPE)
+            return p.stdout.read()
+            
+    # Windows:
+    if os.environ.has_key("NUMBER_OF_PROCESSORS"):
+            ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
+            if ncpus > 0:
+                return ncpus
+    return 1 # Default
+
+
+def getXcodePath():
+    p = subprocess.Popen("xcode-select -print-path", shell=True, stdout=subprocess.PIPE)
+    output = p.stdout.read()
+    return output.strip()
 
 
 def exitIfError(code, msg):
@@ -61,10 +70,12 @@ def exitIfError(code, msg):
             sys.exit(1)
      
             
-def getWxRelease():
-    global wxRootDir
-    configureText = open(os.path.join(wxRootDir, "configure.in"), "r").read()
-    
+def getWxRelease(wxRoot=None):
+    if not wxRoot:
+        global wxRootDir
+        wxRoot = wxRootDir
+        
+    configureText = open(os.path.join(wxRoot, "configure.in"), "r").read()
     majorVersion = re.search("wx_major_version_number=(\d+)", configureText).group(1)
     minorVersion = re.search("wx_minor_version_number=(\d+)", configureText).group(1)
     
@@ -77,6 +88,24 @@ def getWxRelease():
     return versionText
 
 
+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
+
+
 def macFixupInstallNames(destdir, prefix, buildDir=None):
     # When an installdir is used then the install_names embedded in
     # the dylibs are not correct.  Reset the IDs and the dependencies
@@ -108,6 +137,7 @@ def run(cmd):
         print "Running %s" % cmd
     return exitIfError(os.system(cmd), "Error running %s" % cmd)
 
+
 def main(scriptName, args):
     global scriptDir
     global wxRootDir
@@ -132,43 +162,56 @@ def main(scriptName, args):
     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."),
-        "j"          : (repr(numCPUs()), "Number of jobs to run at one time."),
-        "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"),
+        "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"),
-        "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 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."),
+        "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")
-    
-    for opt in option_dict:
+
+    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])
+        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 = []
@@ -223,51 +266,71 @@ def main(scriptName, args):
         # developer.  TODO: there should be a command line option to set
         # the SDK...
         if sys.platform.startswith("darwin"):
+            xcodePath = getXcodePath()
+            sdks = [
+                xcodePath+"/SDKs/MacOSX10.5.sdk",
+                xcodePath+"/SDKs/MacOSX10.6.sdk",
+                xcodePath+"/SDKs/MacOSX10.7.sdk",
+            ]
             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")
-
+                sdks.insert(0, xcodePath+"/SDKs/MacOSX10.4u.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:
                 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:
-            # Framework build is always a universal binary
-            options.mac_universal_binary = True
-            name = "wxOSX"
-            if options.osx_cocoa:
-                name += "Cocoa"
-            else:
-                name += "Carbon"
-            prefixDir = "/Library/Frameworks/%s.framework/Versions/%s" % (name, getWxRelease())
+            # 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")
 
-        if installDir and not prefixDir:
-            prefixDir = installDir
-        if prefixDir:
+            # 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()
@@ -294,6 +357,8 @@ def main(scriptName, args):
                 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:
@@ -312,7 +377,7 @@ def main(scriptName, args):
 
             if VERSION >= (2,9):
                 flags["wxUSE_UIACTIONSIMULATOR"] = "1"
-                
+
     
         mswIncludeDir = os.path.join(wxRootDir, "include", "wx", "msw")
         setup0File = os.path.join(mswIncludeDir, "setup0.h")
@@ -347,6 +412,14 @@ def main(scriptName, args):
                     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()
             
@@ -360,40 +433,31 @@ def main(scriptName, args):
             # 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")
+        wxBuilder.clean(dir=buildDir, options=args)
         
         sys.exit(0)
 
     if options.extra_make:
         args.append(options.extra_make)
-    args.append("-j" + options.j)
+     
+    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(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.mac_framework:
+    if options.install and options.mac_framework:
     
         def renameLibrary(libname, frameworkname):
             reallib = libname
@@ -402,7 +466,7 @@ def main(scriptName, args):
                 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:
@@ -417,18 +481,35 @@ def main(scriptName, args):
         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")
-
-        run("ln -s -f bin Resources")
+        
+        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), "wx")
-        run("ln -s -f lib/wx.dylib wx")
+        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)
@@ -444,11 +525,10 @@ def main(scriptName, args):
                 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 = """
-        
+        header_template = """        
 #ifndef __WX_FRAMEWORK_HEADER__
 #define __WX_FRAMEWORK_HEADER__
 
@@ -459,29 +539,48 @@ def main(scriptName, args):
         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/wx wx")
+        run("ln -s -f Versions/Current/%s %s" % (fwname, fwname))
         
         # sanity check to ensure the symlink works
-        run("cd Versions/Current")
-        run("cd ../..")
-
-    # adjust the install_name if needed  TODO: skip this for framework builds?
+        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'
@@ -489,6 +588,7 @@ def main(scriptName, args):
 
     # make a package if a destdir was set.
     if options.mac_framework and \
+            options.install and \
             options.installdir and \
             options.mac_distdir:
 
@@ -499,7 +599,7 @@ def main(scriptName, args):
         os.makedirs(packagedir)
         basename = os.path.basename(prefixDir.split(".")[0])
         packageName = basename + "-" + getWxRelease()
-        packageMakerPath = "/Developer/usr/bin/packagemaker "
+        packageMakerPath = getXcodePath()+"/usr/bin/packagemaker "
         args = []
         args.append("--root %s" % options.installdir)
         args.append("--id org.wxwidgets.%s" % basename.lower())