1 # warnings.m4 serial 14
2 dnl Copyright (C) 2008-2018 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl From Simon Josefsson
9 # gl_AS_VAR_APPEND(VAR, VALUE)
10 # ----------------------------
11 # Provide the functionality of AS_VAR_APPEND if Autoconf does not have it.
12 m4_ifdef([AS_VAR_APPEND],
13 [m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])],
14 [m4_define([gl_AS_VAR_APPEND],
15 [AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
18 # gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
19 # [PROGRAM = AC_LANG_PROGRAM()])
20 # -----------------------------------------------------------------
21 # Check if the compiler supports OPTION when compiling PROGRAM.
23 # The effects of this macro depend on the current language (_AC_LANG).
24 AC_DEFUN([gl_COMPILER_OPTION_IF],
26 dnl FIXME: gl_Warn must be used unquoted until we can assume Autoconf
28 AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
29 AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
31 [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
34 -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;;
36 m4_pushdef([gl_Positive], [$gl_positive])])dnl
37 AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
38 gl_save_compiler_FLAGS="$gl_Flags"
39 gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
40 [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
41 AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
42 [AS_VAR_SET(gl_Warn, [yes])],
43 [AS_VAR_SET(gl_Warn, [no])])
44 gl_Flags="$gl_save_compiler_FLAGS"
46 AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
47 m4_popdef([gl_Positive])dnl
48 AS_VAR_POPDEF([gl_Flags])dnl
49 AS_VAR_POPDEF([gl_Warn])dnl
52 # gl_UNKNOWN_WARNINGS_ARE_ERRORS
53 # ------------------------------
54 # Clang doesn't complain about unknown warning options unless one also
55 # specifies -Wunknown-warning-option -Werror. Detect this.
57 # The effects of this macro depend on the current language (_AC_LANG).
58 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
59 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
61 # Specialization for _AC_LANG = C. This macro can be AC_REQUIREd.
62 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
63 m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)],
66 gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
70 # Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd.
71 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
72 m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)],
75 gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
79 # Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd.
80 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
81 m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)],
83 AC_LANG_PUSH([Objective C])
84 gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
85 AC_LANG_POP([Objective C])
88 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL],
89 [gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
90 [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
91 [gl_unknown_warnings_are_errors=])])
93 # gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
94 # [PROGRAM = AC_LANG_PROGRAM()])
95 # -----------------------------------------------------------
96 # Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it
97 # when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]).
99 # If VARIABLE is a variable name, AC_SUBST it.
101 # The effects of this macro depend on the current language (_AC_LANG).
102 AC_DEFUN([gl_WARN_ADD],
103 [AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)])
104 gl_COMPILER_OPTION_IF([$1],
105 [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])],
109 [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
110 [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl