1# ===========================================================================
2#   https://www.gnu.org/software/autoconf-archive/ax_compiler_version.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_COMPILER_VERSION
8#
9# DESCRIPTION
10#
11#   This macro retrieves the compiler version and returns it in the cache
12#   variable $ax_cv_c_compiler_version for C and $ax_cv_cxx_compiler_version
13#   for C++.
14#
15#   Version is returned as epoch:major.minor.patchversion
16#
17#   Epoch is used in order to have an increasing version number in case of
18#   marketing change.
19#
20#   Epoch use: * borland compiler use chronologically 0turboc for turboc
21#   era,
22#
23#     1borlanc BORLANDC++ before 5, 2cppbuilder for cppbuilder era,
24#     3borlancpp for return of BORLANDC++ (after version 5.5),
25#     4cppbuilder for cppbuilder with year version,
26#     and 5xe for XE era.
27#
28#   An empty string is returned otherwise.
29#
30# LICENSE
31#
32#   Copyright (c) 2014 Bastien ROUCARIES <roucaries.bastien+autoconf@gmail.com>
33#
34#   Copying and distribution of this file, with or without modification, are
35#   permitted in any medium without royalty provided the copyright notice
36#   and this notice are preserved. This file is offered as-is, without any
37#   warranty.
38
39#serial 12
40
41# for intel
42AC_DEFUN([_AX_COMPILER_VERSION_INTEL],
43  [ dnl
44  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
45    [__INTEL_COMPILER/100],,
46    AC_MSG_FAILURE([[[$0]] unknown intel compiler version]))
47  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
48    [(__INTEL_COMPILER%100)/10],,
49    AC_MSG_FAILURE([[[$0]] unknown intel compiler version]))
50  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
51    [(__INTEL_COMPILER%10)],,
52    AC_MSG_FAILURE([[[$0]] unknown intel compiler version]))
53  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
54  ])
55
56# for IBM
57AC_DEFUN([_AX_COMPILER_VERSION_IBM],
58  [ dnl
59  dnl check between z/OS C/C++  and XL C/C++
60  AC_COMPILE_IFELSE([
61    AC_LANG_PROGRAM([],
62      [
63        #if defined(__COMPILER_VER__)
64        choke me;
65        #endif
66      ])],
67    [
68      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
69        [__xlC__/100],,
70      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler major version]))
71      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
72        [__xlC__%100],,
73      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler minor version]))
74      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
75        [__xlC_ver__/0x100],,
76      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler patch version]))
77      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_build,
78        [__xlC_ver__%0x100],,
79      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler build version]))
80      ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_build"
81    ],
82    [
83      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
84        [__xlC__%1000],,
85      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler patch version]))
86      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
87        [(__xlC__/10000)%10],,
88      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler minor version]))
89      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
90        [(__xlC__/100000)%10],,
91      	AC_MSG_FAILURE([[[$0]] unknown IBM compiler major version]))
92      ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
93    ])
94])
95
96# for pathscale
97AC_DEFUN([_AX_COMPILER_VERSION_PATHSCALE],[
98  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
99    __PATHCC__,,
100    AC_MSG_FAILURE([[[$0]] unknown pathscale major]))
101  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
102    __PATHCC_MINOR__,,
103    AC_MSG_FAILURE([[[$0]] unknown pathscale minor]))
104  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
105    [__PATHCC_PATCHLEVEL__],,
106    AC_MSG_FAILURE([[[$0]] unknown pathscale patch level]))
107  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
108  ])
109
110# for clang
111AC_DEFUN([_AX_COMPILER_VERSION_CLANG],[
112  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
113    __clang_major__,,
114    AC_MSG_FAILURE([[[$0]] unknown clang major]))
115  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
116    __clang_minor__,,
117    AC_MSG_FAILURE([[[$0]] unknown clang minor]))
118  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
119    [__clang_patchlevel__],,0)
120  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
121  ])
122
123# for crayc
124AC_DEFUN([_AX_COMPILER_VERSION_CRAY],[
125  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
126    _RELEASE,,
127    AC_MSG_FAILURE([[[$0]] unknown crayc release]))
128  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
129    _RELEASE_MINOR,,
130    AC_MSG_FAILURE([[[$0]] unknown crayc minor]))
131  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor"
132  ])
133
134# for fujitsu
135AC_DEFUN([_AX_COMPILER_VERSION_FUJITSU],[
136  AC_COMPUTE_INT(ax_cv_[]_AC_LANG_ABBREV[]_compiler_version,
137                 __FCC_VERSION,,
138		 AC_MSG_FAILURE([[[$0]]unknown fujitsu release]))
139  ])
140
141# for GNU
142AC_DEFUN([_AX_COMPILER_VERSION_GNU],[
143  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
144    __GNUC__,,
145    AC_MSG_FAILURE([[[$0]] unknown gcc major]))
146  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
147    __GNUC_MINOR__,,
148    AC_MSG_FAILURE([[[$0]] unknown gcc minor]))
149  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
150    [__GNUC_PATCHLEVEL__],,
151    AC_MSG_FAILURE([[[$0]] unknown gcc patch level]))
152  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
153  ])
154
155# For sun
156AC_DEFUN([_AX_COMPILER_VERSION_SUN],[
157  m4_define([_AX_COMPILER_VERSION_SUN_NUMBER],
158            [
159	     #if defined(__SUNPRO_CC)
160	     __SUNPRO_CC
161	     #else
162	     __SUNPRO_C
163	     #endif
164	    ])
165  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_until59,
166    !!(_AX_COMPILER_VERSION_SUN_NUMBER < 0x1000),,
167    AC_MSG_FAILURE([[[$0]] unknown sun release version]))
168  AS_IF([test "X$_ax_[]_AC_LANG_ABBREV[]_compiler_version_until59" = X1],
169    [dnl
170      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
171        _AX_COMPILER_VERSION_SUN_NUMBER % 0x10,,
172	AC_MSG_FAILURE([[[$0]] unknown sun patch version]))
173      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
174        (_AX_COMPILER_VERSION_SUN_NUMBER / 0x10) % 0x10,,
175        AC_MSG_FAILURE([[[$0]] unknown sun minor version]))
176      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
177        (_AX_COMPILER_VERSION_SUN_NUMBER / 0x100),,
178        AC_MSG_FAILURE([[[$0]] unknown sun major version]))
179    ],
180    [dnl
181      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
182        _AX_COMPILER_VERSION_SUN_NUMBER % 0x10,,
183        AC_MSG_FAILURE([[[$0]] unknown sun patch version]))
184      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
185        (_AX_COMPILER_VERSION_SUN_NUMBER / 0x100) % 0x100,,
186        AC_MSG_FAILURE([[[$0]] unknown sun minor version]))
187      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
188        (_AX_COMPILER_VERSION_SUN_NUMBER / 0x1000),,
189        AC_MSG_FAILURE([[[$0]] unknown sun major version]))
190    ])
191  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
192])
193
194AC_DEFUN([_AX_COMPILER_VERSION_HP],[
195  m4_define([_AX_COMPILER_VERSION_HP_NUMBER],
196            [
197	     #if defined(__HP_cc)
198	     __HP_cc
199	     #else
200	     __HP_aCC
201	     #endif
202	    ])
203  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_untilA0121,
204    !!(_AX_COMPILER_VERSION_HP_NUMBER <= 1),,
205    AC_MSG_FAILURE([[[$0]] unknown hp release version]))
206  AS_IF([test "X$_ax_[]_AC_LANG_ABBREV[]_compiler_version_untilA0121" = X1],
207    [dnl By default output last version with this behavior.
208     dnl it is so old
209      ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="01.21.00"
210    ],
211    [dnl
212      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
213        (_AX_COMPILER_VERSION_HP_NUMBER % 100),,
214        AC_MSG_FAILURE([[[$0]] unknown hp release version]))
215      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
216        ((_AX_COMPILER_VERSION_HP_NUMBER / 100)%100),,
217        AC_MSG_FAILURE([[[$0]] unknown hp minor version]))
218      AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
219        ((_AX_COMPILER_VERSION_HP_NUMBER / 10000)%100),,
220        AC_MSG_FAILURE([[[$0]] unknown hp major version]))
221      ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
222    ])
223])
224
225AC_DEFUN([_AX_COMPILER_VERSION_DEC],[dnl
226  m4_define([_AX_COMPILER_VERSION_DEC_NUMBER],
227            [
228	     #if defined(__DECC_VER)
229	     __DECC_VER
230	     #else
231	     __DECCXX_VER
232	     #endif
233	    ])
234  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
235    (_AX_COMPILER_VERSION_DEC_NUMBER % 10000),,
236    AC_MSG_FAILURE([[[$0]] unknown dec release version]))
237  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
238    ((_AX_COMPILER_VERSION_DEC_NUMBER / 100000UL)%100),,
239    AC_MSG_FAILURE([[[$0]] unknown dec minor version]))
240  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
241    ((_AX_COMPILER_VERSION_DEC_NUMBER / 10000000UL)%100),,
242    AC_MSG_FAILURE([[[$0]] unknown dec major version]))
243  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
244  ])
245
246# borland
247AC_DEFUN([_AX_COMPILER_VERSION_BORLAND],[dnl
248  m4_define([_AX_COMPILER_VERSION_TURBOC_NUMBER],
249            [
250	     #if defined(__TURBOC__)
251	     __TURBOC__
252	     #else
253	     choke me
254	     #endif
255	    ])
256  m4_define([_AX_COMPILER_VERSION_BORLANDC_NUMBER],
257            [
258	     #if defined(__BORLANDC__)
259	     __BORLANDC__
260	     #else
261	     __CODEGEARC__
262	     #endif
263	    ])
264 AC_COMPILE_IFELSE(
265   [AC_LANG_PROGRAM(,
266     _AX_COMPILER_VERSION_TURBOC_NUMBER)],
267   [dnl TURBOC
268     AC_COMPUTE_INT(
269       _ax_[]_AC_LANG_ABBREV[]_compiler_version_turboc_raw,
270       _AX_COMPILER_VERSION_TURBOC_NUMBER,,
271       AC_MSG_FAILURE([[[$0]] unknown turboc version]))
272     AS_IF(
273       [test $_ax_[]_AC_LANG_ABBREV[]_compiler_version_turboc_raw -lt 661 || test $_ax_[]_AC_LANG_ABBREV[]_compiler_version_turboc_raw -gt 1023],
274       [dnl compute normal version
275        AC_COMPUTE_INT(
276	  _ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
277	  _AX_COMPILER_VERSION_TURBOC_NUMBER % 0x100,,
278	  AC_MSG_FAILURE([[[$0]] unknown turboc minor version]))
279	AC_COMPUTE_INT(
280	  _ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
281	  (_AX_COMPILER_VERSION_TURBOC_NUMBER/0x100)%0x100,,
282	  AC_MSG_FAILURE([[[$0]] unknown turboc major version]))
283	ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="0turboc:$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor"],
284      [dnl special version
285       AS_CASE([$_ax_[]_AC_LANG_ABBREV[]_compiler_version_turboc_raw],
286         [661],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="0turboc:1.00"],
287	 [662],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="0turboc:1.01"],
288         [663],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="0turboc:2.00"],
289	 [
290	 AC_MSG_WARN([[[$0]] unknown turboc version between 0x295 and 0x400 please report bug])
291	 ax_cv_[]_AC_LANG_ABBREV[]_compiler_version=""
292	 ])
293      ])
294    ],
295    # borlandc
296    [
297    AC_COMPUTE_INT(
298      _ax_[]_AC_LANG_ABBREV[]_compiler_version_borlandc_raw,
299      _AX_COMPILER_VERSION_BORLANDC_NUMBER,,
300      AC_MSG_FAILURE([[[$0]] unknown borlandc version]))
301    AS_CASE([$_ax_[]_AC_LANG_ABBREV[]_compiler_version_borlandc_raw],
302      dnl BORLANDC++ before 5.5
303      [512] ,[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:2.00"],
304      [1024],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:3.00"],
305      [1024],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:3.00"],
306      [1040],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:3.1"],
307      [1106],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:4.0"],
308      [1280],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:5.0"],
309      [1312],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="1borlanc:5.02"],
310      dnl C++ Builder era
311      [1328],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="2cppbuilder:3.0"],
312      [1344],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="2cppbuilder:4.0"],
313      dnl BORLANDC++ after 5.5
314      [1360],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="3borlancpp:5.5"],
315      [1361],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="3borlancpp:5.51"],
316      [1378],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="3borlancpp:5.6.4"],
317      dnl C++ Builder with year number
318      [1392],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="4cppbuilder:2006"],
319      [1424],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="4cppbuilder:2007"],
320      [1555],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="4cppbuilder:2009"],
321      [1569],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="4cppbuilder:2010"],
322      dnl XE version
323      [1584],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="5xe"],
324      [1600],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="5xe:2"],
325      [1616],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="5xe:3"],
326      [1632],[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="5xe:4"],
327      [
328      AC_MSG_WARN([[[$0]] Unknown borlandc compiler version $_ax_[]_AC_LANG_ABBREV[]_compiler_version_borlandc_raw please report bug])
329      ])
330    ])
331  ])
332
333# COMO
334AC_DEFUN([_AX_COMPILER_VERSION_COMEAU],
335  [ dnl
336  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
337    [__COMO_VERSION__%100],,
338    AC_MSG_FAILURE([[[$0]] unknown comeau compiler minor version]))
339  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
340    [(__COMO_VERSION__/100)%10],,
341    AC_MSG_FAILURE([[[$0]] unknown comeau compiler major version]))
342  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor"
343  ])
344
345# KAI
346AC_DEFUN([_AX_COMPILER_VERSION_KAI],[
347  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
348    [__KCC_VERSION%100],,
349    AC_MSG_FAILURE([[[$0]] unknown kay compiler patch version]))
350  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
351    [(__KCC_VERSION/100)%10],,
352    AC_MSG_FAILURE([[[$0]] unknown kay compiler minor version]))
353  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
354    [(__KCC_VERSION/1000)%10],,
355    AC_MSG_FAILURE([[[$0]] unknown kay compiler major version]))
356  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
357  ])
358
359dnl LCC
360dnl LCC does not output version...
361
362# SGI
363AC_DEFUN([_AX_COMPILER_VERSION_SGI],[
364   m4_define([_AX_COMPILER_VERSION_SGI_NUMBER],
365            [
366	     #if defined(_COMPILER_VERSION)
367	     _COMPILER_VERSION
368	     #else
369	     _SGI_COMPILER_VERSION
370	     #endif
371	    ])
372  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
373    [_AX_COMPILER_VERSION_SGI_NUMBER%10],,
374    AC_MSG_FAILURE([[[$0]] unknown SGI compiler patch version]))
375  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
376    [(_AX_COMPILER_VERSION_SGI_NUMBER/10)%10],,
377    AC_MSG_FAILURE([[[$0]] unknown SGI compiler minor version]))
378  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
379    [(_AX_COMPILER_VERSION_SGI_NUMBER/100)%10],,
380    AC_MSG_FAILURE([[[$0]] unknown SGI compiler major version]))
381  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
382  ])
383
384# microsoft
385AC_DEFUN([_AX_COMPILER_VERSION_MICROSOFT],[
386  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
387    _MSC_VER%100,,
388    AC_MSG_FAILURE([[[$0]] unknown microsoft compiler minor version]))
389  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
390    (_MSC_VER/100)%100,,
391    AC_MSG_FAILURE([[[$0]] unknown microsoft compiler major version]))
392  dnl could be overridden
393  _ax_[]_AC_LANG_ABBREV[]_compiler_version_patch=0
394  _ax_[]_AC_LANG_ABBREV[]_compiler_version_build=0
395  # special case for version 6
396  AS_IF([test "X$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major" = "X12"],
397    [AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
398       _MSC_FULL_VER%1000,,
399       _ax_[]_AC_LANG_ABBREV[]_compiler_version_patch=0)])
400  # for version 7
401  AS_IF([test "X$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major" = "X13"],
402    [AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
403       _MSC_FULL_VER%1000,,
404       AC_MSG_FAILURE([[[$0]] unknown microsoft compiler patch version]))
405    ])
406  # for version > 8
407 AS_IF([test $_ax_[]_AC_LANG_ABBREV[]_compiler_version_major -ge 14],
408    [AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
409       _MSC_FULL_VER%10000,,
410       AC_MSG_FAILURE([[[$0]] unknown microsoft compiler patch version]))
411    ])
412 AS_IF([test $_ax_[]_AC_LANG_ABBREV[]_compiler_version_major -ge 15],
413    [AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_build,
414       _MSC_BUILD,,
415       AC_MSG_FAILURE([[[$0]] unknown microsoft compiler build version]))
416    ])
417 ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_build"
418 ])
419
420# for metrowerks
421AC_DEFUN([_AX_COMPILER_VERSION_METROWERKS],[dnl
422  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
423    __MWERKS__%0x100,,
424    AC_MSG_FAILURE([[[$0]] unknown metrowerks compiler patch version]))
425  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
426    (__MWERKS__/0x100)%0x10,,
427    AC_MSG_FAILURE([[[$0]] unknown metrowerks compiler minor version]))
428  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
429    (__MWERKS__/0x1000)%0x10,,
430    AC_MSG_FAILURE([[[$0]] unknown metrowerks compiler major version]))
431  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
432  ])
433
434# for watcom
435AC_DEFUN([_AX_COMPILER_VERSION_WATCOM],[dnl
436  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
437    __WATCOMC__%100,,
438    AC_MSG_FAILURE([[[$0]] unknown watcom compiler minor version]))
439  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
440    (__WATCOMC__/100)%100,,
441    AC_MSG_FAILURE([[[$0]] unknown watcom compiler major version]))
442  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor"
443  ])
444
445# for PGI
446AC_DEFUN([_AX_COMPILER_VERSION_PORTLAND],[
447  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
448    __PGIC__,,
449    AC_MSG_FAILURE([[[$0]] unknown pgi major]))
450  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
451    __PGIC_MINOR__,,
452    AC_MSG_FAILURE([[[$0]] unknown pgi minor]))
453  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
454    [__PGIC_PATCHLEVEL__],,
455    AC_MSG_FAILURE([[[$0]] unknown pgi patch level]))
456  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
457  ])
458
459# tcc
460AC_DEFUN([_AX_COMPILER_VERSION_TCC],[
461  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version=[`tcc -v | $SED 's/^[ ]*tcc[ ]\+version[ ]\+\([0-9.]\+\).*/\1/g'`]
462  ])
463
464# for GNU
465AC_DEFUN([_AX_COMPILER_VERSION_SDCC],[
466  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_major,
467    /* avoid parse error with comments */
468    #if(defined(__SDCC_VERSION_MAJOR))
469	__SDCC_VERSION_MAJOR
470    #else
471	SDCC/100
472    #endif
473    ,,
474    AC_MSG_FAILURE([[[$0]] unknown sdcc major]))
475  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor,
476    /* avoid parse error with comments */
477    #if(defined(__SDCC_VERSION_MINOR))
478	__SDCC_VERSION_MINOR
479    #else
480	(SDCC%100)/10
481    #endif
482    ,,
483    AC_MSG_FAILURE([[[$0]] unknown sdcc minor]))
484  AC_COMPUTE_INT(_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch,
485    [
486    /* avoid parse error with comments */
487    #if(defined(__SDCC_VERSION_PATCH))
488	__SDCC_VERSION_PATCH
489    #elsif(defined(_SDCC_VERSION_PATCHLEVEL))
490	__SDCC_VERSION_PATCHLEVEL
491    #else
492	SDCC%10
493    #endif
494    ],,
495    AC_MSG_FAILURE([[[$0]] unknown sdcc patch level]))
496  ax_cv_[]_AC_LANG_ABBREV[]_compiler_version="$_ax_[]_AC_LANG_ABBREV[]_compiler_version_major.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_minor.$_ax_[]_AC_LANG_ABBREV[]_compiler_version_patch"
497  ])
498
499# main entry point
500AC_DEFUN([AX_COMPILER_VERSION],[dnl
501  AC_REQUIRE([AX_COMPILER_VENDOR])
502  AC_REQUIRE([AC_PROG_SED])
503  AC_CACHE_CHECK([for _AC_LANG compiler version],
504    ax_cv_[]_AC_LANG_ABBREV[]_compiler_version,
505    [ dnl
506      AS_CASE([$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor],
507        [intel],[_AX_COMPILER_VERSION_INTEL],
508	[ibm],[_AX_COMPILER_VERSION_IBM],
509	[pathscale],[_AX_COMPILER_VERSION_PATHSCALE],
510	[clang],[_AX_COMPILER_VERSION_CLANG],
511	[cray],[_AX_COMPILER_VERSION_CRAY],
512	[fujitsu],[_AX_COMPILER_VERSION_FUJITSU],
513        [gnu],[_AX_COMPILER_VERSION_GNU],
514	[sun],[_AX_COMPILER_VERSION_SUN],
515	[hp],[_AX_COMPILER_VERSION_HP],
516	[dec],[_AX_COMPILER_VERSION_DEC],
517	[borland],[_AX_COMPILER_VERSION_BORLAND],
518	[comeau],[_AX_COMPILER_VERSION_COMEAU],
519	[kai],[_AX_COMPILER_VERSION_KAI],
520	[sgi],[_AX_COMPILER_VERSION_SGI],
521	[microsoft],[_AX_COMPILER_VERSION_MICROSOFT],
522	[metrowerks],[_AX_COMPILER_VERSION_METROWERKS],
523	[watcom],[_AX_COMPILER_VERSION_WATCOM],
524	[portland],[_AX_COMPILER_VERSION_PORTLAND],
525	[tcc],[_AX_COMPILER_VERSION_TCC],
526	[sdcc],[_AX_COMPILER_VERSION_SDCC],
527  	[ax_cv_[]_AC_LANG_ABBREV[]_compiler_version=""])
528    ])
529])
530