import os

#For internal sdk, this file exists in $SDK_ROOT/external
#For external sdk, this file exists in $SDK_ROOT
code_base = os.path.abspath(Dir('.').abspath,)
if code_base.endswith('internal/external'):
  code_base = os.path.abspath(os.path.join(code_base,'..'))

env = DefaultEnvironment(ENV = os.environ, tools = ['mingw','textfile'])
env.Replace(STANDALONE_SDK = True)

for k,v in ARGUMENTS.items():
  env[k] = v
  
env.Replace(SDK_ROOT=code_base)

#For external builds, there is no $SDK_ROOT/build. however, users will also be provided with
#HK11 / HY11_1 folders. here we can point to that
BUILD_ROOT = ARGUMENTS.get('BUILD_ROOT')
if not BUILD_ROOT:
  print "WARNING! BUILD_ROOT dir {} does not exist or was not passed!".format(BUILD_ROOT)
  print "In order to work with libraries that are only included in HK11 / HY11_1 distributions"
  print "You must specify the full path to HK11/trustzone_images or HY11_1/trustzone_images"
  print "via the BUILD_ROOT argument in order for .libs and headers to be found"
  BUILD_ROOT = env['SDK_ROOT']
else:
  env.Replace(OUT_DIR = '${BUILD_ROOT}/apps/bsp/trustzone/qsapps/${APP_NAME}/build')
  env.Replace(LIB_OUT_DIR = '${BUILD_ROOT}/apps/bsp/trustzone/qsapps/${LIBNAME}/${APP_NAME}/${PROC}/${SHORT_BUILDPATH}')
env.Replace(BUILD_ROOT=BUILD_ROOT)

env = env.Clone()
#Load the Tools and methods
print "SDK_ROOT",env.subst('$SDK_ROOT')
env.Tool('ssg_environment', toolpath = ['${SDK_ROOT}/scripts'])
env.Tool('qcscons_replacement', toolpath= ['${SDK_ROOT}/scripts'])
env.Tool('sdk_tools', toolpath= ['${SDK_ROOT}/scripts'])
env.Tool('idlcompiler', toolpath= ['${SDK_ROOT}/scripts'])

env.Replace(SECTOOLS_BUILDER_VERBOSITY = 'z')
env.Decider('MD5-timestamp')

def dummy(*args,**kwargs):
  pass
  
env.AddMethod(dummy,'Deploy')
env.AddMethod(dummy,'DeployInternal')
env.AddMethod(lambda *args, **kwargs: [],'GetDefaultPublicVariants')
env.AddMethod(lambda *args, **kwargs: [],'GetDefaultPrivateVariants')

Return('env')