Update scons build readme and howto document
authorCaiwen Zhang <caiwen.zhang@intel.com>
Tue, 3 Mar 2015 07:13:20 +0000 (15:13 +0800)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Mon, 23 Mar 2015 03:23:48 +0000 (03:23 +0000)
Change-Id: I3a9e7dd82ad98f969449da42acadfad2e0eb4705
Signed-off-by: Caiwen Zhang<caiwen.zhang@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/432
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
(cherry picked from commit f7c465f6d306179b4244591cfe0be73a14feb047)
Reviewed-on: https://gerrit.iotivity.org/gerrit/472
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
Readme.scons.txt
scons_script_how_to.txt

index 34abbff..997011d 100644 (file)
@@ -38,7 +38,7 @@ 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_type>/
 e.g.
-       oic-resource/out/android/armeabi-v7a/release/.
+       iotivity/out/android/armeabi-v7a/release/.
 
 This document takes 'iotivity' project as example, the way to build other
 projects is almost the same.
@@ -56,7 +56,16 @@ 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.
+The change of options value may impact the help information and the behavior
+of the building.
+
+Generally, it's required to specify the target OS and target ARCH, that's to say
+tell Scons which OS and which ARCH you'd like build this project for. By default,
+the target OS and ARCH is the same as the host.
+
+Some more options may be required, please care the 'error' notification when build.
+For help about how to set an option, please run:
+     $ scons TARGET_OS=xxx TARGET_ARCH=yyy [XXX=zzz ...] -h
 
 
 === Prerequites ===
@@ -76,7 +85,7 @@ 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)
+ NDK >= r10)
 
 Arduino:
 To build for Arduino, Arduino IDE is required.
@@ -106,19 +115,22 @@ Java codes, this isn't required)
 so you don't need to add it in command line each time. The build script will
 guide you to do that.)
 
-=== Build IoTivity project on Linux(Ubuntu) ===
+* 3. External libraries
+IoTivity project depends on some external libraries, such as boost, expat ...
+During building, the existence of external library will be checked, if it doesn't
+exist, the build script will try to download, unpack and build the library or
+notify user to install it.
 
-Generally, it's required to specify the target OS and target ARCH, that's to say
-tell Scons which OS and which ARCH you'd like build this project for. By default,
-the target OS and ARCH is the same as the host.
+Downloading and unpacking may fail due to network problem or required unpacking
+tool isn't installed. An message will be displayed, please follow the message
+to skip it.
 
-Some more options may be required, please care the 'error' notification when build.
-For help about how to set an option, please run:
-       $ scons TARGET_OS=xxx TARGET_ARCH=yyy [XXX=zzz ...] -h
+
+=== 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 libexpat1-dev libboost-thread-dev
+      $ sudo apt-get install libboost-dev libexpat1-dev libboost-thread-dev
       $ scons
 
 2. Build IoTivity project for Android
@@ -127,10 +139,6 @@ For help about how to set an option, please run:
 (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
index 390bbde..4e34cc2 100644 (file)
@@ -90,8 +90,8 @@ 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.
+You can use 'env' directly after import it(it isn't recommended). You can also
+clone a new environment and update its keys(recommended).
 
        new_env1 = Clone('env')
        new_env2 = Clone('env')
@@ -112,15 +112,15 @@ RELEASE: build type, 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 / tizen
-(the line means on Linux, you can build the project for Linux/Android/Arduino/Tizen)
+               linux: linux / android / arduino / tizen (means on Linux, you can build the
+                       project for Linux/Android/Arduino/Tizen)
                windows: windows / winrt / android / arduino
                darwin: darwin / ios / android / arduino
 
-TARGET_ARCH: the target CPU arch. Its possible value depend on the target OS.
+TARGET_ARCH: the target CPU arch. Its possible value depends 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)
+               linux: x86 / x86_64 / arm / arm64 (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
@@ -132,9 +132,12 @@ TARGET_ARCH: the target CPU arch. Its possible value depend on the target OS.
 
 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.
+PrintTargets(): print all target names in the help information.
+AppendTarget(name, target = None): add a target name into targets list, when use
+       PrintTargets, the target name will be print
+# @param name - the name of the target(s)(user defined name)
+# @param target - Final binary, file(s) etc genereted after build.
+
 InstallTarget(files, name): it takes the same action as AppendTarget, besides,
        it installs the 'files' to BUILD_DIR.
 
@@ -145,14 +148,40 @@ this function. 'lib' is the name of the library 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
+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.
+required .hex (and .eep if target arch is avr) file from 'bin'.
 
 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(the output of command "scons
 [options] -h")
+Functions for external library management:
+PrepareLib(libname, lib = None, path = None, script = None): Check whether a
+library exists, if not, notify user to install it or try to download the source
+code and build it
+# @param libname - the name of the library try to prepare
+# @param lib - the lib(.so, .a etc) to check (a library may include more then
+#      one lib, e.g. boost, includes boost_thread, boost_system ...
+# @param path - the path of the library building script, if it's not set,
+#                      by default, it's <src_dir>/extlibs/<libname>/
+# @param script - the building script, by default, it's 'SConscript'
+
+Download(target, url): Download source code from URL 'url' and save as 'target'.
+# @param target - the name of the source code package to be saved as
+# @param url - the URL from which to download the source code
+
+Configure(cwd, cmd): Run configure command(such as: boostrap, configure etc.
+usually it's done before build a library)
+# @param cwd - the work directory, full path or relative path to the directory
+               where the library build script in
+# @param cmd - the command to run, can be a script or system command
+
+Install_head_file(file): Install header file(s) to <src_dir>/deps/<target_os>/include
+# @param file - the head file(s) to install
+
+Install_lib(lib): Install library binaries to <src_dir>/deps/<target_os>/lib/<arch>
+# @param lib - the library binary(.so, .a etc) to install
 
 ==== Scripts Hierarchy ====
 
@@ -191,7 +220,7 @@ 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.
+(build_dir + 'prj_1/sub_prj_1x/SConscript'), but it's not recommended.
 
 Above just to show a recommended way to manage subsidiary scripts. You don't
 need restrictly follow it.
@@ -202,7 +231,7 @@ 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
+update it accroding to the requirement of current sub project. Then specify the
 target(usually binary) to build.
 
 Below is an example:
@@ -214,7 +243,7 @@ Below is an example:
 
        # 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
+       # optional.
        new_env.AppeneUnique(xxx = [ .... ])
 
        # Specify the target(application, library, object or others) to build
@@ -224,16 +253,17 @@ Below is an example:
        # If it's an important library or daemon to be published
        new_env.InstallTarget(ts, 'target_name')
 or
-       # If is't examples or test program or others will not be published
-       new_env.Alias('target_name', ts)
-       new_env.AppendTarget('target_name')
+       # If it's examples or test program or others will not be published
+       new_env.AppendTarget('target_name', ts)
 
 ==== 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.
+1. library order: if A lib use B lib, both A and B are linked to target T, when
+       specify libraries, A should in front of B, otherwise there may be link
+       error. e.g.
+               xx_env.AppendUnique(LIBS = ['A', 'B'])
+
 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
+       (3)If STL is used, need link 'gnustl_shared' library