Home | History | Annotate | Download | only in m4
      1 # warnings.m4 serial 11
      2 # modified for strace project
      3 dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
      4 dnl This file is free software; the Free Software Foundation
      5 dnl gives unlimited permission to copy and/or distribute it,
      6 dnl with or without modifications, as long as this notice is preserved.
      7 
      8 dnl From Simon Josefsson
      9 
     10 # gl_AS_VAR_APPEND(VAR, VALUE)
     11 # ----------------------------
     12 # Provide the functionality of AS_VAR_APPEND if Autoconf does not have it.
     13 m4_ifdef([AS_VAR_APPEND],
     14 [m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])],
     15 [m4_define([gl_AS_VAR_APPEND],
     16 [AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
     17 
     18 
     19 # gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
     20 #                       [PROGRAM = AC_LANG_PROGRAM()])
     21 # -----------------------------------------------------------------
     22 # Check if the compiler supports OPTION when compiling PROGRAM.
     23 #
     24 # FIXME: gl_Warn must be used unquoted until we can assume Autoconf
     25 # 2.64 or newer.
     26 AC_DEFUN([gl_COMPILER_OPTION_IF],
     27 [AS_VAR_PUSHDEF([gl_Flags], _AC_LANG_PREFIX[]FLAGS)dnl
     28 AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]gl_Flags[]_$1])dnl
     29 AS_LITERAL_IF([$1],
     30   [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
     31   [gl_positive="$1"
     32 case $gl_positive in
     33   -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;;
     34 esac
     35 m4_pushdef([gl_Positive], [$gl_positive])])dnl
     36 AC_CACHE_CHECK([whether $[]_AC_CC[] handles $1], m4_defn([gl_Warn]), [
     37   gl_save_compiler_FLAGS="$gl_Flags"
     38   gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
     39     [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
     40   AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
     41                  [AS_VAR_SET(gl_Warn, [yes])],
     42                  [AS_VAR_SET(gl_Warn, [no])])
     43   gl_Flags="$gl_save_compiler_FLAGS"
     44 ])
     45 AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
     46 m4_popdef([gl_Positive])dnl
     47 AS_VAR_POPDEF([gl_Flags])dnl
     48 AS_VAR_POPDEF([gl_Warn])dnl
     49 ])
     50 
     51 # gl_UNKNOWN_WARNINGS_ARE_ERRORS
     52 # ------------------------------
     53 # Clang doesn't complain about unknown warning options unless one also
     54 # specifies -Wunknown-warning-option -Werror.  Detect this.
     55 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
     56 [AS_IF([test x${gl_unknown_warnings_are_errors+set} = x],
     57   [gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
     58     [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
     59     [gl_unknown_warnings_are_errors=])
     60   ])
     61 ])
     62 
     63 # gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS],
     64 #             [PROGRAM = AC_LANG_PROGRAM()])
     65 # ---------------------------------------------
     66 # Adds parameter to WARN_CFLAGS if the compiler supports it when
     67 # compiling PROGRAM.  For example, gl_WARN_ADD([-Wparentheses]).
     68 #
     69 # If VARIABLE is a variable name, AC_SUBST it.
     70 AC_DEFUN([gl_WARN_ADD],
     71 [gl_UNKNOWN_WARNINGS_ARE_ERRORS
     72 gl_COMPILER_OPTION_IF([$1],
     73   [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])],
     74   [],
     75   [$3])
     76 m4_ifval([$2],
     77          [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
     78          [AC_SUBST([WARN_CFLAGS])])dnl
     79 ])
     80 
     81 # Local Variables:
     82 # mode: autoconf
     83 # End:
     84