9

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.

user5071535
  • 1,312
  • 8
  • 25
  • 42
  • Is bitbake using the makefile at all? Does it explicitly override `CFLAGS` on the command line when it runs `make`? – Etan Reisner Jan 21 '16 at 22:05
  • 1
    This is confusing: bitbake uses `recipe` files, not the `makefile`. Why are you using bitbake? If you have a makefile, use gnu make. – chqrlie Jan 21 '16 at 22:07
  • @EtanReisner Bitbake does use the makefile, but as far as I can tell it's not explicitly overriding CFLAGS on the command line when running make. – user5071535 Jan 21 '16 at 22:12
  • @chqrlie The recipe file describes to BitBake how to build the application. The makefile is being utilized, but CFLAGS in particular is for some reason being ignored. I have to use BitBake as it's part of the OpenEmbedded based build system I use for cross-compiling for an embedded system. – user5071535 Jan 21 '16 at 22:17
  • it is highly probable that bitbake passes its own value of `CFLAGS` to `make` in a way that makes `make` ignore the value set in the Makefile, such as on `make`s command line. You can verify this with some sort of verbose mode. – chqrlie Jan 21 '16 at 22:21

1 Answers1

28

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.

pevik
  • 4,523
  • 3
  • 33
  • 44
Richard Purdie
  • 2,028
  • 10
  • 16
  • Note that bitbake.conf now has `EXTRA_OEMAKE = ""`. See https://www.yoctoproject.org/docs/2.5/ref-manual/ref-manual.html#migration-2.1-makefile-environment-changes – akarollil Jul 19 '19 at 16:51