freebsd-dev/share/mk/bsd.compiler.mk
Warner Losh 79f387daa8 Allow CC to not actually exist. During the ports INDEX run, all the
Makefiles are evaluated without building things. In a normal build,
the prerequisites would be built, and CC would be an actual thing. In
an INDEX build, though, they don't exists. Redirect stderr to get rid
of annoying messages, and assume that the compiler version is 0 if the
actual compiler can't tell us. Do this in preference to guessing based
on numbers because gcc410 might be 4.10, or 4.1.0 and without
carefully crafted special knowledge we differentiate between them
easily (also ming-gcc has no clues at all). Elsewhere, don't trust
the compiler version if it is 0.
2014-05-23 14:34:22 +00:00

52 lines
1.6 KiB
Makefile

# $FreeBSD$
# Setup variables for the compiler
#
# COMPILTER_TYPE is the major type of compiler. Currently gcc and clang support
# automatic detetion. Other compiler types can be shoe-horned in, but require explicit
# setting of the compiler type. The compiler type can also be set explicitly if, say,
# you install gcc as clang...
#
# COMPILER_VERSION is a numeric constant equal to major * 10000 + minor * 100 + tiny. It
# too can be overriden on the command line. When testing it, be sure to make sure that you
# are limiting the test to a specific compiler. Testing against 30300 for gcc likely isn't
# what you wanted (since versions of gcc prior to 4.2 likely have no prayer of working).
#
# COMPILER_FEATURES will contain one or more of the following, based on compiler support
# for that feature: c++11 (supports full (or nearly full) C++11 programming environment).
#
# This file may be included multiple times, but only has effect the first time.
#
.if !target(__<bsd.compiler.mk>__)
__<bsd.compiler.mk>__:
_v!= ${CC} --version 2>/dev/null || echo 0.0.0
.if !defined(COMPILER_TYPE)
. if ${CC:T:M*gcc*}
COMPILER_TYPE:= gcc
. elif ${CC:T:M*clang*}
COMPILER_TYPE:= clang
. elif ${_v:Mgcc}
COMPILER_TYPE:= gcc
. elif ${_v:M\(GCC\)}
COMPILER_TYPE:= gcc
. elif ${_v:Mclang}
COMPILER_TYPE:= clang
. else
.error Unable to determine compiler type for ${CC}. Consider setting COMPILER_TYPE.
. endif
.endif
.if !defined(COMPILER_VERSION)
COMPILER_VERSION!=echo ${_v:M[1-9].[0-9]*} | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
.endif
.undef _v
.if ${COMPILER_TYPE} == "clang"
COMPILER_FEATURES= c++11
.else
COMPILER_FEATURES=
.endif
.endif # !target(__<bsd.compiler.mk>__)