1dnl
2dnl  This file is part of Bakefile (http://www.bakefile.org)
3dnl
4dnl  Copyright (C) 2003-2007 Vaclav Slavik, David Elliott and others
5dnl
6dnl  Permission is hereby granted, free of charge, to any person obtaining a
7dnl  copy of this software and associated documentation files (the "Software"),
8dnl  to deal in the Software without restriction, including without limitation
9dnl  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10dnl  and/or sell copies of the Software, and to permit persons to whom the
11dnl  Software is furnished to do so, subject to the following conditions:
12dnl
13dnl  The above copyright notice and this permission notice shall be included in
14dnl  all copies or substantial portions of the Software.
15dnl
16dnl  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17dnl  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18dnl  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19dnl  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20dnl  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21dnl  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22dnl  DEALINGS IN THE SOFTWARE.
23dnl
24dnl  Compiler detection macros by David Elliott and Vadim Zeitlin
25dnl
26
27
28dnl ===========================================================================
29dnl Macros to detect different C/C++ compilers
30dnl ===========================================================================
31
32dnl Based on autoconf _AC_LANG_COMPILER_GNU
33dnl _AC_BAKEFILE_LANG_COMPILER(NAME, LANG, SYMBOL, IF-YES, IF-NO)
34AC_DEFUN([_AC_BAKEFILE_LANG_COMPILER],
35[
36    AC_LANG_PUSH($2)
37    AC_CACHE_CHECK(
38        [whether we are using the $1 $2 compiler],
39        [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3],
40        [AC_TRY_COMPILE(
41            [],
42            [
43             #ifndef $3
44                choke me
45             #endif
46            ],
47            [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3=yes],
48            [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3=no]
49         )
50        ]
51    )
52    if test "x$bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3" = "xyes"; then
53        :; $4
54    else
55        :; $5
56    fi
57    AC_LANG_POP($2)
58])
59
60dnl More specific version of the above macro checking whether the compiler
61dnl version is at least the given one (assumes that we do use this compiler)
62dnl
63dnl _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(NAME, LANG, SYMBOL, VER, VERMSG, IF-YES, IF-NO)
64AC_DEFUN([_AC_BAKEFILE_LANG_COMPILER_LATER_THAN],
65[
66    AC_LANG_PUSH($2)
67    AC_CACHE_CHECK(
68        [whether we are using $1 $2 compiler v$5 or later],
69        [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4],
70        [AC_TRY_COMPILE(
71            [],
72            [
73             #ifndef $3 || $3 < $4
74                choke me
75             #endif
76            ],
77            [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4=yes],
78            [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4=no]
79         )
80        ]
81    )
82    if test "x$bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4" = "xyes"; then
83        :; $6
84    else
85        :; $7
86    fi
87    AC_LANG_POP($2)
88])
89
90dnl IBM xlC compiler defines __xlC__ for both C and C++
91AC_DEFUN([AC_BAKEFILE_PROG_XLCC],
92[
93    _AC_BAKEFILE_LANG_COMPILER([IBM xlC], C, __xlC__, XLCC=yes)
94])
95
96AC_DEFUN([AC_BAKEFILE_PROG_XLCXX],
97[
98    _AC_BAKEFILE_LANG_COMPILER([IBM xlC], C++, __xlC__, XLCXX=yes)
99])
100
101dnl recent versions of SGI mipsPro compiler define _SGI_COMPILER_VERSION
102dnl
103dnl NB: old versions define _COMPILER_VERSION but this could probably be
104dnl     defined by other compilers too so don't test for it to be safe
105AC_DEFUN([AC_BAKEFILE_PROG_SGICC],
106[
107    _AC_BAKEFILE_LANG_COMPILER(SGI, C, _SGI_COMPILER_VERSION, SGICC=yes)
108])
109
110AC_DEFUN([AC_BAKEFILE_PROG_SGICXX],
111[
112    _AC_BAKEFILE_LANG_COMPILER(SGI, C++, _SGI_COMPILER_VERSION, SGICXX=yes)
113])
114
115dnl Sun compiler defines __SUNPRO_C/__SUNPRO_CC
116AC_DEFUN([AC_BAKEFILE_PROG_SUNCC],
117[
118    _AC_BAKEFILE_LANG_COMPILER(Sun, C, __SUNPRO_C, SUNCC=yes)
119])
120
121AC_DEFUN([AC_BAKEFILE_PROG_SUNCXX],
122[
123    _AC_BAKEFILE_LANG_COMPILER(Sun, C++, __SUNPRO_CC, SUNCXX=yes)
124])
125
126dnl Intel icc compiler defines __INTEL_COMPILER for both C and C++
127AC_DEFUN([AC_BAKEFILE_PROG_INTELCC],
128[
129    _AC_BAKEFILE_LANG_COMPILER(Intel, C, __INTEL_COMPILER, INTELCC=yes)
130])
131
132AC_DEFUN([AC_BAKEFILE_PROG_INTELCXX],
133[
134    _AC_BAKEFILE_LANG_COMPILER(Intel, C++, __INTEL_COMPILER, INTELCXX=yes)
135])
136
137dnl Intel compiler command line options changed in incompatible ways sometimes
138dnl before v8 (-KPIC was replaced with gcc-compatible -fPIC) and again in v10
139dnl (-create-pch deprecated in favour of -pch-create) so we need to test for
140dnl its exact version too
141AC_DEFUN([AC_BAKEFILE_PROG_INTELCC_8],
142[
143    _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C, __INTEL_COMPILER, 800, 8, INTELCC8=yes)
144])
145AC_DEFUN([AC_BAKEFILE_PROG_INTELCXX_8],
146[
147    _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C++, __INTEL_COMPILER, 800, 8, INTELCXX8=yes)
148])
149
150AC_DEFUN([AC_BAKEFILE_PROG_INTELCC_10],
151[
152    _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C, __INTEL_COMPILER, 1000, 10, INTELCC10=yes)
153])
154
155AC_DEFUN([AC_BAKEFILE_PROG_INTELCXX_10],
156[
157    _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C++, __INTEL_COMPILER, 1000, 10, INTELCXX10=yes)
158])
159
160dnl HP-UX aCC: see http://docs.hp.com/en/6162/preprocess.htm#macropredef
161AC_DEFUN([AC_BAKEFILE_PROG_HPCC],
162[
163    _AC_BAKEFILE_LANG_COMPILER(HP, C, __HP_cc, HPCC=yes)
164])
165
166AC_DEFUN([AC_BAKEFILE_PROG_HPCXX],
167[
168    _AC_BAKEFILE_LANG_COMPILER(HP, C++, __HP_aCC, HPCXX=yes)
169])
170
171dnl Tru64 cc and cxx
172AC_DEFUN([AC_BAKEFILE_PROG_COMPAQCC],
173[
174    _AC_BAKEFILE_LANG_COMPILER(Compaq, C, __DECC, COMPAQCC=yes)
175])
176
177AC_DEFUN([AC_BAKEFILE_PROG_COMPAQCXX],
178[
179    _AC_BAKEFILE_LANG_COMPILER(Compaq, C++, __DECCXX, COMPAQCXX=yes)
180])
181
182dnl ===========================================================================
183dnl Macros to do all of the compiler detections as one macro
184dnl ===========================================================================
185
186dnl check for different proprietary compilers depending on target platform
187dnl _AC_BAKEFILE_PROG_COMPILER(LANG)
188AC_DEFUN([_AC_BAKEFILE_PROG_COMPILER],
189[
190    AC_REQUIRE([AC_PROG_$1])
191
192    dnl Intel compiler can be used under several different OS and even
193    dnl different architectures (x86, amd64 and Itanium) so it's easier to just
194    dnl always test for it
195    AC_BAKEFILE_PROG_INTEL$1
196
197    dnl If we use Intel compiler we also need to know its version
198    if test "$INTEL$1" = "yes"; then
199        AC_BAKEFILE_PROG_INTEL$1_8
200        AC_BAKEFILE_PROG_INTEL$1_10
201    fi
202
203    dnl if we're using gcc, we can't be using any of incompatible compilers
204    if test "x$G$1" != "xyes"; then
205        dnl most of these compilers are only used under well-defined OS so
206        dnl don't waste time checking for them on other ones
207        case `uname -s` in
208            AIX*)
209                AC_BAKEFILE_PROG_XL$1
210                ;;
211
212            Darwin)
213                AC_BAKEFILE_PROG_XL$1
214                ;;
215
216            IRIX*)
217                AC_BAKEFILE_PROG_SGI$1
218                ;;
219
220            Linux*)
221                dnl Sun CC is now available under Linux too, test for it unless
222                dnl we already found that we were using a different compiler
223                if test "$INTEL$1" != "yes"; then
224                    AC_BAKEFILE_PROG_SUN$1
225                fi
226                ;;
227
228            HP-UX*)
229                AC_BAKEFILE_PROG_HP$1
230                ;;
231
232            OSF1)
233                AC_BAKEFILE_PROG_COMPAQ$1
234                ;;
235
236            SunOS)
237                AC_BAKEFILE_PROG_SUN$1
238                ;;
239        esac
240    fi
241])
242
243AC_DEFUN([AC_BAKEFILE_PROG_CC],
244[
245    _AC_BAKEFILE_PROG_COMPILER(CC)
246])
247
248AC_DEFUN([AC_BAKEFILE_PROG_CXX],
249[
250    _AC_BAKEFILE_PROG_COMPILER(CXX)
251])
252
253