]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.compiler.mk
Merge bmake 20151020
[FreeBSD/FreeBSD.git] / share / mk / bsd.compiler.mk
1 # $FreeBSD$
2
3 # Setup variables for the compiler
4 #
5 # COMPILER_TYPE is the major type of compiler. Currently gcc and clang support
6 # automatic detection. Other compiler types can be shoe-horned in, but require
7 # explicit setting of the compiler type. The compiler type can also be set
8 # explicitly if, say, you install gcc as clang...
9 #
10 # COMPILER_VERSION is a numeric constant equal to:
11 #     major * 10000 + minor * 100 + tiny
12 # It too can be overriden on the command line. When testing it, be sure to
13 # make sure that you are limiting the test to a specific compiler. Testing
14 # against 30300 for gcc likely isn't  what you wanted (since versions of gcc
15 # prior to 4.2 likely have no prayer of working).
16 #
17 # COMPILER_FEATURES will contain one or more of the following, based on
18 # compiler support for that feature:
19 #
20 # - c++11 : supports full (or nearly full) C++11 programming environment.
21 #
22 # This file may be included multiple times, but only has effect the first time.
23 #
24
25 .if !target(__<bsd.compiler.mk>__)
26 __<bsd.compiler.mk>__:
27
28 # Try to import COMPILER_TYPE and COMPILER_VERSION from parent make.
29 # The value is only used/exported for the same environment that impacts
30 # CC and COMPILER_* settings here.
31 _exported_vars= COMPILER_TYPE COMPILER_VERSION
32 _cc_hash=       ${CC}${MACHINE}${PATH}
33 _cc_hash:=      ${_cc_hash:hash}
34 # Only import if none of the vars are set somehow else.
35 _can_export=    yes
36 .for var in ${_exported_vars}
37 .if defined(${var})
38 _can_export=    no
39 .endif
40 .endfor
41 .if ${_can_export} == yes
42 .for var in ${_exported_vars}
43 .if defined(${var}.${_cc_hash})
44 ${var}= ${${var}.${_cc_hash}}
45 .endif
46 .endfor
47 .endif
48
49 .if ${MACHINE} == "common"
50 # common is a pseudo machine for architecture independent
51 # generated files - thus there is no compiler.
52 COMPILER_TYPE= none
53 COMPILER_VERSION= 0
54 .elif !defined(COMPILER_TYPE) || !defined(COMPILER_VERSION)
55 _v!=    ${CC} --version 2>/dev/null || echo 0.0.0
56
57 .if !defined(COMPILER_TYPE)
58 . if ${CC:T:M*gcc*}
59 COMPILER_TYPE:= gcc  
60 . elif ${CC:T:M*clang*}
61 COMPILER_TYPE:= clang
62 . elif ${_v:Mgcc}
63 COMPILER_TYPE:= gcc
64 . elif ${_v:M\(GCC\)}
65 COMPILER_TYPE:= gcc
66 . elif ${_v:Mclang}
67 COMPILER_TYPE:= clang
68 . else
69 .error Unable to determine compiler type for ${CC}.  Consider setting COMPILER_TYPE.
70 . endif
71 .endif
72 .if !defined(COMPILER_VERSION)
73 COMPILER_VERSION!=echo ${_v:M[1-9].[0-9]*} | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
74 .endif
75 .undef _v
76 .endif
77
78 # Export the values so sub-makes don't have to look them up again, using the
79 # hash key computed above.
80 .for var in ${_exported_vars}
81 ${var}.${_cc_hash}:=    ${${var}}
82 .export-env ${var}.${_cc_hash}
83 .undef ${var}.${_cc_hash}
84 .endfor
85
86 .if ${COMPILER_TYPE} == "clang" || \
87         (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40800)
88 COMPILER_FEATURES=      c++11
89 .else
90 COMPILER_FEATURES=
91 .endif
92
93 .endif  # !target(__<bsd.compiler.mk>__)