#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# liboc_logger (share library) build script
##

Import('env')

lib_env = env.Clone()
SConscript('#resource/third_party_libs.scons', 'lib_env')

liboc_logger_env = lib_env.Clone()
######################################################################
# Build flags
######################################################################
liboc_logger_env.PrependUnique(CPPPATH = ['include'])

target_os = env.get('TARGET_OS')
if target_os == 'android':
	liboc_logger_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
	liboc_logger_env.AppendUnique(LIBS = ['gnustl_shared', 'log'])
	liboc_logger_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,liboc_logger.so'])

if target_os not in ['arduino', 'windows']:
	liboc_logger_env.AppendUnique(CFLAGS = ['-Wall', '-std=c99', '-fPIC'])
	liboc_logger_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x', '-fPIC'])

if target_os not in ['darwin', 'ios', 'windows', 'msys_nt']:
	liboc_logger_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])

######################################################################
# Source files and Targets
######################################################################

oc_logger_libs = []

if target_os in ['windows', 'msys_nt','ios']:
	# If oc_logger APIs have to be exported from a Windows DLL, these functions
	# should be exported from octbstack.dll. Building a separate oc_logger.dll here
	# would result in duplicated code and data across these two DLLs. Using just
	# the static oc_logger.lib is good enough for Windows for now.
	oc_logger_libs += liboc_logger_env.StaticLibrary('oc_logger',
		['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
else:
	oc_logger_libs += Flatten(liboc_logger_env.SharedLibrary('oc_logger_core',
		['c/oc_logger.c'],  OBJPREFIX='core_'))
	oc_logger_libs += Flatten(liboc_logger_env.SharedLibrary('oc_logger',
		['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp']))

liboc_logger_env.InstallTarget(oc_logger_libs, 'oc_logger')
liboc_logger_env.UserInstallTargetLib(oc_logger_libs, 'oc_logger')
liboc_logger_env.UserInstallTargetHeader('include/oc_logger.hpp', 'resource', 'oc_logger.hpp')
liboc_logger_env.UserInstallTargetHeader('include/oc_logger.h', 'resource', 'oc_logger.h')
liboc_logger_env.UserInstallTargetHeader('include/oc_logger_types.h', 'resource', 'oc_logger_types.h')
liboc_logger_env.UserInstallTargetHeader('include/oc_log_stream.hpp', 'resource', 'oc_log_stream.hpp')
liboc_logger_env.UserInstallTargetHeader('include/targets/oc_console_logger.h', 'resource/targets', 'oc_console_logger.h')
liboc_logger_env.UserInstallTargetHeader('include/targets/oc_ostream_logger.h', 'resource/targets', 'oc_ostream_logger.h')

if target_os not in ['ios', 'android']:
	SConscript('examples/SConscript')

