1# bison-check-compile-flag.m4
2
3# serial 1
4
5# Copyright (C) 2018-2021 Free Software Foundation, Inc.
6
7# This file is free software; the Free Software Foundation
8# gives unlimited permission to copy and/or distribute it,
9# with or without modifications, as long as this notice is preserved.
10
11
12
13# BISON_CHECK_COMPILER_FLAG(FLAG,
14#                           [ACTION-SUCCESS], [ACTION-FAILURE],
15#                           [EXTRA-FLAGS])
16# -------------------------------------------------------------
17
18# Based on Autoconf Macro Archive's AX_CHECK_COMPILE_FLAG, but using
19# AC_LINK_IFELSE, not just AC_COMPILE_IFELSE to capture failures such
20# as:
21#
22#  ./c++.at:401:  $PREPARSER ./list
23#  stderr:
24#  ./list: error while loading shared libraries: libc++.so.1: cannot open shared object file: No such file or directory
25#
26# because we thought '-stdlib=c++' works, as it passes with AC_COMPILE_IFELSE.
27#
28# Not using AX_CHECK_LINK_FLAG, because its message is inappropriate:
29#
30#  checking whether the linker accepts -std=c++11... yes
31#  checking whether the linker accepts -std=c++14... yes
32#  checking whether the linker accepts -std=c++17... no
33AC_DEFUN([BISON_CHECK_COMPILER_FLAG],
34[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
35AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
36AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
37  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
38  _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
39  AC_LINK_IFELSE([m4_default([$5], [AC_LANG_PROGRAM()])],
40    [AS_VAR_SET(CACHEVAR,[yes])],
41    [AS_VAR_SET(CACHEVAR,[no])])
42  _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
43AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], [$2], [$3])
44AS_VAR_POPDEF([CACHEVAR])dnl
45])dnl BISON_CHECK_COMPILER_FLAGS
46