Imported Upstream version 3.0.3
[debian/gnuradio] / config / lf_cxx.m4
1 dnl Autoconf support for C++
2 dnl Copyright (C) 1988 Eleftherios Gkioulekas <lf@amath.washington.edu>
3 dnl  
4 dnl This program is free software; you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation; either version 2 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program; if not, write to the Free Software 
16 dnl Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301, USA.
17 dnl 
18 dnl As a special exception to the GNU General Public License, if you 
19 dnl distribute this file as part of a program that contains a configuration 
20 dnl script generated by Autoconf, you may include it under the same 
21 dnl distribution terms that you use for the rest of that program.
22
23 # -----------------------------------------------------------------
24 # This macro should be called to configure your C++ compiler.
25 # When called, the macro does the following things:
26 # 1. It finds an appropriate C++ compiler
27 #    If you passed the flag --with-cxx=foo, then it uses that
28 #    particular compiler
29 # 2. Checks whether the compiler accepts the -g 
30 # ------------------------------------------------------------------
31
32 AC_DEFUN([LF_CONFIGURE_CXX],[
33  AC_REQUIRE([AC_PROG_CXX])dnl
34  AC_REQUIRE([AC_PROG_CXXCPP])dnl
35  LF_CXX_PORTABILITY
36 ])
37
38 # -----------------------------------------------------------------------
39 # This macro tests the C++ compiler for various portability problem.
40 # 1. Defines CXX_HAS_NO_BOOL if the compiler does not support the bool
41 #    data type
42 # 2. Defines CXX_HAS_BUGGY_FOR_LOOPS if the compiler has buggy
43 #    scoping for the for-loop
44 # 3. Defines USE_ASSERT if the user wants to use assertions
45 # -----------------------------------------------------------------------
46
47
48 AC_DEFUN([LF_CXX_PORTABILITY],[
49
50   dnl
51   dnl Check for common C++ portability problems
52   dnl
53
54   dnl AC_LANG_PUSH
55   dnl AC_LANG_CPLUSPLUS
56   AC_LANG_SAVE
57   AC_LANG_CPLUSPLUS
58
59   dnl Check whether we have bool
60   AC_MSG_CHECKING(whether C++ has bool)
61   AC_TRY_RUN([main() { bool b1=true; bool b2=false; }],
62              [ AC_MSG_RESULT(yes) ],
63              [ AC_MSG_RESULT(no)
64                AC_DEFINE(CXX_HAS_NO_BOOL,[],[Define if C++ is missing bool type]) ],
65              [ AC_MSG_WARN(Don't cross-compile)]
66             )
67
68   dnl Test whether C++ has buggy for-loops
69   AC_MSG_CHECKING(whether C++ has buggy scoping in for-loops)
70   AC_TRY_COMPILE([#include <iostream.h>], [
71    for (int i=0;i<10;i++) { }
72    for (int i=0;i<10;i++) { }
73 ], [ AC_MSG_RESULT(no) ],
74    [ AC_MSG_RESULT(yes)
75      AC_DEFINE(CXX_HAS_BUGGY_FOR_LOOPS,[],[Define if for loop scoping is broken]) ])
76
77   dnl Test whether the user wants to enable assertions
78   AC_MSG_CHECKING(whether user wants assertions)
79   AC_ARG_ENABLE(assert,
80                 [  --disable-assert        don't use cpp.h assert],
81                 [ AC_DEFINE(NDEBUG,[],[Define to disable asserts (don't doit!)])
82                   AC_MSG_RESULT(no)  ],
83                 [ AC_MSG_RESULT(yes) ],
84                )
85
86   dnl Test whether C++ has std::isnan
87   AC_MSG_CHECKING(whether C++ has std::isnan)
88   AC_TRY_COMPILE([#include <cmath>], [
89    std::isnan(0);
90 ], [ AC_MSG_RESULT(yes)
91         AC_DEFINE(CXX_HAS_STD_ISNAN,[],[Define if has std::isnan]) ],
92    [ AC_MSG_RESULT(no) ])
93
94   dnl Done with the portability checks
95   dnl AC_LANG_POP([C++])
96   AC_LANG_RESTORE
97 ])
98
99 AH_BOTTOM([// Workaround for compilers with buggy for-loop scoping
100 // That's quite a few compilers actually including recent versions of
101 // Dec Alpha cxx, HP-UX CC and SGI CC.
102 // The trivial "if" statement provides the correct scoping to the 
103 // for loop
104
105 #ifdef CXX_HAS_BUGGY_FOR_LOOPS
106 #undef for
107 #define for if(1) for
108 #endif
109 ])
110
111 AH_BOTTOM([// If the C++ compiler we use doesn't have bool, then
112 // the following is a near-perfect work-around. 
113 // You must make sure your code does not depend on "int" and "bool"
114 // being two different types, in overloading for instance.
115
116 #ifdef CXX_HAS_NO_BOOL
117 #define bool int
118 #define true 1
119 #define false 0
120 #endif
121 ])