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,
|
|
|
|
dnl add it to CFLAGS if it is
|
|
|
|
AC_DEFUN([NM_COMPILER_FLAG], [
|
|
|
|
_NM_COMPILER_FLAG([$1], [], [
|
|
|
|
CFLAGS="$CFLAGS $1"
|
|
|
|
$2
|
|
|
|
], [$3])
|
|
|
|
])
|
|
|
|
|
|
|
|
dnl Check whether a particular warning is not emitted with code provided,
|
|
|
|
dnl disable it in CFLAGS if the check fails.
|
|
|
|
AC_DEFUN([NM_COMPILER_WARNING], [
|
|
|
|
_NM_COMPILER_FLAG([-W$1], [$2], [CFLAGS="$CFLAGS -W$1"], [CFLAGS="$CFLAGS -Wno-$1"])
|
|
|
|
])
|
|
|
|
|
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]),
|
2017-01-18 10:08:10 +00:00
|
|
|
set_more_warnings="$enableval",set_more_warnings=$1)
|
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.
|
2014-10-29 10:52:47 +00:00
|
|
|
CFLAGS_SAVED="$CFLAGS"
|
2015-03-18 18:02:29 +00:00
|
|
|
CFLAGS="$CFLAGS -Qunused-arguments"
|
|
|
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([])], [], CFLAGS="$CFLAGS_SAVED")
|
|
|
|
unset 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.
|
2015-03-18 18:02:29 +00:00
|
|
|
NM_COMPILER_WARNING([unknown-warning-option], [])
|
|
|
|
|
build: allow using GCC C99 dialect instead of C89
We already use several GCC extenions, like typeof() and
__attribute__((cleanup)). They are too convinient to miss
and every supported compiler must support these.
Currently, gcc and clang does. Maybe other compilers would
support that too, but who knows, nobody seems to test that.
We also already use stdbool.h (C99) and the imported systemd
code is mostly gnu99 too (it's not clear to me, because I don't
find it precisely documented. Certainly it makes use of C99 features
too).
C99/gnu99 has some nice improvements that we no longer should miss
out. For example "flexible array members" or "variable declaration
in init-part of for loop".
It doesn't mean we have to use every obscure (badly supported?)
feature, it means we don't have to forgo features that are well
supported. C99 is 17 years old, I mean, really...
If somebody comes along and ports NM to non-gcc/clang, we can address
bugs about unsupported language features as they surface.
But let's not restrict us to some hypothetical compiler (or language
specification).
Also, NetworkManager is not ported on environment beside Linux.
We don't have to be so considerate about the required build environment.
Gcc is probably the most portable compiler out there. I doubt porting
NetworkManager to *BSD fails due to missing gnu99 features. And if that
causes issues, we should fix them after they happen in practice.
2016-11-10 07:28:39 +00:00
|
|
|
CFLAGS_MORE_WARNINGS="-Wall -std=gnu99"
|
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 \
|
2017-02-06 17:24:33 +00:00
|
|
|
-Wextra \
|
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 \
|
|
|
|
-Wimplicit-fallthrough \
|
2017-02-06 13:23:35 +00:00
|
|
|
-Wimplicit-function-declaration \
|
|
|
|
-Winit-self \
|
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 \
|
|
|
|
-Wpointer-arith \
|
|
|
|
-Wshadow \
|
|
|
|
-Wstrict-prototypes \
|
|
|
|
-Wundef \
|
|
|
|
-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 \
|
|
|
|
-Wno-missing-field-initializers \
|
|
|
|
-Wno-pragmas \
|
|
|
|
-Wno-sign-compare \
|
|
|
|
-Wno-unused-but-set-variable \
|
|
|
|
-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)
|
2016-05-18 18:49:30 +00:00
|
|
|
_NM_COMPILER_FLAG([$(printf '%s' "$option" | sed 's/^-Wno-/-W/')], [],
|
|
|
|
[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
|
|
|
|
NM_COMPILER_WARNING([unknown-attributes], [#include <glib.h>])
|
|
|
|
|
2015-03-19 15:29:33 +00:00
|
|
|
dnl https://bugzilla.gnome.org/show_bug.cgi?id=744473
|
|
|
|
NM_COMPILER_WARNING([typedef-redefinition], [#include <gio/gio.h>])
|
|
|
|
|
2015-03-18 18:02:29 +00:00
|
|
|
dnl https://llvm.org/bugs/show_bug.cgi?id=21614
|
|
|
|
NM_COMPILER_WARNING([array-bounds],
|
|
|
|
[#include <string.h>]
|
|
|
|
[void f () { strcmp ("something", "0"); }]
|
|
|
|
)
|
|
|
|
|
|
|
|
dnl https://llvm.org/bugs/show_bug.cgi?id=22949
|
|
|
|
NM_COMPILER_WARNING([parentheses-equality],
|
|
|
|
[#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.
|
|
|
|
NM_COMPILER_WARNING([unused-value],
|
|
|
|
[#define yolo ({ (666 + 666); })]
|
|
|
|
[int f () { int i = yolo; yolo; return i; }]
|
2017-04-15 10:23:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
dnl clang 3.9 would like to see "{ { 0 } }" here, but that does not
|
|
|
|
dnl look too wise.
|
|
|
|
NM_COMPILER_WARNING([missing-braces],
|
|
|
|
[union { int a[1]; int b[2]; } c = { 0 }]
|
2015-03-18 18:02:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
CFLAGS="$CFLAGS_MORE_WARNINGS $CFLAGS"
|
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],
|
|
|
|
[AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto], [Enable Link Time Optimization for smaller size (default: no)]))
|
|
|
|
if (test "${enable_lto}" = "yes"); then
|
2017-02-10 11:22:21 +00:00
|
|
|
CC_CHECK_FLAG_APPEND([lto_flags], [CFLAGS], [-flto])
|
|
|
|
if (test -n "${lto_flags}"); then
|
|
|
|
CFLAGS="-flto $CFLAGS"
|
|
|
|
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],
|
|
|
|
[AC_ARG_ENABLE(ld-gc, AS_HELP_STRING([--enable-ld-gc], [Enable garbage collection of unused symbols on linking (default: auto)]))
|
|
|
|
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
|
|
|
|
])
|
|
|
|
|