#===============================================================================
#  Copyright (c) 2011-2020 QUALCOMM Technologies Incorporated.
#  All Rights Reserved.
#  Qualcomm Confidential and Proprietary
#===============================================================================

#-------------------------------------------------------------------------------
# Source PATH
#-------------------------------------------------------------------------------
import os
Import('env')
env = env.Clone()

if not hasattr(env, 'IMAGE_ALIASES'):
  aliases = []
  aliases = ['tz_test',]
  env.Replace(OUT_DIR = '${BUILD_ROOT}/ssg/bsp/trustzone/qsapps/tz_test/build')
  env.Replace(LIB_OUT_DIR = '${BUILD_ROOT}/ssg/bsp/trustzone/qsapps/tz_test/build/${SHORT_BUILDPATH}')

if env.has_key('USES_NO_CP'):
  env.Append(CCFLAGS = ' -DUSES_NO_CP ')

#------------------------------------------------------------------------------
# We need to specify "neon" to generate SIMD instructions in 32-bit mode
#------------------------------------------------------------------------------
if env['PROC'] == 'scorpion':
  env.Append(CCFLAGS = " -mfpu=neon ")

env.Append(CCFLAGS = " -DTEST1_APP")

includes = ['#../../core/api/services',                                 # comdef.h
            '#../../ssg/api/securemsm/trustzone/gp',                    # Global Platform API
            '#../../ssg/api/securemsm/trustzone/qsee',                  # QSEE API
            '#../../ssg/securemsm/trustzone/qsee/idl/public',           # .idl
            '#../../ssg/securemsm/trustzone/qsee/mink/include',         # object.h
            '#../../ssg/securemsm/tz_iccc_common/public',               # tz_iccc_comdef.h
            '#../../ssg/securemsm/trustzone/qsapps/tz_test/inc',        # TEST internal
]

#----------------------------------------------------------------------------
# App core Objects
#----------------------------------------------------------------------------

sources = ['../../tz_test/src/app_main.c',
           '../../../../tz_iccc_common/tl/tz_iccc_common_tl.c',
]

#-------------------------------------------------------------------------------
# Add Libraries to image
#-------------------------------------------------------------------------------

libs = []

if env['PROC'] == 'scorpion':
  libca = env.SubstRealPath('${MUSL32PATH}/lib/libc.a')
else:
  libca = env.SubstRealPath('${MUSLPATH}/lib/libc.a')

libs.append(env.File(libca))

target_name = 'tz_test'
app_name = 'tz_test'
#uuid_name = '192605ba-3b7a-4f78-af3b-003212aa6dc3'

#-------------------------------------------------------------------------------
# Add metadata to image
#-------------------------------------------------------------------------------
md = {
  'appName': app_name, # 'UUID': uuid_name, (Only for new chipset)
  'privileges': [
                 'default',
                 'ICCCSaveData',
                 'ICCCReadData',
                 'ICCCGetDeviceStatus'
                ],
  'heapSize': 0x10000,
}

deploy_header_files = env.Glob('../inc/*')

test_units = env.SecureAppBuilder(
  sources = sources,
  includes = includes,
  metadata = md,
  image = target_name,
  user_libs = libs,
  deploy_sources = sources + ['SConscript'] + deploy_header_files,
)

if hasattr(env, 'IMAGE_ALIASES'):
  for image in env['IMAGE_ALIASES']:
    env.Alias(image, test_units)
else:
  env.Alias(aliases, test_units)
