Mercurial > parpg-core
diff SConstruct @ 6:dd4ed4945411
Ported binary launcher to Windows.
* Reorganized the parpg executable source so that it now compiles with the MSVC compiler (tested with MSVC Express 2010).
* Cleaned up the launcher source by adding a bunch of const statements and removing the superfluous NULL_TERMINATE macro.
* Fixed a few memory leaks in the launcher source by freeing malloced/calloced pointers;
* Added a new SubstfileEscape builder to the SConstruct script used to escape certain sequences when substituting a template file. This is used to escape backslashes ("\") in c strings in the bin/parpg.c.in template for Windows paths.
* Fixed the PY_LIB_DIR_DEFAULT for Windows so that it now correctly points to the default Python installation path.
* Modified the SConstruct script to support compiling the launcher executable with debugging symbols in Windows with the DEBUG flag.
author | M. George Hansen |
---|---|
date | Sun, 22 May 2011 00:53:59 -0700 |
parents | 33684971cdb1 |
children | 4706e0194af3 |
line wrap: on
line diff
--- a/SConstruct Tue May 17 14:18:25 2011 -0700 +++ b/SConstruct Sun May 22 00:53:59 2011 -0700 @@ -7,6 +7,8 @@ from types import StringType from multiprocessing import cpu_count +from SCons.Util import is_Sequence, is_Dict + def InstallChmod(env, dest, source, mode): targets = env.Install(dest, source) for target in targets: @@ -62,10 +64,31 @@ targets = env.InstallReadOnly(dest, source) return targets +def SubstfileEscape(env, *args, **kwargs): + subst_dict = kwargs.get('SUBST_DICT') or env.get('SUBST_DICT') + escape_sequences = kwargs.get('ESCAPE_SEQUENCES') or env.get('ESCAPE_SEQUENCES') + if subst_dict is not None and escape_sequences is not None: + if not is_Dict(subst_dict) and is_Sequence(subst_dict): + subst_dict = dict(subst_dict) + else: + error_message = 'SUBST_DICT must be dict or sequence' + raise SCons.Errors.UserError(error_message) + escaped_subst_dict = {} + for key, value in subst_dict.items(): + escaped_value = value + for seq, escaped_seq in escape_sequences.items(): + escaped_value = escaped_value.replace(seq, escaped_seq) + escaped_subst_dict[key] = escaped_value + kwargs['SUBST_DICT'] = escaped_subst_dict + + target = env.Substfile(*args, **kwargs) + return target + AddMethod(Environment, InstallChmod) AddMethod(Environment, InstallExecutable) AddMethod(Environment, InstallReadOnly) AddMethod(Environment, InstallPyPackages) +AddMethod(Environment, SubstfileEscape) EnsurePythonVersion(2, 6) @@ -139,7 +162,6 @@ INCLUDE_DIR_DEFAULT = '$PREFIX/include' DOC_DIR_DEFAULT = '$PREFIX/doc/' LIB_DIR_DEFAULT = '$EXEC_PREFIX/lib' - PY_LIB_DIR_DEFAULT = '$EXEC_PREFIX/lib' # FIXME M. George Hansen 2011-05-12: Does sys.prefix include the # PythonX.Y part on Windows? python_prefix = sys.prefix @@ -149,13 +171,7 @@ PY_PACKAGES_DIR_DEFAULT = \ os.path.join(python_prefix, 'Lib', 'site-packages') PY_HEADERS_DIR_DEFAULT = os.path.join(python_prefix, 'include') - try: - PY_LIB_DIR_DEFAULT = os.environ['SYSTEMROOT'] - except KeyError: - PY_LIB_DIR_DEFAULT = '' - error_message = '%SYSTEMROOT% environmental variable is not set, ' \ - 'unable to determine path to Windows system folder' - raise SConfWarning(error_message) + PY_LIB_DIR_DEFAULT = os.path.join(python_prefix, 'libs') PY_LIB_NAME = 'python$PY_VERSION_MAJOR$PY_VERSION_MINOR' # Platform-independant variables: @@ -250,11 +266,10 @@ ), ) -platform_name = platform.system() python_version_tuple = platform.python_version_tuple() environment = Environment( - tools=['default', 'cc', 'textfile', 'packaging'], + tools=['default', 'textfile', 'packaging'], variables=variables, PROJECT_NAME='parpg', PROJECT_VERSION_MAJOR=0, @@ -277,7 +292,11 @@ EXECUTABLES=[], ) if environment['DEBUG']: - environment.AppendUnique(CCFLAGS=['-gdwarf-2', '-g3']) + if platform_name == 'Windows': + environment['CCPDBFLAGS'] = '/Z7 /Od' + environment.AppendUnique(LINKFLAGS='/DEBUG') + else: + environment.AppendUnique(CCFLAGS=['-gdwarf-2', '-g3']) Help(variables.GenerateHelpText(environment)) @@ -307,9 +326,12 @@ Glob('data/*'), ) -executable_source = environment.Substfile( +# FIXME M. George Hansen 2011-05-20: Do any other sequences need to be escaped +# in a C string? +executable_source = environment.SubstfileEscape( 'bin/parpg.c.in', SUBST_DICT=config_dict, + ESCAPE_SEQUENCES={'\\': r'\\\\', '"': r'\\"'}, ) build_executable = environment.Program( executable_source, @@ -317,11 +339,13 @@ LIBPATH='$PY_LIB_DIR', CPPPATH=['$PY_HEADERS_DIR'], ) -# FIXME M. George Hansen 2011-05-17: Should the executable target be hard-coded -# like this? +# Clean up any files created by the MSVC compiler on Windows. +if platform_name == 'Windows': + environment.Clean(build_executable, 'bin/parpg.ilk') + environment.Clean(build_executable, 'bin/parpg.pdb') install_executable = environment.InstallExecutable( '$BIN_DIR', - 'bin/parpg', + build_executable, ) # TODO M. George Hansen 2011-05-12: Implement package builder.