Sync with 5.4.2
[deliverable/titan.core.git] / core / gccversion.c
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 /* Write a header that checks the expected version of the compiler.
9 * gccversion.c is a bit of a misnomer (also handles the Sun compiler),
10 * but it's shorter than compiler_version.c */
11
12 #include <stdio.h>
13
14
15 #if defined(__GNUC__)
16
17 /* clang defines __GNUC__ but also has its own version numbers */
18 #ifdef __clang__
19
20 unsigned int
21 compiler_major = __clang_major__,
22 compiler_minor = __clang_minor__,
23 compiler_patchlevel = __clang_patchlevel__;
24 #define COMPILER_NAME_STRING "clang"
25
26 #else
27
28 #define COMPILER_NAME_STRING "GCC"
29 unsigned int compiler_major = __GNUC__, compiler_minor = __GNUC_MINOR__;
30 # ifdef __GNUC_PATCHLEVEL__
31 unsigned int compiler_patchlevel = __GNUC_PATCHLEVEL__;
32 # else
33 unsigned int compiler_patchlevel = 0; /* GCC below 3.0 */
34 # endif
35
36 #endif /* __clang__ */
37
38 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
39 /* Just in case it's compiled with the C++ compiler */
40 # if !defined(__SUNPRO_C)
41 # define __SUNPRO_C __SUNPRO_CC
42 # endif
43 unsigned int compiler_major = (__SUNPRO_C & 0xF00) >> 8;
44 unsigned int compiler_minor = (__SUNPRO_C & 0x0F0) >> 4;
45 unsigned int compiler_patchlevel = (__SUNPRO_C & 0x00F);
46
47 #else
48 /* unknown compiler */
49 unsigned int compiler_major = 0, compiler_minor = 0, compiler_patchlevel = 0;
50 #endif
51
52 int main(void)
53 {
54 puts(
55 "/* Check if the compiler matches the one used to build the runtime */\n"
56 "#ifndef MAKEDEPEND_RUN\n\n");
57 /* Do not check compiler version when makedepend is being run.
58 * Old Solaris makedepend cannot compute GCC_VERSION. */
59 #if defined(__GNUC__)
60 printf("\n"
61 #ifdef __clang__
62 "#if CLANG_VERSION != %d\n"
63 #else
64 "#if GCC_VERSION != %d\n"
65 #endif
66 "#error The version of " COMPILER_NAME_STRING " does not match the expected version (" COMPILER_NAME_STRING " %d.%d.%d)\n"
67 "#endif\n", compiler_major * 10000 + compiler_minor * 100,
68 /* Note that we don't use compiler_patchlevel when checking.
69 * This assumes that code is portable between GCC a.b.x and a.b.y */
70 compiler_major, compiler_minor, compiler_patchlevel);
71 #elif defined(__SUNPRO_C)
72 printf("\n"
73 "#if __SUNPRO_CC != 0x%X\n"
74 "#error The version of the Sun compiler does not match the expected version.\n"
75 "#endif\n",
76 compiler_major * 0x100 + compiler_minor * 0x10 + compiler_patchlevel);
77 #endif
78
79 puts("\n#endif\n");
80
81 return 0;
82 }
This page took 0.032361 seconds and 5 git commands to generate.