In this lesson, you will learn how to encapsulate your custom software into a Yocto recipe, enabling BitBake to automatically fetch, compile, and package your code into your embedded root filesystem.
The Anatomy of a Recipe
A recipe (.bb file) acts as a declarative instruction set for BitBake. Since Yocto doesn’t know where your source code lives or how to build it, the recipe provides that metadata. At a minimum, a recipe must define the source location (SRC_URI), the license, and the build logic.
For a simple C application, you typically inherit the base and bin_package classes or use the standard do_compile and do_install tasks. Here is a minimal example of a recipe named myapp_1.0.bb:
SUMMARY = "My Custom Application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0... "
SRC_URI = "file://main.c"
S = "${WORKDIR}"
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} main.c -o myapp
}
do_install() {
install -d ${D}${bindir}
install -m 0755 myapp ${D}${bindir}
}
From Compilation to Packaging
When you run bitbake myapp, BitBake moves through a series of tasks:
do_fetch: Retrieves the source (in this case, from your local directory).do_compile: Uses the cross-compiler defined in your toolchain to turn your C code into an executable compatible with your target architecture.do_install: Copies the final binary into a temporary staging area (${D}). We use${bindir}to ensure the binary is placed in/usr/binwithin the final root filesystem.do_package: Yocto takes the files staged indo_installand bundles them into a package (e.g., an.rpm,.deb, or.ipk), which is then ready to be included in your final image.
To actually include this in your system, you simply add the recipe name to the IMAGE_INSTALL variable in your local.conf or your custom image recipe. BitBake handles the dependency chain, ensuring the binary is injected into the root filesystem image during the final assembly phase.
Key Takeaway: A Yocto recipe defines the lifecycle of your software by mapping source code to standard build tasks, allowing BitBake to manage cross-compilation and automated deployment into your final image.