[yocto] Changing HOST_CC_ARCH temporarily in recipe

Ross Burton ross.burton at intel.com
Wed Sep 18 02:20:08 PDT 2019


On 18/09/2019 09:26, Damien LEFEVRE wrote:
> I have a package which requires to first build a x64 binary which is 
> then used to compile the target platform binaries.
> 
> The way I got away with it was to build that host binary from 
> do_configure_prepend() and then continue with the build procedure.
> 
> I recently upgraded to GCC7 + warrior and now building the host binary 
> from do_configure_prepend fails due to this error:
> testCCompiler.c:1:0: error: bad value (armv8-a+crc) for -march= switch
> 
> I figured that the arch switch (building for tegra) is defined 
> in HOST_CC_ARCH as:
> -march=armv8-a+crc -fstack-protector-strong  -D_FORTIFY_SOURCE=2 
> -Wformat -Wformat-security -Werror=format-security
> 
> If I clear HOST_CC_ARCH in my recipe file, do_configure_prepend succeeds 
> but of course the rest of the build will fail.
> 
> So i'm trying to do something like this:
> do_configure_prepend(){
>      export HOST_CC_ARCH_BACKUP="${HOST_CC_ARCH}"
>      HOST_CC_ARCH=""
>      echo "HOST_CC_ARCH before cmake: ${HOST_CC_ARCH}"
>      CC="${BUILD_CC}" CXX="${BUILD_CXX}" CCFLAGS="${BUILD_CFLAGS}" 
>   CXXFLAGS="${BUILD_CPPFLAGS} -std=c++11" LDFLAGS="${BUILD_LDFLAGS}" 
> cmake ${S}
>      make
>      HOST_CC_ARCH="${HOST_CC_ARCH_BACKUP}"
> }

Two solutions:
1) Work around the problem by manually building the tool yourself.  This 
should be done in do_compile_prepend so that it isn't newer than the 
makefiles, which would cause it to be regenerated.

There's no need to mess around with HOST_CC_ARCH. That is only used in 
CC/CXX/FC/CPP, and you should be using BUILD_CC etc anyway.  This 
*should* work:

do_compile_prepend() {
   CC="${BUILD_CC}" CPP=... CFLAGS=... CXXFLAGS=... LDFLAGS=... make 
[target]
}

(expand the ..., I'm lazy)

If HOST_CC_ARCH is being used then there's only a limited number of 
variables that use it, so override the right ones. May be CPP, may be 
CXX. Looking at the makefile will tell you. Always just build exactly 
what you need with the native compiler, not more.

However the proper solution is
2) fix the cmakefiles to work in cross builds.  CMake actually makes 
this even harder than autotools which is quite an achievement: 
https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling#using-executables-in-the-build-created-during-the-build. 
  Quite likely easier to port to Meson, where you just set the native 
property on a binary target.

Ross


More information about the yocto mailing list