new-recipe.rst 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Writing a New Recipe
  3. ********************
  4. Recipes (``.bb`` files) are fundamental components in the Yocto Project
  5. environment. Each software component built by the OpenEmbedded build
  6. system requires a recipe to define the component. This section describes
  7. how to create, write, and test a new recipe.
  8. .. note::
  9. For information on variables that are useful for recipes and for
  10. information about recipe naming issues, see the
  11. ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
  12. Reference Manual.
  13. Overview
  14. ========
  15. The following figure shows the basic process for creating a new recipe.
  16. The remainder of the section provides details for the steps.
  17. .. image:: figures/recipe-workflow.png
  18. :align: center
  19. :width: 50%
  20. Locate or Automatically Create a Base Recipe
  21. ============================================
  22. You can always write a recipe from scratch. However, there are three choices
  23. that can help you quickly get started with a new recipe:
  24. - ``devtool add``: A command that assists in creating a recipe and an
  25. environment conducive to development.
  26. - ``recipetool create``: A command provided by the Yocto Project that
  27. automates creation of a base recipe based on the source files.
  28. - *Existing Recipes:* Location and modification of an existing recipe
  29. that is similar in function to the recipe you need.
  30. .. note::
  31. For information on recipe syntax, see the
  32. ":ref:`dev-manual/new-recipe:recipe syntax`" section.
  33. Creating the Base Recipe Using ``devtool add``
  34. ----------------------------------------------
  35. The ``devtool add`` command uses the same logic for auto-creating the
  36. recipe as ``recipetool create``, which is listed below. Additionally,
  37. however, ``devtool add`` sets up an environment that makes it easy for
  38. you to patch the source and to make changes to the recipe as is often
  39. necessary when adding a recipe to build a new piece of software to be
  40. included in a build.
  41. You can find a complete description of the ``devtool add`` command in
  42. the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
  43. in the Yocto Project Application Development and the Extensible Software
  44. Development Kit (eSDK) manual.
  45. Creating the Base Recipe Using ``recipetool create``
  46. ----------------------------------------------------
  47. ``recipetool create`` automates creation of a base recipe given a set of
  48. source code files. As long as you can extract or point to the source
  49. files, the tool will construct a recipe and automatically configure all
  50. pre-build information into the recipe. For example, suppose you have an
  51. application that builds using Autotools. Creating the base recipe using
  52. ``recipetool`` results in a recipe that has the pre-build dependencies,
  53. license requirements, and checksums configured.
  54. To run the tool, you just need to be in your :term:`Build Directory` and
  55. have sourced the build environment setup script (i.e.
  56. :ref:`structure-core-script`). To get help on the tool, use the following
  57. command::
  58. $ recipetool -h
  59. NOTE: Starting bitbake server...
  60. usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
  61. OpenEmbedded recipe tool
  62. options:
  63. -d, --debug Enable debug output
  64. -q, --quiet Print only errors
  65. --color COLOR Colorize output (where COLOR is auto, always, never)
  66. -h, --help show this help message and exit
  67. subcommands:
  68. create Create a new recipe
  69. newappend Create a bbappend for the specified target in the specified
  70. layer
  71. setvar Set a variable within a recipe
  72. appendfile Create/update a bbappend to replace a target file
  73. appendsrcfiles Create/update a bbappend to add or replace source files
  74. appendsrcfile Create/update a bbappend to add or replace a source file
  75. Use recipetool <subcommand> --help to get help on a specific command
  76. Running ``recipetool create -o OUTFILE`` creates the base recipe and
  77. locates it properly in the layer that contains your source files.
  78. Following are some syntax examples:
  79. - Use this syntax to generate a recipe based on source. Once generated,
  80. the recipe resides in the existing source code layer::
  81. recipetool create -o OUTFILE source
  82. - Use this syntax to generate a recipe using code that
  83. you extract from source. The extracted code is placed in its own layer
  84. defined by :term:`EXTERNALSRC`.
  85. ::
  86. recipetool create -o OUTFILE -x EXTERNALSRC source
  87. - Use this syntax to generate a recipe based on source. The options
  88. direct ``recipetool`` to generate debugging information. Once generated,
  89. the recipe resides in the existing source code layer::
  90. recipetool create -d -o OUTFILE source
  91. Locating and Using a Similar Recipe
  92. -----------------------------------
  93. Before writing a recipe from scratch, it is often useful to discover
  94. whether someone else has already written one that meets (or comes close
  95. to meeting) your needs. The Yocto Project and OpenEmbedded communities
  96. maintain many recipes that might be candidates for what you are doing.
  97. You can find a good central index of these recipes in the
  98. :oe_layerindex:`OpenEmbedded Layer Index <>`.
  99. Working from an existing recipe or a skeleton recipe is the best way to
  100. get started. Here are some points on both methods:
  101. - *Locate and modify a recipe that is close to what you want to do:*
  102. This method works when you are familiar with the current recipe
  103. space. The method does not work so well for those new to the Yocto
  104. Project or writing recipes.
  105. Some risks associated with this method are using a recipe that has
  106. areas totally unrelated to what you are trying to accomplish with
  107. your recipe, not recognizing areas of the recipe that you might have
  108. to add from scratch, and so forth. All these risks stem from
  109. unfamiliarity with the existing recipe space.
  110. - *Use and modify the following skeleton recipe:* If for some reason
  111. you do not want to use ``recipetool`` and you cannot find an existing
  112. recipe that is close to meeting your needs, you can use the following
  113. structure to provide the fundamental areas of a new recipe.
  114. ::
  115. DESCRIPTION = ""
  116. HOMEPAGE = ""
  117. LICENSE = ""
  118. SECTION = ""
  119. DEPENDS = ""
  120. LIC_FILES_CHKSUM = ""
  121. SRC_URI = ""
  122. Storing and Naming the Recipe
  123. =============================
  124. Once you have your base recipe, you should put it in your own layer and
  125. name it appropriately. Locating it correctly ensures that the
  126. OpenEmbedded build system can find it when you use BitBake to process
  127. the recipe.
  128. - *Storing Your Recipe:* The OpenEmbedded build system locates your
  129. recipe through the layer's ``conf/layer.conf`` file and the
  130. :term:`BBFILES` variable. This
  131. variable sets up a path from which the build system can locate
  132. recipes. Here is the typical use::
  133. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  134. ${LAYERDIR}/recipes-*/*/*.bbappend"
  135. Consequently, you need to be sure you locate your new recipe inside
  136. your layer such that it can be found.
  137. You can find more information on how layers are structured in the
  138. ":ref:`dev-manual/layers:understanding and creating layers`" section.
  139. - *Naming Your Recipe:* When you name your recipe, you need to follow
  140. this naming convention::
  141. basename_version.bb
  142. Use lower-cased characters and do not include the reserved suffixes
  143. ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
  144. them as part of your recipe name unless the string applies). Here are some
  145. examples:
  146. .. code-block:: none
  147. cups_1.7.0.bb
  148. gawk_4.0.2.bb
  149. irssi_0.8.16-rc1.bb
  150. Running a Build on the Recipe
  151. =============================
  152. Creating a new recipe is usually an iterative process that requires
  153. using BitBake to process the recipe multiple times in order to
  154. progressively discover and add information to the recipe file.
  155. Assuming you have sourced the build environment setup script (i.e.
  156. :ref:`structure-core-script`) and you are in the :term:`Build Directory`, use
  157. BitBake to process your recipe. All you need to provide is the
  158. ``basename`` of the recipe as described in the previous section::
  159. $ bitbake basename
  160. During the build, the OpenEmbedded build system creates a temporary work
  161. directory for each recipe
  162. (``${``\ :term:`WORKDIR`\ ``}``)
  163. where it keeps extracted source files, log files, intermediate
  164. compilation and packaging files, and so forth.
  165. The path to the per-recipe temporary work directory depends on the
  166. context in which it is being built. The quickest way to find this path
  167. is to have BitBake return it by running the following::
  168. $ bitbake -e basename | grep ^WORKDIR=
  169. As an example, assume a Source Directory
  170. top-level folder named ``poky``, a default :term:`Build Directory` at
  171. ``poky/build``, and a ``qemux86-poky-linux`` machine target system.
  172. Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
  173. case, the work directory the build system uses to build the package
  174. would be as follows::
  175. poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
  176. Inside this directory you can find sub-directories such as ``image``,
  177. ``packages-split``, and ``temp``. After the build, you can examine these
  178. to determine how well the build went.
  179. .. note::
  180. You can find log files for each task in the recipe's ``temp``
  181. directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
  182. Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
  183. ``log.do_fetch``, and ``log.do_compile``).
  184. You can find more information about the build process in
  185. ":doc:`/overview-manual/development-environment`"
  186. chapter of the Yocto Project Overview and Concepts Manual.
  187. Fetching Code
  188. =============
  189. The first thing your recipe must do is specify how to fetch the source
  190. files. Fetching is controlled mainly through the
  191. :term:`SRC_URI` variable. Your recipe
  192. must have a :term:`SRC_URI` variable that points to where the source is
  193. located. For a graphical representation of source locations, see the
  194. ":ref:`overview-manual/concepts:sources`" section in
  195. the Yocto Project Overview and Concepts Manual.
  196. The :ref:`ref-tasks-fetch` task uses
  197. the prefix of each entry in the :term:`SRC_URI` variable value to determine
  198. which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
  199. source files. It is the :term:`SRC_URI` variable that triggers the fetcher.
  200. The :ref:`ref-tasks-patch` task uses
  201. the variable after source is fetched to apply patches. The OpenEmbedded
  202. build system uses
  203. :term:`FILESOVERRIDES` for
  204. scanning directory locations for local files in :term:`SRC_URI`.
  205. The :term:`SRC_URI` variable in your recipe must define each unique location
  206. for your source files. It is good practice to not hard-code version
  207. numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these
  208. values, use ``${``\ :term:`PV`\ ``}``,
  209. which causes the fetch process to use the version specified in the
  210. recipe filename. Specifying the version in this manner means that
  211. upgrading the recipe to a future version is as simple as renaming the
  212. recipe to match the new version.
  213. Here is a simple example from the
  214. ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
  215. comes from a single tarball. Notice the use of the
  216. :term:`PV` variable::
  217. SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
  218. Files mentioned in :term:`SRC_URI` whose names end in a typical archive
  219. extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
  220. forth), are automatically extracted during the
  221. :ref:`ref-tasks-unpack` task. For
  222. another example that specifies these types of files, see the
  223. ":ref:`dev-manual/new-recipe:autotooled package`" section.
  224. Another way of specifying source is from an SCM. For Git repositories,
  225. you must specify :term:`SRCREV` and you should specify :term:`PV` to include
  226. the revision with :term:`SRCPV`. Here is an example from the recipe
  227. ``meta/recipes-core/musl/gcompat_git.bb``::
  228. SRC_URI = "git://git.adelielinux.org/adelie/gcompat.git;protocol=https;branch=current"
  229. PV = "1.0.0+1.1+git${SRCPV}"
  230. SRCREV = "af5a49e489fdc04b9cf02547650d7aeaccd43793"
  231. If your :term:`SRC_URI` statement includes URLs pointing to individual files
  232. fetched from a remote server other than a version control system,
  233. BitBake attempts to verify the files against checksums defined in your
  234. recipe to ensure they have not been tampered with or otherwise modified
  235. since the recipe was written. Two checksums are used:
  236. ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
  237. If your :term:`SRC_URI` variable points to more than a single URL (excluding
  238. SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
  239. each URL. For these cases, you provide a name for each URL as part of
  240. the :term:`SRC_URI` and then reference that name in the subsequent checksum
  241. statements. Here is an example combining lines from the files
  242. ``git.inc`` and ``git_2.24.1.bb``::
  243. SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
  244. ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
  245. SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
  246. SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
  247. SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
  248. SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
  249. Proper values for ``md5`` and ``sha256`` checksums might be available
  250. with other signatures on the download page for the upstream source (e.g.
  251. ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
  252. OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
  253. you should verify all the signatures you find by hand.
  254. If no :term:`SRC_URI` checksums are specified when you attempt to build the
  255. recipe, or you provide an incorrect checksum, the build will produce an
  256. error for each missing or incorrect checksum. As part of the error
  257. message, the build system provides the checksum string corresponding to
  258. the fetched file. Once you have the correct checksums, you can copy and
  259. paste them into your recipe and then run the build again to continue.
  260. .. note::
  261. As mentioned, if the upstream source provides signatures for
  262. verifying the downloaded source code, you should verify those
  263. manually before setting the checksum values in the recipe and
  264. continuing with the build.
  265. This final example is a bit more complicated and is from the
  266. ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
  267. example's :term:`SRC_URI` statement identifies multiple files as the source
  268. files for the recipe: a tarball, a patch file, a desktop file, and an
  269. icon.
  270. ::
  271. SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
  272. file://xwc.patch \
  273. file://rxvt.desktop \
  274. file://rxvt.png"
  275. When you specify local files using the ``file://`` URI protocol, the
  276. build system fetches files from the local machine. The path is relative
  277. to the :term:`FILESPATH` variable
  278. and searches specific directories in a certain order:
  279. ``${``\ :term:`BP`\ ``}``,
  280. ``${``\ :term:`BPN`\ ``}``, and
  281. ``files``. The directories are assumed to be subdirectories of the
  282. directory in which the recipe or append file resides. For another
  283. example that specifies these types of files, see the
  284. ":ref:`dev-manual/new-recipe:single .c file package (hello world!)`" section.
  285. The previous example also specifies a patch file. Patch files are files
  286. whose names usually end in ``.patch`` or ``.diff`` but can end with
  287. compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
  288. The build system automatically applies patches as described in the
  289. ":ref:`dev-manual/new-recipe:patching code`" section.
  290. Fetching Code Through Firewalls
  291. -------------------------------
  292. Some users are behind firewalls and need to fetch code through a proxy.
  293. See the ":doc:`/ref-manual/faq`" chapter for advice.
  294. Limiting the Number of Parallel Connections
  295. -------------------------------------------
  296. Some users are behind firewalls or use servers where the number of parallel
  297. connections is limited. In such cases, you can limit the number of fetch
  298. tasks being run in parallel by adding the following to your ``local.conf``
  299. file::
  300. do_fetch[number_threads] = "4"
  301. Unpacking Code
  302. ==============
  303. During the build, the
  304. :ref:`ref-tasks-unpack` task unpacks
  305. the source with ``${``\ :term:`S`\ ``}``
  306. pointing to where it is unpacked.
  307. If you are fetching your source files from an upstream source archived
  308. tarball and the tarball's internal structure matches the common
  309. convention of a top-level subdirectory named
  310. ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
  311. then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to
  312. fetch source from an archive that does not use this convention, or from
  313. an SCM like Git or Subversion, your recipe needs to define :term:`S`.
  314. If processing your recipe using BitBake successfully unpacks the source
  315. files, you need to be sure that the directory pointed to by ``${S}``
  316. matches the structure of the source.
  317. Patching Code
  318. =============
  319. Sometimes it is necessary to patch code after it has been fetched. Any
  320. files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or
  321. ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
  322. treated as patches. The
  323. :ref:`ref-tasks-patch` task
  324. automatically applies these patches.
  325. The build system should be able to apply patches with the "-p1" option
  326. (i.e. one directory level in the path will be stripped off). If your
  327. patch needs to have more directory levels stripped off, specify the
  328. number of levels using the "striplevel" option in the :term:`SRC_URI` entry
  329. for the patch. Alternatively, if your patch needs to be applied in a
  330. specific subdirectory that is not specified in the patch file, use the
  331. "patchdir" option in the entry.
  332. As with all local files referenced in
  333. :term:`SRC_URI` using ``file://``,
  334. you should place patch files in a directory next to the recipe either
  335. named the same as the base name of the recipe
  336. (:term:`BP` and
  337. :term:`BPN`) or "files".
  338. Licensing
  339. =========
  340. Your recipe needs to have both the
  341. :term:`LICENSE` and
  342. :term:`LIC_FILES_CHKSUM`
  343. variables:
  344. - :term:`LICENSE`: This variable specifies the license for the software.
  345. If you do not know the license under which the software you are
  346. building is distributed, you should go to the source code and look
  347. for that information. Typical files containing this information
  348. include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could
  349. also find the information near the top of a source file. For example,
  350. given a piece of software licensed under the GNU General Public
  351. License version 2, you would set :term:`LICENSE` as follows::
  352. LICENSE = "GPL-2.0-only"
  353. The licenses you specify within :term:`LICENSE` can have any name as long
  354. as you do not use spaces, since spaces are used as separators between
  355. license names. For standard licenses, use the names of the files in
  356. ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names
  357. defined in ``meta/conf/licenses.conf``.
  358. - :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this
  359. variable to make sure the license text has not changed. If it has,
  360. the build produces an error and it affords you the chance to figure
  361. it out and correct the problem.
  362. You need to specify all applicable licensing files for the software.
  363. At the end of the configuration step, the build process will compare
  364. the checksums of the files to be sure the text has not changed. Any
  365. differences result in an error with the message containing the
  366. current checksum. For more explanation and examples of how to set the
  367. :term:`LIC_FILES_CHKSUM` variable, see the
  368. ":ref:`dev-manual/licenses:tracking license changes`" section.
  369. To determine the correct checksum string, you can list the
  370. appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect
  371. md5 strings, attempt to build the software, and then note the
  372. resulting error messages that will report the correct md5 strings.
  373. See the ":ref:`dev-manual/new-recipe:fetching code`" section for
  374. additional information.
  375. Here is an example that assumes the software has a ``COPYING`` file::
  376. LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
  377. When you try to build the
  378. software, the build system will produce an error and give you the
  379. correct string that you can substitute into the recipe file for a
  380. subsequent build.
  381. Dependencies
  382. ============
  383. Most software packages have a short list of other packages that they
  384. require, which are called dependencies. These dependencies fall into two
  385. main categories: build-time dependencies, which are required when the
  386. software is built; and runtime dependencies, which are required to be
  387. installed on the target in order for the software to run.
  388. Within a recipe, you specify build-time dependencies using the
  389. :term:`DEPENDS` variable. Although there are nuances,
  390. items specified in :term:`DEPENDS` should be names of other
  391. recipes. It is important that you specify all build-time dependencies
  392. explicitly.
  393. Another consideration is that configure scripts might automatically
  394. check for optional dependencies and enable corresponding functionality
  395. if those dependencies are found. If you wish to make a recipe that is
  396. more generally useful (e.g. publish the recipe in a layer for others to
  397. use), instead of hard-disabling the functionality, you can use the
  398. :term:`PACKAGECONFIG` variable to allow functionality and the
  399. corresponding dependencies to be enabled and disabled easily by other
  400. users of the recipe.
  401. Similar to build-time dependencies, you specify runtime dependencies
  402. through a variable -
  403. :term:`RDEPENDS`, which is
  404. package-specific. All variables that are package-specific need to have
  405. the name of the package added to the end as an override. Since the main
  406. package for a recipe has the same name as the recipe, and the recipe's
  407. name can be found through the
  408. ``${``\ :term:`PN`\ ``}`` variable, then
  409. you specify the dependencies for the main package by setting
  410. ``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you
  411. would set ``RDEPENDS:${PN}-tools``, and so forth.
  412. Some runtime dependencies will be set automatically at packaging time.
  413. These dependencies include any shared library dependencies (i.e. if a
  414. package "example" contains "libexample" and another package "mypackage"
  415. contains a binary that links to "libexample" then the OpenEmbedded build
  416. system will automatically add a runtime dependency to "mypackage" on
  417. "example"). See the
  418. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  419. section in the Yocto Project Overview and Concepts Manual for further
  420. details.
  421. Configuring the Recipe
  422. ======================
  423. Most software provides some means of setting build-time configuration
  424. options before compilation. Typically, setting these options is
  425. accomplished by running a configure script with options, or by modifying
  426. a build configuration file.
  427. .. note::
  428. As of Yocto Project Release 1.7, some of the core recipes that
  429. package binary configuration scripts now disable the scripts due to
  430. the scripts previously requiring error-prone path substitution. The
  431. OpenEmbedded build system uses ``pkg-config`` now, which is much more
  432. robust. You can find a list of the ``*-config`` scripts that are disabled
  433. in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
  434. in the Yocto Project Reference Manual.
  435. A major part of build-time configuration is about checking for
  436. build-time dependencies and possibly enabling optional functionality as
  437. a result. You need to specify any build-time dependencies for the
  438. software you are building in your recipe's
  439. :term:`DEPENDS` value, in terms of
  440. other recipes that satisfy those dependencies. You can often find
  441. build-time or runtime dependencies described in the software's
  442. documentation.
  443. The following list provides configuration items of note based on how
  444. your software is built:
  445. - *Autotools:* If your source files have a ``configure.ac`` file, then
  446. your software is built using Autotools. If this is the case, you just
  447. need to modify the configuration.
  448. When using Autotools, your recipe needs to inherit the
  449. :ref:`autotools <ref-classes-autotools>` class and it does not have to
  450. contain a :ref:`ref-tasks-configure` task. However, you might still want to
  451. make some adjustments. For example, you can set :term:`EXTRA_OECONF` or
  452. :term:`PACKAGECONFIG_CONFARGS` to pass any needed configure options that
  453. are specific to the recipe.
  454. - *CMake:* If your source files have a ``CMakeLists.txt`` file, then
  455. your software is built using CMake. If this is the case, you just
  456. need to modify the configuration.
  457. When you use CMake, your recipe needs to inherit the
  458. :ref:`cmake <ref-classes-cmake>` class and it does not have to contain a
  459. :ref:`ref-tasks-configure` task. You can make some adjustments by setting
  460. :term:`EXTRA_OECMAKE` to pass any needed configure options that are
  461. specific to the recipe.
  462. .. note::
  463. If you need to install one or more custom CMake toolchain files
  464. that are supplied by the application you are building, install the
  465. files to ``${D}${datadir}/cmake/Modules`` during :ref:`ref-tasks-install`.
  466. - *Other:* If your source files do not have a ``configure.ac`` or
  467. ``CMakeLists.txt`` file, then your software is built using some
  468. method other than Autotools or CMake. If this is the case, you
  469. normally need to provide a
  470. :ref:`ref-tasks-configure` task
  471. in your recipe unless, of course, there is nothing to configure.
  472. Even if your software is not being built by Autotools or CMake, you
  473. still might not need to deal with any configuration issues. You need
  474. to determine if configuration is even a required step. You might need
  475. to modify a Makefile or some configuration file used for the build to
  476. specify necessary build options. Or, perhaps you might need to run a
  477. provided, custom configure script with the appropriate options.
  478. For the case involving a custom configure script, you would run
  479. ``./configure --help`` and look for the options you need to set.
  480. Once configuration succeeds, it is always good practice to look at the
  481. ``log.do_configure`` file to ensure that the appropriate options have
  482. been enabled and no additional build-time dependencies need to be added
  483. to :term:`DEPENDS`. For example, if the configure script reports that it
  484. found something not mentioned in :term:`DEPENDS`, or that it did not find
  485. something that it needed for some desired optional functionality, then
  486. you would need to add those to :term:`DEPENDS`. Looking at the log might
  487. also reveal items being checked for, enabled, or both that you do not
  488. want, or items not being found that are in :term:`DEPENDS`, in which case
  489. you would need to look at passing extra options to the configure script
  490. as needed. For reference information on configure options specific to
  491. the software you are building, you can consult the output of the
  492. ``./configure --help`` command within ``${S}`` or consult the software's
  493. upstream documentation.
  494. Using Headers to Interface with Devices
  495. =======================================
  496. If your recipe builds an application that needs to communicate with some
  497. device or needs an API into a custom kernel, you will need to provide
  498. appropriate header files. Under no circumstances should you ever modify
  499. the existing
  500. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
  501. These headers are used to build ``libc`` and must not be compromised
  502. with custom or machine-specific header information. If you customize
  503. ``libc`` through modified headers all other applications that use
  504. ``libc`` thus become affected.
  505. .. note::
  506. Never copy and customize the ``libc`` header file (i.e.
  507. ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
  508. The correct way to interface to a device or custom kernel is to use a
  509. separate package that provides the additional headers for the driver or
  510. other unique interfaces. When doing so, your application also becomes
  511. responsible for creating a dependency on that specific provider.
  512. Consider the following:
  513. - Never modify ``linux-libc-headers.inc``. Consider that file to be
  514. part of the ``libc`` system, and not something you use to access the
  515. kernel directly. You should access ``libc`` through specific ``libc``
  516. calls.
  517. - Applications that must talk directly to devices should either provide
  518. necessary headers themselves, or establish a dependency on a special
  519. headers package that is specific to that driver.
  520. For example, suppose you want to modify an existing header that adds I/O
  521. control or network support. If the modifications are used by a small
  522. number programs, providing a unique version of a header is easy and has
  523. little impact. When doing so, bear in mind the guidelines in the
  524. previous list.
  525. .. note::
  526. If for some reason your changes need to modify the behavior of the ``libc``,
  527. and subsequently all other applications on the system, use a ``.bbappend``
  528. to modify the ``linux-kernel-headers.inc`` file. However, take care to not
  529. make the changes machine specific.
  530. Consider a case where your kernel is older and you need an older
  531. ``libc`` ABI. The headers installed by your recipe should still be a
  532. standard mainline kernel, not your own custom one.
  533. When you use custom kernel headers you need to get them from
  534. :term:`STAGING_KERNEL_DIR`,
  535. which is the directory with kernel headers that are required to build
  536. out-of-tree modules. Your recipe will also need the following::
  537. do_configure[depends] += "virtual/kernel:do_shared_workdir"
  538. Compilation
  539. ===========
  540. During a build, the :ref:`ref-tasks-compile` task happens after source is fetched,
  541. unpacked, and configured. If the recipe passes through :ref:`ref-tasks-compile`
  542. successfully, nothing needs to be done.
  543. However, if the compile step fails, you need to diagnose the failure.
  544. Here are some common issues that cause failures.
  545. .. note::
  546. For cases where improper paths are detected for configuration files
  547. or for when libraries/headers cannot be found, be sure you are using
  548. the more robust ``pkg-config``. See the note in section
  549. ":ref:`dev-manual/new-recipe:Configuring the Recipe`" for additional information.
  550. - *Parallel build failures:* These failures manifest themselves as
  551. intermittent errors, or errors reporting that a file or directory
  552. that should be created by some other part of the build process could
  553. not be found. This type of failure can occur even if, upon
  554. inspection, the file or directory does exist after the build has
  555. failed, because that part of the build process happened in the wrong
  556. order.
  557. To fix the problem, you need to either satisfy the missing dependency
  558. in the Makefile or whatever script produced the Makefile, or (as a
  559. workaround) set :term:`PARALLEL_MAKE` to an empty string::
  560. PARALLEL_MAKE = ""
  561. For information on parallel Makefile issues, see the
  562. ":ref:`dev-manual/debugging:debugging parallel make races`" section.
  563. - *Improper host path usage:* This failure applies to recipes building
  564. for the target or ":ref:`nativesdk <ref-classes-nativesdk>`" only. The
  565. failure occurs when the compilation process uses improper headers,
  566. libraries, or other files from the host system when cross-compiling for
  567. the target.
  568. To fix the problem, examine the ``log.do_compile`` file to identify
  569. the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
  570. so forth) and then either add configure options, apply a patch, or do
  571. both.
  572. - *Failure to find required libraries/headers:* If a build-time
  573. dependency is missing because it has not been declared in
  574. :term:`DEPENDS`, or because the
  575. dependency exists but the path used by the build process to find the
  576. file is incorrect and the configure step did not detect it, the
  577. compilation process could fail. For either of these failures, the
  578. compilation process notes that files could not be found. In these
  579. cases, you need to go back and add additional options to the
  580. configure script as well as possibly add additional build-time
  581. dependencies to :term:`DEPENDS`.
  582. Occasionally, it is necessary to apply a patch to the source to
  583. ensure the correct paths are used. If you need to specify paths to
  584. find files staged into the sysroot from other recipes, use the
  585. variables that the OpenEmbedded build system provides (e.g.
  586. :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so
  587. forth).
  588. Installing
  589. ==========
  590. During :ref:`ref-tasks-install`, the task copies the built files along with their
  591. hierarchy to locations that would mirror their locations on the target
  592. device. The installation process copies files from the
  593. ``${``\ :term:`S`\ ``}``,
  594. ``${``\ :term:`B`\ ``}``, and
  595. ``${``\ :term:`WORKDIR`\ ``}``
  596. directories to the ``${``\ :term:`D`\ ``}``
  597. directory to create the structure as it should appear on the target
  598. system.
  599. How your software is built affects what you must do to be sure your
  600. software is installed correctly. The following list describes what you
  601. must do for installation depending on the type of build system used by
  602. the software being built:
  603. - *Autotools and CMake:* If the software your recipe is building uses
  604. Autotools or CMake, the OpenEmbedded build system understands how to
  605. install the software. Consequently, you do not have to have a
  606. :ref:`ref-tasks-install` task as part of your recipe. You just need to make
  607. sure the install portion of the build completes with no issues.
  608. However, if you wish to install additional files not already being
  609. installed by ``make install``, you should do this using a
  610. ``do_install:append`` function using the install command as described
  611. in the "Manual" bulleted item later in this list.
  612. - *Other (using* ``make install``\ *)*: You need to define a :ref:`ref-tasks-install`
  613. function in your recipe. The function should call
  614. ``oe_runmake install`` and will likely need to pass in the
  615. destination directory as well. How you pass that path is dependent on
  616. how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
  617. ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
  618. For an example recipe using ``make install``, see the
  619. ":ref:`dev-manual/new-recipe:makefile-based package`" section.
  620. - *Manual:* You need to define a :ref:`ref-tasks-install` function in your
  621. recipe. The function must first use ``install -d`` to create the
  622. directories under
  623. ``${``\ :term:`D`\ ``}``. Once the
  624. directories exist, your function can use ``install`` to manually
  625. install the built software into the directories.
  626. You can find more information on ``install`` at
  627. https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
  628. For the scenarios that do not use Autotools or CMake, you need to track
  629. the installation and diagnose and fix any issues until everything
  630. installs correctly. You need to look in the default location of
  631. ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
  632. installed correctly.
  633. .. note::
  634. - During the installation process, you might need to modify some of
  635. the installed files to suit the target layout. For example, you
  636. might need to replace hard-coded paths in an initscript with
  637. values of variables provided by the build system, such as
  638. replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
  639. modifications during :ref:`ref-tasks-install`, be sure to modify the
  640. destination file after copying rather than before copying.
  641. Modifying after copying ensures that the build system can
  642. re-execute :ref:`ref-tasks-install` if needed.
  643. - ``oe_runmake install``, which can be run directly or can be run
  644. indirectly by the
  645. :ref:`autotools <ref-classes-autotools>` and
  646. :ref:`cmake <ref-classes-cmake>` classes,
  647. runs ``make install`` in parallel. Sometimes, a Makefile can have
  648. missing dependencies between targets that can result in race
  649. conditions. If you experience intermittent failures during
  650. :ref:`ref-tasks-install`, you might be able to work around them by disabling
  651. parallel Makefile installs by adding the following to the recipe::
  652. PARALLEL_MAKEINST = ""
  653. See :term:`PARALLEL_MAKEINST` for additional information.
  654. - If you need to install one or more custom CMake toolchain files
  655. that are supplied by the application you are building, install the
  656. files to ``${D}${datadir}/cmake/Modules`` during
  657. :ref:`ref-tasks-install`.
  658. Enabling System Services
  659. ========================
  660. If you want to install a service, which is a process that usually starts
  661. on boot and runs in the background, then you must include some
  662. additional definitions in your recipe.
  663. If you are adding services and the service initialization script or the
  664. service file itself is not installed, you must provide for that
  665. installation in your recipe using a ``do_install:append`` function. If
  666. your recipe already has a :ref:`ref-tasks-install` function, update the function
  667. near its end rather than adding an additional ``do_install:append``
  668. function.
  669. When you create the installation for your services, you need to
  670. accomplish what is normally done by ``make install``. In other words,
  671. make sure your installation arranges the output similar to how it is
  672. arranged on the target system.
  673. The OpenEmbedded build system provides support for starting services two
  674. different ways:
  675. - *SysVinit:* SysVinit is a system and service manager that manages the
  676. init system used to control the very basic functions of your system.
  677. The init program is the first program started by the Linux kernel
  678. when the system boots. Init then controls the startup, running and
  679. shutdown of all other programs.
  680. To enable a service using SysVinit, your recipe needs to inherit the
  681. :ref:`update-rc.d <ref-classes-update-rc.d>` class. The class helps
  682. facilitate safely installing the package on the target.
  683. You will need to set the
  684. :term:`INITSCRIPT_PACKAGES`,
  685. :term:`INITSCRIPT_NAME`,
  686. and
  687. :term:`INITSCRIPT_PARAMS`
  688. variables within your recipe.
  689. - *systemd:* System Management Daemon (systemd) was designed to replace
  690. SysVinit and to provide enhanced management of services. For more
  691. information on systemd, see the systemd homepage at
  692. https://freedesktop.org/wiki/Software/systemd/.
  693. To enable a service using systemd, your recipe needs to inherit the
  694. :ref:`systemd <ref-classes-systemd>` class. See the ``systemd.bbclass`` file
  695. located in your :term:`Source Directory` section for more information.
  696. Packaging
  697. =========
  698. Successful packaging is a combination of automated processes performed
  699. by the OpenEmbedded build system and some specific steps you need to
  700. take. The following list describes the process:
  701. - *Splitting Files*: The :ref:`ref-tasks-package` task splits the files produced
  702. by the recipe into logical components. Even software that produces a
  703. single binary might still have debug symbols, documentation, and
  704. other logical components that should be split out. The :ref:`ref-tasks-package`
  705. task ensures that files are split up and packaged correctly.
  706. - *Running QA Checks*: The
  707. :ref:`insane <ref-classes-insane>` class adds a
  708. step to the package generation process so that output quality
  709. assurance checks are generated by the OpenEmbedded build system. This
  710. step performs a range of checks to be sure the build's output is free
  711. of common problems that show up during runtime. For information on
  712. these checks, see the
  713. :ref:`insane <ref-classes-insane>` class and
  714. the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
  715. chapter in the Yocto Project Reference Manual.
  716. - *Hand-Checking Your Packages*: After you build your software, you
  717. need to be sure your packages are correct. Examine the
  718. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  719. directory and make sure files are where you expect them to be. If you
  720. discover problems, you can set
  721. :term:`PACKAGES`,
  722. :term:`FILES`,
  723. ``do_install(:append)``, and so forth as needed.
  724. - *Splitting an Application into Multiple Packages*: If you need to
  725. split an application into several packages, see the
  726. ":ref:`dev-manual/new-recipe:splitting an application into multiple packages`"
  727. section for an example.
  728. - *Installing a Post-Installation Script*: For an example showing how
  729. to install a post-installation script, see the
  730. ":ref:`dev-manual/new-recipe:post-installation scripts`" section.
  731. - *Marking Package Architecture*: Depending on what your recipe is
  732. building and how it is configured, it might be important to mark the
  733. packages produced as being specific to a particular machine, or to
  734. mark them as not being specific to a particular machine or
  735. architecture at all.
  736. By default, packages apply to any machine with the same architecture
  737. as the target machine. When a recipe produces packages that are
  738. machine-specific (e.g. the
  739. :term:`MACHINE` value is passed
  740. into the configure script or a patch is applied only for a particular
  741. machine), you should mark them as such by adding the following to the
  742. recipe::
  743. PACKAGE_ARCH = "${MACHINE_ARCH}"
  744. On the other hand, if the recipe produces packages that do not
  745. contain anything specific to the target machine or architecture at
  746. all (e.g. recipes that simply package script files or configuration
  747. files), you should use the
  748. :ref:`allarch <ref-classes-allarch>` class to
  749. do this for you by adding this to your recipe::
  750. inherit allarch
  751. Ensuring that the package architecture is correct is not critical
  752. while you are doing the first few builds of your recipe. However, it
  753. is important in order to ensure that your recipe rebuilds (or does
  754. not rebuild) appropriately in response to changes in configuration,
  755. and to ensure that you get the appropriate packages installed on the
  756. target machine, particularly if you run separate builds for more than
  757. one target machine.
  758. Sharing Files Between Recipes
  759. =============================
  760. Recipes often need to use files provided by other recipes on the build
  761. host. For example, an application linking to a common library needs
  762. access to the library itself and its associated headers. The way this
  763. access is accomplished is by populating a sysroot with files. Each
  764. recipe has two sysroots in its work directory, one for target files
  765. (``recipe-sysroot``) and one for files that are native to the build host
  766. (``recipe-sysroot-native``).
  767. .. note::
  768. You could find the term "staging" used within the Yocto project
  769. regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
  770. variable).
  771. Recipes should never populate the sysroot directly (i.e. write files
  772. into sysroot). Instead, files should be installed into standard
  773. locations during the
  774. :ref:`ref-tasks-install` task within
  775. the ``${``\ :term:`D`\ ``}`` directory. The
  776. reason for this limitation is that almost all files that populate the
  777. sysroot are cataloged in manifests in order to ensure the files can be
  778. removed later when a recipe is either modified or removed. Thus, the
  779. sysroot is able to remain free from stale files.
  780. A subset of the files installed by the :ref:`ref-tasks-install` task are
  781. used by the :ref:`ref-tasks-populate_sysroot` task as defined by the
  782. :term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
  783. is possible to modify the list of directories that populate the sysroot.
  784. The following example shows how you could add the ``/opt`` directory to
  785. the list of directories within a recipe::
  786. SYSROOT_DIRS += "/opt"
  787. .. note::
  788. The `/sysroot-only` is to be used by recipes that generate artifacts
  789. that are not included in the target filesystem, allowing them to share
  790. these artifacts without needing to use the :term:`DEPLOY_DIR`.
  791. For a more complete description of the :ref:`ref-tasks-populate_sysroot`
  792. task and its associated functions, see the
  793. :ref:`staging <ref-classes-staging>` class.
  794. Using Virtual Providers
  795. =======================
  796. Prior to a build, if you know that several different recipes provide the
  797. same functionality, you can use a virtual provider (i.e. ``virtual/*``)
  798. as a placeholder for the actual provider. The actual provider is
  799. determined at build-time.
  800. A common scenario where a virtual provider is used would be for the
  801. kernel recipe. Suppose you have three kernel recipes whose
  802. :term:`PN` values map to ``kernel-big``,
  803. ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
  804. in some way uses a :term:`PROVIDES`
  805. statement that essentially identifies itself as being able to provide
  806. ``virtual/kernel``. Here is one way through the
  807. :ref:`kernel <ref-classes-kernel>` class::
  808. PROVIDES += "virtual/kernel"
  809. Any recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is
  810. going to utilize a :term:`PROVIDES` statement that identifies that recipe as
  811. being able to provide the ``virtual/kernel`` item.
  812. Now comes the time to actually build an image and you need a kernel
  813. recipe, but which one? You can configure your build to call out the
  814. kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
  815. an example, consider the :yocto_git:`x86-base.inc
  816. </poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a
  817. machine (i.e. :term:`MACHINE`) configuration file. This include file is the
  818. reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
  819. relevant lines from the include file::
  820. PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
  821. PREFERRED_VERSION_linux-yocto ??= "4.15%"
  822. When you use a virtual provider, you do not have to "hard code" a recipe
  823. name as a build dependency. You can use the
  824. :term:`DEPENDS` variable to state the
  825. build is dependent on ``virtual/kernel`` for example::
  826. DEPENDS = "virtual/kernel"
  827. During the build, the OpenEmbedded build system picks
  828. the correct recipe needed for the ``virtual/kernel`` dependency based on
  829. the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel
  830. mentioned at the beginning of this section, configure your build as
  831. follows::
  832. PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
  833. .. note::
  834. Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not
  835. selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these
  836. recipes from building is usually the desired behavior since this mechanism's
  837. purpose is to select between mutually exclusive alternative providers.
  838. The following lists specific examples of virtual providers:
  839. - ``virtual/kernel``: Provides the name of the kernel recipe to use
  840. when building a kernel image.
  841. - ``virtual/bootloader``: Provides the name of the bootloader to use
  842. when building an image.
  843. - ``virtual/libgbm``: Provides ``gbm.pc``.
  844. - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
  845. - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
  846. - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
  847. - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
  848. .. note::
  849. Virtual providers only apply to build time dependencies specified with
  850. :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
  851. dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
  852. Properly Versioning Pre-Release Recipes
  853. =======================================
  854. Sometimes the name of a recipe can lead to versioning problems when the
  855. recipe is upgraded to a final release. For example, consider the
  856. ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
  857. the ":ref:`dev-manual/new-recipe:storing and naming the recipe`" section.
  858. This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
  859. released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
  860. change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
  861. build system and package managers, so the resulting packages will not
  862. correctly trigger an upgrade.
  863. In order to ensure the versions compare properly, the recommended
  864. convention is to set :term:`PV` within the
  865. recipe to "previous_version+current_version". You can use an additional
  866. variable so that you can use the current version elsewhere. Here is an
  867. example::
  868. REALPV = "0.8.16-rc1"
  869. PV = "0.8.15+${REALPV}"
  870. Post-Installation Scripts
  871. =========================
  872. Post-installation scripts run immediately after installing a package on
  873. the target or during image creation when a package is included in an
  874. image. To add a post-installation script to a package, add a
  875. ``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file
  876. (``.bb``) and replace `PACKAGENAME` with the name of the package you want
  877. to attach to the ``postinst`` script. To apply the post-installation
  878. script to the main package for the recipe, which is usually what is
  879. required, specify
  880. ``${``\ :term:`PN`\ ``}`` in place of
  881. PACKAGENAME.
  882. A post-installation function has the following structure::
  883. pkg_postinst:PACKAGENAME() {
  884. # Commands to carry out
  885. }
  886. The script defined in the post-installation function is called when the
  887. root filesystem is created. If the script succeeds, the package is
  888. marked as installed.
  889. .. note::
  890. Any RPM post-installation script that runs on the target should
  891. return a 0 exit code. RPM does not allow non-zero exit codes for
  892. these scripts, and the RPM package manager will cause the package to
  893. fail installation on the target.
  894. Sometimes it is necessary for the execution of a post-installation
  895. script to be delayed until the first boot. For example, the script might
  896. need to be executed on the device itself. To delay script execution
  897. until boot time, you must explicitly mark post installs to defer to the
  898. target. You can use ``pkg_postinst_ontarget()`` or call
  899. ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
  900. failure of a ``pkg_postinst()`` script (including exit 1) triggers an
  901. error during the
  902. :ref:`ref-tasks-rootfs` task.
  903. If you have recipes that use ``pkg_postinst`` function and they require
  904. the use of non-standard native tools that have dependencies during
  905. root filesystem construction, you need to use the
  906. :term:`PACKAGE_WRITE_DEPS`
  907. variable in your recipe to list these tools. If you do not use this
  908. variable, the tools might be missing and execution of the
  909. post-installation script is deferred until first boot. Deferring the
  910. script to the first boot is undesirable and impossible for read-only
  911. root filesystems.
  912. .. note::
  913. There is equivalent support for pre-install, pre-uninstall, and post-uninstall
  914. scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
  915. respectively. These scrips work in exactly the same way as does
  916. ``pkg_postinst`` with the exception that they run at different times. Also,
  917. because of when they run, they are not applicable to being run at image
  918. creation time like ``pkg_postinst``.
  919. Testing
  920. =======
  921. The final step for completing your recipe is to be sure that the
  922. software you built runs correctly. To accomplish runtime testing, add
  923. the build's output packages to your image and test them on the target.
  924. For information on how to customize your image by adding specific
  925. packages, see ":ref:`dev-manual/customizing-images:customizing images`" section.
  926. Examples
  927. ========
  928. To help summarize how to write a recipe, this section provides some
  929. examples given various scenarios:
  930. - Recipes that use local files
  931. - Using an Autotooled package
  932. - Using a Makefile-based package
  933. - Splitting an application into multiple packages
  934. - Adding binaries to an image
  935. Single .c File Package (Hello World!)
  936. -------------------------------------
  937. Building an application from a single file that is stored locally (e.g.
  938. under ``files``) requires a recipe that has the file listed in the
  939. :term:`SRC_URI` variable. Additionally, you need to manually write the
  940. :ref:`ref-tasks-compile` and :ref:`ref-tasks-install` tasks. The :term:`S` variable defines the
  941. directory containing the source code, which is set to
  942. :term:`WORKDIR` in this case --- the
  943. directory BitBake uses for the build.
  944. ::
  945. SUMMARY = "Simple helloworld application"
  946. SECTION = "examples"
  947. LICENSE = "MIT"
  948. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
  949. SRC_URI = "file://helloworld.c"
  950. S = "${WORKDIR}"
  951. do_compile() {
  952. ${CC} ${LDFLAGS} helloworld.c -o helloworld
  953. }
  954. do_install() {
  955. install -d ${D}${bindir}
  956. install -m 0755 helloworld ${D}${bindir}
  957. }
  958. By default, the ``helloworld``, ``helloworld-dbg``, and
  959. ``helloworld-dev`` packages are built. For information on how to
  960. customize the packaging process, see the
  961. ":ref:`dev-manual/new-recipe:splitting an application into multiple packages`"
  962. section.
  963. Autotooled Package
  964. ------------------
  965. Applications that use Autotools such as ``autoconf`` and ``automake``
  966. require a recipe that has a source archive listed in :term:`SRC_URI` and
  967. also inherit the :ref:`autotools <ref-classes-autotools>` class,
  968. which contains the definitions of all the steps needed to build an
  969. Autotool-based application. The result of the build is automatically
  970. packaged. And, if the application uses NLS for localization, packages
  971. with local information are generated (one package per language).
  972. Following is one example: (``hello_2.3.bb``)
  973. ::
  974. SUMMARY = "GNU Helloworld application"
  975. SECTION = "examples"
  976. LICENSE = "GPL-2.0-or-later"
  977. LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
  978. SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
  979. inherit autotools gettext
  980. The variable :term:`LIC_FILES_CHKSUM` is used to track source license
  981. changes as described in the
  982. ":ref:`dev-manual/licenses:tracking license changes`" section in
  983. the Yocto Project Overview and Concepts Manual. You can quickly create
  984. Autotool-based recipes in a manner similar to the previous example.
  985. Makefile-Based Package
  986. ----------------------
  987. Applications that use GNU ``make`` also require a recipe that has the
  988. source archive listed in :term:`SRC_URI`. You do not need to add a
  989. :ref:`ref-tasks-compile` step since by default BitBake starts the ``make`` command
  990. to compile the application. If you need additional ``make`` options, you
  991. should store them in the
  992. :term:`EXTRA_OEMAKE` or
  993. :term:`PACKAGECONFIG_CONFARGS`
  994. variables. BitBake passes these options into the GNU ``make``
  995. invocation. Note that a :ref:`ref-tasks-install` task is still required.
  996. Otherwise, BitBake runs an empty :ref:`ref-tasks-install` task by default.
  997. Some applications might require extra parameters to be passed to the
  998. compiler. For example, the application might need an additional header
  999. path. You can accomplish this by adding to the :term:`CFLAGS` variable. The
  1000. following example shows this::
  1001. CFLAGS:prepend = "-I ${S}/include "
  1002. In the following example, ``lz4`` is a makefile-based package::
  1003. SUMMARY = "Extremely Fast Compression algorithm"
  1004. DESCRIPTION = "LZ4 is a very fast lossless compression algorithm, providing compression speed at 400 MB/s per core, scalable with multi-cores CPU. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems."
  1005. HOMEPAGE = "https://github.com/lz4/lz4"
  1006. LICENSE = "BSD-2-Clause | GPL-2.0-only"
  1007. LIC_FILES_CHKSUM = "file://lib/LICENSE;md5=ebc2ea4814a64de7708f1571904b32cc \
  1008. file://programs/COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
  1009. file://LICENSE;md5=d57c0d21cb917fb4e0af2454aa48b956 \
  1010. "
  1011. PE = "1"
  1012. SRCREV = "d44371841a2f1728a3f36839fd4b7e872d0927d3"
  1013. SRC_URI = "git://github.com/lz4/lz4.git;branch=release;protocol=https \
  1014. file://CVE-2021-3520.patch \
  1015. "
  1016. UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)"
  1017. S = "${WORKDIR}/git"
  1018. # Fixed in r118, which is larger than the current version.
  1019. CVE_CHECK_IGNORE += "CVE-2014-4715"
  1020. EXTRA_OEMAKE = "PREFIX=${prefix} CC='${CC}' CFLAGS='${CFLAGS}' DESTDIR=${D} LIBDIR=${libdir} INCLUDEDIR=${includedir} BUILD_STATIC=no"
  1021. do_install() {
  1022. oe_runmake install
  1023. }
  1024. BBCLASSEXTEND = "native nativesdk"
  1025. Splitting an Application into Multiple Packages
  1026. -----------------------------------------------
  1027. You can use the variables :term:`PACKAGES` and :term:`FILES` to split an
  1028. application into multiple packages.
  1029. Following is an example that uses the ``libxpm`` recipe. By default,
  1030. this recipe generates a single package that contains the library along
  1031. with a few binaries. You can modify the recipe to split the binaries
  1032. into separate packages::
  1033. require xorg-lib-common.inc
  1034. SUMMARY = "Xpm: X Pixmap extension library"
  1035. LICENSE = "MIT"
  1036. LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
  1037. DEPENDS += "libxext libsm libxt"
  1038. PE = "1"
  1039. XORG_PN = "libXpm"
  1040. PACKAGES =+ "sxpm cxpm"
  1041. FILES:cxpm = "${bindir}/cxpm"
  1042. FILES:sxpm = "${bindir}/sxpm"
  1043. In the previous example, we want to ship the ``sxpm`` and ``cxpm``
  1044. binaries in separate packages. Since ``bindir`` would be packaged into
  1045. the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable
  1046. so additional package names are added to the start of list. This results
  1047. in the extra ``FILES:*`` variables then containing information that
  1048. define which files and directories go into which packages. Files
  1049. included by earlier packages are skipped by latter packages. Thus, the
  1050. main :term:`PN` package does not include the above listed files.
  1051. Packaging Externally Produced Binaries
  1052. --------------------------------------
  1053. Sometimes, you need to add pre-compiled binaries to an image. For
  1054. example, suppose that there are binaries for proprietary code,
  1055. created by a particular division of a company. Your part of the company
  1056. needs to use those binaries as part of an image that you are building
  1057. using the OpenEmbedded build system. Since you only have the binaries
  1058. and not the source code, you cannot use a typical recipe that expects to
  1059. fetch the source specified in
  1060. :term:`SRC_URI` and then compile it.
  1061. One method is to package the binaries and then install them as part of
  1062. the image. Generally, it is not a good idea to package binaries since,
  1063. among other things, it can hinder the ability to reproduce builds and
  1064. could lead to compatibility problems with ABI in the future. However,
  1065. sometimes you have no choice.
  1066. The easiest solution is to create a recipe that uses the
  1067. :ref:`bin_package <ref-classes-bin-package>` class
  1068. and to be sure that you are using default locations for build artifacts.
  1069. In most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the
  1070. configure and compile steps as well as sets things up to grab packages
  1071. from the appropriate area. In particular, this class sets ``noexec`` on
  1072. both the :ref:`ref-tasks-configure`
  1073. and :ref:`ref-tasks-compile` tasks,
  1074. sets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a
  1075. :ref:`ref-tasks-install` task, which
  1076. effectively copies all files from ``${S}`` to ``${D}``. The
  1077. :ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}``
  1078. are already laid out in the way they should be laid out on the target.
  1079. For more information on these variables, see the
  1080. :term:`FILES`,
  1081. :term:`PN`,
  1082. :term:`S`, and
  1083. :term:`D` variables in the Yocto Project
  1084. Reference Manual's variable glossary.
  1085. .. note::
  1086. - Using :term:`DEPENDS` is a good
  1087. idea even for components distributed in binary form, and is often
  1088. necessary for shared libraries. For a shared library, listing the
  1089. library dependencies in :term:`DEPENDS` makes sure that the libraries
  1090. are available in the staging sysroot when other recipes link
  1091. against the library, which might be necessary for successful
  1092. linking.
  1093. - Using :term:`DEPENDS` also allows runtime dependencies between
  1094. packages to be added automatically. See the
  1095. ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
  1096. section in the Yocto Project Overview and Concepts Manual for more
  1097. information.
  1098. If you cannot use the :ref:`bin_package <ref-classes-bin-package>` class, you need to be sure you are
  1099. doing the following:
  1100. - Create a recipe where the
  1101. :ref:`ref-tasks-configure` and
  1102. :ref:`ref-tasks-compile` tasks do
  1103. nothing: It is usually sufficient to just not define these tasks in
  1104. the recipe, because the default implementations do nothing unless a
  1105. Makefile is found in
  1106. ``${``\ :term:`S`\ ``}``.
  1107. If ``${S}`` might contain a Makefile, or if you inherit some class
  1108. that replaces :ref:`ref-tasks-configure` and :ref:`ref-tasks-compile` with custom
  1109. versions, then you can use the
  1110. ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
  1111. flag to turn the tasks into no-ops, as follows::
  1112. do_configure[noexec] = "1"
  1113. do_compile[noexec] = "1"
  1114. Unlike
  1115. :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
  1116. using the flag preserves the dependency chain from the
  1117. :ref:`ref-tasks-fetch`,
  1118. :ref:`ref-tasks-unpack`, and
  1119. :ref:`ref-tasks-patch` tasks to the
  1120. :ref:`ref-tasks-install` task.
  1121. - Make sure your :ref:`ref-tasks-install` task installs the binaries
  1122. appropriately.
  1123. - Ensure that you set up :term:`FILES`
  1124. (usually
  1125. ``FILES:${``\ :term:`PN`\ ``}``) to
  1126. point to the files you have installed, which of course depends on
  1127. where you have installed them and whether those files are in
  1128. different locations than the defaults.
  1129. Following Recipe Style Guidelines
  1130. =================================
  1131. When writing recipes, it is good to conform to existing style
  1132. guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
  1133. provides rough guidelines for preferred recipe style.
  1134. It is common for existing recipes to deviate a bit from this style.
  1135. However, aiming for at least a consistent style is a good idea. Some
  1136. practices, such as omitting spaces around ``=`` operators in assignments
  1137. or ordering recipe components in an erratic way, are widely seen as poor
  1138. style.
  1139. Recipe Syntax
  1140. =============
  1141. Understanding recipe file syntax is important for writing recipes. The
  1142. following list overviews the basic items that make up a BitBake recipe
  1143. file. For more complete BitBake syntax descriptions, see the
  1144. ":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`"
  1145. chapter of the BitBake User Manual.
  1146. - *Variable Assignments and Manipulations:* Variable assignments allow
  1147. a value to be assigned to a variable. The assignment can be static
  1148. text or might include the contents of other variables. In addition to
  1149. the assignment, appending and prepending operations are also
  1150. supported.
  1151. The following example shows some of the ways you can use variables in
  1152. recipes::
  1153. S = "${WORKDIR}/postfix-${PV}"
  1154. CFLAGS += "-DNO_ASM"
  1155. CFLAGS:append = " --enable-important-feature"
  1156. - *Functions:* Functions provide a series of actions to be performed.
  1157. You usually use functions to override the default implementation of a
  1158. task function or to complement a default function (i.e. append or
  1159. prepend to an existing function). Standard functions use ``sh`` shell
  1160. syntax, although access to OpenEmbedded variables and internal
  1161. methods are also available.
  1162. Here is an example function from the ``sed`` recipe::
  1163. do_install () {
  1164. autotools_do_install
  1165. install -d ${D}${base_bindir}
  1166. mv ${D}${bindir}/sed ${D}${base_bindir}/sed
  1167. rmdir ${D}${bindir}/
  1168. }
  1169. It is
  1170. also possible to implement new functions that are called between
  1171. existing tasks as long as the new functions are not replacing or
  1172. complementing the default functions. You can implement functions in
  1173. Python instead of shell. Both of these options are not seen in the
  1174. majority of recipes.
  1175. - *Keywords:* BitBake recipes use only a few keywords. You use keywords
  1176. to include common functions (``inherit``), load parts of a recipe
  1177. from other files (``include`` and ``require``) and export variables
  1178. to the environment (``export``).
  1179. The following example shows the use of some of these keywords::
  1180. export POSTCONF = "${STAGING_BINDIR}/postconf"
  1181. inherit autoconf
  1182. require otherfile.inc
  1183. - *Comments (#):* Any lines that begin with the hash character (``#``)
  1184. are treated as comment lines and are ignored::
  1185. # This is a comment
  1186. This next list summarizes the most important and most commonly used
  1187. parts of the recipe syntax. For more information on these parts of the
  1188. syntax, you can reference the
  1189. ":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`" chapter
  1190. in the BitBake User Manual.
  1191. - *Line Continuation (\\):* Use the backward slash (``\``) character to
  1192. split a statement over multiple lines. Place the slash character at
  1193. the end of the line that is to be continued on the next line::
  1194. VAR = "A really long \
  1195. line"
  1196. .. note::
  1197. You cannot have any characters including spaces or tabs after the
  1198. slash character.
  1199. - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
  1200. access the contents of a variable::
  1201. SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
  1202. .. note::
  1203. It is important to understand that the value of a variable
  1204. expressed in this form does not get substituted automatically. The
  1205. expansion of these expressions happens on-demand later (e.g.
  1206. usually when a function that makes reference to the variable
  1207. executes). This behavior ensures that the values are most
  1208. appropriate for the context in which they are finally used. On the
  1209. rare occasion that you do need the variable expression to be
  1210. expanded immediately, you can use the
  1211. :=
  1212. operator instead of
  1213. =
  1214. when you make the assignment, but this is not generally needed.
  1215. - *Quote All Assignments ("value"):* Use double quotes around values in
  1216. all variable assignments (e.g. ``"value"``). Following is an example::
  1217. VAR1 = "${OTHERVAR}"
  1218. VAR2 = "The version is ${PV}"
  1219. - *Conditional Assignment (?=):* Conditional assignment is used to
  1220. assign a value to a variable, but only when the variable is currently
  1221. unset. Use the question mark followed by the equal sign (``?=``) to
  1222. make a "soft" assignment used for conditional assignment. Typically,
  1223. "soft" assignments are used in the ``local.conf`` file for variables
  1224. that are allowed to come through from the external environment.
  1225. Here is an example where ``VAR1`` is set to "New value" if it is
  1226. currently empty. However, if ``VAR1`` has already been set, it
  1227. remains unchanged::
  1228. VAR1 ?= "New value"
  1229. In this next example, ``VAR1`` is left with the value "Original value"::
  1230. VAR1 = "Original value"
  1231. VAR1 ?= "New value"
  1232. - *Appending (+=):* Use the plus character followed by the equals sign
  1233. (``+=``) to append values to existing variables.
  1234. .. note::
  1235. This operator adds a space between the existing content of the
  1236. variable and the new content.
  1237. Here is an example::
  1238. SRC_URI += "file://fix-makefile.patch"
  1239. - *Prepending (=+):* Use the equals sign followed by the plus character
  1240. (``=+``) to prepend values to existing variables.
  1241. .. note::
  1242. This operator adds a space between the new content and the
  1243. existing content of the variable.
  1244. Here is an example::
  1245. VAR =+ "Starts"
  1246. - *Appending (:append):* Use the ``:append`` operator to append values
  1247. to existing variables. This operator does not add any additional
  1248. space. Also, the operator is applied after all the ``+=``, and ``=+``
  1249. operators have been applied and after all ``=`` assignments have
  1250. occurred. This means that if ``:append`` is used in a recipe, it can
  1251. only be overridden by another layer using the special ``:remove``
  1252. operator, which in turn will prevent further layers from adding it back.
  1253. The following example shows the space being explicitly added to the
  1254. start to ensure the appended value is not merged with the existing
  1255. value::
  1256. CFLAGS:append = " --enable-important-feature"
  1257. You can also use
  1258. the ``:append`` operator with overrides, which results in the actions
  1259. only being performed for the specified target or machine::
  1260. CFLAGS:append:sh4 = " --enable-important-sh4-specific-feature"
  1261. - *Prepending (:prepend):* Use the ``:prepend`` operator to prepend
  1262. values to existing variables. This operator does not add any
  1263. additional space. Also, the operator is applied after all the ``+=``,
  1264. and ``=+`` operators have been applied and after all ``=``
  1265. assignments have occurred.
  1266. The following example shows the space being explicitly added to the
  1267. end to ensure the prepended value is not merged with the existing
  1268. value::
  1269. CFLAGS:prepend = "-I${S}/myincludes "
  1270. You can also use the
  1271. ``:prepend`` operator with overrides, which results in the actions
  1272. only being performed for the specified target or machine::
  1273. CFLAGS:prepend:sh4 = "-I${S}/myincludes "
  1274. - *Overrides:* You can use overrides to set a value conditionally,
  1275. typically based on how the recipe is being built. For example, to set
  1276. the :term:`KBRANCH` variable's
  1277. value to "standard/base" for any target
  1278. :term:`MACHINE`, except for
  1279. qemuarm where it should be set to "standard/arm-versatile-926ejs",
  1280. you would do the following::
  1281. KBRANCH = "standard/base"
  1282. KBRANCH:qemuarm = "standard/arm-versatile-926ejs"
  1283. Overrides are also used to separate
  1284. alternate values of a variable in other situations. For example, when
  1285. setting variables such as
  1286. :term:`FILES` and
  1287. :term:`RDEPENDS` that are
  1288. specific to individual packages produced by a recipe, you should
  1289. always use an override that specifies the name of the package.
  1290. - *Indentation:* Use spaces for indentation rather than tabs. For
  1291. shell functions, both currently work. However, it is a policy
  1292. decision of the Yocto Project to use tabs in shell functions. Realize
  1293. that some layers have a policy to use spaces for all indentation.
  1294. - *Using Python for Complex Operations:* For more advanced processing,
  1295. it is possible to use Python code during variable assignments (e.g.
  1296. search and replacement on a variable).
  1297. You indicate Python code using the ``${@python_code}`` syntax for the
  1298. variable assignment::
  1299. SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
  1300. - *Shell Function Syntax:* Write shell functions as if you were writing
  1301. a shell script when you describe a list of actions to take. You
  1302. should ensure that your script works with a generic ``sh`` and that
  1303. it does not require any ``bash`` or other shell-specific
  1304. functionality. The same considerations apply to various system
  1305. utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
  1306. might wish to use. If in doubt, you should check with multiple
  1307. implementations --- including those from BusyBox.