view SConstruct @ 379:1ae78e506bd7

Updated the devkit installer to the one I used for the Jan2010 Dev Kit.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 12 Jan 2010 16:49:06 +0000
parents 64738befdf3b
children 2a1259ce2b95
line wrap: on
line source

import os, sys
import utils.scons.scons_utils as utils
from distutils.sysconfig import get_python_lib

_sep = os.path.sep

vars = Variables()
vars.Add(PathVariable('DESTDIR', 
			'Destination directory (prepended to prefix)',
			None,
			PathVariable.PathAccept ))

#propagate the invoking users complete external environment
env = Environment(variables = vars, 
			ENV = os.environ,
			DESTDIR = '${DESTDIR}')

env.EnsureSConsVersion(1,2)

#**************************************************************************
#add any command line options here
#**************************************************************************
AddOption('--release',
		dest='release',
		action="store_true",
		help='Builds the release version of the binaries',
		default=False)
		
AddOption('--disable-opengl',
		dest='disable-opengl',
		action="store_true",
		help='Disable OpenGL support',
		default=False)		

AddOption('--disable-zip',
		dest='disable-zip',
		action="store_true",
		help='Disable ZIP archive support',
		default=False)	

AddOption('--disable-log',
		dest='disable-log',
		action="store_true",
		help='Disable engine logging support',
		default=False)	

AddOption('--enable-rend-camzone',
		dest='enable-rend-camzone',
		action="store_true",
		help='Enables camera zone renderer',
		default=False)
		
AddOption('--enable-rend-grid',
		dest='enable-rend-grid',
		action="store_true",
		help='Enables camera grid renderer',
		default=False)

AddOption('--enable-profile',
		dest='enable-profile',
		action="store_true",
		help='Build with profiling information',
		default=False)
		
AddOption('--prefix',
		dest='prefix',
		nargs=1, type='string',
		action='store',
		metavar='DIR',
		help='installation prefix')
		
AddOption('--python-prefix',
		dest='python-prefix',
		nargs=1, type='string',
		action='store',
		metavar='DIR',
		help='Python module installation prefix')
		
#**************************************************************************
#save command line options here
#**************************************************************************
if GetOption('release'):
	debug = 0
else:
	debug = 1
	
if GetOption('disable-opengl'):
	opengl = 0
else:
	opengl = 1

if GetOption('disable-zip'):
	zip = 0
else:
	zip = 1

if GetOption('disable-log'):
	log = 0
else:
	log = 1

if GetOption('enable-rend-camzone'):
	rend_camzone = 1
else:
	rend_camzone = 0

if GetOption('enable-rend-grid'):
	rend_grid = 1
else:
	rend_grid = 0

if GetOption('enable-profile'):
	profile = 1
else:
	profile = 0

#set the default installation directories.
prefix = GetOption('prefix')
if prefix is None:
	if sys.platform == 'win32':
		prefix = '\\fife'
	elif sys.platform == 'darwin':
		prefix = '/opt/local'
	else:
		prefix = '/usr/local'

pythonprefix = GetOption('python-prefix')
if pythonprefix is None:
	pythonprefix = get_python_lib()

if env.has_key('DESTDIR'):
	prefix = env['DESTDIR'] + prefix
	pythonprefix = env['DESTDIR'] + pythonprefix

#**************************************************************************
#get platform specific information
#**************************************************************************
platformConfig = utils.getPlatformConfig()
env = platformConfig.initEnvironment(env)
env = platformConfig.addExtras(env, opengl)

#**************************************************************************
#define custom library/header check functions
#**************************************************************************
conf = Configure(env,
		custom_tests = {'checkPKG': utils.checkPKG,
				'checkConf': utils.checkConf },
				conf_dir = os.path.join('#','build','.sconf_temp'),
				log_file = os.path.join('#','build','config.log'),
				clean=True)
	
def checkForLib(lib, header='', language='c++'):
	ret = conf.checkPKG(lib)
	if not ret:
		ret = conf.checkConf(lib)
		if not ret:
			if len(header):
				ret = conf.CheckLibWithHeader(libs=lib, header=header, language=language)
			else:
				ret = conf.CheckLib(library=lib, language=language)
					
	return ret
	
def checkForLibs(liblist, required=1, language='c++'):
	ret = 0
	for lib, header in liblist:
		if (isinstance(lib, tuple)):
			for item in lib:
				ret = checkForLib(item, header, language)
					
				if ret:
					env.AppendUnique(LIBS = [item])
					break
		else:
			ret = checkForLib(lib, header, language)
			if ret:
				env.AppendUnique(LIBS=[lib])
	
		if required and not ret:
			if (isinstance(lib, tuple)):
				for item in lib:
					print 'Required lib %s not found!' %item
			else:
				print 'Required lib %s not found!' %lib
			Exit(1)
		
#**************************************************************************
#check the existence of required libraries and headers
#**************************************************************************
required_libs = platformConfig.getRequiredLibs(opengl)
optional_libs = platformConfig.getOptionalLibs(opengl)

required_headers = platformConfig.getRequiredHeaders(opengl)

# do not run the check for dependencies if you are running
# a clean or building the external dependencies
if not GetOption('clean') and 'ext' not in COMMAND_LINE_TARGETS:
	if required_libs:
		checkForLibs(required_libs, required = 1)
	if optional_libs:
		checkForLibs(optional_libs, required = 0)
	if required_headers:
		for h in required_headers:
			conf.CheckHeader(h)

#**************************************************************************
#set variables based on command line options
#**************************************************************************
if debug:
	env.AppendUnique(CXXFLAGS=['-ggdb', '-O0', '-D_DEBUG'])
	engine_var_dir = os.path.join('build','engine','debug')
	tests_var_dir = os.path.join('build','tests','debug')
	print "Building DEBUG binaries..."
else:
	env.AppendUnique(CXXFLAGS=['-O2'])
	engine_var_dir = os.path.join('build','engine','release')
	tests_var_dir = os.path.join('build','tests','release')
	print "Building RELEASE binaries..."

if opengl: 
	env.Append(CPPDEFINES = ['HAVE_OPENGL'])
if zip:
	env.Append(CPPDEFINES = ['HAVE_ZIP'])
if log:
	env.Append(CPPDEFINES = ['LOG_ENABLED'])
if rend_camzone:
	env.Append(CPPDEFINES = ['RENDER_CAMZONES'])
if rend_grid:
	env.Append(CPPDEFINES = ['RENDER_GRID'])
if profile:
	env.Append(CPPFLAGS = ['-pg'])
	env.Append(LINKFLAGS = ['-pg'])
	
#last but not least get any CXXFLAGS passed to scons via command line
if ARGUMENTS.get('CXXFLAGS'):
	env.AppendUnique(CXXFLAGS = Split(ARGUMENTS.get('CXXFLAGS'))) 
else:
	env.AppendUnique(CXXFLAGS=['-Wall', '-Wno-unused'])

#**************************************************************************
#global compiler flags used for ALL targets
#**************************************************************************
env.Append(CPPPATH='#engine/core')

#**************************************************************************
#variables to pass to the SConscript
#TODO: clean this up a bit.  Should probably make sure unittest++ exists.
#**************************************************************************
opts = {'SRC' : os.path.join(os.getcwd(), 'engine',),
		'DEBUG' : debug,
		'PREFIX' : prefix,
		'TESTLIBS' : ['fife', 'UnitTest++'],
		'PYTHON_PREFIX' : pythonprefix,
		'WRAP_COPY_DEST' : os.path.join('#engine', 'swigwrappers', 'python'),
		'PYLIB_COPY_DEST' : os.path.join('#engine', 'python', 'fife')}

if debug:
	opts['LIBPATH'] = os.path.join(os.getcwd(), 'build', 'engine', 'debug')
else:
	opts['LIBPATH'] = os.path.join(os.getcwd(), 'build', 'engine', 'release')

#**************************************************************************
#target for static and shared libraries
#**************************************************************************
Export('env')

#build the engine
env.SConscript('engine/SConscript', variant_dir=engine_var_dir, duplicate=0, exports='opts')

#build the engine tests
env.SConscript('tests/core_tests/SConscript', variant_dir=tests_var_dir, duplicate=0, exports='opts')

#build the external dependencies
env.SConscript('ext/SConscript')

#**************************************************************************
#documentation target
#**************************************************************************
def generate_docs(target = None, source = None, env = None):
	os.system('doxygen $SOURCES')

doc_builder = Builder(action = generate_docs)
env.Append(BUILDERS = {'BuildDocs': doc_builder})
Alias('docs', env.BuildDocs('docs', os.path.join('doc', 'doxygen', 'doxyfile')))

#**************************************************************************
#Set the default target
#**************************************************************************
#clear the default target
Default()
#make fife-python the default target
Default('fife-python')

# vim: set filetype=python: