If you need to build different pieces for different execution hosts, then the cleanest way to go about it is to build the build tools separately. One of the answers you linked describes a way to do this. If you have a well-written Autotools build system, however, then you might be able to tackle this differently, by leveraging out-of-source builds. This can be scripted.
Create a directory within which to build the tools. In that directory, configure for the build system (path-to-source-dir/configure
), and then build (just) the needed tools. Then in the source directory or a different out-of-source build directory, configure for the cross-compilation by specifying the appropriate --build
and --host
triplets to configure
, copy or link the already-built tools into the build directory, and perform the rest of the build.
If the build system is especially carefully crafted, then you may need to overcome provisions for different executable extensions for the build tools on different hosts. If you need to do this and you're planning to script the two-stage cross-compilation anyway, then you can probably handle the issue when you copy/link the tools; that will avoid any need to write special support for it into the core build system.
To support cross-compilation in general, configure.ac
should use the AC_CANONICAL_BUILD
and AC_CANONICAL_HOST
macros, and the build machine will need to have an appropriate cross-compilation toolchain installed.