Effectiveness of *_FOR_BUILD and *_FOR_TARGET environment variables

Manuel Jacob <[email protected]> Sat, 21 Mar 2026 18:23:14 +0100
Newsgroups gmane.comp.gcc.help
Message-ID <[email protected]>
Hi,

I found that the *_FOR_BUILD and *_FOR_TARGET environment variables are 
not always used by the GCC build system.

If "${build}" = "${host}" ([1]), *_FOR_BUILD are not used and get 
overwritten with a reference to the unsuffixed (“for host”) variable. I 
think it would be useful to use the *_FOR_BUILD environment variables if 
non-empty and default to the current behavior otherwise. My use case is 
that, even in the native compilation case, I have a separate sysroot for 
the libraries that the produced compiler links against. This requires 
the build definition in my package manager to list all dependencies 
explicitly instead of implicitly relying on libraries that happen to be 
installed on the build system. The general goal is to handle native 
compilation and cross-compilation as similar as possible.

A separate issue is that, if $build != $host ([2], used by [3] and 
following), the *_FOR_TARGET environment variables get overwritten with 
the empty string and later overwritten with an inferred value. I think 
it would be useful to keep the environment variable if non-empty. I’m 
unsure what should take precedence if both a *_FOR_TARGET environment 
variable and --with-build-time-tools is given. I tend towards that the 
environment variable should take precedence because it’s more specific 
(per-tool). But it should not make much difference in practice, as there 
is no reason to pass contradicting values.

Does that make sense? Or is there a good reason for keeping the current 
behavior?

-Manuel


[1] 
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=configure.ac;h=c5de225b0ac3bfc7e4b3c0eea6c390509af58bd5;hb=HEAD#l1470
[2] 
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=config/acx.m4;h=7304d7b82adb2b81a8a14ede14abf3ac688063f8;hb=HEAD#l353
[3] 
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=configure.ac;h=c5de225b0ac3bfc7e4b3c0eea6c390509af58bd5;hb=HEAD#l4206