Pass COMPILER_TYPE and COMPILER_VERSION to sub-makes to avoid redundant

lookups.

This uses a special variable name based on a hash of ${CC}, ${PATH}, and
${MACHINE} to ensure that a cached value is not used if any of these
values changes to use a new compiler.

Before this there were 34,620 fork/exec from bsd.compiler.mk during a buildworld.
After this there are 608.  More improvement is needed to cache a value from
the top-level before descending into subdirs in the various build phases.

Reviewed by:	brooks (earlier version)
MFC after:	3 weeks
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D3898
This commit is contained in:
Bryan Drewery 2015-10-20 20:15:25 +00:00
parent 1ed2e49b55
commit 16a5c008cc

View File

@ -25,6 +25,18 @@
.if !target(__<bsd.compiler.mk>__)
__<bsd.compiler.mk>__:
# Try to import COMPILER_TYPE and COMPILER_VERSION from parent make.
# The value is only used/exported for the same environment that impacts
# CC and COMPILER_* settings here.
_exported_vars= COMPILER_TYPE COMPILER_VERSION
_cc_hash= ${CC}${MACHINE}${PATH}
_cc_hash:= ${_cc_hash:hash}
.for var in ${_exported_vars}
.if defined(${var}.${_cc_hash})
${var}= ${${var}.${_cc_hash}}
.endif
.endfor
.if ${MACHINE} == "common"
# common is a pseudo machine for architecture independent
# generated files - thus there is no compiler.
@ -54,6 +66,14 @@ COMPILER_VERSION!=echo ${_v:M[1-9].[0-9]*} | awk -F. '{print $$1 * 10000 + $$2 *
.undef _v
.endif
# Export the values so sub-makes don't have to look them up again, using the
# hash key computed above.
.for var in ${_exported_vars}
${var}.${_cc_hash}:= ${${var}}
.export-env ${var}.${_cc_hash}
.undef ${var}.${_cc_hash}
.endfor
.if ${COMPILER_TYPE} == "clang" || \
(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40800)
COMPILER_FEATURES= c++11