【问题标题】:autoconf (configure) get host compiler when cross compiling (HOSTCC / CC_FOR_BUILD)autoconf (config) 交叉编译时获取宿主编译器 (HOSTCC / CC_FOR_BUILD)
【发布时间】:2020-12-21 22:54:12
【问题描述】:

当我交叉编译时,我应该如何获得主机编译器(例如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) 时。但无论是指定它还是使用默认值,它都无法帮助我找到编译器。

另外,autotools 中似乎没有支持:

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

也许没有办法从$build 变量中检测到它(使用一些脚本),我必须要求用户定义它:

HOSTCC=${HOSTCC-cc}

【问题讨论】:

标签: cross-compiling autoconf automake toolchain


【解决方案1】:

也许使用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.acMakefile.in

我将在configure.ac 中添加test -z "$HOSTCC" && HOSTCC='$(CC)' 而不是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 开箱即用,那就太好了。

【讨论】:

猜你喜欢
  • 2020-07-05
  • 1970-01-01
  • 2018-04-11
  • 2013-02-20
  • 1970-01-01
  • 2013-10-10
  • 1970-01-01
  • 2011-09-03
  • 1970-01-01
相关资源
最近更新 更多