1dnl This is from crypt.to/autoconf-archive, slightly modified.
2dnl It defines bool as int if it is not availalbe
3dnl
4AC_DEFUN([AX_CXX_BOOL],
5[AC_CACHE_CHECK(whether the compiler recognizes bool as a built-in type,
6ac_cv_cxx_bool,
7[AC_LANG_SAVE
8 AC_LANG_CPLUSPLUS
9 AC_TRY_COMPILE([
10int f(int  x){return 1;}
11int f(char x){return 1;}
12int f(bool x){return 1;}
13],[bool b = true; return f(b);],
14 ac_cv_cxx_bool=yes, ac_cv_cxx_bool=no)
15 AC_LANG_RESTORE
16])
17if test "$ac_cv_cxx_bool" != yes; then
18  AC_DEFINE(bool,int,[define if bool is a built-in type])
19fi
20])
21
22dnl This is from crypt.to/autoconf-archive, slightly modified (name defined)
23dnl
24AC_DEFUN([AX_CXX_EXCEPTIONS],
25[AC_CACHE_CHECK(whether the compiler supports exceptions,
26ac_cv_cxx_exceptions,
27[AC_LANG_SAVE
28 AC_LANG_CPLUSPLUS
29 AC_TRY_COMPILE(,[try { throw  1; } catch (int i) { return i; }],
30 ac_cv_cxx_exceptions=yes, ac_cv_cxx_exceptions=no)
31 AC_LANG_RESTORE
32])
33if test "$ac_cv_cxx_exceptions" = yes; then
34  AC_DEFINE(HAVE_CXX_EXCEPTIONS,,[define if the compiler supports exceptions])
35fi
36])
37
38dnl This is from crypt.to/autoconf-archive
39dnl
40AC_DEFUN([AX_CXX_NAMESPACES],
41[AC_CACHE_CHECK(whether the compiler implements namespaces,
42ac_cv_cxx_namespaces,
43[AC_LANG_SAVE
44 AC_LANG_CPLUSPLUS
45 AC_TRY_COMPILE([namespace Outer { namespace Inner { int i = 0; }}],
46                [using namespace Outer::Inner; return i;],
47 ac_cv_cxx_namespaces=yes, ac_cv_cxx_namespaces=no)
48 AC_LANG_RESTORE
49])
50if test "$ac_cv_cxx_namespaces" = yes; then
51  AC_DEFINE(HAVE_NAMESPACES,,[define if the compiler implements namespaces])
52fi
53])
54
55dnl Some compilers support namespaces but don't know about std
56dnl
57AC_DEFUN([AX_CXX_NAMESPACE_STD],
58[AC_REQUIRE([AX_CXX_NAMESPACES])
59AC_CACHE_CHECK(whether the compiler implements the namespace std,
60ac_cv_cxx_namespace_std,
61[ac_cv_cxx_namespace_std=no
62if test "$ac_cv_cxx_namespaces" = yes ; then
63   AC_LANG_SAVE
64   AC_LANG_CPLUSPLUS
65   AC_TRY_COMPILE([
66#include <iostream>
67using namespace std;],
68                [cout << "message\n";],
69 ac_cv_cxx_namespace_std=yes, ac_cv_cxx_namespace_std=no)
70   AC_LANG_RESTORE
71fi
72])
73if test "$ac_cv_cxx_namespace_std" = yes; then
74  AC_DEFINE(HAVE_NAMESPACE_STD,,[define if the compiler implements namespace std])
75fi
76])
77
78dnl/*D
79dnl PAC_CXX_CHECK_COMPILER_OPTION - Check that a C++ compiler option is
80dnl accepted without warning messages
81dnl
82dnl Synopsis:
83dnl PAC_CXX_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
84dnl
85dnl Output Effects:
86dnl
87dnl If no actions are specified, a working value is added to 'CXXOPTIONS'
88dnl
89dnl Notes:
90dnl This is now careful to check that the output is different, since
91dnl some compilers are noisy.
92dnl
93dnl We are extra careful to prototype the functions in case compiler options
94dnl that complain about poor code are in effect.
95dnl
96dnl Because this is a long script, we have ensured that you can pass a
97dnl variable containing the option name as the first argument.
98dnl D*/
99AC_DEFUN([PAC_CXX_CHECK_COMPILER_OPTION],[
100AC_MSG_CHECKING([whether C++ compiler accepts option $1])
101pac_opt="$1"
102AC_LANG_PUSH([C++])
103CXXFLAGS_orig="$CXXFLAGS"
104CXXFLAGS_opt="$pac_opt $CXXFLAGS"
105pac_result="unknown"
106
107AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
108CXXFLAGS="$CXXFLAGS_orig"
109rm -f pac_test1.log
110PAC_LINK_IFELSE_LOG([pac_test1.log], [], [
111    CXXFLAGS="$CXXFLAGS_opt"
112    rm -f pac_test2.log
113    PAC_LINK_IFELSE_LOG([pac_test2.log], [], [
114        PAC_RUNLOG_IFELSE([diff -b pac_test1.log pac_test2.log],
115                          [pac_result=yes],[pac_result=no])
116    ],[
117        pac_result=no
118    ])
119], [
120    pac_result=no
121])
122AC_MSG_RESULT([$pac_result])
123dnl Delete the conftest created by AC_LANG_CONFTEST.
124rm -f conftest.$ac_ext
125
126if test "$pac_result" = "yes" ; then
127    AC_MSG_CHECKING([whether routines compiled with $pac_opt can be linked with ones compiled without $pac_opt])
128    pac_result=unknown
129    CXXFLAGS="$CXXFLAGS_orig"
130    rm -f pac_test3.log
131    PAC_COMPILE_IFELSE_LOG([pac_test3.log], [
132        AC_LANG_SOURCE([
133            int foo(void);
134            int foo(void){return 0;}
135        ])
136    ],[
137        PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
138        saved_LIBS="$LIBS"
139        LIBS="pac_conftest.$OBJEXT $LIBS"
140
141        CXXFLAGS="$CXXFLAGS_opt"
142        rm -f pac_test4.log
143        PAC_LINK_IFELSE_LOG([pac_test4.log], [AC_LANG_PROGRAM()], [
144            PAC_RUNLOG_IFELSE([diff -b pac_test2.log pac_test4.log],
145                              [pac_result=yes], [pac_result=no])
146        ],[
147            pac_result=no
148        ])
149        LIBS="$saved_LIBS"
150        rm -f pac_conftest.$OBJEXT
151    ],[
152        pac_result=no
153    ])
154    AC_MSG_RESULT([$pac_result])
155    rm -f pac_test3.log pac_test4.log
156fi
157rm -f pac_test1.log pac_test2.log
158
159dnl Restore CXXFLAGS before 2nd/3rd argument commands are executed,
160dnl as 2nd/3rd argument command could be modifying CXXFLAGS.
161CXXFLAGS="$CXXFLAGS_orig"
162if test "$pac_result" = "yes" ; then
163     ifelse([$2],[],[CXXOPTIONS="$CXXOPTIONS $1"],[$2])
164else
165     ifelse([$3],[],[:],[$3])
166fi
167AC_LANG_POP([C++])
168])
169