How to add header file to /usr/include in Yocto - linux

I am working with Linux built with Yocto. I would like to add to the image my app to /bin and some header file to /usr/include. I have no problem with adding the app to /bin, but I am not able to add the header file to my rootfs. The .h file is added to a proper package, but it is not copied to rootfs.
Here is my recipe:
bindir = "${localdir}/bin"
incldir = "${localdir}/usr/include"
FILESEXTRAPATHS_prepend := "${THISDIR}/files/:"
SRC_URI = "file://My_app_dir/* \
\
"
S = "${WORKDIR}"
FILES_${PN} += "${incldir}/*"
do_compile() {
cd My_app_dir/src
make
}
do_install() {
install -d ${D}${bindir}
cp "${S}/My_app_dir/src/my_app" "${D}${bindir}/my_app"
install -d ${D}${incldir}
cp "${S}/My_app_dir/some_lib.h" "${D}${incldir}/some_lib.h"
}
After building the image, the include file exists in /build/tmp/work/<machine>/<my_app>/image/usr/include.
Do you have any idea why I cannot add .h file to /usr/include in rootfs? Thank you in advance for any help.

The header files (among other files like pkgconfig and shared library symlinks) are not added to the main package (say foo), but to the development package (e.g. foo-dev). This is called package split and you can learn more in the Package Splitting of the official documentation. The development packages (and BTW also the debug foo-dbg) are not installed by default.
But please be aware that adding the development package may pull other dependencies (because of various runtime dependencies) and files (there are other files in the development package).
Please note that your line FILES_${PN} += "${incldir}/*" has no effect, as the files in $includedir (i.e. FILES_${PN}-dev) are split before the FILES_${PN} are processed. The order is defined in the variable PACKAGES (check the official documentation).
BTW, there are minor things in the recipe which you can update (unrelated to your question though):
You can use location of standard system paths in the respective variables bindir, includedir etc.
install is preferred over the cp in do_install.
The line FILESEXTRAPATHS_prepend := "${THISDIR}/files/:" is needed only in bbappends. The files directory inside the recipe's directory is in the standard search path of files (among other paths like ${PN} etc.).

Related

CMake: how to get PATHS variable for find_package?

Here is an example how to specify PATHS variable to make cmake be able to find library:
cmake find_package specify path
But how to get this PATHS variable for specific library?
For example I have installed apt-get install libharfbuzz-dev and dpkg -L libharfbuzz-dev shows me:
/usr
/usr/include
/usr/include/harfbuzz
/usr/include/harfbuzz/hb-blob.h
/usr/include/harfbuzz/hb-buffer.h
/usr/include/harfbuzz/hb-common.h
/usr/include/harfbuzz/hb-deprecated.h
/usr/include/harfbuzz/hb-face.h
/usr/include/harfbuzz/hb-font.h
/usr/include/harfbuzz/hb-ft.h
/usr/include/harfbuzz/hb-glib.h
/usr/include/harfbuzz/hb-gobject-enums.h
/usr/include/harfbuzz/hb-gobject-structs.h
/usr/include/harfbuzz/hb-gobject.h
/usr/include/harfbuzz/hb-graphite2.h
/usr/include/harfbuzz/hb-icu.h
/usr/include/harfbuzz/hb-ot-font.h
/usr/include/harfbuzz/hb-ot-layout.h
/usr/include/harfbuzz/hb-ot-math.h
/usr/include/harfbuzz/hb-ot-shape.h
/usr/include/harfbuzz/hb-ot-tag.h
/usr/include/harfbuzz/hb-ot-var.h
/usr/include/harfbuzz/hb-ot.h
/usr/include/harfbuzz/hb-set.h
/usr/include/harfbuzz/hb-shape-plan.h
/usr/include/harfbuzz/hb-shape.h
/usr/include/harfbuzz/hb-unicode.h
/usr/include/harfbuzz/hb-version.h
/usr/include/harfbuzz/hb.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libharfbuzz-gobject.a
/usr/lib/x86_64-linux-gnu/libharfbuzz-icu.a
/usr/lib/x86_64-linux-gnu/libharfbuzz.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/harfbuzz-gobject.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/harfbuzz-icu.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/harfbuzz.pc
/usr/share
/usr/share/doc
/usr/share/doc/libharfbuzz-dev
/usr/share/doc/libharfbuzz-dev/copyright
/usr/share/gir-1.0
/usr/share/gir-1.0/HarfBuzz-0.0.gir
/usr/lib/x86_64-linux-gnu/libharfbuzz-gobject.so
/usr/lib/x86_64-linux-gnu/libharfbuzz-icu.so
/usr/lib/x86_64-linux-gnu/libharfbuzz.so
/usr/share/doc/libharfbuzz-dev/changelog.Debian.gz
Which path should I use?
Update:
Error message:
CMake Error at <some_path>/CMakeLists.txt:6 (find_package):
By not providing "FindHarfbuzz.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Harfbuzz",
but CMake did not find one.
Could not find a package configuration file provided by "Harfbuzz" with any
of the following names:
HarfbuzzConfig.cmake
harfbuzz-config.cmake
Add the installation prefix of "Harfbuzz" to CMAKE_PREFIX_PATH or set
"Harfbuzz_DIR" to a directory containing one of the above files. If
"Harfbuzz" provides a separate development package or SDK, be sure it has
been installed.
I tried to add path via CMAKE_PREFIX_PATH like cmake .. -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu but it doesn't help.

How to transfer python3-flask project into yocto image?

I am a beginner in yocto. Till now i have learnt about how to build a yocto image and add recipes through layers.openembedded. But i am not able to figure out e.g. i have developed a python3-flask project in my PC and then i want to copy/transfer that project into my yocto os. how can i do that? do i have to make something like executable of that project and then copy that into my os using some recipe?
I have seen this recipe but i am not able to understand what does LIC_FILES_CHSUM means and where to get it? where should i put these file e.g. setup.py? in the same directory as my .bb file?
and on building where my project would be copied in the yocto os?
DESCRIPTION = "Simple Python setuptools hello world application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://setup.py \
file://python-helloworld.py \
file://helloworld/__init__.py \
file://helloworld/main.py"
S = "${WORKDIR}"
inherit setuptools
do_install_append () {
install -d ${D}${bindir}
install -m 0755 python-helloworld.py ${D}${bindir}
}
The LICENSE field should obviously correspond to the license you picked for your SW. LIC_FILES_CHKSUM needs a file that holds the actual license defined in LICENSE and its md5sum passed as an "argument". It is just a way to monitor if the license ever changes. Then its md5sum changes and then the recipe fail to build because the license probably changed and requires the maintainer's attention.
THISDIR being the directory containing the recipe (not exactly but enough for the example), files in SRC_URI will be searched for in FILESPATH (which is first ${THISDIR}/<recipe_name>-<recipe_version> then ${THISDIR}/<recipe-name> then ${THISDIR}/files). So you need to put files (the ones starting with file://) declared in SRC_URI into one of those directories.
Best would actually to have your SW in a git repo somewhere. This better follows the philosophy of having SW source code separate from your build system (what if you decide you want to use a different build system later?).
When you're wondering what some variables or tasks are doing, I highly recommend looking them up on the mega manual: https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html. This works extremely well as a "dictionary". The documentation is great albeit dense and long but it is rare not to found what you look for as a beginner.
Update
LIC_FILES_CHKSUM can be found in yocto meta/files/common-licenses in the Source Directory. You can also take your own license and check the checksum with md5sum filename and copy that to bb file. If your SW is to be distributed, it is highly recommended to have the license mentioned somewhere in your sources. So better use that part of the code in LIC_FILES_CHKSUM than using the ones in ${COMMON_LICENSE_DIR} so that people will know if and when there is a license change in your project.
The below recipe works fine and you can find your app in /usr/bin directory.
DESCRIPTION = "Simple Python setuptools application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://setup.py \
file://packagetest.py \
file://example/__init__.py \
file://example/file1.py \
file://example/file2.py \
file://example/file3.py"
S = "${WORKDIR}"
inherit pypi setuptools3
do_install_append () {
install -d ${D}${bindir}
install -m 0755 packagetest.py ${D}${bindir}
}

How to use an own kernel configuration for a raspberry pi in yocto?

I like to remove some unused drivers for my RPI2 + custom board. For that I am creating an own configuration via:
bitbake linux-raspberrypi -c menuconfig
and save the new kernel preset to the file defconfig.
After this I created an append file for the linux-raspberryp recipe.
So I created the file
linux-raspberrypi%.bbappend
and filled it with:
FILESEXTRAPATHS_prepend := "${THISDIR}/linux-raspberrypi:"
SRC_URI += "file://defconfig"
PACKAGE_ARCH = "raspberrypi2"
I put the defconfig file to:
<meta-mylayer>/recipes-kernel/linux/linux-raspberrypi/raspberrypi2/defconfig
When recompiling the kernel via:
bitbake linux-raspberrypi -c clean
bitbake linux-raspberrypi
The standard RPI2 configuration is taken.
Any idea how to overcome this problem?
I am working on the "actual" pyro branch of meta-raspberrypi and yocto.
Well, unfortunately, the easiest way is probably to patch the kernel source... Or copy your defconfig over the in kernel-tree one.
The meta-raspberrypi layer does some unfortunate things in their kernel recipes, and even though this has become better with time, they're still not really nice...
If you take a look at recipes-kernel/linux/linux-raspberrypi.inc, the following lines explains the issue:
KERNEL_DEFCONFIG_raspberrypi2 ?= "bcm2709_defconfig"
do_kernel_configme_prepend() {
install -m 0644 ${S}/arch/${ARCH}/configs/${KERNEL_DEFCONFIG} ${WORKDIR}/defconfig || die "No default configuration for ${MACHINE} / ${KERNEL_DEFCONFIG} available."
}
Thus,they're copying the in-tree defconfig to ${WORKDIR}/defconfig, thereby overwriting your own defconfig.
You in you .bbappend, you could try to add:
do_kernel_configme_prepend() {
install -m 0644 ${WORKDIR}/defconfig ${S}/arch/${ARCH}/configs/${KERNEL_DEFCONFIG} || die "No default configuration for ${MACHINE} / ${KERNEL_DEFCONFIG} available."
}
Thus, first overwriting the in-kernel-tree one with your own defconfig.
Please take a look at how to use devtool to modify source code for the jethro:
http://www.yoctoproject.org/docs/2.0/dev-manual/dev-manual.html#using-devtool-in-your-workflow
I would start by having a fork at the git repository that it is using;
http://git.yoctoproject.org/cgit/cgit.cgi/meta-raspberrypi/tree/recipes-kernel/linux/linux-raspberrypi_4.9.bb
Using devtool in Yocto;
in your build directory: create a my-linux-raspberry folder;
mkdir linux-raspberry-test
devtool modify -x linux-raspberry ./my-linux-raspberry
This will put unpack the source code into my-linux-raspberry for you to modify; It also create the git repository in there;
Then, modify the code in my-linux-raspberry; To test build, run devtool build linux-raspberry; Once you are satisfied, add this git repository to your fork;
git add .
git commit -m "my-linux-raspberry"
devtool update-recipe linux-raspberry
Optional: run devtool reset linux-raspberry to remove the bbappend file;

How to add a new library using Yocto

I am using Yocto and I just would like to integrate a new library in my project.
I create a new recipe name "libxerces" which contains a file "libxerces-3.1.1.bb". The bb file is quite simple because it is based on autotools :
DESCRIPTION = "Xerces-c is a validating xml parser written in C++"
HOMEPAGE = "http://xerces.apache.org/xerces-c/"
PRIORITY = "optional"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57"
PR = "r1"
SRC_URI = "http://mirror.bit.edu.cn/apache//xerces/c/3/sources/xerces-c-${PV}.tar.gz"
s="${WORKDIR}/xerces-c-${PV}"
inherit autotools pkgconfig
SRC_URI[md5sum] = "6a8ec45d83c8cfb1584c5a5345cb51ae"
SRC_URI[sha256sum] = "a42785f71e0b91d5fd273831c87410ce60a73ccfdd207de1b805d26d44968736"
PACKAGES =+ "${PN}-utils"
FILES_${PN} = "${libdir}/*.so"
FILES_${PN}-utils = "${bindir}/*"
FILES_${PN}-staticdev = "${libdir}/*.a"*
BBCLASSEXTEND += "native"
I added "libxerces" to my bb image by using IMAGE_INSTALL += " libxerces". Then, I try to build my image thru bitbake my-image-test and eveything is done correctly but libxerces returns an error because it can not be installed. Howerver, I note that libxerces-dbg, libxerces-utils, libxerces-samples are visible under /tmp/work/deploy/ipk. I know that libxml2 is integrated by default into poky layer but I have to use xerces..
I solved the error
ERROR: Unable to install packages.
Collected errors:
* opkg_install_cmd: Cannot install package libxerces.
overriding the PACKAGES variable.
In your case:
PACKAGES = "${PN} ${PN}-utils ${PN}-staticdev"
I think that is because the .so files goes to ${PN}-dev package by default.
I hope there is a smarter solution, but for now I fixed in this way.
If you are building a library and the library offers static linking, you can control which static library files (*.a files) get included in the built library.
The PACKAGES and FILES_* variables in the meta/conf/bitbake.conf configuration file define how files installed by the do_install task are packaged. By default, the PACKAGES variable includes ${PN}-staticdev, which represents all static library files.
FILES_${PN}-staticdev ="" # for static libs
FILES_${PN}-dev ="" # for dynamic libs
FILES_${PN}-dbg ="" # for debug options
you need to add above line to your recipe

scons: how to extract archives depending on timestamps

My project uses external packages. These packages are distributed in tarball and their contents is extracted when the tarballs are updated.
For example, I use boost. The corresponding external package is boost.tar.bz2. This package contains the header files and libraries. What I would like to do is to automatically extract the contents of this archive with scons when the tarball is updated.
I can achieve this with a Makefile using a "timestamp file". When the tarball is newer than the timestamp file, the archive is automatically extracted:
all: external-packages
external-packages: boost xml2
boost: .boost-timestamp
xml2: .xml2-timestamp
.boost-timestamp: boost.tar.bz2
#echo updating boost externals
#tar xjf boost.tar.bz2
#touch .boost-timestamp
.xml2-timestamp: xml2.tar.bz2
#echo updating xml2 externals
#tar xjf xml2.tar.bz2
#touch .xml2-timestamp
clean:
rm -rf .*-timestamp boost xml2
How can I achieve the same with scons?
I think your best bet is to have a look at the untar builder.
After you add the addition of the builder function/emitter in your site_scons folder your scons file might look like this:
env = Environment()
env..Append(BUILDERS = {'UnTar' : unTarBuilder})
external_package = "packages/boost.tar.bz2"
archive = env.UnTar(source=external_package)
You should however note that the untar builder doesn't take directories into the emitter, and thus does not delete these on a clean
The point with this builder is the emitter it will make sure that SCons knows that it can create the headers, so whenever something depends on them (someone include them) it will launch the untar builder whenever the tar file has changed.

Resources