Convert spirv-llvm to Android.bp

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

Reapplies Ie5b29b3898cebc3ca3b25d2f207069d9f3cb6f71 with -fno-rtti
-fno-exceptions for host builds.

Test: mma -j
Test: mma -j FORCE_BUILD_LLVM_COMPONENTS=true
Change-Id: I7245f937ebc7753a45444c1c734a3ca7a2fc083e
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..7866be1
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,4 @@
+subdirs = [
+    "lib/SPIRV",
+    "tools/llvm-spirv",
+]
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 933e54f..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-#=====================================================================
-# Include Subdirectories
-#=====================================================================
-
-LOCAL_PATH:=$(call my-dir)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
diff --git a/lib/Android.mk b/lib/Android.mk
deleted file mode 100644
index 933e54f..0000000
--- a/lib/Android.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-#=====================================================================
-# Include Subdirectories
-#=====================================================================
-
-LOCAL_PATH:=$(call my-dir)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
diff --git a/lib/SPIRV/Android.bp b/lib/SPIRV/Android.bp
new file mode 100644
index 0000000..7936dab
--- /dev/null
+++ b/lib/SPIRV/Android.bp
@@ -0,0 +1,110 @@
+//
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+//=====================================================================
+// Shared Library libSPIRV
+//=====================================================================
+
+cc_library_shared {
+    name: "libSPIRV",
+    host_supported: true,
+
+    srcs: [
+        "libSPIRV/SPIRVBasicBlock.cpp",
+        "libSPIRV/SPIRVDebug.cpp",
+        "libSPIRV/SPIRVDecorate.cpp",
+        "libSPIRV/SPIRVEntry.cpp",
+        "libSPIRV/SPIRVFunction.cpp",
+        "libSPIRV/SPIRVInstruction.cpp",
+        "libSPIRV/SPIRVModule.cpp",
+        "libSPIRV/SPIRVStream.cpp",
+        "libSPIRV/SPIRVType.cpp",
+        "libSPIRV/SPIRVValue.cpp",
+        "Mangler/FunctionDescriptor.cpp",
+        "Mangler/Mangler.cpp",
+        "Mangler/ManglingUtils.cpp",
+        "Mangler/ParameterType.cpp",
+        "OCL20To12.cpp",
+        "OCL20ToSPIRV.cpp",
+        "OCL21ToSPIRV.cpp",
+        "OCLTypeToSPIRV.cpp",
+        "OCLUtil.cpp",
+        "SPIRVLowerBool.cpp",
+        "SPIRVLowerConstExpr.cpp",
+        "SPIRVLowerOCLBlocks.cpp",
+        "SPIRVReader.cpp",
+        "SPIRVRegularizeLLVM.cpp",
+        "SPIRVToOCL20.cpp",
+        "SPIRVUtil.cpp",
+        "SPIRVWriter.cpp",
+        "SPIRVWriterPass.cpp",
+        "TransOCLMD.cpp",
+    ],
+
+    export_include_dirs: [
+        ".",
+        "libSPIRV",
+        "Mangler",
+    ],
+
+    header_libs: ["llvm-headers"],
+
+    compile_multilib: "first",
+
+    target: {
+        android: {
+            cflags: ["-Wno-error=non-virtual-dtor"],
+        },
+        host: {
+            cflags: [
+                "-fno-rtti",
+                "-fno-exceptions",
+            ],
+        },
+        linux: {
+            host_ldlibs: [
+                "-lrt",
+                "-ldl",
+                "-lpthread",
+            ],
+        },
+        darwin: {
+            host_ldlibs: [
+                "-ldl",
+                "-lpthread",
+            ],
+        },
+    },
+
+    shared_libs: ["libLLVM"],
+
+    cflags: [
+        "-D_SPIRV_LLVM_API",
+        "-D__STDC_LIMIT_MACROS",
+        "-D__STDC_CONSTANT_MACROS",
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+
+    product_variables: {
+        unbundled_build: {
+            // Don't build for unbundled branches
+            enabled: false,
+        },
+    },
+}
diff --git a/lib/SPIRV/Android.mk b/lib/SPIRV/Android.mk
deleted file mode 100644
index 65b7437..0000000
--- a/lib/SPIRV/Android.mk
+++ /dev/null
@@ -1,158 +0,0 @@
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-LIBSPIRV_ROOT_PATH := $(LOCAL_PATH)
-LLVM_ROOT := external/llvm
-
-FORCE_BUILD_LLVM_DISABLE_NDEBUG ?= false
-# Legality check: FORCE_BUILD_LLVM_DISABLE_NDEBUG should consist of
-# one word -- either "true" or "false".
-ifneq "$(words $(FORCE_BUILD_LLVM_DISABLE_NDEBUG))$(words $(filter-out true \
- false,$(FORCE_BUILD_LLVM_DISABLE_NDEBUG)))" "10"
-  $(error FORCE_BUILD_LLVM_DISABLE_NDEBUG may only be true, false, or unset)
-endif
-
-FORCE_BUILD_LLVM_DEBUG ?= false
-# Legality check: FORCE_BUILD_LLVM_DEBUG should consist of
-# one word -- either "true" or "false".
-ifneq "$(words $(FORCE_BUILD_LLVM_DEBUG))$(words $(filter-out true \
- false,$(FORCE_BUILD_LLVM_DEBUG)))" "10"
-  $(error FORCE_BUILD_LLVM_DEBUG may only be true, false, or unset)
-endif
-
-SPIRV_SOURCES:= \
-  libSPIRV/SPIRVBasicBlock.cpp \
-  libSPIRV/SPIRVDebug.cpp \
-  libSPIRV/SPIRVDecorate.cpp \
-  libSPIRV/SPIRVEntry.cpp \
-  libSPIRV/SPIRVFunction.cpp \
-  libSPIRV/SPIRVInstruction.cpp \
-  libSPIRV/SPIRVModule.cpp \
-  libSPIRV/SPIRVStream.cpp \
-  libSPIRV/SPIRVType.cpp \
-  libSPIRV/SPIRVValue.cpp \
-  Mangler/FunctionDescriptor.cpp \
-  Mangler/Mangler.cpp \
-  Mangler/ManglingUtils.cpp \
-  Mangler/ParameterType.cpp \
-  OCL20To12.cpp \
-  OCL20ToSPIRV.cpp \
-  OCL21ToSPIRV.cpp \
-  OCLTypeToSPIRV.cpp \
-  OCLUtil.cpp \
-  SPIRVLowerBool.cpp \
-  SPIRVLowerConstExpr.cpp \
-  SPIRVLowerOCLBlocks.cpp \
-  SPIRVReader.cpp \
-  SPIRVRegularizeLLVM.cpp \
-  SPIRVToOCL20.cpp \
-  SPIRVUtil.cpp \
-  SPIRVWriter.cpp \
-  SPIRVWriterPass.cpp \
-  TransOCLMD.cpp
-
-#=====================================================================
-# Host Shared Library libSPIRV
-#=====================================================================
-
-# Don't build for unbundled branches
-ifeq (,$(TARGET_BUILD_APPS))
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-  $(SPIRV_SOURCES)
-
-LOCAL_C_INCLUDES := \
-  $(LIBSPIRV_ROOT_PATH)/Mangler \
-  $(LIBSPIRV_ROOT_PATH)/libSPIRV \
-  $(LLVM_ROOT)/include \
-  $(LLVM_ROOT)/host/include
-
-LOCAL_MODULE := libSPIRV
-
-# TODO: test windows build
-
-LOCAL_MODULE_HOST_OS := linux darwin
-LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MULTILIB := first
-
-LOCAL_LDLIBS_linux := -lrt -ldl -ltinfo -lpthread
-LOCAL_LDLIBS_darwin := -ldl -lpthread
-
-LOCAL_SHARED_LIBRARIES += libLLVM
-
-LOCAL_CFLAGS += $(TOOL_CFLAGS) \
-  -D_SPIRV_LLVM_API \
-  -D__STDC_LIMIT_MACROS \
-  -Wno-error=pessimizing-move \
-  -Wno-error=unused-variable \
-  -Wno-error=unused-private-field \
-  -Wno-error=unused-function \
-  -Wno-error=dangling-else \
-  -Wno-error=ignored-qualifiers
-
-include $(LLVM_ROOT)/llvm.mk
-include $(LLVM_GEN_INTRINSICS_MK)
-include $(LLVM_GEN_ATTRIBUTES_MK)
-include $(LLVM_HOST_BUILD_MK)
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-endif # Don't build in unbundled branches
-
-#=====================================================================
-# Device Shared Library libSPIRV
-#=====================================================================
-ifneq (true,$(DISABLE_LLVM_DEVICE_BUILDS))
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libSPIRV
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-
-LOCAL_SHARED_LIBRARIES := libLLVM
-
-LOCAL_SRC_FILES := \
-  $(SPIRV_SOURCES)
-
-LOCAL_C_INCLUDES := \
-  $(LIBSPIRV_ROOT_PATH)/Mangler \
-  $(LIBSPIRV_ROOT_PATH)/libSPIRV
-
-LOCAL_CFLAGS += $(TOOL_CFLAGS) \
-  -D_SPIRV_LLVM_API \
-  -Wno-error=pessimizing-move \
-  -Wno-error=unused-variable \
-  -Wno-error=unused-private-field \
-  -Wno-error=unused-function \
-  -Wno-error=dangling-else \
-  -Wno-error=ignored-qualifiers \
-  -Wno-error=non-virtual-dtor
-
-include $(LLVM_GEN_INTRINSICS_MK)
-include $(LLVM_GEN_ATTRIBUTES_MK)
-include $(LLVM_DEVICE_BUILD_MK)
-include $(BUILD_SHARED_LIBRARY)
-endif
-
-#=====================================================================
-# Include Subdirectories
-#=====================================================================
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
diff --git a/tools/Android.mk b/tools/Android.mk
deleted file mode 100644
index 933e54f..0000000
--- a/tools/Android.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-#=====================================================================
-# Include Subdirectories
-#=====================================================================
-
-LOCAL_PATH:=$(call my-dir)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
diff --git a/tools/llvm-spirv/Android.bp b/tools/llvm-spirv/Android.bp
new file mode 100644
index 0000000..dec1bb6
--- /dev/null
+++ b/tools/llvm-spirv/Android.bp
@@ -0,0 +1,76 @@
+//
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//=====================================================================
+// Executable llvm-spirv
+//=====================================================================
+
+cc_binary {
+    name: "llvm-spirv",
+    host_supported: true,
+
+    srcs: ["llvm-spirv.cpp"],
+
+    target: {
+        linux: {
+            host_ldlibs: [
+                "-lrt",
+                "-ldl",
+                "-lpthread",
+            ],
+        },
+        darwin: {
+            host_ldlibs: [
+                "-ldl",
+                "-lpthread",
+            ],
+        },
+        android: {
+            cflags: [
+                "-DNDEBUG=1",
+            ],
+        },
+        host: {
+            cflags: [
+                "-fno-rtti",
+                "-fno-exceptions",
+            ],
+        },
+    },
+
+    shared_libs: [
+        "libLLVM",
+        "libSPIRV",
+    ],
+
+    header_libs: ["llvm-headers"],
+
+    cflags: [
+        "-D_SPIRV_LLVM_API",
+        "-D__STDC_LIMIT_MACROS",
+        "-D__STDC_CONSTANT_MACROS",
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+
+    product_variables: {
+        unbundled_build: {
+            // Don't build for unbundled branches
+            enabled: false,
+        },
+    },
+}
diff --git a/tools/llvm-spirv/Android.mk b/tools/llvm-spirv/Android.mk
deleted file mode 100644
index ec7f3b2..0000000
--- a/tools/llvm-spirv/Android.mk
+++ /dev/null
@@ -1,119 +0,0 @@
-#
-# Copyright (C) 2016 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-LLVM_SPIRV_ROOT_PATH := $(LOCAL_PATH)
-LLVM_ROOT := external/llvm
-
-LIBSPIRV_ROOT_PATH := $(LOCAL_PATH)/../../lib/SPIRV
-
-LLVM_SPIRV_SOURCES := \
-  llvm-spirv.cpp
-
-#=====================================================================
-# Host Executable llvm-spirv
-#=====================================================================
-
-# Don't build for unbundled branches
-ifeq (,$(TARGET_BUILD_APPS))
-
-include $(CLEAR_VARS)
-include $(CLEAR_TBLGEN_VARS)
-LLVM_ROOT_PATH := external/llvm
-
-LOCAL_SRC_FILES := \
-  $(LLVM_SPIRV_SOURCES)
-
-LOCAL_C_INCLUDES := \
-  $(LIBSPIRV_ROOT_PATH) \
-  $(LIBSPIRV_ROOT_PATH)/Mangler \
-  $(LIBSPIRV_ROOT_PATH)/libSPIRV \
-  $(LLVM_ROOT)/include \
-  $(LLVM_ROOT)/host/include
-
-LOCAL_MODULE := llvm-spirv
-LOCAL_MODULE_CLASS := EXECUTABLES
-
-# TODO: handle windows and darwin
-
-LOCAL_MODULE_HOST_OS := linux darwin
-LOCAL_IS_HOST_MODULE := true
-
-LOCAL_LDLIBS_linux := -lrt -ldl -ltinfo -lpthread
-LOCAL_LDLIBS_darwin := -ldl -lpthread
-
-LOCAL_SHARED_LIBRARIES += libLLVM libSPIRV
-
-LOCAL_CFLAGS += $(TOOL_CFLAGS) \
-  -D_SPIRV_LLVM_API \
-  -Wno-error=pessimizing-move \
-  -Wno-error=unused-variable \
-  -Wno-error=unused-private-field \
-  -Wno-error=unused-function \
-  -Wno-error=dangling-else \
-  -Wno-error=ignored-qualifiers
-
-include $(LLVM_ROOT)/llvm.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
-
-#=====================================================================
-# Device Executable llvm-spirv
-#=====================================================================
-ifneq (true,$(DISABLE_LLVM_DEVICE_BUILDS)))
-
-include $(CLEAR_VARS)
-include $(CLEAR_TBLGEN_VARS)
-LLVM_ROOT_PATH := external/llvm
-
-LOCAL_SRC_FILES := \
-  $(LLVM_SPIRV_SOURCES)
-
-LOCAL_C_INCLUDES := \
-  $(LIBSPIRV_ROOT_PATH) \
-  $(LIBSPIRV_ROOT_PATH)/Mangler \
-  $(LIBSPIRV_ROOT_PATH)/libSPIRV
-
-LOCAL_MODULE := llvm-spirv
-LOCAL_MODULE_CLASS := EXECUTABLES
-
-LOCAL_SHARED_LIBRARIES += libSPIRV libLLVM
-
-LOCAL_CFLAGS += $(TOOL_CFLAGS) \
-  -D_SPIRV_LLVM_API \
-  -DNDEBUG=1 \
-  -Wno-error=pessimizing-move \
-  -Wno-error=unused-variable \
-  -Wno-error=unused-private-field \
-  -Wno-error=unused-function \
-  -Wno-error=dangling-else \
-  -Wno-error=ignored-qualifiers
-
-include $(LLVM_GEN_INTRINSICS_MK)
-include $(LLVM_GEN_ATTRIBUTES_MK)
-include $(LLVM_DEVICE_BUILD_MK)
-include $(BUILD_EXECUTABLE)
-
-endif # Don't build in unbundled branches
-
-#=====================================================================
-# Include Subdirectories
-#=====================================================================
-include $(call all-makefiles-under,$(LOCAL_PATH))