]> www.infradead.org Git - mtd-utils.git/commitdiff
make sure compiler supports warning flags
authorMike Frysinger <vapier@gentoo.org>
Thu, 26 Feb 2009 08:30:06 +0000 (03:30 -0500)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 27 Feb 2009 18:38:55 +0000 (20:38 +0200)
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 <vapier@gentoo.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
common.mk

index 0e8c62b89e4043c1786cf2541fd6bffca6472d4f..5e92b07e4e31da9c03370a0f2fdd05c15b2c5049 100644 (file)
--- 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)")
+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