Question

I have made a little project using autoconf/automake.

The project is intended to be both natively compiled and cross compiled e.g. as such:

./configure --host=arm-none-eabi

This works fine. But one issue is if the cross compiler isn't installed, the configured script ignores it, and happily compiles it using the default compiler installed e.g.

./configure --host=arm-none-eabi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-eabi-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make sets $(MAKE)... (cached) yes
checking for arm-none-eabi-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes

Here arm-none-eabi-gcc was not found. But it finds the native gcc, and continues using the native compiler.

What can I put in the configure.ac to have the configure script halt and error out if I request a cross compilation by using --host=XXXX and a compiler for that cannot be found ?

Was it helpful?

Solution

When you specify --host=<host-type>, and this value differs from the result of running the config.guess script, autoconf enters cross-compilation mode. Specifically, the variable cross_compiling is set to yes.

If the configure script is in 'cross-compilation' mode, it can't run any resulting executable, so there's no way to tell if a resulting binary is a valid 'host' binary or not. Presumably, a large database of file magic values might be able to tell if a valid host binary has been generated. Despite a couple of decades worth of experience built into the autotools, there are some combinatorial problems that can never keep up with all possible architectures and ABIs.

The autoconf C compiler tests check to see if the compiler - that is $CC - can build an executable. autoconf may provide a warning if the compiler is not prefixed with the host triplet, e.g., arm-none-eabi-gcc, but will not 'fail' if it finds a working compiler, such as the native gcc.

So, the only way to ensure cross-compilation with the correct compiler is to specify the compiler:

./configure --host=arm-none-eabi CC="arm-none-eabi-gcc"

If this compiler can't build executables, the configure script will fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top