autoconf配置在交叉编译时获取主机编译器HOSTCC / CC_FOR_BUILD

问题描述

交叉编译时应如何获取主机编译器(例如gcc,但可能会有所不同)

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

我在config.log中得到了变量:

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

但是我无法从中获得类似$HOSTCC的东西。 我知道,当我省略--build the default is --build=$(config.guess)时。但是无论指定它还是使用认值都不能帮助我找到编译器。

另外,自动工具似乎不支持

仅供参考,我需要在LTP添加一些编译时帮助工具,这些工具使用automake and autoconfbut otherwise have somehow custom build system,而不使用Makefile.am。因此CC=$(CC_FOR_BUILD)之类的东西不可用:(。

也许无法(使用某些脚本)从$build变量中检测到它,我不得不要求用户定义它:

HOSTCC=${HOSTCC-cc}

解决方法

也许使用AC_ARG_VAR

configure.ac

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

Makefile.in

HOSTCC  = @HOSTCC@

信用:Gforth项目:configure.ac Makefile.in

我将代替test -z "$HOSTCC" && HOSTCC='$(CC)'中的configure.ac,将其添加到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

但如果开箱即用地支持HOSTCCCC_FOR_BUILD,那就太好了。