Link all internal libraries statically into oatdump(d) on host.

Avoid all DSO dependencies except system libs, similar to dex2oat and
hiddenapi binaries, to make it work when added to
art-module-host-exports.

The stripped oatdump binary is 12 MB, oatdumpd is 15 MB.

Test: `m oatdump{,d}` and run them from out/host/linux-x86/bin
Test: readelf -d out/host/linux-x86/bin/oatdump(d)
  Check that NEEDED only lists system libraries (libdl, libpthread,
  libm, librt, libgcc_s, libc).
Bug: 145934348
Change-Id: Ib20ce3382435b76058b88b9085e3c0831848a489
diff --git a/oatdump/Android.bp b/oatdump/Android.bp
index 545d676..87f3a69 100644
--- a/oatdump/Android.bp
+++ b/oatdump/Android.bp
@@ -24,41 +24,105 @@
     ],
 }
 
+// Collect all the static defaults and build a host-only static library, which
+// is then used for the (mostly) static host oatdump binary.
+art_cc_library_static {
+    name: "liboatdump_static",
+    device_supported: false,
+    host_supported: true,
+    defaults: [
+        "libart-compiler_static_defaults",
+        "libart-dexlayout_static_defaults",
+        "libart-disassembler_static_defaults",
+        "libart_static_defaults",
+        "libartbase_static_defaults",
+        "libdexfile_static_defaults",
+        "libprofile_static_defaults",
+        "oatdump-defaults",
+    ],
+    whole_static_libs: [
+        "libbase",
+    ],
+}
+
 art_cc_binary {
     name: "oatdump",
     defaults: ["oatdump-defaults"],
-    shared_libs: [
-        "libart",
-        "libart-compiler",
-        "libart-dexlayout",
-        "libart-disassembler",
-        "libdexfile",
-        "libartbase",
-        "libprofile",
-        "libbase",
-    ],
+
+    target: {
+        android: {
+            shared_libs: [
+                "libart",
+                "libart-compiler",
+                "libart-dexlayout",
+                "libart-disassembler",
+                "libartbase",
+                "libbase",
+                "libdexfile",
+                "libprofile",
+            ],
+        },
+        host: {
+            // Make the host binary static, except for system libraries.
+            static_libs: ["liboatdump_static"],
+            stl: "c++_static",
+        },
+    },
+
     apex_available: [
         "com.android.art.release",
         "com.android.art.debug",
     ],
 }
 
+// Collect all the static defaults and build a host-only static library, which
+// is then used for the (mostly) static host oatdump binary.
+art_cc_library_static {
+    name: "liboatdumpd_static",
+    device_supported: false,
+    host_supported: true,
+    defaults: [
+        "libartd-compiler_static_defaults",
+        "libartd-dexlayout_static_defaults",
+        "libartd-disassembler_static_defaults",
+        "libartd_static_defaults",
+        "libartbased_static_defaults",
+        "libdexfiled_static_defaults",
+        "libprofiled_static_defaults",
+        "oatdump-defaults",
+    ],
+    whole_static_libs: [
+        "libbase",
+    ],
+}
+
 art_cc_binary {
     name: "oatdumpd",
     defaults: [
         "art_debug_defaults",
         "oatdump-defaults",
     ],
-    shared_libs: [
-        "libartd",
-        "libartd-compiler",
-        "libartd-dexlayout",
-        "libartd-disassembler",
-        "libdexfiled",
-        "libartbased",
-        "libprofiled",
-        "libbase",
-    ],
+
+    target: {
+        android: {
+            shared_libs: [
+                "libartbased",
+                "libartd",
+                "libartd-compiler",
+                "libartd-dexlayout",
+                "libartd-disassembler",
+                "libbase",
+                "libdexfiled",
+                "libprofiled",
+            ],
+        },
+        host: {
+            // Make the host binary static, except for system libraries.
+            static_libs: ["liboatdumpd_static"],
+            stl: "c++_static",
+        },
+    },
+
     apex_available: [
         "com.android.art.debug",
     ],