mk: fix cross build

The "-Wimplicit-fallthrough=2" option was introduced into gcc 7.0, it was
enabled when the cross compiler gcc is greater than 7.0, but for the host
side buildtools/pmdinfogen, if the native gcc is older than 7.0, or the
host cc compiler is clang, it should not be enabled.

The fix is to differentiate the host gcc Werror options from the cross gcc.

gcc -Wp,-MD,./.pmdinfogen.o.d.tmp  -W -Wall -Wstrict-prototypes
-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition
-Wpointer-arith -Wcast-align -Wnested-externs -Wcast-qual
-Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wdeprecated
-Werror -Wimplicit-fallthrough=2 -Dbbb -Wno-format-truncation -g
-I/dpdk/build/include    -o pmdinfogen.o -c
~/dpdk/buildtools/pmdinfogen/pmdinfogen.c gcc: error:
unrecognized command line option ‘-Wimplicit-fallthrough=2’

Fixes: ced3e6f8 ("mk: adjust gcc flags for new gcc 7 warnings")
Cc: stable@dpdk.org

Signed-off-by: Gavin Hu <gavin.hu@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Steve Capper <steve.capper@arm.com>
Tested-by: Ali Alnubani <alialnu@mellanox.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
This commit is contained in:
Gavin Hu 2018-06-30 01:27:33 +08:00 committed by Thomas Monjalon
parent 26fd4b7312
commit ebaa070de8
3 changed files with 15 additions and 1 deletions

View File

@ -41,7 +41,7 @@ HOSTAPP = dpdk-pmdinfogen
#
SRCS-y += pmdinfogen.c
HOST_CFLAGS += $(WERROR_FLAGS) -g
HOST_CFLAGS += $(HOST_WERROR_FLAGS) -g
HOST_CFLAGS += -I$(RTE_OUTPUT)/include
include $(RTE_SDK)/mk/rte.hostapp.mk

View File

@ -15,6 +15,11 @@ GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
GCC_PATCHLEVEL = $(shell echo __GNUC_PATCHLEVEL__ | $(CC) -E -x c - | tail -n 1)
GCC_VERSION = $(GCC_MAJOR)$(GCC_MINOR)
HOST_GCC_MAJOR = $(shell echo __GNUC__ | $(HOSTCC) -E -x c - | tail -n 1)
HOST_GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(HOSTCC) -E -x c - | tail -n 1)
HOST_GCC_PATCHLEVEL = $(shell echo __GNUC_PATCHLEVEL__ | $(HOSTCC) -E -x c - | tail -n 1)
HOST_GCC_VERSION = $(HOST_GCC_MAJOR)$(HOST_GCC_MINOR)
# if GCC is older than 4.x
ifeq ($(shell test $(GCC_VERSION) -lt 40 && echo 1), 1)
MACHINE_CFLAGS =

View File

@ -71,6 +71,15 @@ ifeq ($(shell test $(GCC_VERSION) -lt 47 && echo 1), 1)
WERROR_FLAGS += -Wno-uninitialized
endif
HOST_WERROR_FLAGS := $(WERROR_FLAGS)
ifeq ($(shell test $(HOST_GCC_VERSION) -gt 70 && echo 1), 1)
# Tell GCC only to error for switch fallthroughs without a suitable comment
HOST_WERROR_FLAGS += -Wimplicit-fallthrough=2
# Ignore errors for snprintf truncation
HOST_WERROR_FLAGS += -Wno-format-truncation
endif
ifeq ($(shell test $(GCC_VERSION) -gt 70 && echo 1), 1)
# Tell GCC only to error for switch fallthroughs without a suitable comment
WERROR_FLAGS += -Wimplicit-fallthrough=2