compilationbitbakeopenembeddedcompiler-flags

Exclude/ignore/disable gcc compiler flags during BitBake do_compile


I am trying to run a script during the do_compile stage of a bitbake (.bb) recipe. The project is built inside an openembedded environment.

  1. The script can be successfully run outside the openembedded environment.

  2. The script fails when run inside the openembedded environment with the following error:

    bin/arm-linux-gnueabihf-ld.bfd -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -r -o bin/arm-linux-gnueabihf-ld.bfd: unrecognized option '-Wl,-O1'

Openembedded environment is adding these extra flags, -Wl,-O1 -Wl,--hash-style=gnu.

  1. When the script is run outside the openembedded project, this is the output:

    bin/arm-linux-gnueabihf-ld.bfd -r -o

I am looking for a way to have these linkers, optimization, and other flags disabled or excluded during compile stage. I am struggling to find a solution and I am not well versed in many areas of coding & development.

Is there a statement I can call either inside the script or inside the bitbake (.bb) recipe so that these flags can be skipped or ignored?

Or is there a way I can modify my script to recognize these flags?

Thanks for any information or help. I will be happy to provide more information if needed.


Solution

  • Solved:

    do_compile() {
        unset LDFLAGS
        unset CFLAGS
        unset CPPFLAGS
        # remove CC so it is defined here
        sed -e '/^CC\t=/d' -i ${S}/config.mk
        oe_runmake all 
    
        # fix tools/env Makefile usage
        sed -e 's/$(CROSS_COMPILE)gcc/$(CC)/g' \
            -e 's/ln -s /ln -sf /g' \
            -e '/CFLAGS :=/ aCFLAGS += -DMEM_SIZE_${@d.getVar('KERNEL_BOOTLOADER_MEM_SIZE',1) or '128'}MB' \
            -i ${S}/tools/env/Makefile
        oe_runmake env CC="${CC}"
        oe_runmake fw_env_lib CC="${CC}"}