From b9bc20f4da12f15b8950daea177e6dda42cd6c3f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 12 Jul 2018 10:23:35 +0200 Subject: [PATCH] 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 --- Makefile.am | 16 +++++++++++++++- m4/compiler_options.m4 | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9fe016445b..353f57fb81 100644 --- a/Makefile.am +++ b/Makefile.am @@ -105,6 +105,8 @@ endif endif +dflt_cppflags = -std=gnu99 + ############################################################################### # with autotools, it is not easily possible to generate these defines @@ -592,6 +594,7 @@ nodist_libnminclude_HEADERS += \ ############################################################################### dflt_cppflags_libnm_core = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -1216,6 +1219,7 @@ libnm_tests_libnm_vpn_plugin_utils_test_la_SOURCES = \ shared/nm-utils/nm-vpn-plugin-utils.h libnm_tests_libnm_vpn_plugin_utils_test_la_CFLAGS = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -1322,7 +1326,7 @@ EXTRA_DIST += shared/c-list/src/c-list.h ############################################################################### src_libsystemd_nm_la_cppflags = \ - $(dflt_cppflags_std) \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -1859,6 +1863,7 @@ EXTRA_DIST += \ libexec_PROGRAMS += src/dhcp/nm-dhcp-helper src_dhcp_nm_dhcp_helper_CPPFLAGS = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -DG_LOG_DOMAIN=\""nm-dhcp-helper"\" \ @@ -1920,6 +1925,7 @@ core_plugins += src/ppp/libnm-ppp-plugin.la pppd_plugin_LTLIBRARIES += src/ppp/nm-pppd-plugin.la src_ppp_nm_pppd_plugin_la_CPPFLAGS = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -3152,6 +3158,7 @@ noinst_LTLIBRARIES += \ dispatcher/libnm-dispatcher-core.la dispatcher_cppflags = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -3249,6 +3256,7 @@ EXTRA_DIST += \ check_programs += dispatcher/tests/test-dispatcher-envp dispatcher_tests_test_dispatcher_envp_CPPFLAGS = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -3289,6 +3297,7 @@ EXTRA_DIST += \ bin_PROGRAMS += clients/nm-online clients_nm_online_CPPFLAGS = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -3317,6 +3326,7 @@ EXTRA_DIST += \ ############################################################################### clients_cppflags = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-core \ @@ -3830,6 +3840,7 @@ lib_LTLIBRARIES += libnm-util/libnm-util.la libnm_util_libnm_util_includedir=$(includedir)/NetworkManager libnm_util_cppflags = \ + $(dflt_cppflags) \ -I$(srcdir)/libnm-util \ -I$(builddir)/libnm-util \ -I$(srcdir)/shared \ @@ -4041,6 +4052,7 @@ dist_dependencies += libnm-util/libnm-util.la ############################################################################### libnm_util_tests_cppflags = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-util \ @@ -4120,6 +4132,7 @@ EXTRA_DIST += \ ############################################################################### libnm_glib_cppflags = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-util \ @@ -4398,6 +4411,7 @@ dist_dependencies += \ ############################################################################### libnm_glib_tests_cppflags = \ + $(dflt_cppflags) \ -I$(srcdir)/shared \ -I$(builddir)/shared \ -I$(srcdir)/libnm-util \ diff --git a/m4/compiler_options.m4 b/m4/compiler_options.m4 index 8a3a9c4f5f..ee1712ebfa 100644 --- a/m4/compiler_options.m4 +++ b/m4/compiler_options.m4 @@ -58,7 +58,7 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then dnl attach it to the CFLAGS. NM_COMPILER_WARNING([$1], [unknown-warning-option], []) - CFLAGS_MORE_WARNINGS="-Wall -std=gnu99" + CFLAGS_MORE_WARNINGS="-Wall" if test "x$set_more_warnings" = xerror; then CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS -Werror"