1

How should I get host compiler (e.g. gcc, but it could be different) when I cross compile:

./configure --host aarch64-suse-linux CROSS_COMPILE="aarch64-suse-linux-"

I get variables in config.log:

build='x86_64-pc-linux-gnu'
build_cpu='x86_64'

But I have no way to get something like $HOSTCC from it. I know that when I omit --build the default is --build=$(config.guess). But regardless specifying it or use the default it does not help me to find the compiler.

Also it looks like there is no support in autotools:

FYI I need it to add some compile-time helper tools in LTP, which uses automake and autoconf, but otherwise have somehow custom build system, which does not use Makefile.am. Thus something like CC=$(CC_FOR_BUILD) is not available :(.

Maybe there is no way to detect it from $build variable (using some script) and I have to ask users to define it:

HOSTCC=${HOSTCC-cc}
pevik
  • 4,523
  • 3
  • 33
  • 44
  • Does this answer your question? [How to get "build" and "target" C compiler with autoconf](https://stackoverflow.com/questions/42674571/how-to-get-build-and-target-c-compiler-with-autoconf) – Jan Hudec Jun 09 '21 at 12:44

1 Answers1

0

Maybe using AC_ARG_VAR:

configure.ac:

AC_ARG_VAR(HOSTCC, [The C compiler on the host])
test -z "$HOSTCC" && HOSTCC='$(CC)'

Makefile.in:

HOSTCC  = @HOSTCC@

Credits: Gforth project: configure.ac Makefile.in.

Instead of test -z "$HOSTCC" && HOSTCC='$(CC)' in configure.ac I'll add into Makefile.in:

build := @build@
host := @host@
ifeq ($(strip $(HOSTCC)),)
# native build, respect CC
ifeq ($(build),$(host))
HOSTCC := $(CC)
else
# cross compilation
HOSTCC := cc
endif
endif

But it'd be great if HOSTCC or CC_FOR_BUILD was supported out of the box.

pevik
  • 4,523
  • 3
  • 33
  • 44
  • BTW Although we support for `--host` parameter, I'm going to use `AC_ARG_VAR` macro also for `CROSS_COMPILE` variable in [LTP configure.ac script](https://github.com/linux-test-project/ltp/blob/master/configure.ac). – pevik Jan 11 '21 at 08:57
  • It is supported almost-out-of-the-box with autoconf-archive, see https://stackoverflow.com/questions/42674571/how-to-get-build-and-target-c-compiler-with-autoconf – Jan Hudec Jun 09 '21 at 12:45