xref: /freebsd/share/mk/bsd.compiler.mk (revision 98e0ffaefb0f241cda3a72395d3be04192ae0d47)
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.if ${MACHINE} == "common"
29COMPILER_TYPE= none
30COMPILER_VERSION= 0
31.elif !defined(COMPILER_TYPE) || !defined(COMPILER_VERSION)
32_v!=	${CC} --version 2>/dev/null || echo 0.0.0
33
34.if !defined(COMPILER_TYPE)
35. if ${CC:T:M*gcc*}
36COMPILER_TYPE:=	gcc
37. elif ${CC:T:M*clang*}
38COMPILER_TYPE:=	clang
39. elif ${_v:Mgcc}
40COMPILER_TYPE:=	gcc
41. elif ${_v:M\(GCC\)}
42COMPILER_TYPE:=	gcc
43. elif ${_v:Mclang}
44COMPILER_TYPE:=	clang
45. else
46.error Unable to determine compiler type for ${CC}.  Consider setting COMPILER_TYPE.
47. endif
48.endif
49.if !defined(COMPILER_VERSION)
50COMPILER_VERSION!=echo ${_v:M[1-9].[0-9]*} | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
51.endif
52.undef _v
53.endif
54
55.if ${COMPILER_TYPE} == "clang" || \
56	(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40800)
57COMPILER_FEATURES=	c++11
58.else
59COMPILER_FEATURES=
60.endif
61
62.endif	# !target(__<bsd.compiler.mk>__)
63