Dmitry V. Levin | 174583d | 2015-01-21 20:49:04 +0000 | [diff] [blame] | 1 | # warnings.m4 serial 11 |
| 2 | dnl Copyright (C) 2008-2013 Free Software Foundation, Inc. |
Dmitry V. Levin | 918e49b | 2010-09-09 17:41:15 +0000 | [diff] [blame] | 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. |
| 6 | |
| 7 | dnl 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. |
| 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])])]) |
| 16 | |
Dmitry V. Levin | 174583d | 2015-01-21 20:49:04 +0000 | [diff] [blame] | 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 | # FIXME: gl_Warn must be used unquoted until we can assume Autoconf |
| 24 | # 2.64 or newer. |
| 25 | AC_DEFUN([gl_COMPILER_OPTION_IF], |
| 26 | [AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl |
| 27 | AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl |
| 28 | AS_LITERAL_IF([$1], |
| 29 | [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))], |
| 30 | [gl_positive="$1" |
| 31 | case $gl_positive in |
| 32 | -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;; |
| 33 | esac |
| 34 | m4_pushdef([gl_Positive], [$gl_positive])])dnl |
| 35 | AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([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" |
Dmitry V. Levin | 918e49b | 2010-09-09 17:41:15 +0000 | [diff] [blame] | 43 | ]) |
Dmitry V. Levin | 174583d | 2015-01-21 20:49:04 +0000 | [diff] [blame] | 44 | AS_VAR_IF(gl_Warn, [yes], [$2], [$3]) |
| 45 | m4_popdef([gl_Positive])dnl |
Dmitry V. Levin | 918e49b | 2010-09-09 17:41:15 +0000 | [diff] [blame] | 46 | AS_VAR_POPDEF([gl_Flags])dnl |
| 47 | AS_VAR_POPDEF([gl_Warn])dnl |
Dmitry V. Levin | 916aded | 2010-09-09 17:36:36 +0000 | [diff] [blame] | 48 | ]) |
Dmitry V. Levin | 174583d | 2015-01-21 20:49:04 +0000 | [diff] [blame] | 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 | AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS], |
| 55 | [gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option], |
| 56 | [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'], |
| 57 | [gl_unknown_warnings_are_errors=])]) |
| 58 | |
| 59 | # gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS], |
| 60 | # [PROGRAM = AC_LANG_PROGRAM()]) |
| 61 | # --------------------------------------------- |
| 62 | # Adds parameter to WARN_CFLAGS if the compiler supports it when |
| 63 | # compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]). |
| 64 | # |
| 65 | # If VARIABLE is a variable name, AC_SUBST it. |
| 66 | AC_DEFUN([gl_WARN_ADD], |
| 67 | [AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS]) |
| 68 | gl_COMPILER_OPTION_IF([$1], |
| 69 | [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])], |
| 70 | [], |
| 71 | [$3]) |
| 72 | m4_ifval([$2], |
| 73 | [AS_LITERAL_IF([$2], [AC_SUBST([$2])])], |
| 74 | [AC_SUBST([WARN_CFLAGS])])dnl |
| 75 | ]) |
| 76 | |
| 77 | # Local Variables: |
| 78 | # mode: autoconf |
| 79 | # End: |