#******************************************************************
#
# Copyright 2014 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# Simulator build script
##

import os, sys
Import('env')

lib_env = env.Clone()
src_dir = env.get('SRC_DIR')
SConscript(src_dir + '/service/third_party_libs.scons', 'lib_env')
simulator_env = lib_env.Clone()

#Raml Parser
SConscript('ramlparser/SConscript')

target_os = env.get('TARGET_OS')
######################################################################
# Build flags
######################################################################
simulator_env.AppendUnique(CPPPATH = ['inc', 'src/client', 'src/server', 'src/common'])
simulator_env.AppendUnique(CPPPATH = [
		'../../resource/include/',
		'../../resource/csdk/stack/include',
		'../../resource/c_common/ocrandom/include',
		'../../resource/csdk/logger/include',
		'../../resource/oc_logger/include',
		'./ramlparser/raml',
		'./ramlparser/raml/model',		
		'./ramlparser/raml/jsonSchemaParser',	
		'../../extlibs/yaml/yaml/include'
		])

# Including Java path for building JNI files
try:
	os.environ['JAVA_HOME']
except KeyError:
	print '''
*************************************** Error *********************************
* JAVA_HOME environment variable not set                                      
* Simulator has dependency on java, Please set environment variable JAVA_HOME
*******************************************************************************
	'''
	sys.exit(1)
	
java_headers = [os.path.join(os.environ['JAVA_HOME'], 'include')]
java_headers.append(os.path.join(java_headers[0], 'win32'))
java_headers.append(os.path.join(java_headers[0], 'linux'))
java_headers.append(os.path.join(java_headers[0], 'solaris'))
simulator_env.AppendUnique(CPPPATH = java_headers)

simulator_env.Append( RPATH = env.Literal('\\$$ORIGIN'))

simulator_env.AppendUnique(CPPPATH = ['../../extlibs/cjson'])
simulator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'RamlParser'])
simulator_env.AppendUnique(LIBS = ['pthread'])

simulator_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-std=c++0x'])

######################################################################
# Source files and Targets
######################################################################
simulator_src = [env.Glob('src/*.cpp')
                 ,env.Glob('src/*/*.cpp')
                 ,env.Glob('java/jni/*.cpp')
                ]
simulatorsdk = simulator_env.SharedLibrary('SimulatorManager', simulator_src)

simulator_env.InstallTarget(simulatorsdk, 'libSimulatorManager')

#Build sample application
SConscript('examples/server/SConscript')
SConscript('examples/client/SConscript')
