mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 03:15:07 -04:00
Freeze improvements for makepanda
This commit is contained in:
parent
051bc71397
commit
ae9f8f4aaf
@ -38,7 +38,6 @@ Python = None
|
|||||||
|
|
||||||
# The directory that includes Python.h.
|
# The directory that includes Python.h.
|
||||||
PythonIPath = get_python_inc()
|
PythonIPath = get_python_inc()
|
||||||
PythonLPath = get_python_lib()
|
|
||||||
PythonVersion = get_python_version()
|
PythonVersion = get_python_version()
|
||||||
|
|
||||||
# The root directory of Microsoft Visual Studio (if relevant)
|
# The root directory of Microsoft Visual Studio (if relevant)
|
||||||
@ -57,14 +56,13 @@ elif sys.platform == 'darwin':
|
|||||||
# OSX
|
# OSX
|
||||||
compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
|
compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
|
||||||
linkExe = "gcc -o %(basename)s %(basename)s.o -framework Python"
|
linkExe = "gcc -o %(basename)s %(basename)s.o -framework Python"
|
||||||
#linkExe = "gcc -o %(basename)s %(basename)s.o -lpython%(pythonVersion)s -L%(pythonLPath)s"
|
|
||||||
linkDll = "gcc -undefined dynamic_lookup -bundle -o %(basename)s.so %(basename)s.o"
|
linkDll = "gcc -undefined dynamic_lookup -bundle -o %(basename)s.so %(basename)s.o"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Linux
|
# Linux
|
||||||
compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 %(filename)s -I %(pythonIPath)s"
|
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"
|
linkExe = "gcc -o %(basename)s %(basename)s.o -lpython%(pythonVersion)s"
|
||||||
linkDll = "gcc -shared -o %(basename)s.so %(basename)s.o -lpython%(pythonVersion)s -L %(pythonLPath)s"
|
linkDll = "gcc -shared -o %(basename)s.so %(basename)s.o -lpython%(pythonVersion)s"
|
||||||
|
|
||||||
# The code from frozenmain.c in the Python source repository.
|
# The code from frozenmain.c in the Python source repository.
|
||||||
frozenMainCode = """
|
frozenMainCode = """
|
||||||
@ -431,6 +429,8 @@ class Freezer:
|
|||||||
directories within a particular directory.
|
directories within a particular directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
moduleName = moduleName.replace("/", ".").replace("direct.src", "direct")
|
||||||
|
|
||||||
if implicit:
|
if implicit:
|
||||||
token = self.MTAuto
|
token = self.MTAuto
|
||||||
else:
|
else:
|
||||||
@ -476,6 +476,7 @@ class Freezer:
|
|||||||
self.modules[moduleName] = token
|
self.modules[moduleName] = token
|
||||||
|
|
||||||
def setMain(self, moduleName):
|
def setMain(self, moduleName):
|
||||||
|
moduleName = moduleName.replace("/", ".").replace("direct.src", "direct")
|
||||||
self.addModule(moduleName)
|
self.addModule(moduleName)
|
||||||
self.mainModule = moduleName
|
self.mainModule = moduleName
|
||||||
self.compileToExe = True
|
self.compileToExe = True
|
||||||
@ -718,13 +719,15 @@ class Freezer:
|
|||||||
# Add a special entry for __main__.
|
# Add a special entry for __main__.
|
||||||
moduleList.append(self.makeModuleListEntry(mangledName, code, '__main__', module))
|
moduleList.append(self.makeModuleListEntry(mangledName, code, '__main__', module))
|
||||||
|
|
||||||
|
filename = basename + self.sourceExtension
|
||||||
|
|
||||||
if self.compileToExe:
|
if self.compileToExe:
|
||||||
code = self.frozenMainCode
|
code = self.frozenMainCode
|
||||||
if self.platform == 'win32':
|
if self.platform == 'win32':
|
||||||
code += self.frozenDllMainCode
|
code += self.frozenDllMainCode
|
||||||
initCode = self.mainInitCode % {
|
initCode = self.mainInitCode % {
|
||||||
'frozenMainCode' : code,
|
'frozenMainCode' : code,
|
||||||
'programName' : basename,
|
'programName' : os.path.basename(basename),
|
||||||
}
|
}
|
||||||
if self.platform == 'win32':
|
if self.platform == 'win32':
|
||||||
initCode += self.frozenExtensions
|
initCode += self.frozenExtensions
|
||||||
@ -732,7 +735,7 @@ class Freezer:
|
|||||||
else:
|
else:
|
||||||
target = basename
|
target = basename
|
||||||
|
|
||||||
doCompile = self.compileExe
|
compileFunc = self.compileExe
|
||||||
|
|
||||||
else:
|
else:
|
||||||
dllexport = ''
|
dllexport = ''
|
||||||
@ -741,13 +744,13 @@ class Freezer:
|
|||||||
target = basename + '.pyd'
|
target = basename + '.pyd'
|
||||||
else:
|
else:
|
||||||
target = basename + '.so'
|
target = basename + '.so'
|
||||||
|
|
||||||
initCode = dllInitCode % {
|
initCode = dllInitCode % {
|
||||||
'dllexport' : dllexport,
|
'dllexport' : dllexport,
|
||||||
'moduleName' : basename.split('.')[0],
|
'moduleName' : os.path.basename(basename),
|
||||||
'newcount' : len(moduleList),
|
'newcount' : len(moduleList),
|
||||||
}
|
}
|
||||||
doCompile = self.compileDll
|
compileFunc = self.compileDll
|
||||||
|
|
||||||
text = programFile % {
|
text = programFile % {
|
||||||
'moduleDefs' : '\n'.join(moduleDefs),
|
'moduleDefs' : '\n'.join(moduleDefs),
|
||||||
@ -755,15 +758,18 @@ class Freezer:
|
|||||||
'initCode' : initCode,
|
'initCode' : initCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = basename + self.sourceExtension
|
|
||||||
file = open(filename, 'w')
|
file = open(filename, 'w')
|
||||||
file.write(text)
|
file.write(text)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
doCompile(filename, basename)
|
try:
|
||||||
os.unlink(filename)
|
compileFunc(filename, basename)
|
||||||
os.unlink(basename + self.objectExtension)
|
finally:
|
||||||
|
if (os.path.exists(filename)):
|
||||||
|
os.unlink(filename)
|
||||||
|
if (os.path.exists(basename + self.objectExtension)):
|
||||||
|
os.unlink(basename + self.objectExtension)
|
||||||
|
|
||||||
return target
|
return target
|
||||||
|
|
||||||
def compileExe(self, filename, basename):
|
def compileExe(self, filename, basename):
|
||||||
@ -771,7 +777,6 @@ class Freezer:
|
|||||||
'python' : Python,
|
'python' : Python,
|
||||||
'msvs' : MSVS,
|
'msvs' : MSVS,
|
||||||
'pythonIPath' : PythonIPath,
|
'pythonIPath' : PythonIPath,
|
||||||
'pythonLPath' : PythonLPath,
|
|
||||||
'pythonVersion' : PythonVersion,
|
'pythonVersion' : PythonVersion,
|
||||||
'filename' : filename,
|
'filename' : filename,
|
||||||
'basename' : basename,
|
'basename' : basename,
|
||||||
@ -784,7 +789,6 @@ class Freezer:
|
|||||||
'python' : Python,
|
'python' : Python,
|
||||||
'msvs' : MSVS,
|
'msvs' : MSVS,
|
||||||
'pythonIPath' : PythonIPath,
|
'pythonIPath' : PythonIPath,
|
||||||
'pythonLPath' : PythonLPath,
|
|
||||||
'pythonVersion' : PythonVersion,
|
'pythonVersion' : PythonVersion,
|
||||||
'filename' : filename,
|
'filename' : filename,
|
||||||
'basename' : basename,
|
'basename' : basename,
|
||||||
@ -798,7 +802,6 @@ class Freezer:
|
|||||||
'python' : Python,
|
'python' : Python,
|
||||||
'msvs' : MSVS,
|
'msvs' : MSVS,
|
||||||
'pythonIPath' : PythonIPath,
|
'pythonIPath' : PythonIPath,
|
||||||
'pythonLPath' : PythonLPath,
|
|
||||||
'pythonVersion' : PythonVersion,
|
'pythonVersion' : PythonVersion,
|
||||||
'filename' : filename,
|
'filename' : filename,
|
||||||
'basename' : basename,
|
'basename' : basename,
|
||||||
@ -811,7 +814,6 @@ class Freezer:
|
|||||||
'python' : Python,
|
'python' : Python,
|
||||||
'msvs' : MSVS,
|
'msvs' : MSVS,
|
||||||
'pythonIPath' : PythonIPath,
|
'pythonIPath' : PythonIPath,
|
||||||
'pythonLPath' : PythonLPath,
|
|
||||||
'pythonVersion' : PythonVersion,
|
'pythonVersion' : PythonVersion,
|
||||||
'filename' : filename,
|
'filename' : filename,
|
||||||
'basename' : basename,
|
'basename' : basename,
|
||||||
|
@ -52,60 +52,62 @@ def usage(code, msg = ''):
|
|||||||
print >> sys.stderr, msg
|
print >> sys.stderr, msg
|
||||||
sys.exit(code)
|
sys.exit(code)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# We're not protecting the next part under a __name__ == __main__
|
||||||
freezer = FreezeTool.Freezer()
|
# check, just so we can import this file directly in ppython.cxx.
|
||||||
|
|
||||||
basename = None
|
freezer = FreezeTool.Freezer()
|
||||||
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'o:i:x:p:h')
|
|
||||||
except getopt.error, msg:
|
|
||||||
usage(1, msg)
|
|
||||||
|
|
||||||
for opt, arg in opts:
|
basename = None
|
||||||
if opt == '-o':
|
|
||||||
basename = arg
|
|
||||||
elif opt == '-i':
|
|
||||||
for module in arg.split(','):
|
|
||||||
freezer.addModule(module)
|
|
||||||
elif opt == '-x':
|
|
||||||
for module in arg.split(','):
|
|
||||||
freezer.excludeModule(module)
|
|
||||||
elif opt == '-p':
|
|
||||||
for module in arg.split(','):
|
|
||||||
freezer.handleCustomPath(module)
|
|
||||||
elif opt == '-h':
|
|
||||||
usage(0)
|
|
||||||
|
|
||||||
if not args:
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], 'o:i:x:p:h')
|
||||||
|
except getopt.error, msg:
|
||||||
|
usage(1, msg)
|
||||||
|
|
||||||
|
for opt, arg in opts:
|
||||||
|
if opt == '-o':
|
||||||
|
basename = arg
|
||||||
|
elif opt == '-i':
|
||||||
|
for module in arg.split(','):
|
||||||
|
freezer.addModule(module)
|
||||||
|
elif opt == '-x':
|
||||||
|
for module in arg.split(','):
|
||||||
|
freezer.excludeModule(module)
|
||||||
|
elif opt == '-p':
|
||||||
|
for module in arg.split(','):
|
||||||
|
freezer.handleCustomPath(module)
|
||||||
|
elif opt == '-h':
|
||||||
usage(0)
|
usage(0)
|
||||||
|
|
||||||
if not basename:
|
if not args:
|
||||||
usage(1, 'You did not specify an output file.')
|
usage(0)
|
||||||
|
|
||||||
if len(args) != 1:
|
if not basename:
|
||||||
usage(1, 'Only one main file may be specified.')
|
usage(1, 'You did not specify an output file.')
|
||||||
|
|
||||||
outputType = 'exe'
|
if len(args) != 1:
|
||||||
bl = basename.lower()
|
usage(1, 'Only one main file may be specified.')
|
||||||
if bl.endswith('.mf'):
|
|
||||||
outputType = 'mf'
|
|
||||||
elif bl.endswith('.dll') or bl.endswith('.pyd') or bl.endswith('.so'):
|
|
||||||
basename = os.path.splitext(basename)[0]
|
|
||||||
outputType = 'dll'
|
|
||||||
|
|
||||||
startfile = args[0]
|
outputType = 'exe'
|
||||||
if startfile.endswith('.py') or startfile.endswith('.pyw') or \
|
bl = basename.lower()
|
||||||
startfile.endswith('.pyc') or startfile.endswith('.pyo'):
|
if bl.endswith('.mf'):
|
||||||
startfile = os.path.splitext(startfile)[0]
|
outputType = 'mf'
|
||||||
|
elif bl.endswith('.dll') or bl.endswith('.pyd') or bl.endswith('.so'):
|
||||||
|
basename = os.path.splitext(basename)[0]
|
||||||
|
outputType = 'dll'
|
||||||
|
|
||||||
freezer.addModule(startfile)
|
startfile = args[0]
|
||||||
if outputType != 'dll':
|
if startfile.endswith('.py') or startfile.endswith('.pyw') or \
|
||||||
freezer.setMain(startfile)
|
startfile.endswith('.pyc') or startfile.endswith('.pyo'):
|
||||||
freezer.done()
|
startfile = os.path.splitext(startfile)[0]
|
||||||
|
|
||||||
if outputType == 'mf':
|
freezer.addModule(startfile)
|
||||||
freezer.writeMultifile(basename)
|
if outputType != 'dll':
|
||||||
else:
|
freezer.setMain(startfile)
|
||||||
freezer.generateCode(basename)
|
freezer.done()
|
||||||
|
|
||||||
|
if outputType == 'mf':
|
||||||
|
freezer.writeMultifile(basename)
|
||||||
|
else:
|
||||||
|
freezer.generateCode(basename)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user