Anonymous avatar Anonymous committed 1f7958b

Patch to improve cx_freeze on OS X

Comments (0)

Files changed (3)

cx_Freeze/hooks.py

     import _tkinter
     tk = _tkinter.create()
     tclDir = os.path.dirname(tk.call("info", "library"))
-    tclSourceDir = os.path.join(tclDir, "tcl%s" % _tkinter.TCL_VERSION)
-    tkSourceDir = os.path.join(tclDir, "tk%s" % _tkinter.TK_VERSION)
+    #On OS X, Tcl and Tk are organized in frameworks, different layout
+    if sys.platform == 'darwin' and tk.call('tk', 'windowingsystem') == 'aqua':
+        tclSourceDir=os.path.join(os.path.split(tclDir)[0], 'Tcl')
+        tkSourceDir = tclSourceDir.replace('Tcl', 'Tk')
+    else:       
+        tclSourceDir = os.path.join(tclDir, "tcl%s" % _tkinter.TCL_VERSION)
+        tkSourceDir = os.path.join(tclDir, "tk%s" % _tkinter.TK_VERSION)
     finder.IncludeFiles(tclSourceDir, "tcl")
     finder.IncludeFiles(tkSourceDir, "tk")
 

cx_Freeze/macdist.py

             just fail for files on which they do not apply."""
         files = os.listdir(self.binDir)
         for file in files:
+            #install_name_tool can't handle zip files
+            if file.endswith('.zip'):
+                continue
+            #install_name_tool can't handle directories
+            if os.path.isdir(file):
+                continue
             filepath = os.path.join(self.binDir, file)
 
             #Ensure write permissions
 from distutils.core import setup
 from distutils.extension import Extension
 
+
+import os
+os.environ['CFLAGS'] = '-arch i386 -arch x86_64 -fobjc-gc  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -framework Cocoa'
+os.environ['LDFLAGS'] = '-arch i386 -arch x86_64 -fobjc-gc  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -framework Cocoa'
+
 class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):
 
     # rpm automatically byte compiles all Python files in a package but we
         fileName = os.path.splitext(self.get_ext_filename(ext.name))[0]
         fullName = os.path.join(self.build_lib, fileName)
         libraryDirs = ext.library_dirs or []
-        libraries = self.get_libraries(ext)
+        libraries = self.get_libraries(ext)       
+        
         extraArgs = ext.extra_link_args or []
         if sys.platform != "win32":
             vars = distutils.sysconfig.get_config_vars()
+            #make sure that universal binary is built on OS X and links to Cocoa framework
+            if sys.platform == 'darwin' and 'CoreFoundation' in vars['SHLIBS']:
+                vars['SHLIBS'] = '-ldl  -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64 '
+            if sys.platform == 'darwin' and 'CoreFoundation' in vars['LIBS']:
+                vars['LIBS'] = '-ldl  -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64 '                
             if not vars.get("Py_ENABLE_SHARED", 0):
                 libraryDirs.append(vars["LIBPL"])
                 libraries.append("python%s.%s" % sys.version_info[:2])
                 if vars["LOCALMODLIBS"]:
                     extraArgs.extend(vars["LOCALMODLIBS"].split())
             extraArgs.append("-s")
+            
         elif ext.name.find("Win32GUI") > 0 \
                 and self.compiler.compiler_type == "mingw32":
             extraArgs.append("-mwindows")
 fullDepends = depends + [baseModulesFileName]
 includeDirs = [baseModulesDir]
 console = Extension("cx_Freeze.bases.Console", ["source/bases/Console.c"],
-        depends = fullDepends, include_dirs = includeDirs)
+                    depends = fullDepends, include_dirs = includeDirs)
 consoleKeepPath = Extension("cx_Freeze.bases.ConsoleKeepPath",
         ["source/bases/ConsoleKeepPath.c"], depends = depends)
 extensions = [utilModule, console, consoleKeepPath]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.