flags.m4 2.23 KB
Newer Older
1
# Copyright © 2006 Rémi Denis-Courmont
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15
# This file (flags.m4) is free software; unlimited permission to
# copy and/or distribute it , with or without modifications, as long
# as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

AC_DEFUN([RDC_PROG_CC_FLAGS_IFELSE],
[AC_LANG_ASSERT(C)
  CFLAGS_save="${CFLAGS}"
  as_ac_var=`echo "ac_cv_prog_cc_flags_$1" | $as_tr_sh`
  AC_CACHE_CHECK([if $CC accepts $1], [$as_ac_var], [
16
    CFLAGS="${CFLAGS} $1"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
17 18 19 20 21 22 23
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
      eval "$as_ac_var=yes"
    ],[
      eval "$as_ac_var=no"
    ])
  ])

Rémi Denis-Courmont's avatar
Fixes  
Rémi Denis-Courmont committed
24
  ac_res=`eval echo '${'$as_ac_var'}'`
Pierre's avatar
Pierre committed
25 26 27 28 29 30 31
  CFLAGS="${CFLAGS_save}"
  AS_IF([test "${ac_res}" != "no"], [$2], [$3])
])

AC_DEFUN([RDC_PROG_CC_FLAGS],
[AC_LANG_ASSERT(C)
  RDC_PROG_CC_FLAGS_IFELSE([$1], [CFLAGS="${CFLAGS} $1"])
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
32 33 34 35
])

AC_DEFUN([RDC_PROG_CC_WFLAGS],
[ for a in $1; do
Pierre's avatar
Pierre committed
36
    RDC_PROG_CC_FLAGS([-W$a])
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
37 38
  done
])
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
39

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53
AC_DEFUN([RDC_PROG_CXX_FLAGS_IFELSE],
[AC_LANG_ASSERT(C++)
  CXXFLAGS_save="${CXXFLAGS}"
  as_ac_var=`echo "ac_cv_prog_cxx_flags_$1" | $as_tr_sh`
  AC_CACHE_CHECK([if $CXX accepts $1], [$as_ac_var], [
    CXXFLAGS="${CXXFLAGS} $1"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
      eval "$as_ac_var=yes"
    ],[
      eval "$as_ac_var=no"
    ])
  ])

  ac_res=`eval echo '${'$as_ac_var'}'`
54
  CXXFLAGS="${CXXFLAGS_save}"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68
  AS_IF([test "${ac_res}" != "no"], [$2], [$3])
])

AC_DEFUN([RDC_PROG_CXX_FLAGS],
[AC_LANG_ASSERT(C++)
  RDC_PROG_CXX_FLAGS_IFELSE([$1], [CXXFLAGS="${CXXFLAGS} $1"])
])

AC_DEFUN([RDC_PROG_CXX_WFLAGS],
[ for a in $1; do
    RDC_PROG_CXX_FLAGS([-W$a])
  done
])

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
69 70
AC_DEFUN([RDC_PROG_LINK_FLAGS_IFELSE],
[AC_LANG_ASSERT(C)
71 72 73
  LDFLAGS_save="${LDFLAGS}"
  as_ac_var=`echo "ac_cv_prog_link_flags_$1" | $as_tr_sh`
  AC_CACHE_CHECK([if $LINK accepts $1], [$as_ac_var], [
74
    LDFLAGS="${LDFLAGS} $1"
75
    AC_LINK_IFELSE([AC_LANG_PROGRAM()], [
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
76 77 78 79 80 81 82 83
      eval "$as_ac_var=yes"
    ],[
      eval "$as_ac_var=no"
    ])
  ])

  ac_res=`eval echo '${'$as_ac_var'}'`
  AS_IF([test "${ac_res}" != "no"], [
84
    LDFLAGS="${LDFLAGS} $1"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
85 86
    $2
  ], [
87
    LDFLAGS="${LDFLAGS_save}"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
88 89 90
    $3
  ])
])