blob: 9e08e57a4e786a9a032268acd49ead1d306bca75 [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3************************
4Using the Extensible SDK
5************************
6
7This chapter describes the extensible SDK and how to install it.
8Information covers the pieces of the SDK, how to install it, and
9presents a look at using the ``devtool`` functionality. The extensible
10SDK makes it easy to add new applications and libraries to an image,
11modify the source for an existing component, test changes on the target
12hardware, and ease integration into the rest of the
13:term:`OpenEmbedded Build System`.
14
15.. note::
16
17 For a side-by-side comparison of main features supported for an
Andrew Geissler09036742021-06-25 14:25:14 -050018 extensible SDK as compared to a standard SDK, see the
19 :ref:`sdk-manual/intro:introduction` section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050020
21In addition to the functionality available through ``devtool``, you can
22alternatively make use of the toolchain directly, for example from
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050023Makefile and Autotools. See the
24":ref:`sdk-manual/working-projects:using the sdk toolchain directly`" chapter
25for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050026
Andrew Geisslerc9f78652020-09-18 14:11:35 -050027Why use the Extensible SDK and What is in It?
28=============================================
29
30The extensible SDK provides a cross-development toolchain and libraries
31tailored to the contents of a specific image. You would use the
32Extensible SDK if you want a toolchain experience supplemented with the
33powerful set of ``devtool`` commands tailored for the Yocto Project
34environment.
35
36The installed extensible SDK consists of several files and directories.
37Basically, it contains an SDK environment setup script, some
38configuration files, an internal build system, and the ``devtool``
39functionality.
40
Andrew Geisslerc9f78652020-09-18 14:11:35 -050041Installing the Extensible SDK
42=============================
43
Patrick Williams92b42cb2022-09-03 06:53:57 -050044Two ways to install the Extensible SDK
45--------------------------------------
46
47Extensible SDK can be installed in two different ways, and both have
48their own pros and cons:
49
Andrew Geissler517393d2023-01-13 08:55:19 -060050#. *Setting up the Extensible SDK environment directly in a Yocto build*. This
Patrick Williams92b42cb2022-09-03 06:53:57 -050051avoids having to produce, test, distribute and maintain separate SDK installer
52archives, which can get very large. There is only one environment for the regular
53Yocto build and the SDK and less code paths where things can go not according to plan.
54It's easier to update the SDK: it simply means updating the Yocto layers with
55git fetch or layer management tooling. The SDK extensibility is better than in the
56second option: just run ``bitbake`` again to add more things to the sysroot, or add layers
57if even more things are required.
58
Andrew Geissler517393d2023-01-13 08:55:19 -060059#. *Setting up the Extensible SDK from a standalone installer*. This has the benefit of
Patrick Williams92b42cb2022-09-03 06:53:57 -050060having a single, self-contained archive that includes all the needed binary artifacts.
61So nothing needs to be rebuilt, and there is no need to provide a well-functioning
62binary artefact cache over the network for developers with underpowered laptops.
63
64Setting up the Extensible SDK environment directly in a Yocto build
65-------------------------------------------------------------------
66
Andrew Geissler517393d2023-01-13 08:55:19 -060067#. Set up all the needed layers and a Yocto :term:`Build Directory`, e.g. a regular Yocto
Patrick Williams92b42cb2022-09-03 06:53:57 -050068 build where ``bitbake`` can be executed.
69
Andrew Geissler517393d2023-01-13 08:55:19 -060070#. Run:
Patrick Williams92b42cb2022-09-03 06:53:57 -050071 $ bitbake meta-ide-support
72 $ bitbake -c populate_sysroot gtk+3
73 (or any other target or native item that the application developer would need)
Patrick Williams975a06f2022-10-21 14:42:47 -050074 $ bitbake build-sysroots
Patrick Williams92b42cb2022-09-03 06:53:57 -050075
76
77Setting up the Extensible SDK from a standalone installer
78---------------------------------------------------------
79
Andrew Geisslerc9f78652020-09-18 14:11:35 -050080The first thing you need to do is install the SDK on your :term:`Build
81Host` by running the ``*.sh`` installation script.
82
83You can download a tarball installer, which includes the pre-built
84toolchain, the ``runqemu`` script, the internal build system,
85``devtool``, and support files from the appropriate
Andrew Geissler09209ee2020-12-13 08:44:15 -060086:yocto_dl:`toolchain </releases/yocto/yocto-&DISTRO;/toolchain/>` directory within the Index of
Andrew Geisslerc9f78652020-09-18 14:11:35 -050087Releases. Toolchains are available for several 32-bit and 64-bit
88architectures with the ``x86_64`` directories, respectively. The
89toolchains the Yocto Project provides are based off the
90``core-image-sato`` and ``core-image-minimal`` images and contain
91libraries appropriate for developing against that image.
92
93The names of the tarball installer scripts are such that a string
94representing the host system appears first in the filename and then is
95immediately followed by a string representing the target architecture.
96An extensible SDK has the string "-ext" as part of the name. Following
Andrew Geisslerc926e172021-05-07 16:11:35 -050097is the general form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050098
99 poky-glibc-host_system-image_type-arch-toolchain-ext-release_version.sh
100
101 Where:
102 host_system is a string representing your development system:
103
104 i686 or x86_64.
105
106 image_type is the image for which the SDK was built:
107
108 core-image-sato or core-image-minimal
109
110 arch is a string representing the tuned target architecture:
111
112 aarch64, armv5e, core2-64, i586, mips32r2, mips64, ppc7400, or cortexa8hf-neon
113
114 release_version is a string representing the release number of the Yocto Project:
115
Andrew Geissler09209ee2020-12-13 08:44:15 -0600116 &DISTRO;, &DISTRO;+snapshot
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500117
118For example, the following SDK installer is for a 64-bit
119development host system and a i586-tuned target architecture based off
Andrew Geisslerc926e172021-05-07 16:11:35 -0500120the SDK for ``core-image-sato`` and using the current &DISTRO; snapshot::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500121
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600122 poky-glibc-x86_64-core-image-sato-i586-toolchain-ext-&DISTRO;.sh
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500123
124.. note::
125
126 As an alternative to downloading an SDK, you can build the SDK
Andrew Geissler09036742021-06-25 14:25:14 -0500127 installer. For information on building the installer, see the
128 :ref:`sdk-manual/appendix-obtain:building an sdk installer`
129 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500130
131The SDK and toolchains are self-contained and by default are installed
132into the ``poky_sdk`` folder in your home directory. You can choose to
133install the extensible SDK in any location when you run the installer.
134However, because files need to be written under that directory during
135the normal course of operation, the location you choose for installation
136must be writable for whichever users need to use the SDK.
137
138The following command shows how to run the installer given a toolchain
139tarball for a 64-bit x86 development host system and a 64-bit x86 target
140architecture. The example assumes the SDK installer is located in
Andrew Geissler517393d2023-01-13 08:55:19 -0600141``~/Downloads/`` and has execution rights::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500142
143 $ ./Downloads/poky-glibc-x86_64-core-image-minimal-core2-64-toolchain-ext-2.5.sh
144 Poky (Yocto Project Reference Distro) Extensible SDK installer version 2.5
145 ==========================================================================
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500146 Enter target directory for SDK (default: poky_sdk):
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500147 You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed [Y/n]? Y
148 Extracting SDK..............done
149 Setting it up...
150 Extracting buildtools...
151 Preparing build system...
152 Parsing recipes: 100% |##################################################################| Time: 0:00:52
153 Initialising tasks: 100% |###############################################################| Time: 0:00:00
154 Checking sstate mirror object availability: 100% |#######################################| Time: 0:00:00
155 Loading cache: 100% |####################################################################| Time: 0:00:00
156 Initialising tasks: 100% |###############################################################| Time: 0:00:00
157 done
158 SDK has been successfully set up and is ready to be used.
159 Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
160 $ . /home/scottrif/poky_sdk/environment-setup-core2-64-poky-linux
161
Andrew Geissler517393d2023-01-13 08:55:19 -0600162.. note::
163
164 If you do not have write permissions for the directory into which you
165 are installing the SDK, the installer notifies you and exits. For
166 that case, set up the proper permissions in the directory and run the
167 installer again.
168
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500169Running the Extensible SDK Environment Setup Script
170===================================================
171
172Once you have the SDK installed, you must run the SDK environment setup
Patrick Williams92b42cb2022-09-03 06:53:57 -0500173script before you can actually use the SDK.
174
175When using a SDK directly in a Yocto build, you will find the script in
Patrick Williams2390b1b2022-11-03 13:47:49 -0500176``tmp/deploy/images/qemux86-64/`` in your :term:`Build Directory`.
Patrick Williams92b42cb2022-09-03 06:53:57 -0500177
178When using a standalone SDK installer, this setup script resides in
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500179the directory you chose when you installed the SDK, which is either the
180default ``poky_sdk`` directory or the directory you chose during
181installation.
182
183Before running the script, be sure it is the one that matches the
184architecture for which you are developing. Environment setup scripts
185begin with the string "``environment-setup``" and include as part of
186their name the tuned target architecture. As an example, the following
187commands set the working directory to where the SDK was installed and
188then source the environment setup script. In this example, the setup
Andrew Geisslerc926e172021-05-07 16:11:35 -0500189script is for an IA-based target machine using i586 tuning::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500190
191 $ cd /home/scottrif/poky_sdk
192 $ source environment-setup-core2-64-poky-linux
193 SDK environment now set up; additionally you may now run devtool to perform development tasks.
194 Run devtool --help for further details.
195
Patrick Williams92b42cb2022-09-03 06:53:57 -0500196When using the environment script directly in a Yocto build, it can
197be run similarly:
198
199 $ source tmp/deploy/images/qemux86-64/environment-setup-core2-64-poky-linux
200
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500201Running the setup script defines many environment variables needed in
202order to use the SDK (e.g. ``PATH``,
203:term:`CC`,
204:term:`LD`, and so forth). If you want to
205see all the environment variables the script exports, examine the
206installation file itself.
207
208Using ``devtool`` in Your SDK Workflow
209======================================
210
211The cornerstone of the extensible SDK is a command-line tool called
212``devtool``. This tool provides a number of features that help you
213build, test and package software within the extensible SDK, and
214optionally integrate it into an image built by the OpenEmbedded build
215system.
216
217.. note::
218
219 The use of
220 devtool
221 is not limited to the extensible SDK. You can use
222 devtool
223 to help you easily develop any project whose build output must be
224 part of an image built using the build system.
225
226The ``devtool`` command line is organized similarly to
Andrew Geissler09209ee2020-12-13 08:44:15 -0600227:ref:`overview-manual/development-environment:git` in that it has a number of
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500228sub-commands for each function. You can run ``devtool --help`` to see
229all the commands.
230
231.. note::
232
233 See the "
234 devtool
235  Quick Reference
236 " in the Yocto Project Reference Manual for a
237 devtool
238 quick reference.
239
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700240Three ``devtool`` subcommands provide entry-points into
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500241development:
242
243- *devtool add*: Assists in adding new software to be built.
244
245- *devtool modify*: Sets up an environment to enable you to modify
246 the source of an existing component.
247
248- *devtool upgrade*: Updates an existing recipe so that you can
249 build it for an updated set of source files.
250
251As with the build system, "recipes" represent software packages within
252``devtool``. When you use ``devtool add``, a recipe is automatically
253created. When you use ``devtool modify``, the specified existing recipe
254is used in order to determine where to get the source code and how to
255patch it. In both cases, an environment is set up so that when you build
256the recipe a source tree that is under your control is used in order to
257allow you to make changes to the source as desired. By default, new
258recipes and the source go into a "workspace" directory under the SDK.
259
260The remainder of this section presents the ``devtool add``,
261``devtool modify``, and ``devtool upgrade`` workflows.
262
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500263Use ``devtool add`` to Add an Application
264-----------------------------------------
265
266The ``devtool add`` command generates a new recipe based on existing
267source code. This command takes advantage of the
268:ref:`devtool-the-workspace-layer-structure`
269layer that many ``devtool`` commands use. The command is flexible enough
270to allow you to extract source code into both the workspace or a
271separate local Git repository and to use existing code that does not
272need to be extracted.
273
274Depending on your particular scenario, the arguments and options you use
275with ``devtool add`` form different combinations. The following diagram
276shows common development flows you would use with the ``devtool add``
277command:
278
279.. image:: figures/sdk-devtool-add-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500280 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500281
Andrew Geissler517393d2023-01-13 08:55:19 -0600282#. *Generating the New Recipe*: The top part of the flow shows three
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500283 scenarios by which you could use ``devtool add`` to generate a recipe
284 based on existing source code.
285
286 In a shared development environment, it is typical for other
287 developers to be responsible for various areas of source code. As a
288 developer, you are probably interested in using that source code as
289 part of your development within the Yocto Project. All you need is
290 access to the code, a recipe, and a controlled area in which to do
291 your work.
292
293 Within the diagram, three possible scenarios feed into the
294 ``devtool add`` workflow:
295
296 - *Left*: The left scenario in the figure represents a common
297 situation where the source code does not exist locally and needs
298 to be extracted. In this situation, the source code is extracted
Andrew Geissler615f2f12022-07-15 14:00:58 -0500299 to the default workspace --- you do not want the files in some
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500300 specific location outside of the workspace. Thus, everything you
Andrew Geisslerc926e172021-05-07 16:11:35 -0500301 need will be located in the workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500302
303 $ devtool add recipe fetchuri
304
305 With this command, ``devtool`` extracts the upstream
306 source files into a local Git repository within the ``sources``
307 folder. The command then creates a recipe named recipe and a
308 corresponding append file in the workspace. If you do not provide
309 recipe, the command makes an attempt to determine the recipe name.
310
311 - *Middle*: The middle scenario in the figure also represents a
312 situation where the source code does not exist locally. In this
313 case, the code is again upstream and needs to be extracted to some
Andrew Geissler615f2f12022-07-15 14:00:58 -0500314 local area --- this time outside of the default workspace.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500315
316 .. note::
317
318 If required,
319 devtool
320 always creates a Git repository locally during the extraction.
321
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700322 Furthermore, the first positional argument ``srctree`` in this case
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500323 identifies where the ``devtool add`` command will locate the
324 extracted code outside of the workspace. You need to specify an
Andrew Geisslerc926e172021-05-07 16:11:35 -0500325 empty directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500326
327 $ devtool add recipe srctree fetchuri
328
329 In summary,
330 the source code is pulled from fetchuri and extracted into the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700331 location defined by ``srctree`` as a local Git repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500332
333 Within workspace, ``devtool`` creates a recipe named recipe along
334 with an associated append file.
335
336 - *Right*: The right scenario in the figure represents a situation
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700337 where the ``srctree`` has been previously prepared outside of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500338 ``devtool`` workspace.
339
340 The following command provides a new recipe name and identifies
Andrew Geisslerc926e172021-05-07 16:11:35 -0500341 the existing source tree location::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500342
343 $ devtool add recipe srctree
344
345 The command examines the source code and creates a recipe named
346 recipe for the code and places the recipe into the workspace.
347
348 Because the extracted source code already exists, ``devtool`` does
Andrew Geissler615f2f12022-07-15 14:00:58 -0500349 not try to relocate the source code into the workspace --- only the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500350 new recipe is placed in the workspace.
351
352 Aside from a recipe folder, the command also creates an associated
353 append folder and places an initial ``*.bbappend`` file within.
354
Andrew Geissler517393d2023-01-13 08:55:19 -0600355#. *Edit the Recipe*: You can use ``devtool edit-recipe`` to open up the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500356 editor as defined by the ``$EDITOR`` environment variable and modify
Andrew Geisslerc926e172021-05-07 16:11:35 -0500357 the file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500358
359 $ devtool edit-recipe recipe
360
361 From within the editor, you
Andrew Geissler595f6302022-01-24 19:11:47 +0000362 can make modifications to the recipe that take effect when you build
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500363 it later.
364
Andrew Geissler517393d2023-01-13 08:55:19 -0600365#. *Build the Recipe or Rebuild the Image*: The next step you take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500366 depends on what you are going to do with the new code.
367
368 If you need to eventually move the build output to the target
369 hardware, use the following ``devtool`` command:
370 :;
371
372 $ devtool build recipe
373
374 On the other hand, if you want an image to contain the recipe's
375 packages from the workspace for immediate deployment onto a device
376 (e.g. for testing purposes), you can use the ``devtool build-image``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500377 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500378
379 $ devtool build-image image
380
Andrew Geissler517393d2023-01-13 08:55:19 -0600381#. *Deploy the Build Output*: When you use the ``devtool build`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500382 to build out your recipe, you probably want to see if the resulting
383 build output works as expected on the target hardware.
384
385 .. note::
386
387 This step assumes you have a previously built image that is
388 already either running in QEMU or is running on actual hardware.
389 Also, it is assumed that for deployment of the image to the
390 target, SSH is installed in the image and, if the image is running
391 on real hardware, you have network access to and from your
392 development machine.
393
394 You can deploy your build output to that target hardware by using the
395 ``devtool deploy-target`` command: $ devtool deploy-target recipe
396 target The target is a live target machine running as an SSH server.
397
398 You can, of course, also deploy the image you build to actual
399 hardware by using the ``devtool build-image`` command. However,
400 ``devtool`` does not provide a specific command that allows you to
401 deploy the image to actual hardware.
402
Andrew Geissler517393d2023-01-13 08:55:19 -0600403#. *Finish Your Work With the Recipe*: The ``devtool finish`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500404 creates any patches corresponding to commits in the local Git
405 repository, moves the new recipe to a more permanent layer, and then
406 resets the recipe so that the recipe is built normally rather than
Andrew Geissler517393d2023-01-13 08:55:19 -0600407 from the workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500408
409 $ devtool finish recipe layer
410
411 .. note::
412
413 Any changes you want to turn into patches must be committed to the
414 Git repository in the source tree.
415
416 As mentioned, the ``devtool finish`` command moves the final recipe
417 to its permanent layer.
418
419 As a final process of the ``devtool finish`` command, the state of
420 the standard layers and the upstream source is restored so that you
421 can build the recipe from those areas rather than the workspace.
422
423 .. note::
424
425 You can use the
426 devtool reset
427 command to put things back should you decide you do not want to
428 proceed with your work. If you do use this command, realize that
429 the source tree is preserved.
430
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500431Use ``devtool modify`` to Modify the Source of an Existing Component
432--------------------------------------------------------------------
433
434The ``devtool modify`` command prepares the way to work on existing code
435that already has a local recipe in place that is used to build the
436software. The command is flexible enough to allow you to extract code
437from an upstream source, specify the existing recipe, and keep track of
438and gather any patch files from other developers that are associated
439with the code.
440
441Depending on your particular scenario, the arguments and options you use
442with ``devtool modify`` form different combinations. The following
443diagram shows common development flows for the ``devtool modify``
444command:
445
446.. image:: figures/sdk-devtool-modify-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500447 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500448
Andrew Geissler517393d2023-01-13 08:55:19 -0600449#. *Preparing to Modify the Code*: The top part of the flow shows three
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500450 scenarios by which you could use ``devtool modify`` to prepare to
451 work on source files. Each scenario assumes the following:
452
453 - The recipe exists locally in a layer external to the ``devtool``
454 workspace.
455
456 - The source files exist either upstream in an un-extracted state or
457 locally in a previously extracted state.
458
459 The typical situation is where another developer has created a layer
460 for use with the Yocto Project and their recipe already resides in
461 that layer. Furthermore, their source code is readily available
462 either upstream or locally.
463
464 - *Left*: The left scenario in the figure represents a common
465 situation where the source code does not exist locally and it
466 needs to be extracted from an upstream source. In this situation,
467 the source is extracted into the default ``devtool`` workspace
468 location. The recipe, in this scenario, is in its own layer
469 outside the workspace (i.e. ``meta-``\ layername).
470
471 The following command identifies the recipe and, by default,
Andrew Geisslerc926e172021-05-07 16:11:35 -0500472 extracts the source files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500473
474 $ devtool modify recipe
475
476 Once
477 ``devtool``\ locates the recipe, ``devtool`` uses the recipe's
478 :term:`SRC_URI` statements to
479 locate the source code and any local patch files from other
480 developers.
481
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700482 With this scenario, there is no ``srctree`` argument. Consequently, the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500483 default behavior of the ``devtool modify`` command is to extract
Andrew Geissler09036742021-06-25 14:25:14 -0500484 the source files pointed to by the :term:`SRC_URI` statements into a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500485 local Git structure. Furthermore, the location for the extracted
486 source is the default area within the ``devtool`` workspace. The
487 result is that the command sets up both the source code and an
488 append file within the workspace while the recipe remains in its
489 original location.
490
491 Additionally, if you have any non-patch local files (i.e. files
Andrew Geissler09036742021-06-25 14:25:14 -0500492 referred to with ``file://`` entries in :term:`SRC_URI` statement
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500493 excluding ``*.patch/`` or ``*.diff``), these files are copied to
494 an ``oe-local-files`` folder under the newly created source tree.
495 Copying the files here gives you a convenient area from which you
496 can modify the files. Any changes or additions you make to those
497 files are incorporated into the build the next time you build the
498 software just as are other changes you might have made to the
499 source.
500
501 - *Middle*: The middle scenario in the figure represents a situation
502 where the source code also does not exist locally. In this case,
503 the code is again upstream and needs to be extracted to some local
504 area as a Git repository. The recipe, in this scenario, is again
505 local and in its own layer outside the workspace.
506
507 The following command tells ``devtool`` the recipe with which to
508 work and, in this case, identifies a local area for the extracted
509 source files that exists outside of the default ``devtool``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500510 workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500511
512 $ devtool modify recipe srctree
513
514 .. note::
515
516 You cannot provide a URL for
517 srctree
518 using the
519 devtool
520 command.
521
Andrew Geissler09036742021-06-25 14:25:14 -0500522 As with all extractions, the command uses the recipe's :term:`SRC_URI`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500523 statements to locate the source files and any associated patch
524 files. Non-patch files are copied to an ``oe-local-files`` folder
525 under the newly created source tree.
526
527 Once the files are located, the command by default extracts them
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700528 into ``srctree``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500529
530 Within workspace, ``devtool`` creates an append file for the
531 recipe. The recipe remains in its original location but the source
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700532 files are extracted to the location you provide with ``srctree``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500533
534 - *Right*: The right scenario in the figure represents a situation
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700535 where the source tree (``srctree``) already exists locally as a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500536 previously extracted Git structure outside of the ``devtool``
537 workspace. In this example, the recipe also exists elsewhere
538 locally in its own layer.
539
540 The following command tells ``devtool`` the recipe with which to
541 work, uses the "-n" option to indicate source does not need to be
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700542 extracted, and uses ``srctree`` to point to the previously extracted
Andrew Geisslerc926e172021-05-07 16:11:35 -0500543 source files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500544
545 $ devtool modify -n recipe srctree
546
547 If an ``oe-local-files`` subdirectory happens to exist and it
548 contains non-patch files, the files are used. However, if the
549 subdirectory does not exist and you run the ``devtool finish``
550 command, any non-patch files that might exist next to the recipe
551 are removed because it appears to ``devtool`` that you have
552 deleted those files.
553
554 Once the ``devtool modify`` command finishes, it creates only an
555 append file for the recipe in the ``devtool`` workspace. The
556 recipe and the source code remain in their original locations.
557
Andrew Geissler517393d2023-01-13 08:55:19 -0600558#. *Edit the Source*: Once you have used the ``devtool modify`` command,
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500559 you are free to make changes to the source files. You can use any
560 editor you like to make and save your source code modifications.
561
Andrew Geissler517393d2023-01-13 08:55:19 -0600562#. *Build the Recipe or Rebuild the Image*: The next step you take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500563 depends on what you are going to do with the new code.
564
565 If you need to eventually move the build output to the target
Andrew Geisslerc926e172021-05-07 16:11:35 -0500566 hardware, use the following ``devtool`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500567
568 $ devtool build recipe
569
570 On the other hand, if you want an image to contain the recipe's
571 packages from the workspace for immediate deployment onto a device
572 (e.g. for testing purposes), you can use the ``devtool build-image``
573 command: $ devtool build-image image
574
Andrew Geissler517393d2023-01-13 08:55:19 -0600575#. *Deploy the Build Output*: When you use the ``devtool build`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500576 to build out your recipe, you probably want to see if the resulting
577 build output works as expected on target hardware.
578
579 .. note::
580
581 This step assumes you have a previously built image that is
582 already either running in QEMU or running on actual hardware.
583 Also, it is assumed that for deployment of the image to the
584 target, SSH is installed in the image and if the image is running
585 on real hardware that you have network access to and from your
586 development machine.
587
588 You can deploy your build output to that target hardware by using the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500589 ``devtool deploy-target`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500590
591 $ devtool deploy-target recipe target
592
593 The target is a live target machine running as an SSH server.
594
595 You can, of course, use other methods to deploy the image you built
596 using the ``devtool build-image`` command to actual hardware.
597 ``devtool`` does not provide a specific command to deploy the image
598 to actual hardware.
599
Andrew Geissler517393d2023-01-13 08:55:19 -0600600#. *Finish Your Work With the Recipe*: The ``devtool finish`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500601 creates any patches corresponding to commits in the local Git
602 repository, updates the recipe to point to them (or creates a
603 ``.bbappend`` file to do so, depending on the specified destination
604 layer), and then resets the recipe so that the recipe is built
Andrew Geissler517393d2023-01-13 08:55:19 -0600605 normally rather than from the workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500606
607 $ devtool finish recipe layer
608
609 .. note::
610
611 Any changes you want to turn into patches must be staged and
612 committed within the local Git repository before you use the
613 devtool finish
614 command.
615
616 Because there is no need to move the recipe, ``devtool finish``
617 either updates the original recipe in the original layer or the
618 command creates a ``.bbappend`` file in a different layer as provided
619 by layer. Any work you did in the ``oe-local-files`` directory is
620 preserved in the original files next to the recipe during the
621 ``devtool finish`` command.
622
623 As a final process of the ``devtool finish`` command, the state of
624 the standard layers and the upstream source is restored so that you
625 can build the recipe from those areas rather than from the workspace.
626
627 .. note::
628
629 You can use the
630 devtool reset
631 command to put things back should you decide you do not want to
632 proceed with your work. If you do use this command, realize that
633 the source tree is preserved.
634
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500635Use ``devtool upgrade`` to Create a Version of the Recipe that Supports a Newer Version of the Software
636-------------------------------------------------------------------------------------------------------
637
638The ``devtool upgrade`` command upgrades an existing recipe to that of a
639more up-to-date version found upstream. Throughout the life of software,
640recipes continually undergo version upgrades by their upstream
641publishers. You can use the ``devtool upgrade`` workflow to make sure
642your recipes you are using for builds are up-to-date with their upstream
643counterparts.
644
645.. note::
646
647 Several methods exist by which you can upgrade recipes -
Andrew Geissler09036742021-06-25 14:25:14 -0500648 ``devtool upgrade``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500649 happens to be one. You can read about all the methods by which you
Andrew Geissler09036742021-06-25 14:25:14 -0500650 can upgrade recipes in the
Andrew Geissler517393d2023-01-13 08:55:19 -0600651 :ref:`dev-manual/upgrading-recipes:upgrading recipes` section
Andrew Geissler09036742021-06-25 14:25:14 -0500652 of the Yocto Project Development Tasks Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500653
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500654The ``devtool upgrade`` command is flexible enough to allow you to specify
655source code revision and versioning schemes, extract code into or out of the
656``devtool`` :ref:`devtool-the-workspace-layer-structure`, and work with any
657source file forms that the
658:ref:`bitbake-user-manual/bitbake-user-manual-fetching:fetchers` support.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500659
660The following diagram shows the common development flow used with the
661``devtool upgrade`` command:
662
663.. image:: figures/sdk-devtool-upgrade-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500664 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500665
Andrew Geissler517393d2023-01-13 08:55:19 -0600666#. *Initiate the Upgrade*: The top part of the flow shows the typical
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500667 scenario by which you use the ``devtool upgrade`` command. The
668 following conditions exist:
669
670 - The recipe exists in a local layer external to the ``devtool``
671 workspace.
672
673 - The source files for the new release exist in the same location
674 pointed to by :term:`SRC_URI`
675 in the recipe (e.g. a tarball with the new version number in the
676 name, or as a different revision in the upstream Git repository).
677
678 A common situation is where third-party software has undergone a
679 revision so that it has been upgraded. The recipe you have access to
680 is likely in your own layer. Thus, you need to upgrade the recipe to
Andrew Geisslerc926e172021-05-07 16:11:35 -0500681 use the newer version of the software::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500682
683 $ devtool upgrade -V version recipe
684
685 By default, the ``devtool upgrade`` command extracts source
686 code into the ``sources`` directory in the
687 :ref:`devtool-the-workspace-layer-structure`.
688 If you want the code extracted to any other location, you need to
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700689 provide the ``srctree`` positional argument with the command as follows::
690
691 $ devtool upgrade -V version recipe srctree
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500692
693 .. note::
694
695 In this example, the "-V" option specifies the new version. If you
696 don't use "-V", the command upgrades the recipe to the latest
697 version.
698
Andrew Geissler09036742021-06-25 14:25:14 -0500699 If the source files pointed to by the :term:`SRC_URI` statement in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500700 recipe are in a Git repository, you must provide the "-S" option and
701 specify a revision for the software.
702
Andrew Geissler09036742021-06-25 14:25:14 -0500703 Once ``devtool`` locates the recipe, it uses the :term:`SRC_URI` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500704 to locate the source code and any local patch files from other
705 developers. The result is that the command sets up the source code,
706 the new version of the recipe, and an append file all within the
707 workspace.
708
709 Additionally, if you have any non-patch local files (i.e. files
Andrew Geissler09036742021-06-25 14:25:14 -0500710 referred to with ``file://`` entries in :term:`SRC_URI` statement
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500711 excluding ``*.patch/`` or ``*.diff``), these files are copied to an
712 ``oe-local-files`` folder under the newly created source tree.
713 Copying the files here gives you a convenient area from which you can
714 modify the files. Any changes or additions you make to those files
715 are incorporated into the build the next time you build the software
716 just as are other changes you might have made to the source.
717
Andrew Geissler517393d2023-01-13 08:55:19 -0600718#. *Resolve any Conflicts created by the Upgrade*: Conflicts could happen
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700719 after upgrading the software to a new version. Conflicts occur
Andrew Geissler09036742021-06-25 14:25:14 -0500720 if your recipe specifies some patch files in :term:`SRC_URI` that
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500721 conflict with changes made in the new version of the software. For
722 such cases, you need to resolve the conflicts by editing the source
723 and following the normal ``git rebase`` conflict resolution process.
724
725 Before moving onto the next step, be sure to resolve any such
726 conflicts created through use of a newer or different version of the
727 software.
728
Andrew Geissler517393d2023-01-13 08:55:19 -0600729#. *Build the Recipe or Rebuild the Image*: The next step you take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500730 depends on what you are going to do with the new code.
731
732 If you need to eventually move the build output to the target
Andrew Geisslerc926e172021-05-07 16:11:35 -0500733 hardware, use the following ``devtool`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500734
735 $ devtool build recipe
736
737 On the other hand, if you want an image to contain the recipe's
738 packages from the workspace for immediate deployment onto a device
739 (e.g. for testing purposes), you can use the ``devtool build-image``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500740 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500741
742 $ devtool build-image image
743
Andrew Geissler517393d2023-01-13 08:55:19 -0600744#. *Deploy the Build Output*: When you use the ``devtool build`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500745 or ``bitbake`` to build your recipe, you probably want to see if the
746 resulting build output works as expected on target hardware.
747
748 .. note::
749
750 This step assumes you have a previously built image that is
751 already either running in QEMU or running on actual hardware.
752 Also, it is assumed that for deployment of the image to the
753 target, SSH is installed in the image and if the image is running
754 on real hardware that you have network access to and from your
755 development machine.
756
757 You can deploy your build output to that target hardware by using the
758 ``devtool deploy-target`` command: $ devtool deploy-target recipe
759 target The target is a live target machine running as an SSH server.
760
761 You can, of course, also deploy the image you build using the
762 ``devtool build-image`` command to actual hardware. However,
763 ``devtool`` does not provide a specific command that allows you to do
764 this.
765
Andrew Geissler517393d2023-01-13 08:55:19 -0600766#. *Finish Your Work With the Recipe*: The ``devtool finish`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500767 creates any patches corresponding to commits in the local Git
768 repository, moves the new recipe to a more permanent layer, and then
769 resets the recipe so that the recipe is built normally rather than
770 from the workspace.
771
772 Any work you did in the ``oe-local-files`` directory is preserved in
773 the original files next to the recipe during the ``devtool finish``
774 command.
775
776 If you specify a destination layer that is the same as the original
777 source, then the old version of the recipe and associated files are
Andrew Geissler517393d2023-01-13 08:55:19 -0600778 removed prior to adding the new version::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500779
780 $ devtool finish recipe layer
781
782 .. note::
783
784 Any changes you want to turn into patches must be committed to the
785 Git repository in the source tree.
786
787 As a final process of the ``devtool finish`` command, the state of
788 the standard layers and the upstream source is restored so that you
789 can build the recipe from those areas rather than the workspace.
790
791 .. note::
792
793 You can use the
794 devtool reset
795 command to put things back should you decide you do not want to
796 proceed with your work. If you do use this command, realize that
797 the source tree is preserved.
798
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500799A Closer Look at ``devtool add``
800================================
801
802The ``devtool add`` command automatically creates a recipe based on the
803source tree you provide with the command. Currently, the command has
804support for the following:
805
806- Autotools (``autoconf`` and ``automake``)
807
808- CMake
809
810- Scons
811
812- ``qmake``
813
814- Plain ``Makefile``
815
816- Out-of-tree kernel module
817
818- Binary package (i.e. "-b" option)
819
820- Node.js module
821
822- Python modules that use ``setuptools`` or ``distutils``
823
824Apart from binary packages, the determination of how a source tree
825should be treated is automatic based on the files present within that
826source tree. For example, if a ``CMakeLists.txt`` file is found, then
827the source tree is assumed to be using CMake and is treated accordingly.
828
829.. note::
830
831 In most cases, you need to edit the automatically generated recipe in
832 order to make it build properly. Typically, you would go through
833 several edit and build cycles until the recipe successfully builds.
834 Once the recipe builds, you could use possible further iterations to
835 test the recipe on the target device.
836
837The remainder of this section covers specifics regarding how parts of
838the recipe are generated.
839
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500840Name and Version
841----------------
842
843If you do not specify a name and version on the command line,
844``devtool add`` uses various metadata within the source tree in an
845attempt to determine the name and version of the software being built.
846Based on what the tool determines, ``devtool`` sets the name of the
847created recipe file accordingly.
848
849If ``devtool`` cannot determine the name and version, the command prints
850an error. For such cases, you must re-run the command and provide the
851name and version, just the name, or just the version as part of the
852command line.
853
854Sometimes the name or version determined from the source tree might be
Andrew Geisslerc926e172021-05-07 16:11:35 -0500855incorrect. For such a case, you must reset the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500856
857 $ devtool reset -n recipename
858
859After running the ``devtool reset`` command, you need to
860run ``devtool add`` again and provide the name or the version.
861
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500862Dependency Detection and Mapping
863--------------------------------
864
865The ``devtool add`` command attempts to detect build-time dependencies
866and map them to other recipes in the system. During this mapping, the
867command fills in the names of those recipes as part of the
868:term:`DEPENDS` variable within the
869recipe. If a dependency cannot be mapped, ``devtool`` places a comment
870in the recipe indicating such. The inability to map a dependency can
871result from naming not being recognized or because the dependency simply
872is not available. For cases where the dependency is not available, you
873must use the ``devtool add`` command to add an additional recipe that
874satisfies the dependency. Once you add that recipe, you need to update
Andrew Geissler09036742021-06-25 14:25:14 -0500875the :term:`DEPENDS` variable in the original recipe to include the new
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500876recipe.
877
878If you need to add runtime dependencies, you can do so by adding the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500879following to your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500880
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500881 RDEPENDS:${PN} += "dependency1 dependency2 ..."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500882
883.. note::
884
885 The
886 devtool add
887 command often cannot distinguish between mandatory and optional
888 dependencies. Consequently, some of the detected dependencies might
889 in fact be optional. When in doubt, consult the documentation or the
890 configure script for the software the recipe is building for further
891 details. In some cases, you might find you can substitute the
892 dependency with an option that disables the associated functionality
893 passed to the configure script.
894
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500895License Detection
896-----------------
897
898The ``devtool add`` command attempts to determine if the software you
899are adding is able to be distributed under a common, open-source
900license. If so, the command sets the
901:term:`LICENSE` value accordingly.
902You should double-check the value added by the command against the
903documentation or source files for the software you are building and, if
Andrew Geissler09036742021-06-25 14:25:14 -0500904necessary, update that :term:`LICENSE` value.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500905
906The ``devtool add`` command also sets the
907:term:`LIC_FILES_CHKSUM`
908value to point to all files that appear to be license-related. Realize
909that license statements often appear in comments at the top of source
910files or within the documentation. In such cases, the command does not
911recognize those license statements. Consequently, you might need to
Andrew Geissler09036742021-06-25 14:25:14 -0500912amend the :term:`LIC_FILES_CHKSUM` variable to point to one or more of those
913comments if present. Setting :term:`LIC_FILES_CHKSUM` is particularly
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500914important for third-party software. The mechanism attempts to ensure
915correct licensing should you upgrade the recipe to a newer upstream
916version in future. Any change in licensing is detected and you receive
917an error prompting you to check the license text again.
918
919If the ``devtool add`` command cannot determine licensing information,
Andrew Geissler09036742021-06-25 14:25:14 -0500920``devtool`` sets the :term:`LICENSE` value to "CLOSED" and leaves the
921:term:`LIC_FILES_CHKSUM` value unset. This behavior allows you to continue
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500922with development even though the settings are unlikely to be correct in
923all cases. You should check the documentation or source files for the
924software you are building to determine the actual license.
925
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500926Adding Makefile-Only Software
927-----------------------------
928
929The use of Make by itself is very common in both proprietary and
930open-source software. Unfortunately, Makefiles are often not written
931with cross-compilation in mind. Thus, ``devtool add`` often cannot do
932very much to ensure that these Makefiles build correctly. It is very
933common, for example, to explicitly call ``gcc`` instead of using the
934:term:`CC` variable. Usually, in a
935cross-compilation environment, ``gcc`` is the compiler for the build
936host and the cross-compiler is named something similar to
937``arm-poky-linux-gnueabi-gcc`` and might require arguments (e.g. to
938point to the associated sysroot for the target machine).
939
940When writing a recipe for Makefile-only software, keep the following in
941mind:
942
943- You probably need to patch the Makefile to use variables instead of
944 hardcoding tools within the toolchain such as ``gcc`` and ``g++``.
945
946- The environment in which Make runs is set up with various standard
Andrew Geissler09036742021-06-25 14:25:14 -0500947 variables for compilation (e.g. :term:`CC`, :term:`CXX`, and so forth) in a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500948 similar manner to the environment set up by the SDK's environment
949 setup script. One easy way to see these variables is to run the
950 ``devtool build`` command on the recipe and then look in
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700951 ``oe-logs/run.do_compile``. Towards the top of this file, there is
952 a list of environment variables that are set. You can take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500953 advantage of these variables within the Makefile.
954
955- If the Makefile sets a default for a variable using "=", that default
956 overrides the value set in the environment, which is usually not
957 desirable. For this case, you can either patch the Makefile so it
958 sets the default using the "?=" operator, or you can alternatively
959 force the value on the ``make`` command line. To force the value on
960 the command line, add the variable setting to
961 :term:`EXTRA_OEMAKE` or
962 :term:`PACKAGECONFIG_CONFARGS`
Andrew Geissler09036742021-06-25 14:25:14 -0500963 within the recipe. Here is an example using :term:`EXTRA_OEMAKE`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500964
965 EXTRA_OEMAKE += "'CC=${CC}' 'CXX=${CXX}'"
966
967 In the above example,
968 single quotes are used around the variable settings as the values are
969 likely to contain spaces because required default options are passed
970 to the compiler.
971
972- Hardcoding paths inside Makefiles is often problematic in a
973 cross-compilation environment. This is particularly true because
974 those hardcoded paths often point to locations on the build host and
975 thus will either be read-only or will introduce contamination into
976 the cross-compilation because they are specific to the build host
977 rather than the target. Patching the Makefile to use prefix variables
978 or other path variables is usually the way to handle this situation.
979
980- Sometimes a Makefile runs target-specific commands such as
981 ``ldconfig``. For such cases, you might be able to apply patches that
982 remove these commands from the Makefile.
983
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500984Adding Native Tools
985-------------------
986
987Often, you need to build additional tools that run on the :term:`Build
988Host` as opposed to
989the target. You should indicate this requirement by using one of the
990following methods when you run ``devtool add``:
991
992- Specify the name of the recipe such that it ends with "-native".
993 Specifying the name like this produces a recipe that only builds for
994 the build host.
995
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700996- Specify the "--also-native" option with the ``devtool add``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500997 command. Specifying this option creates a recipe file that still
998 builds for the target but also creates a variant with a "-native"
999 suffix that builds for the build host.
1000
1001.. note::
1002
1003 If you need to add a tool that is shipped as part of a source tree
1004 that builds code for the target, you can typically accomplish this by
1005 building the native and target parts separately rather than within
1006 the same compilation process. Realize though that with the
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001007 "--also-native" option, you can add the tool using just one
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001008 recipe file.
1009
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001010Adding Node.js Modules
1011----------------------
1012
1013You can use the ``devtool add`` command two different ways to add
1014Node.js modules: 1) Through ``npm`` and, 2) from a repository or local
1015source.
1016
Andrew Geisslerc926e172021-05-07 16:11:35 -05001017Use the following form to add Node.js modules through ``npm``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001018
1019 $ devtool add "npm://registry.npmjs.org;name=forever;version=0.15.1"
1020
1021The name and
1022version parameters are mandatory. Lockdown and shrinkwrap files are
1023generated and pointed to by the recipe in order to freeze the version
1024that is fetched for the dependencies according to the first time. This
1025also saves checksums that are verified on future fetches. Together,
1026these behaviors ensure the reproducibility and integrity of the build.
1027
1028.. note::
1029
1030 - You must use quotes around the URL. The ``devtool add`` does not
1031 require the quotes, but the shell considers ";" as a splitter
1032 between multiple commands. Thus, without the quotes,
1033 ``devtool add`` does not receive the other parts, which results in
1034 several "command not found" errors.
1035
1036 - In order to support adding Node.js modules, a ``nodejs`` recipe
1037 must be part of your SDK.
1038
1039As mentioned earlier, you can also add Node.js modules directly from a
1040repository or local source tree. To add modules this way, use
Andrew Geisslerc926e172021-05-07 16:11:35 -05001041``devtool add`` in the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001042
1043 $ devtool add https://github.com/diversario/node-ssdp
1044
1045In this example, ``devtool``
1046fetches the specified Git repository, detects the code as Node.js code,
1047fetches dependencies using ``npm``, and sets
1048:term:`SRC_URI` accordingly.
1049
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001050Working With Recipes
1051====================
1052
1053When building a recipe using the ``devtool build`` command, the typical
1054build progresses as follows:
1055
Andrew Geissler517393d2023-01-13 08:55:19 -06001056#. Fetch the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001057
Andrew Geissler517393d2023-01-13 08:55:19 -06001058#. Unpack the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001059
Andrew Geissler517393d2023-01-13 08:55:19 -06001060#. Configure the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001061
Andrew Geissler517393d2023-01-13 08:55:19 -06001062#. Compile the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001063
Andrew Geissler517393d2023-01-13 08:55:19 -06001064#. Install the build output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001065
Andrew Geissler517393d2023-01-13 08:55:19 -06001066#. Package the installed output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001067
1068For recipes in the workspace, fetching and unpacking is disabled as the
1069source tree has already been prepared and is persistent. Each of these
1070build steps is defined as a function (task), usually with a "do\_" prefix
1071(e.g. :ref:`ref-tasks-fetch`,
1072:ref:`ref-tasks-unpack`, and so
1073forth). These functions are typically shell scripts but can instead be
1074written in Python.
1075
1076If you look at the contents of a recipe, you will see that the recipe
1077does not include complete instructions for building the software.
1078Instead, common functionality is encapsulated in classes inherited with
1079the ``inherit`` directive. This technique leaves the recipe to describe
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001080just the things that are specific to the software being built. There is
Andrew Geissler517393d2023-01-13 08:55:19 -06001081a :ref:`ref-classes-base` class that is implicitly inherited by all recipes
1082and provides the functionality that most recipes typically need.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001083
1084The remainder of this section presents information useful when working
1085with recipes.
1086
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001087Finding Logs and Work Files
1088---------------------------
1089
1090After the first run of the ``devtool build`` command, recipes that were
1091previously created using the ``devtool add`` command or whose sources
1092were modified using the ``devtool modify`` command contain symbolic
1093links created within the source tree:
1094
1095- ``oe-logs``: This link points to the directory in which log files and
1096 run scripts for each build step are created.
1097
1098- ``oe-workdir``: This link points to the temporary work area for the
1099 recipe. The following locations under ``oe-workdir`` are particularly
1100 useful:
1101
1102 - ``image/``: Contains all of the files installed during the
1103 :ref:`ref-tasks-install` stage.
1104 Within a recipe, this directory is referred to by the expression
1105 ``${``\ :term:`D`\ ``}``.
1106
1107 - ``sysroot-destdir/``: Contains a subset of files installed within
Patrick Williams2194f502022-10-16 14:26:09 -05001108 :ref:`ref-tasks-install` that have been put into the shared sysroot. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001109 more information, see the
Andrew Geissler517393d2023-01-13 08:55:19 -06001110 ":ref:`dev-manual/new-recipe:sharing files between recipes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001111
1112 - ``packages-split/``: Contains subdirectories for each package
1113 produced by the recipe. For more information, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001114 ":ref:`sdk-manual/extensible:packaging`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001115
1116You can use these links to get more information on what is happening at
1117each build step.
1118
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001119Setting Configure Arguments
1120---------------------------
1121
1122If the software your recipe is building uses GNU autoconf, then a fixed
1123set of arguments is passed to it to enable cross-compilation plus any
1124extras specified by
1125:term:`EXTRA_OECONF` or
1126:term:`PACKAGECONFIG_CONFARGS`
1127set within the recipe. If you wish to pass additional options, add them
Andrew Geissler09036742021-06-25 14:25:14 -05001128to :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`. Other supported build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001129tools have similar variables (e.g.
1130:term:`EXTRA_OECMAKE` for
1131CMake, :term:`EXTRA_OESCONS`
1132for Scons, and so forth). If you need to pass anything on the ``make``
Andrew Geissler09036742021-06-25 14:25:14 -05001133command line, you can use :term:`EXTRA_OEMAKE` or the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001134:term:`PACKAGECONFIG_CONFARGS`
1135variables to do so.
1136
1137You can use the ``devtool configure-help`` command to help you set the
1138arguments listed in the previous paragraph. The command determines the
1139exact options being passed, and shows them to you along with any custom
Andrew Geissler09036742021-06-25 14:25:14 -05001140arguments specified through :term:`EXTRA_OECONF` or
1141:term:`PACKAGECONFIG_CONFARGS`. If applicable, the command also shows you
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001142the output of the configure script's "--help" option as a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001143reference.
1144
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001145Sharing Files Between Recipes
1146-----------------------------
1147
1148Recipes often need to use files provided by other recipes on the
1149:term:`Build Host`. For example,
1150an application linking to a common library needs access to the library
1151itself and its associated headers. The way this access is accomplished
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001152within the extensible SDK is through the sysroot. There is one sysroot per
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001153"machine" for which the SDK is being built. In practical terms, this
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001154means there is a sysroot for the target machine, and a sysroot for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001155the build host.
1156
1157Recipes should never write files directly into the sysroot. Instead,
1158files should be installed into standard locations during the
1159:ref:`ref-tasks-install` task within
1160the ``${``\ :term:`D`\ ``}`` directory. A
1161subset of these files automatically goes into the sysroot. The reason
1162for this limitation is that almost all files that go into the sysroot
1163are cataloged in manifests in order to ensure they can be removed later
1164when a recipe is modified or removed. Thus, the sysroot is able to
1165remain free from stale files.
1166
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001167Packaging
1168---------
1169
1170Packaging is not always particularly relevant within the extensible SDK.
1171However, if you examine how build output gets into the final image on
1172the target device, it is important to understand packaging because the
1173contents of the image are expressed in terms of packages and not
1174recipes.
1175
1176During the :ref:`ref-tasks-package`
1177task, files installed during the
1178:ref:`ref-tasks-install` task are
1179split into one main package, which is almost always named the same as
1180the recipe, and into several other packages. This separation exists
1181because not all of those installed files are useful in every image. For
1182example, you probably do not need any of the documentation installed in
1183a production image. Consequently, for each recipe the documentation
1184files are separated into a ``-doc`` package. Recipes that package
1185software containing optional modules or plugins might undergo additional
1186package splitting as well.
1187
1188After building a recipe, you can see where files have gone by looking in
1189the ``oe-workdir/packages-split`` directory, which contains a
1190subdirectory for each package. Apart from some advanced cases, the
1191:term:`PACKAGES` and
1192:term:`FILES` variables controls
Andrew Geissler09036742021-06-25 14:25:14 -05001193splitting. The :term:`PACKAGES` variable lists all of the packages to be
1194produced, while the :term:`FILES` variable specifies which files to include
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001195in each package by using an override to specify the package. For
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001196example, ``FILES:${PN}`` specifies the files to go into the main package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001197(i.e. the main package has the same name as the recipe and
1198``${``\ :term:`PN`\ ``}`` evaluates to the
Andrew Geissler09036742021-06-25 14:25:14 -05001199recipe name). The order of the :term:`PACKAGES` value is significant. For
1200each installed file, the first package whose :term:`FILES` value matches the
1201file is the package into which the file goes. Both the :term:`PACKAGES` and
1202:term:`FILES` variables have default values. Consequently, you might find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001203you do not even need to set these variables in your recipe unless the
1204software the recipe is building installs files into non-standard
1205locations.
1206
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001207Restoring the Target Device to its Original State
1208=================================================
1209
1210If you use the ``devtool deploy-target`` command to write a recipe's
1211build output to the target, and you are working on an existing component
1212of the system, then you might find yourself in a situation where you
1213need to restore the original files that existed prior to running the
1214``devtool deploy-target`` command. Because the ``devtool deploy-target``
1215command backs up any files it overwrites, you can use the
1216``devtool undeploy-target`` command to restore those files and remove
Andrew Geisslerc926e172021-05-07 16:11:35 -05001217any other files the recipe deployed. Consider the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001218
1219 $ devtool undeploy-target lighttpd root@192.168.7.2
1220
1221If you have deployed
1222multiple applications, you can remove them all using the "-a" option
Andrew Geisslerc926e172021-05-07 16:11:35 -05001223thus restoring the target device to its original state::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001224
1225 $ devtool undeploy-target -a root@192.168.7.2
1226
1227Information about files deployed to
1228the target as well as any backed up files are stored on the target
1229itself. This storage, of course, requires some additional space on the
1230target machine.
1231
1232.. note::
1233
1234 The
1235 devtool deploy-target
1236 and
1237 devtool undeploy-target
1238 commands do not currently interact with any package management system
1239 on the target device (e.g. RPM or OPKG). Consequently, you should not
1240 intermingle
1241 devtool deploy-target
1242 and package manager operations on the target device. Doing so could
1243 result in a conflicting set of files.
1244
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001245Installing Additional Items Into the Extensible SDK
1246===================================================
1247
1248Out of the box the extensible SDK typically only comes with a small
1249number of tools and libraries. A minimal SDK starts mostly empty and is
1250populated on-demand. Sometimes you must explicitly install extra items
1251into the SDK. If you need these extra items, you can first search for
1252the items using the ``devtool search`` command. For example, suppose you
1253need to link to libGL but you are not sure which recipe provides libGL.
Andrew Geisslerc926e172021-05-07 16:11:35 -05001254You can use the following command to find out::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001255
1256 $ devtool search libGL mesa
Patrick Williams92b42cb2022-09-03 06:53:57 -05001257 A free implementation of the OpenGL API
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001258
Patrick Williams92b42cb2022-09-03 06:53:57 -05001259Once you know the recipe
1260(i.e. ``mesa`` in this example), you can install it.
1261
1262When using the extensible SDK directly in a Yocto build
1263-------------------------------------------------------
1264
1265In this scenario, the Yocto build tooling, e.g. ``bitbake``
1266is directly accessible to build additional items, and it
1267can simply be executed directly:
1268
1269 $ bitbake mesa
Patrick Williams975a06f2022-10-21 14:42:47 -05001270 $ bitbake build-sysroots
Patrick Williams92b42cb2022-09-03 06:53:57 -05001271
1272When using a standalone installer for the Extensible SDK
1273--------------------------------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001274
1275 $ devtool sdk-install mesa
1276
1277By default, the ``devtool sdk-install`` command assumes
1278the item is available in pre-built form from your SDK provider. If the
1279item is not available and it is acceptable to build the item from
Andrew Geisslerc926e172021-05-07 16:11:35 -05001280source, you can add the "-s" option as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001281
1282 $ devtool sdk-install -s mesa
1283
1284It is important to remember that building the item from source
1285takes significantly longer than installing the pre-built artifact. Also,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001286if there is no recipe for the item you want to add to the SDK, you must
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001287instead add the item using the ``devtool add`` command.
1288
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001289Applying Updates to an Installed Extensible SDK
1290===============================================
1291
1292If you are working with an installed extensible SDK that gets
1293occasionally updated (e.g. a third-party SDK), then you will need to
1294manually "pull down" the updates into the installed SDK.
1295
Andrew Geisslerc926e172021-05-07 16:11:35 -05001296To update your installed SDK, use ``devtool`` as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001297
1298 $ devtool sdk-update
1299
1300The previous command assumes your SDK provider has set the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001301default update URL for you through the :term:`SDK_UPDATE_URL`
1302variable as described in the
1303":ref:`sdk-manual/appendix-customizing:Providing Updates to the Extensible SDK After Installation`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001304section. If the SDK provider has not set that default URL, you need to
1305specify it yourself in the command as follows: $ devtool sdk-update
1306path_to_update_directory
1307
1308.. note::
1309
1310 The URL needs to point specifically to a published SDK and not to an
1311 SDK installer that you would download and install.
1312
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001313Creating a Derivative SDK With Additional Components
1314====================================================
1315
1316You might need to produce an SDK that contains your own custom
1317libraries. A good example would be if you were a vendor with customers
1318that use your SDK to build their own platform-specific software and
1319those customers need an SDK that has custom libraries. In such a case,
1320you can produce a derivative SDK based on the currently installed SDK
1321fairly easily by following these steps:
1322
Andrew Geissler517393d2023-01-13 08:55:19 -06001323#. If necessary, install an extensible SDK that you want to use as a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001324 base for your derivative SDK.
1325
Andrew Geissler517393d2023-01-13 08:55:19 -06001326#. Source the environment script for the SDK.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001327
Andrew Geissler517393d2023-01-13 08:55:19 -06001328#. Add the extra libraries or other components you want by using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001329 ``devtool add`` command.
1330
Andrew Geissler517393d2023-01-13 08:55:19 -06001331#. Run the ``devtool build-sdk`` command.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001332
1333The previous steps take the recipes added to the workspace and construct
1334a new SDK installer that contains those recipes and the resulting binary
1335artifacts. The recipes go into their own separate layer in the
1336constructed derivative SDK, which leaves the workspace clean and ready
1337for users to add their own recipes.