Update build scripts
authorCaiwen Zhang <caiwen.zhang@intel.com>
Fri, 5 Dec 2014 08:00:57 +0000 (16:00 +0800)
committerCaiwen Zhang <caiwen.zhang@intel.com>
Mon, 8 Dec 2014 05:35:47 +0000 (13:35 +0800)
1) Add build options to enviornment(env) to avoid export variables
2) Sync with the newest code
3) Update Readme(Readme.scons.txt)
4) Extend arduino supporting
5) Add build scripts for services
6) Add a doc(scons_script_how_to.txt) about how to write iotivity
    build script
7) change resource libs from static library to share library

Last sync and test with the newest code commit:
  e9403ce6d4d7a1a0ac8d12c5acc876af7f7a8f76

Note:
  Scripts for Service are provided but aren't enabled due to the
service code is too old it can't pass the build.

Change-Id: I06427cfe65e6fcf5837376f2f89d1e93c662f920
Signed-off-by: Caiwen Zhang<caiwen.zhang@intel.com>
55 files changed:
Readme.scons.txt [new file with mode: 0644]
SConstruct [new file with mode: 0644]
arduino.scons [new file with mode: 0644]
auto_build.sh [moved from resource/auto_build.sh with 51% similarity]
build_common/SConscript [new file with mode: 0644]
build_common/android/SConscript [moved from resource/build_common/android/SConscript with 76% similarity]
build_common/android/jni/Android.mk [moved from resource/build_common/android/jni/Android.mk with 93% similarity]
build_common/arduino/SConscript [new file with mode: 0755]
build_common/darwin/SConscript [new file with mode: 0644]
build_common/ios/SConscript [new file with mode: 0644]
build_common/linux/SConscript [new file with mode: 0644]
build_common/windows/SConscript [new file with mode: 0644]
extra_options.scons [new file with mode: 0644]
resource/Readme.scons.txt [deleted file]
resource/SConscript [new file with mode: 0644]
resource/SConstruct [deleted file]
resource/arduino.scons [deleted file]
resource/build_common/SConscript [deleted file]
resource/build_common/arduino/SConscript [deleted file]
resource/build_common/darwin/SConscript [deleted file]
resource/build_common/ios/SConscript [deleted file]
resource/build_common/linux/SConscript [deleted file]
resource/build_common/windows/SConscript [deleted file]
resource/csdk/SConscript
resource/csdk/libcoap-4.1.1/SConscript
resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript [new file with mode: 0644]
resource/examples/SConscript
resource/examples/ocicuc/SConscript
resource/oc_logger/SConscript
resource/oc_logger/examples/SConscript [new file with mode: 0644]
resource/src/SConscript
resource/third_party_libs.scons
scons_script_how_to.txt [new file with mode: 0644]
service/SConscript [new file with mode: 0644]
service/notification-manager/SConscript [new file with mode: 0644]
service/notification-manager/SampleApp/SConscript [new file with mode: 0644]
service/notification-manager/SampleApp/arduino/SConscript [new file with mode: 0644]
service/notification-manager/SampleApp/linux/SConscript [new file with mode: 0644]
service/protocol-plugin/SConscript [new file with mode: 0644]
service/protocol-plugin/lib/cpluff/SConscript [new file with mode: 0644]
service/protocol-plugin/plugin-manager/SConscript [new file with mode: 0644]
service/protocol-plugin/plugins/SConscript [new file with mode: 0644]
service/protocol-plugin/plugins/mqtt-fan/lib/SConscript [new file with mode: 0644]
service/protocol-plugin/plugins/mqtt-fan/lib/cpp/SConscript [new file with mode: 0644]
service/protocol-plugin/sample-app/SConscript [new file with mode: 0644]
service/protocol-plugin/sample-app/linux/SConscript [new file with mode: 0644]
service/soft-sensor-manager/SConscript [new file with mode: 0644]
service/soft-sensor-manager/SampleApp/SConscript [new file with mode: 0644]
service/soft-sensor-manager/SampleApp/linux/ClientApp/SConscript [new file with mode: 0644]
service/soft-sensor-manager/SampleApp/linux/THSensorApp/SConscript [new file with mode: 0644]
service/soft-sensor-manager/SampleApp/linux/THSensorApp1/SConscript [new file with mode: 0644]
service/things-manager/SConscript [new file with mode: 0644]
service/things-manager/sampleapp/SConscript [new file with mode: 0644]
service/things-manager/sampleapp/linux/tgmclient/SConscript [new file with mode: 0644]
service/third_party_libs.scons [new file with mode: 0644]

diff --git a/Readme.scons.txt b/Readme.scons.txt
new file mode 100644 (file)
index 0000000..8956c2d
--- /dev/null
@@ -0,0 +1,187 @@
+== How to build Iotivity projects ==
+
+Iotivity includes a series of projects. You can find all these projects here:
+    https://oic-review.01.org/gerrit/#/admin/projects/
+
+You can build Iotivity project on Linux / Windows / MAC OSX for various OS(
+Linux, Tizen, Android, Arduino, Windows, MAC OSX, IOS ...).
+The output of the build is in:
+  <top directory of the project>/out/<target_os>/<target_arch>/<build version>/
+e.g.
+       oic-resource/out/android/armeabi-v7a/release/.
+
+This document takes oic-resource project as example, the way to build other
+projects is almost the same.
+
+=== Iotivity project build tool scons ===
+
+Scons is a cross-platform build tool, its usage is quite similar to GNU make.
+To build a project, you just require to run following command at the directory
+where a SConstruct file exists(SConstruct is the entrance of scons build, it's
+equivalent to Makefile of 'make') :
+      $ scons [options] [target]
+
+In additional, usually the scons build script of a project provides useful help
+information(include build options). To see the help information:
+      $ scons [options] -h
+
+Note: If no value is specified for an option, the default value will be used.
+The change of options value may impact the output.
+
+
+=== Prerequites ===
+
+* 1. Scons
+
+Please refer to the following page to install scons:
+   http://www.scons.org/doc/production/HTML/scons-user.html#chap-build-install
+(Note: on Windows, install Python 2.x before installing scons)
+
+* 2. IDE/SDK Prerequites
+To build for some OS (Android / Arduino / IOS ...), an IDE/SDK may be required,
+please go to the relative page to download and install the required IDE/SDK.
+
+Android:
+To build for Android, Andorid NDK and SDK are required.
+  Android NDK: http://developer.android.com/tools/sdk/ndk/index.html
+  Android SDK: http://developer.android.com/sdk/index.html
+(Note: as in some Iotivity projects, C++11 features are used, recommend Android
+ NDK >= r10, according to our test result r10c is the best one currently)
+
+Arduino:
+To build for Arduino, Arduino IDE is required.
+  Arduino IDE: http://arduino.cc/en/Main/Software
+  (Note: recommend install Arduino IDE >=1.5.7)
+
+Arduino builds are dependent on latest Time library. Download it from here:
+    http://www.pjrc.com/teensy/td_libs_Time.html
+and extract to <arduino_ide_root>/libraries/
+
+(Note: If you are using Arduino IDE 1.5.8 BETA on Windows, it may pop up some
+dll isn't found. please copy relative dll from the IDE directory to
+C:\Windows\SysWOW64. IDE 1.5.7 doesn't have this issue. Other version IDE isn't
+tested.)
+
+Apple:
+To build for Mac OSX or IOS, Xcode is required.
+  Xcode: https://developer.apple.com/xcode/downloads/
+
+Java:
+To build the Java code, JDK is required.
+  JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
+(If the project doesn't include Java code or you wouldn't like build the
+Java codes, this isn't required)
+
+(Note: for convenience, suggest add the IDE/SDK path in environment variable,
+so you don't need to add it in command line each time. The build script will
+guide you to do that.)
+
+* 3. External libraries
+For Android and IOS build, most of the external libraries are provided as
+binary in oic-utilities project (https://oic-review.01.org/gerrit/oic-utilities).
+Please download it in the same directory as other Iotivity projects. If it's
+in different directory, an additional option (OIC_UITLS) will be required. The
+build command should be:
+      $ scons OIC_UITLS=<path to oic-utilities> [other options] [target]
+
+(Note: for convenience, you can also add it in environment variable. So you
+don't need to add this option in command line each time.)
+  e.g.:
+      $ export OIC_UITLS=<path to oic-utilities project>
+
+
+=== Build Iotivity project on Linux(Ubuntu) ===
+
+1. Build Iotivity project for Linux
+      $ cd <top directory of the project>
+      $ sudo apt-get install libboost-dev libboost-program-options-dev
+      $ scons
+
+2. Build Iotivity project for Android
+      $ cd <top directory of the project>
+      $ scons TARGET_OS=android TARGET_ARCH=xxx
+(xxx can be x86, armeabi, armeabi-v7a, armeabi-v7a-hard. To see all of its
+allowed value, please execute command 'scons TARGET_OS=android -Q -h'.
+
+Note: Currently as x86_64/arm64_v8a external library binaries aren't provided,
+you may meet link problem if build executable binary which depends on external
+library for x86_64/arm64_v8a.
+
+3. Build Iotivity project for Arduino
+      $ cd <top directory of the project>
+      $ scons TARGET_OS=arduino TARGET_ARCH=xxx BOARD=yyy
+(xxx can be avr, arm; yyy is the name of the board, to get its allowed value
+run: scons TARGET_OS=arduino TARGET_ARCH=xxx -h. You may see a option 'CPU' in
+the output of above command line, that's due to some boards have different
+processor, to specify the processor, add 'CPU=zzz' in the command line. If no
+'CPU' option exists, that means the board only support one kind of processor,
+it's unnecessary to specify it)
+
+
+=== Build Iotivity project on Windows ===
+
+1. Build Iotivity project for Android(It's the same as on Ubuntu)
+      $ cd <top directory of the project>
+      $ scons TARGET_OS=android TARGET_ARCH=xxx
+(xxx can be x86, armeabi, armeabi-v7a, armeabi-v7a-hard ...)
+
+2. Build Iotivity project for Arduino(It's the same as on Ubuntu)
+      $ cd <top directory of the project>
+      $ scons TARGET_OS=arduino TARGET_ARCH=xxx BOARD=yyy
+(xxx can be avr, arm; yyy is the name of the board, to get its allowed value
+run: scons TARGET_OS=arduino TARGET_ARCH=xxx -h. You may see a option 'CPU' in
+the output of above command line, that's due to some boards have different
+processor, to specify the processor, add 'CPU=zzz' in the command line. If no
+'CPU' option exists, that means the board only support one kind of processor,
+it's unnecessary to specify it)
+
+
+Note: Currently most Iotivity project doesn't support Windows, so you can't set
+TARGET_OS to 'windows' except the project support Windows.
+
+That's to say if the project doesn't support Windows, run:
+      $ scons TARGET_OS=windows ....
+or run on Windows
+      $ scons
+may always fail.
+
+
+=== Build Iotivity project on Mac OSX ===
+
+1. Build Iotivity project for Mac OSX
+      $ cd <top directory of the project>
+      $ scons SYS_VERSION=yyy
+(yyy is the OSX version, e.g. 10.9)
+
+2. Build Iotivity project for Android(It's the same as on Ubuntu)
+      $ cd <top directory of the project>
+      $ scons TARGET_OS=android TARGET_ARCH=xxx
+(xxx can be x86, armeabi, armeabi-v7a, armeabi-v7a-hard)
+
+3. Build Iotivity project for IOS
+      $ cd <top directory of the project>
+      $ scons TARGET_OS=ios TARGET_ARCH=xxx SYS_VERSION=yyy
+(xxx can be i386, x86_64, armv7, armv7s, arm64, yyy is IOS version, e.g. 7.0)
+
+Note:
+1) for convenience, a script (auto_build.sh) is provided to run possible build
+at once. Following is the usage:
+
+To build:
+     $ auto_build.sh <path-to-android-ndk> <path-to-arduino-home>
+To clean:
+     $ auto_build.sh -c
+
+2) Last sync and test with commit e9403ce6d4d7a1a0ac8d12c5acc876af7f7a8f76
+If you meet build error with newest code, it may due to the scripts are not up
+to date. Please try commit 5f16c38a5380e4b5c0d82e2cfea4af5fdc30c9ac or send mail
+to <OIC-OSD@list.01.org>.
+
+3) The build scripts for services have been provided. As the services code is
+out of date, it must the sync with newest resource code, otherwise, it can't
+pass the build, currently, the build scripts for services aren't enabled. Please
+remove the '#' at line 31 in 'SConstruct' file to enable it after the code is
+updated.
+
+4) For Arduino build, the Time library should >=1.3. The old can only be built
+with Arduino IDE 1.0.x
diff --git a/SConstruct b/SConstruct
new file mode 100644 (file)
index 0000000..fd1b034
--- /dev/null
@@ -0,0 +1,39 @@
+##
+# The main build script
+#
+##
+
+# Load common build config
+SConscript('build_common/SConscript')
+
+# Load extra options
+SConscript('extra_options.scons')
+Import('env')
+
+target_os = env.get('TARGET_OS')
+if target_os == 'arduino':
+       SConscript('arduino.scons')
+# By default, src_dir is current dir, the build_dir is:
+#     ./out/<target_os>/<target_arch>/<release or debug>/
+#
+# The build_dir is a variant directory of the source directory(You can
+# consider build_dir as a soft link to src_dir, for detail please refer to:
+#     http://www.scons.org/doc/production/HTML/scons-user.html#f-VariantDir
+#
+# Any way, to make the output is in build_dir, when load scripts, the path should
+# be relevant to build_dir.
+build_dir = env.get('BUILD_DIR')
+
+# Build 'resource' sub-project
+SConscript(build_dir + 'resource/SConscript')
+
+# Build 'service' sub-project
+#SConscript(build_dir + 'service/SConscript')
+
+# Append targets information to the help information, to see help info, execute command line:
+#     $ scon [options] -h
+env.PrintTargets()
+
+# Print bin upload command line (arduino only)
+if target_os == 'arduino':
+       env.UploadHelp()
diff --git a/arduino.scons b/arduino.scons
new file mode 100644 (file)
index 0000000..4ab2aff
--- /dev/null
@@ -0,0 +1,11 @@
+##
+# This script includes arduino specific config for oic-resource
+##
+Import('env')
+
+env.ImportLib('Time')
+if env.get('NET') == 'Ethernet':
+       env.ImportLib('Ethernet')
+else:
+       env.ImportLib('WiFi')
+env.ImportLib('SPI')
\ No newline at end of file
similarity index 51%
rename from resource/auto_build.sh
rename to auto_build.sh
index 14aca7f..9f947eb 100755 (executable)
@@ -4,58 +4,58 @@ function clean()
 {
        echo "*********** Clean build *************"
        scons -c
-       rm out -rf
+       rm -rf out
 }
 
 function build()
 {
-       echo "*********** Build for linux *************"
-       scons
+       if [ $(uname -s) = "Linux" ]
+        then
+               echo "*********** Build for linux *************"
+               scons RELEASE=$3
+       fi
 
        # Note: for android, as oic-resource uses C++11 feature stoi and to_string,
        # it requires gcc-4.9, currently only android-ndk-r10(for linux)
        # and windows android-ndk-r10(64bit target version) support these features.
 
        echo "*********** Build for android x86 *************"
-       scons BUILD_TARGET=Android CPU_ARCH=x86 ANDROID_HOME=$1 ANDROID_NDK=$2
+       scons TARGET_OS=android TARGET_ARCH=x86 ANDROID_NDK=$1 RELEASE=$3
 
        echo "*********** Build for android armeabi *************"
-       scons BUILD_TARGET=Android CPU_ARCH=armeabi ANDROID_HOME=$1 ANDROID_NDK=$2
+       scons TARGET_OS=android TARGET_ARCH=armeabi ANDROID_NDK=$1 RELEASE=$3
 
        echo "*********** Build for android armeabi-v7a *************"
-       scons BUILD_TARGET=Android CPU_ARCH=armeabi-v7a ANDROID_HOME=$1 ANDROID_NDK=$2
+       scons TARGET_OS=android TARGET_ARCH=armeabi-v7a ANDROID_NDK=$1 RELEASE=$3
 
        echo "*********** Build for android armeabi-v7a-hard *************"
-       scons BUILD_TARGET=Android CPU_ARCH=armeabi-v7a-hard ANDROID_HOME=$1 ANDROID_NDK=$2
+       scons TARGET_OS=android TARGET_ARCH=armeabi-v7a-hard ANDROID_NDK=$1 RELEASE=$3
 
        echo "*********** Build for arduino avr *************"
-       scons BUILD_TARGET=Arduino CPU_ARCH=avr ARDUINO_HOME=$3
+       scons TARGET_OS=arduino TARGET_ARCH=avr ARDUINO_HOME=$2 RELEASE=$3
 
        echo "*********** Build for arduino arm *************"
-       scons BUILD_TARGET=Arduino CPU_ARCH=arm ARDUINO_HOME=$3
+       scons TARGET_OS=arduino TARGET_ARCH=arm ARDUINO_HOME=$2 RELEASE=$3
 
        if [ $(uname -s) = "Darwin" ]
        then
-               echo "*********** Build for OSX i386 *************"
-               scons BUILD_TARGET=Darwin CPU_ARCH=i386 SYS_VERSION=10.9
-
-               echo "*********** Build for OSX x86_64 *************"
-               scons BUILD_TARGET=Darwin CPU_ARCH=x86_64 SYS_VERSION=10.9
+               echo "*********** Build for OSX *************"
+               scons TARGET_OS=darwin SYS_VERSION=10.9 RELEASE=$3
 
                echo "*********** Build for IOS i386 *************"
-               scons BUILD_TARGET=IOS CPU_ARCH=i386 SYS_VERSION=7.0
+               scons TARGET_OS=ios TARGET_ARCH=i386 SYS_VERSION=7.0 RELEASE=$3
 
                echo "*********** Build for IOS x86_64 *************"
-               scons BUILD_TARGET=IOS CPU_ARCH=x86_64 SYS_VERSION=7.0
+               scons TARGET_OS=ios TARGET_ARCH=x86_64 SYS_VERSION=7.0 RELEASE=$3
 
                echo "*********** Build for IOS armv7 *************"
-               scons BUILD_TARGET=IOS CPU_ARCH=armv7 SYS_VERSION=7.0
+               scons TARGET_OS=ios TARGET_ARCH=armv7 SYS_VERSION=7.0 RELEASE=$3
 
                echo "*********** Build for IOS armv7s *************"
-               scons BUILD_TARGET=IOS CPU_ARCH=armv7s SYS_VERSION=7.0
+               scons TARGET_OS=ios TARGET_ARCH=armv7s SYS_VERSION=7.0 RELEASE=$3
 
                echo "*********** Build for IOS arm64 *************"
-               scons BUILD_TARGET=IOS CPU_ARCH=arm64 SYS_VERSION=7.0
+               scons TARGET_OS=ios TARGET_ARCH=arm64 SYS_VERSION=7.0 RELEASE=$3
        fi
 }
 
@@ -63,7 +63,7 @@ function  help()
 {
        echo "Usage:"
         echo "  build:"
-        echo "     `basename $0` <path-to-android-sdk> <path-to-android-ndk> <path-to-arduino-home>"
+        echo "     `basename $0` <path-to-android-ndk> <path-to-arduino-home>"
         echo "  clean:"
         echo "     `basename $0` -c"
 }
@@ -78,12 +78,14 @@ then
                help
                exit -1
        fi
-elif [ $# -ne 3 ]
+elif [ $# -ne 2 ]
 then
        help
        exit -1
 fi
 
-
-build $1 $2 $3
+# Suppress "Reading ..." message and enable parallel build
+export SCONSFLAGS="-Q -j 8"
+build $1 $2 true
+build $1 $2 false
 echo "===================== done ====================="
diff --git a/build_common/SConscript b/build_common/SConscript
new file mode 100644 (file)
index 0000000..c6708e4
--- /dev/null
@@ -0,0 +1,182 @@
+##
+# This script includes generic build options:
+#    release/debug, target os, target arch, cross toolchain, build environment etc
+##
+import os
+import platform
+
+# Map of host os and allowed target os (host: allowed target os)
+host_target_map = {
+               'linux': ['linux', 'android', 'arduino'],
+               'windows': ['windows', 'winrt', 'android', 'arduino'],
+               'darwin': ['darwin', 'ios', 'android', 'arduino'],
+               }
+
+# Map of os and allowed archs (os: allowed archs)
+os_arch_map = {
+               'linux': ['x86', 'x86_64', 'arm', 'arm64'],
+               'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
+               'windows': ['x86', 'amd64', 'arm'],
+               'winrt': ['arm'],
+               'darwin': ['i386', 'x86_64'],
+               'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
+               'arduino': ['avr', 'arm'],
+               }
+
+host = platform.system().lower()
+
+if not host_target_map.has_key(host):
+       print "\nError: Current system (%s) isn't supported\n" % host
+       Exit(1)
+
+######################################################################
+# Get build options (the optins from command line)
+######################################################################
+target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
+
+if target_os not in host_target_map[host]:
+       print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
+       Exit(1)
+
+default_arch = platform.machine()
+if default_arch not in os_arch_map[target_os]:
+       default_arch = os_arch_map[target_os][0].lower()
+
+target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
+
+######################################################################
+# Common build options (release, target os, target arch)
+######################################################################
+help_vars = Variables()
+help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
+help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
+help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
+
+######################################################################
+# Platform(build target) specific options: SDK/NDK & toolchain
+######################################################################
+targets_support_cc = ['linux', 'arduino']
+
+if target_os in targets_support_cc:
+       # Set cross compile toolchain
+       help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
+       help_vars.Add(PathVariable('TC_PATH',
+                       'Toolchain path (Generally only be required for cross-compiling)',
+                       os.environ.get('TC_PATH')))
+
+if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
+       env = Environment(variables = help_vars,
+                       tools = ['gnulink', 'gcc', 'g++', 'ar', 'as']
+                       )
+else:
+       env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
+
+Help(help_vars.GenerateHelpText(env))
+
+tc_set_msg = '''
+************************************ Warning **********************************
+*   Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
+* toolchain, if it isn't what you expect you should unset it, otherwise it may*
+* cause inexplicable errors.                                                  *
+*******************************************************************************
+'''
+
+if target_os in targets_support_cc:
+       prefix = env.get('TC_PREFIX')
+       tc_path = env.get('TC_PATH')
+       if prefix:
+               env.Replace(CC = prefix + 'gcc')
+               env.Replace(CXX = prefix + 'g++')
+               env.Replace(AR = prefix + 'ar')
+               env.Replace(AS = prefix + 'as')
+               env.Replace(LINK = prefix + 'ld')
+               env.Replace(RANLIB = prefix + 'ranlib')
+
+       if tc_path:
+               env.PrependENVPath('PATH', tc_path)
+               sys_root = os.path.abspath(tc_path + '/../')
+               env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
+               env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
+
+       if prefix or tc_path:
+               print tc_set_msg
+
+# Ensure scons be able to change its working directory
+env.SConscriptChdir(1)
+
+# Set the source directory and build directory
+#   Source directory: 'dir'
+#   Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
+#
+# You can get the directory as following:
+#   env.get('SRC_DIR')
+#   env.get('BUILD_DIR')
+
+def __set_dir(env, dir):
+       if not os.path.exists(dir + '/SConstruct'):
+               print '''
+*************************************** Error *********************************
+* The directory(%s) seems isn't a source code directory, no SConstruct file is
+* found. *
+*******************************************************************************
+''' % dir
+               Exit(1)
+
+       if env.get('RELEASE'):
+               build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
+       else:
+               build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
+       env.VariantDir(build_dir, dir, duplicate=0)
+
+       env.Replace(BUILD_DIR = build_dir)
+       env.Replace(SRC_DIR = dir)
+
+def __src_to_obj(env, src, home = ''):
+       obj = env.get('BUILD_DIR') + src.replace(home, '')
+       if env.get('OBJSUFFIX'):
+               obj += env.get('OBJSUFFIX')
+       return env.Object(obj, src)
+
+def __install(ienv, targets, name):
+       i_n = ienv.Install(env.get('BUILD_DIR'), targets)
+       Alias(name, i_n)
+       env.AppendUnique(TS = [name])
+
+def __append_target(ienv, target):
+       env.AppendUnique(TS = [target])
+
+def __print_targets(env):
+       Help('''
+===============================================================================
+Targets:\n    ''')
+       for t in env.get('TS'):
+               Help(t + ' ')
+       Help('''
+\nDefault all targets will be built. You can specify the target to build:
+
+    $ scons [options] [target]
+===============================================================================
+''')
+
+env.AddMethod(__set_dir, 'SetDir')
+env.AddMethod(__print_targets, 'PrintTargets')
+env.AddMethod(__src_to_obj, 'SrcToObj')
+env.AddMethod(__append_target, 'AppendTarget')
+env.AddMethod(__install, 'InstallTarget')
+env.SetDir(env.GetLaunchDir())
+
+Export('env')
+
+# Load config of target os
+env.SConscript(target_os + '/SConscript')
+
+# Delete the temp files of configuration
+if env.GetOption('clean'):
+       dir = env.get('SRC_DIR')
+
+       if os.path.exists(dir + '/config.log'):
+               Execute(Delete(dir + '/config.log'))
+               Execute(Delete(dir + '/.sconsign.dblite'))
+               Execute(Delete(dir + '/.sconf_temp'))
+
+Return('env')
similarity index 76%
rename from resource/build_common/android/SConscript
rename to build_common/android/SConscript
index 7704e70..6e81213 100644 (file)
@@ -5,13 +5,19 @@ import os
 import platform
 import subprocess
 
-Import('env', 'RELEASE_BUILD', 'TARGET_CPU_ARCH', 'ANDROID_NDK')
+Import('env')
 
-if not ANDROID_NDK:
+help_vars = Variables()
+help_vars.Add(PathVariable('ANDROID_NDK', 'Android NDK root directory', os.environ.get('ANDROID_NDK')))
+help_vars.Update(env)
+Help(help_vars.GenerateHelpText(env))
+
+android_ndk = env.get('ANDROID_NDK')
+if not android_ndk:
        print '''
 *************************************** Error *********************************
-*   Android NDK path (ANDROID_NDK) isn't set, you can set enviornment variable*
-* ANDROID_NDK or add it in command line as:                                   *
+*    Android NDK path isn't set, you can set enviornment variable ANDROID_NDK *
+* or add it in command line as:                                               *
 *      # scons ANDROID_NDK=<path to android NDK> ...                          *
 *******************************************************************************
 '''
@@ -46,7 +52,7 @@ env.AppendUnique(LINKFLAGS = ['-Wl,--gc-sections', '-Wl,-z,nocopyreloc'])
 ######################################################################
 # Probe Android NDK default flags
 ######################################################################
-ndk_build_cmd = ANDROID_NDK + '/ndk-build'
+ndk_build_cmd = android_ndk + '/ndk-build'
 if env['HOST_OS'] == 'win32':
        if os.path.isfile(ndk_build_cmd + '.cmd'):
                ndk_build_cmd += '.cmd'
@@ -57,7 +63,7 @@ if not os.path.isfile(ndk_build_cmd):
 *   It seems android ndk path is not set properly, please check if "%s"
 * is the root directory of android ndk.                                       *
 *******************************************************************************
-''' % ANDROID_NDK
+''' % android_ndk
        Exit(1)
 
 ANDROID_HOME = os.environ.get('ANDROID_HOME')
@@ -72,24 +78,26 @@ if ANDROID_HOME is None or not os.path.exists(ANDROID_HOME):
 *******************************************************************************
 '''
 
+target_arch = env.get('TARGET_ARCH')
+
 # Android ndk early version doesn't support C++11. Detect the toolchain
 # and platform version to make sure the newest version is used.
 
 # Detect toolchain version
 for tc_ver in ['4.9', '4.8', '4.7', '']:
-       if os.path.exists(ANDROID_NDK + '/sources/cxx-stl/gnu-libstdc++/' + tc_ver):
+       if os.path.exists(android_ndk + '/sources/cxx-stl/gnu-libstdc++/' + tc_ver):
                break
 
 # Detect platform version.
 platform_ver = ''
 for pf_ver in range(0, 100): # 100 should be big enough :)
-       if os.path.exists(ANDROID_NDK + '/platforms/android-%d' % pf_ver):
+       if os.path.exists(android_ndk + '/platforms/android-%d' % pf_ver):
                platform_ver = "%d" % pf_ver
 
 cmd = [ndk_build_cmd]
-cmd.append('APP_ABI=' + TARGET_CPU_ARCH)
+cmd.append('APP_ABI=' + target_arch)
 cmd.append('APP_STL=gnustl_static')
-if RELEASE_BUILD:
+if env.get('RELEASE'):
        cmd.append('APP_OPTIM=release')
 else:
        cmd.append('APP_OPTIM=debug')
@@ -127,25 +135,30 @@ for flags in p.stdout.readlines():
                env.AppendUnique(CPPPATH = Split(flags[8:]))
 
        elif cmp(flags[0:8], 'SYSROOT=') == 0:
-               env.AppendUnique(LINKFLAGS = ['--sysroot=' + flags[8:].strip()])
-               env.AppendUnique(LIBPATH = [flags[8:].strip() + '/usr/lib'])
+               sysroot = flags[8:].strip()
+               env.AppendUnique(LINKFLAGS = ['--sysroot=' + sysroot])
+               env.AppendUnique(LIBPATH = [sysroot + '/usr/lib'])
+               # To fix android NDK issue
+               # Some functions, e.g. rand, srand. strtof ... are static in static inline
+               # prior to android-L. so libc.so before android-L doesn't have them. If build
+               # build on android-L and the function(s) is used, should link libc.a
+               if platform_ver == '' or int(platform_ver) > 20:
+                       env.AppendUnique(LIBS = File(sysroot + '/usr/lib/libc.a'))
 
        elif cmp(flags[0:8], 'LDFLAGS=') == 0:
                env.AppendUnique(LINKFLAGS = Split(flags[8:]))
 
        elif cmp(flags[0:7], 'TC_VER=') == 0:  # set gnustl library path
                ver = flags[7:].strip()
-               env.AppendUnique(LIBPATH = [ANDROID_NDK + '/sources/cxx-stl/gnu-libstdc++/'
-                               + ver + '/libs/' + TARGET_CPU_ARCH])
+               env.AppendUnique(LIBPATH = [android_ndk + '/sources/cxx-stl/gnu-libstdc++/'
+                               + ver + '/libs/' + target_arch])
 
 ######################################################################
 # Set release/debug flags
 ######################################################################
-if RELEASE_BUILD:
-       env.AppendUnique(CFLAGS = ['-Os'])
-       env.AppendUnique(CXXFLAGS = ['-Os'])
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
        env.AppendUnique(CPPDEFINES = ['NDEBUG'])
        env.AppendUnique(LINKFLAGS = ['-s'])
 else:
-       env.AppendUnique(CFLAGS = ['-g'])
-       env.AppendUnique(CXXFLAGS = ['-g'])
\ No newline at end of file
+       env.AppendUnique(CCFLAGS = ['-g'])
similarity index 93%
rename from resource/build_common/android/jni/Android.mk
rename to build_common/android/jni/Android.mk
index a7f2267..9bc6284 100644 (file)
@@ -1,6 +1,6 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := flags_probe
-include $(BUILD_SHARE_LIBRARY)
+include $(BUILD_SHARED_LIBRARY)
 
 $(info TC_PREFIX=$(TOOLCHAIN_PREFIX))
 $(info CFLAGS=$(TARGET_CFLAGS))
diff --git a/build_common/arduino/SConscript b/build_common/arduino/SConscript
new file mode 100755 (executable)
index 0000000..4c3a01f
--- /dev/null
@@ -0,0 +1,400 @@
+##
+# This script includes arduino specific config
+##
+import os
+import platform
+
+Import('env')
+
+def __parse_config(f):
+       dict = {}
+
+       if not os.path.isfile(f):
+               return dict
+
+       file = open(f, 'r')
+       strs = file.readlines()
+       for str in strs:
+               str = str.strip()
+               if len(str) > 0 and str[0] == '#':
+                       continue
+
+               idx = str.find('=')
+               if idx > 0:
+                       dict.setdefault(str[0:idx], str[idx + 1:])
+
+       return dict
+
+def __get_boards(dict):
+       boards = []
+       keys = dict.keys()
+       for key in keys:
+               idx = key.find('.name')
+               if idx > 0:
+                       if key.endswith('.name'):
+                               boards.append(key[0:idx])
+       return boards
+
+def __get_cpu(dict, board):
+       cpus = []
+       keys = dict.keys()
+       for key in keys:
+               idx = key.find(board + '.menu.cpu.')
+               start = len(board + '.menu.cpu.')
+               if idx >= 0:
+                       end = key.find('.', start)
+                       if end > 0:
+                               cpu = key[start:end]
+                               exist = False
+                               for c in cpus:
+                                       if c == cpu:
+                                               exist = True
+                                               break
+
+                               if not exist:
+                                       cpus.append(cpu)
+       return cpus
+
+def __get_board_info(board, key):
+       if cpu:
+               v = boards_info.get(board + '.menu.cpu.' + cpu + key)
+               if not v:
+                       v = boards_info.get(board + key)
+       else:
+               v = boards_info.get(board + key)
+       return v
+
+def __search_files(path, pattern, ondisk=True, source=True, strings=False, recursive=True):
+       if not recursive:
+               return Glob(pattern, ondisk, source, strings)
+
+       matches = []
+       for root, dirnames, filenames in os.walk(path):
+               matches.extend(Glob(root + '/' + pattern, ondisk, source, strings))
+
+       return matches
+
+# To make sure the src is built in 'BUILD_DIR' (by default it will be built at
+# the same directory as the .c .cpp .S)
+def __src_to_obj(env, srcs):
+       objs = []
+       prefix = env.get('BOARD') + '_'
+       if env.get('CPU'):
+               prefix += env.get('CPU') + '_'
+
+       build_dir = env.get('BUILD_DIR') + '/arduino/'
+       for src in srcs:
+               obj = src.path.replace(arduino_home, build_dir)
+               i = obj.rfind('.')
+               obj = obj[0:i]
+               if env.get('OBJSUFFIX'):
+                       obj += env.get('OBJSUFFIX')
+               objs.extend(env.Object(obj, src, OBJPREFIX=prefix))
+       return objs
+
+def __import_lib(env, lib):
+       lib_path = arduino_home + '/libraries/' + lib
+       if not os.path.exists(lib_path):
+               if target_arch == 'avr':
+                       lib_path = arduino_home + '/hardware/arduino/avr/libraries/' + lib
+               else:
+                       lib_path = arduino_home + '/hardware/arduino/sam/libraries/' + lib
+
+       if os.path.exists(lib_path + '/src'):
+               lib_path = lib_path + '/src'
+
+       env.AppendUnique(CPPPATH = [lib_path])
+
+       if os.path.exists(lib_path + '/utility'):
+               env.AppendUnique(CPPPATH = [lib_path + '/utility'])
+
+       lib_src = []
+       lib_src.extend(__search_files(lib_path, '*.S'))
+       lib_src.extend(__search_files(lib_path, '*.c'))
+       lib_src.extend(__search_files(lib_path, '*.cpp'))
+
+       build_dir = env.get('BUILD_DIR')
+       if build_dir:
+               lib_a = env.StaticLibrary(build_dir + lib, __src_to_obj(env, lib_src))
+       else:
+               lib_a = env.StaticLibrary(lib, __src_to_obj(env, lib_src))
+       env.AppendUnique(LIBS = [File(lib_a[0])])
+
+def __build_core(env):
+       core_src = __search_files(core_folder, '*.S')
+       core_src.extend(__search_files(core_folder, '*.c'))
+       core_src.extend(__search_files(core_folder, '*.cpp'))
+
+       core_src.extend(__search_files(variant_folder, '*.S'))
+       core_src.extend(__search_files(variant_folder, '*.c'))
+       core_src.extend(__search_files(variant_folder, '*.cpp'))
+
+       core_obj = __src_to_obj(env, core_src)
+       build_dir = env.get('BUILD_DIR')
+       if build_dir:
+               s_core = env.StaticLibrary(build_dir + 'core', core_obj)
+       else:
+               s_core = env.StaticLibrary('core', core_obj)
+       env.AppendUnique(LIBS = [File(s_core[0])])
+
+       # To avoid compiler issue. Otherewise there may be warnings:
+       #       undefined reference to '_exit' '_close', '_getpid' ...
+       # Above functions are used in libc.a and implemented in syscalls_sam3.c
+       if env.get('TARGET_ARCH') == 'arm':
+               for obj in core_obj:
+                       if obj.name.endswith('syscalls_sam3.o'):
+                               env.AppendUnique(LIBS = [File(obj)])
+
+def __create_bin(env, source):
+       name = source
+       if env.get('TARGET_ARCH') == 'avr':
+               eep = env.Command(name + '.eep', source, 'avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $SOURCE $TARGET')
+               hex = env.Command(name + '.hex', source, 'avr-objcopy -O ihex -R .eeprom $SOURCE $TARGET')
+       else:
+               hex = env.Command(name + '.hex', source, 'arm-none-eabi-objcopy -O binary $SOURCE $TARGET')
+
+# Print the command line that to upload binary to the board
+def __upload_help(env):
+       if target_arch == 'avr':
+               protocol = __get_board_info(board, '.upload.protocol')
+               speed = __get_board_info(board, '.upload.speed')
+
+               upload_cmd = arduino_home + '/hardware/tools/avr/bin/avrdude -C' + arduino_home +'/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -p' \
+       + mcu + ' -c' + protocol + ' -P<serial_port>' + ' -b' + speed + ' -D -Uflash:w:<hex_file>:i'
+       else:
+               uu = __get_board_info(board, '.upload.native_usb')
+               upload_cmd = arduino_home + '/hardware/tools/bossac -i -d --port=<serial_port> -U ' + uu + ' -e -w -v -b <bin file> -R'
+
+       Help('''
+===============================================================================
+You can upload the bin file with following command line:
+''')
+       Help('\n   $ ' + upload_cmd)
+       Help('''
+\nPlease replace <xxx> according to the actual situation.
+===============================================================================
+''')
+
+# ARDUINO_HOME build option
+help_vars = Variables()
+help_vars.Add(PathVariable('ARDUINO_HOME', 'ARDUINO root directory', os.environ.get('ARDUINO_HOME')))
+help_vars.Update(env)
+Help(help_vars.GenerateHelpText(env))
+
+target_arch = env.get('TARGET_ARCH')
+arduino_home = env.get('ARDUINO_HOME')
+if not arduino_home:
+       print '''
+************************************* Error ***********************************
+*   Arduino root directory isn't set, you can set enviornment variable        *
+* ARDUINO_HOME or add it in command line as:                                  *
+*      # scons ARDUINO_HOME=<path to arduino root directory> ...              *
+*******************************************************************************
+'''
+       Exit(1)
+
+# Overwrite suffixes and prefixes
+if env['HOST_OS'] == 'win32':
+       env['OBJSUFFIX'] = '.o'
+       env['SHOBJSUFFIX'] = '.os'
+       env['LIBPREFIX'] = 'lib'
+       env['LIBSUFFIX'] = '.a'
+       env['SHLIBPREFIX'] = 'lib'
+       env['SHLIBSUFFIX'] = '.so'
+       env['LIBPREFIXES'] = ['lib']
+       env['LIBSUFFIXES'] = ['.a', '.so']
+       env['PROGSUFFIX'] = ''
+elif platform.system().lower() == 'darwin':
+       env['SHLIBSUFFIX'] = '.so'
+       env['LIBSUFFIXES'] = ['.a', '.so']
+       env['PROGSUFFIX'] = ''
+
+# Debug/release relative flags
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+       env.AppendUnique(CCFLAGS = ['-g'])
+
+# BOARD / CPU option
+
+# Get IDE version
+if os.path.exists(arduino_home + '/lib/version.txt'):
+       vf = open(arduino_home + '/lib/version.txt', 'r')
+       version = vf.readline().replace('.', '')
+else:
+       print '''
+************************************* Error ***********************************
+* Can't find version file (lib/version.txt), please check if (%s)
+* is arduino root directory.                                                  *
+*******************************************************************************
+''' % arduino_home
+       Exit(1)
+
+if version[0:2] == '10':
+       is_1_0_x = True
+       boards_info = __parse_config(arduino_home + '/hardware/arduino/boards.txt')
+       env.PrependENVPath('PATH', arduino_home + '/hardware/tools/avr/bin/')
+       env.Replace(CC = 'avr-gcc')
+       env.Replace(CXX = 'avr-g++')
+       env.Replace(AR = 'avr-ar')
+       env.Replace(AS = 'avr-as')
+       env.Replace(LINK = 'avr-gcc')
+       env.Replace(RANLIB = 'avr-ranlib')
+       if target_arch != 'avr':
+               print '''
+************************************* Error ***********************************
+* Arduino 1.0.x IDE only support 'avr', to support other arch at least 1.5.x  *
+* is required.
+*******************************************************************************
+'''
+               Exit(1)
+else:
+       is_1_0_x = False
+       if target_arch == 'avr':
+               boards_info = __parse_config(arduino_home + '/hardware/arduino/avr/boards.txt')
+               platform_info = __parse_config(arduino_home + '/hardware/arduino/avr/platform.txt')
+       elif target_arch == 'arm':
+               boards_info = __parse_config(arduino_home + '/hardware/arduino/sam/boards.txt')
+               platform_info = __parse_config(arduino_home + '/hardware/arduino/sam/platform.txt')
+       else:
+               print '''
+************************************* Error ***********************************
+* CPU arch %s isn't supported currently.
+*******************************************************************************
+''' % target_arch
+
+#Board option, let user to select the board
+boards = __get_boards(boards_info)
+help_vars = Variables()
+help_vars.Add(EnumVariable('BOARD', 'arduino board', boards[0], boards))
+help_vars.Update(env)
+Help(help_vars.GenerateHelpText(env))
+
+#CPU option
+board = env.get('BOARD')
+cpus = __get_cpu(boards_info, board)
+if len(cpus) > 0:
+       help_vars = Variables()
+       help_vars.Add(EnumVariable('CPU', 'arduino board cpu', cpus[0], cpus))
+       help_vars.Update(env)
+       Help(help_vars.GenerateHelpText(env))
+
+# Arduino commom flags
+cpu = env.get('CPU')
+board = env.get('BOARD')
+mcu = __get_board_info(board, '.build.mcu')
+f_cpu = __get_board_info(board, '.build.f_cpu')
+usb_vid = __get_board_info(board, '.build.vid')
+usb_pid = __get_board_info(board, '.build.pid')
+variant = __get_board_info(board, '.build.variant')
+
+if not usb_vid:
+       usb_vid = __get_board_info(board, '.vid.0')
+if not usb_pid:
+       usb_pid = __get_board_info(board, '.pid.0')
+
+if is_1_0_x:
+       core_base = arduino_home + '/hardware/arduino/'
+else:
+       if target_arch == 'avr':
+               core_base = arduino_home + '/hardware/arduino/avr/'
+       else:
+               core_base = arduino_home + '/hardware/arduino/sam/'
+
+variant_folder = core_base + 'variants/' + variant
+env.AppendUnique(CPPPATH = [variant_folder])
+
+core = __get_board_info(board, '.build.core')
+core_folder = core_base + 'cores/' + core + '/'
+env.AppendUnique(CPPPATH = [core_folder])
+
+if is_1_0_x:
+       comm_flags = []
+       if mcu:
+               comm_flags.extend(['-mmcu=' + mcu])
+       if f_cpu:
+               comm_flags.extend(['-DF_CPU=' + f_cpu])
+       comm_flags.extend(['-DARDUINO=' + version])
+       if usb_vid:
+               comm_flags.extend(['-DUSB_VID=' + usb_vid])
+       if usb_pid:
+               comm_flags.extend(['-DUSB_PID=' + usb_pid])
+
+       env.AppendUnique(ASFLAGS = ['-x', 'assembler-with-cpp'])
+       env.AppendUnique(ASFLAGS = comm_flags)
+
+       env.AppendUnique(CFLAGS = ['-Os', '-ffunction-sections', '-fdata-sections', '-MMD'])
+       env.AppendUnique(CFLAGS = comm_flags)
+
+       env.AppendUnique(CXXFLAGS = ['-Os', '-fno-exceptions', '-ffunction-sections', '-fdata-sections','-MMD'])
+       env.AppendUnique(CXXFLAGS = comm_flags)
+
+       env.AppendUnique(LINKFLAGS = ['-Os'])
+       if mcu == 'atmega2560':
+               env.AppendUnique(LINKFLAGS = ['-Wl,--gc-sections,--relax'])
+       else:
+               env.AppendUnique(LINKFLAGS = ['-Wl,--gc-sections'])
+       env.AppendUnique(LINKFLAGS = ['-mmcu=' + mcu])
+else:
+       if target_arch == 'avr':
+               cpu_flag = '-mmcu=' + mcu
+       else:
+               cpu_flag = '-mcpu=' + mcu
+
+       comm_flag = [cpu_flag, '-DF_CPU=' + f_cpu, '-DARDUINO=' + version, '-DARDUINO_' + __get_board_info(board, '.build.board')]
+       if target_arch == 'arm':
+               comm_flag.extend(['-DARDUINO_ARCH_SAM'])
+       else:
+               comm_flag.extend(['-DARDUINO_ARCH_AVR'])
+
+       compiler_path = platform_info.get('compiler.path')
+       compiler_path = compiler_path.replace('{runtime.ide.path}', arduino_home)
+       env.PrependENVPath('PATH', compiler_path)
+       env.Replace(CC = platform_info.get('compiler.c.cmd'))
+       env.Replace(CXX = platform_info.get('compiler.cpp.cmd'))
+       env.Replace(AR = platform_info.get('compiler.ar.cmd'))
+       if target_arch == 'arm':
+               env.AppendUnique(CPPPATH = [arduino_home + '/hardware/arduino/sam/system/libsam',
+                                                       arduino_home + '/hardware/arduino/sam/system/CMSIS/CMSIS/Include/',
+                                                       arduino_home + '/hardware/arduino/sam/system//CMSIS/Device/ATMEL'])
+       env.AppendUnique(ASFLAGS = ['-x', 'assembler-with-cpp'])
+       env.AppendUnique(ASFLAGS = comm_flag)
+       env.AppendUnique(CFLAGS = Split(platform_info.get('compiler.c.flags')))
+       env.AppendUnique(CXXFLAGS = Split(platform_info.get('compiler.cpp.flags')))
+       env.AppendUnique(ARFLAGS = Split(platform_info.get('compiler.ar.flags')))
+       env.AppendUnique(CCFLAGS = comm_flag)
+
+       extra_flags = __get_board_info(board, '.build.extra_flags')
+       if extra_flags:
+               extra_flags = extra_flags.replace('{build.usb_flags}', '')
+               env.AppendUnique(CCFLAGS = Split(extra_flags))
+               usb_flags = ['-DUSB_VID=' + usb_vid, '-DUSB_PID=' + usb_pid, '-DUSBCON', '-DUSB_MANUFACTURER="Unknown"']
+               env.AppendUnique(CCFLAGS = usb_flags)
+
+       if target_arch == 'arm':
+               env.AppendUnique(LINKFLAGS = ['-Os', '-Wl,--gc-sections', cpu_flag,
+                                       '-T' + variant_folder + '/' + __get_board_info(board, '.build.ldscript'),
+                                       '-Wl,-Map,' + env.get('BUILD_DIR') + 'arduino_prj.map'])
+               env.AppendUnique(LINKFLAGS = Split('-lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group'))
+
+               variant_system_lib = __get_board_info(board, '.build.variant_system_lib')
+               if variant_system_lib:
+                       if variant_folder.find(' ') >= 0:
+                               variant_folder = '"' + variant_folder + '"'
+                       env.Replace(LINKCOM = '$LINK -o $TARGET $_LIBDIRFLAGS $LINKFLAGS $SOURCES $_LIBFLAGS '
+                                       + variant_folder + '/' + variant_system_lib + ' -Wl,--end-group')
+               else:
+                       env.Replace(LINKCOM = '$LINK -o $TARGET $_LIBDIRFLAGS $LINKFLAGS $SOURCES $_LIBFLAGS -Wl,--end-group')
+       else:
+               env.AppendUnique(LINKFLAGS = Split(platform_info.get('compiler.c.elf.flags')))
+               env.AppendUnique(LINKFLAGS = [cpu_flag])
+               env.AppendUnique(LIBS = 'm')
+       env.Replace(ARCOM = '$AR ' + platform_info.get('compiler.ar.flags') + ' $TARGET $SOURCES')
+
+__build_core(env)
+
+env.AddMethod(__import_lib, "ImportLib") #import arduino library
+#env.AddMethod(__build_core, "BuildCore") #build arduino core
+env.AddMethod(__create_bin, "CreateBin") #create binary files(.eep and .hex)
+env.AddMethod(__upload_help, "UploadHelp") #print the command line that to upload binary to the boardf
diff --git a/build_common/darwin/SConscript b/build_common/darwin/SConscript
new file mode 100644 (file)
index 0000000..7d57774
--- /dev/null
@@ -0,0 +1,54 @@
+##
+# This script set darwin specific flags (GNU GCC)
+#
+##
+import os
+import platform
+
+Import('env')
+
+# SYS_VERSION build option
+help_vars = Variables()
+help_vars.Add('SYS_VERSION', 'MAC OS X version / IOS version', os.environ.get('SYS_VERSION'))
+help_vars.Update(env)
+Help(help_vars.GenerateHelpText(env))
+
+sys_version = env.get('SYS_VERSION')
+
+if sys_version is None:
+       print '''
+*********************************** Error *************************************
+*   MAC OSX/IOS version isn't set, please set it in command line as :         *
+*      # scons SYS_VERSION=<version> ...                                      *
+*   To get the version, please see:                                                              *
+* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/   *
+* /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ *
+*******************************************************************************
+'''
+       Exit(1)
+
+target_arch = env.get('TARGET_ARCH')
+target_os = env.get('TARGET_OS')
+# Set release/debug flags
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+       env.AppendUnique(CCFLAGS = ['-g'])
+
+if target_os == 'darwin':
+       sys_root = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + sys_version + '.sdk/'
+else:
+       if target_arch in ['i386', 'x86_64']:
+               sys_root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator' + sys_version + '.sdk/'
+       else:
+               sys_root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS' + sys_version + '.sdk/'
+
+# Set arch flags
+env.AppendUnique(CCFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
+env.AppendUnique(LINKFLAGS = ['-arch', target_arch, '-isysroot', sys_root])
+
+if target_os == 'darwin':
+       flag = '-mmacosx-version-min=' + sys_version
+       env.AppendUnique(CCFLAGS = [flag])
+       env.AppendUnique(LINKFLAGS = [flag])
\ No newline at end of file
diff --git a/build_common/ios/SConscript b/build_common/ios/SConscript
new file mode 100644 (file)
index 0000000..fcf62aa
--- /dev/null
@@ -0,0 +1,18 @@
+##
+# This script set ios specific flags (GNU GCC)
+#
+##
+Import('env')
+
+# setting of IOS is almost the same as Darwin(MAC OSX)
+env.SConscript('../darwin/SConscript')
+
+sys_version = env.get('SYS_VERSION')
+if env.get('TARGET_ARCH') in ['i386', 'x86_64']: #Simulator
+       flag = '-mios-simulator-version-min=' + sys_version
+       env.AppendUnique(CCFLAGS = [flag])
+       env.AppendUnique(LINKFLAGS = [flag])
+else:
+       flag = '-miphoneos-version-min=' + sys_version
+       env.AppendUnique(CCFLAGS = [flag])
+       env.AppendUnique(LINKFLAGS = [flag])
\ No newline at end of file
diff --git a/build_common/linux/SConscript b/build_common/linux/SConscript
new file mode 100644 (file)
index 0000000..bb939be
--- /dev/null
@@ -0,0 +1,33 @@
+##
+# This script set linux specific flags (GNU GCC)
+#
+##
+Import('env')
+
+# Set release/debug flags
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['-Os'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+       env.AppendUnique(LINKFLAGS = ['-s'])
+else:
+       env.AppendUnique(CCFLAGS = ['-g'])
+
+# Set arch flags
+target_arch = env.get('TARGET_ARCH')
+if target_arch in ['x86']:
+       env.AppendUnique(CCFLAGS = ['-m32'])
+       env.AppendUnique(LINKFLAGS = ['-m32'])
+elif target_arch in ['x86_64']:
+       env.AppendUnique(CCFLAGS = ['-m64'])
+       env.AppendUnique(LINKFLAGS = ['-m64'])
+elif target_arch.find('v7a-hard') > 0:
+       env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
+       env.AppendUnique(CPPFLAGS = ['-mfloat-abi=hard'])
+       env.AppendUnique(CCFLAGS = ['-mfloat-abi=hard'])
+       env.AppendUnique(LINKFLAGS = ['-mfloat-abi=hard'])
+elif target_arch.find('v7a') > 0:
+       env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
+elif target_arch.find('arm64') > 0:
+       env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])
+else:
+       env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
diff --git a/build_common/windows/SConscript b/build_common/windows/SConscript
new file mode 100644 (file)
index 0000000..4c35d35
--- /dev/null
@@ -0,0 +1,17 @@
+##
+# This script includes windows specific config (MSVS/MSVC)
+##
+Import('env')
+
+# Set common flags
+env.AppendUnique(CXXFLAGS=['/wd4244', '/wd4267','/wd4345', '/wd4355', '/wd4800', '/wd4996'])
+env.AppendUnique(CCFLAGS=['/EHsc'])
+
+# Set release/debug flags
+if env.get('RELEASE'):
+       env.AppendUnique(CCFLAGS = ['/MD', '/O2', '/GF'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+       env.AppendUnique(CCFLAGS = ['/MDd', '/Od', '/ZI', '/GZ', '/Gm'])
+       env.AppendUnique(CPPDEFINES = ['_DEBUG'])
+       env.AppendUnique(LINKFLAGS = ['/debug'])
diff --git a/extra_options.scons b/extra_options.scons
new file mode 100644 (file)
index 0000000..e1280da
--- /dev/null
@@ -0,0 +1,65 @@
+######################################################################
+# This script manages extra build options
+#
+######################################################################
+import os
+import platform
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+target_arch = env.get('TARGET_ARCH')
+src_dir = env.get('SRC_DIR')
+
+# Add 'OIC_UTILS' build option for user to set oic-utilities project path
+if target_os not in ['linux', 'darwin', 'arduino']:
+       default_dir = os.environ.get('OIC_UTILS')
+       if not default_dir:
+               default_dir = os.path.abspath(src_dir + '/../oic-utilities')
+       else:
+               default_dir = os.path.abspath(default_dir)
+
+       if not os.path.exists(default_dir):
+               default_dir = None
+
+       help_vars = Variables()
+       help_vars.Add(PathVariable('OIC_UTILS', 'oic-utilities project path', default_dir))
+       help_vars.Update(env)
+       Help(help_vars.GenerateHelpText(env))
+
+       utils_path = env.get('OIC_UTILS', default_dir)
+       if utils_path:
+               utils_path = os.path.abspath(utils_path)
+
+       if not utils_path or not os.path.exists(utils_path):
+               print '''
+*********************************** Error: ************************************
+*   oic-utilities project directory isn't set properly, please set enviornment*
+* variable OIC_UTILS or set it in command line:                               *
+*     # scons  OIC_UTILS=<path to oic-utilities> ...                          *
+*******************************************************************************
+'''
+               Exit(1)
+
+if target_os == 'arduino':
+       # Add 'NET' build option, let user select board network connection type
+       vars = Variables()
+       vars.Add(EnumVariable('NET', 'Network connection type', 'Ethernet', ['Ethernet', 'Wifi']))
+       vars.Update(env)
+       Help(vars.GenerateHelpText(env))
+
+# check 'cereal' library, temporarily put it here
+if not os.path.exists(src_dir + '/extlibs/cereal'):
+       print '''
+*********************************** Error: **************************************
+*  'Cereal' library doesn't exist. please download cereal to extlibs directory  *
+* add apply the patch as following:                                             *
+*     $ git clone https://github.com/USCiLab/cereal.git <src_dir>/extlibs/cereal*
+*     $ cd <src_dir>/extlibs/cereal                                             *
+*     $ git reset --hard 7121e91e6ab8c3e6a6516d9d9c3e6804e6f65245               *
+*     $ git apply ../../resource/patches/cereal_gcc46.patch                     *
+*********************************************************************************
+'''
+       Exit(1)
+else:
+       env.AppendUnique(CPPPATH = [src_dir + '/extlibs/cereal/include'])
diff --git a/resource/Readme.scons.txt b/resource/Readme.scons.txt
deleted file mode 100644 (file)
index f8b9c45..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-1) Build with default option
-  To build with default option:
-  # scons
-
-  To see help information with default option(the output may be different with different options):
-  # scons -Q -h
-
-  To clean the project:
-  # scons -c
-
-2) Build with options
-  To build with options:
-  # scons OPTION1=xxx OPTION2=xxx OPTION3=....
-
-  To see help information:
-  # scons OPTION1=xxx OPTION2=xxx OPTION3=.... -Q -h
-
-  To clean the project:
-  # scons OPTION1=xxx OPTION2=xxx OPTION3=.... -c
-
-3) Examples
-  To build default
-  # scons
-  To see default help
-  # scons -Q -h
-  To clean
-  # scons -c
-
-  To build android armeabi-v7a
-  # scon BUILD_TARGET=Android CPU_ARCH=armeabi-v7a
-  To see help
-  # scon BUILD_TARGET=Android CPU_ARCH=armeabi-v7a -Q -h
-  To clean
-  # scon BUILD_TARGET=Android CPU_ARCH=armeabi-v7a -c
-
-Note:
-  1. To build android binary, android NDK should be newer than r8e(recommend r10).
-  2. You may be asked to set some options. Besides set it in command line, you
-can also set it by create a environment variable. Command line has higher priority.
-If both are set, the command line value will be used.
diff --git a/resource/SConscript b/resource/SConscript
new file mode 100644 (file)
index 0000000..fc82826
--- /dev/null
@@ -0,0 +1,26 @@
+##
+# 'resource' sub-project main build script
+#
+##
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+
+# Build libcoap
+SConscript('csdk/libcoap/SConscript')
+
+# Build liboctbstack
+SConscript('csdk/SConscript')
+
+if target_os != 'arduino':
+       # Build liboc_logger
+       SConscript('oc_logger/SConscript')
+
+       # Build liboc
+       SConscript('src/SConscript')
+
+       # Build examples
+       SConscript('examples/SConscript')
+else:
+       SConscript('csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript')
\ No newline at end of file
diff --git a/resource/SConstruct b/resource/SConstruct
deleted file mode 100644 (file)
index f2a9b50..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-##
-# The main build script
-#
-##
-import os
-
-SRC_TOP_DIR = os.path.abspath('.') + '/' #oic-resource project top directory
-
-# Common build options
-SConscript('build_common/SConscript')
-Import('RELEASE_BUILD', 'BUILD_TARGET', 'TARGET_CPU_ARCH')
-
-# Set build directory
-if RELEASE_BUILD:
-       BUILD_DIR = SRC_TOP_DIR + '/out/' + BUILD_TARGET + '/' + TARGET_CPU_ARCH + '/release/'
-else:
-       BUILD_DIR = SRC_TOP_DIR + '/out/' + BUILD_TARGET + '/' + TARGET_CPU_ARCH + '/debug/'
-VariantDir(BUILD_DIR, SRC_TOP_DIR, duplicate=0)
-Export('SRC_TOP_DIR', 'BUILD_DIR')
-
-if BUILD_TARGET == 'arduino':
-       SConscript('arduino.scons')
-
-# Build libcoap
-SConscript(BUILD_DIR + 'csdk/libcoap/SConscript')
-
-# Build liboctbstack
-SConscript(BUILD_DIR + 'csdk/SConscript')
-
-if BUILD_TARGET != 'arduino':
-       # Build liboc_logger
-       SConscript(BUILD_DIR + 'oc_logger/SConscript')
-
-       # Build liboc
-       SConscript(BUILD_DIR + 'src/SConscript')
-
-       # Build examples
-       SConscript(BUILD_DIR + 'examples/SConscript')
-
-# Print targets
-Import('env')
-
-Help('''
-===============================================================================
-Targets:\n    ''')
-for t in env.get('TS'):
-       Help(t + ' ')
-Help('''
-\nDefault all targets will be built. You can specify the target to build:
-
-    #scons [options] [target]
-===============================================================================
-''')
\ No newline at end of file
diff --git a/resource/arduino.scons b/resource/arduino.scons
deleted file mode 100644 (file)
index 287482c..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-##
-# This script includes arduino specific config for oic-resource
-##
-Import('env', 'TARGET_CPU_ARCH', 'ARDUINO_HOME')
-
-# 'NET' build option
-if env.get('NET') is None:
-       vars = Variables()
-       vars.Add(EnumVariable('NET', 'Network connection type', 'Ethernet', ['Ethernet', 'Wifi']))
-       vars.Update(env)
-       Help(vars.GenerateHelpText(env))
-
-env.AppendUnique(CPPPATH = [
-               ARDUINO_HOME + '/libraries/Ethernet/src',
-               ARDUINO_HOME + '/libraries/Ethernet/src/utility',
-               ARDUINO_HOME + '/libraries/WiFi/src',
-               ARDUINO_HOME + '/libraries/WiFi/src/utility',
-               ARDUINO_HOME + '/libraries/Time/',
-               ])
-
-if TARGET_CPU_ARCH == 'arm':
-       # Include path
-       env.AppendUnique(CPPPATH = [
-                       ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino',
-                       ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/USB',
-                       ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/avr',
-                       ARDUINO_HOME + '/hardware/arduino/sam/system/libsam',
-                       ARDUINO_HOME + '/hardware/arduino/sam/system/CMSIS/CMSIS/Include',
-                       ARDUINO_HOME + '/hardware/arduino/sam/system/CMSIS/Device/ATMEL',
-                       ARDUINO_HOME + '/hardware/arduino/sam/variants/arduino_due_x',
-                       ARDUINO_HOME + '/hardware/arduino/sam/libraries/SPI',
-                       ])
-
-       # Compiler/Linker flags
-       env.AppendUnique(CXXFLAGS = ['-ffunction-sections', '-fdata-sections', '-nostdlib',
-                                               '--param', 'max-inline-insns-single=500', '-fno-rtti', '-fno-exceptions',
-                                               '-mcpu=cortex-m3', '-mthumb'
-                                       ])
-       env.AppendUnique(CPPDEFINES = ['printf=iprintf', 'F_CPU=84000000L', 'ARDUINO=157',
-                                               'ARDUINO_SAM_DUE', 'ARDUINO_ARCH_SAM', '__SAM3X8E__', 'USB_VID=0x2341',
-                                               'USB_PID=0x003e', 'USBCON', 'DUSB_MANUFACTURER="Unknown"', 'WITH_ARDUINO',
-                                       ])
-
-       # Source
-       ARDUINO_SRC = []
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/*.c'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/*.cpp'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/avr/*.c'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/USB/*.cpp'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/hardware/arduino/sam/variants/arduino_due_x/*.cpp'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/hardware/arduino/sam/libraries/SPI/*.cpp'))
-else:
-       # Include path
-       env.AppendUnique(CPPPATH = [
-                       ARDUINO_HOME + '/hardware/arduino/avr/cores/arduino',
-                       ARDUINO_HOME + '/hardware/arduino/avr/libraries/SPI',
-                       ARDUINO_HOME + '/hardware/arduino/avr/variants/mega',
-                       ])
-
-       # Compiler/Linker flags
-       env.AppendUnique(CXXFLAGS = ['-mmcu=atmega2560', '-MMD', '-std=c++0x',
-                                               '-Wno-write-strings', '-ffunction-sections', '-fdata-sections',
-                                               '-fno-exceptions', '-felide-constructors'
-                                       ])
-       env.AppendUnique(CPPDEFINES = ['F_CPU=16000000L', 'ARDUINO=156', 'ARDUINO_AVR_MEGA2560',
-                                               'ARDUINO_ARCH_AVR', 'WITH_ARDUINO', 'ATMEGA2560'
-                                       ])
-
-       # Source
-       ARDUINO_SRC = [
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/WInterrupts.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/wiring.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/wiring_digital.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/main.cpp',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/Stream.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/WMath.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/WString.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/HardwareSerial.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/Print.c',
-               ARDUINO_HOME + '/hardware/arduino/sam/cores/arduino/IPAddress.c',
-               ARDUINO_HOME + '/hardware/arduino/avr/libraries/SPI/SPI.cpp',
-               ]
-
-if env.get('NET') == 'Ethernet':
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/libraries/Ethernet/src/*.cpp'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/libraries/Ethernet/src/utility/*.cpp'))
-else:
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/libraries/WiFi/src/*.cpp'))
-       ARDUINO_SRC.extend(Glob(ARDUINO_HOME + '/libraries/WiFi/src/utility/*.cpp'))
-
-Export('ARDUINO_SRC')
\ No newline at end of file
diff --git a/resource/build_common/SConscript b/resource/build_common/SConscript
deleted file mode 100644 (file)
index b3dd335..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-##
-# This script includes generic build options:
-#    release/debug, build target, CPU ARCH, toolchain, build environment etc
-##
-import os
-import platform
-
-host = platform.system()
-default_arch = platform.machine()
-
-if host not in ['Linux', 'Windows', 'Darwin']:
-       host = 'Linux'
-
-# Map of host and allowed targets
-allow_target_map = {
-               'Linux': ['Linux', 'Android', 'Arduino'],
-               'Windows': ['Windows', 'WinRT', 'Android', 'Arduino'],
-               'Darwin': ['Darwin', 'IOS', 'Android', 'Arduino'],
-               }
-
-# Map of platform(target) and allowed archs
-allow_arch_map = {
-               'linux': ['x86', 'x86_64', 'arm', 'arm64'],
-               'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
-               'windows': ['x86', 'amd64', 'arm'],
-               'winrt': ['arm'],
-               'darwin': ['i386', 'x86_64'],
-               'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
-               'arduino': ['avr', 'arm'],
-               }
-
-######################################################################
-# Get build options (the optins from command line)
-######################################################################
-BUILD_TARGET = ARGUMENTS.get('BUILD_TARGET', host).lower() # target platform
-
-if not allow_arch_map.has_key(BUILD_TARGET):
-       print "\nError: Unknown target platform: %s (Allow values: %s)\n" % (BUILD_TARGET, allow_target_map[host])
-       Exit(1)
-
-if default_arch not in allow_arch_map[BUILD_TARGET]:
-       default_arch = allow_arch_map[BUILD_TARGET][0]
-       default_arch = default_arch.lower()
-
-TARGET_CPU_ARCH = ARGUMENTS.get('CPU_ARCH', default_arch) # target CPU ARCH
-ANDROID_NDK = ARGUMENTS.get('ANDROID_NDK', os.environ.get('ANDROID_NDK')) # ANDROID NDK base directory
-SYS_VERSION = ARGUMENTS.get('SYS_VERSION', os.environ.get('SYS_VERSION'))  # OSX/IOS version
-ARDUINO_HOME = ARGUMENTS.get('ARDUINO_HOME', os.environ.get('ARDUINO_HOME')) # ARDUINO root directory
-
-######################################################################
-# Common build options (release, build target, CPU)
-######################################################################
-vars = Variables()
-vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
-vars.Add(EnumVariable('BUILD_TARGET', 'Target platform', host, allow_target_map[host]))
-vars.Add(EnumVariable('CPU_ARCH', 'Target CPU ARCH', default_arch, allow_arch_map[BUILD_TARGET]))
-
-######################################################################
-# Platform(build target) specific options: SDK/NDK & toolchain
-######################################################################
-targets_support_cc = ['linux', 'arduino']
-
-if BUILD_TARGET == 'android':
-       vars.Add(PathVariable('ANDROID_NDK', 'Android NDK root directory', os.environ.get('ANDROID_NDK')))
-
-elif BUILD_TARGET in ['darwin', 'ios']:
-       vars.Add('SYS_VERSION', 'MAC OS X version / IOS version', os.environ.get('SYS_VERSION'))
-
-elif BUILD_TARGET == 'arduino':
-       vars.Add(PathVariable('ARDUINO_HOME', 'ARDUINO root directory', os.environ.get('ARDUINO_HOME')))
-
-if BUILD_TARGET in targets_support_cc:
-       # Set cross compile toolchain
-       vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
-       vars.Add(PathVariable('TC_PATH',
-                       'Toolchain path (Generally only be required for cross-compiling)',
-                       os.environ.get('TC_PATH')))
-
-if BUILD_TARGET == 'android': # Android always uses GNU compiler regardless of the host
-       env = Environment(variables = vars,
-                       tools = ['gnulink', 'gcc', 'g++', 'ar', 'as']
-                       )
-else:
-       env = Environment(variables = vars, TARGET_ARCH = TARGET_CPU_ARCH, TARGET_OS = BUILD_TARGET)
-
-Help(vars.GenerateHelpText(env))
-
-RELEASE_BUILD = env.get('RELEASE') # Whethere is release build, True: release, False: debug
-
-tc_set_msg = '''
-************************************ Warning **********************************
-*   Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
-* toolchain, if it isn't what you expect you should unset it, otherwise it may*
-* cause inexplicable errors.                                                  *
-*******************************************************************************
-'''
-
-if BUILD_TARGET in targets_support_cc:
-       prefix = ARGUMENTS.get('TC_PREFIX', os.environ.get('TC_PREFIX'))
-       tc_path = ARGUMENTS.get('TC_PATH', os.environ.get('TC_PATH'))
-       if prefix:
-               env.Replace(CC = prefix + 'gcc')
-               env.Replace(CXX = prefix + 'g++')
-               env.Replace(AR = prefix + 'ar')
-               env.Replace(AS = prefix + 'as')
-               env.Replace(LINK = prefix + 'ld')
-               env.Replace(RANLIB = prefix + 'ranlib')
-
-       if tc_path:
-               env.PrependENVPath('PATH', tc_path)
-               sys_root = os.path.abspath(tc_path + '/../')
-               env.AppendUnique(CFLAGS = ['--sysroot=' + sys_root])
-               env.AppendUnique(CXXFLAGS = ['--sysroot=' + sys_root])
-               env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
-
-       if prefix or tc_path:
-               print tc_set_msg
-
-# Ensure scons be able to change its working directory
-env.SConscriptChdir(1)
-
-Export('env', 'RELEASE_BUILD', 'BUILD_TARGET', 'TARGET_CPU_ARCH',
-               'ANDROID_NDK', 'SYS_VERSION', 'ARDUINO_HOME')
-
-# Load config of specific platform(build target)
-env.SConscript(BUILD_TARGET + '/SConscript')
-
-Return('env')
\ No newline at end of file
diff --git a/resource/build_common/arduino/SConscript b/resource/build_common/arduino/SConscript
deleted file mode 100644 (file)
index d33cc55..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-##
-# This script includes arduino specific config
-##
-import os
-import platform
-
-Import('env', 'RELEASE_BUILD', 'TARGET_CPU_ARCH', 'ARDUINO_HOME')
-
-if not ARDUINO_HOME:
-       print '''
-************************************* Error ***********************************
-*   Arduino root directory (ARDUINO_HOME) isn't set, you can set enviornment  *
-* variable ARDUINO_HOME or add it in command line as:                         *
-*      # scons ARDUINO_HOME=<path to arduino root directory> ...              *
-*******************************************************************************
-'''
-       Exit(1)
-
-# Overwrite suffixes and prefixes
-if env['HOST_OS'] == 'win32':
-       env['OBJSUFFIX'] = '.o'
-       env['SHOBJSUFFIX'] = '.os'
-       env['LIBPREFIX'] = 'lib'
-       env['LIBSUFFIX'] = '.a'
-       env['SHLIBPREFIX'] = 'lib'
-       env['SHLIBSUFFIX'] = '.so'
-       env['LIBPREFIXES'] = ['lib']
-       env['LIBSUFFIXES'] = ['.a', '.so']
-       env['PROGSUFFIX'] = ''
-elif platform.system().lower() == 'darwin':
-       env['SHLIBSUFFIX'] = '.so'
-       env['LIBSUFFIXES'] = ['.a', '.so']
-       env['PROGSUFFIX'] = ''
-
-# Set toolchain
-def find_toolchain(dir, tc):
-       for root, dirs, files in os.walk(dir, True, None, False):
-               for f in files:
-                       lf = f.lower()
-                       if lf == tc:
-                               return root
-       return None
-
-if TARGET_CPU_ARCH == 'arm':
-       prefix = 'arm-none-eabi-'
-else:
-       prefix = 'avr-'
-
-tc_path = find_toolchain(ARDUINO_HOME + '/hardware/tools/', prefix + 'g++')
-if not tc_path:
-       print '''
-************************************* Error ***********************************
-*   Arduino toolchain isn't detected. Please specify the toolchain prefix and *
-* path, you can do it by setting enviornment variable TC_PREFIX and TC_PATH or*
-* add it in command line as:                                                  *
-*     # scons TC_PREFIX=<prefix> TC_PATH=<path to toolchain> ...              *
-* e.g. scons TC_PREFIX=avr- TC_PATH=/opt/arduino-1.5.7/hardware/tools/avr/bin *                                                                         *
-* Note: TC_PREFIX shouldn't include path                                      *
-*******************************************************************************
-'''
-       Exit(1)
-
-env.PrependENVPath('PATH', tc_path)
-env.Replace(CC = prefix + 'gcc')
-env.Replace(CXX = prefix + 'g++')
-env.Replace(AR = prefix + 'ar')
-env.Replace(AS = prefix + 'as')
-env.Replace(LINK = prefix + 'ld')
-env.Replace(RANLIB = prefix + 'ranlib')
-
-sys_root = os.path.abspath(os.path.join(tc_path, '..'))
-env.AppendUnique(CFLAGS = ['--sysroot=' + sys_root])
-env.AppendUnique(CXXFLAGS = ['--sysroot=' + sys_root])
-env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
-
-# Debug/release relative flags
-if RELEASE_BUILD:
-       env.AppendUnique(CFLAGS = ['-Os'])
-       env.AppendUnique(CXXFLAGS = ['-Os'])
-       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
-       env.AppendUnique(LINKFLAGS = ['-s'])
-else:
-       env.AppendUnique(CFLAGS = ['-g'])
-       env.AppendUnique(CXXFLAGS = ['-g'])
\ No newline at end of file
diff --git a/resource/build_common/darwin/SConscript b/resource/build_common/darwin/SConscript
deleted file mode 100644 (file)
index fb98616..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-##
-# This script set darwin specific flags (GNU GCC)
-#
-##
-import platform
-
-Import('env', 'RELEASE_BUILD', 'BUILD_TARGET', 'TARGET_CPU_ARCH', 'SYS_VERSION')
-
-if SYS_VERSION is None:
-       print '''
-*********************************** Error *************************************
-*   MAC OSX/IOS version isn't set, please set it in command line as :         *
-*      # scons SYS_VERSION=<version> ...                                      *
-*   To get the version, please see:                                                              *
-* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/   *
-* /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ *
-*******************************************************************************
-'''
-       Exit(1)
-
-# Set release/debug flags
-if RELEASE_BUILD:
-       env.AppendUnique(CFLAGS = ['-Os'])
-       env.AppendUnique(CXXFLAGS = ['-Os'])
-       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
-else:
-       env.AppendUnique(CFLAGS = ['-g'])
-       env.AppendUnique(CXXFLAGS = ['-g'])
-
-if BUILD_TARGET == 'darwin':
-       SYS_ROOT = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX' + SYS_VERSION + '.sdk/'
-else:
-       if TARGET_CPU_ARCH in ['i386', 'x86_64']:
-               SYS_ROOT = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator' + SYS_VERSION + '.sdk/'
-       else:
-               SYS_ROOT = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS' + SYS_VERSION + '.sdk/'
-
-# Set arch flags
-env.AppendUnique(CXXFLAGS = ['-arch', TARGET_CPU_ARCH, '-isysroot', SYS_ROOT])
-env.AppendUnique(CCFLAGS = ['-arch', TARGET_CPU_ARCH, '-isysroot', SYS_ROOT])
-env.AppendUnique(LINKFLAGS = ['-arch', TARGET_CPU_ARCH, '-isysroot', SYS_ROOT])
-
-if BUILD_TARGET == 'darwin':
-       flag = '-mmacosx-version-min=' + SYS_VERSION
-       env.AppendUnique(CXXFLAGS = [flag])
-       env.AppendUnique(CCFLAGS = [flag])
-       env.AppendUnique(LINKFLAGS = [flag])
\ No newline at end of file
diff --git a/resource/build_common/ios/SConscript b/resource/build_common/ios/SConscript
deleted file mode 100644 (file)
index 78630b1..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-##
-# This script set ios specific flags (GNU GCC)
-#
-##
-Import('env', 'TARGET_CPU_ARCH', 'SYS_VERSION')
-
-# setting of IOS is almost the same as Darwin(MAC OSX)
-env.SConscript('../darwin/SConscript')
-
-if TARGET_CPU_ARCH in ['i386', 'x86_64']: #Simulator
-       flag = '-mios-simulator-version-min=' + SYS_VERSION
-       env.AppendUnique(CXXFLAGS = [flag])
-       env.AppendUnique(CCFLAGS = [flag])
-       env.AppendUnique(LINKFLAGS = [flag])
-else:
-       flag = '-miphoneos-version-min=' + SYS_VERSION
-       env.AppendUnique(CXXFLAGS = [flag])
-       env.AppendUnique(CCFLAGS = [flag])
-       env.AppendUnique(LINKFLAGS = [flag])
\ No newline at end of file
diff --git a/resource/build_common/linux/SConscript b/resource/build_common/linux/SConscript
deleted file mode 100644 (file)
index d0d999e..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-##
-# This script set linux specific flags (GNU GCC)
-#
-##
-Import('env', 'RELEASE_BUILD', 'TARGET_CPU_ARCH')
-
-# Set release/debug flags
-if RELEASE_BUILD:
-       env.AppendUnique(CFLAGS = ['-Os'])
-       env.AppendUnique(CXXFLAGS = ['-Os'])
-       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
-       env.AppendUnique(LINKFLAGS = ['-s'])
-else:
-       env.AppendUnique(CFLAGS = ['-g'])
-       env.AppendUnique(CXXFLAGS = ['-g'])
-
-# Set arch flags
-if TARGET_CPU_ARCH in ['x86']:
-       env.AppendUnique(CFLAGS = ['-m32'])
-       env.AppendUnique(CXXFLAGS = ['-m32'])
-       env.AppendUnique(LINKFLAGS = ['-m32'])
-elif TARGET_CPU_ARCH in ['x86_64']:
-       env.AppendUnique(CXXFLAGS = ['-m64'])
-       env.AppendUnique(CFLAGS = ['-m64'])
-       env.AppendUnique(LINKFLAGS = ['-m64'])
-elif TARGET_CPU_ARCH.find('v7a-hard') > 0:
-       env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
-       env.AppendUnique(CPPFLAGS = ['-mfloat-abi=hard'])
-       env.AppendUnique(CFLAGS = ['-mfloat-abi=hard'])
-       env.AppendUnique(CXXFLAGS = ['-mfloat-abi=hard'])
-       env.AppendUnique(LINKFLAGS = ['-mfloat-abi=hard'])
-elif TARGET_CPU_ARCH.find('v7a') > 0:
-       env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
-elif TARGET_CPU_ARCH.find('arm64') > 0:
-       env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])
-else:
-       env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
\ No newline at end of file
diff --git a/resource/build_common/windows/SConscript b/resource/build_common/windows/SConscript
deleted file mode 100644 (file)
index 49fd8a0..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-##
-# This script includes windows specific config (MSVS/MSVC)
-##
-Import('env', 'RELEASE_BUILD', 'TARGET_CPU_ARCH')
-
-# Set common flags
-env.AppendUnique(CXXFLAGS=['/wd4244', '/wd4267','/wd4345', '/wd4355', '/wd4800', '/wd4996'])
-env.AppendUnique(CFLAGS=['/EHsc'])
-env.AppendUnique(CXXFLAGS=['/EHsc'])
-
-# Set release/debug flags
-if RELEASE_BUILD:
-       env.AppendUnique(CFLAGS = ['/MD', '/O2', '/GF'])
-       env.AppendUnique(CXXFLAGS = ['/MD', '/O2', '/GF'])
-       env.AppendUnique(CPPDEFINES = ['NDEBUG'])
-else:
-       env.AppendUnique(CFLAGS = ['/MDd', '/Od', '/ZI', '/GZ', '/Gm'])
-       env.AppendUnique(CXXFLAGS = ['/MDd', '/Od', '/ZI', '/GZ', '/Gm'])
-       env.AppendUnique(CPPDEFINES = ['_DEBUG'])
-       env.AppendUnique(LINKFLAGS = ['/debug'])
\ No newline at end of file
index d47f3e0..5df1507 100644 (file)
@@ -1,18 +1,18 @@
 ##
-# liboctbstack (static library) build script
+# liboctbstack (share library) build script
 ##
 
-Import('env', 'BUILD_TARGET', 'TARGET_CPU_ARCH', 'RELEASE_BUILD', 'BUILD_DIR', 'SRC_TOP_DIR')
+Import('env')
 
-liboctbstack_env = env.Clone()
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
 
-# Add third party libraries
-SConscript(SRC_TOP_DIR + '/third_party_libs.scons')
-Import('OIC_UTILS')
+liboctbstack_env = lib_env.Clone()
 
+target_os = env.get('TARGET_OS')
 # As in the source code, it includes arduino Time library (C++)
 # It requires compile the .c with g++
-if BUILD_TARGET == 'arduino':
+if target_os == 'arduino':
        liboctbstack_env.Replace(CC = env.get('CXX'))
        liboctbstack_env.Replace(CFLAGS = env.get('CXXFLAGS'))
 
@@ -20,7 +20,7 @@ if BUILD_TARGET == 'arduino':
 # Build flags
 ######################################################################
 liboctbstack_env.PrependUnique(CPPPATH = [
-               OIC_UTILS + '/tb/cJSON/',
+               '../../extlibs/cjson/',
                'ocsocket/include',
                'logger/include',
                'ocrandom/include',
@@ -32,14 +32,28 @@ liboctbstack_env.PrependUnique(CPPPATH = [
                '../oc_logger/include'
                ])
 
-if BUILD_TARGET not in ['arduino', 'windows', 'winrt']:
+if target_os not in ['arduino', 'windows', 'winrt']:
        liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX'])
        liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
 
-if BUILD_TARGET not in ['windows', 'winrt']:
+if target_os not in ['windows', 'winrt']:
        liboctbstack_env.AppendUnique(CFLAGS = ['-Wall'])
 
-if not RELEASE_BUILD:
+if target_os == 'android':
+       liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       liboctbstack_env.AppendUnique(LIBS = ['coap', 'm'])
+
+if target_os == 'arduino':
+       liboctbstack_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
+else:
+       liboctbstack_env.AppendUnique(CFLAGS = ['-fPIC'])
+
+if target_os in ['darwin', 'ios']:
+       liboctbstack_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+       liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       liboctbstack_env.AppendUnique(LIBS = ['coap'])
+
+if not env.get('RELEASE'):
        liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 ######################################################################
@@ -47,24 +61,20 @@ if not RELEASE_BUILD:
 ######################################################################
 OCTBSTACK_SRC = 'stack/src/'
 liboctbstack_src = [
+       '../../extlibs/cjson/cJSON.c',
        'occoap/src/occoap.c',
        'occoap/src/occoaphelper.c',
        OCTBSTACK_SRC + 'ocstack.c',
        OCTBSTACK_SRC + 'occlientcb.c',
        OCTBSTACK_SRC + 'ocresource.c',
        OCTBSTACK_SRC + 'ocobserve.c',
-       OCTBSTACK_SRC + 'ocserverrequest.c',
+        OCTBSTACK_SRC + 'ocserverrequest.c',
        OCTBSTACK_SRC + 'occollection.c',
+       OCTBSTACK_SRC + 'ocsecurity.c'
        ]
-
-if RELEASE_BUILD:
-       prefix = TARGET_CPU_ARCH + '-'
+if target_os == 'arduino':
+       liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
 else:
-       prefix = TARGET_CPU_ARCH + 'd-'
-cjson_obj = liboctbstack_env.Object(OIC_UTILS + '/tb/cJSON/cJSON.c', OBJPREFIX=prefix)
-liboctbstack_src.append(cjson_obj)
+       liboctbstack = liboctbstack_env.SharedLibrary('octbstack', liboctbstack_src)
 
-liboctbstack = liboctbstack_env.StaticLibrary('octbstack', liboctbstack_src)
-i_lctbs = liboctbstack_env.Install(BUILD_DIR, liboctbstack)
-Alias('liboctbstack', i_lctbs)
-env.AppendUnique(TS = ['liboctbstack'])
+liboctbstack_env.InstallTarget(liboctbstack, 'liboctbstack')
index 3f3efe3..7e1bdf1 100644 (file)
@@ -1,14 +1,15 @@
 ##
-# libcoap (static library) build script
+# libcoap (share library) build script
 ##
 
-Import('env', 'BUILD_TARGET', 'TARGET_CPU_ARCH', 'RELEASE_BUILD', 'BUILD_DIR', 'ARDUINO_HOME')
+Import('env')
 
 libcoap_env = env.Clone()
 
-# As in the source code, it includes arduino Time library (C++)
+target_os = env.get('TARGET_OS')
+# As in the source code(C) includes arduino Time library head file(C++)
 # It requires compile the .c with g++
-if BUILD_TARGET == 'arduino':
+if target_os == 'arduino':
        libcoap_env.Replace(CC = env.get('CXX'))
        libcoap_env.Replace(CFLAGS = env.get('CXXFLAGS'))
 
@@ -24,15 +25,24 @@ libcoap_env.PrependUnique(CPPPATH = [
                '../../oc_logger/include'
                ])
 
-if BUILD_TARGET not in ['arduino', 'windows', 'winrt']:
+if target_os not in ['arduino', 'windows', 'winrt']:
        libcoap_env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
-       libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99'])
+       libcoap_env.AppendUnique(CFLAGS = ['-std=gnu99', '-fPIC'])
 
-if BUILD_TARGET not in ['windows', 'winrt']:
+if target_os not in ['windows', 'winrt']:
        libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
                        '-fdata-sections', '-fno-exceptions'])
 
-if not RELEASE_BUILD:
+if target_os == 'android':
+       libcoap_env.AppendUnique(LIBS = ['log'])
+
+if target_os == 'arduino':
+       libcoap_env.AppendUnique(CPPDEFINES = ['NDEBUG', 'WITH_ARDUINO'])
+
+if target_os in ['darwin', 'ios']:
+       libcoap_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
+if not env.get('RELEASE'):
        libcoap_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 ######################################################################
@@ -45,7 +55,7 @@ libcoap_src = [
        'encode.c',
        'uri.c',
        'coap_list.c',
-       'resource.c',
+#      'resource.c',
        'hashkey.c',
     'str.c',
        'option.c',
@@ -59,22 +69,17 @@ libcoap_src = [
        '../../oc_logger/c/oc_console_logger.c'
        ]
 
-if BUILD_TARGET == 'arduino':
+if target_os == 'arduino':
        if env.get('NET') == 'Wifi':
                libcoap_src.append(['../ocsocket/src/ocsocket_arduino_wifi.cpp'])
        else:
                libcoap_src.append(['../ocsocket/src/ocsocket_arduino.cpp'])
-
-       if RELEASE_BUILD:
-               prefix = TARGET_CPU_ARCH + '-'
-       else:
-               prefix = TARGET_CPU_ARCH + 'd-'
-       time_obj = libcoap_env.Object(ARDUINO_HOME + '/libraries/Time/Time.cpp', OBJPREFIX=prefix)
-       libcoap_src.append(time_obj)
 else:
        libcoap_src.append(['../ocsocket/src/ocsocket.c'])
 
-libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap')
-i_lc = libcoap_env.Install(BUILD_DIR, libcoap)
-Alias('libcoap', i_lc)
-env.AppendUnique(TS = ['libcoap'])
\ No newline at end of file
+if target_os == 'arduino':
+       libcoap = libcoap_env.StaticLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+else:
+       libcoap = libcoap_env.SharedLibrary('libcoap', libcoap_src, OBJPREFIX='libcoap_')
+
+libcoap_env.InstallTarget(libcoap, 'libcoap')
diff --git a/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript b/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
new file mode 100644 (file)
index 0000000..f5a4222
--- /dev/null
@@ -0,0 +1,23 @@
+Import('env')
+
+arduino_simplecs_env = env.Clone()
+######################################################################
+# Build flags
+######################################################################
+arduino_simplecs_env.PrependUnique(CPPPATH = [
+               '../../../../../ocsocket/include',
+               '../../../../../logger/include',
+               '../../../../../stack/include',
+               '../../../../../../oc_logger/include'
+               ])
+
+arduino_simplecs_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'coap'])
+
+arduino_simplecs = arduino_simplecs_env.Program('SimpleClientServer', 'ocserver.cpp')
+env.CreateBin('SimpleClientServer')
+
+i_arduino_simplecs = arduino_simplecs_env.Install(env.get('BUILD_DIR'), arduino_simplecs)
+
+Alias('arduino_simplecs', i_arduino_simplecs)
+env.AppendTarget('arduino_simplecs')
\ No newline at end of file
index 3c7380f..12a7dcc 100644 (file)
@@ -1,10 +1,12 @@
 ##
 # Examples build script
 ##
-Import('env', 'RELEASE_BUILD', 'BUILD_TARGET', 'BUILD_DIR', 'SRC_TOP_DIR')
+Import('env')
 # Add third party libraries
-SConscript(SRC_TOP_DIR + '/third_party_libs.scons')
-examples_env = env.Clone()
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
+
+examples_env = lib_env.Clone()
 
 ######################################################################
 # Build flags
@@ -19,34 +21,52 @@ examples_env.AppendUnique(CPPPATH = [
                '../oc_logger/include'
                ])
 
-if BUILD_TARGET not in ['windows', 'winrt']:
-       examples_env.AppendUnique(CXXFLAGS = ['-std=c++11', '-Wall'])
+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 = [BUILD_DIR])
+examples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 examples_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger'])
 
-if BUILD_TARGET == 'android':
+if target_os == 'android':
        examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
        examples_env.AppendUnique(LIBS = ['gnustl_static'])
-       examples_env.AppendUnique(LINKFLAGS = ['-static'])
        examples_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
 
-       if not RELEASE_BUILD:
+       if not env.get('RELEASE'):
                examples_env.AppendUnique(LIBS = ['log'])
+
+if target_os in ['darwin', 'ios']:
+       examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
+
 ######################################################################
 # Source files and Targets
 ######################################################################
 simpleserver = examples_env.Program('simpleserver', 'simpleserver.cpp')
+simpleserverHQ = examples_env.Program('simpleserverHQ', 'simpleserverHQ.cpp')
 simpleclient = examples_env.Program('simpleclient', 'simpleclient.cpp')
+simpleclientHQ = examples_env.Program('simpleclientHQ', 'simpleclientHQ.cpp')
+fridgeserver = examples_env.Program('fridgeserver', 'fridgeserver.cpp')
+fridgeclient = examples_env.Program('fridgeclient', 'fridgeclient.cpp')
 presenceserver = examples_env.Program('presenceserver', 'presenceserver.cpp')
 presenceclient = examples_env.Program('presenceclient', 'presenceclient.cpp')
 simpleclientserver = examples_env.Program('simpleclientserver', 'simpleclientserver.cpp')
 roomserver = examples_env.Program('roomserver', 'roomserver.cpp')
 roomclient = examples_env.Program('roomclient', 'roomclient.cpp')
+garageserver = examples_env.Program('garageserver', 'garageserver.cpp')
+garageclient = examples_env.Program('garageclient', 'garageclient.cpp')
 
-Alias("examples", [simpleserver, simpleclient, presenceserver, presenceclient,
-               simpleclientserver, roomserver, roomclient])
-env.AppendUnique(TS = ['examples'])
+Alias("examples", [simpleserver, simpleserverHQ, simpleclient, simpleclientHQ,
+               fridgeserver, fridgeclient, presenceserver, presenceclient,
+               simpleclientserver, roomserver, roomclient, garageserver,
+               garageclient])
+env.AppendTarget('examples')
 
-if BUILD_TARGET not in ['ios']:
-       SConscript(BUILD_DIR + 'examples/ocicuc/SConscript')
+#ios doesn't allow run application from terminal, so won't build these examples
+if target_os != 'ios':
+       SConscript('ocicuc/SConscript')
index eae0706..0b52b29 100644 (file)
@@ -1,11 +1,12 @@
 ##
 # Examples build script
 ##
-Import('env', 'RELEASE_BUILD', 'BUILD_TARGET', 'BUILD_DIR', 'SRC_TOP_DIR')
+Import('env')
 # Add third party libraries
-SConscript(SRC_TOP_DIR + '/third_party_libs.scons')
-ocicuc_env = env.Clone()
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
 
+ocicuc_env = lib_env.Clone()
 ######################################################################
 # Build flags
 ######################################################################
@@ -18,22 +19,22 @@ ocicuc_env.AppendUnique(CPPPATH = [
                '../../oc_logger/include'
                ])
 
-ocicuc_env.AppendUnique(LIBPATH = [BUILD_DIR])
+ocicuc_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 ocicuc_env.PrependUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger'])
 
-if BUILD_TARGET not in ['windows', 'winrt']:
-       ocicuc_env.AppendUnique(CXXFLAGS = ['-std=c++11'])
+target_os = env.get('TARGET_OS')
+if target_os not in ['windows', 'winrt']:
+       ocicuc_env.AppendUnique(CXXFLAGS = ['-std=c++0x'])
 
-if BUILD_TARGET == 'android':
+if target_os == 'android':
        ocicuc_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
        ocicuc_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
        ocicuc_env.AppendUnique(LIBS = ['boost_program_options-gcc-mt-1_49', 'boost_thread-gcc-mt-1_49', 'gnustl_static'])
-       ocicuc_env.AppendUnique(LINKFLAGS = ['-static'])
 
-       if not RELEASE_BUILD:
+       if not env.get('RELEASE'):
                ocicuc_env.AppendUnique(LIBS = ['log'])
 
-if BUILD_TARGET == 'darwin':
+if target_os == 'darwin':
        ocicuc_env.AppendUnique(LIBS = ['boost_program_options'])
 
 ######################################################################
@@ -41,8 +42,8 @@ if BUILD_TARGET == 'darwin':
 ######################################################################
 client = ocicuc_env.Program('client', ['client.cpp', 'driver.cpp', 'utility.cpp'])
 server = ocicuc_env.Program('server', ['server.cpp', 'driver.cpp', 'utility.cpp', 'light_resource.cpp'])
-monoprocess = ocicuc_env.Program('monoprocess',
-               ['monoprocess.cpp', 'driver.cpp', 'utility.cpp', 'light_resource.cpp'])
+monoprocess = ocicuc_env.Program('monoprocess', ['monoprocess.cpp', 'driver.cpp', 'utility.cpp', 'light_resource.cpp'])
+small_example = ocicuc_env.Program('small_example', ['small_example.cpp', 'driver.cpp', 'utility.cpp'])
 
-Alias("examples_ocicuc", [client, server, monoprocess])
-env.AppendUnique(TS = ['examples_ocicuc'])
+Alias("examples_ocicuc", [client, server, monoprocess, small_example])
+env.AppendTarget('examples_ocicuc')
\ No newline at end of file
index 465627b..0b18e4d 100644 (file)
@@ -1,33 +1,36 @@
 ##
-# liboctbstack (static library) build script
+# liboc_logger (share library) build script
 ##
 
-Import('env', 'BUILD_TARGET', 'TARGET_CPU_ARCH', 'BUILD_DIR', 'SRC_TOP_DIR')
+Import('env')
 
-# Add third party libraries
-SConscript(SRC_TOP_DIR + '/third_party_libs.scons')
-
-liboc_logger_env = env.Clone()
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
 
+liboc_logger_env = lib_env.Clone()
 ######################################################################
 # Build flags
 ######################################################################
 liboc_logger_env.PrependUnique(CPPPATH = ['include'])
 
-if BUILD_TARGET == 'android':
+target_os = env.get('TARGET_OS')
+if target_os == 'android':
        liboc_logger_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
        liboc_logger_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+       liboc_logger_env.AppendUnique(LIBS = ['gnustl_static', 'log'])
 
-if BUILD_TARGET not in ['arduino', 'windows', 'winrt']:
-       liboc_logger_env.AppendUnique(CFLAGS = ['-Wall', '-std=c99'])
-       liboc_logger_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
+if target_os not in ['arduino', 'windows', 'winrt']:
+       liboc_logger_env.AppendUnique(CFLAGS = ['-Wall', '-std=c99', '-fPIC'])
+       liboc_logger_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x', '-fPIC'])
 
 ######################################################################
 # Source files and Targets
 ######################################################################
-liboc_logger_core = liboc_logger_env.StaticLibrary('oc_logger_core', 'c/oc_logger.c',  OBJPREFIX='core')
-liboc_logger = liboc_logger_env.StaticLibrary('oc_logger',
+liboc_logger_core = liboc_logger_env.SharedLibrary('oc_logger_core', 'c/oc_logger.c',  OBJPREFIX='core_')
+liboc_logger = liboc_logger_env.SharedLibrary('oc_logger',
                ['c/oc_logger.c', 'c/oc_console_logger.c', 'cpp/oc_ostream_logger.cpp'])
-i_loggers = liboc_logger_env.Install(BUILD_DIR, [liboc_logger_core, liboc_logger])
-Alias('liboc_logger', i_loggers)
-env.AppendUnique(TS = ['liboc_logger'])
\ No newline at end of file
+
+liboc_logger_env.InstallTarget([liboc_logger_core, liboc_logger], 'liboc_logger')
+
+if target_os not in ['ios']:
+       SConscript('examples/SConscript')
diff --git a/resource/oc_logger/examples/SConscript b/resource/oc_logger/examples/SConscript
new file mode 100644 (file)
index 0000000..d3205ba
--- /dev/null
@@ -0,0 +1,35 @@
+##
+# liboc_logger examples build script
+##
+
+Import('env')
+
+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.PrependUnique(CPPPATH = ['../include'])
+examples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+examples_env.AppendUnique(LIBS = ['oc_logger', 'stdc++'])
+
+target_os = env.get('TARGET_OS')
+if target_os == 'android':
+       examples_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       examples_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+       examples_env.AppendUnique(LIBS = ['gnustl_static'])
+
+if target_os not in ['arduino', 'windows', 'winrt']:
+       examples_env.AppendUnique(CFLAGS = Split('-Wall -std=c99 -Werror'))
+       examples_env.AppendUnique(CXXFLAGS = Split('-Wall -std=c++0x'))
+
+######################################################################
+# Source files and Targets
+######################################################################
+examples_c = examples_env.Program('examples_c', 'test_logging.c', OBJPREFIX='c_')
+examples_cpp = examples_env.Program('examples_cpp', 'test_logging.cpp')
+
+Alias('liboc_logger_examples', [examples_c, examples_cpp])
+examples_env.AppendTarget('liboc_logger_examples')
\ No newline at end of file
index 2447934..7ec0c8e 100644 (file)
@@ -1,13 +1,13 @@
 ##
-# OCLib (static library) build script
+# OCLib (share library) build script
 ##
-Import('env', 'BUILD_TARGET', 'BUILD_DIR', 'SRC_TOP_DIR')
+Import('env')
 
 # Add third party libraries
-SConscript(SRC_TOP_DIR + '/third_party_libs.scons')
-
-oclib_env = env.Clone()
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
 
+oclib_env = lib_env.Clone()
 ######################################################################
 # Build flags
 ######################################################################
@@ -21,26 +21,33 @@ oclib_env.AppendUnique(CPPPATH = [
                '../oc_logger/include'
                ])
 
-if BUILD_TARGET not in ['windows', 'winrt']:
-       oclib_env.AppendUnique(CXXFLAGS = ['-std=c++11', '-Wall'])
+target_os = env.get('TARGET_OS')
+if target_os not in ['windows', 'winrt']:
+       oclib_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-fPIC'])
 
-if BUILD_TARGET == 'android':
+if target_os == 'android':
        oclib_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
        oclib_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+       oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       oclib_env.AppendUnique(LIBS = ['octbstack', 'coap', 'oc_logger', 'boost_thread-gcc-mt-1_49', 'gnustl_static', 'log'])
+
+if target_os in ['darwin', 'ios']:
+       oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       oclib_env.AppendUnique(LIBS = ['octbstack', 'coap', 'oc_logger'])
 
 ######################################################################
 # Source files and Targets
 ######################################################################
 oclib_src = [
                'OCPlatform.cpp',
+               'OCPlatform_impl.cpp',
                'OCResource.cpp',
                'OCUtilities.cpp',
                'OCException.cpp',
+               'OCRepresentation.cpp',
                'InProcServerWrapper.cpp',
                'InProcClientWrapper.cpp'
        ]
 
-oclib = oclib_env.StaticLibrary('oc', oclib_src)
-i_ocl = oclib_env.Install(BUILD_DIR, oclib)
-Alias('liboc', i_ocl)
-env.AppendUnique(TS = ['liboc'])
\ No newline at end of file
+oclib = oclib_env.SharedLibrary('oc', oclib_src)
+oclib_env.InstallTarget(oclib, 'liboc')
index 2cf1cfc..a22bc36 100644 (file)
@@ -4,75 +4,66 @@
 #Note: The paths must keep consistent with oic-utilities
 ######################################################################
 import os
+import platform
 
-Import('env', 'BUILD_TARGET', 'TARGET_CPU_ARCH', 'SRC_TOP_DIR')
+Import('env', 'lib_env')
 
-# Add 'OIC_UTILS' build option for user to set oic-utilities project path
-default_dir = os.path.abspath(SRC_TOP_DIR + '/../oic-utilities')
-OIC_UTILS = ARGUMENTS.get('OIC_UTILS', default_dir)
-if not os.path.exists(OIC_UTILS):
-       print '''
-*********************************** Error: ************************************
-*   oic-utilities project directory(OIC_UTILS) isn't set properly, please set *
-* enviornment variable OIC_UTILS or set it in command line:                   *
-*     # scons  OIC_UTILS=<path to oic-utilities> ...                          *
-*******************************************************************************
-'''
-       Exit(1)
+target_os = env.get('TARGET_OS')
+target_arch = env.get('TARGET_ARCH')
+src_dir = env.get('SRC_DIR')
 
-if env.get('OIC_UTILS') is None:
-       vars = Variables()
-       vars.Add(PathVariable('OIC_UTILS', 'oic-utilities project path', OIC_UTILS))
-       vars.Update(env)
-       Help(vars.GenerateHelpText(env))
-       Export('OIC_UTILS')
+if target_os not in ['linux', 'darwin']:
+       utils_path = env.get('OIC_UTILS')
 
-       ######################################################################
-       # Check dependent packages (Linux)
-       ######################################################################
-       if BUILD_TARGET == 'linux':
-               # Delete the temp files of configuration
-               if env.GetOption('clean'):
-                       if os.path.exists(SRC_TOP_DIR + 'config.log'):
-                               Execute(Delete(SRC_TOP_DIR + 'config.log'))
-                               Execute(Delete(SRC_TOP_DIR + '.sconsign.dblite'))
-                               Execute(Delete(SRC_TOP_DIR + '.sconf_temp'))
-               elif not env.GetOption('help'):
-                       conf = Configure(env)
+######################################################################
+# Check dependent packages (Linux only)
+######################################################################
+if target_os == 'linux':
+       if not env.GetOption('help'):
+               if not target_arch == platform.machine():
+                       print '''
+*********************************** Warning ***********************************
+* You are trying cross build, please make sure (%s) version libraries are
+* installed!                                                                 *
+*******************************************************************************
+''' % target_arch
 
-                       if not conf.CheckLib('boost_program_options'):
-                               print 'Did not find boost_program_options, exiting!'
-                               Exit(1)
+               conf = Configure(lib_env)
 
-                       conf.Finish()
+               if not conf.CheckLib('boost_program_options'):
+                       print 'Did not find boost_program_options, exiting!'
+                       Exit(1)
 
-       ######################################################################
-       # The 'include' path of third party libraries
-       ######################################################################
+               conf.Finish()
 
-       if BUILD_TARGET == 'android':
-               env.AppendUnique(CPPPATH = [OIC_UTILS + '/android/boost/include'])
+######################################################################
+# The 'include' path of third party libraries
+######################################################################
+if target_os == 'android':
+       lib_env.AppendUnique(CPPPATH = [utils_path + '/android/boost/include'])
 
-       ######################################################################
-       # The path of third party libraries binary
-       ######################################################################
-       if BUILD_TARGET == 'android':
-               arch = TARGET_CPU_ARCH
-               if arch == 'armeabi-v7a-hard':
-                       arch = 'armeabi-v7a'
+######################################################################
+# The path of third party libraries binary
+######################################################################
+if target_os == 'android':
+       if target_arch == 'armeabi-v7a-hard':
+               target_arch = 'armeabi-v7a'
 
-               if arch not in ['x86', 'armeabi', 'armeabi-v7a']:
+       if target_arch not in ['x86', 'armeabi', 'armeabi-v7a']:
+               if not env.GetOption('help') and not env.GetOption('clean'):
                        print '''
 *********************************** Warning ***********************************
-* current only x86, armeabi, armeabi-v7a libraries are offered!               *
+* current only x86, armeabi, armeabi-v7a libraries are provided!              *
 *******************************************************************************
 '''
-               else:
-                       env.AppendUnique(LIBPATH = [OIC_UTILS + '/android/boost/libs/' + arch])
+       else:
+               lib_env.AppendUnique(LIBPATH = [utils_path + '/android/boost/libs/' + target_arch])
+               # Too much boost warning, suppress the warning
+               lib_env.AppendUnique(CCFLAGS = ['-w'])
 
-       elif BUILD_TARGET == 'ios':
-               env.AppendUnique(FRAMEWORKPATH = [OIC_UTILS + '/ios/frameworks/'])
-               env.AppendUnique(FRAMEWORKS = ['boost'])
-       elif BUILD_TARGET == 'darwin':
-               env.AppendUnique(CPPPATH = ['/usr/local/include'])
-               env.AppendUnique(LIBPATH = ['/usr/local/lib'])
\ No newline at end of file
+elif target_os == 'ios':
+       lib_env.AppendUnique(FRAMEWORKPATH = [utils_path + '/ios/frameworks/'])
+       lib_env.AppendUnique(FRAMEWORKS = ['boost'])
+elif target_os == 'darwin':
+       lib_env.AppendUnique(CPPPATH = ['/usr/local/include'])
+       lib_env.AppendUnique(LIBPATH = ['/usr/local/lib'])
\ No newline at end of file
diff --git a/scons_script_how_to.txt b/scons_script_how_to.txt
new file mode 100644 (file)
index 0000000..c210419
--- /dev/null
@@ -0,0 +1,235 @@
+== How to write iotivity build script ==
+
+Iotivity projects are built with Scons. Scons is a cross-platform build tool,
+it's quite similar to 'make'. 'SConstruct' is the entrance of scons build, it's
+equivalent to 'Makefile' to 'make'.
+
+This document only a brief reference. Detail about how to write scons script,
+please refer to:
+       http://www.scons.org/doc/production/HTML/scons-user.html#
+
+== Background: How to control source code compiling ==
+
+Environment is a base conception of Scons. An environment is a collection of
+values that can affect how a program is built.
+
+e.g. There is a C file named hello.c, enter the following into a file named
+SConstruct:
+       env = Environment()
+       env.Program('H', 'hello.c')
+
+When run Scons in console, following will be executed:
+cc -o hello.o -c hello.c
+cc -o H hello.o
+
+If you would like keep debug information in the binary, '-g' flag should be added
+when build the source code. To do this, append a C compiler flags as following:
+       env = Environment()
+       env.AppendUnique(CFLAGS = ['-g'])
+       env.Program('H', 'hello.c')
+
+When run Scons, following will be executed:
+cc -o hello.o -c -g hello.c
+cc -o H hello.o
+
+In above example, 'CFLAGS' is changed. Following list the frequently used keys:
+
+CFLAGS: General options that are passed to the C compiler
+CCFLAGS: General options that are passed to the C & C++ compiler
+CXXFLAGS: General options that are passed to the C++ compiler
+CPPPATH: The directories that the preprocessor will search for include headers.
+CPPDEFINES: Platform independent specification of C preprocessor definitions.
+
+Note: CPPPATH and CPPDEFINES is common for all compiler. But others are
+compiler specific, when change the key value, it may requried to specify the
+target platform(actually the compiler).
+
+e.g.
+       env.AppendUnique(CPPPATH = ['.', 'include'])
+       env.AppendUnique(CPPDEFINES = ['NDEBUG', 'VER_TEST'])
+Above two lines are fine for all target platform. but below line:
+       env.AppenUnique(CXXFLAGS = ['-g'])
+is only fine for gcc compiler, as '-g' is a gcc flag, other compiler may don't
+understand it. so it may should be:
+       if target_os not in ['windows', 'winrt']:
+               env.AppenUnique(CXXFLAGS = ['-g'])
+
+Still take the hello.c as example. Assume hello.h is in ./include/ directory,
+#include "hello.h"
+int main(int argc, char** argv)
+{
+#ifdef LANG_FR
+    printf("Bonjour\n");
+#else
+       printf("Hello\n");
+#endif
+}
+
+The Scons configure file should as following:
+       env = Environment()
+       env.AppendUnique(CFLAGS = ['-g'])
+       env.AppendUnique(CPPPATH = ['include'])
+       env.AppendUnique(CPPDEFINES = ['LANG_FR'])
+       env.Program('H', 'hello.c')
+
+When run Scons, following will be executed:
+cc -o hello.o -c -g -Iinclude -DLANG_FR hello.c
+cc -o H hello.o
+
+=== Get extra information ===
+
+In above example, 'target_os' is used. How to get it?
+
+User can build iotivity project on linux / windows / MAC OSX for various
+targets(Linux, Tizen, Android, Arduino, Windows, MAC OSX, IOS ...). Most
+platform specific configures have been done in the common scripts whitch are in
+build_common. The common scripts prepare an environment named 'env' with
+target platform specific configuration.
+
+When write iotivity project build script, you can get this environment as
+following:
+       Import('env')
+
+You can use 'env' directly after import it. You can also clone a new environment
+and update its keys.
+
+       new_env1 = Clone('env')
+       new_env2 = Clone('env')
+       new_env1.AppendUnqiue(xxx = [...])
+       new_env2.AppendUnqiue(xxx = [...])
+
+The 'env' environment contains platform specific configuration, besides, there is
+some common information. You can get the information with following line:
+       env.get('XXX')
+
+XXX is the information name, below are the extra information added by iotivity
+common scrirpts:
+BUILD_DIR: the path of the build directory
+SRC_DIR: the path of the top directory of the source code
+OIC_UTILS: the path of oic-utilities project
+RELEASE: boolean. True - release build, False - debug build
+TARGET_OS: the name of the target OS. The possible value depends on the host
+       platform. Bellow is the list of host and possible target OS. (darwin means
+       MAC OSX)
+               linux: linux / android / arduino
+(the line means on linux, you can build the project for linux/android/arduino)
+               windows: windows / winrt / android / arduino
+               darwin: darwin / ios / android / arduino
+
+TARGET_ARCH: the target CPU arch. Its possible value depend on the target OS
+       Bellow list the target OS and allowed CPU architecture.
+               linux: x86 / x86_64 / arm / arm64
+(above line means if the target OS is linux, the CPU arch can be x86/x86_64/arm/arm64)
+               android: x86 / x86_64 / armeabi / armeabi-v7a / armeabi-v7a-hard / arm64-v8a
+               windows: x86 / amd64 / arm
+               winrt: arm
+               darwin: i386 / x86_64
+               ios: i386 / x86_64 / armv7 / armv7s / arm64,
+               arduino: avr / arm
+
+=== Extra functions ===
+
+For convenience, in the common scripts, some extra functions are added.
+
+PrintTargets(): print all targets in the help information.
+AppendTarget(target): add 'target' into targets list, when use PrintTargets,
+       the 'target' will be print.
+InstallTarget(files, name): it takes the same action as AppendTarget, besides,
+       it installs the 'files' to BUILD_DIR.
+
+Following functions are only for Arduino:
+ImportLib(lib): Arduino IDE includes many libraries. To control the binary size,
+by default, no library is used. If your project use some libraries, you can
+import the lib with this function. 'lib' is the name of the lib to import.
+The include path will be auto added to the environment and the library will be
+built and linked into the final binary.
+
+CreateBin('bin', src): For Arduino, after build the program, it's required to
+be converted into specific format (e.g .hex). This function will genearate the
+required .hex (and .eep if target arch is avr) file.
+
+UploadHelp(): For different board, the upload command line is different, this
+function print the recommended upload command line. You can see the recommended
+upload command line in the help information.
+
+==== Scripts Hierarchy ====
+
+Scons provides a function 'SConscript(scripts, [exports, variant_dir, duplicate])'
+It tells scons to execute one or more subsidiary configuration files(A script,
+usually named SConscript). Take below project hierarchy as example to show how
+to organize the scripts.
+
+               prj
+               |-------prj_1
+               |               |--------sub_prj_11
+               |               |--------sub_prj_..
+               |               |--------sub_prj_1n
+               |-------prj_2
+               |
+               | ... ...
+               |
+               |-------prj_n
+
+As above project hierarchy, in 'SConstruct' file in the 'prj' directory, there
+should include some lines like these:
+
+#Please change this part according to the organization of your projects.
+#Note: To make the output is in build_dir, the path of the scripts should
+#be relevant to build_dir
+SConscript(build_dir + 'prj_1/SConscript')
+SConscript(build_dir + 'prj_2/SConscript')
+... ...
+SConscript(build_dir + 'prj_n/SConscript')
+
+
+It's the same, in the 'prj_1/SConscript', there should include lines like
+these:
+SConscript('sub_prj_11/SConscript')
+... ...
+SConscript('sub_prj_1n/SConscript')
+
+The path is relevant to 'prj_1/SConscript'. You can also use the full path
+build_dir + 'prj_1/sub_prj_1x/SConscript', but it's not recommended.
+
+Above just to show a usual way to manage subsidiary scripts. You don't need
+restrictly follow it.
+
+==== The content of a typical script ====
+
+After run the scripts in build_common (usally it's done at the beginning of
+SConstruct), an global environment 'env' is exported, 'env' has include the
+default configuration of the target OS and arch. 'env' is used in all projects,
+should avoid to change its keys. To avoid change 'env', usually clone 'env' and
+update it accroding to the requirement of cuurent sub project. Then specify the
+target(usually binary) to build.
+
+Below is an example:
+       # import the global enviroment 'env'
+       Import('env')
+
+       # Clone a new enviroment from 'env'
+       new_env = env.Clone()
+
+       # Update the new enviroment, usally include add header file paths,
+       # library path, libs to link and other compiler flags. This part is
+       # optional. If not present, the default configuration will be used
+       new_env.AppeneUnique(xxx = [ .... ])
+
+       # Specify the target(application, library, object or others) to build
+       ts = new_env.Program('progam_name', [source_list])
+
+       # Install the target (optional)
+       new_env.InstallTarget(ts, 'target_name')
+or
+       new_env.Alias('target_name', ts)
+       new_env.AppendTarget('target_name')
+
+==== Tips ====
+1. library order: if A lib use B lib, both A and B are linked to target T, the
+       when specify libraries, A should in front of B, otherwise there may be link
+       error.
+2. On android:
+       (1)'pthread' is in libc. So don't use '-lpthread' for android
+       (2)By default 'rtti' and 'exception' is disabled, to enable it, you need
+       add flags '-frtti' and '-fexceptions'
+       (3)If STL is used, need link 'gnustl_static' library
diff --git a/service/SConscript b/service/SConscript
new file mode 100644 (file)
index 0000000..4f49777
--- /dev/null
@@ -0,0 +1,25 @@
+##
+# 'service' sub-project main build script
+#
+##
+Import('env')
+
+target_os = env.get('TARGET_OS')
+
+if target_os != 'arduino':
+       # Build things manager project
+       SConscript('things-manager/SConscript')
+
+       # Build soft sensor manager project
+       SConscript('soft-sensor-manager/SConscript')
+
+       # Build protocol plugin project
+       # protocol-plugin use 'sys/inotify.h', this header file doesn't
+       # exist on MAC OSX
+       if target_os not in ['darwin', 'ios']:
+               SConscript('protocol-plugin/SConscript')
+
+       # Build notification manager project
+       SConscript('notification-manager/SConscript')
+else:
+       SConscript('notification-manager/SampleApp/arduino/SConscript')
diff --git a/service/notification-manager/SConscript b/service/notification-manager/SConscript
new file mode 100644 (file)
index 0000000..a5e52dd
--- /dev/null
@@ -0,0 +1,48 @@
+##
+# NotificationManager build script
+##
+
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+notimgr_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+notimgr_env.AppendUnique(CPPPATH = ['NotificationManager/include'])
+notimgr_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap'])
+
+if target_os not in ['windows', 'winrt']:
+       notimgr_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+if target_os == 'linux':
+       notimgr_env.AppendUnique(LIBS = ['pthread'])
+
+if target_os == 'android':
+       notimgr_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       notimgr_env.AppendUnique(LIBS = ['gnustl_static'])
+       notimgr_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+
+       if not env.get('RELEASE'):
+               notimgr_env.AppendUnique(LIBS = ['log'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+NOTI_SRC_DIR = 'NotificationManager/src/'
+notimgr_src = [
+               NOTI_SRC_DIR + 'LinuxMain.cpp',
+               NOTI_SRC_DIR + 'NotificationManager.cpp',
+               NOTI_SRC_DIR + 'RegistrationManager.cpp',
+               NOTI_SRC_DIR + 'ResourceManager.cpp',
+               NOTI_SRC_DIR + 'VirtualRepresentation.cpp']
+
+notificationmanager = notimgr_env.Program('noti_manager', notimgr_src)
+
+notimgr_env.InstallTarget(notificationmanager, 'notificationmanager')
+
+# Go to build sample apps
+SConscript('SampleApp/SConscript')
diff --git a/service/notification-manager/SampleApp/SConscript b/service/notification-manager/SampleApp/SConscript
new file mode 100644 (file)
index 0000000..d59dc6d
--- /dev/null
@@ -0,0 +1,10 @@
+##
+# Examples build script
+##
+Import('env')
+
+target_os = env.get('TARGET_OS')
+if target_os == 'linux':
+       SConscript('linux/SConscript')
+elif target_os == 'arduino':
+       SConscript('arduino/SConscript')
\ No newline at end of file
diff --git a/service/notification-manager/SampleApp/arduino/SConscript b/service/notification-manager/SampleApp/arduino/SConscript
new file mode 100644 (file)
index 0000000..04602f6
--- /dev/null
@@ -0,0 +1,33 @@
+##
+# NotificationManager build script
+##
+
+Import('env')
+
+notimgr_env = env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+resource_path = env.get('SRC_DIR') + '/resource'
+
+notimgr_env.AppendUnique(CPPPATH = [
+               resource_path + '/oc_logger/include',
+               resource_path + '/csdk/stack/include',
+               resource_path + '/csdk/ocsocket/include',
+               resource_path + '/csdk/logger/include'
+               ])
+
+notimgr_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+notimgr_env.PrependUnique(LIBS = ['octbstack', 'coap'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+thserver = notimgr_env.Program('thserver', 'thserver.cpp')
+notimgr_env.CreateBin('thserver')
+
+i_thserver = notimgr_env.Install(env.get('BUILD_DIR'), thserver)
+
+Alias('thserver_arduino', i_thserver)
+env.AppendTarget('thserver_arduino')
\ No newline at end of file
diff --git a/service/notification-manager/SampleApp/linux/SConscript b/service/notification-manager/SampleApp/linux/SConscript
new file mode 100644 (file)
index 0000000..be46453
--- /dev/null
@@ -0,0 +1,22 @@
+##
+# NotificationManager build script
+##
+
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+notimgr_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+notimgr_env.AppendUnique(CPPPATH = ['../../NotificationManager/include'])
+notimgr_env.AppendUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'coap', 'pthread'])
+notimgr_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+sampleprovider = notimgr_env.Program('sampleprovider', 'sampleProvider/SampleProvider.cpp')
+sampleconsumer = notimgr_env.Program('sampleconsumer', 'sampleConsumer/SampleConsumer.cpp')
\ No newline at end of file
diff --git a/service/protocol-plugin/SConscript b/service/protocol-plugin/SConscript
new file mode 100644 (file)
index 0000000..d8db971
--- /dev/null
@@ -0,0 +1,13 @@
+##
+# protocol plugin build script
+##
+Import('env')
+
+SConscript('lib/cpluff/SConscript')
+SConscript('plugin-manager/SConscript')
+
+#The code include pthread_cancel method, can't build on android
+if env.get('TARGET_OS') != 'android':
+       SConscript('plugins/SConscript')
+
+SConscript('sample-app/SConscript')
diff --git a/service/protocol-plugin/lib/cpluff/SConscript b/service/protocol-plugin/lib/cpluff/SConscript
new file mode 100644 (file)
index 0000000..58e79f7
--- /dev/null
@@ -0,0 +1,31 @@
+##
+#c-pluff build script
+##
+import platform,os
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+cpluff_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+cpluff_env.AppendUnique(CPPPATH = ['libcpluff/'])
+if target_os not in ['windows', 'winrt']:
+       cpluff_env.AppendUnique(CFLAGS = ['-g','-fPIC', '-DPIC',
+                               '-DDLOPEN_POSIX',
+                               '-DCP_HOST=\\"' + platform.platform() + '\\"',
+                               '-DCP_SHREXT=\\".so\\"',
+                               '-DCP_FNAMESEP_CHAR=\\"\'/\'\\"',
+                               '-DCP_THREADS=\\"Posix\\"'])
+       cpluff_env.AppendUnique(LIBS = ['dl'])
+######################################################################
+# Source files and Targets
+######################################################################
+cpluff_src = [f for f in env.Glob('libcpluff/*.c') if os.path.basename(f.path) not in ['thread_windows.c']]
+cpluff_src.extend(env.Glob('kazlib/*.c'))
+
+cpluff = cpluff_env.StaticLibrary('cpluff', cpluff_src)
+cpluff_env.InstallTarget(cpluff, 'libcpluff')
\ No newline at end of file
diff --git a/service/protocol-plugin/plugin-manager/SConscript b/service/protocol-plugin/plugin-manager/SConscript
new file mode 100644 (file)
index 0000000..1e7d42b
--- /dev/null
@@ -0,0 +1,47 @@
+##
+# plugin-manager project build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+plugin_manager_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+plugin_manager_env.AppendUnique(CPPPATH = [
+               '../lib/cpluff/libcpluff',
+               'src'
+               ])
+
+if target_os not in ['windows', 'winrt']:
+       plugin_manager_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall',
+               '-fpermissive', '-Wsign-compare'])
+
+if target_os == 'android':
+       plugin_manager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       plugin_manager_env.AppendUnique(LIBS = ['boost_thread-gcc-mt-1_49', 'gnustl_static'])
+
+plugin_manager_env.AppendUnique(LIBS = ['oc', 'octbstack', 'expat', 'dl'])
+######################################################################
+# Source files and Targets
+######################################################################
+ppm_src = ['src/Plugin.cpp', 'src/PluginManager.cpp']
+ppm = plugin_manager_env.StaticLibrary('ppm', ppm_src)
+
+pmimpl_src = [
+               'src/CpluffAdapter.cpp',
+               'src/FelixAdapter.cpp',
+               'src/Plugin.cpp',
+               'src/PluginManagerImpl.cpp']
+
+pmimpl_env = plugin_manager_env.Clone()
+pmimpl_env.PrependUnique(CCFLAGS = ['-fPIC'])
+pmimpl_env.PrependUnique(LIBS = File(env.get('BUILD_DIR') + '/libcpluff.a'))
+pmimpl = pmimpl_env.SharedLibrary('pmimpl', pmimpl_src)
+
+plugin_manager_env.InstallTarget([ppm, pmimpl], 'libppm')
diff --git a/service/protocol-plugin/plugins/SConscript b/service/protocol-plugin/plugins/SConscript
new file mode 100644 (file)
index 0000000..0d9e0cf
--- /dev/null
@@ -0,0 +1,40 @@
+##
+# Plugins build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+plugins_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+plugins_env.AppendUnique(CPPPATH = ['../lib/cpluff/libcpluff'])
+
+if target_os not in ['windows', 'winrt']:
+       plugins_env.AppendUnique(CXXFLAGS = ['-g3', '-Wall', '-pthread', '-std=c++0x'])
+       plugins_env.AppendUnique(LINKFLAGS = ['-fPIC'])
+
+       if target_os not in ['arduino', 'android']:
+               plugins_env.AppendUnique(LIBS = ['pthread'])
+
+if target_os == 'android':
+       plugins_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       plugins_env.AppendUnique(LIBS = ['gnustl_static'])
+       plugins_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+mqtt_fan_src = Glob('mqtt-fan/src/' + '*.cpp')
+fanserver = plugins_env.SharedLibrary('fanserver_mqtt_plugin', mqtt_fan_src)
+
+mqtt_light_src = Glob('mqtt-light/src/' + '*.cpp')
+lightserver = plugins_env.SharedLibrary('lightserver_mqtt_plugin', mqtt_light_src)
+
+SConscript('mqtt-fan/lib/SConscript')
diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/SConscript b/service/protocol-plugin/plugins/mqtt-fan/lib/SConscript
new file mode 100644 (file)
index 0000000..a5695c2
--- /dev/null
@@ -0,0 +1,27 @@
+##
+# mosquitto build script
+##
+import platform,os
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+mosquitto_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+mosquitto_env.AppendUnique(CPPPATH = ['./'])
+if target_os not in ['windows', 'winrt']:
+       mosquitto_env.AppendUnique(CFLAGS = ['-Wall', '-ggdb', '-fPIC',
+                       '-DWITH_TLS', '-DWITH_TLS_PSK', '-DWITH_THREADING'])
+######################################################################
+# Source files and Targets
+######################################################################
+mosquitto_src = env.Glob('*.c')
+
+mosquitto = mosquitto_env.StaticLibrary('mosquitto', mosquitto_src)
+mosquitto_env.InstallTarget(mosquitto, 'libmosquitto')
+
+SConscript('cpp/SConscript')
diff --git a/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/SConscript b/service/protocol-plugin/plugins/mqtt-fan/lib/cpp/SConscript
new file mode 100644 (file)
index 0000000..55e2333
--- /dev/null
@@ -0,0 +1,24 @@
+##
+# mosquittopp build script
+##
+import platform,os
+Import('env')
+
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+mosquittopp_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+mosquittopp_env.AppendUnique(CPPPATH = ['./', '../'])
+if target_os not in ['windows', 'winrt']:
+       mosquittopp_env.AppendUnique(CFLAGS = ['-Wall', '-ggdb', '-O2', '-fPIC'])
+
+mosquittopp_env.AppendUnique(LIBS = ['mosquitto', 'ssl', 'crypto'])
+######################################################################
+# Source files and Targets
+######################################################################
+mosquittopp = mosquittopp_env.SharedLibrary('mosquittopp', 'mosquittopp.cpp')
+mosquittopp_env.InstallTarget(mosquittopp, 'libmosquittopp')
diff --git a/service/protocol-plugin/sample-app/SConscript b/service/protocol-plugin/sample-app/SConscript
new file mode 100644 (file)
index 0000000..413dd94
--- /dev/null
@@ -0,0 +1,10 @@
+##
+#sample-app build script
+##
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+
+if target_os == 'linux':
+       SConscript('linux/SConscript')
diff --git a/service/protocol-plugin/sample-app/linux/SConscript b/service/protocol-plugin/sample-app/linux/SConscript
new file mode 100644 (file)
index 0000000..339d4bb
--- /dev/null
@@ -0,0 +1,28 @@
+##
+#sample-app build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+sample_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+sample_env.AppendUnique(CPPPATH = ['../../plugin-manager/src/',
+                               '../../lib/cpluff/libcpluff/'])
+if target_os not in ['windows', 'winrt']:
+       sample_env.AppendUnique(CXXFLAGS = ['-Wall', '-pthread', '-std=c++0x'])
+
+sample_env.AppendUnique(LIBS = ['oc', 'oc_logger', 'octbstack', 'coap', 'ppm', 'pmimpl', 'dl'])
+######################################################################
+# Source files and Targets
+######################################################################
+fanclient = sample_env.Program('fanclient', 'fan-control/fanclient.cpp')
+
+Alias('fanclient', fanclient)
+env.AppendTarget('fanclient')
\ No newline at end of file
diff --git a/service/soft-sensor-manager/SConscript b/service/soft-sensor-manager/SConscript
new file mode 100644 (file)
index 0000000..aec6fcb
--- /dev/null
@@ -0,0 +1,103 @@
+##
+# soft-sensor-manager project build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+soft_sensor_manager_env = lib_env.Clone()
+
+target_os = env.get('TARGET_OS')
+# As in the source code, it includes arduino Time library (C++)
+# It requires compile the .c with g++
+if target_os == 'arduino':
+       soft_sensor_manager_env.Replace(CC = env.get('CXX'))
+       soft_sensor_manager_env.Replace(CFLAGS = env.get('CXXFLAGS'))
+
+######################################################################
+# Build flags
+######################################################################
+if target_os not in ['windows', 'winrt']:
+       soft_sensor_manager_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+       if target_os != 'android':
+               soft_sensor_manager_env.AppendUnique(CXXFLAGS = ['-pthread'])
+
+#######################################################################
+## build SSM SDK
+#######################################################################
+sdk_env = soft_sensor_manager_env.Clone()
+sdk_env.AppendUnique(CPPPATH = ['SDK/include'])
+
+ssm_sdk = sdk_env.Object('SDK/src/SSMClient.cpp')
+i_ssmsdk = sdk_env.Install(env.get('BUILD_DIR'), )
+Alias('libSSMSDKLibrary', i_ssmsdk)
+env.AppendTarget('libSSMSDKLibrary')
+
+######################################################################
+# build DiscomfortIndexSensor plugin
+######################################################################
+DiscomfortIndexSensor_env = soft_sensor_manager_env.Clone()
+
+DiscomfortIndexSensor_env.AppendUnique(CCFLAGS = ['-fPIC'])
+DISCOMFORTINDEXSENSOR_DIR = 'SoftSensorPlugin/DiscomfortIndexSensor/'
+DiscomfortIndexSensor_env.AppendUnique(CPPPATH = [
+               DISCOMFORTINDEXSENSOR_DIR + 'include',
+               'SSMCore/src/SSMInterface/'
+               ])
+
+DiscomfortIndexSensor_src = [ Glob(DISCOMFORTINDEXSENSOR_DIR + 'src/*.cpp')]
+
+DiscomfortIndexSensor = DiscomfortIndexSensor_env.SharedLibrary('DiscomfortIndexSensor', DiscomfortIndexSensor_src)
+DiscomfortIndexSensor_env.InstallTarget(DiscomfortIndexSensor, 'libDiscomfortIndexSensor')
+
+######################################################################
+# build SSM CORE
+######################################################################
+ssmcore_env = soft_sensor_manager_env.Clone()
+MODEL_DIR = "\"\\\"" + env.get('BUILD_DIR') + "\\\"\""
+LOCATION = "\"\\\"" + env.get('BUILD_DIR') + "HighContextDictionary.xml" + "\\\"\""
+
+ssmcore_env.AppendUnique(CPPDEFINES = ['MODEL_DIRECTORY='+MODEL_DIR, 'HIGH_LOCATION='+LOCATION])
+ssmcore_env.AppendUnique(CPPPATH = [
+               'SSMCore/include/',
+               'SSMCore/src/',
+               'SSMCore/src/Common/'
+               'SSMCore/src/QueryProcessor/'
+               'SSMCore/src/SensorProcessor/'
+               'SSMCore/src/SSMInterface/'
+               ])
+
+import os.path
+
+if target_os != 'android':
+       SSMINTERFACE_PATH = 'SSMCore/src/SSMInterface/'
+       omit_src = ['SSMCore_JNI.cpp']
+       ssminterface_src = [f for f in env.Glob(SSMINTERFACE_PATH + '*.cpp') if os.path.basename(f.path) not in omit_src]
+else :
+       ssminterface_src = Glob(SSMINTERFACE_PATH + '*.cpp')
+
+ssm_core_cpp_src = [
+               'SSMCore/src/SSMResourceServerLauncher.cpp',
+               Glob('SSMCore/src/Common/*.cpp'),
+               Glob('SSMCore/src/QueryProcessor/*.cpp'),
+               Glob('SSMCore/src/SensorProcessor/*.cpp'),
+               ssminterface_src,
+               ]
+
+ssm_core_c_src = [
+               'SSMCore/src/Common/sqlite3.c'
+]
+
+libssmcore = ssmcore_env.StaticLibrary(
+               target = 'SSMCoreUbuntu',
+               source = [ssm_core_cpp_src, ssm_core_c_src]
+               )
+
+ssmcore_env.InstallTarget(libssmcore, 'libSSMCORE')
+
+#######################################################################
+## build SampleApp
+#######################################################################
+#SConscript('SampleApp/SConscript')
diff --git a/service/soft-sensor-manager/SampleApp/SConscript b/service/soft-sensor-manager/SampleApp/SConscript
new file mode 100644 (file)
index 0000000..925f281
--- /dev/null
@@ -0,0 +1,24 @@
+##
+# sampleapp build script
+##
+
+Import('env')
+
+# Add third party libraries
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons')
+sample_env = env.Clone()
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+
+######################################################################
+# Source files and Targets
+######################################################################
+if target_os == 'linux' :
+       # Build linux sample app
+       SConscript('linux/ClientApp/SConscript')
+       SConscript('linux/THSensorApp/SConscript')
+       SConscript('linux/THSensorApp1/SConscript')
+
diff --git a/service/soft-sensor-manager/SampleApp/linux/ClientApp/SConscript b/service/soft-sensor-manager/SampleApp/linux/ClientApp/SConscript
new file mode 100644 (file)
index 0000000..8ef6e46
--- /dev/null
@@ -0,0 +1,25 @@
+##
+# linux sample app  build script
+##
+
+Import('env')
+
+# Add third party libraries
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons')
+linux_sample_env = env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include/'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['pthread'])
+
+######################################################################
+#build sampleapp
+######################################################################
+clientapp = linux_sample_env.Program('ClientApp', 'src/SSMTestApp.cpp')
+Alias("clientapp_sample", clientapp)
+env.AppendTarget('clientapp_sample')
diff --git a/service/soft-sensor-manager/SampleApp/linux/THSensorApp/SConscript b/service/soft-sensor-manager/SampleApp/linux/THSensorApp/SConscript
new file mode 100644 (file)
index 0000000..accd6ef
--- /dev/null
@@ -0,0 +1,25 @@
+##
+# linux sample app  build script
+##
+
+Import('env')
+
+# Add third party libraries
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons')
+linux_sample_env = env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include/'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['pthread'])
+
+######################################################################
+#build sampleapp
+######################################################################
+thsensorapp = linux_sample_env.Program('THSensorApp', 'src/ThingResourceServer.cpp')
+Alias("thsensorapp_sample", thsensorapp)
+env.AppendTarget('thsensorapp_sample')
diff --git a/service/soft-sensor-manager/SampleApp/linux/THSensorApp1/SConscript b/service/soft-sensor-manager/SampleApp/linux/THSensorApp1/SConscript
new file mode 100644 (file)
index 0000000..6b5a0bf
--- /dev/null
@@ -0,0 +1,25 @@
+##
+# linux sample app  build script
+##
+
+Import('env')
+
+# Add third party libraries
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons')
+linux_sample_env = env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include/'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['pthread'])
+
+######################################################################
+#build sampleapp
+######################################################################
+thsensorapp1 = linux_sample_env.Program('THSensorApp', 'src/ThingResourceServer1.cpp')
+Alias("thsensorapp1_sample", thsensorapp1)
+env.AppendTarget('thsensorapp1_sample')
diff --git a/service/things-manager/SConscript b/service/things-manager/SConscript
new file mode 100644 (file)
index 0000000..1fb3198
--- /dev/null
@@ -0,0 +1,36 @@
+##
+# things_manager project build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
+
+things_manager_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+######################################################################
+# Build flags
+######################################################################
+things_manager_env.AppendUnique(CPPPATH = ['tgm/inc'])
+things_manager_env.AppendUnique(CPPPATH = ['sdk/inc'])
+
+if target_os not in ['windows', 'winrt']:
+       things_manager_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+       if target_os != 'android':
+               things_manager_env.AppendUnique(CXXFLAGS = ['-pthread'])
+
+if target_os == 'android':
+       things_manager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       things_manager_env.AppendUnique(CPPDEFINES = ['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+tgmsdk = things_manager_env.StaticLibrary('TGMSDKLibrary', 'sdk/src/TGMClient.cpp')
+
+things_manager_env.InstallTarget(tgmsdk, 'libTGMSDK')
+
+#Go to build sample apps
+SConscript('sampleapp/SConscript')
\ No newline at end of file
diff --git a/service/things-manager/sampleapp/SConscript b/service/things-manager/sampleapp/SConscript
new file mode 100644 (file)
index 0000000..bd1b631
--- /dev/null
@@ -0,0 +1,9 @@
+##
+# sampleapp build script
+##
+
+Import('env')
+
+if env.get('TARGET_OS') == 'linux':
+       # Build linux sample app
+       SConscript('linux/tgmclient/SConscript')
diff --git a/service/things-manager/sampleapp/linux/tgmclient/SConscript b/service/things-manager/sampleapp/linux/tgmclient/SConscript
new file mode 100644 (file)
index 0000000..2c347ff
--- /dev/null
@@ -0,0 +1,28 @@
+##
+# linux sample app  build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+linux_sample_env = lib_env.Clone()
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['oc', 'octbstack', 'coap', 'oc_logger', 'TGMSDKLibrary'])
+
+if env.get('TARGET_OS') not in ['windows', 'winrt']:
+       linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+tgmclient = linux_sample_env.Program('tgmclient', 'tgmsdkclient.cpp')
+
+Alias("tgmclient_sample", tgmclient)
+env.AppendTarget('tgmclient_sample')
\ No newline at end of file
diff --git a/service/third_party_libs.scons b/service/third_party_libs.scons
new file mode 100644 (file)
index 0000000..e9a140c
--- /dev/null
@@ -0,0 +1,99 @@
+######################################################################
+# This script manages third party libraries
+#
+#Note: The paths must keep consistent with oic-resource
+######################################################################
+import os
+import platform
+
+Import('env', 'lib_env')
+
+target_os = env.get('TARGET_OS')
+target_arch = env.get('TARGET_ARCH')
+src_dir = env.get('SRC_DIR')
+
+if target_os not in ['linux', 'darwin']:
+       utils_path = env.get('OIC_UTILS')
+
+resource_path = src_dir + '/resource'
+
+######################################################################
+# Check dependent packages (Linux only)
+######################################################################
+if target_os == 'linux':
+       if not env.GetOption('help'):
+               if not target_arch == platform.machine():
+                       print '''
+*********************************** Warning ***********************************
+* You are trying cross build, please make sure (%s) version libraries are
+* installed!                                                                 *
+*******************************************************************************
+''' % target_arch
+
+               conf = Configure(lib_env)
+
+               if not conf.CheckLib('boost_thread'):
+                       print 'Did not find boost_thread, exiting!'
+                       Exit(1)
+
+               if not conf.CheckLib('boost_system'):
+                       print 'Did not find boost_system, exiting!'
+                       Exit(1)
+
+               conf.Finish()
+
+######################################################################
+# The 'include' path of external libraries
+######################################################################
+lib_env.AppendUnique(CPPPATH = [
+               resource_path ,
+               resource_path + '/include' ,
+               resource_path + '/oc_logger/include',
+               resource_path + '/csdk/stack/include',
+               resource_path + '/csdk/ocsocket/include',
+               resource_path + '/csdk/ocrandom/include',
+               resource_path + '/csdk/logger/include'
+               ])
+
+######################################################################
+# The 'include' path of third party libraries
+######################################################################
+if target_os == 'android':
+       lib_env.AppendUnique(CPPPATH = [
+                                       utils_path + '/android/boost/include',
+                                       utils_path + '/android/expat/include/expat/',
+                                       utils_path + '/android/openssl/include',
+                               ])
+
+######################################################################
+# The path of third party libraries binary
+######################################################################
+if target_os == 'android':
+       if target_arch == 'armeabi-v7a-hard':
+               target_arch = 'armeabi-v7a'
+
+       if target_arch not in ['x86', 'armeabi', 'armeabi-v7a']:
+               if not env.GetOption('help') and not env.GetOption('clean'):
+                       print '''
+*********************************** Warning ***********************************
+* current only x86, armeabi, armeabi-v7a libraries are provided!              *
+*******************************************************************************
+'''
+       else:
+               lib_env.AppendUnique(LIBPATH = [
+                                                               utils_path + '/android/boost/libs/' + target_arch,
+                                                               utils_path + '/android/expat/lib/' + target_arch,
+                                                               utils_path + '/android/openssl/lib/' + target_arch,
+                                                       ])
+               # Too much boost warning, suppress the warning
+               lib_env.AppendUnique(CCFLAGS = ['-w'])
+
+elif target_os == 'ios':
+       lib_env.AppendUnique(FRAMEWORKPATH = [utils_path + '/ios/frameworks/'])
+       lib_env.AppendUnique(FRAMEWORKS = ['boost', 'expat', 'openssl'])
+elif target_os == 'darwin':
+       lib_env.AppendUnique(CPPPATH = ['/usr/local/include'])
+       lib_env.AppendUnique(LIBPATH = ['/usr/local/lib'])
+
+Import('env')
+lib_env.AppendUnique(LIBPATH = env.get('BUILD_DIR'))