2 dnl This file is part of Bakefile (http://www.bakefile.org)
4 dnl Copyright (C) 2003-2007 Vaclav Slavik, David Elliott and others
6 dnl Permission is hereby granted, free of charge, to any person obtaining a
7 dnl copy of this software and associated documentation files (the "Software"),
8 dnl to deal in the Software without restriction, including without limitation
9 dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 dnl and/or sell copies of the Software, and to permit persons to whom the
11 dnl Software is furnished to do so, subject to the following conditions:
13 dnl The above copyright notice and this permission notice shall be included in
14 dnl all copies or substantial portions of the Software.
16 dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 dnl DEALINGS IN THE SOFTWARE.
24 dnl $Id: bakefile-lang.m4 1278 2008-11-17 22:26:10Z vadz $
26 dnl Compiler detection macros by David Elliott and Vadim Zeitlin
30 dnl ===========================================================================
31 dnl Macros to detect different C/C++ compilers
32 dnl ===========================================================================
34 dnl Based on autoconf _AC_LANG_COMPILER_GNU
35 dnl _AC_BAKEFILE_LANG_COMPILER(NAME, LANG, SYMBOL, IF-YES, IF-NO)
36 AC_DEFUN([_AC_BAKEFILE_LANG_COMPILER],
40 [whether we are using the $1 $2 compiler],
41 [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3],
49 [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3=yes],
50 [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3=no]
54 if test "x$bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3" = "xyes"; then
62 dnl More specific version of the above macro checking whether the compiler
63 dnl version is at least the given one (assumes that we do use this compiler)
65 dnl _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(NAME, LANG, SYMBOL, VER, VERMSG, IF-YES, IF-NO)
66 AC_DEFUN([_AC_BAKEFILE_LANG_COMPILER_LATER_THAN],
70 [whether we are using $1 $2 compiler v$5 or later],
71 [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4],
79 [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4=yes],
80 [bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4=no]
84 if test "x$bakefile_cv_[]_AC_LANG_ABBREV[]_compiler_[]$3[]_lt_[]$4" = "xyes"; then
92 dnl CodeWarrior Metrowerks compiler defines __MWERKS__ for both C and C++
93 AC_DEFUN([AC_BAKEFILE_PROG_MWCC],
95 _AC_BAKEFILE_LANG_COMPILER(Metrowerks, C, __MWERKS__, MWCC=yes)
98 AC_DEFUN([AC_BAKEFILE_PROG_MWCXX],
100 _AC_BAKEFILE_LANG_COMPILER(Metrowerks, C++, __MWERKS__, MWCXX=yes)
103 dnl IBM xlC compiler defines __xlC__ for both C and C++
104 AC_DEFUN([AC_BAKEFILE_PROG_XLCC],
106 _AC_BAKEFILE_LANG_COMPILER([IBM xlC], C, __xlC__, XLCC=yes)
109 AC_DEFUN([AC_BAKEFILE_PROG_XLCXX],
111 _AC_BAKEFILE_LANG_COMPILER([IBM xlC], C++, __xlC__, XLCXX=yes)
114 dnl recent versions of SGI mipsPro compiler define _SGI_COMPILER_VERSION
116 dnl NB: old versions define _COMPILER_VERSION but this could probably be
117 dnl defined by other compilers too so don't test for it to be safe
118 AC_DEFUN([AC_BAKEFILE_PROG_SGICC],
120 _AC_BAKEFILE_LANG_COMPILER(SGI, C, _SGI_COMPILER_VERSION, SGICC=yes)
123 AC_DEFUN([AC_BAKEFILE_PROG_SGICXX],
125 _AC_BAKEFILE_LANG_COMPILER(SGI, C++, _SGI_COMPILER_VERSION, SGICXX=yes)
128 dnl Sun compiler defines __SUNPRO_C/__SUNPRO_CC
129 AC_DEFUN([AC_BAKEFILE_PROG_SUNCC],
131 _AC_BAKEFILE_LANG_COMPILER(Sun, C, __SUNPRO_C, SUNCC=yes)
134 AC_DEFUN([AC_BAKEFILE_PROG_SUNCXX],
136 _AC_BAKEFILE_LANG_COMPILER(Sun, C++, __SUNPRO_CC, SUNCXX=yes)
139 dnl Intel icc compiler defines __INTEL_COMPILER for both C and C++
140 AC_DEFUN([AC_BAKEFILE_PROG_INTELCC],
142 _AC_BAKEFILE_LANG_COMPILER(Intel, C, __INTEL_COMPILER, INTELCC=yes)
145 AC_DEFUN([AC_BAKEFILE_PROG_INTELCXX],
147 _AC_BAKEFILE_LANG_COMPILER(Intel, C++, __INTEL_COMPILER, INTELCXX=yes)
150 dnl Intel compiler command line options changed in incompatible ways sometimes
151 dnl before v8 (-KPIC was replaced with gcc-compatible -fPIC) and again in v10
152 dnl (-create-pch deprecated in favour of -pch-create) so we need to test for
153 dnl its exact version too
154 AC_DEFUN([AC_BAKEFILE_PROG_INTELCC_8],
156 _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C, __INTEL_COMPILER, 800, 8, INTELCC8=yes)
158 AC_DEFUN([AC_BAKEFILE_PROG_INTELCXX_8],
160 _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C++, __INTEL_COMPILER, 800, 8, INTELCXX8=yes)
163 AC_DEFUN([AC_BAKEFILE_PROG_INTELCC_10],
165 _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C, __INTEL_COMPILER, 1000, 10, INTELCC10=yes)
168 AC_DEFUN([AC_BAKEFILE_PROG_INTELCXX_10],
170 _AC_BAKEFILE_LANG_COMPILER_LATER_THAN(Intel, C++, __INTEL_COMPILER, 1000, 10, INTELCXX10=yes)
173 dnl HP-UX aCC: see http://docs.hp.com/en/6162/preprocess.htm#macropredef
174 AC_DEFUN([AC_BAKEFILE_PROG_HPCC],
176 _AC_BAKEFILE_LANG_COMPILER(HP, C, __HP_cc, HPCC=yes)
179 AC_DEFUN([AC_BAKEFILE_PROG_HPCXX],
181 _AC_BAKEFILE_LANG_COMPILER(HP, C++, __HP_aCC, HPCXX=yes)
185 AC_DEFUN([AC_BAKEFILE_PROG_COMPAQCC],
187 _AC_BAKEFILE_LANG_COMPILER(Compaq, C, __DECC, COMPAQCC=yes)
190 AC_DEFUN([AC_BAKEFILE_PROG_COMPAQCXX],
192 _AC_BAKEFILE_LANG_COMPILER(Compaq, C++, __DECCXX, COMPAQCXX=yes)
195 dnl ===========================================================================
196 dnl macros to detect specialty compiler options
197 dnl ===========================================================================
199 dnl Figure out if we need to pass -ext o to compiler (MetroWerks)
200 AC_DEFUN([AC_BAKEFILE_METROWERKS_EXTO],
201 [AC_CACHE_CHECK([if the _AC_LANG compiler requires -ext o], bakefile_cv_[]_AC_LANG_ABBREV[]_exto,
202 dnl First create an empty conf test
203 [AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
204 dnl Now remove .o and .c.o or .cc.o
205 rm -f conftest.$ac_objext conftest.$ac_ext.o
206 dnl Now compile the test
207 AS_IF([AC_TRY_EVAL(ac_compile)],
208 dnl If the test succeeded look for conftest.c.o or conftest.cc.o
209 [for ac_file in `(ls conftest.* 2>/dev/null)`; do
212 bakefile_cv_[]_AC_LANG_ABBREV[]_exto="-ext o"
218 [AC_MSG_FAILURE([cannot figure out if compiler needs -ext o: cannot compile])
221 rm -f conftest.$ac_ext.o conftest.$ac_objext conftest.$ac_ext
222 ]) dnl AC_CACHE_CHECK
224 if test "x$bakefile_cv_[]_AC_LANG_ABBREV[]_exto" '!=' "x"; then
225 if test "[]_AC_LANG_ABBREV[]" = "c"; then
226 CFLAGS="$bakefile_cv_[]_AC_LANG_ABBREV[]_exto $CFLAGS"
228 if test "[]_AC_LANG_ABBREV[]" = "cxx"; then
229 CXXFLAGS="$bakefile_cv_[]_AC_LANG_ABBREV[]_exto $CXXFLAGS"
235 dnl ===========================================================================
236 dnl Macros to do all of the compiler detections as one macro
237 dnl ===========================================================================
239 dnl check for different proprietary compilers depending on target platform
240 dnl _AC_BAKEFILE_PROG_COMPILER(LANG)
241 AC_DEFUN([_AC_BAKEFILE_PROG_COMPILER],
243 AC_REQUIRE([AC_PROG_$1])
245 dnl Intel compiler can be used under several different OS and even
246 dnl different architectures (x86, amd64 and Itanium) so it's easier to just
247 dnl always test for it
248 AC_BAKEFILE_PROG_INTEL$1
250 dnl If we use Intel compiler we also need to know its version
251 if test "$INTEL$1" = "yes"; then
252 AC_BAKEFILE_PROG_INTEL$1_8
253 AC_BAKEFILE_PROG_INTEL$1_10
256 dnl if we're using gcc, we can't be using any of incompatible compilers
257 if test "x$G$1" != "xyes"; then
258 if test "x$1" = "xC"; then
259 AC_BAKEFILE_METROWERKS_EXTO
260 if test "x$bakefile_cv_c_exto" '!=' "x"; then
261 unset ac_cv_prog_cc_g
266 dnl most of these compilers are only used under well-defined OS so
267 dnl don't waste time checking for them on other ones
270 AC_BAKEFILE_PROG_XL$1
274 AC_BAKEFILE_PROG_MW$1
275 if test "$MW$1" != "yes"; then
276 AC_BAKEFILE_PROG_XL$1
281 AC_BAKEFILE_PROG_SGI$1
285 dnl Sun CC is now available under Linux too, test for it unless
286 dnl we already found that we were using a different compiler
287 if test "$INTEL$1" != "yes"; then
288 AC_BAKEFILE_PROG_SUN$1
293 AC_BAKEFILE_PROG_HP$1
297 AC_BAKEFILE_PROG_COMPAQ$1
301 AC_BAKEFILE_PROG_SUN$1
307 AC_DEFUN([AC_BAKEFILE_PROG_CC],
309 _AC_BAKEFILE_PROG_COMPILER(CC)
312 AC_DEFUN([AC_BAKEFILE_PROG_CXX],
314 _AC_BAKEFILE_PROG_COMPILER(CXX)