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