3 # Allows to determine the compiler being used
6 # Usage: USES=compiler or USES=compiler:ARGS
7 # Valid ARGS: env (default, implicit) c++0x c++11-lib c++11-lang c11 openmp nestedfct features
9 # c++0x: The port needs a compiler understanding C++0X
10 # c++11-lang: The port needs a compiler understanding C++11
11 # c++14-lang: The port needs a compiler understanding C++14
12 # gcc-c++11-lib:The port needs g++ compiler with a C++11 library
13 # c++11-lib: The port needs a compiler understanding C++11 and with a C++11 ready standard library
14 # c11: The port needs a compiler understanding C11
15 # openmp: The port needs a compiler understanding openmp
16 # nestedfct: The port needs a compiler understanding nested functions
17 # features: The port will determine the features supported by the default compiler
19 # Variable to test after <bsd.port.pre.mk>
21 # COMPILER_TYPE: can be gcc or clang
22 # ALT_COMPILER_TYPE: can be gcc or clang depending on COMPILER_TYPE, only set if the base system has 2 compilers
23 # COMPILER_VERSION: first 2 digits of the version: 33 for clang 3.3.*, 47 for gcc 4.7.*
24 # ALT_COMPILER_VERSION: first 2 digits of the version: 33 for clang 3.3.*, 47 for gcc 4.7.* of the ALT_COMPILER_TYPE
26 # COMPILER_FEATURES: the list of features supported by the compiler includes the standard C++ library.
27 # CHOSEN_COMPILER_TYPE: can be gcc or clang (type of compiler chosen by the framework)
29 # MAINTAINER: portmgr@FreeBSD.org
31 .if !defined(_INCLUDE_USES_COMPILER_MK)
32 _INCLUDE_USES_COMPILER_MK= yes
34 .if empty(compiler_ARGS)
38 VALID_ARGS= c++11-lib c++11-lang c++14-lang c11 features openmp env nestedfct c++0x gcc-c++11-lib
40 .if ${compiler_ARGS} == gcc-c++11-lib
41 _COMPILER_ARGS+= features gcc-c++11-lib
42 .elif ${compiler_ARGS} == c++11-lib
43 _COMPILER_ARGS+= features c++11-lib
44 .elif ${compiler_ARGS} == c++0x
45 _COMPILER_ARGS+= features c++0x
46 .elif ${compiler_ARGS} == c++11-lang
47 _COMPILER_ARGS+= features c++11-lang
48 .elif ${compiler_ARGS} == c++14-lang
49 _COMPILER_ARGS+= features c++14-lang
50 .elif ${compiler_ARGS} == c11
51 _COMPILER_ARGS+= features c11
52 .elif ${compiler_ARGS} == features
53 _COMPILER_ARGS+= features
54 .elif ${compiler_ARGS} == env
56 .elif ${compiler_ARGS} == openmp
57 _COMPILER_ARGS+= env openmp
58 .elif ${compiler_ARGS} == nestedfct
59 _COMPILER_ARGS+= env nestedfct
61 IGNORE= Invalid argument "${compiler_ARGS}", valid arguments are: ${VALID_ARGS}
65 .if ${_COMPILER_ARGS:Mc++*} || ${_COMPILER_ARGS:Mc11}
66 _COMPILER_ARGS+= features
70 # This is the DragonFly base compiler, we know it's gcc (for now)
74 _CCVERSION!= ${CC} --version
75 .if defined(.PARSEDIR)
76 COMPILER_VERSION= ${_CCVERSION:M[0-9].[0-9]*:tW:C/([0-9]).([0-9]).*/\1\2/g}
78 COMPILER_VERSION= ${_CCVERSION:M[0-9].[0-9]*:C/([0-9]).([0-9]).*/\1\2/g:u}
80 .if ${_CCVERSION:Mclang}
87 ALT_COMPILER_VERSION= 0
88 ALT_COMPILER_TYPE= none
90 .if ${COMPILER_TYPE} == gcc && exists(/usr/bin/clang)
91 .if ${ARCH} == amd64 || ${ARCH} == i386 # clang often non-default for a reason
92 _ALTCCVERSION!= /usr/bin/clang --version
94 .elif ${COMPILER_TYPE} == clang && exists(/usr/bin/gcc)
95 _ALTCCVERSION!= /usr/bin/gcc --version
98 .if defined(.PARSEDIR)
99 ALT_COMPILER_VERSION= ${_ALTCCVERSION:M[0-9].[0-9]*:tW:C/([0-9]).([0-9]).*/\1\2/g}
101 ALT_COMPILER_VERSION= ${_ALTCCVERSION:M[0-9].[0-9]*:C/([0-9]).([0-9]).*/\1\2/g:u}
103 .if ${_ALTCCVERSION:Mclang}
104 ALT_COMPILER_TYPE= clang
105 .elif !empty(_ALTCCVERSION)
106 ALT_COMPILER_TYPE= gcc
109 CHOSEN_COMPILER_TYPE= ${COMPILER_TYPE}
111 .if ${_COMPILER_ARGS:Mopenmp}
112 .if ${COMPILER_TYPE} == clang
114 CHOSEN_COMPILER_TYPE= gcc
118 .if ${_COMPILER_ARGS:Mnestedfct}
119 .if ${COMPILER_TYPE} == clang
121 CHOSEN_COMPILER_TYPE= gcc
125 .if ${_COMPILER_ARGS:Mfeatures}
126 . if ${CC} == cc && ${CXX} == c++
127 # This is DragonFly's base gcc50 compiler
128 # Use a cache for DF rather than testing each feature.
129 COMPILER_FEATURES= libstdc++ c89 c99 c11 gnu89 gnu99 gnu11 c++98 \
130 c++0x c++11 c++14 gnu++98 gnu++11 dragonfly
132 _CXXINTERNAL!= ${CXX} -\#\#\# /dev/null 2>&1
133 .if ${_CXXINTERNAL:M\"-lc++\"}
134 COMPILER_FEATURES= libc++
136 COMPILER_FEATURES= libstdc++
139 CSTD= c89 c99 c11 gnu89 gnu99 gnu11
140 CXXSTD= c++98 c++0x c++11 c++14 gnu++98 gnu++11
142 .for std in ${CSTD} ${CXXSTD}
144 .if ${CXXSTD:M${std}}
147 OUTPUT_${std}!= echo | ${CC} -std=${std} -c -x ${_LANG} /dev/null -o /dev/null 2>&1; echo
148 .if !${OUTPUT_${std}:M*error*}
149 COMPILER_FEATURES+= ${std}
152 . endif # DragonFly base compiler
155 .if ${_COMPILER_ARGS:Mc++11-lib}
156 .if !${COMPILER_FEATURES:Mc++11}
158 CHOSEN_COMPILER_TYPE= gcc
159 .elif ${COMPILER_TYPE} == clang && ${COMPILER_FEATURES:Mlibstdc++}
161 CHOSEN_COMPILER_TYPE= gcc
165 .if ${_COMPILER_ARGS:Mc++14-lang}
166 .if !${COMPILER_FEATURES:Mc++14}
167 .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2
169 CHOSEN_COMPILER_TYPE= gcc
170 .elif (${COMPILER_TYPE} == clang && ${COMPILER_VERSION} < 35) || ${COMPILER_TYPE} == gcc
171 .if ${ALT_COMPILER_TYPE} == clang && ${ALT_COMPILER_VERSION} >= 35
175 CHOSEN_COMPILER_TYPE= clang
177 BUILD_DEPENDS+= ${LOCALBASE}/bin/clang36:lang/clang36
178 CPP= ${LOCALBASE}/bin/clang-cpp36
179 CC= ${LOCALBASE}/bin/clang36
180 CXX= ${LOCALBASE}/bin/clang++36
181 CHOSEN_COMPILER_TYPE= clang
187 .if ${_COMPILER_ARGS:Mc++11-lang}
188 .if !${COMPILER_FEATURES:Mc++11}
189 .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2
191 CHOSEN_COMPILER_TYPE= gcc
192 .elif (${COMPILER_TYPE} == clang && ${COMPILER_VERSION} < 34) || ${COMPILER_TYPE} == gcc
193 .if ${ALT_COMPILER_TYPE} == clang && ${ALT_COMPILER_VERSION} >= 34
197 CHOSEN_COMPILER_TYPE= clang
199 BUILD_DEPENDS+= ${LOCALBASE}/bin/clang38:lang/clang38
200 CPP= ${LOCALBASE}/bin/clang-cpp38
201 CC= ${LOCALBASE}/bin/clang38
202 CXX= ${LOCALBASE}/bin/clang++38
203 CHOSEN_COMPILER_TYPE= clang
209 .if ${_COMPILER_ARGS:Mc++0x}
210 .if !${COMPILER_FEATURES:Mc++0x}
211 .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2
213 CHOSEN_COMPILER_TYPE= gcc
214 .elif (${COMPILER_TYPE} == clang && ${COMPILER_VERSION} < 34) || ${COMPILER_TYPE} == gcc
215 .if ${ALT_COMPILER_TYPE} == clang && ${ALT_COMPILER_VERSION} >= 34
219 CHOSEN_COMPILER_TYPE= clang
221 BUILD_DEPENDS+= ${LOCALBASE}/bin/clang38:lang/clang38
222 CHOSEN_COMPILER_TYPE= clang
223 CPP= ${LOCALBASE}/bin/clang-cpp38
224 CC= ${LOCALBASE}/bin/clang38
225 CXX= ${LOCALBASE}/bin/clang++38
231 .if ${_COMPILER_ARGS:Mc11}
232 .if !${COMPILER_FEATURES:Mc11}
233 .if (defined(FAVORITE_COMPILER) && ${FAVORITE_COMPILER} == gcc) || (${ARCH} != amd64 && ${ARCH} != i386) # clang not always supported on Tier-2
235 CHOSEN_COMPILER_TYPE= gcc
236 .elif (${COMPILER_TYPE} == clang && ${COMPILER_VERSION} < 34) || ${COMPILER_TYPE} == gcc
237 .if ${ALT_COMPILER_TYPE} == clang && ${ALT_COMPILER_VERSION} >= 34
241 CHOSEN_COMPILER_TYPE= clang
243 BUILD_DEPENDS+= ${LOCALBASE}/bin/clang38:lang/clang38
244 CHOSEN_COMPILER_TYPE= clang
245 CPP= ${LOCALBASE}/bin/clang-cpp38
246 CC= ${LOCALBASE}/bin/clang38
247 CXX= ${LOCALBASE}/bin/clang++38
253 .if ${_COMPILER_ARGS:Mgcc-c++11-lib}
255 CHOSEN_COMPILER_TYPE= gcc
256 .if ${COMPILER_FEATURES:Mlibc++}
257 LDFLAGS+= -L${LOCALBASE}/lib/c++
258 CXXFLAGS+= -nostdinc++ -isystem ${LOCALBASE}/include/c++/v1
259 BUILD_DEPENDS+= ${LOCALBASE}/lib/c++/libstdc++.so:devel/libc++