From patchwork Wed Feb 25 23:38:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: make sure compiler supports warning flags X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 23734 Message-Id: <1235605127-2024-1-git-send-email-vapier@gentoo.org> To: linux-mtd@lists.infradead.org Date: Wed, 25 Feb 2009 18:38:47 -0500 From: Mike Frysinger List-Id: Linux MTD discussion mailing list Some compilers (like gcc-3.3) don't support all the newer -W flags that we are using. So import the compiler check found in the kernel and test each flag we add. The := is important so we only do the compiler tests once per `make` rather than every time we compile a file. Signed-off-by: Mike Frysinger --- common.mk | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/common.mk b/common.mk index 0e8c62b..3ff5cad 100644 --- a/common.mk +++ b/common.mk @@ -1,8 +1,18 @@ CC := $(CROSS)gcc AR := $(CROSS)ar RANLIB := $(CROSS)ranlib + +# Stolen from Linux build system +try-run = $(shell set -e; ($(1)) >/dev/null 2>&1 && echo "$(2)" || echo "$(3)"; echo CHECK $(2) >/dev/stderr) +cc-option = $(call try-run, $(CC) $(1) -c -xc /dev/null -o /dev/null,$(1),$(2)) + CFLAGS ?= -O2 -g -CFLAGS += -Wall -Wextra -Wwrite-strings -Wno-sign-compare -D_FILE_OFFSET_BITS=64 +WFLAGS := -Wall \ + $(call cc-option,-Wextra) \ + $(call cc-option,-Wwrite-strings) \ + $(call cc-option,-Wno-sign-compare) +CFLAGS += $(WFLAGS) +CPPFLAGS += -D_FILE_OFFSET_BITS=64 DESTDIR ?= /usr/local PREFIX=/usr