#######################################################
#	Build IP adapter
#######################################################

Import('env')
import os.path

print "Reading IP adapter script"

target_os = env.get('TARGET_OS')
inc_files = env.get('CPPPATH')
secured = env.get('SECURED')
src_dir = './ip_adapter/'


# Source files to build common for all platforms
common_files = None
if target_os == 'arduino':
    common_files = [ os.path.join(src_dir,
                                  'caipadapter.c') ]
else:
    common_files = [
        os.path.join(src_dir, 'caipadapter.c'),
	os.path.join(src_dir, 'caipserver.c') ]

# Get list of target-specific source file base names, i.e. no parent
# directories prepended to the path.
#
# Target-specific SConscript files are expected to return that list.
target_files = []
target_sconscript = os.path.join(target_os, 'SConscript')

# Check for the existence of the platform-specific SConscript file
# relative to the top-level source directory, not the build (variant)
# directory, before calling that SConscript file to prevent a missing
# file warning platforms that don't provide one.
target_sconscript_abspath = str(File(target_sconscript).srcnode().abspath)
if os.path.exists(target_sconscript_abspath):
        target_files = env.SConscript(target_sconscript, exports='src_dir')

# Now prepend the appropriate parent directories
# (e.g. ./ip_adapter/android) to each of the target source files in
# the list.
target_files = [ os.path.join(src_dir, target_os, f) for f in target_files ]

# Source files to build for Linux-like platforms
if target_os in ['linux','darwin','ios']:
    target_files += [ os.path.join(src_dir,
                                   'linux/caipnwmonitor.c') ]

if target_os in ['msys_nt']:
	target_files += [ os.path.join(src_dir, 'windows/caipnwmonitor.c') ]

# The list of BLE adapter source files is a combination of both the
# common and target-specific source file lists.
env.AppendUnique(CA_SRC = common_files + target_files)
