简体   繁体   English

bitbake 配方中的可选依赖项

[英]Optional dependency in a bitbake recipe

Assume I have a package foo that auto-detects another package bar and enables extra functionality if bar is present.假设我有一个包foo可以自动检测另一个包bar并在bar存在时启用额外的功能。 However foo can build and works just fine without bar .然而foo可以在没有bar情况下构建和工作。 How can I represent this dependency in the recipe for foo ?我如何在foo的配方中表示这种依赖关系? Things I've thought of:我想到的事情:

  • I could add bar to foo 's DEPENDS , but that means that now bar will always get installed whenever an image includes foo .我可以添加barfooDEPENDS ,但是这意味着现在bar总是会得到安装时的图像包括foo
  • I could do nothing, but then foo will randomly include the extra functionality or not depending on whether bar was compiled before or after.我什么也做不了,但是foo会随机包含额外的功能,这取决于bar是在之前还是之后编译的。
  • I could add a PACKAGECONFIG[bar] = ",,bar" , but then I must remember to add bar to foo 's PACKAGECONFIG when I add it to the image and to remove it when I want to remove it from the image.我可以添加PACKAGECONFIG[bar] = ",,bar" ,但是我必须记住在将bar添加到图像时将bar添加到fooPACKAGECONFIG并在我想从图像中删除它时将其删除。

Is there a way to tell bitbake that foo builds fine without bar but if both are present then bar should be built first?有没有办法告诉 bitbake foo在没有bar情况下构建得很好,但是如果两者都存在,那么应该先构建bar


To make things clearer, assume I have the following in foo 's configure.ac :为了让事情更清楚,假设我在fooconfigure.ac有以下内容:

PKG_CHECK_MODULES([BAR], [bar], [AC_DEFINE([HAVE_BAR]), [1], [Is bar available?])])

Then in foo.c :然后在foo.c

#ifdef HAVE_BAR
#include <bar.h>
#endif

/* And later: */
void foo_init (void)
{
#if HAVE_BAR
   bar_init();
   enable_bar_functionnality();
#endif
}

So foo will detect if bar is present and activate or not the corresponding functionality at compile time .因此foo将检测bar是否存在并在编译时激活或不激活相应的功能。

If I understand your question correctly, you have foo detecting bar 's presence at runtime.如果我没有理解你的问题,你有foo检测bar在运行时的身影。 A more yocto-ish way to do this would be to have the functionality and dependencies clarified at compile time so that when the image is built it contains what is desired.一种更 yocto-ish 的方法是在编译时澄清功能和依赖关系,以便在构建映像时包含所需的内容。

You could do this either by defining "features" of foo using PACKAGECONFIG or by defining multiple packages using PACKAGES .您可以通过使用PACKAGECONFIG定义 foo 的“功能”或使用PACKAGES定义多个包来做到这一点。 The former lets you set compiler arguments;前者让你设置编译器参数; the latter only lets you define subset of files for deployment.后者只允许您定义用于部署的文件子集。 Either way, you can define RDEPENDS ("runtime depends") that only apply to the foo+bar case.无论哪种方式,您都可以定义仅适用于 foo+bar 情况的RDEPENDS (“运行时依赖”)。

Using PACKAGES使用PACKAGES

DEPENDS is a compile-time dependency, ie something needed to compile or assemble all of the packages defined in the recipe. DEPENDS是编译时依赖,即编译或组装配方中定义的所有包所需的东西。 These files will only end up in the image if they are defined to be part of a package with FILES.如果这些文件被定义为带有 FILES 的包的一部分,它们只会出现在映像中。

DEPENDS += "bar"
PACKAGES += "foo foo-with-bar"
FILES_foo = "${bindir}/foo"
FILES_foo-with-bar = "${bindir}/foo ${bindir}/bar"
# probably not necessary since bar is included in foo-with-bar
# and RDEPENDS should be set to this automatically
# RDEPENDS_foo-with-bar += "bar"

Using PACKAGECONFIG使用PACKAGECONFIG

I find PACKAGECONFIG difficult to use, but if you need to compile in bar support, this is the way to go.我发现PACKAGECONFIG很难使用,但是如果您需要在 bar support 中编译,这是要走的路。 It takes up to six arguments, including runtime-deps-for-f1 , which is what you need to get bar installed when the bar feature of foo is enabled.它需要长达六个参数,包括runtime-deps-for-f1 ,这是你需要得到什么bar安装的栏功能时foo启用。

PACKAGECONFIG[f1] = "\
    --with-f1, \
    --without-f1, \
    build-deps-for-f1, \
    runtime-deps-for-f1, \
    runtime-recommends-for-f1, \
    packageconfig-conflicts-for-f1"

One recipe in poky/meta that sets runtime deps is recipes-connectivity/connman/connman.inc : poky/meta中设置运行时依赖的一个方法是recipes-connectivity/connman/connman.inc

PACKAGECONFIG[nftables] = " \
  --with-firewall=nftables , \
  , \
  libmnl libnftnl,\
  , \
  kernel-module-nf-tables kernel-module-nft-chain-nat-ipv4 (...) \
"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM