Convert to Android.bp

Converts the rest of the Host/Android rules from Android.mk to
Android.bp. See build/soong/README.md for more information.

Test: cd device/google/contexthub; mma
Change-Id: I7e29b58010ccf6f966afe94f5a11f79692700b4c
diff --git a/contexthubhal/test/Android.bp b/contexthubhal/test/Android.bp
new file mode 100644
index 0000000..9ab543c
--- /dev/null
+++ b/contexthubhal/test/Android.bp
@@ -0,0 +1,39 @@
+//
+// 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.
+//
+
+cc_test {
+    name: "nanohub_hal_test",
+    gtest: false,
+
+    srcs: ["main.cpp"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+        "-DHOST_BUILD",
+        "-DBOOTLOADER=",
+        "-DBOOTLOADER_RO=",
+    ],
+
+    static_libs: ["libnanohub_common"],
+
+    shared_libs: [
+        "libhardware",
+        "liblog",
+        "libcutils",
+    ],
+}
diff --git a/contexthubhal/test/Android.mk b/contexthubhal/test/Android.mk
deleted file mode 100644
index 44d2744..0000000
--- a/contexthubhal/test/Android.mk
+++ /dev/null
@@ -1,48 +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)
-
-include $(CLEAR_VARS)
-
-
-LOCAL_SRC_FILES := main.cpp \
-        ../../lib/nanohub/nanoapp.c \
-
-
-LOCAL_CFLAGS := \
-        -Wall \
-        -Werror \
-        -Wextra \
-        -DHOST_BUILD \
-        -DBOOTLOADER= \
-        -DBOOTLOADER_RO= \
-
-
-LOCAL_C_INCLUDES := \
-        device/google/contexthub/lib/include \
-        hardware/libhardware/include \
-
-LOCAL_SHARED_LIBRARIES := \
-        libhardware \
-        liblog \
-        libcutils \
-
-LOCAL_MODULE := nanohub_hal_test
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_EXECUTABLE)
diff --git a/lib/Android.bp b/lib/Android.bp
index 828d29e..58b7126 100644
--- a/lib/Android.bp
+++ b/lib/Android.bp
@@ -1,5 +1,47 @@
+//
+// 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.
+//
+
 cc_library_headers {
     name: "libnanohub_common_headers",
     vendor_available: true,
     export_include_dirs: ["include"],
 }
+
+cc_library_static {
+    name: "libnanohub_common",
+    host_supported: true,
+
+    srcs: ["nanohub/nanoapp.c"],
+
+    export_include_dirs: ["include"],
+
+    target: {
+        host: {
+            cflags: [
+                "-DHOST_BUILD",
+                "-DRSA_SUPPORT_PRIV_OP_BIGRAM",
+            ],
+
+            srcs: [
+                "nanohub/aes.c",
+                "nanohub/rsa.c",
+                "nanohub/sha2.c",
+
+                "nanohub/softcrc.c",
+            ],
+        },
+    },
+}
diff --git a/lib/Android.mk b/lib/Android.mk
index 88707e1..c47b6af 100644
--- a/lib/Android.mk
+++ b/lib/Android.mk
@@ -46,29 +46,6 @@
 
 include $(BUILD_NANOHUB_OS_STATIC_LIBRARY)
 
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libnanohub_common
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := \
-    $(src_files) \
-    nanohub/softcrc.c \
-    nanohub/nanoapp.c \
-
-LOCAL_CFLAGS := \
-    -DHOST_BUILD \
-    -DRSA_SUPPORT_PRIV_OP_BIGRAM \
-
-LOCAL_C_INCLUDES := \
-    $(src_includes)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := \
-    $(src_includes)
-
-LOCAL_MULTILIB := both
-
-include $(BUILD_HOST_STATIC_LIBRARY)
-
 include $(call first-makefiles-under, $(LOCAL_PATH))
 
 src_files :=
diff --git a/util/nanoapp_cmd/Android.bp b/util/nanoapp_cmd/Android.bp
new file mode 100644
index 0000000..62aabae
--- /dev/null
+++ b/util/nanoapp_cmd/Android.bp
@@ -0,0 +1,42 @@
+//
+// 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.
+//
+
+cc_binary {
+    name: "nanoapp_cmd",
+
+    srcs: ["nanoapp_cmd.c"],
+
+    header_libs: [
+        "libnanohub_common_headers",
+    ],
+    include_dirs: [
+        "device/google/contexthub/firmware/os/inc",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+
+    shared_libs: [
+        "liblog",
+        "libutils",
+    ],
+
+    owner: "google",
+    vendor: true,
+}
diff --git a/util/nanoapp_cmd/Android.mk b/util/nanoapp_cmd/Android.mk
deleted file mode 100644
index 35320eb..0000000
--- a/util/nanoapp_cmd/Android.mk
+++ /dev/null
@@ -1,39 +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)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= nanoapp_cmd.c
-
-LOCAL_C_INCLUDES += \
-	$(LOCAL_PATH)/../../firmware/os/inc \
-	$(LOCAL_PATH)/../../lib/include
-
-LOCAL_CFLAGS := -Wall -Werror -Wextra
-
-LOCAL_MODULE:= nanoapp_cmd
-
-LOCAL_MODULE_TAGS:= optional
-LOCAL_MODULE_OWNER := google
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_LDLIBS := -llog
-
-LOCAL_SHARED_LIBRARIES := \
-	libutils \
-
-include $(BUILD_EXECUTABLE)
diff --git a/util/nanoapp_encr/Android.bp b/util/nanoapp_encr/Android.bp
new file mode 100644
index 0000000..5e9ff1e
--- /dev/null
+++ b/util/nanoapp_encr/Android.bp
@@ -0,0 +1,32 @@
+//
+// 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.
+//
+
+cc_binary_host {
+    name: "nanoapp_encr",
+
+    srcs: ["nanoapp_encr.c"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+        "-DHOST_BUILD",
+        "-DBOOTLOADER=",
+        "-DBOOTLOADER_RO=",
+    ],
+
+    static_libs: ["libnanohub_common"],
+}
diff --git a/util/nanoapp_encr/Android.mk b/util/nanoapp_encr/Android.mk
deleted file mode 100644
index 84444e1..0000000
--- a/util/nanoapp_encr/Android.mk
+++ /dev/null
@@ -1,40 +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)
-
-include $(CLEAR_VARS)
-
-
-LOCAL_SRC_FILES := \
-    nanoapp_encr.c \
-
-
-LOCAL_CFLAGS := \
-        -Wall \
-        -Werror \
-        -Wextra \
-        -DHOST_BUILD \
-        -DBOOTLOADER= \
-        -DBOOTLOADER_RO= \
-
-LOCAL_STATIC_LIBRARIES := libnanohub_common
-
-LOCAL_MODULE := nanoapp_encr
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_HOST_EXECUTABLE)
diff --git a/util/nanoapp_postprocess/Android.bp b/util/nanoapp_postprocess/Android.bp
new file mode 100644
index 0000000..6a8400f
--- /dev/null
+++ b/util/nanoapp_postprocess/Android.bp
@@ -0,0 +1,47 @@
+//
+// 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.
+//
+
+cc_binary_host {
+    name: "nanoapp_postprocess",
+
+    srcs: ["postprocess_elf.c"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+
+    static_libs: [
+        "libnanohub_common",
+
+        // libelf needed for ELF parsing support, libz required by libelf
+        "libelf",
+        "libz",
+    ],
+
+    // Statically linking libc++ so this binary can be copied out of the tree and
+    // still work (needed by dependencies)
+    stl: "libc++_static",
+
+    target: {
+        // libelf is not available in the Mac build as of June 2016, but we currently
+        // only need to use this tool on Linux, so exclude this from non-Linux builds
+        darwin: {
+            enabled: false,
+        },
+    },
+}
diff --git a/util/nanoapp_postprocess/Android.mk b/util/nanoapp_postprocess/Android.mk
deleted file mode 100644
index 9b4539b..0000000
--- a/util/nanoapp_postprocess/Android.mk
+++ /dev/null
@@ -1,45 +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.
-#
-
-# libelf is not available in the Mac build as of June 2016, but we currently
-# only need to use this tool on Linux, so exclude this from non-Linux builds
-ifeq ($(HOST_OS),linux)
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    postprocess_elf.c \
-
-LOCAL_CFLAGS := -Wall -Werror -Wextra
-
-LOCAL_STATIC_LIBRARIES := libnanohub_common
-
-LOCAL_MODULE := nanoapp_postprocess
-
-# libelf needed for ELF parsing support, libz required by libelf
-LOCAL_STATIC_LIBRARIES += libelf libz
-
-# Statically linking libc++ so this binary can be copied out of the tree and
-# still work (needed by dependencies)
-LOCAL_CXX_STL := libc++_static
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_HOST_EXECUTABLE)
-
-endif # linux
diff --git a/util/nanoapp_sign/Android.bp b/util/nanoapp_sign/Android.bp
new file mode 100644
index 0000000..752ba87
--- /dev/null
+++ b/util/nanoapp_sign/Android.bp
@@ -0,0 +1,33 @@
+//
+// 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.
+//
+
+cc_binary_host {
+    name: "nanoapp_sign",
+
+    srcs: ["nanoapp_sign.c"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+        "-DRSA_SUPPORT_PRIV_OP_BIGRAM",
+        "-DHOST_BUILD",
+        "-DBOOTLOADER=",
+        "-DBOOTLOADER_RO=",
+    ],
+
+    static_libs: ["libnanohub_common"],
+}
diff --git a/util/nanoapp_sign/Android.mk b/util/nanoapp_sign/Android.mk
deleted file mode 100644
index 7be5197..0000000
--- a/util/nanoapp_sign/Android.mk
+++ /dev/null
@@ -1,44 +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)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    nanoapp_sign.c \
-
-LOCAL_CFLAGS := \
-    -Wall \
-    -Werror \
-    -Wextra \
-    -DRSA_SUPPORT_PRIV_OP_BIGRAM \
-    -DHOST_BUILD \
-    -DBOOTLOADER= \
-    -DBOOTLOADER_RO= \
-
-
-ifneq ($(filter userdebug eng,$(TARGET_BUILD_VARIANT)),)
-LOCAL_CFLAGS += -DDEBUG_KEYS
-endif
-
-LOCAL_STATIC_LIBRARIES := libnanohub_common
-
-LOCAL_MODULE := nanoapp_sign
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_HOST_EXECUTABLE)
diff --git a/util/nanotool/Android.bp b/util/nanotool/Android.bp
new file mode 100644
index 0000000..0dc1ec0
--- /dev/null
+++ b/util/nanotool/Android.bp
@@ -0,0 +1,54 @@
+//
+// 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.
+//
+
+NANOTOOL_VERSION = "1.2.0"
+
+cc_binary {
+    name: "nanotool",
+
+    srcs: [
+        "androidcontexthub.cpp",
+        "apptohostevent.cpp",
+        "calibrationfile.cpp",
+        "contexthub.cpp",
+        "log.cpp",
+        "logevent.cpp",
+        "nanomessage.cpp",
+        "nanotool.cpp",
+        "resetreasonevent.cpp",
+        "sensorevent.cpp",
+    ],
+
+    // JSON file handling from chinook
+    static_libs: ["libhubutilcommon"],
+    shared_libs: [
+        "liblog",
+        "libstagefright_foundation",
+        "libutils",
+    ],
+
+    cpp_std: "c++11",
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+
+        "-DNANOTOOL_VERSION_STR=\"version " + NANOTOOL_VERSION + "\"",
+    ],
+
+    owner: "google",
+    vendor: true,
+}
diff --git a/util/nanotool/Android.mk b/util/nanotool/Android.mk
deleted file mode 100644
index fdd0295..0000000
--- a/util/nanotool/Android.mk
+++ /dev/null
@@ -1,58 +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)
-
-NANOTOOL_VERSION := 1.2.0
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    androidcontexthub.cpp \
-    apptohostevent.cpp \
-    calibrationfile.cpp \
-    contexthub.cpp \
-    log.cpp \
-    logevent.cpp \
-    nanomessage.cpp \
-    nanotool.cpp \
-    resetreasonevent.cpp \
-    sensorevent.cpp
-
-# JSON file handling from chinook
-COMMON_UTILS_DIR := ../common
-LOCAL_SRC_FILES += \
-    $(COMMON_UTILS_DIR)/file.cpp \
-    $(COMMON_UTILS_DIR)/JSONObject.cpp
-
-LOCAL_C_INCLUDES := \
-    $(LOCAL_PATH)/$(COMMON_UTILS_DIR)
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog \
-    libstagefright_foundation \
-    libutils
-
-LOCAL_CFLAGS += -Wall -Werror -Wextra
-LOCAL_CFLAGS += -std=c++11
-LOCAL_CFLAGS += -DNANOTOOL_VERSION_STR='"version $(NANOTOOL_VERSION)"'
-
-LOCAL_MODULE := nanotool
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_OWNER := google
-
-include $(BUILD_EXECUTABLE)
diff --git a/util/sensortest/Android.bp b/util/sensortest/Android.bp
new file mode 100644
index 0000000..e1de6ae
--- /dev/null
+++ b/util/sensortest/Android.bp
@@ -0,0 +1,35 @@
+// Copyright (C) 2015 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.
+
+cc_binary {
+    name: "sensortest",
+
+    srcs: ["sensortest.cpp"],
+
+    shared_libs: ["libandroid"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+
+    owner: "google",
+
+    strip: {
+        keep_symbols: true,
+    },
+
+    sdk_version: "current",
+}
diff --git a/util/sensortest/Android.mk b/util/sensortest/Android.mk
deleted file mode 100644
index 0f385e0..0000000
--- a/util/sensortest/Android.mk
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright (C) 2015 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                       \
-        sensortest.cpp                  \
-
-LOCAL_SHARED_LIBRARIES :=               \
-        libandroid                      \
-
-LOCAL_C_INCLUDES:= \
-
-LOCAL_CFLAGS := -Wall -Werror -Wextra
-
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_OWNER := google
-
-LOCAL_STRIP_MODULE := keep_symbols
-
-LOCAL_MODULE:= sensortest
-
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_EXECUTABLE)
-
diff --git a/util/stm32_flash/Android.bp b/util/stm32_flash/Android.bp
new file mode 100644
index 0000000..18e6f7b
--- /dev/null
+++ b/util/stm32_flash/Android.bp
@@ -0,0 +1,36 @@
+//
+// 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.
+//
+
+cc_binary {
+    name: "stm32_flash",
+
+    shared_libs: ["libcutils"],
+
+    srcs: [
+        "flash.c",
+        "i2c.c",
+        "spi.c",
+        "stm32_bl.c",
+        "stm32f4_crc.c",
+        "uart.c",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+}
diff --git a/util/stm32_flash/Android.mk b/util/stm32_flash/Android.mk
deleted file mode 100644
index 3063c0c..0000000
--- a/util/stm32_flash/Android.mk
+++ /dev/null
@@ -1,37 +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)
-
-include $(CLEAR_VARS)
-
-LOCAL_SHARED_LIBRARIES := libcutils libc
-
-LOCAL_SRC_FILES := \
-        flash.c \
-        i2c.c \
-        spi.c \
-        stm32_bl.c \
-        stm32f4_crc.c \
-        uart.c
-
-LOCAL_CFLAGS := -Wall -Werror -Wextra
-
-LOCAL_MODULE := stm32_flash
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_EXECUTABLE)