yocto-public/2-usage/recipecreate.md

104 lines
3.1 KiB
Markdown
Raw Permalink Normal View History

2015-07-21 12:22:25 +00:00
# Create a Recipe
## Creation
It may be better to use already existing recipes and customize them.
<info data-markdown>A recipe file must be named `<name>_<version>.bb` (lowercase only)</info>
<warn data-markdown>To be enabled, the recipe must be available in the `BBFILES` variable located in the `conf/layer.conf` file</warn>
Recipe skeleton
```sh
SUMMARY = ""
HOMEPAGE = ""
LICENSE = ""
LIC_FILES_CHKSUM = ""
# Source download URI
SRC_URI = ""
SRC_URI[md5sum] = ""
SRC_URI[sha256sum] = ""
# Source folder
S = "${WORKDIR}/${PN}-${PV}"
# Classes to use
inherit <classname>
# Task definition
do_compile() {
${CC} helloworld.c -o helloworld
}
```
## Configuration
### Variable list
|Variable|Content|
|---|---|
|`PN`| Recipe name |
|`PV`| Recipe version |
|`PR`| Recipe revision |
|`WORKDIR`| Directory where sources are extracted and the recipe is built |
|`SRCREV `| Commit hash, Tag or branch to checkout if the sources are a repository |
|`SRC_URI`| Files to download (new-line separated list) |
|`DEPENDS`| Recipe build-time dependency list |
|`RDEPENDS_${PN}`| Recipe run-time dependency list |
#### Function list
|Task/Function|Role|
|---|---|
|`do_unpack()`|Unpacks the downloaded source code to `${S}`.<br/>Automatically generated if the downloaded package is named `<recipe_name>-<recipe_version>.*`|
|`do_patch()`|Applies patches to source code.<br/>If `SRC_URI` contains a `.patch` or `.diff` file, it will automatically apply it to source code.|
|`do_configure()`|Configures the project (ie `./configure` for _Autotools_).<br/>Automatically generated if the project uses _Autotools_ or _CMake_. [More](http://www.yoctoproject.org/docs/1.8/dev-manual/dev-manual.html#new-recipe-configuring-the-recipe)|
|`do_compile()`|Commands to build the recipe<br/>Automatically generated for _Autotools_ or _CMake_|
|`do_install()`|Commands to install on the system (into `${D}${bindir}`)<br/>Automatically generated for _Autotools_ or _CMake_|
|` pkg_postinst_<RECIPENAME>()`|__Replace `<RECIPENAME>` with the recipe name__<br/>Contains the commands to execute after the package installation.<br/>`pkg_postinst_yolo(){`<br/>`#!/bin/sh -e`<br/>`cp A B`<br/>`}`|
### Useful classes
To use some Yocto tools in recipes, you may need to inherit some packages:
|Tool|Inheritance|
|---|---|
|Autotools|`inherit autotools gettext`|
|SysVInit|`inherit update-rc.d`|
[Full class list](http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#ref-classes)
## Enabling services
If `do_install()` exists in the recipe add code to the end of the function, else write a `do_install_append()` function that will contain the service initialization code.
[Details](http://www.yoctoproject.org/docs/1.8/dev-manual/dev-manual.html#new-recipe-enabling-system-services)
### SysVinit
You must add to the recipe:
```sh
inherit update-rc.d
# List of packages that contains initscripts
# Optional, default: ${PN}
#INITSCRIPT_PACKAGES
# Name of the init script installed in /etc/init.d
# Mandatory
INITSCRIPT_NAME = "${PN}"
# Parameters to pass to the init command
# Mandatory
INITSCRIPT_PARAMS = "start 99 5 2 . stop 20 0 1 6 ."
```
## Build the recipe
`bitbake <recipe_name>`