Jmb
Jmb

Reputation: 23443

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. However foo can build and works just fine without bar. How can I represent this dependency in the recipe for foo? Things I've thought of:

Is there a way to tell bitbake that foo builds fine without bar but if both are present then bar should be built first?


To make things clearer, assume I have the following in foo's configure.ac:

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

Then in 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.

Upvotes: 2

Views: 1787

Answers (1)

Robert Calhoun
Robert Calhoun

Reputation: 5153

If I understand your question correctly, you have foo detecting bar's presence at runtime. 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.

You could do this either by defining "features" of foo using PACKAGECONFIG or by defining multiple packages using 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.

Using PACKAGES

DEPENDS is a compile-time dependency, i.e. something needed to compile or assemble all of the packages defined in the recipe. These files will only end up in the image if they are defined to be part of a package with 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

I find PACKAGECONFIG difficult to use, but if you need to compile in bar support, this is the way to go. 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.

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:

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

Upvotes: 2

Related Questions