[PATCH 3/3] Makefile: use -Wdeclaration-after-statement if supported
- From
Adam Spiers <git@adamspiers.org>
- Date
- Dec 16, 2012, 19:36 UTC
- Message-ID
- <1355686561-1057-4-git-send-email-git@adamspiers.org>
- In-Reply-To
- <1355686561-1057-1-git-send-email-git@adamspiers.org>
CodingGuidelines requests that code should be nice to older C compilers. Since modern gcc can warn on code written using newer dialects such as C99, it makes sense to take advantage of this by auto-detecting this capability and enabling it when found.
Signed-off-by: Adam Spiers <git@adamspiers.org> --- If we adopt this approach, it may make sense to enable other flags where available (e.g. -Wzero-as-null-pointer-constant, maybe even -ansi). In that case, something like this might be a more efficient way of writing it:
GCC_FLAGS=-Wdeclaration-after-statement,-Wanother-flag,-Wand-another
GCC_FLAGS_REGEXP=$(shell echo $(GCC_FLAGS) | sed 's/,/\\|/g')
GCC_SUPPORTED_FLAGS=$(shell cc --help -v 2>&1 | \
sed -n '/.* \($(GCC_FLAGS_REGEXP)\) .*/{s//\1/;p}')Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index a49d1db..aae70d4 100644 --- a/Makefile +++ b/Makefile @@ -331,8 +331,13 @@ endif # CFLAGS and LDFLAGS are for the users to override from the command line. CFLAGS = -g -O2 -Wall +GCC_DECL_AFTER_STATEMENT = \ + $(shell $(CC) --help -v 2>&1 | \ + grep -q -- -Wdeclaration-after-statement && \ + echo -Wdeclaration-after-statement) +GCC_FLAGS = $(GCC_DECL_AFTER_STATEMENT) +ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) $(GCC_FLAGS) LDFLAGS = -ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS) STRIP ?= strip
-- 1.7.12.1.396.g53b3ea9