# Copyright (c) Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.

import os

# First, call into the QTEE SDK to get an Environment with all the tools
try:
  sdk_dir = "../../"

  print("Initialising QTEE SDK..")
  # Call the QTEE SDK SConscript to get a QTEE SDK SCons Environment
  qtee_sdk_env = SConscript(os.path.join(sdk_dir,'SConstruct'))

except:
  print("Unable to initialize QTEE SDK at: {}".format(os.path.realpath(sdk_dir)))

  #re-raise the exception
  raise
  Exit(1)

# This example builds both 32bit and 64bit versions of te skeleton CA/TA
for arch in ["aarch32", "aarch64"]:
  env = qtee_sdk_env.Clone()

  # Initialize the environment for the target architecture
  # note: for off-target builds aarchXX is mapped to x86-XX
  env.InitArch(arch)
  if not env.UserModeSupportsArchitecture():
     print("Not building unsupported architecture: ", env["PROC"])
     continue

  out_dir = os.path.join(Dir(".").srcnode().abspath, "out", env["SHORT_BUILDPATH"], "${PROC}")
  env.Replace(OUT_DIR=out_dir)
  env.Replace(LIB_OUT_DIR=out_dir)

  # Call the TA and common SConscripts
  ta = env.SConscript("src/SConscript", exports="env")
