Building 18.01.0 with a different SYSROOT

I’m upgrading my six-month-old legato to 18.01, and I’m having trouble with sysroot.

It used to be that I could add a new target pretty easily to the build system, provided I:

  • Made some minor changes to the Makefile to add the new target
  • Defined the ${TARGET}_TOOLCHAIN_DIR and ${TARGET}_TOOLCHAIN_PREFIX
  • Defined ${TARGET}_SYSROOT

Version 18.01 seems to have changed the build system a fair amount. The toolchain directory and prefix still take effect, and the Legato build system has no problem finding my cross-compiler.

But I can’t for the life of me figure out how to convince Legato to recognize the sysroot. The error I get is clearly related the missing sysroot:

/home/cholmes/leardev/legwork/legato/framework/include/legato.h:145:20: fatal error: unistd.h: No such file or directory

If I copy & paste the failed command onto the command line, but just add --sysroot=$IMX6_SYSROOT then the header file can be found.

What do I have to do to convince Legato to recognize my custom target’s SYSROOT?

I had this same issue. Try setting LEGATO_SYSROOT to the same thing as you have for ${TARGET}_SYSROOT. It’s kind of clunky, but this commit (which should be in 18.02) will make things a bit better. Basically it will define LEGATO_SYSROOT based on ${TARGET}_SYSROOT if it’s not already defined.

commit 2ffa814e8a4a68539d1865a4fe0b5d05e76e2290
Author: Keith Dunwoody <kdunwoody@sierrawireless.com>
Date:   Tue Feb 20 12:11:38 2018 -0800

    Set LEGATO_SYSROOT from $(TARGET)_SYSROOT

    LEGATO_SYSROOT needs to be set for framework build to work, so if
    user has set $(TARGET)_SYSROOT, set LEGATO_SYSROOT from that.

    Resolves: LE-9482
    Change-Id: I2bd448f630603809e35ee3e0c87b8a32d690b2ab

diff --git a/targetDefs b/targetDefs
index 4ab104a86..672ba7a74 100644
--- a/targetDefs
+++ b/targetDefs
@@ -48,6 +48,7 @@ else
     endif
     export TOOLCHAIN_DIR := $($(TARGET_CAPS)_TOOLCHAIN_DIR)
     export TOOLCHAIN_PREFIX := $($(TARGET_CAPS)_TOOLCHAIN_PREFIX)
+    export LEGATO_SYSROOT ?= $($(TARGET_CAPS)_SYSROOT)
 endif


That worked so, progress!

Peeling the onion one more time…

Now I have an issue with the CFLAGS while building the framework. I need to add the flag float-abi during compile time, but again nothing I do seems to have any effect.

I added a file “targets/imx6.sinc” with the following content:

cflags:
{
    -mfloat-abi=hard
}

It doesn’t have any effect, at least not while building the framework. So I tried adding the same clause to the default.sdef file, and again no effect.

So, is there an approved way to change the cflags during the framework build?

Again, if I take the failed compiler command and manually add my flag, the compiler behaves correctly. I just can’t figure out how to convince Legato to include my flags during the framework compilation.

I have tried adding to the MKSYS_FLAGS in Makefile, and setting CFLAGS and CXXFLAGS in the environment. All to no avail.

It seems that the framework build knows what flags it wants to use, and is deaf to all other entreaties.

I found I could change the CFLAGS of the liblegato build by setting an environment variable:

NINJA_CFLAGS=-mfloat-abi=hard

I’m not sure yet if that change affects all of the application builds or not.