diff --git a/Makefile.inc1 b/Makefile.inc1 index e20a9b343c61..95e660bee562 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -130,6 +130,15 @@ MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/}-${MACH TARGET_ABI?= unknown TARGET_TRIPLE?= ${TARGET_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/}-${TARGET_ABI}-freebsd12.0 +# If all targets are disabled for system llvm then don't expect it to work +# for cross-builds. +.if ${MK_LLVM_TARGET_ALL} == "no" && \ + ${MACHINE} != ${TARGET} && ${MACHINE_ARCH} != ${TARGET_ARCH} && \ + !make(showconfig) +MK_SYSTEM_COMPILER= no +MK_SYSTEM_LINKER= no +.endif + # Handle external binutils. .if defined(CROSS_TOOLCHAIN_PREFIX) CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX} diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk index 503f668f241c..ba68ec5d5e0a 100644 --- a/share/mk/src.opts.mk +++ b/share/mk/src.opts.mk @@ -211,6 +211,7 @@ __DEFAULT_NO_OPTIONS = \ # RIGHT option is disabled. __DEFAULT_DEPENDENT_OPTIONS= \ CLANG_FULL/CLANG \ + LLVM_TARGET_ALL/CLANG \ # MK_*_SUPPORT options which default to "yes" unless their corresponding # MK_* variable is set to "no". @@ -249,6 +250,27 @@ __TT=${TARGET} __TT=${MACHINE} .endif +# All supported backends for LLVM_TARGET_XXX +__LLVM_TARGETS= \ + aarch64 \ + arm \ + mips \ + powerpc \ + sparc \ + x86 +__LLVM_TARGET_FILT= C/(amd64|i386)/x86/:S/sparc64/sparc/:S/arm64/aarch64/ +# Default the given TARGET_ARCH's LLVM_TARGET support to the value of +# MK_CLANG. +# Default the rest of the LLVM_TARGETs to the value of MK_LLVM_TARGET_ALL +# which is based on MK_CLANG. +.for __llt in ${__LLVM_TARGETS} +.if ${__llt} != ${__T:${__LLVM_TARGET_FILT}} +__DEFAULT_DEPENDENT_OPTIONS+= LLVM_TARGET_${__llt:${__LLVM_TARGET_FILT}:tu}/LLVM_TARGET_ALL +.else +__DEFAULT_DEPENDENT_OPTIONS+= LLVM_TARGET_${__llt:${__LLVM_TARGET_FILT}:tu}/CLANG +.endif +.endfor + .include # If the compiler is not C++11 capable, disable Clang and use GCC instead. # This means that architectures that have GCC 4.2 as default can not @@ -258,23 +280,17 @@ __TT=${MACHINE} ${__T} == "amd64" || ${__TT} == "arm" || ${__T} == "i386") # Clang is enabled, and will be installed as the default /usr/bin/cc. __DEFAULT_YES_OPTIONS+=CLANG CLANG_BOOTSTRAP CLANG_IS_CC LLD -__DEFAULT_YES_OPTIONS+=LLVM_TARGET_AARCH64 LLVM_TARGET_ARM LLVM_TARGET_MIPS -__DEFAULT_YES_OPTIONS+=LLVM_TARGET_POWERPC LLVM_TARGET_SPARC LLVM_TARGET_X86 __DEFAULT_NO_OPTIONS+=GCC GCC_BOOTSTRAP GNUCXX GPL_DTC .elif ${COMPILER_FEATURES:Mc++11} && ${__T:Mriscv*} == "" && ${__T} != "sparc64" # If an external compiler that supports C++11 is used as ${CC} and Clang # supports the target, then Clang is enabled but GCC is installed as the # default /usr/bin/cc. __DEFAULT_YES_OPTIONS+=CLANG GCC GCC_BOOTSTRAP GNUCXX GPL_DTC LLD -__DEFAULT_YES_OPTIONS+=LLVM_TARGET_AARCH64 LLVM_TARGET_ARM LLVM_TARGET_MIPS -__DEFAULT_YES_OPTIONS+=LLVM_TARGET_POWERPC LLVM_TARGET_SPARC LLVM_TARGET_X86 __DEFAULT_NO_OPTIONS+=CLANG_BOOTSTRAP CLANG_IS_CC .else # Everything else disables Clang, and uses GCC instead. __DEFAULT_YES_OPTIONS+=GCC GCC_BOOTSTRAP GNUCXX GPL_DTC __DEFAULT_NO_OPTIONS+=CLANG CLANG_BOOTSTRAP CLANG_IS_CC LLD -__DEFAULT_NO_OPTIONS+=LLVM_TARGET_AARCH64 LLVM_TARGET_ARM LLVM_TARGET_MIPS -__DEFAULT_NO_OPTIONS+=LLVM_TARGET_POWERPC LLVM_TARGET_SPARC LLVM_TARGET_X86 .endif # In-tree binutils/gcc are older versions without modern architecture support. .if ${__T} == "aarch64" || ${__T:Mriscv*} != "" diff --git a/tools/build/options/WITHOUT_LLVM_TARGET_ALL b/tools/build/options/WITHOUT_LLVM_TARGET_ALL new file mode 100644 index 000000000000..357d998039dc --- /dev/null +++ b/tools/build/options/WITHOUT_LLVM_TARGET_ALL @@ -0,0 +1,3 @@ +.\" $FreeBSD$ +Set to only build the required LLVM target support. +This option is preferred to specific target support options. diff --git a/tools/build/options/WITH_LLVM_TARGET_ALL b/tools/build/options/WITH_LLVM_TARGET_ALL new file mode 100644 index 000000000000..0270c03bc58e --- /dev/null +++ b/tools/build/options/WITH_LLVM_TARGET_ALL @@ -0,0 +1,2 @@ +.\" $FreeBSD$ +Set to build support for all LLVM targets.