${D} variable in install command

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.


${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"