Skip to content

Commit

Permalink
Cleanup C and C++ compiler flags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pavlin Radoslavov authored and Andre Eisenbach committed Feb 18, 2016
1 parent 0ec558b commit 0b60bb0
Show file tree
Hide file tree
Showing 27 changed files with 317 additions and 159 deletions.
58 changes: 42 additions & 16 deletions Android.mk
Original file line number Diff line number Diff line change
@@ -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 :=
8 changes: 6 additions & 2 deletions audio_a2dp_hw/Android.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
LOCAL_PATH := $(call my-dir)

# Audio A2DP shared library for target
# ========================================================
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
Expand All @@ -10,8 +12,6 @@ LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../utils/include

LOCAL_CFLAGS += -std=c99 $(bdroid_CFLAGS)

LOCAL_MODULE := audio.a2dp.default
LOCAL_MODULE_RELATIVE_PATH := hw

Expand All @@ -20,4 +20,8 @@ LOCAL_STATIC_LIBRARIES := libosi

LOCAL_MODULE_TAGS := optional

LOCAL_CFLAGS += $(bluetooth_CFLAGS)
LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)

include $(BUILD_SHARED_LIBRARY)
12 changes: 6 additions & 6 deletions bta/Android.mk
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down Expand Up @@ -99,7 +96,10 @@ LOCAL_C_INCLUDES+= . \
$(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)
34 changes: 23 additions & 11 deletions btcore/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,37 @@ btcoreCommonIncludes := \
# 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

Expand All @@ -79,27 +85,33 @@ endif
# 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
20 changes: 13 additions & 7 deletions btif/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,38 @@ btifCommonIncludes := \
$(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)
8 changes: 6 additions & 2 deletions conf/Android.mk
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,7 +10,8 @@ LOCAL_MODULE_TAGS := optional
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
Expand All @@ -17,7 +20,8 @@ LOCAL_MODULE_TAGS := optional
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
Expand Down
20 changes: 14 additions & 6 deletions device/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

LOCAL_PATH := $(call my-dir)

# Bluetooth device static library for target
# ========================================================
include $(CLEAR_VARS)

LOCAL_C_INCLUDES := \
Expand All @@ -27,38 +29,44 @@ LOCAL_C_INCLUDES := \
$(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

include $(BUILD_STATIC_LIBRARY)
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)
4 changes: 0 additions & 4 deletions embdrv/Android.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
LOCAL_PATH := $(call my-dir)

include $(call all-subdir-makefiles)

# Cleanup our locals
#bdroid_C_INCLUDES :=
#bdroid_CFLaGS :=
4 changes: 0 additions & 4 deletions embdrv/sbc/Android.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
LOCAL_PATH := $(call my-dir)

include $(call all-subdir-makefiles)

# Cleanup our locals
#bdroid_C_INCLUDES :=
#bdroid_CFLaGS :=
7 changes: 7 additions & 0 deletions embdrv/sbc/decoder/Android.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
LOCAL_PATH:= $(call my-dir)

# Bluetooth SBC decoder static library for target
# ========================================================
include $(CLEAR_VARS)

# sbc decoder
Expand All @@ -25,4 +28,8 @@ LOCAL_MODULE:= libbt-qcom_sbc_decoder
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)
Loading

0 comments on commit 0b60bb0

Please sign in to comment.