Cleanup makefiles and warning producing code.

Many entries in our makefiles are not needed:
- LOCAL_CPPFLAGS += -fno-exceptions is the default
- LOCAL_MODULE_TARGET_ARCH_WARN is obsolete
- LOCAL_CXX_STL:= libc++ is the default
- LOCAL_MODULE_TAGS := optional is the default
- LOCAL_IS_HOST_MODULE := true is the default if we're using
    $include(BUILD_HOST_*).  This can't be removed for the generated
    subdirectories however without triggering a bug in Ninja.
- Removed the -ldl where not needed.
- LOCAL_CLANG is no longer needed.

Added -Werror -Wall -Wextra to a lot of targets and cleaned up
the code that created errors.

Removed some hacky code that would prevent tests/java_api from
being compiled except under special cicumstances.

Corrected some LOCAL_MODULE_TAGS that should have been set to tests.
Cleanup warning producing code.

Bug: 34265954
Test: Compiled the code.
Test: Ran the cpp test, imageprocessing_jb, and cts
Change-Id: I27da19b18a6c0ac3686bb8c93681e3d870d587fe
diff --git a/Android.mk b/Android.mk
index df2f248..cfa1244 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,7 +22,9 @@
     host_cross_bcc_compat
 endif
 
-rs_base_CFLAGS := -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -fno-exceptions -std=c++11
+rs_base_CFLAGS := -Werror -Wall -Wextra \
+	-Wno-unused-parameter -Wno-unused-variable \
+	-std=c++11
 
 ifneq ($(OVERRIDE_RS_DRIVER),)
   rs_base_CFLAGS += -DOVERRIDE_RS_DRIVER=$(OVERRIDE_RS_DRIVER)
@@ -37,9 +39,7 @@
 endif
 
 include $(CLEAR_VARS)
-LOCAL_CLANG := true
 LOCAL_MODULE := libRSDriver
-LOCAL_MODULE_TARGET_ARCH_WARN := arm mips mips64 x86 x86_64 arm64
 
 LOCAL_SRC_FILES:= \
 	driver/rsdAllocation.cpp \
@@ -71,12 +71,7 @@
 
 LOCAL_C_INCLUDES += frameworks/compile/libbcc/include
 
-LOCAL_CXX_STL := libc++
-
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
-LOCAL_CPPFLAGS += -fno-exceptions
-
-LOCAL_MODULE_TAGS := optional
 
 include $(BUILD_SHARED_LIBRARY)
 
@@ -101,13 +96,10 @@
 
 include $(BUILD_HOST_EXECUTABLE)
 
-# TODO: This should go into build/core/config.mk
 RSG_GENERATOR:=$(LOCAL_BUILT_MODULE)
 
 include $(CLEAR_VARS)
-LOCAL_CLANG := true
 LOCAL_MODULE := libRS_internal
-LOCAL_MODULE_TARGET_ARCH_WARN := arm mips mips64 x86 x86_64 arm64
 
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 generated_sources:= $(local-generated-sources-dir)
@@ -191,23 +183,12 @@
 
 LOCAL_SHARED_LIBRARIES += libbcinfo
 
-LOCAL_C_INCLUDES += external/freetype/include
-LOCAL_C_INCLUDES += frameworks/compile/libbcc/include
-
-LOCAL_CXX_STL := libc++
-
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
 
-LOCAL_CPPFLAGS += -fno-exceptions
-
-LOCAL_MODULE_TAGS := optional
-
 include $(BUILD_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
-LOCAL_CLANG := true
 LOCAL_MODULE := libRS
-LOCAL_MODULE_TARGET_ARCH_WARN := arm mips mips64 x86 x86_64 arm64
 
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 generated_sources:= $(local-generated-sources-dir)
@@ -260,12 +241,8 @@
 
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
 
-LOCAL_CPPFLAGS += -fno-exceptions
-
 LOCAL_LDFLAGS += -Wl,--version-script,${LOCAL_PATH}/libRS.map
 
-LOCAL_MODULE_TAGS := optional
-
 # These runtime modules, including libcompiler_rt.so, are required for
 # RenderScript.
 LOCAL_REQUIRED_MODULES := \
@@ -286,7 +263,6 @@
 # Now build a host version for serialization
 include $(CLEAR_VARS)
 LOCAL_MODULE:= libRS
-LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 LOCAL_IS_HOST_MODULE := true
 
@@ -325,7 +301,6 @@
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
 LOCAL_CFLAGS += -DANDROID_RS_SERIALIZE
 LOCAL_CFLAGS += -fPIC
-LOCAL_CPPFLAGS += -fno-exceptions
 
 LOCAL_SRC_FILES:= \
 	rsAllocation.cpp \
@@ -366,8 +341,6 @@
 
 LOCAL_STATIC_LIBRARIES := libcutils libutils liblog
 
-LOCAL_CLANG := true
-
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/cpp/Android.mk b/cpp/Android.mk
index 8ba7170..102f973 100644
--- a/cpp/Android.mk
+++ b/cpp/Android.mk
@@ -15,12 +15,13 @@
 
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 include frameworks/compile/slang/rs_version.mk
-local_cflags_for_rs_cpp += $(RS_VERSION_DEFINE)
-local_cflags_for_rs_cpp += -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable -fno-exceptions -std=c++11
+local_cflags_for_rs_cpp += $(RS_VERSION_DEFINE) \
+	-Werror -Wall -Wextra \
+	-Wno-unused-parameter -Wno-unused-variable
+	-std=c++11
 
 LOCAL_SRC_FILES := $(rs_cpp_SRC_FILES)
 
-LOCAL_CLANG := true
 LOCAL_CFLAGS += $(local_cflags_for_rs_cpp)
 
 LOCAL_SHARED_LIBRARIES := \
@@ -36,8 +37,6 @@
 
 LOCAL_MODULE:= libRScpp
 
-LOCAL_MODULE_TAGS := optional
-
 LOCAL_C_INCLUDES += frameworks/rs
 LOCAL_C_INCLUDES += $(intermediates)
 
@@ -52,7 +51,6 @@
 include $(CLEAR_VARS)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
-LOCAL_CLANG := true
 LOCAL_CFLAGS += $(local_cflags_for_rs_cpp)
 
 ifeq ($(my_32_64_bit_suffix),32)
@@ -71,8 +69,6 @@
 
 LOCAL_MODULE:= libRScpp_static
 
-LOCAL_MODULE_TAGS := optional
-
 LOCAL_C_INCLUDES += frameworks/rs
 LOCAL_C_INCLUDES += $(intermediates)
 
diff --git a/cpu_ref/Android.mk b/cpu_ref/Android.mk
index 465ab32..ed72ad2 100644
--- a/cpu_ref/Android.mk
+++ b/cpu_ref/Android.mk
@@ -1,7 +1,8 @@
 LOCAL_PATH:=$(call my-dir)
 
-rs_base_CFLAGS := -Werror -Wall -Wextra -Wno-unused-parameter \
-                  -Wno-unused-variable -fno-exceptions -std=c++11
+rs_base_CFLAGS := -Werror -Wall -Wextra \
+				  -Wno-unused-parameter -Wno-unused-variable \
+				  -std=c++11
 ifeq ($(TARGET_BUILD_PDK), true)
   rs_base_CFLAGS += -D__RS_PDK__
 endif
@@ -16,7 +17,6 @@
 
 include $(CLEAR_VARS)
 ifneq ($(HOST_OS),windows)
-LOCAL_CLANG := true
 endif
 LOCAL_MODULE := libRSCpuRef
 LOCAL_MODULE_TARGET_ARCH := arm mips mips64 x86 x86_64 arm64
@@ -97,6 +97,4 @@
 
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
 
-LOCAL_MODULE_TAGS := optional
-
 include $(BUILD_SHARED_LIBRARY)
diff --git a/driver/runtime/Android.mk b/driver/runtime/Android.mk
index 0f17f41..8d7e5bf 100755
--- a/driver/runtime/Android.mk
+++ b/driver/runtime/Android.mk
@@ -31,7 +31,8 @@
     rs_convert.c \
     rs_quaternion.c
 
-clcore_cflags := -Iframeworks/rs/cpu_ref -DRS_DECLARE_EXPIRED_APIS
+clcore_cflags := -Werror -Wall -Wextra \
+	         -Iframeworks/rs/cpu_ref -DRS_DECLARE_EXPIRED_APIS
 
 clcore_base_files_32 := \
     ll32/allocation.ll
diff --git a/driver/runtime/rs_allocation.c b/driver/runtime/rs_allocation.c
index fc60ea9..03cd943 100644
--- a/driver/runtime/rs_allocation.c
+++ b/driver/runtime/rs_allocation.c
@@ -37,16 +37,23 @@
         rsAllocationGetElement(rs_allocation a) {
     Allocation_t *alloc = (Allocation_t *)a.p;
     if (alloc == NULL) {
-        rs_element nullElem = {0};
+        rs_element nullElem = RS_NULL_OBJ;
         return nullElem;
     }
     Type_t *type = (Type_t *)alloc->mHal.state.type;
-    rs_element returnElem = {type->mHal.state.element};
-    rs_element rs_retval = {0};
+    rs_element returnElem = {
+        type->mHal.state.element
+#ifdef __LP64__
+        , 0, 0, 0
+#endif
+    };
+    rs_element rs_retval = RS_NULL_OBJ;
     rsSetObject(&rs_retval, returnElem);
     return rs_retval;
 }
 
+#if defined(RS_G_RUNTIME) || !defined(RS_DEBUG_RUNTIME)
+
 // TODO: this needs to be optimized, obviously
 static void local_memcpy(void* dst, const void* src, size_t size) {
     char* dst_c = (char*) dst;
@@ -55,6 +62,7 @@
         *dst_c++ = *src_c++;
     }
 }
+#endif
 
 #ifdef RS_DEBUG_RUNTIME
 #define ELEMENT_AT(T)                                                   \
@@ -101,7 +109,7 @@
         rsGetElementAt_##T(a, &tmp, x, y, z);                           \
         return tmp;                                                     \
     }
-#else
+#else  // NOT RS_DEBUG_RUNTIME
 
 uint8_t*
 rsOffset(rs_allocation a, uint32_t sizeOf, uint32_t x, uint32_t y,
@@ -191,7 +199,7 @@
 #define SET_ELEMENT_AT_TYPE_IMPL(T, typename) /* nothing */
 #define GET_ELEMENT_AT_TYPE_IMPL(T, typename) /* nothing */
 
-#else
+#else  //NOT RS_G_RUNTIME
 
 #define SET_ELEMENT_AT_TYPE_IMPL(T, typename)                                    \
     void                                                                \
@@ -494,7 +502,7 @@
 #undef VOP_DEF
 #undef VOP
 
-static const rs_element kInvalidElement = {0};
+static const rs_element kInvalidElement = RS_NULL_OBJ;
 
 extern rs_element __attribute__((overloadable)) rsCreateElement(
         int32_t dt, int32_t dk, bool isNormalized, uint32_t vecSize);
diff --git a/driver/runtime/rs_cl.c b/driver/runtime/rs_cl.c
index 1dcc23c..dd36783 100644
--- a/driver/runtime/rs_cl.c
+++ b/driver/runtime/rs_cl.c
@@ -1,6 +1,8 @@
 #include "rs_core.rsh"
 #include "rs_f16_util.h"
 
+#include <string.h>
+
 extern float2 __attribute__((overloadable)) convert_float2(int2 c);
 extern float3 __attribute__((overloadable)) convert_float3(int3 c);
 extern float4 __attribute__((overloadable)) convert_float4(int4 c);
@@ -297,37 +299,37 @@
     return r;                                   \
 }
 
-static const int iposinf = 0x7f800000;
-static const int ineginf = 0xff800000;
+static const unsigned int iposinf = 0x7f800000;
+static const unsigned int ineginf = 0xff800000;
 
-static const float posinf() {
+static float posinf() {
     float f = *((float*)&iposinf);
     return f;
 }
 
-static const float neginf() {
-    float f = *((float*)&ineginf);
-    return f;
+static unsigned int float_bits(float f) {
+    unsigned int result;
+    // Get the bits while following the strict aliasing rules.
+    memcpy(&result, &f, sizeof(f));
+    return result;
 }
 
 static bool isinf(float f) {
-    int i = *((int*)(void*)&f);
+    unsigned int i = float_bits(f);
     return (i == iposinf) || (i == ineginf);
 }
 
 static bool isnan(float f) {
-    int i = *((int*)(void*)&f);
+    unsigned int i = float_bits(f);
     return (((i & 0x7f800000) == 0x7f800000) && (i & 0x007fffff));
 }
 
 static bool isposzero(float f) {
-    int i = *((int*)(void*)&f);
-    return (i == 0x00000000);
+    return (float_bits(f) == 0x00000000);
 }
 
 static bool isnegzero(float f) {
-    int i = *((int*)(void*)&f);
-    return (i == 0x80000000);
+    return (float_bits(f) == 0x80000000);
 }
 
 static bool iszero(float f) {
diff --git a/driver/runtime/rs_element.c b/driver/runtime/rs_element.c
index 55a6ec9..b32dfda 100644
--- a/driver/runtime/rs_element.c
+++ b/driver/runtime/rs_element.c
@@ -17,11 +17,19 @@
         rsElementGetSubElement(rs_element e, uint32_t index) {
     Element_t *element = (Element_t *)e.p;
     if (element == NULL || index >= element->mHal.state.fieldsCount) {
-        rs_element nullElem = {0};
+        rs_element nullElem = RS_NULL_OBJ;
         return nullElem;
     }
-    rs_element returnElem = {element->mHal.state.fields[index]};
-    rs_element rs_retval = {0};
+    rs_element returnElem = {
+        element->mHal.state.fields[index]
+#ifdef __LP64__
+        // TODO(jeanluc) In 64 bits, rs_element has four fields.
+        // I'm not sure if we should initialize them to something else
+        // than 0.
+        , 0, 0, 0
+#endif
+    };
+    rs_element rs_retval = RS_NULL_OBJ;
     rsSetObject(&rs_retval, returnElem);
     return rs_retval;
 }
diff --git a/driver/runtime/rs_f16_math.c b/driver/runtime/rs_f16_math.c
index 2308381..991176d 100644
--- a/driver/runtime/rs_f16_math.c
+++ b/driver/runtime/rs_f16_math.c
@@ -115,7 +115,6 @@
 
 // Based on bionic/libm/upstream-freebsd/lib/msun/src/s_nextafterf.c
 extern half __attribute__((overloadable)) nextafter(half x, half y) {
-  volatile half t;
   short hx, hy, ix, iy;
 
   GET_HALF_WORD(hx, x);
diff --git a/driver/runtime/rs_mesh.c b/driver/runtime/rs_mesh.c
index f22beaf..db49cf0 100644
--- a/driver/runtime/rs_mesh.c
+++ b/driver/runtime/rs_mesh.c
@@ -29,11 +29,11 @@
         rsgMeshGetVertexAllocation(rs_mesh m, uint32_t index) {
     Mesh_t *mesh = (Mesh_t *)m.p;
     if (mesh == NULL || index >= mesh->mHal.state.vertexBuffersCount) {
-        rs_allocation nullAlloc = {0};
+        rs_allocation nullAlloc = RS_NULL_OBJ;
         return nullAlloc;
     }
     rs_allocation returnAlloc = {mesh->mHal.state.vertexBuffers[index]};
-    rs_allocation rs_retval = {0};
+    rs_allocation rs_retval = RS_NULL_OBJ;
     rsSetObject(&rs_retval, returnAlloc);
     return rs_retval;
 }
@@ -42,11 +42,11 @@
         rsgMeshGetIndexAllocation(rs_mesh m, uint32_t index) {
     Mesh_t *mesh = (Mesh_t *)m.p;
     if (mesh == NULL || index >= mesh->mHal.state.primitivesCount) {
-        rs_allocation nullAlloc = {0};
+        rs_allocation nullAlloc = RS_NULL_OBJ;
         return nullAlloc;
     }
     rs_allocation returnAlloc = {mesh->mHal.state.indexBuffers[index]};
-    rs_allocation rs_retval = {0};
+    rs_allocation rs_retval = RS_NULL_OBJ;
     rsSetObject(&rs_retval, returnAlloc);
     return rs_retval;
 }
@@ -61,4 +61,3 @@
 }
 
 #endif
-
diff --git a/driver/runtime/rs_sample.c b/driver/runtime/rs_sample.c
index 95620e3..10a3e09 100644
--- a/driver/runtime/rs_sample.c
+++ b/driver/runtime/rs_sample.c
@@ -423,8 +423,6 @@
                                rs_sampler_value wrapS,
                                float uv, uint32_t lod) {
 
-    const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[lod].mallocPtr;
-
     int32_t sourceW = alloc->mHal.drvState.lod[lod].dimX;
     float pixelUV = uv * (float)(sourceW);
     int32_t iPixel = floor(pixelUV);
@@ -469,8 +467,6 @@
                                rs_sampler_value wrapT,
                                float2 uv, uint32_t lod) {
 
-    const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[lod].mallocPtr;
-
     int sourceW = alloc->mHal.drvState.lod[lod].dimX;
     int sourceH = alloc->mHal.drvState.lod[lod].dimY;
 
diff --git a/driver/runtime/rs_structs.h b/driver/runtime/rs_structs.h
index 2d66190..5246f72 100644
--- a/driver/runtime/rs_structs.h
+++ b/driver/runtime/rs_structs.h
@@ -301,4 +301,12 @@
     } mHal;
 } Mesh_t;
 #endif //__LP64__
+
+// Null version of _RS_OBJECT_DECL defined in script_api/rs_object_types.spec
+#ifndef __LP64__
+#define RS_NULL_OBJ {0}
+#else
+#define RS_NULL_OBJ {0, 0, 0, 0}
+#endif //__LP64__
+
 #endif // _RS_CORE_H_
diff --git a/rs_hal.h b/rs_hal.h
index 7e07ddd..34c6eae 100644
--- a/rs_hal.h
+++ b/rs_hal.h
@@ -106,10 +106,15 @@
  * v2 = reserved for use by vendor drivers
  */
 
+// RS_BASE_OBJ must have the same layout as _RS_OBJECT_DECL defined in
+// script_api/rs_object_types.spec.
+// TODO(jeanluc) Look at unifying.
 #ifndef __LP64__
 #define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; } __attribute__((packed, aligned(4)))
+#define RS_BASE_NULL_OBJ {0}
 #else
 #define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; const void* r; const void* v1; const void* v2; }
+#define RS_BASE_NULL_OBJ {0, 0, 0, 0}
 #endif
 
 RS_BASE_OBJ(ObjectBase) rs_object_base;
diff --git a/rsov/compiler/Android.mk b/rsov/compiler/Android.mk
index 3e9eeb7..f1628d7 100644
--- a/rsov/compiler/Android.mk
+++ b/rsov/compiler/Android.mk
@@ -60,8 +60,6 @@
 LOCAL_MODULE := rs2spirv
 LOCAL_MODULE_CLASS := EXECUTABLES
 
-LOCAL_IS_HOST_MODULE := true
-
 LOCAL_SHARED_LIBRARIES += libLLVM libbcinfo libSPIRV
 
 # TODO: fix the remaining warnings
@@ -81,9 +79,9 @@
 endif
 
 include $(LLVM_ROOT_PATH)/llvm.mk
+include $(LLVM_HOST_BUILD_MK)
 include $(LLVM_GEN_INTRINSICS_MK)
 include $(LLVM_GEN_ATTRIBUTES_MK)
-include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_EXECUTABLE)
 
 endif # Don't build in unbundled branches
@@ -148,4 +146,3 @@
 #=====================================================================
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
-
diff --git a/rsov/driver/Android.mk b/rsov/driver/Android.mk
index de6f504..8f4a14f 100644
--- a/rsov/driver/Android.mk
+++ b/rsov/driver/Android.mk
@@ -47,7 +47,7 @@
 
 LOCAL_C_INCLUDES += \
 
-LOCAL_CFLAGS := -Werror -Wall -Wextra -fno-exceptions
+LOCAL_CFLAGS := -Werror -Wall -Wextra
 # TODO: remove warnings on unused variables and parameters
 LOCAL_CFLAGS += -Wno-unused-variable -Wno-unused-parameter
 
diff --git a/support/Android.mk b/support/Android.mk
index 8815a0a..543d797 100644
--- a/support/Android.mk
+++ b/support/Android.mk
@@ -21,8 +21,7 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_CFLAGS += -std=c++11
-
+LOCAL_CFLAGS := -Werror -Wall -Wextra -std=c++11
 LOCAL_MODULE := android-support-v8-renderscript
 LOCAL_SDK_VERSION := 23
 LOCAL_SRC_FILES := $(call all-java-files-under, java/src)
diff --git a/support/jni/Android.mk b/support/jni/Android.mk
index d6a800d..b17ae36 100644
--- a/support/jni/Android.mk
+++ b/support/jni/Android.mk
@@ -1,7 +1,6 @@
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
-LOCAL_CLANG := true
 LOCAL_SDK_VERSION := 14
 
 LOCAL_SRC_FILES:= \
@@ -14,11 +13,12 @@
 	frameworks/rs/cpp \
 	frameworks/rs/driver
 
-LOCAL_CFLAGS += -Wno-unused-parameter -Werror
-LOCAL_CFLAGS += -DRS_COMPATIBILITY_LIB -std=c++11
+LOCAL_CFLAGS += -Werror -Wall -Wextra \
+		-Wno-unused-parameter \
+		-DRS_COMPATIBILITY_LIB \
+		-std=c++11
 
 LOCAL_MODULE:= libRSSupportIO
-LOCAL_MODULE_TAGS := optional
 
 LOCAL_LDLIBS += -landroid
 LOCAL_LDFLAGS += -ldl -Wl,--exclude-libs,libc++_static.a
@@ -27,7 +27,6 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_CLANG := true
 LOCAL_SDK_VERSION := 9
 
 LOCAL_SRC_FILES:= \
@@ -44,10 +43,9 @@
 	frameworks/rs \
 	frameworks/rs/cpp
 
-LOCAL_CFLAGS += -Wno-unused-parameter -Werror -std=c++11
+LOCAL_CFLAGS += -Werror -Wall -Wextra -Wno-unused-parameter -std=c++11
 
 LOCAL_MODULE:= librsjni
-LOCAL_MODULE_TAGS := optional
 LOCAL_REQUIRED_MODULES := libRSSupport
 
 LOCAL_LDFLAGS += -ldl -llog -Wl,--exclude-libs,libc++_static.a
diff --git a/support/rs_support/Android.mk b/support/rs_support/Android.mk
index de8fae0..1aba947 100644
--- a/support/rs_support/Android.mk
+++ b/support/rs_support/Android.mk
@@ -1,7 +1,10 @@
 
 LOCAL_PATH:=frameworks/rs
-rs_base_CFLAGS := -Werror -Wall -Wno-unused-parameter -Wno-unused-variable \
-		  -Wno-overloaded-virtual -DRS_COMPATIBILITY_LIB -std=c++11
+rs_base_CFLAGS := -Werror -Wall -Wextra \
+		  -Wno-unused-parameter \
+		  -Wno-unused-variable \
+		  -Wno-overloaded-virtual -DRS_COMPATIBILITY_LIB \
+		  -std=c++11
 
 ifeq ($(ARCH_ARM_HAVE_NEON),true)
 rs_base_CFLAGS += -DARCH_ARM_HAVE_NEON
@@ -19,10 +22,8 @@
 # These symbols are normally defined by BUILD_XXX, but we need to define them
 # here so that local-intermediates-dir works.
 
-LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 intermediates := $(local-intermediates-dir)
-LOCAL_MODULE_TAGS := optional
 
 LOCAL_SRC_FILES:= \
     spec.l \
@@ -37,7 +38,6 @@
 RSG_GENERATOR_SUPPORT:=$(LOCAL_BUILT_MODULE)
 
 include $(CLEAR_VARS)
-LOCAL_CLANG := true
 LOCAL_MODULE := libRSSupport
 LOCAL_SDK_VERSION := 9
 
@@ -181,7 +181,6 @@
 LOCAL_CFLAGS += $(rs_base_CFLAGS) -DGEMMLOWP_USE_STLPORT
 
 LOCAL_MODULE:= libRSSupport
-LOCAL_MODULE_TAGS := optional
 
 # TODO: why isn't this picked up from the host GLOBAL_CFLAGS?
 LOCAL_CFLAGS += -D__STDC_FORMAT_MACROS
diff --git a/tests/cpp_api/common.mk b/tests/cpp_api/common.mk
index ae453d6..974aadb 100644
--- a/tests/cpp_api/common.mk
+++ b/tests/cpp_api/common.mk
@@ -1,7 +1,7 @@
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_CLANG := true
-LOCAL_CFLAGS := -std=c++11 -Werror
+LOCAL_CFLAGS += -std=c++11 -Werror -Wall -Wextra
+LOCAL_LDFLAGS +=  -llog
 
 intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
 LOCAL_C_INCLUDES += $(intermediates)
diff --git a/tests/cpp_api/cppallocation/Android.mk b/tests/cpp_api/cppallocation/Android.mk
index 36b0279..f2c75c8 100644
--- a/tests/cpp_api/cppallocation/Android.mk
+++ b/tests/cpp_api/cppallocation/Android.mk
@@ -13,7 +13,7 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
-LOCAL_LDFLAGS += -llog -ldl
+LOCAL_LDFLAGS += -llog
 
 include frameworks/rs/tests/cpp_api/common.mk
 include $(BUILD_EXECUTABLE)
diff --git a/tests/cpp_api/cppallocation/compute.cpp b/tests/cpp_api/cppallocation/compute.cpp
index eebb2c5..3a8a81b 100644
--- a/tests/cpp_api/cppallocation/compute.cpp
+++ b/tests/cpp_api/cppallocation/compute.cpp
@@ -19,7 +19,10 @@
 
     sp<RS> rs = new RS();
 
-    bool r = rs->init("/system/bin");
+    if (!rs->init("/system/bin")) {
+        printf("Could not initialize RenderScript\n");
+        return 1;
+    }
 
     sp<const Element> e = Element::U32(rs);
 
diff --git a/tests/cpp_api/cppbasic/Android.mk b/tests/cpp_api/cppbasic/Android.mk
index 56e952b..1c2a60b 100644
--- a/tests/cpp_api/cppbasic/Android.mk
+++ b/tests/cpp_api/cppbasic/Android.mk
@@ -13,7 +13,5 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
-LOCAL_LDFLAGS += -llog -ldl
-
 include frameworks/rs/tests/cpp_api/common.mk
 include $(BUILD_EXECUTABLE)
diff --git a/tests/cpp_api/cppf16/compute.cpp b/tests/cpp_api/cppf16/compute.cpp
index e4ca841..dd271cf 100644
--- a/tests/cpp_api/cppf16/compute.cpp
+++ b/tests/cpp_api/cppf16/compute.cpp
@@ -24,7 +24,10 @@
 {
     sp<RS> rs = new RS();
 
-    bool r = rs->init("/system/bin");
+    if (!rs->init("/system/bin")) {
+        printf("Could not initialize RenderScript\n");
+        return 1;
+    }
 
     // Test ability to create 1D, 2D and 3D allocations of f16 scalars and
     // vectors
diff --git a/tests/cpp_api/cppstrided/Android.mk b/tests/cpp_api/cppstrided/Android.mk
index fa7b398..f3d85e5 100644
--- a/tests/cpp_api/cppstrided/Android.mk
+++ b/tests/cpp_api/cppstrided/Android.mk
@@ -13,7 +13,5 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
-LOCAL_LDFLAGS += -llog -ldl
-
 include frameworks/rs/tests/cpp_api/common.mk
 include $(BUILD_EXECUTABLE)
diff --git a/tests/cpp_api/cppstrided/compute.cpp b/tests/cpp_api/cppstrided/compute.cpp
index 73606b7..11aaa12 100644
--- a/tests/cpp_api/cppstrided/compute.cpp
+++ b/tests/cpp_api/cppstrided/compute.cpp
@@ -20,7 +20,10 @@
 
     sp<RS> rs = new RS();
 
-    bool r = rs->init("/system/bin");
+    if (!rs->init("/system/bin")) {
+        printf("Could not initialize RenderScript\n");
+        return 1;
+    }
 
     sp<const Element> e = Element::U32(rs);
 
diff --git a/tests/cpp_api/latency/Android.mk b/tests/cpp_api/latency/Android.mk
index 9cbbd48..d1fd35d 100644
--- a/tests/cpp_api/latency/Android.mk
+++ b/tests/cpp_api/latency/Android.mk
@@ -13,7 +13,5 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
-LOCAL_LDFLAGS += -llog -ldl
-
 include frameworks/rs/tests/cpp_api/common.mk
 include $(BUILD_EXECUTABLE)
diff --git a/tests/cpp_api/latency/latency.cpp b/tests/cpp_api/latency/latency.cpp
index c4b0612..e945f82 100644
--- a/tests/cpp_api/latency/latency.cpp
+++ b/tests/cpp_api/latency/latency.cpp
@@ -54,7 +54,10 @@
     if (forceCpu) flags |= RS_INIT_LOW_LATENCY;
     if (synchronous) flags |= RS_INIT_SYNCHRONOUS;
 
-    bool r = rs->init("/system/bin", flags);
+    if (!rs->init("/system/bin", flags)) {
+        printf("Could not initialize RenderScript\n");
+        return 1;
+    }
 
     sp<const Element> e = Element::U32(rs);
 
diff --git a/tests/cpp_api/typecheck/Android.mk b/tests/cpp_api/typecheck/Android.mk
index fec5509..d3a15ed 100644
--- a/tests/cpp_api/typecheck/Android.mk
+++ b/tests/cpp_api/typecheck/Android.mk
@@ -13,7 +13,5 @@
 LOCAL_STATIC_LIBRARIES := \
 	libRScpp_static
 
-LOCAL_LDFLAGS += -llog -ldl
-
 include frameworks/rs/tests/cpp_api/common.mk
 include $(BUILD_EXECUTABLE)
diff --git a/tests/cpp_api/typecheck/typecheck.cpp b/tests/cpp_api/typecheck/typecheck.cpp
index 93ed93e..9a8412c 100644
--- a/tests/cpp_api/typecheck/typecheck.cpp
+++ b/tests/cpp_api/typecheck/typecheck.cpp
@@ -30,7 +30,10 @@
 bool test_elem_##KERNELNAME##_##ENAME() { \
     printf("Verifying forEach_test_" #KERNELNAME "() with " #ENAME "\n"); \
     sp<RS> rs = new RS(); \
-    bool r = rs->init("/system/bin"); \
+    if (!rs->init("/system/bin")) { \
+        printf("Could not initialize RenderScript\n"); \
+        return true; \
+    } \
     sp<Allocation> a = createAlloc(rs, Element::ENAME(rs)); \
     ScriptC_kernels sc(rs); \
     sc.forEach_test_##KERNELNAME(a); \
diff --git a/tests/java_api/Android.mk b/tests/java_api/Android.mk
index a040e34..dd92830 100644
--- a/tests/java_api/Android.mk
+++ b/tests/java_api/Android.mk
@@ -1,11 +1,5 @@
 LOCAL_PATH:=$(call my-dir)
 
-# Only build our tests if we doing a top-level build. Do not build the
-# tests if we are just doing an mm or mmm in frameworks/rs.
-ifeq (,$(ONE_SHOT_MAKEFILE))
-
 ifneq (true,$(TARGET_BUILD_PDK))
 include $(call all-makefiles-under,$(LOCAL_PATH))
 endif
-
-endif
diff --git a/tests/java_api/HelloComputeNDK/Android.mk b/tests/java_api/HelloComputeNDK/Android.mk
index 5f1bd17..d801861 100644
--- a/tests/java_api/HelloComputeNDK/Android.mk
+++ b/tests/java_api/HelloComputeNDK/Android.mk
@@ -24,6 +24,8 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
                    $(call all-renderscript-files-under, src)
 
+LOCAL_CFLAGS := -Werror -Wall -Wextra
+
 LOCAL_PACKAGE_NAME := HelloComputeNDK
 LOCAL_SDK_VERSION := 14
 
diff --git a/tests/java_api/HelloComputeNDK/libhellocomputendk/Android.mk b/tests/java_api/HelloComputeNDK/libhellocomputendk/Android.mk
index 9abe487..36c5896 100644
--- a/tests/java_api/HelloComputeNDK/libhellocomputendk/Android.mk
+++ b/tests/java_api/HelloComputeNDK/libhellocomputendk/Android.mk
@@ -18,10 +18,9 @@
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CLANG := true
 
 LOCAL_MODULE := libhellocomputendk
-LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := helloComputeNDK.cpp mono.rs
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/tests/java_api/RsBLAS_Benchmark/libsgemm/Android.mk b/tests/java_api/RsBLAS_Benchmark/libsgemm/Android.mk
index 9327869..15c568d 100644
--- a/tests/java_api/RsBLAS_Benchmark/libsgemm/Android.mk
+++ b/tests/java_api/RsBLAS_Benchmark/libsgemm/Android.mk
@@ -17,10 +17,9 @@
 #
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
-LOCAL_CLANG := true
 
 LOCAL_MODULE := libgemmdata
-LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := test_data.cpp
 LOCAL_SDK_VERSION := 14
 
diff --git a/tests/lldb/cpp/common.mk b/tests/lldb/cpp/common.mk
index 1a05b92..3b65741 100644
--- a/tests/lldb/cpp/common.mk
+++ b/tests/lldb/cpp/common.mk
@@ -1,11 +1,8 @@
 LOCAL_MODULE_TAGS := tests
 
 LOCAL_RENDERSCRIPT_FLAGS += -g -O0 -target-api 0
-
-LOCAL_CFLAGS += --std=c++11
-LOCAL_LDFLAGS += \
-	-ldl \
-	-llog
+LOCAL_CFLAGS := -Werror -Wall -Wextra -std=c++11
+LOCAL_LDFLAGS += -llog
 
 LOCAL_STATIC_LIBRARIES += libRScpp_static
 
diff --git a/tests/lldb/jni/common.mk b/tests/lldb/jni/common.mk
index 987ab98..269f1d9 100644
--- a/tests/lldb/jni/common.mk
+++ b/tests/lldb/jni/common.mk
@@ -4,7 +4,7 @@
 
 LOCAL_CPP_FEATURES += exceptions
 
-LOCAL_CFLAGS += --std=c++11
+LOCAL_CFLAGS := -Werror -Wall -Wextra -std=c++11
 LOCAL_RENDERSCRIPT_FLAGS += -O0 -target-api 0
 
 LOCAL_SHARED_LIBRARIES += libdl liblog