blob: 355c6cb0e4ab3a637cec104c1bb82c3b0f2fb129 [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
Andrew Geissler220dafd2023-10-04 10:18:08 -050051 avoids having to produce, test, distribute and maintain separate SDK
52 installer archives, which can get very large. There is only one environment
53 for the regular Yocto build and the SDK and less code paths where things can
54 go not according to plan. It's easier to update the SDK: it simply means
55 updating the Yocto layers with git fetch or layer management tooling. The
56 SDK extensibility is better than in the second option: just run ``bitbake``
57 again to add more things to the sysroot, or add layers if even more things
58 are required.
Patrick Williams92b42cb2022-09-03 06:53:57 -050059
Andrew Geissler220dafd2023-10-04 10:18:08 -050060#. *Setting up the Extensible SDK from a standalone installer*. This has the
61 benefit of having a single, self-contained archive that includes all the
62 needed binary artifacts. So nothing needs to be rebuilt, and there is no
63 need to provide a well-functioning binary artefact cache over the network
64 for developers with underpowered laptops.
Patrick Williams92b42cb2022-09-03 06:53:57 -050065
66Setting up the Extensible SDK environment directly in a Yocto build
67-------------------------------------------------------------------
68
Andrew Geissler517393d2023-01-13 08:55:19 -060069#. Set up all the needed layers and a Yocto :term:`Build Directory`, e.g. a regular Yocto
Patrick Williams92b42cb2022-09-03 06:53:57 -050070 build where ``bitbake`` can be executed.
71
Andrew Geissler220dafd2023-10-04 10:18:08 -050072#. Run::
Patrick Williams92b42cb2022-09-03 06:53:57 -050073
Andrew Geissler220dafd2023-10-04 10:18:08 -050074 $ bitbake meta-ide-support
75 $ bitbake -c populate_sysroot gtk+3
76 # or any other target or native item that the application developer would need
77 $ bitbake build-sysroots
Patrick Williams92b42cb2022-09-03 06:53:57 -050078
79Setting up the Extensible SDK from a standalone installer
80---------------------------------------------------------
81
Andrew Geisslerc9f78652020-09-18 14:11:35 -050082The first thing you need to do is install the SDK on your :term:`Build
83Host` by running the ``*.sh`` installation script.
84
85You can download a tarball installer, which includes the pre-built
86toolchain, the ``runqemu`` script, the internal build system,
87``devtool``, and support files from the appropriate
Andrew Geissler09209ee2020-12-13 08:44:15 -060088:yocto_dl:`toolchain </releases/yocto/yocto-&DISTRO;/toolchain/>` directory within the Index of
Andrew Geisslerc9f78652020-09-18 14:11:35 -050089Releases. Toolchains are available for several 32-bit and 64-bit
90architectures with the ``x86_64`` directories, respectively. The
91toolchains the Yocto Project provides are based off the
92``core-image-sato`` and ``core-image-minimal`` images and contain
93libraries appropriate for developing against that image.
94
95The names of the tarball installer scripts are such that a string
96representing the host system appears first in the filename and then is
97immediately followed by a string representing the target architecture.
98An extensible SDK has the string "-ext" as part of the name. Following
Andrew Geisslerc926e172021-05-07 16:11:35 -050099is the general form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500100
101 poky-glibc-host_system-image_type-arch-toolchain-ext-release_version.sh
102
103 Where:
104 host_system is a string representing your development system:
105
106 i686 or x86_64.
107
108 image_type is the image for which the SDK was built:
109
110 core-image-sato or core-image-minimal
111
112 arch is a string representing the tuned target architecture:
113
114 aarch64, armv5e, core2-64, i586, mips32r2, mips64, ppc7400, or cortexa8hf-neon
115
116 release_version is a string representing the release number of the Yocto Project:
117
Andrew Geissler09209ee2020-12-13 08:44:15 -0600118 &DISTRO;, &DISTRO;+snapshot
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500119
120For example, the following SDK installer is for a 64-bit
121development host system and a i586-tuned target architecture based off
Andrew Geisslerc926e172021-05-07 16:11:35 -0500122the SDK for ``core-image-sato`` and using the current &DISTRO; snapshot::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500123
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600124 poky-glibc-x86_64-core-image-sato-i586-toolchain-ext-&DISTRO;.sh
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500125
126.. note::
127
128 As an alternative to downloading an SDK, you can build the SDK
Andrew Geissler09036742021-06-25 14:25:14 -0500129 installer. For information on building the installer, see the
130 :ref:`sdk-manual/appendix-obtain:building an sdk installer`
131 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500132
133The SDK and toolchains are self-contained and by default are installed
134into the ``poky_sdk`` folder in your home directory. You can choose to
135install the extensible SDK in any location when you run the installer.
136However, because files need to be written under that directory during
137the normal course of operation, the location you choose for installation
138must be writable for whichever users need to use the SDK.
139
140The following command shows how to run the installer given a toolchain
141tarball for a 64-bit x86 development host system and a 64-bit x86 target
142architecture. The example assumes the SDK installer is located in
Andrew Geissler517393d2023-01-13 08:55:19 -0600143``~/Downloads/`` and has execution rights::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500144
145 $ ./Downloads/poky-glibc-x86_64-core-image-minimal-core2-64-toolchain-ext-2.5.sh
146 Poky (Yocto Project Reference Distro) Extensible SDK installer version 2.5
147 ==========================================================================
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500148 Enter target directory for SDK (default: poky_sdk):
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500149 You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed [Y/n]? Y
150 Extracting SDK..............done
151 Setting it up...
152 Extracting buildtools...
153 Preparing build system...
154 Parsing recipes: 100% |##################################################################| Time: 0:00:52
155 Initialising tasks: 100% |###############################################################| Time: 0:00:00
156 Checking sstate mirror object availability: 100% |#######################################| Time: 0:00:00
157 Loading cache: 100% |####################################################################| Time: 0:00:00
158 Initialising tasks: 100% |###############################################################| Time: 0:00:00
159 done
160 SDK has been successfully set up and is ready to be used.
161 Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
162 $ . /home/scottrif/poky_sdk/environment-setup-core2-64-poky-linux
163
Andrew Geissler517393d2023-01-13 08:55:19 -0600164.. note::
165
166 If you do not have write permissions for the directory into which you
167 are installing the SDK, the installer notifies you and exits. For
168 that case, set up the proper permissions in the directory and run the
169 installer again.
170
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500171Running the Extensible SDK Environment Setup Script
172===================================================
173
174Once you have the SDK installed, you must run the SDK environment setup
Patrick Williams92b42cb2022-09-03 06:53:57 -0500175script before you can actually use the SDK.
176
177When using a SDK directly in a Yocto build, you will find the script in
Patrick Williams2390b1b2022-11-03 13:47:49 -0500178``tmp/deploy/images/qemux86-64/`` in your :term:`Build Directory`.
Patrick Williams92b42cb2022-09-03 06:53:57 -0500179
180When using a standalone SDK installer, this setup script resides in
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500181the directory you chose when you installed the SDK, which is either the
182default ``poky_sdk`` directory or the directory you chose during
183installation.
184
185Before running the script, be sure it is the one that matches the
186architecture for which you are developing. Environment setup scripts
187begin with the string "``environment-setup``" and include as part of
188their name the tuned target architecture. As an example, the following
189commands set the working directory to where the SDK was installed and
190then source the environment setup script. In this example, the setup
Andrew Geisslerc926e172021-05-07 16:11:35 -0500191script is for an IA-based target machine using i586 tuning::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500192
193 $ cd /home/scottrif/poky_sdk
194 $ source environment-setup-core2-64-poky-linux
195 SDK environment now set up; additionally you may now run devtool to perform development tasks.
196 Run devtool --help for further details.
197
Patrick Williams92b42cb2022-09-03 06:53:57 -0500198When using the environment script directly in a Yocto build, it can
Andrew Geissler220dafd2023-10-04 10:18:08 -0500199be run similarly::
Patrick Williams92b42cb2022-09-03 06:53:57 -0500200
201 $ source tmp/deploy/images/qemux86-64/environment-setup-core2-64-poky-linux
202
Andrew Geissler220dafd2023-10-04 10:18:08 -0500203Running the setup script defines many environment variables needed in order to
204use the SDK (e.g. ``PATH``, :term:`CC`, :term:`LD`, and so forth). If you want
205to see all the environment variables the script exports, examine the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500206installation 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
Andrew Geissler220dafd2023-10-04 10:18:08 -0500219 The use of ``devtool`` is not limited to the extensible SDK. You can use
220 ``devtool`` to help you easily develop any project whose build output must be
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500221 part of an image built using the build system.
222
223The ``devtool`` command line is organized similarly to
Andrew Geissler09209ee2020-12-13 08:44:15 -0600224:ref:`overview-manual/development-environment:git` in that it has a number of
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500225sub-commands for each function. You can run ``devtool --help`` to see
226all the commands.
227
228.. note::
229
Andrew Geissler220dafd2023-10-04 10:18:08 -0500230 See the ":doc:`/ref-manual/devtool-reference`"
231 section in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500232
Andrew Geissler220dafd2023-10-04 10:18:08 -0500233Three ``devtool`` subcommands provide entry-points into development:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500234
235- *devtool add*: Assists in adding new software to be built.
236
237- *devtool modify*: Sets up an environment to enable you to modify
238 the source of an existing component.
239
240- *devtool upgrade*: Updates an existing recipe so that you can
241 build it for an updated set of source files.
242
243As with the build system, "recipes" represent software packages within
244``devtool``. When you use ``devtool add``, a recipe is automatically
245created. When you use ``devtool modify``, the specified existing recipe
246is used in order to determine where to get the source code and how to
247patch it. In both cases, an environment is set up so that when you build
248the recipe a source tree that is under your control is used in order to
249allow you to make changes to the source as desired. By default, new
250recipes and the source go into a "workspace" directory under the SDK.
251
252The remainder of this section presents the ``devtool add``,
253``devtool modify``, and ``devtool upgrade`` workflows.
254
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500255Use ``devtool add`` to Add an Application
256-----------------------------------------
257
258The ``devtool add`` command generates a new recipe based on existing
259source code. This command takes advantage of the
260:ref:`devtool-the-workspace-layer-structure`
261layer that many ``devtool`` commands use. The command is flexible enough
262to allow you to extract source code into both the workspace or a
263separate local Git repository and to use existing code that does not
264need to be extracted.
265
266Depending on your particular scenario, the arguments and options you use
267with ``devtool add`` form different combinations. The following diagram
268shows common development flows you would use with the ``devtool add``
269command:
270
271.. image:: figures/sdk-devtool-add-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500272 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500273
Andrew Geissler517393d2023-01-13 08:55:19 -0600274#. *Generating the New Recipe*: The top part of the flow shows three
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500275 scenarios by which you could use ``devtool add`` to generate a recipe
276 based on existing source code.
277
278 In a shared development environment, it is typical for other
279 developers to be responsible for various areas of source code. As a
280 developer, you are probably interested in using that source code as
281 part of your development within the Yocto Project. All you need is
282 access to the code, a recipe, and a controlled area in which to do
283 your work.
284
285 Within the diagram, three possible scenarios feed into the
286 ``devtool add`` workflow:
287
288 - *Left*: The left scenario in the figure represents a common
289 situation where the source code does not exist locally and needs
290 to be extracted. In this situation, the source code is extracted
Andrew Geissler615f2f12022-07-15 14:00:58 -0500291 to the default workspace --- you do not want the files in some
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500292 specific location outside of the workspace. Thus, everything you
Andrew Geisslerc926e172021-05-07 16:11:35 -0500293 need will be located in the workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500294
295 $ devtool add recipe fetchuri
296
297 With this command, ``devtool`` extracts the upstream
298 source files into a local Git repository within the ``sources``
299 folder. The command then creates a recipe named recipe and a
300 corresponding append file in the workspace. If you do not provide
301 recipe, the command makes an attempt to determine the recipe name.
302
303 - *Middle*: The middle scenario in the figure also represents a
304 situation where the source code does not exist locally. In this
305 case, the code is again upstream and needs to be extracted to some
Andrew Geissler615f2f12022-07-15 14:00:58 -0500306 local area --- this time outside of the default workspace.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500307
308 .. note::
309
Andrew Geissler220dafd2023-10-04 10:18:08 -0500310 If required, ``devtool`` always creates a Git repository locally
311 during the extraction.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500312
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700313 Furthermore, the first positional argument ``srctree`` in this case
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500314 identifies where the ``devtool add`` command will locate the
315 extracted code outside of the workspace. You need to specify an
Andrew Geisslerc926e172021-05-07 16:11:35 -0500316 empty directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500317
318 $ devtool add recipe srctree fetchuri
319
Andrew Geissler220dafd2023-10-04 10:18:08 -0500320 In summary, the source code is pulled from fetchuri and extracted into the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700321 location defined by ``srctree`` as a local Git repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500322
323 Within workspace, ``devtool`` creates a recipe named recipe along
324 with an associated append file.
325
326 - *Right*: The right scenario in the figure represents a situation
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700327 where the ``srctree`` has been previously prepared outside of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500328 ``devtool`` workspace.
329
330 The following command provides a new recipe name and identifies
Andrew Geisslerc926e172021-05-07 16:11:35 -0500331 the existing source tree location::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500332
333 $ devtool add recipe srctree
334
335 The command examines the source code and creates a recipe named
336 recipe for the code and places the recipe into the workspace.
337
338 Because the extracted source code already exists, ``devtool`` does
Andrew Geissler615f2f12022-07-15 14:00:58 -0500339 not try to relocate the source code into the workspace --- only the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500340 new recipe is placed in the workspace.
341
342 Aside from a recipe folder, the command also creates an associated
343 append folder and places an initial ``*.bbappend`` file within.
344
Andrew Geissler517393d2023-01-13 08:55:19 -0600345#. *Edit the Recipe*: You can use ``devtool edit-recipe`` to open up the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500346 editor as defined by the ``$EDITOR`` environment variable and modify
Andrew Geisslerc926e172021-05-07 16:11:35 -0500347 the file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500348
349 $ devtool edit-recipe recipe
350
Andrew Geissler220dafd2023-10-04 10:18:08 -0500351 From within the editor, you can make modifications to the recipe that
352 take effect when you build it later.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500353
Andrew Geissler517393d2023-01-13 08:55:19 -0600354#. *Build the Recipe or Rebuild the Image*: The next step you take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500355 depends on what you are going to do with the new code.
356
357 If you need to eventually move the build output to the target
Andrew Geissler220dafd2023-10-04 10:18:08 -0500358 hardware, use the following ``devtool`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500359
360 $ devtool build recipe
361
362 On the other hand, if you want an image to contain the recipe's
363 packages from the workspace for immediate deployment onto a device
364 (e.g. for testing purposes), you can use the ``devtool build-image``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500365 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500366
367 $ devtool build-image image
368
Andrew Geissler517393d2023-01-13 08:55:19 -0600369#. *Deploy the Build Output*: When you use the ``devtool build`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500370 to build out your recipe, you probably want to see if the resulting
371 build output works as expected on the target hardware.
372
373 .. note::
374
375 This step assumes you have a previously built image that is
376 already either running in QEMU or is running on actual hardware.
377 Also, it is assumed that for deployment of the image to the
378 target, SSH is installed in the image and, if the image is running
379 on real hardware, you have network access to and from your
380 development machine.
381
382 You can deploy your build output to that target hardware by using the
Andrew Geissler220dafd2023-10-04 10:18:08 -0500383 ``devtool deploy-target`` command::
384
385 $ devtool deploy-target recipe target
386
387 The target is a live target machine running as an SSH server.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500388
389 You can, of course, also deploy the image you build to actual
390 hardware by using the ``devtool build-image`` command. However,
391 ``devtool`` does not provide a specific command that allows you to
392 deploy the image to actual hardware.
393
Andrew Geissler517393d2023-01-13 08:55:19 -0600394#. *Finish Your Work With the Recipe*: The ``devtool finish`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500395 creates any patches corresponding to commits in the local Git
396 repository, moves the new recipe to a more permanent layer, and then
397 resets the recipe so that the recipe is built normally rather than
Andrew Geissler517393d2023-01-13 08:55:19 -0600398 from the workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500399
400 $ devtool finish recipe layer
401
402 .. note::
403
404 Any changes you want to turn into patches must be committed to the
405 Git repository in the source tree.
406
407 As mentioned, the ``devtool finish`` command moves the final recipe
408 to its permanent layer.
409
410 As a final process of the ``devtool finish`` command, the state of
411 the standard layers and the upstream source is restored so that you
412 can build the recipe from those areas rather than the workspace.
413
414 .. note::
415
Andrew Geissler220dafd2023-10-04 10:18:08 -0500416 You can use the ``devtool reset`` command to put things back should you
417 decide you do not want to proceed with your work. If you do use this
418 command, realize that the source tree is preserved.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500419
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500420Use ``devtool modify`` to Modify the Source of an Existing Component
421--------------------------------------------------------------------
422
423The ``devtool modify`` command prepares the way to work on existing code
424that already has a local recipe in place that is used to build the
425software. The command is flexible enough to allow you to extract code
426from an upstream source, specify the existing recipe, and keep track of
427and gather any patch files from other developers that are associated
428with the code.
429
430Depending on your particular scenario, the arguments and options you use
431with ``devtool modify`` form different combinations. The following
432diagram shows common development flows for the ``devtool modify``
433command:
434
435.. image:: figures/sdk-devtool-modify-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500436 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500437
Andrew Geissler517393d2023-01-13 08:55:19 -0600438#. *Preparing to Modify the Code*: The top part of the flow shows three
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500439 scenarios by which you could use ``devtool modify`` to prepare to
440 work on source files. Each scenario assumes the following:
441
442 - The recipe exists locally in a layer external to the ``devtool``
443 workspace.
444
445 - The source files exist either upstream in an un-extracted state or
446 locally in a previously extracted state.
447
448 The typical situation is where another developer has created a layer
449 for use with the Yocto Project and their recipe already resides in
450 that layer. Furthermore, their source code is readily available
451 either upstream or locally.
452
453 - *Left*: The left scenario in the figure represents a common
454 situation where the source code does not exist locally and it
455 needs to be extracted from an upstream source. In this situation,
456 the source is extracted into the default ``devtool`` workspace
457 location. The recipe, in this scenario, is in its own layer
458 outside the workspace (i.e. ``meta-``\ layername).
459
460 The following command identifies the recipe and, by default,
Andrew Geisslerc926e172021-05-07 16:11:35 -0500461 extracts the source files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500462
463 $ devtool modify recipe
464
Andrew Geissler220dafd2023-10-04 10:18:08 -0500465 Once ``devtool`` locates the recipe, ``devtool`` uses the recipe's
466 :term:`SRC_URI` statements to locate the source code and any local
467 patch files from other developers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500468
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700469 With this scenario, there is no ``srctree`` argument. Consequently, the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500470 default behavior of the ``devtool modify`` command is to extract
Andrew Geissler09036742021-06-25 14:25:14 -0500471 the source files pointed to by the :term:`SRC_URI` statements into a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500472 local Git structure. Furthermore, the location for the extracted
473 source is the default area within the ``devtool`` workspace. The
474 result is that the command sets up both the source code and an
475 append file within the workspace while the recipe remains in its
476 original location.
477
478 Additionally, if you have any non-patch local files (i.e. files
Andrew Geissler09036742021-06-25 14:25:14 -0500479 referred to with ``file://`` entries in :term:`SRC_URI` statement
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500480 excluding ``*.patch/`` or ``*.diff``), these files are copied to
481 an ``oe-local-files`` folder under the newly created source tree.
482 Copying the files here gives you a convenient area from which you
483 can modify the files. Any changes or additions you make to those
484 files are incorporated into the build the next time you build the
485 software just as are other changes you might have made to the
486 source.
487
488 - *Middle*: The middle scenario in the figure represents a situation
489 where the source code also does not exist locally. In this case,
490 the code is again upstream and needs to be extracted to some local
491 area as a Git repository. The recipe, in this scenario, is again
492 local and in its own layer outside the workspace.
493
494 The following command tells ``devtool`` the recipe with which to
495 work and, in this case, identifies a local area for the extracted
496 source files that exists outside of the default ``devtool``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500497 workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500498
499 $ devtool modify recipe srctree
500
501 .. note::
502
Andrew Geissler220dafd2023-10-04 10:18:08 -0500503 You cannot provide a URL for ``srctree`` using the ``devtool`` command.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500504
Andrew Geissler09036742021-06-25 14:25:14 -0500505 As with all extractions, the command uses the recipe's :term:`SRC_URI`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500506 statements to locate the source files and any associated patch
507 files. Non-patch files are copied to an ``oe-local-files`` folder
508 under the newly created source tree.
509
510 Once the files are located, the command by default extracts them
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700511 into ``srctree``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500512
513 Within workspace, ``devtool`` creates an append file for the
514 recipe. The recipe remains in its original location but the source
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700515 files are extracted to the location you provide with ``srctree``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500516
517 - *Right*: The right scenario in the figure represents a situation
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700518 where the source tree (``srctree``) already exists locally as a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500519 previously extracted Git structure outside of the ``devtool``
520 workspace. In this example, the recipe also exists elsewhere
521 locally in its own layer.
522
523 The following command tells ``devtool`` the recipe with which to
524 work, uses the "-n" option to indicate source does not need to be
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700525 extracted, and uses ``srctree`` to point to the previously extracted
Andrew Geisslerc926e172021-05-07 16:11:35 -0500526 source files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500527
528 $ devtool modify -n recipe srctree
529
530 If an ``oe-local-files`` subdirectory happens to exist and it
531 contains non-patch files, the files are used. However, if the
532 subdirectory does not exist and you run the ``devtool finish``
533 command, any non-patch files that might exist next to the recipe
534 are removed because it appears to ``devtool`` that you have
535 deleted those files.
536
537 Once the ``devtool modify`` command finishes, it creates only an
538 append file for the recipe in the ``devtool`` workspace. The
539 recipe and the source code remain in their original locations.
540
Andrew Geissler517393d2023-01-13 08:55:19 -0600541#. *Edit the Source*: Once you have used the ``devtool modify`` command,
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500542 you are free to make changes to the source files. You can use any
543 editor you like to make and save your source code modifications.
544
Andrew Geissler517393d2023-01-13 08:55:19 -0600545#. *Build the Recipe or Rebuild the Image*: The next step you take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500546 depends on what you are going to do with the new code.
547
548 If you need to eventually move the build output to the target
Andrew Geisslerc926e172021-05-07 16:11:35 -0500549 hardware, use the following ``devtool`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500550
551 $ devtool build recipe
552
553 On the other hand, if you want an image to contain the recipe's
554 packages from the workspace for immediate deployment onto a device
555 (e.g. for testing purposes), you can use the ``devtool build-image``
Andrew Geissler220dafd2023-10-04 10:18:08 -0500556 command::
557
558 $ devtool build-image image
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500559
Andrew Geissler517393d2023-01-13 08:55:19 -0600560#. *Deploy the Build Output*: When you use the ``devtool build`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500561 to build out your recipe, you probably want to see if the resulting
562 build output works as expected on target hardware.
563
564 .. note::
565
566 This step assumes you have a previously built image that is
567 already either running in QEMU or running on actual hardware.
568 Also, it is assumed that for deployment of the image to the
569 target, SSH is installed in the image and if the image is running
570 on real hardware that you have network access to and from your
571 development machine.
572
573 You can deploy your build output to that target hardware by using the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500574 ``devtool deploy-target`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500575
576 $ devtool deploy-target recipe target
577
578 The target is a live target machine running as an SSH server.
579
580 You can, of course, use other methods to deploy the image you built
581 using the ``devtool build-image`` command to actual hardware.
582 ``devtool`` does not provide a specific command to deploy the image
583 to actual hardware.
584
Andrew Geissler517393d2023-01-13 08:55:19 -0600585#. *Finish Your Work With the Recipe*: The ``devtool finish`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500586 creates any patches corresponding to commits in the local Git
587 repository, updates the recipe to point to them (or creates a
588 ``.bbappend`` file to do so, depending on the specified destination
589 layer), and then resets the recipe so that the recipe is built
Andrew Geissler517393d2023-01-13 08:55:19 -0600590 normally rather than from the workspace::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500591
592 $ devtool finish recipe layer
593
594 .. note::
595
596 Any changes you want to turn into patches must be staged and
597 committed within the local Git repository before you use the
Andrew Geissler220dafd2023-10-04 10:18:08 -0500598 ``devtool finish`` command.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500599
600 Because there is no need to move the recipe, ``devtool finish``
601 either updates the original recipe in the original layer or the
602 command creates a ``.bbappend`` file in a different layer as provided
603 by layer. Any work you did in the ``oe-local-files`` directory is
604 preserved in the original files next to the recipe during the
605 ``devtool finish`` command.
606
607 As a final process of the ``devtool finish`` command, the state of
608 the standard layers and the upstream source is restored so that you
609 can build the recipe from those areas rather than from the workspace.
610
611 .. note::
612
Andrew Geissler220dafd2023-10-04 10:18:08 -0500613 You can use the ``devtool reset`` command to put things back should you
614 decide you do not want to proceed with your work. If you do use this
615 command, realize that the source tree is preserved.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500616
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500617Use ``devtool upgrade`` to Create a Version of the Recipe that Supports a Newer Version of the Software
618-------------------------------------------------------------------------------------------------------
619
620The ``devtool upgrade`` command upgrades an existing recipe to that of a
621more up-to-date version found upstream. Throughout the life of software,
622recipes continually undergo version upgrades by their upstream
623publishers. You can use the ``devtool upgrade`` workflow to make sure
624your recipes you are using for builds are up-to-date with their upstream
625counterparts.
626
627.. note::
628
Andrew Geissler220dafd2023-10-04 10:18:08 -0500629 Several methods exist by which you can upgrade recipes ---
630 ``devtool upgrade`` happens to be one. You can read about all the methods by
631 which you can upgrade recipes in the
632 :ref:`dev-manual/upgrading-recipes:upgrading recipes` section of the Yocto
633 Project Development Tasks Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500634
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500635The ``devtool upgrade`` command is flexible enough to allow you to specify
636source code revision and versioning schemes, extract code into or out of the
637``devtool`` :ref:`devtool-the-workspace-layer-structure`, and work with any
638source file forms that the
639:ref:`bitbake-user-manual/bitbake-user-manual-fetching:fetchers` support.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500640
641The following diagram shows the common development flow used with the
642``devtool upgrade`` command:
643
644.. image:: figures/sdk-devtool-upgrade-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -0500645 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500646
Andrew Geissler517393d2023-01-13 08:55:19 -0600647#. *Initiate the Upgrade*: The top part of the flow shows the typical
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500648 scenario by which you use the ``devtool upgrade`` command. The
649 following conditions exist:
650
651 - The recipe exists in a local layer external to the ``devtool``
652 workspace.
653
654 - The source files for the new release exist in the same location
655 pointed to by :term:`SRC_URI`
656 in the recipe (e.g. a tarball with the new version number in the
657 name, or as a different revision in the upstream Git repository).
658
659 A common situation is where third-party software has undergone a
660 revision so that it has been upgraded. The recipe you have access to
661 is likely in your own layer. Thus, you need to upgrade the recipe to
Andrew Geisslerc926e172021-05-07 16:11:35 -0500662 use the newer version of the software::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500663
664 $ devtool upgrade -V version recipe
665
666 By default, the ``devtool upgrade`` command extracts source
667 code into the ``sources`` directory in the
668 :ref:`devtool-the-workspace-layer-structure`.
669 If you want the code extracted to any other location, you need to
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700670 provide the ``srctree`` positional argument with the command as follows::
671
672 $ devtool upgrade -V version recipe srctree
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500673
674 .. note::
675
676 In this example, the "-V" option specifies the new version. If you
677 don't use "-V", the command upgrades the recipe to the latest
678 version.
679
Andrew Geissler09036742021-06-25 14:25:14 -0500680 If the source files pointed to by the :term:`SRC_URI` statement in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500681 recipe are in a Git repository, you must provide the "-S" option and
682 specify a revision for the software.
683
Andrew Geissler09036742021-06-25 14:25:14 -0500684 Once ``devtool`` locates the recipe, it uses the :term:`SRC_URI` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500685 to locate the source code and any local patch files from other
686 developers. The result is that the command sets up the source code,
687 the new version of the recipe, and an append file all within the
688 workspace.
689
690 Additionally, if you have any non-patch local files (i.e. files
Andrew Geissler09036742021-06-25 14:25:14 -0500691 referred to with ``file://`` entries in :term:`SRC_URI` statement
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500692 excluding ``*.patch/`` or ``*.diff``), these files are copied to an
693 ``oe-local-files`` folder under the newly created source tree.
694 Copying the files here gives you a convenient area from which you can
695 modify the files. Any changes or additions you make to those files
696 are incorporated into the build the next time you build the software
697 just as are other changes you might have made to the source.
698
Andrew Geissler517393d2023-01-13 08:55:19 -0600699#. *Resolve any Conflicts created by the Upgrade*: Conflicts could happen
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700700 after upgrading the software to a new version. Conflicts occur
Andrew Geissler09036742021-06-25 14:25:14 -0500701 if your recipe specifies some patch files in :term:`SRC_URI` that
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500702 conflict with changes made in the new version of the software. For
703 such cases, you need to resolve the conflicts by editing the source
704 and following the normal ``git rebase`` conflict resolution process.
705
706 Before moving onto the next step, be sure to resolve any such
707 conflicts created through use of a newer or different version of the
708 software.
709
Andrew Geissler517393d2023-01-13 08:55:19 -0600710#. *Build the Recipe or Rebuild the Image*: The next step you take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500711 depends on what you are going to do with the new code.
712
713 If you need to eventually move the build output to the target
Andrew Geisslerc926e172021-05-07 16:11:35 -0500714 hardware, use the following ``devtool`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500715
716 $ devtool build recipe
717
718 On the other hand, if you want an image to contain the recipe's
719 packages from the workspace for immediate deployment onto a device
720 (e.g. for testing purposes), you can use the ``devtool build-image``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500721 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500722
723 $ devtool build-image image
724
Andrew Geissler517393d2023-01-13 08:55:19 -0600725#. *Deploy the Build Output*: When you use the ``devtool build`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500726 or ``bitbake`` to build your recipe, you probably want to see if the
727 resulting build output works as expected on target hardware.
728
729 .. note::
730
731 This step assumes you have a previously built image that is
732 already either running in QEMU or running on actual hardware.
733 Also, it is assumed that for deployment of the image to the
734 target, SSH is installed in the image and if the image is running
735 on real hardware that you have network access to and from your
736 development machine.
737
738 You can deploy your build output to that target hardware by using the
Andrew Geissler220dafd2023-10-04 10:18:08 -0500739 ``devtool deploy-target`` command::
740
741 $ devtool deploy-target recipe target
742
743 The target is a live target machine running as an SSH server.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500744
745 You can, of course, also deploy the image you build using the
746 ``devtool build-image`` command to actual hardware. However,
747 ``devtool`` does not provide a specific command that allows you to do
748 this.
749
Andrew Geissler517393d2023-01-13 08:55:19 -0600750#. *Finish Your Work With the Recipe*: The ``devtool finish`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500751 creates any patches corresponding to commits in the local Git
752 repository, moves the new recipe to a more permanent layer, and then
753 resets the recipe so that the recipe is built normally rather than
754 from the workspace.
755
756 Any work you did in the ``oe-local-files`` directory is preserved in
757 the original files next to the recipe during the ``devtool finish``
758 command.
759
760 If you specify a destination layer that is the same as the original
761 source, then the old version of the recipe and associated files are
Andrew Geissler517393d2023-01-13 08:55:19 -0600762 removed prior to adding the new version::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500763
764 $ devtool finish recipe layer
765
766 .. note::
767
768 Any changes you want to turn into patches must be committed to the
769 Git repository in the source tree.
770
771 As a final process of the ``devtool finish`` command, the state of
772 the standard layers and the upstream source is restored so that you
773 can build the recipe from those areas rather than the workspace.
774
775 .. note::
776
Andrew Geissler220dafd2023-10-04 10:18:08 -0500777 You can use the ``devtool reset`` command to put things back should you
778 decide you do not want to proceed with your work. If you do use this
779 command, realize that the source tree is preserved.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500780
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500781A Closer Look at ``devtool add``
782================================
783
784The ``devtool add`` command automatically creates a recipe based on the
785source tree you provide with the command. Currently, the command has
786support for the following:
787
788- Autotools (``autoconf`` and ``automake``)
789
790- CMake
791
792- Scons
793
794- ``qmake``
795
796- Plain ``Makefile``
797
798- Out-of-tree kernel module
799
800- Binary package (i.e. "-b" option)
801
802- Node.js module
803
804- Python modules that use ``setuptools`` or ``distutils``
805
806Apart from binary packages, the determination of how a source tree
807should be treated is automatic based on the files present within that
808source tree. For example, if a ``CMakeLists.txt`` file is found, then
809the source tree is assumed to be using CMake and is treated accordingly.
810
811.. note::
812
813 In most cases, you need to edit the automatically generated recipe in
814 order to make it build properly. Typically, you would go through
815 several edit and build cycles until the recipe successfully builds.
816 Once the recipe builds, you could use possible further iterations to
817 test the recipe on the target device.
818
819The remainder of this section covers specifics regarding how parts of
820the recipe are generated.
821
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500822Name and Version
823----------------
824
825If you do not specify a name and version on the command line,
826``devtool add`` uses various metadata within the source tree in an
827attempt to determine the name and version of the software being built.
828Based on what the tool determines, ``devtool`` sets the name of the
829created recipe file accordingly.
830
831If ``devtool`` cannot determine the name and version, the command prints
832an error. For such cases, you must re-run the command and provide the
833name and version, just the name, or just the version as part of the
834command line.
835
836Sometimes the name or version determined from the source tree might be
Andrew Geisslerc926e172021-05-07 16:11:35 -0500837incorrect. For such a case, you must reset the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500838
839 $ devtool reset -n recipename
840
841After running the ``devtool reset`` command, you need to
842run ``devtool add`` again and provide the name or the version.
843
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500844Dependency Detection and Mapping
845--------------------------------
846
Andrew Geissler220dafd2023-10-04 10:18:08 -0500847The ``devtool add`` command attempts to detect build-time dependencies and map
848them to other recipes in the system. During this mapping, the command fills in
849the names of those recipes as part of the :term:`DEPENDS` variable within the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500850recipe. If a dependency cannot be mapped, ``devtool`` places a comment
851in the recipe indicating such. The inability to map a dependency can
852result from naming not being recognized or because the dependency simply
853is not available. For cases where the dependency is not available, you
854must use the ``devtool add`` command to add an additional recipe that
855satisfies the dependency. Once you add that recipe, you need to update
Andrew Geissler09036742021-06-25 14:25:14 -0500856the :term:`DEPENDS` variable in the original recipe to include the new
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500857recipe.
858
859If you need to add runtime dependencies, you can do so by adding the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500860following to your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500861
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500862 RDEPENDS:${PN} += "dependency1 dependency2 ..."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500863
864.. note::
865
Andrew Geissler220dafd2023-10-04 10:18:08 -0500866 The ``devtool add`` command often cannot distinguish between mandatory and
867 optional dependencies. Consequently, some of the detected dependencies might
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500868 in fact be optional. When in doubt, consult the documentation or the
869 configure script for the software the recipe is building for further
870 details. In some cases, you might find you can substitute the
871 dependency with an option that disables the associated functionality
872 passed to the configure script.
873
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500874License Detection
875-----------------
876
Andrew Geissler220dafd2023-10-04 10:18:08 -0500877The ``devtool add`` command attempts to determine if the software you are
878adding is able to be distributed under a common, open-source license. If
879so, the command sets the :term:`LICENSE` value accordingly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500880You should double-check the value added by the command against the
881documentation or source files for the software you are building and, if
Andrew Geissler09036742021-06-25 14:25:14 -0500882necessary, update that :term:`LICENSE` value.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500883
Andrew Geissler220dafd2023-10-04 10:18:08 -0500884The ``devtool add`` command also sets the :term:`LIC_FILES_CHKSUM`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500885value to point to all files that appear to be license-related. Realize
886that license statements often appear in comments at the top of source
887files or within the documentation. In such cases, the command does not
888recognize those license statements. Consequently, you might need to
Andrew Geissler09036742021-06-25 14:25:14 -0500889amend the :term:`LIC_FILES_CHKSUM` variable to point to one or more of those
890comments if present. Setting :term:`LIC_FILES_CHKSUM` is particularly
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500891important for third-party software. The mechanism attempts to ensure
892correct licensing should you upgrade the recipe to a newer upstream
893version in future. Any change in licensing is detected and you receive
894an error prompting you to check the license text again.
895
896If the ``devtool add`` command cannot determine licensing information,
Andrew Geissler09036742021-06-25 14:25:14 -0500897``devtool`` sets the :term:`LICENSE` value to "CLOSED" and leaves the
898:term:`LIC_FILES_CHKSUM` value unset. This behavior allows you to continue
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500899with development even though the settings are unlikely to be correct in
900all cases. You should check the documentation or source files for the
901software you are building to determine the actual license.
902
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500903Adding Makefile-Only Software
904-----------------------------
905
906The use of Make by itself is very common in both proprietary and
907open-source software. Unfortunately, Makefiles are often not written
908with cross-compilation in mind. Thus, ``devtool add`` often cannot do
909very much to ensure that these Makefiles build correctly. It is very
910common, for example, to explicitly call ``gcc`` instead of using the
911:term:`CC` variable. Usually, in a
912cross-compilation environment, ``gcc`` is the compiler for the build
913host and the cross-compiler is named something similar to
914``arm-poky-linux-gnueabi-gcc`` and might require arguments (e.g. to
915point to the associated sysroot for the target machine).
916
917When writing a recipe for Makefile-only software, keep the following in
918mind:
919
920- You probably need to patch the Makefile to use variables instead of
921 hardcoding tools within the toolchain such as ``gcc`` and ``g++``.
922
923- The environment in which Make runs is set up with various standard
Andrew Geissler09036742021-06-25 14:25:14 -0500924 variables for compilation (e.g. :term:`CC`, :term:`CXX`, and so forth) in a
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500925 similar manner to the environment set up by the SDK's environment
926 setup script. One easy way to see these variables is to run the
927 ``devtool build`` command on the recipe and then look in
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700928 ``oe-logs/run.do_compile``. Towards the top of this file, there is
929 a list of environment variables that are set. You can take
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500930 advantage of these variables within the Makefile.
931
932- If the Makefile sets a default for a variable using "=", that default
933 overrides the value set in the environment, which is usually not
934 desirable. For this case, you can either patch the Makefile so it
935 sets the default using the "?=" operator, or you can alternatively
936 force the value on the ``make`` command line. To force the value on
937 the command line, add the variable setting to
938 :term:`EXTRA_OEMAKE` or
939 :term:`PACKAGECONFIG_CONFARGS`
Andrew Geissler09036742021-06-25 14:25:14 -0500940 within the recipe. Here is an example using :term:`EXTRA_OEMAKE`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500941
942 EXTRA_OEMAKE += "'CC=${CC}' 'CXX=${CXX}'"
943
944 In the above example,
945 single quotes are used around the variable settings as the values are
946 likely to contain spaces because required default options are passed
947 to the compiler.
948
949- Hardcoding paths inside Makefiles is often problematic in a
950 cross-compilation environment. This is particularly true because
951 those hardcoded paths often point to locations on the build host and
952 thus will either be read-only or will introduce contamination into
953 the cross-compilation because they are specific to the build host
954 rather than the target. Patching the Makefile to use prefix variables
955 or other path variables is usually the way to handle this situation.
956
957- Sometimes a Makefile runs target-specific commands such as
958 ``ldconfig``. For such cases, you might be able to apply patches that
959 remove these commands from the Makefile.
960
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500961Adding Native Tools
962-------------------
963
Andrew Geissler220dafd2023-10-04 10:18:08 -0500964Often, you need to build additional tools that run on the :term:`Build Host`
965as opposed to the target. You should indicate this requirement by using one of
966the following methods when you run ``devtool add``:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500967
968- Specify the name of the recipe such that it ends with "-native".
969 Specifying the name like this produces a recipe that only builds for
970 the build host.
971
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700972- Specify the "--also-native" option with the ``devtool add``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500973 command. Specifying this option creates a recipe file that still
974 builds for the target but also creates a variant with a "-native"
975 suffix that builds for the build host.
976
977.. note::
978
979 If you need to add a tool that is shipped as part of a source tree
980 that builds code for the target, you can typically accomplish this by
981 building the native and target parts separately rather than within
982 the same compilation process. Realize though that with the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700983 "--also-native" option, you can add the tool using just one
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500984 recipe file.
985
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500986Adding Node.js Modules
987----------------------
988
989You can use the ``devtool add`` command two different ways to add
Andrew Geissler220dafd2023-10-04 10:18:08 -0500990Node.js modules: through ``npm`` or from a repository or local source.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500991
Andrew Geisslerc926e172021-05-07 16:11:35 -0500992Use the following form to add Node.js modules through ``npm``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500993
994 $ devtool add "npm://registry.npmjs.org;name=forever;version=0.15.1"
995
996The name and
997version parameters are mandatory. Lockdown and shrinkwrap files are
998generated and pointed to by the recipe in order to freeze the version
999that is fetched for the dependencies according to the first time. This
1000also saves checksums that are verified on future fetches. Together,
1001these behaviors ensure the reproducibility and integrity of the build.
1002
1003.. note::
1004
Andrew Geissler220dafd2023-10-04 10:18:08 -05001005 - You must use quotes around the URL. ``devtool add`` does not
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001006 require the quotes, but the shell considers ";" as a splitter
1007 between multiple commands. Thus, without the quotes,
1008 ``devtool add`` does not receive the other parts, which results in
1009 several "command not found" errors.
1010
1011 - In order to support adding Node.js modules, a ``nodejs`` recipe
1012 must be part of your SDK.
1013
1014As mentioned earlier, you can also add Node.js modules directly from a
1015repository or local source tree. To add modules this way, use
Andrew Geisslerc926e172021-05-07 16:11:35 -05001016``devtool add`` in the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001017
1018 $ devtool add https://github.com/diversario/node-ssdp
1019
Andrew Geissler220dafd2023-10-04 10:18:08 -05001020In this example, ``devtool`` fetches the specified Git repository, detects the
1021code as Node.js code, fetches dependencies using ``npm``, and sets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001022:term:`SRC_URI` accordingly.
1023
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001024Working With Recipes
1025====================
1026
1027When building a recipe using the ``devtool build`` command, the typical
1028build progresses as follows:
1029
Andrew Geissler517393d2023-01-13 08:55:19 -06001030#. Fetch the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001031
Andrew Geissler517393d2023-01-13 08:55:19 -06001032#. Unpack the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001033
Andrew Geissler517393d2023-01-13 08:55:19 -06001034#. Configure the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001035
Andrew Geissler517393d2023-01-13 08:55:19 -06001036#. Compile the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001037
Andrew Geissler517393d2023-01-13 08:55:19 -06001038#. Install the build output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001039
Andrew Geissler517393d2023-01-13 08:55:19 -06001040#. Package the installed output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001041
1042For recipes in the workspace, fetching and unpacking is disabled as the
1043source tree has already been prepared and is persistent. Each of these
1044build steps is defined as a function (task), usually with a "do\_" prefix
1045(e.g. :ref:`ref-tasks-fetch`,
1046:ref:`ref-tasks-unpack`, and so
1047forth). These functions are typically shell scripts but can instead be
1048written in Python.
1049
1050If you look at the contents of a recipe, you will see that the recipe
1051does not include complete instructions for building the software.
1052Instead, common functionality is encapsulated in classes inherited with
1053the ``inherit`` directive. This technique leaves the recipe to describe
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001054just the things that are specific to the software being built. There is
Andrew Geissler517393d2023-01-13 08:55:19 -06001055a :ref:`ref-classes-base` class that is implicitly inherited by all recipes
1056and provides the functionality that most recipes typically need.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001057
1058The remainder of this section presents information useful when working
1059with recipes.
1060
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001061Finding Logs and Work Files
1062---------------------------
1063
1064After the first run of the ``devtool build`` command, recipes that were
1065previously created using the ``devtool add`` command or whose sources
1066were modified using the ``devtool modify`` command contain symbolic
1067links created within the source tree:
1068
1069- ``oe-logs``: This link points to the directory in which log files and
1070 run scripts for each build step are created.
1071
1072- ``oe-workdir``: This link points to the temporary work area for the
1073 recipe. The following locations under ``oe-workdir`` are particularly
1074 useful:
1075
1076 - ``image/``: Contains all of the files installed during the
1077 :ref:`ref-tasks-install` stage.
1078 Within a recipe, this directory is referred to by the expression
1079 ``${``\ :term:`D`\ ``}``.
1080
1081 - ``sysroot-destdir/``: Contains a subset of files installed within
Patrick Williams2194f502022-10-16 14:26:09 -05001082 :ref:`ref-tasks-install` that have been put into the shared sysroot. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001083 more information, see the
Andrew Geissler517393d2023-01-13 08:55:19 -06001084 ":ref:`dev-manual/new-recipe:sharing files between recipes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001085
1086 - ``packages-split/``: Contains subdirectories for each package
1087 produced by the recipe. For more information, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001088 ":ref:`sdk-manual/extensible:packaging`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001089
1090You can use these links to get more information on what is happening at
1091each build step.
1092
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001093Setting Configure Arguments
1094---------------------------
1095
1096If the software your recipe is building uses GNU autoconf, then a fixed
1097set of arguments is passed to it to enable cross-compilation plus any
Andrew Geissler220dafd2023-10-04 10:18:08 -05001098extras specified by :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001099set within the recipe. If you wish to pass additional options, add them
Andrew Geissler09036742021-06-25 14:25:14 -05001100to :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`. Other supported build
Andrew Geissler220dafd2023-10-04 10:18:08 -05001101tools have similar variables (e.g. :term:`EXTRA_OECMAKE` for CMake,
1102:term:`EXTRA_OESCONS` for Scons, and so forth). If you need to pass anything on
1103the ``make`` command line, you can use :term:`EXTRA_OEMAKE` or the
1104:term:`PACKAGECONFIG_CONFARGS` variables to do so.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001105
1106You can use the ``devtool configure-help`` command to help you set the
1107arguments listed in the previous paragraph. The command determines the
1108exact options being passed, and shows them to you along with any custom
Andrew Geissler09036742021-06-25 14:25:14 -05001109arguments specified through :term:`EXTRA_OECONF` or
1110:term:`PACKAGECONFIG_CONFARGS`. If applicable, the command also shows you
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001111the output of the configure script's "--help" option as a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001112reference.
1113
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001114Sharing Files Between Recipes
1115-----------------------------
1116
1117Recipes often need to use files provided by other recipes on the
1118:term:`Build Host`. For example,
1119an application linking to a common library needs access to the library
1120itself and its associated headers. The way this access is accomplished
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001121within the extensible SDK is through the sysroot. There is one sysroot per
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001122"machine" for which the SDK is being built. In practical terms, this
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001123means there is a sysroot for the target machine, and a sysroot for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001124the build host.
1125
1126Recipes should never write files directly into the sysroot. Instead,
1127files should be installed into standard locations during the
Andrew Geissler220dafd2023-10-04 10:18:08 -05001128:ref:`ref-tasks-install` task within the ``${``\ :term:`D`\ ``}`` directory. A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001129subset of these files automatically goes into the sysroot. The reason
1130for this limitation is that almost all files that go into the sysroot
1131are cataloged in manifests in order to ensure they can be removed later
1132when a recipe is modified or removed. Thus, the sysroot is able to
1133remain free from stale files.
1134
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001135Packaging
1136---------
1137
1138Packaging is not always particularly relevant within the extensible SDK.
1139However, if you examine how build output gets into the final image on
1140the target device, it is important to understand packaging because the
1141contents of the image are expressed in terms of packages and not
1142recipes.
1143
Andrew Geissler220dafd2023-10-04 10:18:08 -05001144During the :ref:`ref-tasks-package` task, files installed during the
1145:ref:`ref-tasks-install` task are split into one main package, which is almost
1146always named the same as the recipe, and into several other packages. This
1147separation exists because not all of those installed files are useful in every
1148image. For example, you probably do not need any of the documentation installed
1149in a production image. Consequently, for each recipe the documentation
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001150files are separated into a ``-doc`` package. Recipes that package
1151software containing optional modules or plugins might undergo additional
1152package splitting as well.
1153
1154After building a recipe, you can see where files have gone by looking in
1155the ``oe-workdir/packages-split`` directory, which contains a
1156subdirectory for each package. Apart from some advanced cases, the
Andrew Geissler220dafd2023-10-04 10:18:08 -05001157:term:`PACKAGES` and :term:`FILES` variables controls
Andrew Geissler09036742021-06-25 14:25:14 -05001158splitting. The :term:`PACKAGES` variable lists all of the packages to be
1159produced, while the :term:`FILES` variable specifies which files to include
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001160in each package by using an override to specify the package. For
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001161example, ``FILES:${PN}`` specifies the files to go into the main package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001162(i.e. the main package has the same name as the recipe and
1163``${``\ :term:`PN`\ ``}`` evaluates to the
Andrew Geissler09036742021-06-25 14:25:14 -05001164recipe name). The order of the :term:`PACKAGES` value is significant. For
1165each installed file, the first package whose :term:`FILES` value matches the
1166file is the package into which the file goes. Both the :term:`PACKAGES` and
1167:term:`FILES` variables have default values. Consequently, you might find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001168you do not even need to set these variables in your recipe unless the
1169software the recipe is building installs files into non-standard
1170locations.
1171
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001172Restoring the Target Device to its Original State
1173=================================================
1174
1175If you use the ``devtool deploy-target`` command to write a recipe's
1176build output to the target, and you are working on an existing component
1177of the system, then you might find yourself in a situation where you
1178need to restore the original files that existed prior to running the
1179``devtool deploy-target`` command. Because the ``devtool deploy-target``
1180command backs up any files it overwrites, you can use the
1181``devtool undeploy-target`` command to restore those files and remove
Andrew Geisslerc926e172021-05-07 16:11:35 -05001182any other files the recipe deployed. Consider the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001183
1184 $ devtool undeploy-target lighttpd root@192.168.7.2
1185
1186If you have deployed
1187multiple applications, you can remove them all using the "-a" option
Andrew Geisslerc926e172021-05-07 16:11:35 -05001188thus restoring the target device to its original state::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001189
1190 $ devtool undeploy-target -a root@192.168.7.2
1191
1192Information about files deployed to
1193the target as well as any backed up files are stored on the target
1194itself. This storage, of course, requires some additional space on the
1195target machine.
1196
1197.. note::
1198
Andrew Geissler220dafd2023-10-04 10:18:08 -05001199 The ``devtool deploy-target`` and ``devtool undeploy-target`` commands do
1200 not currently interact with any package management system on the target
1201 device (e.g. RPM or OPKG). Consequently, you should not intermingle
1202 ``devtool deploy-target`` and package manager operations on the target
1203 device. Doing so could result in a conflicting set of files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001204
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001205Installing Additional Items Into the Extensible SDK
1206===================================================
1207
1208Out of the box the extensible SDK typically only comes with a small
1209number of tools and libraries. A minimal SDK starts mostly empty and is
1210populated on-demand. Sometimes you must explicitly install extra items
1211into the SDK. If you need these extra items, you can first search for
1212the items using the ``devtool search`` command. For example, suppose you
1213need to link to libGL but you are not sure which recipe provides libGL.
Andrew Geisslerc926e172021-05-07 16:11:35 -05001214You can use the following command to find out::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001215
1216 $ devtool search libGL mesa
Patrick Williams92b42cb2022-09-03 06:53:57 -05001217 A free implementation of the OpenGL API
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001218
Patrick Williams92b42cb2022-09-03 06:53:57 -05001219Once you know the recipe
1220(i.e. ``mesa`` in this example), you can install it.
1221
1222When using the extensible SDK directly in a Yocto build
1223-------------------------------------------------------
1224
1225In this scenario, the Yocto build tooling, e.g. ``bitbake``
1226is directly accessible to build additional items, and it
Andrew Geissler220dafd2023-10-04 10:18:08 -05001227can simply be executed directly::
Patrick Williams92b42cb2022-09-03 06:53:57 -05001228
1229 $ bitbake mesa
Patrick Williams975a06f2022-10-21 14:42:47 -05001230 $ bitbake build-sysroots
Patrick Williams92b42cb2022-09-03 06:53:57 -05001231
1232When using a standalone installer for the Extensible SDK
1233--------------------------------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001234
Andrew Geissler220dafd2023-10-04 10:18:08 -05001235::
1236
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001237 $ devtool sdk-install mesa
1238
1239By default, the ``devtool sdk-install`` command assumes
1240the item is available in pre-built form from your SDK provider. If the
1241item is not available and it is acceptable to build the item from
Andrew Geisslerc926e172021-05-07 16:11:35 -05001242source, you can add the "-s" option as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001243
1244 $ devtool sdk-install -s mesa
1245
1246It is important to remember that building the item from source
1247takes significantly longer than installing the pre-built artifact. Also,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001248if there is no recipe for the item you want to add to the SDK, you must
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001249instead add the item using the ``devtool add`` command.
1250
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001251Applying Updates to an Installed Extensible SDK
1252===============================================
1253
1254If you are working with an installed extensible SDK that gets
1255occasionally updated (e.g. a third-party SDK), then you will need to
1256manually "pull down" the updates into the installed SDK.
1257
Andrew Geisslerc926e172021-05-07 16:11:35 -05001258To update your installed SDK, use ``devtool`` as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001259
1260 $ devtool sdk-update
1261
Andrew Geissler220dafd2023-10-04 10:18:08 -05001262The previous command assumes your SDK provider has set the default update URL
1263for you through the :term:`SDK_UPDATE_URL` variable as described in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001264":ref:`sdk-manual/appendix-customizing:Providing Updates to the Extensible SDK After Installation`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001265section. If the SDK provider has not set that default URL, you need to
Andrew Geissler220dafd2023-10-04 10:18:08 -05001266specify it yourself in the command as follows::
1267
1268 $ devtool sdk-update path_to_update_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001269
1270.. note::
1271
1272 The URL needs to point specifically to a published SDK and not to an
1273 SDK installer that you would download and install.
1274
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001275Creating a Derivative SDK With Additional Components
1276====================================================
1277
1278You might need to produce an SDK that contains your own custom
1279libraries. A good example would be if you were a vendor with customers
1280that use your SDK to build their own platform-specific software and
1281those customers need an SDK that has custom libraries. In such a case,
1282you can produce a derivative SDK based on the currently installed SDK
1283fairly easily by following these steps:
1284
Andrew Geissler517393d2023-01-13 08:55:19 -06001285#. If necessary, install an extensible SDK that you want to use as a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001286 base for your derivative SDK.
1287
Andrew Geissler517393d2023-01-13 08:55:19 -06001288#. Source the environment script for the SDK.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001289
Andrew Geissler517393d2023-01-13 08:55:19 -06001290#. Add the extra libraries or other components you want by using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001291 ``devtool add`` command.
1292
Andrew Geissler517393d2023-01-13 08:55:19 -06001293#. Run the ``devtool build-sdk`` command.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001294
1295The previous steps take the recipes added to the workspace and construct
1296a new SDK installer that contains those recipes and the resulting binary
1297artifacts. The recipes go into their own separate layer in the
1298constructed derivative SDK, which leaves the workspace clean and ready
1299for users to add their own recipes.