From 49f3fd5821994b4967186b5c17a011b3a609304b Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Fri, 18 Dec 2015 00:07:21 -0500
Subject: [PATCH] configure: build with -Werror by default

People can pass --disable-werror to turn this off.  But this will help
keep the main development builds clean with new code coming in.
---
 configure    | 19 ++++++++++++++++++-
 configure.ac | 14 +++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index bb31d53..70bc82a 100755
--- a/configure
+++ b/configure
@@ -705,6 +705,7 @@ with_binutils_include_dir
 with_binutils_ldscript_dir
 with_binutils_build_dir
 enable_ld_elf2flt_binary
+enable_werror
 enable_got_check
 enable_emit_relocs
 enable_emit_ctor_dtor
@@ -1333,6 +1334,7 @@ Optional Features:
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --disable-ld-elf2flt-binary
                           use ld-elf2flt shell script
+  --disable-werror        do not build with -Werror
   --disable-got-check     disable check for GOT (needed on H8)
   --disable-emit-relocs   don't use the --emit-relocs (-q) linker option
   --enable-emit-ctor-dtor manually create ctor/dtor list
@@ -2233,6 +2235,16 @@ var_yn_to_10() {
 	fi
 }
 
+# Check whether --enable-werror was given.
+if test "${enable_werror+set}" = set; then :
+  enableval=$enable_werror;  werror=$enableval
+else
+   werror=yes
+
+fi
+
+var_yn_to_10 werror
+
 # Check whether --enable-got-check was given.
 if test "${enable_got_check+set}" = set; then :
   enableval=$enable_got_check;  got_check=$enableval
@@ -4258,7 +4270,12 @@ fi
 done
 
 
-test "$GCC" = yes && CFLAGS="-Wall $CFLAGS"
+if test "$GCC" = yes ; then
+	CFLAGS="-Wall $CFLAGS"
+	if test "$werror" = 1 ; then
+		CFLAGS="-Werror -Wno-error=unused-label $CFLAGS"
+	fi
+fi
 
 
 
diff --git a/configure.ac b/configure.ac
index 951eb32..4e7df5a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,13 @@ var_yn_to_10() {
 	fi
 }
 
+AC_ARG_ENABLE(werror,
+	AS_HELP_STRING([--disable-werror], [do not build with -Werror]),
+	[ werror=$enableval ],
+	[ werror=yes ]
+)
+var_yn_to_10 werror
+
 AC_ARG_ENABLE(got-check,
 	AS_HELP_STRING([--disable-got-check], [disable check for GOT (needed on H8)]),
 	[ got_check=$enableval ],
@@ -203,7 +210,12 @@ AC_CHECK_FUNCS([ \
 	strsignal \
 ])
 
-test "$GCC" = yes && CFLAGS="-Wall $CFLAGS"
+if test "$GCC" = yes ; then
+	CFLAGS="-Wall $CFLAGS"
+	if test "$werror" = 1 ; then
+		CFLAGS="-Werror -Wno-error=unused-label $CFLAGS"
+	fi
+fi
 
 dnl Subsitute values
 AC_SUBST(target)
-- 
2.39.5