<commit_before>""" This module contains code to freeze a number of Python modules
into a single (mostly) standalone DLL or EXE. """

import modulefinder
import sys
import os
import marshal
import imp
import platform
from distutils.sysconfig import PREFIX, get_python_inc, get_python_version

import direct
from pandac.PandaModules import *

# Check to see if we are running python_d, which implies we have a
# debug build, and we have to build the module with debug options.
# This is only relevant on Windows.

# I wonder if there's a better way to determine this?
python = os.path.splitext(os.path.split(sys.executable)[1])[0]
isDebugBuild = (python.lower().endswith('_d'))

# These are modules that Python always tries to import up-front.  They
# must be frozen in any main.exe.
startupModules = [
    'site', 'sitecustomize', 'os', 'encodings.cp1252',
    'org',
    ]

# Our own Python source trees to watch out for.
sourceTrees = ['direct']

# The command to compile a c to an object file.  Replace %(basename)s
# with the basename of the source file, and an implicit .c extension.
compileObj = 'error'

# The command to link a single object file into an executable.  As
# above, replace $(basename)s with the basename of the original source
# file, and of the target executable.
linkExe = 'error'

# The command to link a single object file into a shared library.
linkDll = 'error'

# Paths to Python stuff.
Python = None
PythonIPath = get_python_inc()
PythonVersion = get_python_version()

# The VC directory of Microsoft Visual Studio (if relevant)
MSVC = None
# Directory to Windows Platform SDK (if relevant)
PSDK = None

# The setting to control release vs. debug builds.  Only relevant on
# Windows.
MD = None

# The _d extension to add to dll filenames on Windows in debug builds.
dllext = ''


if sys.platform == 'win32':
    Python = PREFIX
    
    if ('VCINSTALLDIR' in os.environ):
        MSVC = os.environ['VCINSTALLDIR']
    elif (Filename('/c/Program Files/Microsoft Visual Studio 9.0/VC').exists()):
        MSVC = Filename('/c/Program Files/Microsoft Visual Studio 9.0/VC').toOsSpecific()
    elif (Filename('/c/Program Files/Microsoft Visual Studio .NET 2003/Vc7').exists()):
        MSVC = Filename('/c/Program Files/Microsoft Visual Studio .NET 2003/Vc7').toOsSpecific()
    else:
        print 'Could not locate Microsoft Visual C++ Compiler! Try running from the Visual Studio Command Prompt.'
        sys.exit(1)
    
    if ('WindowsSdkDir' in os.environ):
        PSDK = os.environ['WindowsSdkDir']
    elif (platform.architecture()[0] == '32bit' and Filename('/c/Program Files/Microsoft Platform SDK for Windows Server 2003 R2').exists()):
        PSDK = Filename('/c/Program Files/Microsoft Platform SDK for Windows Server 2003 R2').toOsSpecific()
    elif (os.path.exists(os.path.join(MSVC, 'PlatformSDK'))):
        PSDK = os.path.join(MSVC, 'PlatformSDK')
    else:
        print 'Could not locate the Microsoft Windows Platform SDK! Try running from the Visual Studio Command Prompt.'
        sys.exit(1)

    # We need to use the correct compiler setting for debug vs. release builds.
    MD = '/MD'
    if isDebugBuild:
        MD = '/MDd'
        dllext = '_d'
    
    # If it is run by makepanda, it handles the MSVC and PlatformSDK paths itself.
    if ('MAKEPANDA' in os.environ):
        compileObj = 'cl /wd4996 /Fo%(basename)s.obj /nologo /c %(MD)s /Zi /O2 /Ob2 /EHsc /Zm300 /W3 /I"%(pythonIPath)s" %(filename)s'
        linkExe = 'link /nologo /MAP:NUL /FIXED:NO /OPT:REF /STACK:4194304 /INCREMENTAL:NO /LIBPATH:"%(python)s\libs"  /out:%(basename)s.exe %(basename)s.obj'
        linkDll = 'link /nologo /DLL /MAP:NUL /FIXED:NO /OPT:REF /INCREMENTAL:NO /LIBPATH:"%(python)s\libs"  /out:%(basename)s%(dllext)s.pyd %(basename)s.obj'
    else:
        os.environ['PATH'] += ';' + MSVC + '\\bin;' + MSVC + '\\Common7\\IDE;' + PSDK + '\\bin'
        
        compileObj = 'cl /wd4996 /Fo%(basename)s.obj /nologo /c %(MD)s /Zi /O2 /Ob2 /EHsc /Zm300 /W3 /I"%(pythonIPath)s" /I"%(PSDK)s\include" /I"%(MSVC)s\include" %(filename)s'
        linkExe = 'link /nologo /MAP:NUL /FIXED:NO /OPT:REF /STACK:4194304 /INCREMENTAL:NO /LIBPATH:"%(PSDK)s\lib" /LIBPATH:"%(MSVC)s\lib" /LIBPATH:"%(python)s\libs"  /out:%(basename)s.exe %(basename)s.obj'
        linkDll = 'link /nologo /DLL /MAP:NUL /FIXED:NO /OPT:REF /INCREMENTAL:NO /LIBPATH:"%(PSDK)s\lib" /LIBPATH:"%(MSVC)s\lib" /LIBPATH:"%(python)s\libs"  /out:%(basename)s%(dllext)s.pyd %(basename)s.obj'

elif sys.platform == 'darwin':
    # OSX
    compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
    linkExe = "gcc -o %(basename)s %(basename)s.o -framework Python"
    linkDll = "gcc -undefined dynamic_lookup -bundle -o %(basename)s.so %(basename)s.o"

else:
    # Linux
    compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 %(filename)s -I %(pythonIPath)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"

# The code from frozenmain.c in the Python source repository.
frozenMainCode = """
/* Python interpreter main program for frozen scripts */

#include "Python.h"

#ifdef MS_WINDOWS
extern void PyWinFreeze_ExeInit(void);
extern void PyWinFreeze_ExeTerm(void);
extern int PyInitFrozenExtensions(void);
#endif

/* Main program */

int
Py_FrozenMain(int argc, char **argv)
{
    char *p;
    int n, sts;
    int inspect = 0;
    int unbuffered = 0;

    Py_FrozenFlag = 1; /* Suppress errors from getpath.c */

    if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\\0')
        inspect = 1;
    if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\\0')
        unbuffered = 1;

    if (unbuffered) {<commit_msg>Get pfreeze working on PC-BSD correctly<commit_after>""" This module contains code to freeze a number of Python modules
into a single (mostly) standalone DLL or EXE. """

import modulefinder
import sys
import os
import marshal
import imp
import platform
from distutils.sysconfig import PREFIX, get_python_inc, get_python_version

import direct
from pandac.PandaModules import *

# Check to see if we are running python_d, which implies we have a
# debug build, and we have to build the module with debug options.
# This is only relevant on Windows.

# I wonder if there's a better way to determine this?
python = os.path.splitext(os.path.split(sys.executable)[1])[0]
isDebugBuild = (python.lower().endswith('_d'))

# These are modules that Python always tries to import up-front.  They
# must be frozen in any main.exe.
startupModules = [
    'site', 'sitecustomize', 'os', 'encodings.cp1252',
    'org',
    ]

# Our own Python source trees to watch out for.
sourceTrees = ['direct']

# The command to compile a c to an object file.  Replace %(basename)s
# with the basename of the source file, and an implicit .c extension.
compileObj = 'error'

# The command to link a single object file into an executable.  As
# above, replace $(basename)s with the basename of the original source
# file, and of the target executable.
linkExe = 'error'

# The command to link a single object file into a shared library.
linkDll = 'error'

# Paths to Python stuff.
Python = None
PythonIPath = get_python_inc()
PythonVersion = get_python_version()

# The VC directory of Microsoft Visual Studio (if relevant)
MSVC = None
# Directory to Windows Platform SDK (if relevant)
PSDK = None

# The setting to control release vs. debug builds.  Only relevant on
# Windows.
MD = None

# The _d extension to add to dll filenames on Windows in debug builds.
dllext = ''


if sys.platform == 'win32':
    Python = PREFIX
    
    if ('VCINSTALLDIR' in os.environ):
        MSVC = os.environ['VCINSTALLDIR']
    elif (Filename('/c/Program Files/Microsoft Visual Studio 9.0/VC').exists()):
        MSVC = Filename('/c/Program Files/Microsoft Visual Studio 9.0/VC').toOsSpecific()
    elif (Filename('/c/Program Files/Microsoft Visual Studio .NET 2003/Vc7').exists()):
        MSVC = Filename('/c/Program Files/Microsoft Visual Studio .NET 2003/Vc7').toOsSpecific()
    else:
        print 'Could not locate Microsoft Visual C++ Compiler! Try running from the Visual Studio Command Prompt.'
        sys.exit(1)
    
    if ('WindowsSdkDir' in os.environ):
        PSDK = os.environ['WindowsSdkDir']
    elif (platform.architecture()[0] == '32bit' and Filename('/c/Program Files/Microsoft Platform SDK for Windows Server 2003 R2').exists()):
        PSDK = Filename('/c/Program Files/Microsoft Platform SDK for Windows Server 2003 R2').toOsSpecific()
    elif (os.path.exists(os.path.join(MSVC, 'PlatformSDK'))):
        PSDK = os.path.join(MSVC, 'PlatformSDK')
    else:
        print 'Could not locate the Microsoft Windows Platform SDK! Try running from the Visual Studio Command Prompt.'
        sys.exit(1)

    # We need to use the correct compiler setting for debug vs. release builds.
    MD = '/MD'
    if isDebugBuild:
        MD = '/MDd'
        dllext = '_d'
    
    # If it is run by makepanda, it handles the MSVC and PlatformSDK paths itself.
    if ('MAKEPANDA' in os.environ):
        compileObj = 'cl /wd4996 /Fo%(basename)s.obj /nologo /c %(MD)s /Zi /O2 /Ob2 /EHsc /Zm300 /W3 /I"%(pythonIPath)s" %(filename)s'
        linkExe = 'link /nologo /MAP:NUL /FIXED:NO /OPT:REF /STACK:4194304 /INCREMENTAL:NO /LIBPATH:"%(python)s\libs"  /out:%(basename)s.exe %(basename)s.obj'
        linkDll = 'link /nologo /DLL /MAP:NUL /FIXED:NO /OPT:REF /INCREMENTAL:NO /LIBPATH:"%(python)s\libs"  /out:%(basename)s%(dllext)s.pyd %(basename)s.obj'
    else:
        os.environ['PATH'] += ';' + MSVC + '\\bin;' + MSVC + '\\Common7\\IDE;' + PSDK + '\\bin'
        
        compileObj = 'cl /wd4996 /Fo%(basename)s.obj /nologo /c %(MD)s /Zi /O2 /Ob2 /EHsc /Zm300 /W3 /I"%(pythonIPath)s" /I"%(PSDK)s\include" /I"%(MSVC)s\include" %(filename)s'
        linkExe = 'link /nologo /MAP:NUL /FIXED:NO /OPT:REF /STACK:4194304 /INCREMENTAL:NO /LIBPATH:"%(PSDK)s\lib" /LIBPATH:"%(MSVC)s\lib" /LIBPATH:"%(python)s\libs"  /out:%(basename)s.exe %(basename)s.obj'
        linkDll = 'link /nologo /DLL /MAP:NUL /FIXED:NO /OPT:REF /INCREMENTAL:NO /LIBPATH:"%(PSDK)s\lib" /LIBPATH:"%(MSVC)s\lib" /LIBPATH:"%(python)s\libs"  /out:%(basename)s%(dllext)s.pyd %(basename)s.obj'

elif sys.platform == 'darwin':
    # OSX
    compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
    linkExe = "gcc -o %(basename)s %(basename)s.o -framework Python"
    linkDll = "gcc -undefined dynamic_lookup -bundle -o %(basename)s.so %(basename)s.o"

else:
    # Unix
    compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 %(filename)s -I %(pythonIPath)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"
    
    if (platform.uname()[1]=="pcbsd"):
        linkExe += " -L/usr/PCBSD/local/lib"
        linkDll += " -L/usr/PCBSD/local/lib"

# The code from frozenmain.c in the Python source repository.
frozenMainCode = """
/* Python interpreter main program for frozen scripts */

#include "Python.h"

#ifdef MS_WINDOWS
extern void PyWinFreeze_ExeInit(void);
extern void PyWinFreeze_ExeTerm(void);
extern int PyInitFrozenExtensions(void);
#endif

/* Main program */

int
Py_FrozenMain(int argc, char **argv)
{
    char *p;
    int n, sts;
    int inspect = 0;
    int unbuffered = 0;

    Py_FrozenFlag = 1; /* Suppress errors from getpath.c */

    if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\\0')
        inspect = 1;
    if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\\0')
        unbuffered = 1;

    if (unbuffered) {
{'fraction_non_alphanumeric': 0.1386861313868613, 'fraction_numerical': 0.013997423787033062, 'mean_word_length': 3.4467353951890036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5879314', 'n_tokens_mistral': 4307, 'n_tokens_neox': 4048, 'n_words': 1231}