import glob
import os

Import('env', 'mymode', 'compiler', 'project', 'precision', 'rounding')
localenv = env.Clone()

#flags
#extra compile flags
if mymode == 'maxidebug':
	verbose_define='-DVERBOSE=20'
	mycflags = [verbose_define]

if mymode == 'debug':
	verbose_define='-DVERBOSE=2'
	mycflags = [verbose_define]

if mymode == 'profile':
	verbose_define='-DVERBOSE=0'
	mycflags = [verbose_define]

if mymode == 'release' or mymode == 'optimized':
	verbose_define='-DVERBOSE=0'
	mycflags = [verbose_define]

localenv.Append(CCFLAGS= mycflags)

#libs
localenv.Append(CPPPATH=['#io', '#toolkit', '#subdomain', '#engine'])

#holds the root of the build directory tree
builddir = os.path.join(localenv['workspace'], '.build', project, compiler, mymode, precision, rounding)

#holds the path to the executable in the build directory
targetpath = '../' + project + '-' + mymode + '-' + compiler + '-' + precision + '-' + rounding + '.exec'

#specify the build directory
localenv.VariantDir(builddir, ".", duplicate=0)

#Build objects
objs = SConscript('project/' + project +'/SConscript', exports = 'localenv', variant_dir=os.path.join(builddir,'project', project), duplicate=0)
objs.append(SConscript('engine/SConscript', exports = 'localenv', variant_dir=os.path.join(builddir,'engine'), duplicate=0))
objs.append(SConscript('io/SConscript', exports = 'localenv', variant_dir=os.path.join(builddir,'io'), duplicate=0))
objs.append(SConscript('subdomain/SConscript', exports = 'localenv', variant_dir=os.path.join(builddir,'subdomain'), duplicate=0))
objs.append(SConscript('toolkit/SConscript', exports = 'localenv', variant_dir=os.path.join(builddir,'toolkit'), duplicate=0))

srclst = map(lambda x: builddir + '/' + x, glob.glob('*.cpp'))
objs.append(localenv.Object(srclst))

xxx = localenv.Program(targetpath, objs)

Return('xxx')
