import sys

EnsureSConsVersion(0,98,1)

#######################################################
# reusable functions and data structures
#######################################################

# Platform to Target Map (specifies which default target to build on a platform)
PLATFORM_TO_TARGET_MAP = { 
    'linux-i386' : 'x86-unknown-linux',
    'linux2'     : 'x86-unknown-linux',
    'win32'      : 'x86-microsoft-win32',
    'cygwin'     : 'x86-unknown-cygwin',
    'darwin'     : 'universal-apple-macosx'
}
  
CROSS_PLATFORMS = ['ppu-sony-ps3', 'arm-unknown-linux', 'mips-unknown-linux', 'powerpc-unknown-linux', 'arm-gp2x-linux', 'arm-symbian-symbianos', 'mipsel-sigma-linux', 'arm-apple-darwin', 'arm-android-linux']
  
def DefaultTarget():
    if PLATFORM_TO_TARGET_MAP.has_key(sys.platform):
        return PLATFORM_TO_TARGET_MAP[sys.platform]
    else:
        return None
        
#######################################################
# Main Build
#######################################################
options = Variables()
options.AddVariables(
    EnumVariable('target', 'build target', DefaultTarget(), allowed_values=PLATFORM_TO_TARGET_MAP.values()+CROSS_PLATFORMS),
    BoolVariable('stop_on_warning', 'Stop the build on warnings', False),
    ListVariable('build_config', 'build configurations', 'Debug', names=['Debug', 'Release'])
)

env = Environment(variables=options)
Help(options.GenerateHelpText(env))

### call the actual build script for each build config
base_env = env
for build_config in env['build_config']:
    env = base_env.Clone()
    env['build_config'] = build_config
    print '********** Configuring Build Target =', env['target'], '/', build_config, '********'  
    SConscript('Build.scons', build_dir='Targets/'+env['target']+'/'+build_config, exports='env', duplicate=0)
