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

Import('env')
env = env.Clone()

# Check if current architecture to be built for TA is supported on
# current target or not.
if not env.UserModePreferredArchitecture():
  print("Not building unneeded architecture: ", env["PROC"])
  Return()

# TA output binary will be called 'smcinvoke_example_svc_ta32' or 'smcinvoke_example_svc_ta64'
target = 'smcinvoke_example_svc_ta' + ['32', '64'][env.Is64BitImage()]

includes = [
  "../idl",
  "../inc",
]

sources = [
  'ta_main.c',
  'CAdder.c',
]

# In our TA metadata, we add 'Adder' to a list called 'services'. This is a list of
# services hosted by this TA. By adding Adder here, a different TA with the 'Adder'
# privilege in their 'privileges' metadata section can utilize this service.
md = {
  'appName':      target,
  'privileges': [ 'default' ],
  'services': ['Adder'],
}

# Use the QTEE SDK Builder for TAs
app = env.SecureAppBuilder(
  sources   = sources,
  includes  = includes,
  metadata  = md,
  # 'image' is the name used for the output .so/mbn file
  image     = target,
)

# Add an alias so that the TA can be built by specifying 'smcinvoke_example_svc_ta' on the command line
env.Alias('smcinvoke_example_svc_ta', app)

# Return the TA binary for higher level SConscripts to reference
Return('app')
