From 574b59a3550238d5a329903b5a03f817ae8bbd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 26 Dec 2013 21:16:14 -0500 Subject: [PATCH] configure: Verify that the compiler understands warning cflags Older compilers don't understand all of the flags --- .gitignore | 1 - agent/Makefile.am | 2 +- common.mk | 18 --------- configure.ac | 19 +++++++++ docs/reference/libnice/Makefile.am | 2 +- examples/Makefile.am | 2 +- m4/as-compiler-flag.m4 | 64 ++++++++++++++++++++++++++++++ nice/Makefile.am | 2 +- random/Makefile.am | 2 +- socket/Makefile.am | 2 +- stun/Makefile.am | 2 +- stun/tools/Makefile.am | 2 +- tests/Makefile.am | 2 +- 13 files changed, 92 insertions(+), 28 deletions(-) create mode 100644 m4/as-compiler-flag.m4 diff --git a/.gitignore b/.gitignore index b4f9b7c9..96957932 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,6 @@ stamp-h1 # top level stuff debian -m4 # address/ stuff address/libaddress.la diff --git a/agent/Makefile.am b/agent/Makefile.am index 0494e5e8..7975906c 100644 --- a/agent/Makefile.am +++ b/agent/Makefile.am @@ -10,7 +10,7 @@ include $(top_srcdir)/common.mk AM_CFLAGS = \ -DG_LOG_DOMAIN=\"libnice\" \ - $(ERROR_CFLAGS) \ + $(LIBNICE_CFLAGS) \ $(GLIB_CFLAGS) \ $(GUPNP_CFLAGS) \ -I $(top_srcdir) \ diff --git a/common.mk b/common.mk index 1382422d..e2ca3f43 100644 --- a/common.mk +++ b/common.mk @@ -1,21 +1,3 @@ - -ERROR_CFLAGS = \ - $(LIBNICE_CFLAGS) \ - -fno-strict-aliasing \ - -Wextra \ - -Wundef \ - -Wnested-externs \ - -Wwrite-strings \ - -Wpointer-arith \ - -Wbad-function-cast \ - -Wmissing-declarations \ - -Wmissing-prototypes \ - -Wstrict-prototypes \ - -Wredundant-decls \ - -Wno-unused-parameter \ - -Wno-missing-field-initializers -# -Wold-style-definition -Winline -Wunreachable-code - CLEANFILES = *.gcno *.gcda pkgincludedir = $(includedir)/nice diff --git a/configure.ac b/configure.ac index 115b57f0..2173a4ed 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,25 @@ dnl if asked for, add -Werror if supported if test "x$LIBNICE_RELEASE" != "xyes"; then LIBNICE_CFLAGS="$LIBNICE_CFLAGS -Werror" fi + +AC_DEFUN([NICE_ADD_FLAG], + AS_COMPILER_FLAG([$1], LIBNICE_CFLAGS="$LIBNICE_CFLAGS $1", []) +) + +NICE_ADD_FLAG([-fno-strict-aliasing]) +NICE_ADD_FLAG([-Wextra]) +NICE_ADD_FLAG([-Wundef]) +NICE_ADD_FLAG([-Wnested-externs]) +NICE_ADD_FLAG([-Wwrite-strings]) +NICE_ADD_FLAG([-Wpointer-arith]) +NICE_ADD_FLAG([-Wbad-function-cast]) +NICE_ADD_FLAG([-Wmissing-declarations]) +NICE_ADD_FLAG([-Wmissing-prototypes]) +NICE_ADD_FLAG([-Wstrict-prototypes]) +NICE_ADD_FLAG([-Wredundant-decls]) +NICE_ADD_FLAG([-Wno-unused-parameter]) +NICE_ADD_FLAG([-Wno-missing-field-initializers]) + # # Fixes for Solaris # diff --git a/docs/reference/libnice/Makefile.am b/docs/reference/libnice/Makefile.am index 51384abb..952b2ec2 100644 --- a/docs/reference/libnice/Makefile.am +++ b/docs/reference/libnice/Makefile.am @@ -72,7 +72,7 @@ expand_content_files= # signals and properties. # e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) # e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) -AM_CFLAGS = $(ERROR_CFLAGS) \ +AM_CFLAGS = $(LIBNICE_CFLAGS) \ $(GLIB_CFLAGS) \ -I $(top_srcdir) \ -I $(top_srcdir)/random \ diff --git a/examples/Makefile.am b/examples/Makefile.am index 007a5c86..1e7decfb 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -14,7 +14,7 @@ AM_CFLAGS = \ -I $(top_srcdir)/random \ -I $(top_srcdir)/socket \ -I $(top_srcdir)/stun \ - $(ERROR_CFLAGS) \ + $(LIBNICE_CFLAGS) \ $(GLIB_CFLAGS) \ $(GUPNP_CFLAGS) diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4 new file mode 100644 index 00000000..882a4c7f --- /dev/null +++ b/m4/as-compiler-flag.m4 @@ -0,0 +1,64 @@ +dnl as-compiler-flag.m4 0.1.0 + +dnl autostars m4 macro for detection of compiler flags + +dnl David Schleef +dnl Tim-Philipp Müller + +dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) +dnl Tries to compile with the given CFLAGS. +dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, +dnl and ACTION-IF-NOT-ACCEPTED otherwise. + +AC_DEFUN([AS_COMPILER_FLAG], +[ + AC_MSG_CHECKING([to see if compiler understands $1]) + + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $1" + + AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) + CFLAGS="$save_CFLAGS" + + if test "X$flag_ok" = Xyes ; then + $2 + true + else + $3 + true + fi + AC_MSG_RESULT([$flag_ok]) +]) + +dnl AS_CXX_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) +dnl Tries to compile with the given CPPFLAGS. +dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, +dnl and ACTION-IF-NOT-ACCEPTED otherwise. + +AC_DEFUN([AS_CXX_COMPILER_FLAG], +[ + AC_REQUIRE([AC_PROG_CXX]) + + AC_MSG_CHECKING([to see if c++ compiler understands $1]) + + save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $1" + + AC_LANG_PUSH(C++) + + AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) + CPPFLAGS="$save_CPPFLAGS" + + if test "X$flag_ok" = Xyes ; then + $2 + true + else + $3 + true + fi + + AC_LANG_POP(C++) + + AC_MSG_RESULT([$flag_ok]) +]) + diff --git a/nice/Makefile.am b/nice/Makefile.am index ce2be071..b2ccb2bc 100644 --- a/nice/Makefile.am +++ b/nice/Makefile.am @@ -26,7 +26,7 @@ libnice_la_LDFLAGS = \ AM_CFLAGS = \ - $(ERROR_CFLAGS) \ + $(LIBNICE_CFLAGS) \ $(GLIB_CFLAGS) \ -I $(top_srcdir) \ -I $(top_srcdir)/agent \ diff --git a/random/Makefile.am b/random/Makefile.am index 8d8ab820..86ab9261 100644 --- a/random/Makefile.am +++ b/random/Makefile.am @@ -8,7 +8,7 @@ include $(top_srcdir)/common.mk -AM_CFLAGS = $(ERROR_CFLAGS) $(GLIB_CFLAGS) +AM_CFLAGS = $(LIBNICE_CFLAGS) $(GLIB_CFLAGS) noinst_LTLIBRARIES = libnice-random.la diff --git a/socket/Makefile.am b/socket/Makefile.am index 9b5b0063..336a5a3f 100644 --- a/socket/Makefile.am +++ b/socket/Makefile.am @@ -10,7 +10,7 @@ include $(top_srcdir)/common.mk AM_CFLAGS = \ -DG_LOG_DOMAIN=\"libnice-socket\" \ - $(ERROR_CFLAGS) \ + $(LIBNICE_CFLAGS) \ $(GLIB_CFLAGS) \ $(GUPNP_CFLAGS) \ -I $(top_srcdir)/random \ diff --git a/stun/Makefile.am b/stun/Makefile.am index 76019646..f90c3d47 100644 --- a/stun/Makefile.am +++ b/stun/Makefile.am @@ -10,7 +10,7 @@ SUBDIRS = . tools tests include $(top_srcdir)/common.mk -AM_CFLAGS = -std=gnu99 -DG_LOG_DOMAIN=\"libnice-stun\" $(ERROR_CFLAGS) +AM_CFLAGS = -std=gnu99 -DG_LOG_DOMAIN=\"libnice-stun\" $(LIBNICE_CFLAGS) AM_CPPFLAGS = -I$(top_srcdir) if WINDOWS diff --git a/stun/tools/Makefile.am b/stun/tools/Makefile.am index 42b3108c..7a9b772d 100644 --- a/stun/tools/Makefile.am +++ b/stun/tools/Makefile.am @@ -8,7 +8,7 @@ # include $(top_srcdir)/common.mk -AM_CFLAGS = -std=gnu99 $(ERROR_CFLAGS) +AM_CFLAGS = -std=gnu99 $(LIBNICE_CFLAGS) AM_CPPFLAGS = -I$(top_srcdir) bin_PROGRAMS = stunbdc stund diff --git a/tests/Makefile.am b/tests/Makefile.am index 88cb73fd..5a1a9c75 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,7 +9,7 @@ include $(top_srcdir)/common.mk AM_CFLAGS = \ - $(ERROR_CFLAGS) \ + $(LIBNICE_CFLAGS) \ $(GLIB_CFLAGS) \ $(GUPNP_CFLAGS) \ -I $(top_srcdir) \