[IOT-1089] Change Android build system to accomodate both Android and Generic Java...
[contrib/iotivity.git] / java / SConscript
similarity index 58%
rename from android/android_api/SConscript
rename to java/SConscript
index 38fd526..395fca5 100644 (file)
@@ -2,20 +2,22 @@ import os
 import platform
 Import('env')
 
-android_home = env.get('ANDROID_HOME')
-
-ANDROID_TARGET_ARCH = env.get('TARGET_ARCH')
+TARGET_ARCH = env.get('TARGET_ARCH')
 if env.get('RELEASE'):
-       ANDROID_RELEASE="release"
+       RELEASE="release"
 else:
-       ANDROID_RELEASE="debug"
-ANDROID_SECURED = env.get('SECURED')
+       RELEASE="debug"
+SECURED = env.get('SECURED')
+
+target_os = env.get('TARGET_OS')
 
-os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
-os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
+if target_os == "android":
+       android_home = env.get('ANDROID_HOME')
+       os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME')
+       os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK')
 
-if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
-    print '''
+       if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exists(android_home + '/build-tools/20.0.0'):
+               print '''
 ***************************************** Info ********************************
 *   Either 'Android API 21' is not installed or 'Android SDK Build Tools      *
 *   20.0.0' is not installed. The Android SDK Manager will now open. Please   *
@@ -41,20 +43,23 @@ if not os.path.exists(android_home + '/platforms/android-21') or not os.path.exi
 
 ...Opening Android SDK Manager now. Once you are finished, the build will continue.
 '''
-    os.system(android_home + '/tools/android')
+       os.system(android_home + '/tools/android')
 
 def ensure_libs(target, source, env):
-    return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so']
+       return target, [source, env.get('BUILD_DIR') + 'liboc.so', env.get('BUILD_DIR') + 'liboc_logger.so', env.get('BUILD_DIR') + 'libocstack-jni.so']
+
+SConscript('jni/SConscript')
 
-# build android_api
 jdk_env = Environment(ENV=os.environ)
-jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED), emitter = ensure_libs)
+jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + env.get('SRC_DIR') + '/java/iotivity-%s/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -PBUILD_DIR=%s -PSRC_DIR=%s --stacktrace' %(target_os, TARGET_ARCH, RELEASE, SECURED, env.get('BUILD_DIR'), env.get('SRC_DIR')), emitter = ensure_libs)
 jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
-cmdBuildApi=jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
+cmdBuildApi=jdk_env.Gradle(target="base/objs", source="common/src/main/java/org/iotivity/base/OcResource.java")
 
-jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED))
-cmdBuildExamples=jdk_env.Gradle(target="../examples/devicediscoveryclient/apk", source="../examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java")
+examples_target = "java"
+if target_os == 'android':
+       examples_target = "android"
 
-# android examples require android api to be built before being invoked
-Depends(cmdBuildExamples, cmdBuildApi)
+jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'java/examples-%s/build.gradle -PTARGET_OS=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s --stacktrace' % (examples_target, target_os, TARGET_ARCH, RELEASE, SECURED))
+cmdBuildExamples=jdk_env.Gradle(target="examples-%s/simpleclient/jar" % (examples_target, ), source="examples-%s/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java" % (examples_target, ))
 
+Depends(cmdBuildExamples, cmdBuildApi)