#===============================================================================
#
# HFAT Libs
#
# GENERAL DESCRIPTION
#    build script
#
# Copyright (c) 2009-2011 by QUALCOMM, Incorporated.
# All Rights Reserved.
# QUALCOMM Proprietary/GTDR
#
#-------------------------------------------------------------------------------
#
#  $Header$#  $DateTime$ $Author$
#  $Change$
#                      EDIT HISTORY FOR FILE
#
#  This section contains comments describing changes made to the module.
#  Notice that changes are listed in reverse chronological order.
#
# when        who  what, where, why
# ----------  ---  -------------------------------------------------------------
# 2011-06-02  dks  Migrate from TMC to rcinit.
# 2011-03-25  dks  Support Golden-Copy in RAM for fusion.
# 2011-03-03  dks  Add device setup calls.
# 2010-12-21  dks  Add HFAT lib to modem libraries.
# 2010-12-03  rp   Featurize FS-TAR module.
# 2010-10-14  vr   Remove default inclusion of HOTPLUG for boot.
# 2010-08-26  rp   Enable HFAT for BOOT module based on flag.
# 2010-07-12  dks  Fix USES flag for HFAT feature.
# 2010-06-28  wek  Supress EFS1 related warnings.
# 2010-06-14  vr   Hotplug to compile without EFS for 8660 SBL1.
# 2010-05-10  dks  Added DAL dependency for SCMM maverick.
# 2010-03-19  wek  Unify features defined for boot in all sconscripts.
# 2010-03-05  vr   Add support for QEFS2 in BOOT
# 2010-02-26  yog  Map legacy messages to MSG_SSID_FS
# 2010-02-01  wek  Chaged source path to use core/storage.
#===============================================================================
Import('env')
env = env.Clone()
env.Append(CPPDEFINES=['MSG_BT_SSID_DFLT=MSG_SSID_FS'])

#-------------------------------------------------------------------------------
# Source PATH
#-------------------------------------------------------------------------------
SRCPATH = "${BUILD_ROOT}/core/storage/hfat/src"

env.VariantDir('${BUILDPATH}', SRCPATH, duplicate=0)

#-------------------------------------------------------------------------------
# Internal depends within CoreBSP
#-------------------------------------------------------------------------------
CBSP_API = [
   'DAL',
   'DEBUGTOOLS',
   'MPROC',
   'SERVICES',
   'SYSTEMDRIVERS',
   'STORAGE',

   # needs to be last also contains wrong comdef.h
   'KERNEL',   
]

env.RequirePublicApi(CBSP_API)
env.RequireRestrictedApi(CBSP_API)
env.RequirePrivateApi(['STORAGE'])

#-------------------------------------------------------------------------------
# Sources, libraries
#-------------------------------------------------------------------------------

HFAT_SOURCES = [
   '${BUILDPATH}/hfat_chkfat.c',
   '${BUILDPATH}/hfat_common.c',
   '${BUILDPATH}/hfat_interface.c',
   '${BUILDPATH}/hfat_lfn.c',
   '${BUILDPATH}/hfat_m.c',
   '${BUILDPATH}/hfat_port_f.c'
]

hfat_obj = env.Object(HFAT_SOURCES)
hfat_lib = env.Library('${BUILDPATH}/hfat', hfat_obj)

#-------------------------------------------------------------------------------
# HFAT in BOOT config
#-------------------------------------------------------------------------------

if 'BUILD_BOOT_CHAIN' in env:
  env.Append(CPPDEFINES = ["FEATURE_EFS_BOOT_ENV"])
  env.Append(CPPDEFINES = ["FEATURE_EFS_COMPILE_WITHOUT_MD5"])
  env.Append(CPPDEFINES = ["FEATURE_EFS_COMPILE_WITHOUT_REX"])
  env.Append(CPPDEFINES = ["FEATURE_EFS_COMPILE_WITHOUT_DIAG"])
  env.Append(CPPDEFINES = ["FEATURE_FS_HOTPLUG_DISABLE_TASK"])
  env.Append(CPPDEFINES = ["HOTPLUG_HAVE_PARTITION_SUPPORT"])
  if 'USES_QEFS2_IN_BOOT' in env:
    env.PrintDebugInfo ('efs', "EFS QEFS2 in BOOT variant\n")
  elif 'USES_HOTPLUG_WITHOUT_EFS' in env:
    env.PrintDebugInfo ('efs', "HOTPLUG without EFS variant\n")
    env.Append (CPPDEFINES = ["FEATURE_HOTPLUG_COMPILE_WITHOUT_EFS"])
  else:
    env.PrintDebugInfo ('efs', "EFS ROMFS in BOOT variant\n")
    env.Append (CPPDEFINES = ["FEATURE_EFS_ROMFS"])
else:
  env.PrintDebugInfo ('efs', "EFS in AMSS variant")


if 'USES_FS_HOTPLUG_SD' in env:
  env.Append(CPPDEFINES = ["FEATURE_FS_HOTPLUG_SD"])

if 'USES_FS_FTL' in env:
  env.Append(CPPDEFINES = ["FEATURE_EFS_FTL"])
  env.Append(CPPDEFINES = ["FEATURE_FS_HOTPLUG_FTL"])

if 'USES_FS_HOTPLUG_SD_CPRM' in env:
  env.Append(CPPDEFINES = ["FEATURE_FS_HOTPLUG_SD_CPRM"])

if 'USES_FS_HOTPLUG_USB' in env:
  env.Append(CPPDEFINES = ["FEATURE_FS_HOTPLUG_USB"])

if ('USES_FS_HOTPLUG_SD' in env)        or \
   ('USES_FS_FTL' in env)       or \
   ('USES_FS_HOTPLUG_SD_CPRM' in env)   or \
   ('USES_FS_HOTPLUG_USB' in env):
  env.Append(CPPDEFINES = ["FEATURE_FS_HOTPLUG"])

if 'USES_FS_HFAT' in env:
  env.Append(CPPDEFINES = ["FEATURE_EFS_EXTFS"])
  env.Append(CPPDEFINES = ["FEATURE_EFS_EXTFS_HFAT"])

if 'USES_FS_TAR' in env:
  env.Append(CPPDEFINES = ["FEATURE_FS_TAR"])

if 'USES_EFS_SETUP_DEVICE' in env:
  env.Append(CPPDEFINES = ["FEATURE_EFS_SETUP_DEVICE"])

if 'USES_BACKUP_FUSION_PARTITION' in env:
  env.Append(CPPDEFINES = ["FEATURE_EFS_BACKUP_FUSION_PARTITION"])

if 'USES_NEED_DUAL_SYNC' in env:
  env.Append(CPPDEFINES = ["FEATURE_EFS_NEED_DUAL_SYNC"])

#-------------------------------------------------------------------------------
# Supress all EFS1 warnings on EFS modules.
#-------------------------------------------------------------------------------
env.Append(CPPDEFINES = ["FEATURE_EFS_SUPPRESS_EFS1_WARNINGS"])

#-------------------------------------------------------------------------------
# Add Libraries to image
#-------------------------------------------------------------------------------

if 'USES_FS_HFAT' in env:
  env.AddLibsToImage(['MODEM_IMAGE', 'CBSP_MODEM_IMAGE', 'APPS_IMAGE', 
                      'CBSP_APPS_IMAGE', 'SINGLE_IMAGE', 'CBSP_SINGLE_IMAGE',
                      'SBL3_BOOT_IMAGE'], hfat_lib)

env.AddLibsToImage(['OSBL_BOOT_IMAGE'], hfat_lib)
