--- /dev/null
+##
+# Examples build script
+##
+Import('env')
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
+
+examples_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+examples_env.AppendUnique(CPPPATH = [
+ '../../resource/include/',
+ '../../resource/csdk/stack/include',
+ '../../resource/csdk/ocsocket/include',
+ '../../resource/csdk/ocrandom/include',
+ '../../resource/csdk/logger/include',
+ '../../resource/csdk/libcoap',
+ '../../resource/oc_logger/include'
+ ])
+
+target_os = env.get('TARGET_OS')
+if target_os not in ['windows', 'winrt']:
+ examples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+
+ # Note: 'pthread' is in libc for android. On other platform, if use
+ # new gcc(>4.9?) it isn't required, otherwise, it's required
+ if target_os != 'android':
+ examples_env.AppendUnique(LIBS = ['-lpthread'])
+
+examples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+examples_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'coap_csdk', 'oc_logger', 'connectivity_abstraction'])
+if env.get('SECURED') == '1':
+ examples_env.AppendUnique(LIBS = ['tinydtls'])
+
+examples_env.ParseConfig('pkg-config --libs glib-2.0');
+
+if target_os == 'android':
+ examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+ examples_env.AppendUnique(LIBS = ['gnustl_static'])
+
+ if not env.get('RELEASE'):
+ examples_env.AppendUnique(LIBS = ['log'])
+
+if target_os in ['darwin', 'ios']:
+ examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+examples_env.AppendUnique(CPPDEFINES = ['CA_INT'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+OICMiddle = examples_env.Program('OICMiddle', ['OICMiddle.cpp', 'Client.cpp', 'LineInput.cpp', 'RestInput.cpp', 'Server.cpp', 'WrapResource.cpp'])
+
+Alias("examples", [OICMiddle])
+env.AppendTarget('examples')
+
+
+++ /dev/null
-#For Yocto builds, set OS=yocto as a command-line argument to scons once
-#the Yocto toolchain is installed and configured.
-
-#For Linux builds, set the following two variables:
-#Set OIC_RESOURCE_PATH to the root of oic-resource on Ubuntu.
-
-OIC_RESOURCE_PATH = '../..'
-
-#Set OIC_LIBS_PATH to path on Ubuntu that contains liboc.so, liboctbstack.so,
-#liboc_logger.so and libcoap.so.
-
-OIC_LIBS_PATH = '../../out/linux/x86_64/release'
-
-env = DefaultEnvironment()
-target_os = ARGUMENTS.get("OS", "linux").lower()
-output_dir = env.GetLaunchDir() + "/out/" + target_os
-env.VariantDir(output_dir, env.GetLaunchDir(), duplicate=0)
-env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
-env.AppendUnique(LINKFLAGS = ['-pthread'])
-env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap'])
-env.Program(output_dir + '/OICMiddle', [output_dir + '/OICMiddle.cpp',
- output_dir + '/Client.cpp',
- output_dir + '/Server.cpp',
- output_dir + '/WrapResource.cpp',
- output_dir + '/LineInput.cpp',
- output_dir + '/RestInput.cpp'])
-
-if target_os == "yocto":
- '''
- This code injects Yocto cross-compilation flags into scons' default environment
- in order to invoke the relevant tools while performing a build.
- '''
- import os.path, re
- sdk_root = ''
- try:
- CC = os.environ['CC']
- sdk_root = re.search(r'--sysroot=\S+', CC).group().split('=')[1]
- target_prefix = CC.split()[0]
- target_prefix = target_prefix[:len(target_prefix)-3]
- tools = {"CC" : target_prefix+"gcc",
- "CXX" : target_prefix+"g++",
- "AS" : target_prefix+"as",
- "LD" : target_prefix+"ld",
- "GDB" : target_prefix+"gdb",
- "STRIP" : target_prefix+"strip",
- "RANLIB" : target_prefix+"ranlib",
- "OBJCOPY" : target_prefix+"objcopy",
- "OBJDUMP" : target_prefix+"objdump",
- "AR" : target_prefix+"ar",
- "NM" : target_prefix+"nm",
- "M4" : "m4",
- "STRINGS": target_prefix+"strings"}
- PATH = os.environ['PATH'].split(os.pathsep)
- for tool in tools:
- if tool in os.environ:
- for path in PATH:
- if os.path.isfile(os.path.join(path, tools[tool])):
- env[tool] = os.path.join(path, os.environ[tool])
- env.AppendUnique(CPPPATH = [
- sdk_root + '/usr/include/oic/',
- sdk_root + '/usr/include/oic/stack/',
- sdk_root + '/usr/include/oic/ocsocket/',
- sdk_root + '/usr/include/oic/oc_logger/',
- ])
- except:
- print "ERROR configuring Yocto cross-toolchain environment."
- Exit(1)
-elif target_os == "linux":
- if OIC_RESOURCE_PATH == '' or OIC_LIBS_PATH == '':
- print "ERROR Please set both OIC_RESOURCE_PATH and OIC_LIBS_PATH in SConstruct"
- Exit(1)
- env.AppendUnique(CPPPATH = [
- OIC_RESOURCE_PATH + '/resource/include',
- OIC_RESOURCE_PATH + '/resource/csdk/stack/include',
- OIC_RESOURCE_PATH + '/resource/csdk/ocsocket/include',
- OIC_RESOURCE_PATH + '/resource/oc_logger/include',
- ])
- env.AppendUnique(LIBPATH = [OIC_LIBS_PATH])
-else:
- print "ERROR ", target_os, " is an unsupported target"
- Exit(1)