changeset 16838:a43ad261663e

warnings.m4: provide a means to specify the program to compile. * m4/warnings.m4 (gl_COMPILER_OPTION_IF): New, extracted from (gl_WARN_ADD): here. Use gl_AS_VAR_APPEND. Support an argument to specify the program to compile. (gl_WARN_ADD): Accept an argument to specify the program to compile. AC_SUBST the WARN_CFLAGS when they are used. * modules/warnings (configure.ac): Don't AC_SUBST WARN_CFLAGS, leave this to gl_WARN_ADD.
author Akim Demaille <akim@lrde.epita.fr>
date Mon, 09 Apr 2012 09:33:24 +0200
parents 579368b4bb16
children 85883252217c
files ChangeLog m4/warnings.m4 modules/warnings
diffstat 3 files changed, 45 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-05-08  Akim Demaille  <akim@lrde.epita.fr>
+
+	warnings.m4: provide a means to specify the program to compile.
+	* m4/warnings.m4 (gl_COMPILER_OPTION_IF): New, extracted from...
+	(gl_WARN_ADD): here.
+	Use gl_AS_VAR_APPEND.
+	Support an argument to specify the program to compile.
+	(gl_WARN_ADD): Accept an argument to specify the program to compile.
+	AC_SUBST the WARN_CFLAGS when they are used.
+	* modules/warnings (configure.ac): Don't AC_SUBST WARN_CFLAGS,
+	leave this to gl_WARN_ADD.
+
 2012-05-08  Eric Blake  <eblake@redhat.com>
 
 	doc: recommendations on gettext version
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -1,4 +1,4 @@
-# warnings.m4 serial 6
+# warnings.m4 serial 7
 dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -15,28 +15,47 @@
 [AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
 
 
-# gl_WARN_ADD(PARAMETER, [VARIABLE = WARN_CFLAGS])
-# ------------------------------------------------
-# Adds parameter to WARN_CFLAGS if the compiler supports it.  For example,
-# gl_WARN_ADD([-Wparentheses]).
+# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
+#                       [PROGRAM = AC_LANG_PROGRAM()])
+# -----------------------------------------------------------------
+# Check if the compiler supports OPTION when compiling PROGRAM.
 #
-# If VARIABLE is a variable name, AC_SUBST it.
-AC_DEFUN([gl_WARN_ADD],
-dnl FIXME: gl_Warn must be used unquoted until we can assume
-dnl autoconf 2.64 or newer.
+# FIXME: gl_Warn must be used unquoted until we can assume Autoconf
+# 2.64 or newer.
+AC_DEFUN([gl_COMPILER_OPTION_IF],
 [AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
 AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
 AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
   gl_save_compiler_FLAGS="$gl_Flags"
-  gl_Flags="$gl_Flags $1"
-  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
+  gl_AS_VAR_APPEND(m4_defn([gl_Flags]), [" $1"])
+  AC_COMPILE_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
                     [AS_VAR_SET(gl_Warn, [yes])],
                     [AS_VAR_SET(gl_Warn, [no])])
   gl_Flags="$gl_save_compiler_FLAGS"
 ])
-AS_VAR_IF(gl_Warn, [yes],
-  [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])])
+AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
 AS_VAR_POPDEF([gl_Flags])dnl
 AS_VAR_POPDEF([gl_Warn])dnl
-m4_ifval([$2], [AS_LITERAL_IF([$2], [AC_SUBST([$2])], [])])dnl
 ])
+
+
+# gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS],
+#             [PROGRAM = AC_LANG_PROGRAM()])
+# ---------------------------------------------
+# Adds parameter to WARN_CFLAGS if the compiler supports it when
+# compiling PROGRAM.  For example, gl_WARN_ADD([-Wparentheses]).
+#
+# If VARIABLE is a variable name, AC_SUBST it.
+AC_DEFUN([gl_WARN_ADD],
+[gl_COMPILER_OPTION_IF([$1],
+  [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])],
+  [],
+  [$3])
+m4_ifval([$2],
+         [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
+         [AC_SUBST([WARN_CFLAGS])])dnl
+])
+
+# Local Variables:
+# mode: autoconf
+# End:
--- a/modules/warnings
+++ b/modules/warnings
@@ -7,7 +7,6 @@
 Depends-on:
 
 configure.ac:
-AC_SUBST([WARN_CFLAGS])
 
 License:
 unlimited