2016-05-18 18:49:30 +00:00
|
|
|
AC_DEFUN([_NM_COMPILER_FLAG], [
|
2015-03-18 18:02:29 +00:00
|
|
|
CFLAGS_SAVED="$CFLAGS"
|
2016-05-18 18:49:36 +00:00
|
|
|
CFLAGS="$CFLAGS $GLIB_CFLAGS -Werror $1"
|
2016-05-18 18:49:30 +00:00
|
|
|
AC_MSG_CHECKING([whether $1 works as expected])
|
2015-03-18 18:02:29 +00:00
|
|
|
|
|
|
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [
|
|
|
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[$2]])], [
|
|
|
|
AC_MSG_RESULT(yes)
|
2016-05-18 18:49:30 +00:00
|
|
|
CFLAGS="$CFLAGS_SAVED"
|
|
|
|
$3
|
2015-03-18 18:02:29 +00:00
|
|
|
],[
|
|
|
|
AC_MSG_RESULT(no)
|
2016-05-18 18:49:30 +00:00
|
|
|
CFLAGS="$CFLAGS_SAVED"
|
|
|
|
$4
|
2015-03-18 18:02:29 +00:00
|
|
|
])
|
|
|
|
],[
|
|
|
|
AC_MSG_RESULT(not supported)
|
|
|
|
CFLAGS="$CFLAGS_SAVED"
|
|
|
|
])
|
|
|
|
])
|
|
|
|
|
2016-05-18 18:49:30 +00:00
|
|
|
dnl Check whether a particular compiler flag is supported,
|
2018-02-16 14:49:17 +00:00
|
|
|
dnl append it to the specified variable if the check succeeds.
|
|
|
|
dnl NM_COMPILER_FLAG([ENV-VAR], [FLAG], [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
|
2016-05-18 18:49:30 +00:00
|
|
|
AC_DEFUN([NM_COMPILER_FLAG], [
|
2018-02-16 14:49:17 +00:00
|
|
|
_NM_COMPILER_FLAG([$2], [], [
|
|
|
|
eval "AS_TR_SH([$1])='$$1 $2'"
|
|
|
|
$3
|
|
|
|
], [$4])
|
2016-05-18 18:49:30 +00:00
|
|
|
])
|
|
|
|
|
2022-08-11 08:56:59 +00:00
|
|
|
dnl Check whether a particular warning is supported. If yes, the flag
|
|
|
|
dnl is appended to [ENV-VAR].
|
|
|
|
dnl NM_COMPILER_WARNING_FLAG([ENV-VAR], [WARNING])
|
|
|
|
AC_DEFUN([NM_COMPILER_WARNING_FLAG], [
|
|
|
|
dnl "-Wno-*" requires special handling, see https://gcc.gnu.org/wiki/FAQ#wnowarning.
|
|
|
|
_NM_COMPILER_FLAG([-Wall $(printf '%s' "$2" | sed -e 's/^-W\(no-\|no-error=\)/-W/')], [], [eval "AS_TR_SH([$1])='$$1 $2'"], [])
|
|
|
|
])
|
|
|
|
|
2016-05-18 18:49:30 +00:00
|
|
|
dnl Check whether a particular warning is not emitted with code provided,
|
2018-02-16 14:49:17 +00:00
|
|
|
dnl append an option to disable the warning to a specified variable if the check fails.
|
2022-08-11 08:56:59 +00:00
|
|
|
dnl Note that this always either adds -W$2 or -Wno-$2, depending on whether it's supported.
|
2018-09-04 08:25:19 +00:00
|
|
|
dnl NM_COMPILER_WARNING([ENV-VAR], [WARNING], [C-SNIPPET])
|
2016-05-18 18:49:30 +00:00
|
|
|
AC_DEFUN([NM_COMPILER_WARNING], [
|
2018-02-16 14:49:17 +00:00
|
|
|
_NM_COMPILER_FLAG([-W$2], [$3], [eval "AS_TR_SH([$1])='$$1 -W$2'"], [eval "AS_TR_SH([$1])='$$1 -Wno-$2'"])
|
2016-05-18 18:49:30 +00:00
|
|
|
])
|
|
|
|
|
2018-02-16 14:49:17 +00:00
|
|
|
dnl NM_COMPILER_WARNINGS([ENV-VAR], [MORE-WARNINGS])
|
2009-04-22 00:50:45 +00:00
|
|
|
AC_DEFUN([NM_COMPILER_WARNINGS],
|
|
|
|
[AC_ARG_ENABLE(more-warnings,
|
2012-01-29 21:01:56 +00:00
|
|
|
AS_HELP_STRING([--enable-more-warnings], [Possible values: no/yes/error]),
|
2018-02-16 14:49:17 +00:00
|
|
|
set_more_warnings="$enableval",set_more_warnings=$2)
|
2011-04-26 18:55:52 +00:00
|
|
|
AC_MSG_CHECKING(for more warnings)
|
2009-04-22 00:50:45 +00:00
|
|
|
if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
|
|
|
|
AC_MSG_RESULT(yes)
|
2015-03-18 18:02:29 +00:00
|
|
|
|
|
|
|
dnl This is enabled in clang by default, makes little sense,
|
|
|
|
dnl and causes the build to abort with -Werror.
|
2018-09-04 08:25:19 +00:00
|
|
|
CFLAGS_SAVED="$CFLAGS"
|
|
|
|
CFLAGS="$CFLAGS -Qunused-arguments"
|
|
|
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([])], eval "AS_TR_SH([$1])='$$1 -Qunused-arguments'", [])
|
|
|
|
CFLAGS="$CFLAGS_SAVED"
|
2009-04-22 00:50:45 +00:00
|
|
|
|
2014-07-26 18:11:31 +00:00
|
|
|
dnl clang only warns about unknown warnings, unless
|
|
|
|
dnl called with "-Werror=unknown-warning-option"
|
|
|
|
dnl Test if the compiler supports that, and if it does
|
|
|
|
dnl attach it to the CFLAGS.
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [unknown-warning-option], [])
|
2015-03-18 18:02:29 +00:00
|
|
|
|
build: pass -std=gnu99 to compiler
With --enable-more-warnings, we already used -std=gnu99, see
commit ba2b2de3adcf3e8286249523e3841858e0c2655c.
Compilation may behave differently depending on the selected
C standard that we choose. It seems wrong, with more-warnings,
to build against a C standard, while otherwise leaving it undefind.
Indeed, one might argue, that our build system should not use
such compiler specific options. At least, not without detecting
support for the compiler option during ./configure.
However:
- we already did this for --enable-more-warnings.
- we should not program against a theoretical compiler. In practice,
only gcc and clang works to build NetworkManager. Both these compilers
support this option, so there is no reason to not use it. If we ever
come into the situation to support another compiler, adjusting -std=gnu99
will be the smallest problem. Until that happens (and that's far from
imminent), don't pretend to be portable to non-existing compilers and
use the flag that in practice is available.
See-also: https://gcc.gnu.org/onlinedocs/gcc/Standards.html
2018-07-12 08:23:35 +00:00
|
|
|
CFLAGS_MORE_WARNINGS="-Wall"
|
2015-03-18 18:02:29 +00:00
|
|
|
|
2020-08-14 11:57:38 +00:00
|
|
|
if test "x$enable_lto" = xyes; then
|
|
|
|
dnl With LTO and optimizations enabled, gcc 10.2.1-1.fc32 is really
|
2021-01-08 10:18:35 +00:00
|
|
|
dnl adamant to warn about correct uses of strncpy. Disable "-Wstringop-overflow".
|
2021-01-08 11:36:23 +00:00
|
|
|
_CFLAGS_MORE_WARNINGS_DISABLE_LTO="-Wno-stringop-overflow"
|
2021-01-08 10:18:35 +00:00
|
|
|
|
|
|
|
dnl We want to build with "-Wmaybe-uninitialized" enabled. With LTO that
|
|
|
|
dnl can easily lead to false positives. For manual testing, disable the
|
|
|
|
dnl warning here by uncommenting the following line.
|
|
|
|
dnl _CFLAGS_MORE_WARNINGS_DISABLE_LTO="$_CFLAGS_MORE_WARNINGS_DISABLE_LTO -Wno-error=maybe-uninitialized"
|
2020-08-14 11:57:38 +00:00
|
|
|
else
|
|
|
|
_CFLAGS_MORE_WARNINGS_DISABLE_LTO=
|
|
|
|
fi
|
|
|
|
|
2015-03-18 18:02:29 +00:00
|
|
|
if test "x$set_more_warnings" = xerror; then
|
|
|
|
CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS -Werror"
|
2014-07-26 18:11:31 +00:00
|
|
|
fi
|
|
|
|
|
2017-02-06 13:23:35 +00:00
|
|
|
for option in \
|
2020-08-14 11:57:38 +00:00
|
|
|
$_CFLAGS_MORE_WARNINGS_DISABLE_LTO \
|
2022-11-03 09:21:50 +00:00
|
|
|
-Wall \
|
2017-02-06 17:24:33 +00:00
|
|
|
-Wextra \
|
2022-12-01 12:43:48 +00:00
|
|
|
-Wcast-align=strict \
|
2017-02-06 13:23:35 +00:00
|
|
|
-Wdeclaration-after-statement \
|
|
|
|
-Wfloat-equal \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wformat-nonliteral \
|
|
|
|
-Wformat-security \
|
2017-02-06 13:23:35 +00:00
|
|
|
-Wimplicit-function-declaration \
|
2022-11-03 09:16:10 +00:00
|
|
|
-Wimplicit-int \
|
2017-02-06 13:23:35 +00:00
|
|
|
-Winit-self \
|
2022-11-03 09:16:10 +00:00
|
|
|
-Wint-conversion \
|
2017-05-18 16:11:10 +00:00
|
|
|
-Wlogical-op \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wmissing-declarations \
|
2017-02-06 13:23:35 +00:00
|
|
|
-Wmissing-include-dirs \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wmissing-prototypes \
|
2022-11-03 09:16:10 +00:00
|
|
|
-Wold-style-definition \
|
2022-11-03 09:21:50 +00:00
|
|
|
-Wparentheses-equality \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wpointer-arith \
|
|
|
|
-Wshadow \
|
2017-05-18 16:11:10 +00:00
|
|
|
-Wshift-negative-value \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wstrict-prototypes \
|
2022-11-03 09:21:50 +00:00
|
|
|
-Wtypedef-redefinition \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wundef \
|
2022-11-03 09:21:50 +00:00
|
|
|
-Wunknown-attributes \
|
2017-12-11 15:24:42 +00:00
|
|
|
-Wvla \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wno-duplicate-decl-specifier \
|
2017-02-06 13:52:51 +00:00
|
|
|
-Wno-format-truncation \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wno-format-y2k \
|
2022-11-03 09:21:50 +00:00
|
|
|
-Wno-gnu-variable-sized-type-not-at-end \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wno-missing-field-initializers \
|
|
|
|
-Wno-pragmas \
|
|
|
|
-Wno-sign-compare \
|
2020-02-21 09:25:55 +00:00
|
|
|
-Wno-tautological-constant-out-of-range-compare \
|
2019-05-28 11:08:32 +00:00
|
|
|
-Wno-unknown-pragmas \
|
2017-02-06 18:17:49 +00:00
|
|
|
-Wno-unused-parameter \
|
2017-02-06 13:23:35 +00:00
|
|
|
; do
|
2015-02-24 17:11:21 +00:00
|
|
|
dnl GCC 4.4 does not warn when checking for -Wno-* flags (https://gcc.gnu.org/wiki/FAQ#wnowarning)
|
2021-01-08 10:18:35 +00:00
|
|
|
_NM_COMPILER_FLAG([-Wall $(printf '%s' "$option" | sed -e 's/^-W\(no-\|no-error=\)/-W/')], [],
|
2016-05-18 18:49:30 +00:00
|
|
|
[CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS $option"], [])
|
2009-04-22 00:50:45 +00:00
|
|
|
done
|
|
|
|
unset option
|
2015-03-18 18:02:29 +00:00
|
|
|
|
|
|
|
dnl Disable warnings triggered by known compiler problems
|
|
|
|
|
|
|
|
dnl https://bugzilla.gnome.org/show_bug.cgi?id=745821
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [unknown-attributes], [#include <glib.h>])
|
2015-03-18 18:02:29 +00:00
|
|
|
|
2015-03-19 15:29:33 +00:00
|
|
|
dnl https://bugzilla.gnome.org/show_bug.cgi?id=744473
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [typedef-redefinition], [#include <gio/gio.h>])
|
2015-03-19 15:29:33 +00:00
|
|
|
|
2015-03-18 18:02:29 +00:00
|
|
|
dnl https://llvm.org/bugs/show_bug.cgi?id=21614
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [array-bounds],
|
2015-03-18 18:02:29 +00:00
|
|
|
[#include <string.h>]
|
|
|
|
[void f () { strcmp ("something", "0"); }]
|
|
|
|
)
|
|
|
|
|
|
|
|
dnl https://llvm.org/bugs/show_bug.cgi?id=22949
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [parentheses-equality],
|
2015-03-18 18:02:29 +00:00
|
|
|
[#include <sys/wait.h>]
|
|
|
|
[void f () { if (WIFCONTINUED(0)) return; }]
|
|
|
|
)
|
|
|
|
|
|
|
|
dnl systemd-dhcp's log_internal macro and our handle_warn are sometimes
|
|
|
|
dnl used in void context,u sometimes in int. Makes clang unhappy.
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [unused-value],
|
2015-03-18 18:02:29 +00:00
|
|
|
[#define yolo ({ (666 + 666); })]
|
|
|
|
[int f () { int i = yolo; yolo; return i; }]
|
2017-04-15 10:23:42 +00:00
|
|
|
)
|
|
|
|
|
2018-02-07 10:23:08 +00:00
|
|
|
dnl a new warning in gcc 8, glib 2.55 doesn't play nice yet
|
2018-02-07 20:01:49 +00:00
|
|
|
dnl https://bugzilla.gnome.org/show_bug.cgi?id=793272
|
2018-02-16 14:49:17 +00:00
|
|
|
NM_COMPILER_WARNING([$1], [cast-function-type],
|
2018-02-07 10:23:08 +00:00
|
|
|
[#include <glib-object.h>]
|
|
|
|
[typedef struct { GObject parent; } NMObject;]
|
|
|
|
[typedef struct { GObjectClass parent; } NMObjectClass;]
|
|
|
|
[static void nm_object_init (NMObject *object) { } ]
|
|
|
|
[static void nm_object_class_init (NMObjectClass *object) { }]
|
|
|
|
[G_DEFINE_TYPE (NMObject, nm_object, G_TYPE_OBJECT)]
|
|
|
|
)
|
|
|
|
|
2020-02-21 12:22:23 +00:00
|
|
|
dnl clang started supporting -Wimplicit-fallthrough, but it does not
|
|
|
|
dnl honor the code comments to suppress the warning. Disable the
|
|
|
|
dnl warning with clang.
|
|
|
|
dnl
|
|
|
|
NM_COMPILER_WARNING([$1], [implicit-fallthrough],
|
|
|
|
[int foo(int a);
|
|
|
|
int foo(int a) {
|
|
|
|
int r = 0;
|
|
|
|
switch (a) {
|
|
|
|
case 1:
|
|
|
|
r++;
|
|
|
|
/* fall-through */
|
|
|
|
case 2:
|
|
|
|
r++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}]
|
|
|
|
)
|
|
|
|
|
2018-02-16 14:49:17 +00:00
|
|
|
eval "AS_TR_SH([$1])='$CFLAGS_MORE_WARNINGS $$1'"
|
2009-04-22 00:50:45 +00:00
|
|
|
else
|
|
|
|
AC_MSG_RESULT(no)
|
|
|
|
fi
|
|
|
|
])
|
2017-02-10 10:28:01 +00:00
|
|
|
|
|
|
|
AC_DEFUN([NM_LTO],
|
2019-04-15 13:35:53 +00:00
|
|
|
[AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto], [Enable Link Time Optimization for smaller size [default=no]]))
|
2017-02-10 10:28:01 +00:00
|
|
|
if (test "${enable_lto}" = "yes"); then
|
2019-02-02 14:57:01 +00:00
|
|
|
CC_CHECK_FLAG_APPEND([lto_flags], [CFLAGS], [-flto -flto-partition=none])
|
2017-02-10 11:22:21 +00:00
|
|
|
if (test -n "${lto_flags}"); then
|
2019-02-02 14:57:01 +00:00
|
|
|
CFLAGS="-flto -flto-partition=none $CFLAGS"
|
2017-02-10 11:22:21 +00:00
|
|
|
else
|
|
|
|
AC_MSG_ERROR([Link Time Optimization -flto is not supported.])
|
|
|
|
fi
|
2017-02-10 10:28:01 +00:00
|
|
|
else
|
2017-02-10 11:22:21 +00:00
|
|
|
enable_lto='no'
|
2017-02-10 10:28:01 +00:00
|
|
|
fi
|
|
|
|
])
|
|
|
|
|
|
|
|
AC_DEFUN([NM_LD_GC],
|
2019-04-15 13:35:53 +00:00
|
|
|
[AC_ARG_ENABLE(ld-gc, AS_HELP_STRING([--enable-ld-gc], [Enable garbage collection of unused symbols on linking [default=auto]]))
|
2017-02-10 10:28:01 +00:00
|
|
|
if (test "${enable_ld_gc}" != "no"); then
|
|
|
|
CC_CHECK_FLAG_APPEND([ld_gc_flags], [CFLAGS], [-fdata-sections -ffunction-sections -Wl,--gc-sections])
|
|
|
|
if (test -n "${ld_gc_flags}"); then
|
|
|
|
enable_ld_gc="yes"
|
2017-02-10 11:22:21 +00:00
|
|
|
CFLAGS="$ld_gc_flags $CFLAGS"
|
2017-02-10 10:28:01 +00:00
|
|
|
else
|
|
|
|
if (test "${enable_ld_gc}" = "yes"); then
|
|
|
|
AC_MSG_ERROR([Unused symbol eviction requested but not supported.])
|
|
|
|
else
|
|
|
|
enable_ld_gc="no"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
])
|
|
|
|
|