Skip to content
  • Martin Kelly's avatar
    tools: fix cross-compile var clobbering · 5ee254ef
    Martin Kelly authored
    commit 7ed1c190 upstream.
    
    Currently a number of Makefiles break when used with toolchains that
    pass extra flags in CC and other cross-compile related variables (such
    as --sysroot).
    
    Thus we get this error when we use a toolchain that puts --sysroot in
    the CC var:
    
      ~/src/linux/tools$ make iio
      [snip]
      iio_event_monitor.c:18:10: fatal error: unistd.h: No such file or directory
        #include <unistd.h>
                 ^~~~~~~~~~
    
    This occurs because we clobber several env vars related to
    cross-compiling with lines like this:
    
      CC = $(CROSS_COMPILE)gcc
    
    Although this will point to a valid cross-compiler, we lose any extra
    flags that might exist in the CC variable, which can break toolchains
    that rely on them (for example, those that use --sysroot).
    
    This easily shows up using a Yocto SDK:
    
      $ . [snip]/sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi
    
      $ echo $CC
      arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-ab...
    5ee254ef