Convert more of libRS* to Android.bp

See build/soong/README.md for more information.

This reapplies If935ce5cc04da7801210acb49f0a9ed15fcf5889 with the
support modules disabled for unbundled builds to avoid conflicts
with the prebuilts in prebuilts/sdk/renderscript.

Also moves OVERRIDE_RS_DRIVER to be set for libRS_internal.

Test: m -j checkbuild
Change-Id: Ia98501a471ef5f090446c9fbe2dd1d3422021a6f
diff --git a/Android.bp b/Android.bp
index 15efc6d..4d05b23 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,20 +1,11 @@
-subdirs = ["cpp"]
-
 cc_library_headers {
     name: "rs-headers",
     export_include_dirs: ["."],
     sdk_version: "9",
 }
 
-cc_library_shared {
-    name: "libRS",
-
-    srcs: [
-        "rsApiStubs.cpp",
-        "rsHidlAdaptation.cpp",
-        "rsFallbackAdaptation.cpp",
-    ],
-
+cc_defaults {
+    name: "rs_defaults",
     cflags: [
         "-Werror",
         "-Wall",
@@ -22,6 +13,207 @@
         "-Wno-unused-parameter",
         "-Wno-unused-variable",
     ],
+}
+
+cc_library_shared {
+    name: "libRSDriver",
+    defaults: ["rs_defaults"],
+
+    srcs: [
+        "driver/rsdAllocation.cpp",
+        "driver/rsdBcc.cpp",
+        "driver/rsdCore.cpp",
+        "driver/rsdElement.cpp",
+        "driver/rsdFrameBuffer.cpp",
+        "driver/rsdFrameBufferObj.cpp",
+        "driver/rsdGL.cpp",
+        "driver/rsdMesh.cpp",
+        "driver/rsdMeshObj.cpp",
+        "driver/rsdProgram.cpp",
+        "driver/rsdProgramRaster.cpp",
+        "driver/rsdProgramStore.cpp",
+        "driver/rsdRuntimeStubs.cpp",
+        "driver/rsdSampler.cpp",
+        "driver/rsdScriptGroup.cpp",
+        "driver/rsdShader.cpp",
+        "driver/rsdShaderCache.cpp",
+        "driver/rsdType.cpp",
+        "driver/rsdVertexArray.cpp",
+    ],
+
+    shared_libs: [
+        "libRS_internal",
+        "libRSCpuRef",
+
+        "liblog",
+        "libEGL",
+        "libGLESv1_CM",
+        "libGLESv2",
+
+        "libnativewindow",
+
+        "libbcinfo",
+    ],
+}
+
+// Build rsg-generator ====================
+
+cc_binary_host {
+    name: "rsg-generator",
+
+    srcs: [
+        "spec.l",
+        "rsg_generator.c",
+    ],
+
+    stl: "none",
+    sanitize: {
+        never: true,
+    },
+}
+
+// Generate custom headers
+gensrcs {
+    name: "rs_generated_headers",
+    tools: ["rsg-generator"],
+    tool_files: [
+        "rs.spec",
+        "rsg.spec",
+    ],
+    cmd: "cat $(location rs.spec) $(location rsg.spec) | $(location rsg-generator) $(in) $(out)",
+    output_extension: "h",
+    srcs: [
+        "rsgApiStructs.h_rsg",
+        "rsgApiFuncDecl.h_rsg",
+    ],
+    export_include_dirs: ["."],
+}
+
+gensrcs {
+    name: "rs_generated_sources",
+    tools: ["rsg-generator"],
+    tool_files: [
+        "rs.spec",
+        "rsg.spec",
+    ],
+    cmd: "cat $(location rs.spec) $(location rsg.spec) | $(location rsg-generator) $(in) $(out)",
+    output_extension: "cpp",
+    srcs: [
+        "rsgApi.cpp_rsg",
+        "rsgApiReplay.cpp_rsg",
+    ],
+}
+
+cc_library_shared {
+    name: "libRS_internal",
+    defaults: ["rs_defaults"],
+
+    srcs: [
+        "rsApiAllocation.cpp",
+        "rsApiContext.cpp",
+        "rsApiDevice.cpp",
+        "rsApiElement.cpp",
+        "rsApiFileA3D.cpp",
+        "rsApiMesh.cpp",
+        "rsApiType.cpp",
+        "rsAllocation.cpp",
+        "rsAnimation.cpp",
+        "rsComponent.cpp",
+        "rsContext.cpp",
+        "rsClosure.cpp",
+        "rsCppUtils.cpp",
+        "rsDevice.cpp",
+        "rsDriverLoader.cpp",
+        "rsElement.cpp",
+        "rsFBOCache.cpp",
+        "rsFifoSocket.cpp",
+        "rsFileA3D.cpp",
+        "rsFont.cpp",
+        "rsGrallocConsumer.cpp",
+        "rsObjectBase.cpp",
+        "rsMatrix2x2.cpp",
+        "rsMatrix3x3.cpp",
+        "rsMatrix4x4.cpp",
+        "rsMesh.cpp",
+        "rsMutex.cpp",
+        "rsProgram.cpp",
+        "rsProgramFragment.cpp",
+        "rsProgramStore.cpp",
+        "rsProgramRaster.cpp",
+        "rsProgramVertex.cpp",
+        "rsSampler.cpp",
+        "rsScript.cpp",
+        "rsScriptC.cpp",
+        "rsScriptC_Lib.cpp",
+        "rsScriptC_LibGL.cpp",
+        "rsScriptGroup.cpp",
+        "rsScriptGroup2.cpp",
+        "rsScriptIntrinsic.cpp",
+        "rsSignal.cpp",
+        "rsStream.cpp",
+        "rsThreadIO.cpp",
+        "rsType.cpp",
+    ],
+
+    generated_sources: ["rs_generated_sources"],
+    generated_headers: ["rs_generated_headers"],
+
+    shared_libs: [
+        "liblog",
+        "libutils",
+        "libEGL",
+        "libGLESv1_CM",
+        "libGLESv2",
+
+        "libdl",
+        "libnativewindow",
+
+        "libft2",
+
+        "libbcinfo",
+        "libmediandk",
+    ],
+
+    // These runtime modules, including libcompiler_rt.so, are required for
+    // RenderScript.
+    required: [
+        "libclcore.bc",
+        "libclcore_debug.bc",
+        "libclcore_g.bc",
+        "libcompiler_rt",
+    ],
+
+    arch: {
+        x86: {
+            required: ["libclcore_x86.bc"],
+        },
+        x86_64: {
+            required: ["libclcore_x86.bc"],
+        },
+
+        arm: {
+            neon: {
+                required: ["libclcore_neon.bc"],
+            },
+        },
+    },
+
+    product_variables: {
+        override_rs_driver: {
+            cflags: ["-DOVERRIDE_RS_DRIVER=%s"],
+        },
+    },
+}
+
+cc_library_shared {
+    name: "libRS",
+    defaults: ["rs_defaults"],
+
+    srcs: [
+        "rsApiStubs.cpp",
+        "rsHidlAdaptation.cpp",
+        "rsFallbackAdaptation.cpp",
+    ],
 
     // Default CPU fallback
     required: [
@@ -45,10 +237,14 @@
     static_libs: ["libRSDispatch"],
 
     version_script: "libRS.map",
-
-    product_variables: {
-        override_rs_driver: {
-            cflags: ["-DOVERRIDE_RS_DRIVER=%s"],
-        },
-    },
 }
+
+build = [
+    "support.bp",
+]
+
+subdirs = [
+    "cpp",
+    "cpu_ref",
+    "support",
+]