]> git.saurik.com Git - wxWidgets.git/blobdiff - build/tools/build-wxwidgets.py
Add new sample project files.
[wxWidgets.git] / build / tools / build-wxwidgets.py
index f23dfe8c17c774f4a28dc5671466ded5b6ca77bc..548bb104566c2570e66165c1ea85f9abbf19a7e8 100755 (executable)
@@ -15,6 +15,7 @@ import optparse
 import platform
 import shutil
 import types
+import subprocess
 
 # builder object
 wxBuilder = None
@@ -43,7 +44,9 @@ def numCPUs():
             if isinstance(ncpus, int) and ncpus > 0:
                 return ncpus
         else: # OSX:
-            return int(os.popen2("sysctl -n hw.ncpu")[1].read())
+            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"]);
@@ -182,6 +185,7 @@ def main(scriptName, args):
         "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)"),
     }
         
     parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
@@ -197,7 +201,11 @@ def main(scriptName, args):
                           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 = []
@@ -298,6 +306,13 @@ def main(scriptName, args):
             # 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")
@@ -381,6 +396,11 @@ 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("USE_CAIRO=1")
     
             wxBuilder = builder.MSVCBuilder()
             
@@ -401,34 +421,22 @@ def main(scriptName, args):
     
     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("--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:
     
@@ -454,18 +462,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)
@@ -481,7 +506,7 @@ 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 = """        
@@ -495,29 +520,41 @@ 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
         os.chdir("Versions/Current")
-        os.chdir("../..")
-
+    
+        # 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' % getFrameworkName(options))
+                            '%s.framework' % fwname)
         
         
     # adjust the install_name if needed
@@ -560,8 +597,6 @@ def main(scriptName, args):
         
         shutil.rmtree(packagedir)
         
-        
-        
 if __name__ == '__main__':
     exitWithException = False  # use sys.exit instead
     main(sys.argv[0], sys.argv[1:])