diff options
author | Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 2021-07-11 12:16:41 +0200 |
---|---|---|
committer | Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 2021-07-19 12:53:25 +0200 |
commit | d8c26804b465885737c854c01537021074ed2dae (patch) | |
tree | 1ea22161afa514c60e2ab1714dbfa651e68c971d | |
parent | 988038ea1006bf7e19c34da0ad6f6624dc0c68a0 (diff) | |
download | neard-d8c26804b465885737c854c01537021074ed2dae.tar.gz |
build: add more compiler warnings
Use the AX_CHECK_COMPILE_FLAG() macro from autoconf-archive to check for
support for more compiler warning flags (not enabled via -Wall and
-Wextra) and enable these which pass.
These flags are warning for:
1. Code bugs like dereferencing NULL or truncating string operations
functions.
2. Minor code quality or portability issues like using undefined
defines, wrong casts of functions, missing global function
declarations, skipping variable initializations, duplicated if
conditions or branches, usage of variable-length arrays.
3. Portability issues like implicit promoting float to double,
allocating zero bytes or depending of size of void *.
Keep more warnings for later, because the code does not build with them.
The AX_CHECK_COMPILE_FLAG() macro tries to compile C code with given
flag, so move the code from acinclude.m4 (executed early, before AC_LANG
and others) to separate accflags.m4.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
-rw-r--r-- | HACKING | 1 | ||||
-rw-r--r-- | accflags.m4 | 45 | ||||
-rw-r--r-- | acinclude.m4 | 17 | ||||
-rw-r--r-- | configure.ac | 5 |
4 files changed, 49 insertions, 19 deletions
@@ -7,6 +7,7 @@ Build tools requirements Required packages and tools: autoconf + autoconf-archive automake dbus gcc/clang diff --git a/accflags.m4 b/accflags.m4 new file mode 100644 index 0000000..b1bb150 --- /dev/null +++ b/accflags.m4 @@ -0,0 +1,45 @@ +AC_DEFUN([NEARD_COMPILER_FLAGS], [ + # AX_CHECK_COMPILE_FLAG comes from autoconf-archive + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AX_CHECK_COMPILE_FLAG]) + + if (test "${CFLAGS}" = ""); then + CFLAGS="-Wall -O2 -D_FORTIFY_SOURCE=2" + fi + if (test "$USE_MAINTAINER_MODE" = "yes"); then + CFLAGS="$CFLAGS -Werror -Wextra" + CFLAGS="$CFLAGS -Wno-unused-parameter" + CFLAGS="$CFLAGS -Wno-missing-field-initializers" + CFLAGS="$CFLAGS -Wdeclaration-after-statement" + CFLAGS="$CFLAGS -Wmissing-declarations" + CFLAGS="$CFLAGS -Wredundant-decls" + CFLAGS="$CFLAGS -Wcast-align" + CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED" + + AX_CHECK_COMPILE_FLAG([-Wdouble-promotion], [CFLAGS="$CFLAGS -Wdouble-promotion"]) + AX_CHECK_COMPILE_FLAG([-Wundef], [CFLAGS="$CFLAGS -Wundef"]) + AX_CHECK_COMPILE_FLAG([-Wbad-function-cast], [CFLAGS="$CFLAGS -Wbad-function-cast"]) + AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [CFLAGS="$CFLAGS -Wmissing-prototypes"]) + AX_CHECK_COMPILE_FLAG([-Wjump-misses-init], [CFLAGS="$CFLAGS -Wjump-misses-init"]) + AX_CHECK_COMPILE_FLAG([-Wpointer-arith], [CFLAGS="$CFLAGS -Wpointer-arith"]) + + # GCC v6.0 + AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [CFLAGS="$CFLAGS -Wnull-dereference"]) + AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], [CFLAGS="$CFLAGS -Wduplicated-cond"]) + # GCC v7.0 + AX_CHECK_COMPILE_FLAG([-Wduplicated-branches], [CFLAGS="$CFLAGS -Wduplicated-branches"]) + AX_CHECK_COMPILE_FLAG([-Wvla-larger-than=1], [CFLAGS="$CFLAGS -Wvla-larger-than=1"]) + AX_CHECK_COMPILE_FLAG([-Walloc-zero], [CFLAGS="$CFLAGS -Walloc-zero"]) + # GCC v8.0 + AX_CHECK_COMPILE_FLAG([-Wstringop-truncation], [CFLAGS="$CFLAGS -Wstringop-truncation"]) + fi + if (test "$USE_MAINTAINER_MODE" = "pedantic"); then + AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=3], [CFLAGS="$CFLAGS -Wstrict-overflow=3"]) + AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"]) + AX_CHECK_COMPILE_FLAG([-Wcast-qual], [CFLAGS="$CFLAGS -Wcast-qual"]) + AX_CHECK_COMPILE_FLAG([-Wunsafe-loop-optimizations], [CFLAGS="$CFLAGS -Wunsafe-loop-optimizations"]) + + # GCC v5.0 + AX_CHECK_COMPILE_FLAG([-Wformat-signedness], [CFLAGS="$CFLAGS -Wformat-signedness"]) + fi +]) diff --git a/acinclude.m4 b/acinclude.m4 index 027ed69..a12b939 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -9,20 +9,3 @@ AC_DEFUN([NEARD_PROG_CC_PIE], [ rm -rf conftest* ]) ]) - -AC_DEFUN([NEARD_COMPILER_FLAGS], [ - if (test "${CFLAGS}" = ""); then - CFLAGS="-Wall -O2 -D_FORTIFY_SOURCE=2" - fi - if (test "$USE_MAINTAINER_MODE" = "yes"); then - CFLAGS="$CFLAGS -Werror -Wextra" - CFLAGS="$CFLAGS -Werror -Wextra" - CFLAGS="$CFLAGS -Wno-unused-parameter" - CFLAGS="$CFLAGS -Wno-missing-field-initializers" - CFLAGS="$CFLAGS -Wdeclaration-after-statement" - CFLAGS="$CFLAGS -Wmissing-declarations" - CFLAGS="$CFLAGS -Wredundant-decls" - CFLAGS="$CFLAGS -Wcast-align" - CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED" - fi -]) diff --git a/configure.ac b/configure.ac index c4e8993..b9419c1 100644 --- a/configure.ac +++ b/configure.ac @@ -22,8 +22,6 @@ AC_SUBST(se_plugindir) PKG_PROG_PKG_CONFIG -NEARD_COMPILER_FLAGS - AC_LANG([C]) AC_PROG_CC @@ -34,6 +32,9 @@ AC_PROG_MKDIR_P m4_define([_LT_AC_TAGCONFIG], []) m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])]) +m4_include([accflags.m4]) +NEARD_COMPILER_FLAGS + LT_INIT([disable-static]) AM_CONDITIONAL(READLINE, test "${enable_readline}" = "yes") |