Confused about install -m and install -d using Yocto
Asked Answered
F

1

9

I have taken over a Yocto project, and inside a .bb recipe file, I see the following lines to install new directories in the image:

    do_install() {
    install -m 0755 -d ${DEPLOY_DIR_IMAGE}/app
    install -m 0755 -d ${DEPLOY_DIR_IMAGE}/app/apiary
    install -m 0755 -d ${DEPLOY_DIR_IMAGE}/app/lib
    install -m 0755 -d ${DEPLOY_DIR_IMAGE}/app/config
    install -m 0755 -d ${DEPLOY_DIR_IMAGE}/app/scripts
    install -m 0755 -d ${DEPLOY_DIR_IMAGE}/app/keys

This works but I am confused. From my reading about Yocto and doing do_install, I thought that the -m option is only for installing files and not directories.

What is the effect of doing install -m 0755 -d, both the -m and -d options with the install command?

Also, why is there no ${D} variable like in the majority of other directory installations which I see?

I normally wouldn't resort to Stack Overflow for a question like this, but there is so much inconsistency that I don't understand, and hard to find an answer.

Franklynfrankness answered 30/5, 2019 at 9:51 Comment(3)
install(1) man page. -d is like mkdir -p. The -m sets the mode (permissions). Note that install with options like -d are non-standard. It won't be available on some operating systems, like AIX or Solaris install.Schick
Another standard of interest may be GNU Coding Standard and the Makefile's INSTALL command variable.Schick
@Schick Thanks for that. How is this working without the ${D} variable do you know?, I guess this is Yocto-specific thoFranklynfrankness
H
15

The task in question is defined as a shell function. The install command used within is a shell command, not anything Yocto- or BitBake-specific, so you should be looking at its docs for enlightenment, not relying on BitBake documentation or examples. In the context of Yocto in particular, however, you should be looking at the documentation for the GNU coreutils version of the install program (as linked above), which is the one you will invariably find on Linux systems.*

From my reading about Yocto and doing do_install, I thought that the -m option is only for installing files and not directories.

I'm not sure what would make you think that, other than just not seeing it applied to directories before.

What is the effect of doing install -m 0755 -d, both the -m and -d options with the install command?

The -m option sets the mode (access-control bits) of the installed object(s). Directories have modes just like regular files do, and the -m option has the same meaning for installing directories as it does for installing regular files.

The -d option specifies that the names specified for installation are to be taken as directories to be created, along with any missing directories in the specified path. As @jww observed in comments, the effect is analogous to that of mkdir -p.

These options are orthogonal. When used together, their effects combine in the natural way: the specified directories are created, with parent directories if needed, and all directories created are assigned the specified mode. Setting the modes explicitly to 0755 is superfluous, however, because that's the default. That may be why you are not used to seeing -m options used for directories.

Also, why is there no ${D} variable like in the majority of other directory installations which I see?

The Yocto specifications for do_install say that it should install files relative to ${D}, whereas the variable DEPLOY_DIR_IMAGE refers to the location for ready-to-install images. It seems like installing to ${DEPLOY_DIR_IMAGE} would be the wrong thing to do, but that doesn't necessarily mean that it wouldn't produce the desired ultimate effect. Or perhaps the recipe was simply written for some older version of BitBake where it made more sense. In any event, sorting out the the details would be a much deeper and more involved analysis than I am prepared to perform for you.


*install is not standardized by POSIX. The GNU version was inspired by BSD's program of the same name, and current versions of that have similar options and behavior, including specifically with respect to the -m and -d options.

Hagiographa answered 30/5, 2019 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.