###########################################################################
#
# Copyright 2016 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
###########################################################################

##
# This script includes tizenrt specific config
##
import os
import platform

Import('env')

print "Reading tizenrt configuration script"

host = platform.system().lower()

default_os_dir = env.GetLaunchDir() + '/../../../os'

# TIZENRT_OS_DIR build option
if env.get('TIZENRT_OS_DIR'):
        tizenrt_os_dir = ARGUMENTS.get('TIZENRT_OS_DIR',default_os_dir)
	print 'TIZENRT_OS_DIR = ' + tizenrt_os_dir
else:
        print '''
*************************************** Info **********************************
*   Environment variable TIZENRT_OS_DIR must be set to absolute path of       *
*   tizenrt os directory. To set, please specify TIZENRT_OS_DIR as follows:   *
*       scons TIZENRT_OS_DIR= <path to tizenrt os directory>                  *
*******************************************************************************
'''

target_arch = env.get('TARGET_ARCH')

env.AppendUnique(CCFLAGS = ['-fno-builtin'])
# Set release/debug flags
if env.get('RELEASE') == 1:
	env.AppendUnique(CCFLAGS = ['-Os'])
	env.AppendUnique(CPPDEFINES = ['NDEBUG'])

#Set debug Symbols
if env.get('DEBUGSYM') == 'True':
	env.AppendUnique(CCFLAGS = ['-g'])

arch_board = ARGUMENTS.get('ARCH_BOARD')
if arch_board == 'sidk_s5jt200':
	env.AppendUnique(CCFLAGS = ['-mcpu=cortex-r4', '-mfpu=vfpv3', '-Wall',
		'-Wstrict-prototypes', '-Wshadow', '-Wundef', '-Wno-implicit-function-declaration',
		'-Wno-unused-function', '-Wno-unused-but-set-variable', '-fno-strict-aliasing',
		'-fno-strength-reduce'])
	env.AppendUnique(CXXFLAGS = ['-fno-builtin', '-fexceptions', '-mcpu=cortex-r4', '-mfpu=vfpv3',
		'-Wall', '-Wshadow', '-Wundef', '-fno-strict-aliasing',	'-fno-strength-reduce'])

# we have variety of macros for tizenrt!!
#env.AppendUnique(CPPDEFINES = ['CONFIG_CLOCK_MONOTONIC'])
env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__TIZENRT__'])
# Set device name to __OIC_DEVICE_NAME__
env.AppendUnique(CPPDEFINES = ['-D__OIC_DEVICE_NAME__=' + "\'\"" + env.get('DEVICE_NAME') + "\"\'"])
if env.get('LOGGING'):
	print 'LOGGING is enabled'
	env.AppendUnique(CPPDEFINES = ['TB_LOG'])


# Determine dependency for tizenrt_os_dir

dep_src_dir1 =  os.path.join(tizenrt_os_dir, 'include')
dep_src_dir2 =  os.path.join(tizenrt_os_dir, 'include/tinyara')
dep_src_dir3 =  os.path.join(tizenrt_os_dir, '../external/include')
dep_lib_dir =  '/usr/lib/arm-none-eabi/include'


# Add directories to search for header files and external libraries
env.AppendUnique(CPPPATH = [ dep_src_dir1, dep_src_dir2, dep_src_dir3 ])
env.AppendUnique(LIBPATH = [ dep_lib_dir ])

print env.get('CPPPATH')
