Browse Source

Fix FreezeTool for linux, and auto-strip .py[cow]? when supplied as start file.

rdb 16 years ago
parent
commit
09d7fb02d8
2 changed files with 19 additions and 6 deletions
  1. 11 4
      direct/src/showutil/FreezeTool.py
  2. 8 2
      direct/src/showutil/pfreeze.py

+ 11 - 4
direct/src/showutil/FreezeTool.py

@@ -6,6 +6,7 @@ import sys
 import os
 import os
 import marshal
 import marshal
 import imp
 import imp
+from distutils.sysconfig import get_python_inc, get_python_lib, get_python_version
 
 
 import direct
 import direct
 from pandac.PandaModules import *
 from pandac.PandaModules import *
@@ -36,7 +37,9 @@ linkDll = 'error'
 Python = None
 Python = None
 
 
 # The directory that includes Python.h.
 # The directory that includes Python.h.
-PythonIPath = None
+PythonIPath = get_python_inc()
+PythonLPath = get_python_lib()
+PythonVersion = get_python_version()
 
 
 # The root directory of Microsoft Visual Studio (if relevant)
 # The root directory of Microsoft Visual Studio (if relevant)
 MSVS = None
 MSVS = None
@@ -61,9 +64,9 @@ elif sys.platform == 'darwin':
 
 
 else:
 else:
     # Linux
     # Linux
-    compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 %(filename)s"
-    linkExe = "gcc -o %(basename)s %(basename)s.o"
-    linkDll = "gcc -shared -o %(basename)s.so %(basename)s.o"
+    compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 %(filename)s -I %(pythonIPath)s"
+    linkExe = "gcc -o %(basename)s %(basename)s.o -lpython2.6 -L %(pythonLPath)s"
+    linkDll = "gcc -shared -o %(basename)s.so %(basename)s.o -lpython%(pythonVersion)s -L %(pythonLPath)s"
 
 
 # The code from frozenmain.c in the Python source repository.
 # The code from frozenmain.c in the Python source repository.
 frozenMainCode = """
 frozenMainCode = """
@@ -770,6 +773,8 @@ class Freezer:
             'python' : Python,
             'python' : Python,
             'msvs' : MSVS,
             'msvs' : MSVS,
             'pythonIPath' : PythonIPath,
             'pythonIPath' : PythonIPath,
+            'pythonLPath' : PythonLPath,
+            'pythonVersion' : PythonVersion,
             'filename' : filename,
             'filename' : filename,
             'basename' : basename,
             'basename' : basename,
             }
             }
@@ -792,6 +797,8 @@ class Freezer:
             'python' : Python,
             'python' : Python,
             'msvs' : MSVS,
             'msvs' : MSVS,
             'pythonIPath' : PythonIPath,
             'pythonIPath' : PythonIPath,
+            'pythonLPath' : PythonLPath,
+            'pythonVersion' : PythonVersion,
             'filename' : filename,
             'filename' : filename,
             'basename' : basename,
             'basename' : basename,
             }
             }

+ 8 - 2
direct/src/showutil/pfreeze.py

@@ -94,12 +94,18 @@ if __name__ == '__main__':
         basename = os.path.splitext(basename)[0]
         basename = os.path.splitext(basename)[0]
         outputType = 'dll'
         outputType = 'dll'
 
 
-    freezer.addModule(args[0])
+    startfile = args[0]
+    if startfile.endswith('.py') or startfile.endswith('.pyw') or \
+       startfile.endswith('.pyc') or startfile.endswith('.pyo'):
+        startfile = os.path.splitext(startfile)[0]
+
+    freezer.addModule(startfile)
     if outputType != 'dll':
     if outputType != 'dll':
-        freezer.setMain(args[0])
+        freezer.setMain(startfile)
     freezer.done()
     freezer.done()
 
 
     if outputType == 'mf':
     if outputType == 'mf':
         freezer.writeMultifile(basename)
         freezer.writeMultifile(basename)
     else:
     else:
         freezer.generateCode(basename)
         freezer.generateCode(basename)
+