My application's makefile adds a couple things to CFLAGS as follows:
CFLAGS += -Wall -std=gnu99
When I build the application with OpenEmbedded BitBake however, BitBake is apparently ignoring the CFLAGS variable from the makefile.
I found that adding the following line in the application's recipe causes the flags to be used during a build via BitBake:
EXTRA_OEMAKE += "CFLAGS='-Wall -std=gnu99'"
Why does BitBake ignore the CFLAGS from the makefile like this? Also, is there a better solution than adding the line above to recipe?
I'd prefer that the makefile's CFLAGS just be used in order to eliminate the redundancy.
By default, bitbake.conf
contains EXTRA_OEMAKE = "-e MAKEFLAGS="
which is passed to the make command when its run (see base.bbclass
, which runs ${MAKE} ${EXTRA_OEMAKE} "$@"
).
The -e
option to make means that environment variables override makefiles (from make --help
). You'll also notice that bitbake.conf
sets export CFLAGS = "${TARGET_CFLAGS}"
amongst several other exported variables, so CFLAGS
is set in the environment.
The reason it does this is that there are some compiler flags which are important whilst cross compiling and in general, the system has a better idea of what to use than the Makefile
does. This does sometimes fail as you've found.
You could remove the -e
option from EXTRA_OEMAKE
but you run the risk of other key variables not being set correct (e.g. would it find the cross compiler). Another slightly cleaner solution might be to add to TARGET_CFLAGS
, e.g.:
TARGET_CFLAGS += "-Wall -std=gnu99"
Unfortunately there is likely no perfect solution here however hopefully this helps understand why it does what it does.