#******************************************************************
#
# Copyright 2017 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
##
# Mini Plugin Manager build script
##

import os.path

Import('env')

target_os = env.get('TARGET_OS')
src_dir = env.get('SRC_DIR')
bridging_path = os.path.join(src_dir, 'bridging')

print "Reading MPM script"

######################################################################
# Build flags
######################################################################
env.PrependUnique(CPPPATH = [ os.path.join(src_dir, 'resource', 'c_common', 'oic_string', 'include'),
                              os.path.join(src_dir, 'extlibs', 'rapidjson', 'include', 'rapidjson')
                            ])
env.AppendUnique(CPPPATH = [ os.path.join(bridging_path, 'include')
                           ])

if target_os not in ['arduino', 'windows']:
        env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
        env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-Wextra', '-Werror'])

if target_os in ['darwin','ios']:
        env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])

env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])

if env.get('LOGGING'):
        env.AppendUnique(CPPDEFINES = ['TB_LOG'])


env.PrependUnique(LIBS = ['mpmcommon'])
#####################################################################
# Source files and Target(s)
######################################################################
minipluginmanager_src = [
         os.path.join(bridging_path, 'mini_plugin_manager', 'miniPluginManager.cpp'),
        ]

env.AppendUnique(MINIPLUGINMANAGER_SRC =minipluginmanager_src)

print "Include path is %s" % env.get('CPPPATH')
print "Files path is %s" % env.get('MINIPLUGINMANAGER_SRC')
if target_os in ['android', 'tizen']:
        mpmlib = env.SharedLibrary('minipluginmanager', env.get('MINIPLUGINMANAGER_SRC'))
else:
        mpmlib = env.StaticLibrary('minipluginmanager', env.get('MINIPLUGINMANAGER_SRC'))
env.InstallTarget(mpmlib, 'minipluginmanager')
env.UserInstallTargetLib(mpmlib, 'minipluginmanager')

