From e95a4c50a9bd1dd38e17ece6debd93bdde6bbaf0 Mon Sep 17 00:00:00 2001
From: Joakim Gebart <joakim.gebart@eistec.se>
Date: Tue, 21 Jul 2015 07:05:14 +0200
Subject: [PATCH] make: Build with -Werror by default

Can be overridden from the environment by setting WERROR=0

also remove reversed logic for Werror in Makefile.buildtest
(a typo caused Werror to be always enabled for all builds)
---
 Makefile.buildtests |  6 +-----
 Makefile.docker     |  1 +
 Makefile.include    | 13 ++++++++++---
 Makefile.scan-build |  1 +
 Makefile.vars       |  1 +
 5 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/Makefile.buildtests b/Makefile.buildtests
index f87a19cfac..0a9594fe5d 100644
--- a/Makefile.buildtests
+++ b/Makefile.buildtests
@@ -31,11 +31,6 @@ endif
         info-buildsizes-diff info-build info-boards-supported \
         info-features-missing info-boards-features-missing
 
-# Make buildtests error out on warnings by adding -Werror
-ifeq (, $(filter buildtest, $(MAKECMDGOALS)))
-    CFLAGS+=-Werror
-endif
-
 ifeq ($(BUILD_IN_DOCKER),1)
 buildtest: ..in-docker-container
 else
@@ -63,6 +58,7 @@ buildtest:
 					BINDIRBASE=$${BINDIRBASE} \
 					RIOTNOLINK=$${RIOTNOLINK} \
 					RIOT_VERSION=$${RIOT_VERSION} \
+					WERROR=$${WERROR} \
 					$(MAKE) -j$(NPROC) 2>&1) ; \
 			if [ "$${?}" = "0" ]; then \
 				${COLOR_ECHO} "${COLOR_GREEN}success${COLOR_RESET}"; \
diff --git a/Makefile.docker b/Makefile.docker
index 464e1dff2f..02b087b1de 100644
--- a/Makefile.docker
+++ b/Makefile.docker
@@ -50,6 +50,7 @@ export DOCKER_ENV_VARS = \
   OFLAGS \
   PREFIX \
   QUIET \
+  WERROR \
   RIOT_VERSION \
   SCANBUILD_ARGS \
   SCANBUILD_OUTPUTDIR \
diff --git a/Makefile.include b/Makefile.include
index c2bb0fb057..1b72b31377 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -64,10 +64,17 @@ else
 endif
 
 ifeq ($(QUIET),1)
-	AD=@
-	MAKEFLAGS += --no-print-directory
+  AD=@
+  MAKEFLAGS += --no-print-directory
 else
-	AD=
+  AD=
+endif
+
+# Fail on warnings. Can be overridden by `make WERROR=0`.
+WERROR ?= 1
+export WERROR
+ifeq ($(WERROR),1)
+  CFLAGS += -Werror
 endif
 
 ifneq (10,$(if ${RIOT_VERSION},1,0)$(if ${__RIOTBUILD_FLAG},1,0))
diff --git a/Makefile.scan-build b/Makefile.scan-build
index 5137d05a2c..a12faf29dc 100644
--- a/Makefile.scan-build
+++ b/Makefile.scan-build
@@ -25,6 +25,7 @@ SCANBUILD_ENV_VARS := \
   PATH \
   PREFIX \
   QUIET \
+  WERROR \
   RIOT_VERSION \
   SIZE \
   TOOLCHAIN \
diff --git a/Makefile.vars b/Makefile.vars
index 49fca3116c..2b67ff7fe7 100644
--- a/Makefile.vars
+++ b/Makefile.vars
@@ -37,6 +37,7 @@ export OBJCOPY               # The command used to create the HEXFILE.
 export OFLAGS                # The parameter for OBJCOPY, e.g. to strip the debug information.
 export SIZE                  # The command to read to size of the ELF sections.
 export UNDEF                 # Set by the BOARD's and CPU's Makefile.include, this contains object files with must not be used in the ELFFILE even if the if no call to the functions.
+export WERROR                # Treat all compiler warnings as errors if set to 1 (see -Werror flag in GCC manual)
 
 export FLASHER               # The command to call on "make flash".
 export FFLAGS                # The parameters to supply to FLASHER.
-- 
GitLab