rts.py

来自「这是整套横扫千军3D版游戏的源码」· Python 代码 · 共 453 行 · 第 1/2 页

PY
453
字号
# Copyright (C) 2006  Tobi Vollebregt

import os, sys
import SCons.Util
from SCons.Options import Options
import config, detect, filelist


def exists(env):
	return True


# HACK   Oh noes, msvcrt doesn't support arbitrary lenght commandlines :/
# source: http://www.scons.org/cgi-sys/cgiwrap/scons/moin.cgi/LongCmdLinesOnWin32
def fix_windows_spawn(env):
	# for cross compilation
	if sys.platform != 'win32':
		return

	if env['platform'] == 'windows':
		import win32file
		import win32event
		import win32process
		import win32security
		import string

		def my_spawn(sh, escape, cmd, args, spawnenv):
			for var in spawnenv:
				spawnenv[var] = spawnenv[var].encode('ascii', 'replace')

			sAttrs = win32security.SECURITY_ATTRIBUTES()
			StartupInfo = win32process.STARTUPINFO()
			newargs = string.join(map(escape, args[1:]), ' ')
			cmdline = cmd + " " + newargs

			# check for any special operating system commands
			if cmd == 'del':
				for arg in args[1:]:
					win32file.DeleteFile(arg)
				exit_code = 0
			else:
				# otherwise execute the command.
				hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
				win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
				exit_code = win32process.GetExitCodeProcess(hProcess)
				win32file.CloseHandle(hProcess);
				win32file.CloseHandle(hThread);
				return exit_code
		env['SPAWN'] = my_spawn


def generate(env):
	# Fix scons & gcc borkedness (scons not looking in PATH for gcc
	# and mingw gcc 4.1 linker crashing if TMP or TEMP isn't set).
	env['ENV']['PATH'] = os.environ['PATH']
	if os.environ.has_key('MINGDIR'):
		env['ENV']['MINGDIR'] = os.environ['MINGDIR']
	if os.environ.has_key('TMP'):
		env['ENV']['TMP'] = os.environ['TMP']
	if os.environ.has_key('TEMP'):
		env['ENV']['TEMP'] = os.environ['TEMP']

	# We break unitsync if the filename of the shared object has a 'lib' prefix.
	# It is also nicer for the AI shared objects.
	env['LIBPREFIX'] = ''

	# I don't see any reason to make this configurable --tvo.
	# Note that commenting out / setting this to `None' will break the buildsystem.
	env['builddir'] = 'build'

	# SCons chokes in env.SConsignFile() if path doesn't exist.
	if not os.path.exists(env['builddir']):
		os.makedirs(env['builddir'])

	# Avoid spreading .sconsign files everywhere - keep this line
	# Use os.path.abspath() here because somehow the argument to SConsignFile is relative to the
	# directory of the toplevel trunk/SConstruct and not the current directory, trunk/rts/SConstruct.
	env.SConsignFile(os.path.abspath(os.path.join(env['builddir'], 'scons_signatures')))

	usrcachefile = os.path.join(env['builddir'], 'usropts.py')
	intcachefile = os.path.join(env['builddir'], 'intopts.py')
	usropts = Options(usrcachefile)
	intopts = Options(intcachefile)

	#user visible options
	usropts.AddOptions(
		#permanent options
		('platform',          'Set to linux, freebsd or windows', None),
		('debug',             'Set to yes to produce a binary with debug information', 0),
		('debugdefines',      'Set to no to suppress DEBUG and _DEBUG preprocessor #defines (use to add symbols to release build)', True),
		('syncdebug',         'Set to yes to enable the sync debugger', False),
		('synccheck',         'Set to yes to enable sync checker & resyncer', True),
		('optimize',          'Enable processor optimizations during compilation', 1),
		('profile',           'Set to yes to produce a binary with profiling information', False),
		('profile_generate',  'Set to yes to compile with -fprofile-generate to generate profiling information', False),
		('profile_use',       'Set to yes to compile with -fprofile-use to use profiling information', False),
		('cpppath',           'Set path to extra header files', []),
		('libpath',           'Set path to extra libraries', []),
		('fpmath',            'Set to 387 or SSE on i386 and AMD64 architectures', '387'),
		('prefix',            'Install prefix used at runtime', '/usr/local'),
		('installprefix',     'Install prefix used for installion', '$prefix'),
		('datadir',           'Data directory (relative to prefix)', 'share/games/spring'),
		('bindir',            'Directory for executables (rel. to prefix)', 'games'),
		('libdir',            'Directory for AI plugin modules (rel. to prefix)', 'lib/spring'),
		('strip',             'Discard symbols from the executable (only when neither debugging nor profiling)', True),
		#porting options - optional in a first phase
		('disable_avi',       'Set to no to turn on avi support', 'False on windows, True otherwise'),
		#other ported parts
		('use_tcmalloc',      'Use tcmalloc from goog-perftools for memory allocation', False),
		('use_mmgr',          'Use memory manager', False),
		('dc_allowed',        'Specifies whether FPS mode (Direct Control) is allowed in game', True),
		('cachedir',          'Cache directory (see scons manual)', None))

	#internal options
	intopts.AddOptions(
		('LINKFLAGS',     'linker flags'),
		('LIBPATH',       'library path'),
		('LIBS',          'libraries'),
		('CCFLAGS',       'c compiler flags'),
		('CXXFLAGS',      'c++ compiler flags'),
		('CPPDEFINES',    'c preprocessor defines'),
		('CPPPATH',       'c preprocessor include path'),
		('CC',            'c compiler'),
		('CXX',           'c++ compiler'),
		('spring_defines','extra c preprocessor defines for spring'),
		('is_configured', 'configuration version stamp'))

	usropts.Update(env)
	intopts.Update(env)

	env.Help(usropts.GenerateHelpText(env))

	# Use this to avoid an error message 'how to make target configure ?'
	env.Alias('configure', None)

	if not 'configure' in sys.argv and not ((env.has_key('is_configured') and env['is_configured'] == 5) or env.GetOption('clean')):
		print "Not configured or configure script updated.  Run `scons configure' first."
		print "Use `scons --help' to show available configure options to `scons configure'."
		env.Exit(1)

	# Dont throw an exception if scons -c is run before scons configure (this is done by debian build system for example)
	if not env.has_key('is_configured') and env.GetOption('clean'):
		print "Not configured: nothing to clean"
		env.Exit(0)

	if 'configure' in sys.argv:

		# be paranoid, unset existing variables
		for key in ['platform', 'debug', 'optimize', 'profile', 'profile_use', 'profile_generate', 'cpppath',
			'libpath', 'prefix', 'installprefix', 'datadir', 'bindir', 'libdir', 'cachedir', 'strip',
			'disable_avi', 'use_tcmalloc', 'use_mmgr', 'LINKFLAGS', 'LIBPATH', 'LIBS', 'CCFLAGS',
			'CXXFLAGS', 'CPPDEFINES', 'CPPPATH', 'CC', 'CXX', 'is_configured', 'spring_defines']:
			if env.has_key(key): env.__delitem__(key)

		print "\nNow configuring.  If something fails, consult `config.log' for details.\n"

		#parse cmdline
		def makeHashTable(args):
			table = { }
			for arg in args:
				if len(arg) > 1:
					lst = arg.split('=')
					if len(lst) < 2: continue
					key = lst[0]
					value = lst[1]
					if len(key) > 0 and len(value) > 0: table[key] = value
			return table

		args = makeHashTable(sys.argv)

		env['is_configured'] = 5

		if args.has_key('platform'): env['platform'] = args['platform']
		else: env['platform'] = detect.platform()
		fix_windows_spawn(env)

		if os.environ.has_key('CC'):
			env['CC'] = os.environ['CC']
		else:
			env['CC'] = 'gcc'
		if os.environ.has_key('CXX'):
			env['CXX'] = os.environ['CXX']
		else:
			env['CXX'] = 'g++'

		gcc_version = config.check_gcc_version(env)

		# Declare some helper functions for boolean and string options.
		def bool_opt(key, default):
			if args.has_key(key):
				if args[key] == 'no' or args[key] == 'false' or args[key] == '0':
					env[key] = False
				elif args[key] == 'yes' or args[key] == 'true' or args[key] == '1':
					env[key] = True
				else:
					print "\ninvalid", key, "option, must be one of: yes, true, no, false, 0, 1."
					env.Exit(1)
			else: env[key] = default

		def string_opt(key, default):
			if args.has_key(key):
				env[key] = args[key]
			else: env[key] = default

		def stringarray_opt(key, default):
			if args.has_key(key):
				env[key] = args[key].split(';')
			else: env[key] = default

		# Use single precision constants only.
		# This should be redundant with the modifications done by tools/double_to_single_precision.sed.
		# Other options copied from streflop makefiles.
		env['CCFLAGS'] = ['-fsingle-precision-constant', '-frounding-math', '-fsignaling-nans', '-mieee-fp']

		# profile?
		bool_opt('profile', False)
		if env['profile']:
			print "profiling enabled,",
			env.AppendUnique(CCFLAGS=['-pg'], LINKFLAGS=['-pg'])
		else:
			print "profiling NOT enabled,",

		# debug?
		if args.has_key('debug'):
			level = args['debug']
			if level == 'no' or level == 'false': level = '0'
			elif level == 'yes' or level == 'true': level = '3'

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?