#===============================================================================
#  Copyright (c) 2011-2020 QUALCOMM Technologies Incorporated.
#  All Rights Reserved.
#  Qualcomm Confidential and Proprietary
#===============================================================================

#-------------------------------------------------------------------------------
# Source PATH
#-------------------------------------------------------------------------------
import os
Import('env')
env = env.Clone()

#------------------------------------------------------------------------------
# Check build flag
#------------------------------------------------------------------------------
if 'ICCC_GRDM_FEATURE' in os.environ:
  if os.environ['ICCC_GRDM_FEATURE'] in ['true']:

    if not hasattr(env, 'IMAGE_ALIASES'):
      aliases = []
      aliases = ['testgrd2',]
      env.Replace(OUT_DIR = '${BUILD_ROOT}/ssg/bsp/trustzone/qsapps/testgrd2/build/$PROC')
      env.Replace(LIB_OUT_DIR = '${BUILD_ROOT}/ssg/bsp/trustzone/qsapps/testgrd2/build/${SHORT_BUILDPATH}/$PROC')

    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 = " -DTEST2")

    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/uclib/usr/legacy/secmath/shared/inc', # secmath.h
                '#../../ssg/securemsm/uclib/usr/legacy/secrsa/shared/inc',  # secrsa_err.h
                '#../../ssg/securemsm/uclib/usr/legacy/secrsa/shared/src',  # secrsa_padding.h
                '#../../ssg/securemsm/trustzone/qsapps/testgrd/inc',
                '#../../ssg/securemsm/tz_icccgrd_common/inc',
    ]

    #-------------------------------------------------------------------------------
    # App core Objects
    #-------------------------------------------------------------------------------

    sources = ['../../testgrd/src/app_main.c',
              '../../../../tz_icccgrd_common/src/tz_iccc_grdm_api.c'
    ]

    target_name = 'testgrd2'
    app_name = 'testgrd2'
    #uuid_name = '192605ba-3b7a-4f78-af3b-003212aa6dc3'

    #-------------------------------------------------------------------------------
    # Add metadata to image
    #-------------------------------------------------------------------------------
    md = {
      'appName': app_name, # 'UUID': uuid_name, (Only for new chipset)
      'privileges': [
                    'default',
                    'ICCCGrdmROTCred',
                    'ICCCGrdmBLCred',
                    'ICCCGrdmICCCCred',
                    'ICCCGrdmDefaultCred',
                    ],
      'heapSize': 0x10000,
    }

    deploy_header_files = env.Glob('../inc/*')

    testgrd_units = env.SecureAppBuilder(
      sources = sources,
      includes = includes,
      metadata = md,
      image = target_name,
      deploy_sources = sources + ['SConscript'] + deploy_header_files
    )

    if hasattr(env, 'IMAGE_ALIASES'):
      for image in env['IMAGE_ALIASES']:
        env.Alias(image, testgrd_units)
    else:
      env.Alias(aliases, testgrd_units)
