Fix set command line options for ANDROID_XXX into scons environment.
[platform/upstream/iotivity.git] / build_common / android / SConscript
index 33997cd..ff75940 100644 (file)
@@ -7,34 +7,47 @@ import subprocess
 
 Import('env')
 
+SConscript('../external_libs.scons')
 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))
+if not env.get('ANDROID_NDK'):
+    SConscript('../../extlibs/android/ndk/SConscript')
+    help_vars.Add(PathVariable('ANDROID_NDK', 'Android NDK root directory', os.path.join(env.get('SRC_DIR'), 'extlibs', 'android', 'ndk', 'android-ndk-r10d')))
+
+if not env.get('ANDROID_GRADLE'):
+    SConscript('../../extlibs/android/gradle/SConscript')
+    help_vars.Add(PathVariable('ANDROID_GRADLE', 'Android Gradle directory', os.path.join(env.get('SRC_DIR'), 'extlibs', 'android', 'gradle', 'gradle-2.2.1/bin/gradle')))
+
+if not env.get('ANDROID_HOME'):
+    SConscript('../../extlibs/android/sdk/SConscript')
 
-android_ndk = env.get('ANDROID_NDK')
-if not android_ndk:
+
+if env.get('ANDROID_NDK'):
+       android_ndk = env.get('ANDROID_NDK')
+else:
        print '''
-*************************************** Error *********************************
-*    Android NDK path isn't set, you can set enviornment variable ANDROID_NDK *
-* or add it in command line as:                                               *
+*************************************** Info **********************************
+*    Android NDK path isn't set, the default will be used. You can set        *
+* environment variable ANDROID_NDK or add it in command line as:              *
 *      # scons ANDROID_NDK=<path to android NDK> ...                          *
 *******************************************************************************
 '''
-       Exit(1)
+       android_ndk = os.path.join(env.get('SRC_DIR'), 'extlibs', 'android', 'ndk', 'android-ndk-r10d')
 
-# check 'glib' library
-src_dir = env.get('SRC_DIR')
-if not os.path.exists(src_dir + '/extlibs/glib'):
+if env.get('ANDROID_GRADLE'):
+       android_gradle = env.get('ANDROID_GRADLE')
+else:
        print '''
-*********************************** Error: **************************************
-*  glib' library doesn't exist. please download gnome glib to extlibs directory *
-*  apply the patch as following:                                                *
-* Download the Gnome Glib from http://ftp.gnome.org/pub/GNOME/sources/glib/2.40/*
-* Please go through build instructions at :                                     *
-* resource/csdk/connectivity/lib/android/glibpatch_Readme.txt
-*********************************************************************************
-       '''
+*************************************** Info **********************************
+*    Android Gradle path isn't set, the default will be used. You can set     *
+* environment variable ANDROID_GRADLE or add it in command line as:           *
+*      # scons ANDROID_GRADLE=<path to android GRADLE> ...                    *
+*******************************************************************************
+'''
+       android_gradle = os.path.join(env.get('SRC_DIR'), 'extlibs', 'android', 'gradle', 'gradle-2.2.1', 'bin', 'gradle')
+
+help_vars.Update(env)
+Help(help_vars.GenerateHelpText(env))
+src_dir = env.get('SRC_DIR')
 
 # Overwrite suffixes and prefixes
 if env['HOST_OS'] == 'win32':
@@ -79,15 +92,19 @@ if not os.path.isfile(ndk_build_cmd):
 ''' % android_ndk
        Exit(1)
 
-ANDROID_HOME = os.environ.get('ANDROID_HOME')
-if ANDROID_HOME is not None:
-       ANDROID_HOME = os.path.abspath(ANDROID_HOME)
-
-if ANDROID_HOME is None or not os.path.exists(ANDROID_HOME):
-       print '''
-*************************************** Warning *******************************
-*   Enviornment variable ANDROID_HOME is not set properly. It should be the   *
-* root directory of android sdk. If you'd like build Java code, it's required.*
+# ANDROID_HOME build option
+if env.get('ANDROID_HOME'):
+        android_gradle = env.get('ANDROID_HOME')
+else:
+        help_vars = Variables()
+        help_vars.Add(PathVariable('ANDROID_HOME', 'ANDROID SDK root directory', os.environ.get('ANDROID_HOME')))
+        help_vars.Update(env)
+        Help(help_vars.GenerateHelpText(env))
+        print '''
+*************************************** Info **********************************
+*   Environment variable ANDROID_HOME will use default value. To override     *
+* root directory of android sdk, please specify ANDROID_HOME as follows:      *
+*       scons ANDROID_HOME= <path to Android SDK>                             *
 *******************************************************************************
 '''
 
@@ -101,6 +118,7 @@ for tc_ver in ['4.7', '4.8', '4.9', '']:
 
 cmd = [ndk_build_cmd]
 cmd.append('APP_ABI=' + target_arch)
+cmd.append('APP_PLATFORM=android-21')
 cmd.append('APP_STL=gnustl_shared')
 if env.get('RELEASE'):
        cmd.append('APP_OPTIM=release')
@@ -164,6 +182,12 @@ for flags in p.stdout.readlines():
                if not platform_ver.isdigit():
                        platform_ver = ''
 
+
+       elif cmp(flags[0:9], 'PLATFORM=') == 0:  # get target platform: android-x
+               platform_ver = flags[9+8:].strip()
+               if not platform_ver.isdigit():
+                       platform_ver = ''
+
 # Determine dependency faux SYS_ROOT
 dep_sys_root = os.path.join(env.get('SRC_DIR'), 'dep', 'android', target_arch, 'usr')
 dep_src_dir =  os.path.join(dep_sys_root, 'include')
@@ -186,7 +210,7 @@ else:
        env.AppendUnique(CCFLAGS = ['-g'])
 
 if env.get('LOGGING'):
-        env.AppendUnique(CPPDEFINES = ['-DTB_LOG'])
+        env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 
 env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__ANDROID__'])
@@ -195,13 +219,10 @@ env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC'])
 
 env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 env.AppendUnique(LIBPATH = [src_dir + '/resource/csdk/connectivity/lib/android'])
-env.AppendUnique(LIBS = ['log', 'glib-2.40.2', 'gthread-2.40.2', 'coap'])
+env.AppendUnique(LIBS = ['log', 'coap'])
 
-glib_dir = src_dir + '/extlibs/glib/glib-2.40.2/'
-env.AppendUnique(CPPPATH = [
-                           glib_dir,
-                           glib_dir + 'glib',
-                           glib_dir + 'gthread'])
+if env.get('SECURED') == '1':
+       env.AppendUnique(LIBS = ['tinydtls'])
 
 # From android-5 (API > 20), all application must be built with flags '-fPIE' '-pie'.
 # Due to the limitation of Scons, it's required to added it into the command line
@@ -218,3 +239,4 @@ SConscript('compatibility/cpp11_compat.scons')
 
 # Make sure that boost for android is available
 SConscript(env.get('SRC_DIR') + '/extlibs/boost/SConscript')
+SConscript(env.get('SRC_DIR') + '/extlibs/expat/SConscript')