Home | History | Annotate | Line # | Download | only in buildaux
      1 #
      2 # Copyright (c) 2023, Luke Mewburn <lukem (at] NetBSD.org>
      3 #
      4 # Copying and distribution of this file, with or without modification,
      5 # are permitted in any medium without royalty provided the copyright
      6 # notice and this notice are preserved.  This file is offered as-is,
      7 # without any warranty.
      8 #
      9 
     10 #
     11 # _NB_CHECK_CC_FLAG_PREPARE
     12 #	Check for flags to force a compiler (e.g., clang) to fail
     13 #	if given an unknown -WWARN, and set $nb_cv_check_cc_flags
     14 #	to that flag for NB_CHECK_CC_FLAG() to use.
     15 #
     16 AC_DEFUN([_NB_CHECK_CC_FLAG_PREPARE], [dnl
     17 nb_cv_check_cc_flags=
     18 AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],
     19  [AS_VAR_SET([nb_cv_check_cc_flags], [-Werror=unknown-warning-option])])
     20 ]) dnl _NB_CHECK_CC_FLAG_PREPARE
     21 
     22 #
     23 # NB_CHECK_CC_FLAG(FLAG, [VAR=FLAG_DERIVED])
     24 #	Determine if the C compiler supports FLAG,
     25 #	and sets output variable VAR to FLAG if FLAG is supported.
     26 #
     27 #	If VAR is not provided, default to FLAG_DERIVED, which is
     28 #	FLAG converted to upper-case and all special characters
     29 #	replaced with "_", and the result prepended with "CC_".
     30 #	FLAG_DERIVED is appended to the m4 macro NB_CHECK_CC_FLAG_VARS.
     31 #	E.g., if FLAG is "-Wexample=yes", FLAG_DERIVED is "CC_WEXAMPLE_YES".
     32 #
     33 #	Compiler-specific notes:
     34 #	clang	Uses _NB_CHECK_CC_FLAG_PREPARE() to determine if
     35 #		-Werror=unknown-warning-option.
     36 #	gcc	Check for -WFLAG if FLAG is -Wno-FLAG, to work around
     37 #		gcc silently ignoring unknown -Wno-FLAG.
     38 #
     39 AC_DEFUN([NB_CHECK_CC_FLAG], [dnl
     40 AC_REQUIRE([_NB_CHECK_CC_FLAG_PREPARE])dnl
     41 m4_ifblank([$1], [m4_fatal([Usage: $0(FLAG,[VAR=FLAG_DERIVED])])])dnl
     42 m4_pushdef([NB_flag], [$1])dnl
     43 m4_ifblank([$2], [dnl
     44 m4_pushdef([NB_var], [CC]m4_translit(NB_flag, [-=a-z], [__A-Z]))dnl
     45 m4_append([NB_CHECK_CC_FLAG_VARS], NB_var, [ ])dnl
     46 ], [dnl
     47 m4_pushdef([NB_var], [$2])dnl
     48 ])dnl
     49 m4_pushdef([NB_wflag], m4_bpatsubst(NB_flag, [^-Wno-], [-W]))dnl
     50 AX_CHECK_COMPILE_FLAG(NB_wflag, [AS_VAR_SET(NB_var,NB_flag)], [], [$nb_cv_check_cc_flags])
     51 AC_SUBST(NB_var)
     52 m4_popdef([NB_flag])dnl
     53 m4_popdef([NB_wflag])dnl
     54 m4_popdef([NB_var])dnl
     55 ]) dnl NB_CHECK_CC_FLAG
     56