1# warnings.m4 serial 16 2dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl From Simon Josefsson 8 9# gl_AS_VAR_APPEND(VAR, VALUE) 10# ---------------------------- 11# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it. 12m4_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])])]) 16 17 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. 22# 23# The effects of this macro depend on the current language (_AC_LANG). 24AC_DEFUN([gl_COMPILER_OPTION_IF], 25[ 26AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl 27AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl 28AS_LITERAL_IF([$1], 29 [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))], 30 [gl_positive="$1" 31case $gl_positive in 32 -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;; 33esac 34m4_pushdef([gl_Positive], [$gl_positive])])dnl 35AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], [gl_Warn], [ 36 gl_save_compiler_FLAGS="$gl_Flags" 37 gl_AS_VAR_APPEND(m4_defn([gl_Flags]), 38 [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["]) 39 AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([[]])])], 40 [AS_VAR_SET([gl_Warn], [yes])], 41 [AS_VAR_SET([gl_Warn], [no])]) 42 gl_Flags="$gl_save_compiler_FLAGS" 43]) 44AS_VAR_IF(gl_Warn, [yes], [$2], [$3]) 45m4_popdef([gl_Positive])dnl 46AS_VAR_POPDEF([gl_Flags])dnl 47AS_VAR_POPDEF([gl_Warn])dnl 48]) 49 50# gl_UNKNOWN_WARNINGS_ARE_ERRORS 51# ------------------------------ 52# Clang doesn't complain about unknown warning options unless one also 53# specifies -Wunknown-warning-option -Werror. Detect this. 54# 55# The effects of this macro depend on the current language (_AC_LANG). 56AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS], 57[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) 58 59# Specialization for _AC_LANG = C. This macro can be AC_REQUIREd. 60AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)], 61[ 62 AC_LANG_PUSH([C]) 63 gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL 64 AC_LANG_POP([C]) 65]) 66 67# Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd. 68AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)], 69[ 70 AC_LANG_PUSH([C++]) 71 gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL 72 AC_LANG_POP([C++]) 73]) 74 75# Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd. 76AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)], 77[ 78 AC_LANG_PUSH([Objective C]) 79 gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL 80 AC_LANG_POP([Objective C]) 81]) 82 83AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL], 84[gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option], 85 [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'], 86 [gl_unknown_warnings_are_errors=])]) 87 88# gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS], 89# [PROGRAM = AC_LANG_PROGRAM()]) 90# ----------------------------------------------------------- 91# Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it 92# when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]). 93# 94# If VARIABLE is a variable name, AC_SUBST it. 95# 96# The effects of this macro depend on the current language (_AC_LANG). 97AC_DEFUN([gl_WARN_ADD], 98[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)]) 99gl_COMPILER_OPTION_IF([$1], 100 [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])], 101 [], 102 [$3]) 103m4_ifval([$2], 104 [AS_LITERAL_IF([$2], [AC_SUBST([$2])])], 105 [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl 106]) 107 108# Local Variables: 109# mode: autoconf 110# End: 111