Search code examples
linuxyocto

How to include custom header files directory into rootfs using yocto


I want to install a directory having subdirectories of header source files, into the rootfs in the path /usr/include/.

The files are not included in the image.

directory structure in recipe

maindir
 -subdir
   -headerfile1.h
   -headerfile2.h
 -subdir2
  - headerfile3.h
  - headerfile4.h

recipe.bb file:

SRC_URI += "file://maindir/"

S = "${WORKDIR}"

do_install () {
        
        install -d ${D}${includedir}/
        mkdir   -p ${D}${includedir}/maindir/
        mkdir   -p ${D}${includedir}/maindir/subdir/
        #I can see only an empty directory gets installed with no sub-directories and header files.
        cp -r ${WORKDIR}/maindir/ ${D}${includedir}/

        install -m 0755 ${WORKDIR}/maindir/subdir/* ${D}${includedir}/maindir/subdir/
}

FILES_${PN} += "${includedir}/maindir/"

How could I achieve this? Do I need to use FILES_${PN}-dev instead?


Solution

  • You will need three things:

    1. To install the new directories with subdirectories into target root filesystem —notice it is only for the new directories. This is done with install -d ${D}<path in rootfs>

    2. Copy your header files into them. This is the install -m <files mode> <source dir>/*.h ${D}/<destination> syntax. Permission mode 0644 for header files, as they don't need execution permissions, only read only, unless you want to edit it as a super user, that is the 6 from the previous mode.

    3. Extend FILES for packaging your files to a given package.

    In summary, to accomplish the three steps in a syntactically correct way, you would:

    do_install () {
      install -d ${D}/${includedir}/maindir
      install -d ${D}/${includedir}/maindir/subdir
      install -d ${D}/${includedir}/maindir/subdir2
    
      install -m 0644 ${S}/maindir/subdir/*.h ${D}/${includedir}/maindir/subdir/
      install -m 0644 ${S}/maindir/subdir2/*.h ${D}/${includedir}/maindir/subdir2/
    }
    
    FILES_${PN}-dev += "\
      ${includedir}/maindir/subdir/*.h \
      ${includedir}/maindir/subdir2/*.h \
    "
    

    Notice, it is good practice to use <pkg name>-dev with -dev, for packaging the headers files, nice catch!

    Then, to install your just made recipe-dev package you do:

    IMAGE_INSTALL_append = " recipe-dev"