diff mbox

configure.ac: Add a macro to check for supported compiler flags.

Message ID 1303851974-29838-2-git-send-email-jaschut@sandia.gov (mailing list archive)
State New, archived
Headers show

Commit Message

Jim Schutt April 26, 2011, 9:06 p.m. UTC
Ancient versions of gcc, such as the gcc 4.1.2 in RHEL 5.5, don't
support some -W flags that newer versions do.  Fix up configure.ac
and Makefile.am to use them if you have them.

Signed-off-by: Jim Schutt <jaschut@sandia.gov>
---
 configure.ac    |   21 +++++++++++++++++++++
 src/Makefile.am |    2 +-
 2 files changed, 22 insertions(+), 1 deletions(-)

Comments

Colin McCabe April 26, 2011, 10:39 p.m. UTC | #1
applied, thanks
C.

On Tue, Apr 26, 2011 at 2:06 PM, Jim Schutt <jaschut@sandia.gov> wrote:
> Ancient versions of gcc, such as the gcc 4.1.2 in RHEL 5.5, don't
> support some -W flags that newer versions do.  Fix up configure.ac
> and Makefile.am to use them if you have them.
>
> Signed-off-by: Jim Schutt <jaschut@sandia.gov>
> ---
>  configure.ac    |   21 +++++++++++++++++++++
>  src/Makefile.am |    2 +-
>  2 files changed, 22 insertions(+), 1 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 5642717..dc4d710 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -33,6 +33,27 @@ AC_PROG_CXX
>  AC_PROG_MAKE_SET
>  AC_PROG_LIBTOOL
>
> +# Checks for compiler warning types
> +
> +# AC_CHECK_CC_FLAG(FLAG_TO_TEST, VARIABLE_TO_SET_IF_SUPPORTED)
> +# ---------
> +AC_DEFUN([AC_CHECK_CC_FLAG],
> +[{
> +       AC_LANG_PUSH([C])
> +       my_cflags_save="$CFLAGS"
> +       CFLAGS="$my_cflags_save $1"
> +       AC_MSG_CHECKING([whether $CC accepts $1])
> +       AC_COMPILE_IFELSE(AC_LANG_PROGRAM(),
> +                         [AC_MSG_RESULT([yes]); AC_SUBST([$2], ["$1"])],
> +                         [AC_MSG_RESULT([no])]
> +                        )
> +       CFLAGS="$my_cflags_save"
> +       AC_LANG_POP([C])
> +}])
> +
> +AC_CHECK_CC_FLAG([-Wtype-limits], [WARN_TYPE_LIMITS])
> +AC_CHECK_CC_FLAG([-Wignored-qualifiers], [WARN_IGNORED_QUALIFIERS])
> +
>  # Checks for libraries.
>  AC_CHECK_LIB([m], [pow], [true], AC_MSG_FAILURE([libm not found]))
>  AC_CHECK_LIB([pthread], [pthread_create], [true], AC_MSG_FAILURE([libpthread not found]))
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 3113111..071360e 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -479,7 +479,7 @@ CLEANFILES += \
>  ##
>
>  AM_COMMON_FLAGS = -Wall -D__CEPH__ -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic \
> --Wtype-limits -Wignored-qualifiers -Winit-self -Wpointer-arith \
> +${WARN_TYPE_LIMITS} ${WARN_IGNORED_QUALIFIERS} -Winit-self -Wpointer-arith \
>  -fno-strict-aliasing
>
>  AM_CFLAGS = $(AM_COMMON_FLAGS)
> --
> 1.6.6
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/configure.ac b/configure.ac
index 5642717..dc4d710 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,27 @@  AC_PROG_CXX
 AC_PROG_MAKE_SET
 AC_PROG_LIBTOOL
 
+# Checks for compiler warning types
+
+# AC_CHECK_CC_FLAG(FLAG_TO_TEST, VARIABLE_TO_SET_IF_SUPPORTED)
+# ---------
+AC_DEFUN([AC_CHECK_CC_FLAG],
+[{
+	AC_LANG_PUSH([C])
+	my_cflags_save="$CFLAGS"
+	CFLAGS="$my_cflags_save $1"
+	AC_MSG_CHECKING([whether $CC accepts $1])
+	AC_COMPILE_IFELSE(AC_LANG_PROGRAM(),
+			  [AC_MSG_RESULT([yes]); AC_SUBST([$2], ["$1"])],
+			  [AC_MSG_RESULT([no])]
+			 )
+	CFLAGS="$my_cflags_save"
+	AC_LANG_POP([C])
+}])
+
+AC_CHECK_CC_FLAG([-Wtype-limits], [WARN_TYPE_LIMITS])
+AC_CHECK_CC_FLAG([-Wignored-qualifiers], [WARN_IGNORED_QUALIFIERS])
+
 # Checks for libraries.
 AC_CHECK_LIB([m], [pow], [true], AC_MSG_FAILURE([libm not found]))
 AC_CHECK_LIB([pthread], [pthread_create], [true], AC_MSG_FAILURE([libpthread not found]))
diff --git a/src/Makefile.am b/src/Makefile.am
index 3113111..071360e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -479,7 +479,7 @@  CLEANFILES += \
 ##
 
 AM_COMMON_FLAGS = -Wall -D__CEPH__ -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE -rdynamic \
--Wtype-limits -Wignored-qualifiers -Winit-self -Wpointer-arith \
+${WARN_TYPE_LIMITS} ${WARN_IGNORED_QUALIFIERS} -Winit-self -Wpointer-arith \
 -fno-strict-aliasing
 
 AM_CFLAGS = $(AM_COMMON_FLAGS)