[英]Why does bitbake ignore CFLAGS in my makefile?
My application's makefile adds a couple things to CFLAGS as follows:我的应用程序的 makefile 向 CFLAGS 添加了一些内容,如下所示:
CFLAGS += -Wall -std=gnu99
When I build the application with OpenEmbedded BitBake however, BitBake is apparently ignoring the CFLAGS variable from the makefile.但是,当我使用 OpenEmbedded BitBake 构建应用程序时,BitBake 显然忽略了 makefile 中的 CFLAGS 变量。
I found that adding the following line in the application's recipe causes the flags to be used during a build via BitBake:我发现在应用程序的配方中添加以下行会导致在通过 BitBake 构建期间使用这些标志:
EXTRA_OEMAKE += "CFLAGS='-Wall -std=gnu99'"
Why does BitBake ignore the CFLAGS from the makefile like this?为什么 BitBake 会像这样忽略 makefile 中的 CFLAGS? 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.我更喜欢使用 makefile 的 CFLAGS 来消除冗余。
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} "$@"
).默认情况下,
bitbake.conf
包含EXTRA_OEMAKE = "-e MAKEFLAGS="
在运行时传递给 make 命令(参见base.bbclass
,它运行${MAKE} ${EXTRA_OEMAKE} "$@"
)。
The -e
option to make means that environment variables override makefiles (from make --help
). make 的
-e
选项意味着环境变量覆盖 makefiles(来自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.您还会注意到
bitbake.conf
在其他几个导出变量中设置了export CFLAGS = "${TARGET_CFLAGS}"
,因此在环境中设置了CFLAGS
。
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.这样做的原因是有一些编译器标志在交叉编译时很重要,一般来说,系统比
Makefile
更清楚要使用什么。 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 (eg would it find the cross compiler).您可以从
EXTRA_OEMAKE
删除-e
选项,但您可能会面临其他关键变量设置不正确的风险(例如,它会找到交叉编译器)。 Another slightly cleaner solution might be to add to TARGET_CFLAGS
, eg:另一个稍微干净的解决方案可能是添加到
TARGET_CFLAGS
,例如:
TARGET_CFLAGS += "-Wall -std=gnu99"
Unfortunately there is likely no perfect solution here however hopefully this helps understand why it does what it does.不幸的是,这里可能没有完美的解决方案,但希望这有助于理解它为什么会这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.