16

I have seen the following install command used in multiple yocto recipes

install -d ${D}${libdir}

I am aware of the install command and its purpose, however I am unable to understand the purpose of the ${D} variable as it is often nowhere defined in the recipe. Can somebody explain the purpose of this shell variable?

2

2 Answers 2

13

The ${D} variable allows the software being built to be installed in a directory other than its real target. For example, you might configure the software so that libdir is /usr/lib, but that's for the target device; when you run the installation on your build system, you don't want the newly-built files to actually be installed in /usr/lib, you want the placed somewhere isolated so that they can be readily identified and copied across to the target system. So you create a temporary directory and install there:

mkdir /tmp/yocto-target
make install D=/tmp/yocto-target

That way the files end up in /tmp/yocto-target/usr/lib and so on. You can then archive all of /tmp/yocto-target using whatever tool you prefer, dropping the /tmp/yocto-target prefix, copy the archive to the target device and install its contents there.

In other build systems, the DESTDIR variable is used for the same reason.

5
  • Does installing package in ${D}${libdir} copy the output to package DESTDIR or to rootfs foder in /tmp/work.../rootfs ? Commented Nov 10, 2017 at 15:24
  • Umm... I’m not sure what you’re asking; installing in ${D}${libdir} installs in whatever directory the D and libdir variables point to. DESTDIR is used in other build systems, not Yocto’s. Commented Nov 10, 2017 at 16:09
  • The answer explains the "purpose" of ${D}, but as the OP wrote "it is often nowhere defined in the recipe". It still remains a mystery where its value comes from. E.g. I have a template recipe generated by the petalinux-create command which references ${D} but there is no "include" or any other clue as to where the ${D} is defined. Commented Dec 11, 2017 at 22:04
  • 1
    @2.718 it’s not defined because it’s up to the user to specify its value, as indicated in my example: make install D=/tmp/yocto-target will install to a set of directories rooted in /tmp/yocto-target. If no value is given, the installation is done in /. Commented Dec 11, 2017 at 22:08
  • @Stephen Kitt thanks for the clarification. It is not obvious to a newcomer who has not written BB recipes before and is only looking at them to understand how it all hangs together. Commented Dec 14, 2017 at 21:09
6

${D} is the usual top of the path used by a Yocto recipe where the recipe installs files that belong to packages produced by this recipe. These directories under ${D} are scanned by the build system for files to include into packages (like RPM files) and to be included in the so-called sysroot tree where files (e.g. libraries and headers) go that are used by other packages. There are some default rules for this scan and the rules can be expanded. It is recommended to use these Yocto default paths under ${D} as much as possible to benefit from the built-in mechanisms of Yocto.

${libdir} is defined in bitbake.conf by default as: ${exec_prefix}/lib which is /usr/lib by default, defined in the same file.

install -d ${D}${libdir} 

In the end this "install" shell command just creates a directory where files are to be saved (e.g. by do_install) that should finally be installed under /usr/lib on the target.

${D}/a/b/c for file c is just the intermediate path used for Yocto packaging and ${D} is "cut away" when the same file c is on the target filesystem. So for instance ${D}/a/b/c will be at /a/b/c on the target.

${D} is defined by default in poky/meta/conf/bitbake.conf as:

TMPDIR = "${TOPDIR}/tmp"
BASE_WORKDIR ?= "${TMPDIR}/work"
WORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}"
D = "${WORKDIR}/image"
1
  • I'm not familiar with yocto; does this D variable come into play, given Stephen's answer? Commented Dec 11, 2018 at 16:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.