summaryrefslogtreecommitdiffstats
path: root/share/mk/bsd.compiler.mk
diff options
context:
space:
mode:
Diffstat (limited to 'share/mk/bsd.compiler.mk')
-rw-r--r--share/mk/bsd.compiler.mk31
1 files changed, 30 insertions, 1 deletions
diff --git a/share/mk/bsd.compiler.mk b/share/mk/bsd.compiler.mk
index dcdf598..9ad4bae 100644
--- a/share/mk/bsd.compiler.mk
+++ b/share/mk/bsd.compiler.mk
@@ -25,13 +25,34 @@
.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}
+# Only import if none of the vars are set somehow else.
+_can_export= yes
+.for var in ${_exported_vars}
+.if defined(${var})
+_can_export= no
+.endif
+.endfor
+.if ${_can_export} == yes
+.for var in ${_exported_vars}
+.if defined(${var}.${_cc_hash})
+${var}= ${${var}.${_cc_hash}}
+.endif
+.endfor
+.endif
+
.if ${MACHINE} == "common"
# common is a pseudo machine for architecture independent
# generated files - thus there is no compiler.
COMPILER_TYPE= none
COMPILER_VERSION= 0
.elif !defined(COMPILER_TYPE) || !defined(COMPILER_VERSION)
-_v!= ${CC} --version 2>/dev/null || echo 0.0.0
+_v!= ${CC} --version || echo 0.0.0
.if !defined(COMPILER_TYPE)
. if ${CC:T:M*gcc*}
@@ -54,6 +75,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
OpenPOWER on IntegriCloud