#User build variables
vars=Variables()
vars.Add(BoolVariable('release','Set to true to build a release version',False))
vars.Add(EnumVariable('logLevel','The level of logging you wish to see, higher is more','30',allowed_values=[str(x) for x in xrange(60)]))
vars.Add('TARGET_ARCH','Target architecture')
vars.Add('HOST_ARCH','Host architecture')

#Create a new environment for our project
env=DefaultEnvironment(tools=['default','msvc','midl','mssdk','msrpc'],variables=vars)

#Some defines and includes for the environment
env.Append(CPPDEFINES=['UNICODE','_CRT_SECURE_NO_DEPRECATE',('LOGLEVEL','${logLevel}')])
env.Append(CXXFLAGS=['/EHsc'])
env.Append(CPPPATH=['#.','#../include'])
env.Append(LINKFLAGS='/incremental:no')
TARGET_ARCH=env['TARGET_ARCH']
if TARGET_ARCH=='x86_64':
	env.Append(MIDLFLAGS='/x64')

if env['release']:
	print "Building %s release version"%TARGET_ARCH
	env.Append(CPPDEFINES=['NDEBUG'])
	env.Append(CCFLAGS='/O2')
	env.Append(LINKFLAGS='/release')
else:
	print "Building %s debug version"%TARGET_ARCH
	env.Append(PDB='${TARGET}.pdb')

Export('env')

clientInstallDir=Dir('../../extras/controllerClient')
if TARGET_ARCH=='x86_64':
	libInstallDir=Dir('../lib64')
else:
	libInstallDir=Dir('../lib')

buildList=[]


acrobatAccessRPCStubs=env.SConscript('acrobatAccess_sconscript')
Export('acrobatAccessRPCStubs')

ia2RPCStubs=env.SConscript('ia2_sconscript')
Export('ia2RPCStubs')

if TARGET_ARCH=='x86':
	localLib=env.SConscript('local/sconscript')
	Export('localLib')
	env.Install(libInstallDir,localLib)
	buildList.append(localLib)

clientLib=env.SConscript('client/sconscript')
Export('clientLib')
env.Install(clientInstallDir,clientLib)
buildList.append(clientLib)

remoteLib=env.SConscript('remote/sconscript')
Export('remoteLib')
env.Install(libInstallDir,remoteLib)
buildList.append(remoteLib)

if TARGET_ARCH=='x86_64':
	remoteLoaderProgram=env.SConscript('remoteLoader/sconscript')
	env.Install(libInstallDir,remoteLoaderProgram)
	buildList.append(remoteLoaderProgram)

vbufBaseStaticLib=env.SConscript('vbufBase/sconscript')
Export('vbufBaseStaticLib')

adobeAcrobatVBufBackend=env.SConscript('vbufBackends/adobeAcrobat/sconscript')
env.Install(libInstallDir,adobeAcrobatVBufBackend)
buildList.append(adobeAcrobatVBufBackend)

geckoVBufBackend=env.SConscript('vbufBackends/gecko_ia2/sconscript')
env.Install(libInstallDir,geckoVBufBackend)
buildList.append(geckoVBufBackend)

mshtmlVBufBackend=env.SConscript('vbufBackends/mshtml/sconscript')
env.Install(libInstallDir,mshtmlVBufBackend)
buildList.append(mshtmlVBufBackend)

buildTarget=env.Alias('build',buildList)
installTarget=env.Alias('install',[clientInstallDir,libInstallDir])
env.Requires(installTarget,buildTarget)
env.Default(buildTarget)
