svn commit: r300354 - in head: . share/mk tools/build/options

Bryan Drewery bdrewery at FreeBSD.org
Sat May 21 01:32:26 UTC 2016


Author: bdrewery
Date: Sat May 21 01:32:23 2016
New Revision: 300354
URL: https://svnweb.freebsd.org/changeset/base/300354

Log:
  Opportunistically skip building a cross-compiler with SYSTEM_COMPILER set.
  
  This will still build the compiler for the target but will not build the
  bootstrap cross-compiler in the cross-tools phase.  Other toolchain
  bootstrapping, such as elftoolchan and binutils, currently still occurs.
  
  This will utilize the default CC (cc, /usr/bin/cc) as an external compiler.
  
  This is planned to be on-by-default eventually.
  
  This will utilize the __FreeBSD_cc_version compiler macro defined in the
  source tree and compare it to CC's version.  If they match then the
  cross-compiler is skipped.  If [X]CC is an external compiler (absolute
  path) or WITHOUT_CROSS_COMPILER is already set, then this logic is skipped.
  If the expected bootstrap compiler type no longer matches the found CC
  compiler type (clang vs gcc), then the logic is skipped.  As an extra
  safety check the version number is also compared from the compiler to
  the tree version.
  
  Clang:
    The macro FREEBSD_CC_VERSION is defined in:
      lib/clang/include/clang/Basic/Version.inc
    For clang -target will be used if TARGET_ARCH != MACHINE_ARCH.  This
    is from the current external toolchain logic.  There is currently an
    assumption that the host compiler can build the TARGET_ARCH.  This
    will usually be the case since we don't conditionalize target arch
    support in clang, but it will break when introducing new
    architectures.  This problem is mitigated by incrementing the version
    when adding new architectures.
  
  GCC:
    The macro FBSD_CC_VER is defined in:
      gnu/usr.bin/cc/cc_tools/freebsd-native.h
    For GCC there is no simple -target support when TARGET_ARCH !=
    MACHINE_ARCH.  In this case the opportunistic skip is not done.  If we
    add proper support for this case in external toolchain logic then it
    will be fine to enable.
  
  This relies on the macros being incremented whenever any change occurs
  to these compilers that warrant rebuilding files.  It also should never
  repeat earlier values.
  
  Reviewed by:	brooks, bapt, imp
  Sponsored by:	EMC / Isilon Storage Division
  Differential Revision:	https://reviews.freebsd.org/D6357

Added:
  head/tools/build/options/WITHOUT_SYSTEM_COMPILER   (contents, props changed)
  head/tools/build/options/WITH_SYSTEM_COMPILER   (contents, props changed)
Modified:
  head/Makefile.inc1
  head/share/mk/src.opts.mk

Modified: head/Makefile.inc1
==============================================================================
--- head/Makefile.inc1	Sat May 21 01:32:20 2016	(r300353)
+++ head/Makefile.inc1	Sat May 21 01:32:23 2016	(r300354)
@@ -48,6 +48,7 @@
 .error "Both TARGET and TARGET_ARCH must be defined."
 .endif
 
+SRCDIR?=	${.CURDIR}
 LOCALBASE?=	/usr/local
 
 # Cross toolchain changes must be in effect before bsd.compiler.mk
@@ -97,8 +98,59 @@ X${BINUTIL}?=	${${BINUTIL}}
 MK_CROSS_COMPILER=	no
 .endif
 
-.include <bsd.compiler.mk>		# don't depend on src.opts.mk doing it
-.include "share/mk/src.opts.mk"	
+# Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early.
+.include <bsd.compiler.mk>
+.include "share/mk/src.opts.mk"
+
+# Check if there is a local compiler that can satisfy as an external compiler.
+.if ${MK_SYSTEM_COMPILER} == "yes" && ${MK_CROSS_COMPILER} == "yes" && \
+    (${MK_CLANG_BOOTSTRAP} == "yes" || ${MK_GCC_BOOTSTRAP} == "yes") && \
+    !make(showconfig)
+# Which compiler is expected to be used?
+.if ${MK_CLANG_BOOTSTRAP} == "yes"
+_expected_compiler_type=	clang
+.elif ${MK_GCC_BOOTSTRAP} == "yes"
+_expected_compiler_type=	gcc
+.endif
+# If the expected vs CC is different then we can't skip.
+# GCC cannot be used for cross-arch yet.  For clang we pass -target later if
+# TARGET_ARCH!=MACHINE_ARCH.
+.if ${_expected_compiler_type} == ${COMPILER_TYPE} && \
+    (${COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH})
+# It needs to be the same revision as we would build for the bootstrap.
+.if !defined(CROSS_COMPILER_FREEBSD_VERSION)
+.if ${_expected_compiler_type} == "clang"
+CROSS_COMPILER_FREEBSD_VERSION!= \
+	awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \
+	${SRCDIR}/lib/clang/include/clang/Basic/Version.inc || echo unknown
+CROSS_COMPILER_VERSION!= \
+	awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \
+	${SRCDIR}/lib/clang/include/clang/Basic/Version.inc || echo unknown
+.elif ${_expected_compiler_type} == "gcc"
+CROSS_COMPILER_FREEBSD_VERSION!= \
+	awk '$$2 == "FBSD_CC_VER" {printf("%d\n", $$3)}' \
+	${SRCDIR}/gnu/usr.bin/cc/cc_tools/freebsd-native.h || echo unknown
+CROSS_COMPILER_VERSION!= \
+	awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3}' \
+	${SRCDIR}/contrib/gcc/BASE-VER || echo unknown
+.endif
+.export CROSS_COMPILER_FREEBSD_VERSION CROSS_COMPILER_VERSION
+.endif	# !defined(CROSS_COMPILER_FREEBSD_VERSION)
+.if ${COMPILER_VERSION} == ${CROSS_COMPILER_VERSION} && \
+    ${COMPILER_FREEBSD_VERSION} == ${CROSS_COMPILER_FREEBSD_VERSION}
+# Everything matches, disable the bootstrap compiler.
+MK_CLANG_BOOTSTRAP=	no
+MK_GCC_BOOTSTRAP=	no
+CROSSENV+=	COMPILER_VERSION=${COMPILER_VERSION} \
+		COMPILER_TYPE=${COMPILER_TYPE} \
+		COMPILER_FREEBSD_VERSION=${COMPILER_FREEBSD_VERSION}
+.if make(buildworld)
+.info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree.  Not bootstrapping a cross-compiler.
+.endif
+.endif	# ${COMPILER_VERSION} == ${CROSS_COMPILER_VERSION}
+.endif	# ${_expected_compiler_type} == ${COMPILER_TYPE}
+.endif	# ${XCC:N${CCACHE_BIN}:M/*}
+
 
 # We must do lib/ and libexec/ before bin/ in case of a mid-install error to
 # keep the users system reasonably usable.  For static->dynamic root upgrades,
@@ -108,7 +160,6 @@ MK_CROSS_COMPILER=	no
 # This ordering is not a guarantee though.  The only guarantee of a working
 # system here would require fine-grained ordering of all components based
 # on their dependencies.
-SRCDIR?=	${.CURDIR}
 .if !empty(SUBDIR_OVERRIDE)
 SUBDIR=	${SUBDIR_OVERRIDE}
 .else

Modified: head/share/mk/src.opts.mk
==============================================================================
--- head/share/mk/src.opts.mk	Sat May 21 01:32:20 2016	(r300353)
+++ head/share/mk/src.opts.mk	Sat May 21 01:32:23 2016	(r300354)
@@ -187,7 +187,9 @@ __DEFAULT_NO_OPTIONS = \
     OPENLDAP \
     SHARED_TOOLCHAIN \
     SORT_THREADS \
-    SVN
+    SVN \
+    SYSTEM_COMPILER \
+
 
 #
 # Default behaviour of some options depends on the architecture.  Unfortunately

Added: head/tools/build/options/WITHOUT_SYSTEM_COMPILER
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/options/WITHOUT_SYSTEM_COMPILER	Sat May 21 01:32:23 2016	(r300354)
@@ -0,0 +1,12 @@
+.\" $FreeBSD$
+Set to not opportunistically skip building a cross-compiler during the
+bootstrap phase of the build.
+Normally, if the currently installed compiler matches the planned bootstrap
+compiler type and revision, then it will not be built.
+This does not prevent a compiler from being built for installation though,
+only for building one for the build itself.
+The
+.Va WITHOUT_CLANG
+and
+.Va WITHOUT_GCC
+options control those.

Added: head/tools/build/options/WITH_SYSTEM_COMPILER
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/options/WITH_SYSTEM_COMPILER	Sat May 21 01:32:23 2016	(r300354)
@@ -0,0 +1,12 @@
+.\" $FreeBSD$
+Set to opportunistically skip building a cross-compiler during the
+bootstrap phase of the build.
+If the currently installed compiler matches the planned bootstrap compiler
+type and revision, then it will not be built.
+This does not prevent a compiler from being built for installation though,
+only for building one for the build itself.
+The
+.Va WITHOUT_CLANG
+and
+.Va WITHOUT_GCC
+options control those.


More information about the svn-src-all mailing list