External Toolchain Support

FreeBSD needs support for external toolchains to ease testing of new compiler versions, support compilers that don't make sense to integrate into the base, and speed builds (by avoiding building of bootstrap compilers). This page documents efforts towards this.

XCC

The XCC approach works with top level build targets (buildworld, buildkernel, etc) and overrides common make variables such as CC, CXX, and AS during the cross building portions of the build with values specified by the XCC, XCPP, XAS, etc variables. This method touches few files and is relatively easy to understand, but has drawbacks including the inability to build individual programs easily.

How to use

If is possible to replace both the compiler and binutils. It is possible to replace the compiler and use the built-in binutils. To replace binutils, you must also replace the compiler.

Both the compiler and binutils must be configured to support --sysroot to find headers and libraries.

Using an external compiler

To use an external compiler such as clang, set the variables XCC, XCXX, and XCPP when building and installing. You must generally set all three. For example:

$ make XCC=/usr/local/bin/clang XCXX=/usr/local/bin/clang++ XCPP=/usr/local/bin/clang-cpp buildworld
...

If your versions full paths end in cc, c++, and cpp, then you may use the CROSS_COMPILER_PREFIX variable to set all three (Note that this is a prefix, not a path):

$ ls /tmp/toolchain/
cross-c++       cross-cc        cross-cpp
$ make CROSS_COMPILER_PREFIX=/tmp/toolchain/cross- buildworld
...

If the compiler is clang and the target architecture is not the same as the build host then an appropriate target triple will be created and passed to clang to support native cross compilation.

Using an external binutils

To use an external binutils, set the XAS, XAR, XLD, XNM, XOBJDUMP, XRANLIB, and XSTRINGS. As with the compiler, there is a CROSS_BINUTILS_PREFIX variable. If the both the compiler and binutils have the same prefix a CROSS_TOOLCHAIN_PREFIX variable can be used to set both.

Caveats

To use XCC, you must not set any of the variables that can be overridden by X* variables in /etc/make.conf or /etc/src.conf as Makefile.inc1 will be unable to change them.

External, cross-building gcc toolchains support is still somewhat weak.

Status

An initial patch has been committed to head. It is known to work with a recent external clang-devel port and devel/binutils.

ExternalToolchain (last edited 2013-09-03 17:07:12 by WarnerLosh)