By default, GCC assumes that a cross compiler should not have any valid
initial include or library paths aside from /usr/local/lib/gcc/<mumble>/.
This means that one cannot use --sysroot to point to a system root for
another architecture and have GCC automatically look for headers in
${sysroot}/usr/include, etc. Currently we workaround this in FreeBSD's
build system with explicit -isystem, -B, and -L directives. However,
this is cumbersome compared to clang (where a bare --sysroot DTRT)
especially when using the compiler to build other software (such as test
programs, etc.).
One can override GCC's assumption and force it to assume that it should
honor --sysroot by setting the '--with-sysroot' option to force GCC to
assume a specific system root. By setting this to '/', this means that
the cross-compiler will attempt to use the host's headers by default
if --sysroot is not specified, but if --sysroot is specified then
it is fully honored including for include paths and library paths. With
this change I can now cross-compile both C and C++ binaries simply by
using --sysroot without the need for -isystem, -B, or -L directives.
One caveat is that the built GCC does look for headers in /usr/local/include Note
(underthat the sysroot) before /usr/include, but I think that is an existingbase/gcc and devel/riscv64-gcc ports both use --with-sysroot='/'
problem in the nativealready.
By default, GCC ports as well and whatever solution is used forlooks for headers in /usr/local/include (under the sysroot)
that would be applicable herebefore /usr/include. To disable this and only look for headers in /usr/include,
patch gcc/Makefile.in to not define LOCAL_INCLUDE_DIR.
This patch is also probably relevant for base/gcc and in that case shouldTo avoid populating include-fixed with patched headers from the build host,
allow the packages built via base/gcc to work "normally" without requiringcreate a stub sysroot in the work directory containing only an empty
--sysroot, -isystem, -B, or -L directives. I haven't tried to build/usr/include subdirectory and point --with-build-sysroot at this stub
a patched base/gcc yet thoughsysroot.
On a related note, I also fixed the name of the C++ include directory
option to configure. By my reading it is 'with-gxx-include-dir' rather
than 'with-gcc-include-dir'.