1dnl as-compiler-flag.m4 0.1.0
2
3dnl autostars m4 macro for detection of compiler flags
4
5dnl David Schleef <ds@schleef.org>
6dnl Tim-Philipp Müller <tim centricular net>
7
8dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
9dnl Tries to compile with the given CFLAGS.
10dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
11dnl and ACTION-IF-NOT-ACCEPTED otherwise.
12
13AC_DEFUN([AS_COMPILER_FLAG],
14[
15  AC_MSG_CHECKING([to see if compiler understands $1])
16
17  save_CFLAGS="$CFLAGS"
18  CFLAGS="$CFLAGS $1"
19
20  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
21  CFLAGS="$save_CFLAGS"
22
23  if test "X$flag_ok" = Xyes ; then
24    $2
25    true
26  else
27    $3
28    true
29  fi
30  AC_MSG_RESULT([$flag_ok])
31])
32
33dnl AS_CXX_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
34dnl Tries to compile with the given CPPFLAGS.
35dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
36dnl and ACTION-IF-NOT-ACCEPTED otherwise.
37
38AC_DEFUN([AS_CXX_COMPILER_FLAG],
39[
40  AC_REQUIRE([AC_PROG_CXX])
41
42  AC_MSG_CHECKING([to see if c++ compiler understands $1])
43
44  save_CPPFLAGS="$CPPFLAGS"
45  CPPFLAGS="$CPPFLAGS $1"
46
47  AC_LANG_PUSH(C++)
48
49  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
50  CPPFLAGS="$save_CPPFLAGS"
51
52  if test "X$flag_ok" = Xyes ; then
53    $2
54    true
55  else
56    $3
57    true
58  fi
59
60  AC_LANG_POP(C++)
61
62  AC_MSG_RESULT([$flag_ok])
63])
64
65dnl AS_OBJC_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
66dnl Tries to compile with the given CPPFLAGS.
67dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
68dnl and ACTION-IF-NOT-ACCEPTED otherwise.
69
70AC_DEFUN([AS_OBJC_COMPILER_FLAG],
71[
72  AC_REQUIRE([AC_PROG_OBJC])
73
74  AC_MSG_CHECKING([to see if Objective C compiler understands $1])
75
76  save_CPPFLAGS="$CPPFLAGS"
77  CPPFLAGS="$CPPFLAGS $1"
78
79  AC_LANG_PUSH([Objective C])
80
81  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
82  CPPFLAGS="$save_CPPFLAGS"
83
84  if test "X$flag_ok" = Xyes ; then
85    $2
86    true
87  else
88    $3
89    true
90  fi
91
92  AC_LANG_POP([Objective C])
93
94  AC_MSG_RESULT([$flag_ok])
95])
96
97