## Sconstruct: starting point of scons
##
##    		(for the manual see: www.scons.org)
##
## REMARK: * start with creating a system environment variable BOOST_ROOT,
##         its value should be the top-directory of blitz 
##		   (e.g. 'c:/libraries/blitz++-0.7')
##
##		   * the locations of header-files/binaries of external libraries are
##         defined in e.g. intel-win32.scons.  The locations of header-files/
## 	       binaries of the compiler should be defined as system-environment 
##         variables...
#
#
# Basic files:
# /SConstruct:			starting-point
# /*.scons:			    (e.g. intel-win32.scons): system and compiler 
#					directives, more details, see intel-win32.scons
# /src/SConscript:		information to compile the static-library blitz
# /examples/SConscript:not yet implemented
#

import os

#### Choose debug or release
#debug = ARGUMENTS.get('debug', 0)
opts = Options('custom.py')
opts.AddOptions(
	EnumOption('Compiler', 'Compiler to use', 'gcc-linux',
		allowed_values=('gcc-linux', 'intel-linux')),
	BoolOption('RELEASE', 'Set to build for release', 0),
	BoolOption('warnings', 'compilation with -Wall and similar', 0),
	BoolOption('strict', 'checks ANSI compatibility', 0),
	BoolOption('effective', 'checks some Effective C++ guidelines', 0))
#	BoolOption('precompiled', 'use precompiled headers', 0)
env = Environment(options = opts)
#                  CPPDEFINES={'RELEASE_BUILD' : '${RELEASE}'})
Compiler = env['Compiler']

#### Setup install dir
if (env['RELEASE'] == 1):
   env.Append(VER = 'Release')
else:
   env.Append(VER = 'Debug')
env.Append(BUILD = '#intermediate/' + env['VER'])
env.Append(gameDir = '#../xenocidegame')

env.Alias('install', '#bin/${VER}')
env.Alias('install', '${gameDir}')

Help(opts.GenerateHelpText(env))

#### Checking library availability
#conf = Configure(env)
#if not conf.CheckLibWithHeader('OgreMain', 'Ogre.h', 'CXX'):
#    print 'Did not find libOgreMain.so or OgreMain.dll, exiting!'
#    Exit(1)
#env = conf.Finish()
    

# determine which options you tell your compiler/linker...
if Compiler == 'intel-win32':
	Export('env')  
	# exports 'env' into intel-win32.scons
	# intel-win32.scons Returns the adjusted variable 'env'
	env = SConscript('intel-win32.scons')
	#### what to do with debug?
	if ('${RELEASE}' == 1):
	   env.Append(CPPDEFINES = {'NDEBUG' : '1'})
	else:
	   print 'DEBUG mode not yet implemented'	
	#BuildDir = 'intel-win32'
	# directory where the library will be build

elif Compiler == 'mingw-win32':
	print 'not yet implemented'	
	Exit(1)
	
elif Compiler == 'intel-linux':
	Export('env')  
	env = SConscript('intel-linux.scons')
	if env['RELEASE']:
	   env.Append(CPPDEFINES = ['NDEBUG'])
	else:
           env.Append(CXXFLAGS = ['-g', '-debug'],
			CPPDEFINES = ['_DEBUG'])
	if (env['warnings']):
	   env.Append(CXXFLAGS = ['-Wall', '-w2', '-Winline'])
	
elif Compiler == 'gcc-linux':
	Export('env')  
	env = SConscript('gcc-linux.scons')
	if env['RELEASE']:
	   env.Append(CXXFLAGS = ['-O2'],
			CPPDEFINES = ['NDEBUG'])
	else:
           env.Append(CXXFLAGS = ['-g3', '-O0'],
			CPPDEFINES = ['_DEBUG'])
	if (env['warnings']):
	   env.Append(CXXFLAGS = ['-W', '-Wall',
				'-Wconversion', '-Wshadow', '-Wcast-qual',
				'-Wwrite-strings'])
	if (env['strict']):
	   env.Append(CXXFLAGS = ['-pedantic', '-ansi'])
	if (env['effective']):
	   env.Append(CXXFLAGS = ['-Weffc++'])
	
Export('env')
# the actual building of the library, determine which files need to be 
# compiled...
SConscript('src/SConstruct',build_dir=env['BUILD'], duplicate=0)

