Migrate from Android.mk to Android.bp

Change-Id: I0b04100ace8599c8734bee77f656aab04c06cce9
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..b611429
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,196 @@
+// Note that some host libraries have the same module name as the target
+// libraries. This is currently needed to build, for example, adb. But it's
+// probably something that should be changed.
+
+// Pull in the autogenerated sources modules
+build = ["sources.bp"]
+
+// Used by libcrypto, libssl, bssl tool, and native tests
+cc_defaults {
+    name: "boringssl_flags",
+
+    cflags: [
+        "-fvisibility=hidden",
+        "-DBORINGSSL_SHARED_LIBRARY",
+        "-DBORINGSSL_IMPLEMENTATION",
+        "-DOPENSSL_SMALL",
+        "-D_XOPEN_SOURCE=700",
+        "-Wno-unused-parameter",
+    ],
+
+    cppflags: [
+        "-Wall",
+        "-Werror",
+    ],
+
+    conlyflags: ["-std=c99"],
+}
+
+// Used by libcrypto + libssl
+cc_defaults {
+    name: "boringssl_defaults",
+
+    local_include_dirs: ["src/include"],
+    export_include_dirs: ["src/include"],
+    stl: "none",
+    sdk_version: "9",
+
+    cflags: ["-DBORINGSSL_ANDROID_SYSTEM"],
+}
+
+//// libcrypto
+
+cc_defaults {
+    name: "libcrypto_defaults",
+    host_supported: true,
+
+    // Windows and Macs both have problems with assembly files
+    target: {
+        windows: {
+            enabled: true,
+            cflags: ["-DOPENSSL_NO_ASM"],
+            host_ldlibs: ["-lws2_32"],
+        },
+        darwin: {
+            cflags: ["-DOPENSSL_NO_ASM"],
+        },
+        not_windows: {
+            host_ldlibs: ["-lpthread"],
+        },
+    },
+
+    local_include_dirs: ["src/crypto"],
+
+    // sha256-armv4.S does not compile with clang.
+    arch: {
+        arm: {
+            clang_asflags: ["-no-integrated-as"],
+        },
+        arm64: {
+            clang_asflags: ["-march=armv8-a+crypto"],
+        },
+    },
+}
+
+// Target and host library
+cc_library {
+    name: "libcrypto",
+    defaults: ["libcrypto_sources", "libcrypto_defaults", "boringssl_defaults", "boringssl_flags"],
+
+    // Shared host library is disabled until all users use libcrypto instead of libcrypto-host
+    target: {
+        host: {
+            shared: {
+                enabled: false,
+            },
+        },
+    },
+}
+
+// Static library
+// This should only be used for host modules that will be in a JVM, all other
+// modules should use the static variant of libcrypto.
+cc_library_static {
+    name: "libcrypto_static",
+    defaults: ["libcrypto_sources", "libcrypto_defaults", "boringssl_defaults", "boringssl_flags"],
+
+    target: {
+        host: {
+            // TODO: b/26097626. ASAN breaks use of this library in JVM.
+            // Re-enable sanitization when the issue with making clients of this library
+            // preload ASAN runtime is resolved. Without that, clients are getting runtime
+            // errors due to unresoled ASAN symbols, such as
+            // __asan_option_detect_stack_use_after_return.
+            sanitize: {
+                never: true,
+            },
+        },
+    },
+}
+
+// Host shared library
+cc_library_host_shared {
+    name: "libcrypto-host",
+    defaults: ["libcrypto_sources", "libcrypto_defaults", "boringssl_defaults", "boringssl_flags"],
+}
+
+//// libssl
+
+// Target static library
+// Deprecated: all users should move to libssl
+cc_library_static {
+    name: "libssl_static",
+    defaults: ["libssl_sources", "boringssl_defaults", "boringssl_flags"],
+}
+
+// Static and Shared library
+cc_library {
+    name: "libssl",
+    host_supported: true,
+    defaults: ["libssl_sources", "boringssl_defaults", "boringssl_flags"],
+
+    // Shared host library is disabled until all users use libssl instead of libssl-host
+    target: {
+        android: {
+            shared_libs: ["libcrypto"],
+        },
+        host: {
+            shared_libs: ["libcrypto-host"],
+
+            shared: {
+                enabled: false,
+            },
+        },
+    },
+}
+
+// Host static library
+cc_library_host_static {
+    name: "libssl_static-host",
+    defaults: ["libssl_sources", "boringssl_defaults", "boringssl_flags"],
+
+    // TODO: b/26097626. ASAN breaks use of this library in JVM.
+    // Re-enable sanitization when the issue with making clients of this library
+    // preload ASAN runtime is resolved. Without that, clients are getting runtime
+    // errors due to unresoled ASAN symbols, such as
+    // __asan_option_detect_stack_use_after_return.
+    sanitize: {
+        never: true,
+    },
+}
+
+// Host shared library
+cc_library_host_shared {
+    name: "libssl-host",
+    defaults: ["libssl_sources", "boringssl_defaults", "boringssl_flags"],
+
+    shared_libs: ["libcrypto-host"],
+}
+
+// Tool
+cc_binary {
+    name: "bssl",
+    host_supported: true,
+    defaults: ["bssl_sources", "boringssl_flags"],
+
+    target: {
+        android: {
+            shared_libs: [
+                "libcrypto",
+                "libssl",
+            ],
+        },
+        host: {
+            shared_libs: [
+                "libcrypto-host",
+                "libssl-host",
+            ],
+
+            // Needed for clock_gettime.
+            host_ldlibs: ["-lrt"],
+        },
+        darwin: {
+            enabled: false,
+        },
+    },
+}