]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Build: If using a GCC compatible compiler, ensure that -Werror works
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 26 Sep 2023 16:10:51 +0000 (19:10 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 2 Feb 2025 12:30:19 +0000 (14:30 +0200)
The check can be skipped by passing SKIP_WERROR_CHECK=yes to configure.
It won't be documented anywhere else than in the error message.

Ways to test:

    ./configure CC=gcc CFLAGS=-Wunused-macros
    ./configure CC=clang CFLAGS=-Weverything
    ./configure CC=clang CFLAGS=-Weverything SKIP_WERROR_CHECK=yes

configure.ac

index 3eef0aea9652584835a1d62bda63a9fe79426e91..e04e11b5fa442d7387e420e262989d49fc08fe82 100644 (file)
@@ -642,6 +642,32 @@ AM_PROG_CC_C_O
 AM_PROG_AS
 AC_USE_SYSTEM_EXTENSIONS
 
+# If using GCC or compatible compiler, verify that CFLAGS doesn't contain
+# something that makes -Werror unhappy. It's important to check this after
+# the above check for system extensions. It adds macros that can trigger,
+# for example, -Wunused-macros.
+if test "$GCC" = yes && test "x$SKIP_WERROR_CHECK" != xyes ; then
+       AC_MSG_CHECKING([if the -Werror option is usable])
+       OLD_CFLAGS=$CFLAGS
+       CFLAGS="$CFLAGS -Werror"
+       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[extern int foo; int foo;]])], [
+               AC_MSG_RESULT([yes])
+       ], [
+               AC_MSG_RESULT([no])
+               AC_MSG_ERROR([
+    CFLAGS contains something that makes -Werror complain (see config.log).
+    This would break certain checks in 'configure'. It is strongly
+    recommended to modify CFLAGS to fix this. If you want to use noisy
+    warning options, for example, -Weverything, it is still possible to
+    add them later when running 'make': make CFLAGS+=-Weverything
+
+    In case you really want to continue with the current CFLAGS, pass
+    'SKIP_WERROR_CHECK=yes' as an argument to 'configure'.
+               ])
+       ])
+       CFLAGS=$OLD_CFLAGS
+fi
+
 AS_CASE([$enable_threads],
        [posix], [
                echo