Cleanup C and C++ compiler flags

Cleanup the setting of C and C++ compiler flags:
 * (Almost) all compiler flags are set uniformly
   in the system/bt/Android.mk file.
 * Enable by default breaking the compilation if there is a
   compilation warning: -Werror
 * Enable most compilation warnings: -Wall -Wextra
 * Renamed Android.mk related flags:
   - bdroid_C_INCLUDES -> bluetooth_C_INCLUDES
   - bdroid_CFLAGS -> bluetooth_CFLAGS
 * Introduce variables for C-only and C++ only compiler:
   - bluetooth_CFLAGS: common C and C++ compiler flags
   - bluetooth_CONLYFLAGS: C only compiler flags
   - bluetooth_CPPFLAGS: C++ only compiler flags
 * Disable warnings for existing issues - to be removed as issues are
   resolved
 * Add a workaround for libchrome and -DNDEBUG usage.

Bug: 26879229
Change-Id: Ie7595965ca0c8ead0e95e983e76c327e7891b2c3
diff --git a/Android.mk b/Android.mk
index df3c205..5849e14 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,38 +1,64 @@
 LOCAL_PATH := $(call my-dir)
 
-# Setup bdroid local make variables for handling configuration
+# Setup Bluetooth local make variables for handling configuration
 ifneq ($(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR),)
-  bdroid_C_INCLUDES := $(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR)
-  bdroid_CFLAGS += -DHAS_BDROID_BUILDCFG
+  bluetooth_C_INCLUDES := $(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR)
+  bluetooth_CFLAGS += -DHAS_BDROID_BUILDCFG
 else
-  bdroid_C_INCLUDES :=
-  bdroid_CFLAGS += -DHAS_NO_BDROID_BUILDCFG
+  bluetooth_C_INCLUDES :=
+  bluetooth_CFLAGS += -DHAS_NO_BDROID_BUILDCFG
 endif
 
 ifneq ($(BOARD_BLUETOOTH_BDROID_HCILP_INCLUDED),)
-  bdroid_CFLAGS += -DHCILP_INCLUDED=$(BOARD_BLUETOOTH_BDROID_HCILP_INCLUDED)
+  bluetooth_CFLAGS += -DHCILP_INCLUDED=$(BOARD_BLUETOOTH_BDROID_HCILP_INCLUDED)
 endif
 
 ifneq ($(TARGET_BUILD_VARIANT),user)
-bdroid_CFLAGS += -DBLUEDROID_DEBUG
+bluetooth_CFLAGS += -DBLUEDROID_DEBUG
 endif
 
-bdroid_CFLAGS += -DEXPORT_SYMBOL="__attribute__((visibility(\"default\")))"
+bluetooth_CFLAGS += -DEXPORT_SYMBOL="__attribute__((visibility(\"default\")))"
 
-bdroid_CFLAGS += \
+#
+# Common C/C++ compiler flags.
+#
+# - gnu-variable-sized-type-not-at-end is needed for a variable-size header in
+#   a struct.
+# - constant-logical-operand is needed for code in l2c_utils.c that looks
+#   intentional.
+#
+bluetooth_CFLAGS += \
   -fvisibility=hidden \
   -Wall \
-  -Wunused-but-set-variable \
-  -Werror=format-security \
-  -Werror=pointer-to-int-cast \
-  -Werror=int-to-pointer-cast \
-  -Werror=implicit-function-declaration \
+  -Wextra \
+  -Werror \
+  -Wno-typedef-redefinition \
   -Wno-gnu-variable-sized-type-not-at-end \
+  -Wno-unused-parameter \
+  -Wno-maybe-uninitialized \
+  -Wno-uninitialized \
+  -Wno-missing-field-initializers \
+  -Wno-unused-variable \
+  -Wno-non-literal-null-conversion \
+  -Wno-sign-compare \
+  -Wno-incompatible-pointer-types \
+  -Wno-unused-function \
+  -Wno-missing-braces \
+  -Wno-enum-conversion \
+  -Wno-logical-not-parentheses \
+  -Wno-parentheses \
+  -Wno-constant-logical-operand \
+  -Wno-format \
   -UNDEBUG \
   -DLOG_NDEBUG=1
 
+bluetooth_CONLYFLAGS += -std=c99
+bluetooth_CPPFLAGS :=
+
 include $(call all-subdir-makefiles)
 
 # Cleanup our locals
-bdroid_C_INCLUDES :=
-bdroid_CFLAGS :=
+bluetooth_C_INCLUDES :=
+bluetooth_CFLAGS :=
+bluetooth_CONLYFLAGS :=
+bluetooth_CPPFLAGS :=
diff --git a/audio_a2dp_hw/Android.mk b/audio_a2dp_hw/Android.mk
index e745d0c..0dc1388 100644
--- a/audio_a2dp_hw/Android.mk
+++ b/audio_a2dp_hw/Android.mk
@@ -1,5 +1,7 @@
 LOCAL_PATH := $(call my-dir)
 
+# Audio A2DP shared library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
@@ -10,8 +12,6 @@
 	$(LOCAL_PATH)/../ \
 	$(LOCAL_PATH)/../utils/include
 
-LOCAL_CFLAGS += -std=c99 $(bdroid_CFLAGS)
-
 LOCAL_MODULE := audio.a2dp.default
 LOCAL_MODULE_RELATIVE_PATH := hw
 
@@ -20,4 +20,8 @@
 
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/bta/Android.mk b/bta/Android.mk
index 8f6b368..5e6b381 100644
--- a/bta/Android.mk
+++ b/bta/Android.mk
@@ -1,12 +1,9 @@
 LOCAL_PATH:= $(call my-dir)
 
+# BTA static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
-LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -std=c99
-LOCAL_CLANG_CFLAGS += -Wno-error=gnu-variable-sized-type-not-at-end
-# Too many unused parameters. TODO: Annotate them.
-LOCAL_CFLAGS += -Wno-unused-parameter
-
 LOCAL_SRC_FILES:= \
     ./dm/bta_dm_ci.c \
     ./dm/bta_dm_act.c \
@@ -99,7 +96,10 @@
                    $(LOCAL_PATH)/../udrv/include \
                    $(LOCAL_PATH)/../vnd/include \
                    $(LOCAL_PATH)/../utils/include \
-                   $(bdroid_C_INCLUDES) \
+                   $(bluetooth_C_INCLUDES)
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/btcore/Android.mk b/btcore/Android.mk
index fb22e0e..a8997c8 100644
--- a/btcore/Android.mk
+++ b/btcore/Android.mk
@@ -45,31 +45,37 @@
 # libbtcore static library for target
 # ========================================================
 include $(CLEAR_VARS)
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_C_INCLUDES := $(btcoreCommonIncludes)
 LOCAL_SRC_FILES := $(btcoreCommonSrc)
-LOCAL_CFLAGS := -std=c99 $(bdroid_CFLAGS)
 LOCAL_MODULE := libbtcore
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := libc liblog
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
 # libbtcore static library for host
 # ========================================================
 ifeq ($(HOST_OS),linux)
 include $(CLEAR_VARS)
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_C_INCLUDES := $(btcoreCommonIncludes)
 LOCAL_SRC_FILES := $(btcoreCommonSrc)
-# TODO(armansito): Setting _GNU_SOURCE isn't very platform-independent but
-# should be compatible for a Linux host OS. We should figure out what to do for
-# a non-Linux host OS.
-LOCAL_CFLAGS := -std=c99 $(bdroid_CFLAGS) -D_GNU_SOURCE
 LOCAL_MODULE := libbtcore-host
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+
+# TODO(armansito): Setting _GNU_SOURCE isn't very platform-independent but
+# should be compatible for a Linux host OS. We should figure out what to do for
+# a non-Linux host OS.
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -D_GNU_SOURCE
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_STATIC_LIBRARY)
 endif
 
@@ -79,27 +85,33 @@
 # libbtcore unit tests for target
 # ========================================================
 include $(CLEAR_VARS)
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_C_INCLUDES := $(btcoreCommonIncludes)
 LOCAL_SRC_FILES := $(btcoreCommonTestSrc)
-LOCAL_CFLAGS := -Wall -Werror -Werror=unused-variable
 LOCAL_MODULE := net_test_btcore
 LOCAL_MODULE_TAGS := tests
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_STATIC_LIBRARIES := libbtcore libosi
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_NATIVE_TEST)
 
 # libbtcore unit tests for host
 # ========================================================
 ifeq ($(HOST_OS),linux)
 include $(CLEAR_VARS)
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_C_INCLUDES := $(btcoreCommonIncludes)
 LOCAL_SRC_FILES := $(btcoreCommonTestSrc)
-LOCAL_CFLAGS := -Wall -Werror -Werror=unused-variable
 LOCAL_MODULE := net_test_btcore
 LOCAL_MODULE_TAGS := tests
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_STATIC_LIBRARIES := libbtcore-host libosi-host
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_NATIVE_TEST)
 endif
diff --git a/btif/Android.mk b/btif/Android.mk
index ffb0819..5b5c3d1 100644
--- a/btif/Android.mk
+++ b/btif/Android.mk
@@ -105,32 +105,38 @@
   $(LOCAL_PATH)/../embdrv/sbc/decoder/include \
   $(LOCAL_PATH)/../audio_a2dp_hw \
   $(LOCAL_PATH)/../utils/include \
-  $(bdroid_C_INCLUDES) \
+  $(bluetooth_C_INCLUDES) \
   external/zlib
 
-btifCommonCFlags += -DBUILDCFG $(bdroid_CFLAGS) -std=c99 \
-  -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=unused-parameter
-
 # libbtif static library for target
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_C_INCLUDES := $(btifCommonIncludes)
 LOCAL_SRC_FILES := $(btifCommonSrc)
-LOCAL_CFLAGS := $(btifCommonCFlags)
 # Many .h files have redefined typedefs
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_SHARED_LIBRARIES := libcutils liblog
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := libbtif
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
+# btif unit tests for target
+# ========================================================
 include $(CLEAR_VARS)
 LOCAL_C_INCLUDES := $(btifCommonIncludes)
 LOCAL_SRC_FILES := $(btifTestSrc)
-LOCAL_CFLAGS := $(btifCommonCFlags)
 LOCAL_SHARED_LIBRARIES += liblog libhardware libhardware_legacy libcutils
 LOCAL_STATIC_LIBRARIES += libbtcore libbtif libosi
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := net_test_btif
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_NATIVE_TEST)
diff --git a/conf/Android.mk b/conf/Android.mk
index 22d03d7..6108bcf 100644
--- a/conf/Android.mk
+++ b/conf/Android.mk
@@ -1,5 +1,7 @@
 LOCAL_PATH := $(call my-dir)
 
+# Bluetooth bt_stack.conf config file
+# ========================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := bt_stack.conf
 LOCAL_MODULE_CLASS := ETC
@@ -8,7 +10,8 @@
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
 include $(BUILD_PREBUILT)
 
-
+# Bluetooth bt_did.conf config file
+# ========================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := bt_did.conf
 LOCAL_MODULE_CLASS := ETC
@@ -17,7 +20,8 @@
 LOCAL_SRC_FILES := $(LOCAL_MODULE)
 include $(BUILD_PREBUILT)
 
-
+# Bluetooth auto_pair_devlist.conf config file
+# ========================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := auto_pair_devlist.conf
 LOCAL_MODULE_CLASS := ETC
diff --git a/device/Android.mk b/device/Android.mk
index 494f700..c5b9377 100644
--- a/device/Android.mk
+++ b/device/Android.mk
@@ -18,6 +18,8 @@
 
 LOCAL_PATH := $(call my-dir)
 
+# Bluetooth device static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_C_INCLUDES := \
@@ -27,38 +29,44 @@
     $(LOCAL_PATH)/../hci/include \
     $(LOCAL_PATH)/../include \
     $(LOCAL_PATH)/../stack/include \
-    $(bdroid_C_INCLUDES)
+    $(bluetooth_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
     src/classic/peer.c \
     src/controller.c \
     src/interop.c
 
-LOCAL_CFLAGS := -std=c99 $(bdroid_CFLAGS)
 LOCAL_MODULE := libbtdevice
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := libc liblog
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
-#####################################################
-
+# Bluetooth device unit tests for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_C_INCLUDES := \
     $(LOCAL_PATH)/.. \
-    $(bdroid_C_INCLUDES)
+    $(bluetooth_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
     ../osi/test/AllocationTestHarness.cpp \
     ./test/interop_test.cpp \
     ./test/classic/peer_test.cpp
 
-LOCAL_CFLAGS := -Wall -Werror -Werror=unused-variable
 LOCAL_MODULE := net_test_device
 LOCAL_MODULE_TAGS := tests
 LOCAL_SHARED_LIBRARIES := liblog libdl
 LOCAL_STATIC_LIBRARIES := libbtdevice libbtcore libosi libcutils
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_NATIVE_TEST)
diff --git a/embdrv/Android.mk b/embdrv/Android.mk
index 6e92be4..c455f97 100755
--- a/embdrv/Android.mk
+++ b/embdrv/Android.mk
@@ -1,7 +1,3 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(call all-subdir-makefiles)
-
-# Cleanup our locals
-#bdroid_C_INCLUDES :=
-#bdroid_CFLaGS :=
diff --git a/embdrv/sbc/Android.mk b/embdrv/sbc/Android.mk
index 6e92be4..c455f97 100755
--- a/embdrv/sbc/Android.mk
+++ b/embdrv/sbc/Android.mk
@@ -1,7 +1,3 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(call all-subdir-makefiles)
-
-# Cleanup our locals
-#bdroid_C_INCLUDES :=
-#bdroid_CFLaGS :=
diff --git a/embdrv/sbc/decoder/Android.mk b/embdrv/sbc/decoder/Android.mk
index 68fd143..f5c8c2a 100755
--- a/embdrv/sbc/decoder/Android.mk
+++ b/embdrv/sbc/decoder/Android.mk
@@ -1,4 +1,7 @@
 LOCAL_PATH:= $(call my-dir)
+
+# Bluetooth SBC decoder static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 # sbc decoder
@@ -25,4 +28,8 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
diff --git a/hci/Android.mk b/hci/Android.mk
index 009ce38..24e3d4d 100644
--- a/hci/Android.mk
+++ b/hci/Android.mk
@@ -1,5 +1,7 @@
 LOCAL_PATH := $(call my-dir)
 
+# HCI static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
@@ -19,12 +21,6 @@
     src/packet_fragmenter.c \
     src/vendor.c
 
-ifeq ($(BLUETOOTH_HCI_USE_MCT),true)
-LOCAL_CFLAGS += -DHCI_USE_MCT
-endif
-
-LOCAL_CFLAGS += -std=c99 $(bdroid_CFLAGS)
-
 LOCAL_C_INCLUDES += \
     $(LOCAL_PATH)/include \
     $(LOCAL_PATH)/.. \
@@ -33,13 +29,21 @@
     $(LOCAL_PATH)/../stack/include \
     $(LOCAL_PATH)/../utils/include \
     $(LOCAL_PATH)/../bta/include \
-    $(bdroid_C_INCLUDES)
+    $(bluetooth_C_INCLUDES)
 
 LOCAL_MODULE := libbt-hci
 
+ifeq ($(BLUETOOTH_HCI_USE_MCT),true)
+LOCAL_CFLAGS += -DHCI_USE_MCT
+endif
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
-#####################################################
+# HCI unit tests for target
+# ========================================================
 ifeq (,$(strip $(SANITIZE_TARGET)))
 include $(CLEAR_VARS)
 
@@ -51,8 +55,7 @@
     $(LOCAL_PATH)/../osi/test \
     $(LOCAL_PATH)/../stack/include \
     $(LOCAL_PATH)/../utils/include \
-    $(bdroid_C_INCLUDES)
-
+    $(bluetooth_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
     ../osi/test/AllocationTestHarness.cpp \
@@ -63,12 +66,14 @@
     ./test/low_power_manager_test.cpp \
     ./test/packet_fragmenter_test.cpp
 
-
-LOCAL_CFLAGS := -Wall -Werror $(bdroid_CFLAGS)
 LOCAL_MODULE := net_test_hci
 LOCAL_MODULE_TAGS := tests
 LOCAL_SHARED_LIBRARIES := liblog libdl libprotobuf-cpp-full
 LOCAL_STATIC_LIBRARIES := libbt-hci libosi libcutils libbtcore libbt-protos
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_NATIVE_TEST)
 endif # SANITIZE_TARGET
diff --git a/main/Android.mk b/main/Android.mk
index 8f782c9..badabee 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -1,9 +1,7 @@
 LOCAL_PATH:= $(call my-dir)
 
-#
-# Bluetooth HW module
-#
-
+# Bluetooth main HW module / shared library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 # platform specific
@@ -53,22 +51,9 @@
 	$(LOCAL_PATH)/../embdrv/sbc/decoder/include \
 	$(LOCAL_PATH)/../audio_a2dp_hw \
 	$(LOCAL_PATH)/../utils/include \
-	$(bdroid_C_INCLUDES) \
+	$(bluetooth_C_INCLUDES) \
 	external/zlib
 
-LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=unused-parameter
-LOCAL_CONLYFLAGS := -std=c99
-
-ifeq ($(TARGET_PRODUCT), full_crespo)
-     LOCAL_CFLAGS += -DTARGET_CRESPO
-endif
-ifeq ($(TARGET_PRODUCT), full_crespo4g)
-     LOCAL_CFLAGS += -DTARGET_CRESPO
-endif
-ifeq ($(TARGET_PRODUCT), full_maguro)
-     LOCAL_CFLAGS += -DTARGET_MAGURO
-endif
-
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
     libdl \
@@ -114,9 +99,8 @@
     libbt-hci \
     libbt-vendor
 
-LOCAL_CLANG_CFLAGS := -Wno-error=gnu-variable-sized-type-not-at-end
-LOCAL_CLANG_CFLAGS += -Wno-typedef-redefinition
-# Too many unused parameters. TODO: Annotate them.
-LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/osi/Android.mk b/osi/Android.mk
index 05037a1..d2ee7ab 100644
--- a/osi/Android.mk
+++ b/osi/Android.mk
@@ -75,11 +75,10 @@
 btosiCommonIncludes := \
     $(LOCAL_PATH)/.. \
     $(LOCAL_PATH)/../utils/include \
-    $(LOCAL_PATH)/../stack/include $(bdroid_C_INCLUDES)
+    $(LOCAL_PATH)/../stack/include \
+    $(bluetooth_C_INCLUDES)
 
-btosiCommonCFlags := -Wall -Werror -UNDEBUG -fvisibility=hidden $(bdroid_CFLAGS)
-
-# protobuf library for bluetooth
+# Bluetooth Protobuf static library for target
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := libbt-protos
@@ -88,8 +87,15 @@
 LOCAL_EXPORT_C_INCLUDE_DIRS += \
     $(generated_sources_dir)/proto/system/bt
 LOCAL_SRC_FILES := $(call all-proto-files-under,src/protos/)
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
+# Bluetooth Protobuf static library for host
+# ========================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := libbt-protos
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
@@ -97,6 +103,11 @@
 LOCAL_EXPORT_C_INCLUDE_DIRS += \
     $(generated_sources_dir)/proto/system/bt
 LOCAL_SRC_FILES := $(call all-proto-files-under,src/protos/)
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 # libosi static library for target
@@ -104,14 +115,16 @@
 include $(CLEAR_VARS)
 LOCAL_C_INCLUDES := $(btosiCommonIncludes)
 LOCAL_SRC_FILES := $(btosiCommonSrc)
-LOCAL_CFLAGS := $(btosiCommonCFlags)
-# Many .h files have redefined typedefs
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_MODULE := libosi
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := libc liblog
 LOCAL_STATIC_LIBRARIES := libbt-protos
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
 # libosi static library for host
@@ -120,35 +133,40 @@
 include $(CLEAR_VARS)
 LOCAL_C_INCLUDES := $(btosiCommonIncludes)
 LOCAL_SRC_FILES := $(btosiCommonSrc)
-# TODO(armansito): Setting _GNU_SOURCE isn't very platform-independent but
-# should be compatible for a Linux host OS. We should figure out what to do for
-# a non-Linux host OS.
-LOCAL_CFLAGS := \
-	$(btosiCommonCFlags) \
-	-D_GNU_SOURCE
-# Many .h files have redefined typedefs
-LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
 LOCAL_MODULE := libosi-host
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_STATIC_LIBRARIES := libbt-protos
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+
+# TODO(armansito): Setting _GNU_SOURCE isn't very platform-independent but
+# should be compatible for a Linux host OS. We should figure out what to do for
+# a non-Linux host OS.
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) -D_GNU_SOURCE
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_STATIC_LIBRARY)
 endif
 
+#
 # Note: It's good to get the tests compiled both for the host and the target so
 # we get to test with both Bionic libc and glibc
-
+#
 # libosi unit tests for target
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_C_INCLUDES := $(btosiCommonIncludes)
 LOCAL_SRC_FILES := $(btosiCommonTestSrc)
-LOCAL_CFLAGS := -Wall -UNDEBUG
 LOCAL_MODULE := net_test_osi
 LOCAL_MODULE_TAGS := tests
 LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full
 LOCAL_STATIC_LIBRARIES := libosi libbt-protos
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_NATIVE_TEST)
 
 # libosi unit tests for host
@@ -157,11 +175,15 @@
 include $(CLEAR_VARS)
 LOCAL_C_INCLUDES := $(btosiCommonIncludes)
 LOCAL_SRC_FILES := $(btosiCommonTestSrc)
-LOCAL_CFLAGS := -Wall -UNDEBUG
 LOCAL_LDLIBS := -lrt -lpthread
 LOCAL_MODULE := net_test_osi
 LOCAL_MODULE_TAGS := tests
 LOCAL_SHARED_LIBRARIES := liblog libprotobuf-cpp-full
 LOCAL_STATIC_LIBRARIES := libosi-host libbt-protos
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_NATIVE_TEST)
 endif
diff --git a/profile/Android.mk b/profile/Android.mk
index 5d3e5c9..f0bdcc1 100644
--- a/profile/Android.mk
+++ b/profile/Android.mk
@@ -18,6 +18,8 @@
 
 LOCAL_PATH := $(call my-dir)
 
+# Bluetooth profile static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_C_INCLUDES := \
@@ -25,16 +27,18 @@
     $(LOCAL_PATH)/include \
     $(LOCAL_PATH)/../btcore/include \
     $(LOCAL_PATH)/../include \
-    $(bdroid_C_INCLUDES)
+    $(bluetooth_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
     src/manager.c
 
-LOCAL_CFLAGS := $(bdroid_CFLAGS)
-LOCAL_CONLYFLAGS := $(bdroid_CONLYFLAGS)
 LOCAL_MODULE := libbtprofile
 LOCAL_MODULE_TAGS := optional
 LOCAL_SHARED_LIBRARIES := libc liblog
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
diff --git a/service/Android.mk b/service/Android.mk
index eabce61..7d8de24 100644
--- a/service/Android.mk
+++ b/service/Android.mk
@@ -16,6 +16,26 @@
 
 LOCAL_PATH:= $(call my-dir)
 
+#
+# Workaround for libchrome and -DNDEBUG usage.
+#
+# Test whether the original HOST_GLOBAL_CFLAGS and
+# TARGET_GLOBAL_CFLAGS contain -DNDEBUG .
+# This is needed as a workaround to make sure that
+# libchrome and local files calling logging::InitLogging()
+# are consistent with the usage of -DNDEBUG .
+# ========================================================
+ifneq (,$(findstring NDEBUG,$(HOST_GLOBAL_CFLAGS)))
+  btservice_orig_HOST_NDEBUG := -DBT_LIBCHROME_NDEBUG
+else
+  btservice_orig_HOST_NDEBUG :=
+endif
+ifneq (,$(findstring NDEBUG,$(TARGET_GLOBAL_CFLAGS)))
+  btservice_orig_TARGET_NDEBUG := -DBT_LIBCHROME_NDEBUG
+else
+  btservice_orig_TARGET_NDEBUG :=
+endif
+
 # Source variables
 # ========================================================
 btserviceCommonSrc := \
@@ -92,11 +112,6 @@
 	test/util_unittest.cpp \
 	test/uuid_unittest.cpp
 
-# Some standard CFLAGS used in all targets.
-btservice_common_flags :=
-# libchrome has unused parameters in their .h files. b/26228533
-btservice_common_flags += -Wno-unused-parameter
-
 # Native system service for target
 # ========================================================
 include $(CLEAR_VARS)
@@ -107,7 +122,6 @@
 	$(btserviceDaemonSrc) \
 	main.cpp
 LOCAL_C_INCLUDES += $(btserviceCommonIncludes)
-LOCAL_CFLAGS += $(btservice_common_flags)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := bluetoothtbd
 LOCAL_REQUIRED_MODULES = bluetooth.default
@@ -120,9 +134,14 @@
 	liblog \
 	libutils
 LOCAL_INIT_RC := bluetoothtbd.rc
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) $(btservice_orig_TARGET_NDEBUG)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_EXECUTABLE)
 
-# Native system service unittests for host
+# Native system service unit tests for host
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := \
@@ -141,16 +160,20 @@
 	test/stub_ipc_handler_linux.cpp
 endif
 LOCAL_C_INCLUDES += $(btserviceCommonIncludes)
-LOCAL_CFLAGS += $(btservice_common_flags)
 LOCAL_MODULE_TAGS := debug tests
 LOCAL_MODULE := bluetoothtbd-host_test
 LOCAL_SHARED_LIBRARIES += libchrome
 LOCAL_STATIC_LIBRARIES += libgmock_host libgtest_host liblog
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) $(btservice_orig_HOST_NDEBUG)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_NATIVE_TEST)
 
-# Native system service unittests for target. This
-# includes Binder related tests that can only be run on
-# target.
+# Native system service unit tests for target.
+# This includes Binder related tests that can only be run
+# on target.
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := \
@@ -161,7 +184,6 @@
 	test/main.cpp \
 	test/parcel_helpers_unittest.cpp
 LOCAL_C_INCLUDES += $(btserviceCommonIncludes)
-LOCAL_CFLAGS += $(btservice_common_flags)
 LOCAL_MODULE_TAGS := debug tests
 LOCAL_MODULE := bluetoothtbd_test
 LOCAL_SHARED_LIBRARIES += \
@@ -169,9 +191,15 @@
 	libchrome \
 	libutils
 LOCAL_STATIC_LIBRARIES += libgmock libgtest liblog
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) $(btservice_orig_TARGET_NDEBUG)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_NATIVE_TEST)
 
 # Client library for interacting with Bluetooth daemon
+# This is a static library for target.
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := \
@@ -179,16 +207,19 @@
 	$(btserviceCommonBinderSrc)
 LOCAL_C_INCLUDES += $(btserviceCommonIncludes)
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/common
-LOCAL_CFLAGS += $(btservice_common_flags)
 LOCAL_MODULE := libbluetooth-client
 LOCAL_SHARED_LIBRARIES += libbinder libchrome libutils
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) $(btservice_orig_TARGET_NDEBUG)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
 
 # Native system service CLI for target
 # ========================================================
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := client/main.cpp
-LOCAL_CFLAGS += $(btservice_common_flags)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := bluetooth-cli
 LOCAL_STATIC_LIBRARIES += libbluetooth-client
@@ -196,18 +227,22 @@
 	libbinder \
 	libchrome \
 	libutils
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) $(btservice_orig_TARGET_NDEBUG)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_EXECUTABLE)
 
-# Heart Rate GATT service example
+# Heart Rate GATT service example for target
 # ========================================================
-# TODO(armansito): Move this into a new makefile under examples/ once we build a
-# client static library that the examples can depend on.
+# TODO(armansito): Move this into a new makefile under examples/ once we build
+# a client static library that the examples can depend on.
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := \
 	example/heart_rate/heart_rate_server.cpp \
 	example/heart_rate/server_main.cpp
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/../
-LOCAL_CFLAGS += $(btservice_common_flags)
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := bt-example-hr-server
 LOCAL_STATIC_LIBRARIES += libbluetooth-client
@@ -215,4 +250,9 @@
 	libbinder \
 	libchrome \
 	libutils
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS) $(btservice_orig_TARGET_NDEBUG)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_EXECUTABLE)
diff --git a/service/client/main.cpp b/service/client/main.cpp
index efed027..03f00f6 100644
--- a/service/client/main.cpp
+++ b/service/client/main.cpp
@@ -17,6 +17,10 @@
 #include <iostream>
 #include <string>
 
+#ifdef BT_LIBCHROME_NDEBUG
+#define NDEBUG 1
+#endif
+
 #include <base/at_exit.h>
 #include <base/command_line.h>
 #include <base/logging.h>
diff --git a/service/example/heart_rate/server_main.cpp b/service/example/heart_rate/server_main.cpp
index 80f82bc..d1b63d4 100644
--- a/service/example/heart_rate/server_main.cpp
+++ b/service/example/heart_rate/server_main.cpp
@@ -14,6 +14,10 @@
 //  limitations under the License.
 //
 
+#ifdef BT_LIBCHROME_NDEBUG
+#define NDEBUG 1
+#endif
+
 #include <base/at_exit.h>
 #include <base/bind.h>
 #include <base/command_line.h>
diff --git a/service/main.cpp b/service/main.cpp
index 90b7c9a..3ab81e6 100644
--- a/service/main.cpp
+++ b/service/main.cpp
@@ -14,9 +14,14 @@
 //  limitations under the License.
 //
 
+#ifdef BT_LIBCHROME_NDEBUG
+#define NDEBUG 1
+#endif
+
 #include <base/at_exit.h>
 #include <base/command_line.h>
 #include <base/files/scoped_file.h>
+#include <base/logging.h>
 
 // For system properties
 // TODO(icoolidge): abstraction or non-cutils stub.
diff --git a/service/test/main.cpp b/service/test/main.cpp
index 1c5f1d9..458a83b 100644
--- a/service/test/main.cpp
+++ b/service/test/main.cpp
@@ -14,6 +14,10 @@
 //  limitations under the License.
 //
 
+#ifdef BT_LIBCHROME_NDEBUG
+#define NDEBUG 1
+#endif
+
 #include <base/at_exit.h>
 #include <base/command_line.h>
 #include <base/logging.h>
diff --git a/stack/Android.mk b/stack/Android.mk
index f8ffcb2..40ae5a6 100644
--- a/stack/Android.mk
+++ b/stack/Android.mk
@@ -1,5 +1,7 @@
 LOCAL_PATH:= $(call my-dir)
 
+# Bluetooth stack static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_C_INCLUDES:= \
@@ -31,9 +33,7 @@
                    $(LOCAL_PATH)/../bta/sys \
                    $(LOCAL_PATH)/../utils/include \
                    $(LOCAL_PATH)/../ \
-                   $(bdroid_C_INCLUDES) \
-
-LOCAL_CFLAGS += $(bdroid_CFLAGS) -std=c99
+                   $(bluetooth_C_INCLUDES)
 
 LOCAL_SRC_FILES:= \
     ./a2dp/a2d_api.c \
@@ -152,11 +152,9 @@
 LOCAL_MODULE := libbt-stack
 LOCAL_STATIC_LIBRARIES := libbt-hci
 LOCAL_SHARED_LIBRARIES := libcutils
-# gnu-variable-sized-type-not-at-end is needed for a variable-size header in
-# a struct.
-# const-logical-operand is needed for code in l2c_utils.c that looks intentional.
-LOCAL_CLANG_CFLAGS += -Wno-error=gnu-variable-sized-type-not-at-end -Wno-error=constant-logical-operand
-# Too many unused parameters. TODO: Annotate them.
-LOCAL_CFLAGS += -Wno-unused-parameter
+
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/test/bluedroidtest/Android.mk b/test/bluedroidtest/Android.mk
index 6753588..9f0b65c 100644
--- a/test/bluedroidtest/Android.mk
+++ b/test/bluedroidtest/Android.mk
@@ -16,23 +16,21 @@
 
 LOCAL_PATH:= $(call my-dir)
 
+# Bluetooth unit tests for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:=     \
     bluedroidtest.c
 
 LOCAL_C_INCLUDES :=
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-LOCAL_CFLAGS += -std=c99
-
-LOCAL_CFLAGS += -std=c99
-
 LOCAL_MODULE_TAGS := eng
-
 LOCAL_MODULE:= bdt
-
 LOCAL_SHARED_LIBRARIES += libcutils   \
                           libhardware
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_EXECUTABLE)
diff --git a/test/suite/Android.mk b/test/suite/Android.mk
index ad2149b..aa9d98b 100644
--- a/test/suite/Android.mk
+++ b/test/suite/Android.mk
@@ -16,6 +16,8 @@
 
 LOCAL_PATH := $(call my-dir)
 
+# Bluetooth test suite for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
@@ -50,10 +52,8 @@
   libbtcore \
   libosi
 
-LOCAL_CFLAGS += \
-  -Wall \
-  -Werror \
-  -Wno-unused-parameter \
-  -Wno-missing-field-initializers
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
 
 include $(BUILD_NATIVE_TEST)
diff --git a/tools/bdtool/Android.mk.disabled b/tools/bdtool/Android.mk.disabled
index 7ed5c4a..af04746 100644
--- a/tools/bdtool/Android.mk.disabled
+++ b/tools/bdtool/Android.mk.disabled
@@ -16,6 +16,8 @@
 
 LOCAL_PATH := $(call my-dir)
 
+# Bluetooth tools for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
@@ -33,8 +35,6 @@
   libbtcore \
   libosi
 
-LOCAL_CFLAGS := -std=c99 $(bdroid_CFLAGS) -Wno-unused-parameter -Wno-missing-field-initializers
-
 LOCAL_C_INCLUDES := \
   $(LOCAL_PATH)/../../test/suite \
   $(LOCAL_PATH)/../..
@@ -42,4 +42,8 @@
 LOCAL_SHARED_LIBRARIES += \
   libhardware liblog
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_EXECUTABLE)
diff --git a/tools/hci/Android.mk.disabled b/tools/hci/Android.mk.disabled
index 9477db3..3e2286a 100644
--- a/tools/hci/Android.mk.disabled
+++ b/tools/hci/Android.mk.disabled
@@ -16,6 +16,8 @@
 
 LOCAL_PATH := $(call my-dir)
 
+# Bluetooth HCI tools for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
@@ -23,7 +25,10 @@
 
 LOCAL_SRC_FILES := main.c
 LOCAL_STATIC_LIBRARIES := libosi
-LOCAL_CFLAGS := -std=c99 $(bdroid_CFLAGS)
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_EXECUTABLE)
diff --git a/utils/Android.mk b/utils/Android.mk
index 5e71457..e28d5fa 100644
--- a/utils/Android.mk
+++ b/utils/Android.mk
@@ -1,5 +1,7 @@
 LOCAL_PATH := $(call my-dir)
 
+# Utils static library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_C_INCLUDES := \
@@ -7,9 +9,7 @@
 	$(LOCAL_PATH)/../btcore/include \
 	$(LOCAL_PATH)/../stack/include \
 	$(LOCAL_PATH)/../ \
-	$(bdroid_C_INCLUDES)
-
-LOCAL_CFLAGS += $(bdroid_CFLAGS) -std=c99
+	$(bluetooth_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
 	./src/bt_utils.c
@@ -18,4 +18,8 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_STATIC_LIBRARY)
diff --git a/vendor_libs/linux/Android.mk b/vendor_libs/linux/Android.mk
index 4bebb1d..c5b120d 100644
--- a/vendor_libs/linux/Android.mk
+++ b/vendor_libs/linux/Android.mk
@@ -18,6 +18,8 @@
 
 ifeq ($(BOARD_HAVE_BLUETOOTH_LINUX), true)
 
+# libbt-vendor shared library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
@@ -32,6 +34,10 @@
 LOCAL_MODULE := libbt-vendor
 LOCAL_MODULE_TAGS := optional
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_SHARED_LIBRARY)
 
 endif  # BOARD_HAVE_BLUETOOTH_LINUX
diff --git a/vendor_libs/test_vendor_lib/Android.mk b/vendor_libs/test_vendor_lib/Android.mk
index edd59db..3874ef2 100644
--- a/vendor_libs/test_vendor_lib/Android.mk
+++ b/vendor_libs/test_vendor_lib/Android.mk
@@ -1,5 +1,7 @@
 LOCAL_PATH := $(call my-dir)
 
+# test-vendor shared library for target
+# ========================================================
 include $(CLEAR_VARS)
 
 BT_DIR := $(TOP_DIR)system/bt
@@ -33,8 +35,14 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_SHARED_LIBRARY)
 
+# test-vendor unit tests for host
+# ========================================================
 ifeq ($(HOST_OS), linux)
 include $(CLEAR_VARS)
 
@@ -61,5 +69,9 @@
 LOCAL_MODULE := test-vendor_test_host
 LOCAL_MODULE_TAGS := tests
 
+LOCAL_CFLAGS += $(bluetooth_CFLAGS)
+LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
+LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)
+
 include $(BUILD_HOST_NATIVE_TEST)
 endif