Yocto recipe : how to install in specific folder - embedded-linux

I have created a Yocto recipe for my program.
What are the default folders that are building image from recipe ?
At the time of building image, I want to move my files to another folder like "/opt/xyz".
Should I simply do "mv" or is there any other options?

I guess you want to copy your compiled program to a folder such as ${bindir}:
Quote from Yocto ref-manual 1.1:
When specifying paths as part of the CONFFILES variable, it is good practice to use appropriate path variables. For example, ${sysconfdir} rather than /etc or ${bindir} rather than /usr/bin. You can find a list of these variables at the top of the meta/conf/bitbake.conf file in the Source Directory.
You can copy files from your working directory to any directory in the target filesystem. See the hello-world example for instance (note that the example is taken from the 1.1 reference manual, but I haven't found it yet in the newer version):
DESCRIPTION = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "r0"
SRC_URI = "file://helloworld.c"
S = "${WORKDIR}"
do_compile() {
${CC} helloworld.c -o helloworld
}
do_install() {
install -d ${D}${bindir}
install -m 0755 helloworld ${D}${bindir}
}
FILES_${PN} = "${bindir}"
In this example, the helloworld binary would be copied to /usr/bin on your image (could be /opt too, see Source Directory for the variable definition).
Adjust FILES_${PN} var for ${sysconfdir} ${bindir} ${datadir} ${libdir} directories.

do_install(){
install -d ${D}{base_prefix}/opt/xyz/
install -m ${WORKDIR}/yourbinary ${D}${base_prefix}/opt/xyz/
}
FILES_${PN} = "${base_prefix}/opt/*"
above
1st line creates the dir in imagedir in that opt/xvz/
2nd line copy your binary to opt/xyz/dir
3rd line use to copy of your opt/xyz/binary to yocto rootfs.

Related

Where's the location of the app/binary defined in a yocto recipe?

I have a following recipe which runs a said service which in turns runs an app on boot-up, but I am trying to understand where the location of the app defined which ends up in sysfs image.
Currently, the appSource binary (defined in Makefile) gets stored in /usr/bin but I'm not sure where the destination location (/usr/bin) is defined.
The following command results in
$ bitbake -e appSource | grep ^FILES_${PN}
FILES_appSource="/usr/bin/* /usr/sbin/* /usr/libexec/* /usr/lib/lib*.so.* /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev /usr/lib/udev /lib/udev /usr/lib/udev
Here's the recipe
inherit autotools-brokensep pkgconfig
DESCRIPTION = "A sample recipe"
LICENSE = "CLOSED"
DEPENDS = "glib-2.0"
FILESPATH =+ "${THISDIR}:"
SRC_URI = "file://appSource"
S = "${WORKDIR}/appSource""
FILES_${PN} += "${systemd_unitdir}/*"
INIT_MANAGER = "systemd"
do_install_append() {
if ${#bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
install -d ${D}/etc/initscripts
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/appService/appService.service ${D}${systemd_unitdir}/system/appService.service
install -d ${D}${systemd_unitdir}/system/multi-user.target.wants/
ln -sf ${systemd_unitdir}/system/appService.service ${D}${systemd_unitdir}/system/multi-user.target.wants/appService.service
fi
}
Here is what I find out:
You are inheriting autotools-brokensep which has the following content:
# Autotools class for recipes where separate build dir doesn't work
# Ideally we should fix software so it does work. Standard autotools supports
# this.
inherit autotools
B = "${S}"
So, it inherit autotools which has do_install with the content of:
autotools_do_install() {
oe_runmake 'DESTDIR=${D}' install
# Info dir listing isn't interesting at this point so remove it if it exists.
if [ -e "${D}${infodir}/dir" ]; then
rm -f ${D}${infodir}/dir
fi
}
So, it runs the install target of your Makefile into ${D} which is ${WORKDIR}/image.
So, I assume that your Makefile has an install target that copies the binary into /usr/bin.
For the FILES variable content, this is defined in bitbake.conf:
FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ ...
Provide your Makefile to confirm my assumption, or I do a further research on the topic.

How to build Go + C code in Yocto, fetching the source code from files in the recipe

I'm having issues building Go + C code inside of Yocto.
I'm using Yocto gatesgarth, and the only way I can get it to work is by following the examples where they use git.
I do not want to use git for the fetching, just copy the files and build them. This is to allow me to try out changes, and also avoid dealing with source control revision.
How would you go about doing that?
Thanks!
Edit: I posted a solution bellow, I hope this will be useful.
I could not get it to work without overloading do_compile() and do_install(), but here it is.
DESCRIPTION = "The application code"
LICENSE = "CLOSED"
LIC_FILES_CHKSUM=""
SRC_URI = "file://build/streamerapp.go file://build/gstreamer_pipelines.c file://build/gstreamer_pipelines.h"
GO_IMPORT = "streamerapp"
GO_LINKSHARED = ""
PTEST_ENABLED="0"
export GO111MODULE="auto"
CGO_ENABLED = "1"
inherit go
do_compile() {
cd ${WORKDIR}/build
export TMPDIR="${GOTMPDIR}"
${GO} build ${GO_LINKSHARED} ${GOBUILDFLAGS} -o streamerapp
cd ${OLDPWD}
}
do_install() {
cd ${WORKDIR}/build
#install -m <permisions> SRC DEST
mkdir -p ${D}${bindir}
install -m 0755 ./streamerapp ${D}${bindir}
cd ${OLDPWD}
}

Copy scripts in MPC (Makefile, Project, and Workspace Creator)

In maintaining a project built with MPC (Makefile, Project, and Workspace Creator), I'd like to add a recipe to simply copy some scripts from one location to another.
If I were writing the makefile directly it would be easy: just add another line to the appropriate recipe. But I don't know how to do it with MPC.
I've tried variations of this code, but it creates a skeleton makefile which does nothing.
project(jsonscripts) : ecp {
Define_Custom(PHP) {
command = cp <%input%> scripts/
}
PHP_Files {
*.php
}
Source_Files {
}
}
Deleting the Source_Files or putting the php files into Source_Files creates a Makefile which tries to compile
the *.php files with gcc.
Any suggestions?
I could find no way to elegantly make it work. In the end, I added a postbuild command like this:
project(json) : ecp {
sharedname = someLibname
libpaths += $(LIBDIR)
libs += alib blib
Source_Files {
aa.cpp
bb.cpp
cc.cpp
}
postbuild = \
mkdir -p $(PROJHOME)/bin/util ; \
cp -v scriptA.php scriptB.php $(BIN)/util/ ; \
echo Scripts Copied to $(BIN)/util
}

How can I add a folder or file to the root in a recipe with bitbake?

I am trying to put a folder into the root of the filesystem. In the documentation (e.g. here) they use mostly variables and so the files and folders from SRC_URI result in being stored under /usr/bin or something but never in /.
So here is my recipe:
DESCRIPTION = "Example for adding files and folders to rootfs"
SRC_URI += "file://example_folder"
SRC_URI += "file://example_file"
LICENSE = [...]
do_install() {
install -d ${D}/rootfolder
cp -r ${WORKDIR}/example_folder ${D]/rootfolder/
install -m 0755 ${WORKDIR}/example_file ${D}/rootfolder
}
This is just one of very many do_install variants that I tried.Every of them resulted in either Error: example not found in the base feeds [...] or that the files and folders haven't been placed in the root but in /usr/bin as explained above.
In the cases were you get the error "Error: example not found in the base feeds [...]" it's quite likely that you actually have succeeded in building your recipe example.bb. Assuming of course, that you get that error when building your image, which has IMAGE_INSTALL += "example" in it.
If you install your files into /rootfolder, there's nothing in OE itself that knows how to package those files into an rpm, ipk, or deb package. You need to add that yourself to your recipe by adding a line like:
FILES_${PN} += "/rootfolder"
Doing that, your example above should work.
Depending on what files you install, you might want to add some of them to other packages like ${PN}-dbg, ${PN}-dev, etc.

How to have automake install headers file in a subdirectory of include

My current project has a couple files in its include/tatoparser directory that I would like to distribute along with my library.
qdii#nomada ~/MyProject $ ls include/tatoparser/
dataset.h interface_lib.h linkset.h sentence.h tagset.h
I created a Makefile.am that references those files:
qdii#nomada ~/MyProject $ cat include/Makefile.am
include_HEADERS = tatoparser/interface_lib.h tatoparser/sentence.h tatoparser/dataset.h tatoparser/tagset.h tatoparser/linkset.h
But when I run make install the referenced files get copied into /usr/include (or whatever $(includedir) was set to), and I want them copied in /usr/include/tatoparser.
How can I do that?
Use the nobase prefix to stop Automake from stripping the subdirectory path from the files:
nobase_include_HEADERS = tatoparser/interface_lib.h tatoparser/...

Resources