]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.compiler.mk
Fix some makeman issues.
[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 .include <bsd.opts.mk>
29
30 # Handle ccache after CC is determined, but not if CC/CXX are already
31 # overridden with a manual setup.
32 .if ${MK_CCACHE_BUILD:Uno} == "yes" && \
33     !make(showconfig) && \
34     (${CC:M*ccache/world/*} == "" || ${CXX:M*ccache/world/*} == "")
35 # CC is always prepended with the ccache wrapper rather than modifying
36 # PATH since it is more clear that ccache is used and avoids wasting time
37 # for mkdep/linking/asm builds.
38 LOCALBASE?=             /usr/local
39 CCACHE_WRAPPER_PATH?=   ${LOCALBASE}/libexec/ccache
40 CCACHE_BIN?=            ${LOCALBASE}/bin/ccache
41 .if exists(${CCACHE_BIN})
42 # Export to ensure sub-makes can filter it out for mkdep/linking and
43 # to chain down into kernel build which won't include this file.
44 .export CCACHE_BIN
45 # Expand and export some variables so they may be based on make vars.
46 # This allows doing something like the following in the environment:
47 # CCACHE_BASEDIR='${SRCTOP:H}' MAKEOBJDIRPREFIX='${SRCTOP:H}/obj'
48 .for var in CCACHE_LOGFILE CCACHE_BASEDIR
49 .if defined(${var})
50 ${var}:=        ${${var}}
51 .export         ${var}
52 .endif
53 .endfor
54 # Handle bootstrapped compiler changes properly by hashing their content
55 # rather than checking mtime.  For external compilers it should be safe
56 # to use the more optimal mtime check.
57 # XXX: CCACHE_COMPILERCHECK= string:<compiler_version, compiler_build_rev, compiler_patch_rev, compiler_default_target, compiler_default_sysroot>
58 .if ${CC:N${CCACHE_BIN}:[1]:M/*} == ""
59 CCACHE_COMPILERCHECK?=  content
60 .else
61 CCACHE_COMPILERCHECK?=  mtime
62 .endif
63 .export CCACHE_COMPILERCHECK
64 # Remove ccache from the PATH to prevent double calls and wasted CPP/LD time.
65 PATH:=  ${PATH:C,:?${CCACHE_WRAPPER_PATH}(/world)?(:$)?,,g}
66 # Ensure no bogus CCACHE_PATH leaks in which might avoid the in-tree compiler.
67 CCACHE_PATH=
68 .export CCACHE_PATH
69 # Override various toolchain vars.
70 .for var in CC CXX HOST_CC HOST_CXX
71 .if defined(${var}) && ${${var}:M${CCACHE_BIN}} == ""
72 ${var}:=        ${CCACHE_BIN} ${${var}}
73 .endif
74 .endfor
75 # GCC does not need the CCACHE_CPP2 hack enabled by default in devel/ccache.
76 # The port enables it due to ccache passing preprocessed C to clang
77 # which fails with -Wparentheses-equality, -Wtautological-compare, and
78 # -Wself-assign on macro-expanded lines.
79 .if defined(COMPILER_TYPE) && ${COMPILER_TYPE} == "gcc"
80 CCACHE_NOCPP2=  1
81 .export CCACHE_NOCPP2
82 .endif
83 # Canonicalize CCACHE_DIR for meta mode usage.
84 .if defined(CCACHE_DIR) && empty(.MAKE.META.IGNORE_PATHS:M${CCACHE_DIR})
85 CCACHE_DIR:=    ${CCACHE_DIR:tA}
86 .MAKE.META.IGNORE_PATHS+= ${CCACHE_DIR}
87 .export CCACHE_DIR
88 .endif
89 ccache-print-options: .PHONY
90         @${CCACHE_BIN} -p
91 .endif  # exists(${CCACHE_BIN})
92 .endif  # ${MK_CCACHE_BUILD} == "yes"
93
94 # Try to import COMPILER_TYPE and COMPILER_VERSION from parent make.
95 # The value is only used/exported for the same environment that impacts
96 # CC and COMPILER_* settings here.
97 _exported_vars= COMPILER_TYPE COMPILER_VERSION
98 _cc_hash=       ${CC}${MACHINE}${PATH}
99 _cc_hash:=      ${_cc_hash:hash}
100 # Only import if none of the vars are set somehow else.
101 _can_export=    yes
102 .for var in ${_exported_vars}
103 .if defined(${var})
104 _can_export=    no
105 .endif
106 .endfor
107 .if ${_can_export} == yes
108 .for var in ${_exported_vars}
109 .if defined(${var}.${_cc_hash})
110 ${var}= ${${var}.${_cc_hash}}
111 .endif
112 .endfor
113 .endif
114
115 .if ${MACHINE} == "common"
116 # common is a pseudo machine for architecture independent
117 # generated files - thus there is no compiler.
118 COMPILER_TYPE= none
119 COMPILER_VERSION= 0
120 .elif !defined(COMPILER_TYPE) || !defined(COMPILER_VERSION)
121 _v!=    ${CC} --version || echo 0.0.0
122
123 .if !defined(COMPILER_TYPE)
124 . if ${CC:T:M*gcc*}
125 COMPILER_TYPE:= gcc  
126 . elif ${CC:T:M*clang*}
127 COMPILER_TYPE:= clang
128 . elif ${_v:Mgcc}
129 COMPILER_TYPE:= gcc
130 . elif ${_v:M\(GCC\)}
131 COMPILER_TYPE:= gcc
132 . elif ${_v:Mclang}
133 COMPILER_TYPE:= clang
134 . else
135 .error Unable to determine compiler type for ${CC}.  Consider setting COMPILER_TYPE.
136 . endif
137 .endif
138 .if !defined(COMPILER_VERSION)
139 COMPILER_VERSION!=echo ${_v:M[1-9].[0-9]*} | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
140 .endif
141 .undef _v
142 .endif
143
144 # Export the values so sub-makes don't have to look them up again, using the
145 # hash key computed above.
146 .for var in ${_exported_vars}
147 ${var}.${_cc_hash}:=    ${${var}}
148 .export-env ${var}.${_cc_hash}
149 .undef ${var}.${_cc_hash}
150 .endfor
151
152 .if ${COMPILER_TYPE} == "clang" || \
153         (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40800)
154 COMPILER_FEATURES=      c++11
155 .else
156 COMPILER_FEATURES=
157 .endif
158
159 .endif  # !target(__<bsd.compiler.mk>__)