blob: 1496476be91ee57c3b9cd03e6c97629c9278d1fe [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
3[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='sdk-extensible'>
6
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007 <title>Using the Extensible SDK</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05008
9 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010 This chapter describes the extensible SDK and how to install it.
11 Information covers the pieces of the SDK, how to install it, and
12 presents a look at using the <filename>devtool</filename>
13 functionality.
14 The extensible SDK makes it easy to add new applications and libraries
15 to an image, modify the source for an existing component, test
16 changes on the target hardware, and ease integration into the rest of
17 the
18 <ulink url='&YOCTO_DOCS_DEV_URL;#build-system-term'>OpenEmbedded build system</ulink>.
19 <note>
20 For a side-by-side comparison of main features supported for an
21 extensible SDK as compared to a standard SDK, see the
22 "<link linkend='sdk-manual-intro'>Introduction</link>"
23 section.
24 </note>
25 </para>
26
27 <para>
28 In addition to the functionality available through
29 <filename>devtool</filename>, you can alternatively make use of the
30 toolchain directly, for example from Makefile, Autotools, and
31 Eclipse-based projects.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032 See the
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033 "<link linkend='sdk-working-projects'>Using the SDK Toolchain Directly</link>"
34 chapter for more information.
35 </para>
36
37 <section id='sdk-extensible-sdk-intro'>
38 <title>Why use the Extensible SDK and What is in It?</title>
39
40 <para>
41 The extensible SDK provides a cross-development toolchain and
42 libraries tailored to the contents of a specific image.
43 You would use the Extensible SDK if you want a toolchain experience
44 supplemented with the powerful set of <filename>devtool</filename>
45 commands tailored for the Yocto Project environment.
46 </para>
47
48 <para>
49 The installed extensible SDK consists of several files and
50 directories.
51 Basically, it contains an SDK environment setup script, some
52 configuration files, an internal build system, and the
53 <filename>devtool</filename> functionality.
54 </para>
55 </section>
56
57 <section id='sdk-setting-up-to-use-the-extensible-sdk'>
58 <title>Setting Up to Use the Extensible SDK</title>
59
60 <para>
61 The first thing you need to do is install the SDK on your host
62 development machine by running the <filename>*.sh</filename>
63 installation script.
64 </para>
65
66 <para>
67 You can download a tarball installer, which includes the
68 pre-built toolchain, the <filename>runqemu</filename>
69 script, the internal build system, <filename>devtool</filename>,
70 and support files from the appropriate directory under
71 <ulink url='&YOCTO_TOOLCHAIN_DL_URL;'></ulink>.
72 Toolchains are available for 32-bit and 64-bit x86 development
73 systems from the <filename>i686</filename> and
74 <filename>x86_64</filename> directories, respectively.
75 The toolchains the Yocto Project provides are based off the
76 <filename>core-image-sato</filename> image and contain
77 libraries appropriate for developing against that image.
78 Each type of development system supports five or more target
79 architectures.
80 </para>
81
82 <para>
83 The names of the tarball installer scripts are such that a
84 string representing the host system appears first in the
85 filename and then is immediately followed by a string
86 representing the target architecture.
87 An extensible SDK has the string "-ext" as part of the name.
88 <literallayout class='monospaced'>
89 poky-glibc-<replaceable>host_system</replaceable>-<replaceable>image_type</replaceable>-<replaceable>arch</replaceable>-toolchain-ext-<replaceable>release_version</replaceable>.sh
90
91 Where:
92 <replaceable>host_system</replaceable> is a string representing your development system:
93
94 i686 or x86_64.
95
96 <replaceable>image_type</replaceable> is the image for which the SDK was built.
97
98 <replaceable>arch</replaceable> is a string representing the tuned target architecture:
99
100 i586, x86_64, powerpc, mips, armv7a or armv5te
101
102 <replaceable>release_version</replaceable> is a string representing the release number of the
103 Yocto Project:
104
105 &DISTRO;, &DISTRO;+snapshot
106 </literallayout>
107 For example, the following SDK installer is for a 64-bit
108 development host system and a i586-tuned target architecture
109 based off the SDK for <filename>core-image-sato</filename> and
110 using the current &DISTRO; snapshot:
111 <literallayout class='monospaced'>
112 poky-glibc-x86_64-core-image-sato-i586-toolchain-ext-&DISTRO;.sh
113 </literallayout>
114 <note>
115 As an alternative to downloading an SDK, you can build the
116 SDK installer.
117 For information on building the installer, see the
118 "<link linkend='sdk-building-an-sdk-installer'>Building an SDK Installer</link>"
119 section.
120 Another helpful resource for building an installer is the
121 <ulink url='https://wiki.yoctoproject.org/wiki/TipsAndTricks/RunningEclipseAgainstBuiltImage'>Cookbook guide to Making an Eclipse Debug Capable Image</ulink>
122 wiki page.
123 This wiki page focuses on development when using the Eclipse
124 IDE.
125 </note>
126 </para>
127
128 <para>
129 The SDK and toolchains are self-contained and by default are
130 installed into the <filename>poky_sdk</filename> folder in your
131 home directory.
132 You can choose to install the extensible SDK in any location when
133 you run the installer.
134 However, the location you choose needs to be writable for whichever
135 users need to use the SDK, since files will need to be written
136 under that directory during the normal course of operation.
137 </para>
138
139 <para>
140 The following command shows how to run the installer given a
141 toolchain tarball for a 64-bit x86 development host system and
142 a 64-bit x86 target architecture.
143 The example assumes the SDK installer is located in
144 <filename>~/Downloads/</filename>.
145 <note>
146 If you do not have write permissions for the directory
147 into which you are installing the SDK, the installer
148 notifies you and exits.
149 Be sure you have write permissions in the directory and
150 run the installer again.
151 </note>
152 <literallayout class='monospaced'>
153 $ ./poky-glibc-x86_64-core-image-minimal-core2-64-toolchain-ext-&DISTRO;.sh
154 Poky (Yocto Project Reference Distro) Extensible SDK installer version &DISTRO;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500155 ===================================================================================
156 Enter target directory for SDK (default: ~/poky_sdk):
157 You are about to install the SDK to "/home/scottrif/poky_sdk". Proceed[Y/n]? Y
158 Extracting SDK......................................................................done
159 Setting it up...
160 Extracting buildtools...
161 Preparing build system...
162 done
163 SDK has been successfully set up and is ready to be used.
164 Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
165 $ . /home/scottrif/poky_sdk/environment-setup-core2-64-poky-linux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600166 </literallayout>
167 </para>
168 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500169
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170 <section id='sdk-running-the-extensible-sdk-environment-setup-script'>
171 <title>Running the Extensible SDK Environment Setup Script</title>
172
173 <para>
174 Once you have the SDK installed, you must run the SDK environment
175 setup script before you can actually use it.
176 This setup script resides in the directory you chose when you
177 installed the SDK, which is either the default
178 <filename>poky_sdk</filename> directory or the directory you
179 chose during installation.
180 </para>
181
182 <para>
183 Before running the script, be sure it is the one that matches the
184 architecture for which you are developing.
185 Environment setup scripts begin with the string
186 "<filename>environment-setup</filename>" and include as part of
187 their name the tuned target architecture.
188 As an example, the following commands set the working directory
189 to where the SDK was installed and then source the environment
190 setup script.
191 In this example, the setup script is for an IA-based
192 target machine using i586 tuning:
193 <literallayout class='monospaced'>
194 $ cd /home/scottrif/poky_sdk
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500195 $ source environment-setup-core2-64-poky-linux
196 SDK environment now set up; additionally you may now run devtool to perform development tasks.
197 Run devtool --help for further details.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600198 </literallayout>
199 When you run the setup script, many environment variables are
200 defined:
201 <literallayout class='monospaced'>
202 <ulink url='&YOCTO_DOCS_REF_URL;#var-SDKTARGETSYSROOT'><filename>SDKTARGETSYSROOT</filename></ulink> - The path to the sysroot used for cross-compilation
203 <ulink url='&YOCTO_DOCS_REF_URL;#var-PKG_CONFIG_PATH'><filename>PKG_CONFIG_PATH</filename></ulink> - The path to the target pkg-config files
204 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_SITE'><filename>CONFIG_SITE</filename></ulink> - A GNU autoconf site file preconfigured for the target
205 <ulink url='&YOCTO_DOCS_REF_URL;#var-CC'><filename>CC</filename></ulink> - The minimal command and arguments to run the C compiler
206 <ulink url='&YOCTO_DOCS_REF_URL;#var-CXX'><filename>CXX</filename></ulink> - The minimal command and arguments to run the C++ compiler
207 <ulink url='&YOCTO_DOCS_REF_URL;#var-CPP'><filename>CPP</filename></ulink> - The minimal command and arguments to run the C preprocessor
208 <ulink url='&YOCTO_DOCS_REF_URL;#var-AS'><filename>AS</filename></ulink> - The minimal command and arguments to run the assembler
209 <ulink url='&YOCTO_DOCS_REF_URL;#var-LD'><filename>LD</filename></ulink> - The minimal command and arguments to run the linker
210 <ulink url='&YOCTO_DOCS_REF_URL;#var-GDB'><filename>GDB</filename></ulink> - The minimal command and arguments to run the GNU Debugger
211 <ulink url='&YOCTO_DOCS_REF_URL;#var-STRIP'><filename>STRIP</filename></ulink> - The minimal command and arguments to run 'strip', which strips symbols
212 <ulink url='&YOCTO_DOCS_REF_URL;#var-RANLIB'><filename>RANLIB</filename></ulink> - The minimal command and arguments to run 'ranlib'
213 <ulink url='&YOCTO_DOCS_REF_URL;#var-OBJCOPY'><filename>OBJCOPY</filename></ulink> - The minimal command and arguments to run 'objcopy'
214 <ulink url='&YOCTO_DOCS_REF_URL;#var-OBJDUMP'><filename>OBJDUMP</filename></ulink> - The minimal command and arguments to run 'objdump'
215 <ulink url='&YOCTO_DOCS_REF_URL;#var-AR'><filename>AR</filename></ulink> - The minimal command and arguments to run 'ar'
216 <ulink url='&YOCTO_DOCS_REF_URL;#var-NM'><filename>NM</filename></ulink> - The minimal command and arguments to run 'nm'
217 <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_PREFIX'><filename>TARGET_PREFIX</filename></ulink> - The toolchain binary prefix for the target tools
218 <ulink url='&YOCTO_DOCS_REF_URL;#var-CROSS_COMPILE'><filename>CROSS_COMPILE</filename></ulink> - The toolchain binary prefix for the target tools
219 <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIGURE_FLAGS'><filename>CONFIGURE_FLAGS</filename></ulink> - The minimal arguments for GNU configure
220 <ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'><filename>CFLAGS</filename></ulink> - Suggested C flags
221 <ulink url='&YOCTO_DOCS_REF_URL;#var-CXXFLAGS'><filename>CXXFLAGS</filename></ulink> - Suggested C++ flags
222 <ulink url='&YOCTO_DOCS_REF_URL;#var-LDFLAGS'><filename>LDFLAGS</filename></ulink> - Suggested linker flags when you use CC to link
223 <ulink url='&YOCTO_DOCS_REF_URL;#var-CPPFLAGS'><filename>CPPFLAGS</filename></ulink> - Suggested preprocessor flags
224 </literallayout>
225 </para>
226 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500227
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600228 <section id='using-devtool-in-your-sdk-workflow'>
229 <title>Using <filename>devtool</filename> in Your SDK Workflow</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500230
231 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600232 The cornerstone of the extensible SDK is a command-line tool
233 called <filename>devtool</filename>.
234 This tool provides a number of features that help
235 you build, test and package software within the extensible SDK, and
236 optionally integrate it into an image built by the OpenEmbedded
237 build system.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500238 </para>
239
240 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600241 The <filename>devtool</filename> command line is organized
242 similarly to
243 <ulink url='&YOCTO_DOCS_DEV_URL;#git'>Git</ulink> in that it has a
244 number of sub-commands for each function.
245 You can run <filename>devtool --help</filename> to see all the
246 commands.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500247 </para>
248
249 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600250 Three <filename>devtool</filename> subcommands that provide
251 entry-points into development are:
252 <itemizedlist>
253 <listitem><para>
254 <emphasis><filename>devtool add</filename></emphasis>:
255 Assists in adding new software to be built.
256 </para></listitem>
257 <listitem><para>
258 <emphasis><filename>devtool modify</filename></emphasis>:
259 Sets up an environment to enable you to modify the source of
260 an existing component.
261 </para></listitem>
262 <listitem><para>
263 <emphasis><filename>devtool upgrade</filename></emphasis>:
264 Updates an existing recipe so that you can build it for
265 an updated set of source files.
266 </para></listitem>
267 </itemizedlist>
268 As with the OpenEmbedded build system, "recipes" represent software
269 packages within <filename>devtool</filename>.
270 When you use <filename>devtool add</filename>, a recipe is
271 automatically created.
272 When you use <filename>devtool modify</filename>, the specified
273 existing recipe is used in order to determine where to get the source
274 code and how to patch it.
275 In both cases, an environment is set up so that when you build the
276 recipe a source tree that is under your control is used in order to
277 allow you to make changes to the source as desired.
278 By default, both new recipes and the source go into a "workspace"
279 directory under the SDK.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280 </para>
281
282 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600283 The remainder of this section presents the
284 <filename>devtool add</filename>,
285 <filename>devtool modify</filename>, and
286 <filename>devtool upgrade</filename> workflows.
287 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500288
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600289 <section id='sdk-use-devtool-to-add-an-application'>
290 <title>Use <filename>devtool add</filename> to Add an Application</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500291
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600292 <para>
293 The <filename>devtool add</filename> command generates
294 a new recipe based on existing source code.
295 This command takes advantage of the
296 <ulink url='&YOCTO_DOCS_DEV_URL;#devtool-the-workspace-layer-structure'>workspace</ulink>
297 layer that many <filename>devtool</filename> commands
298 use.
299 The command is flexible enough to allow you to extract source
300 code into both the workspace or a separate local Git repository
301 and to use existing code that does not need to be extracted.
302 </para>
303
304 <para>
305 Depending on your particular scenario, the arguments and options
306 you use with <filename>devtool add</filename> form different
307 combinations.
308 The following diagram shows common development flows
309 you would use with the <filename>devtool add</filename>
310 command:
311 </para>
312
313 <para>
314 <imagedata fileref="figures/sdk-devtool-add-flow.png" align="center" />
315 </para>
316
317 <para>
318 <orderedlist>
319 <listitem><para><emphasis>Generating the New Recipe</emphasis>:
320 The top part of the flow shows three scenarios by which
321 you could use <filename>devtool add</filename> to
322 generate a recipe based on existing source code.</para>
323
324 <para>In a shared development environment, it is
325 typical where other developers are responsible for
326 various areas of source code.
327 As a developer, you are probably interested in using
328 that source code as part of your development using
329 the Yocto Project.
330 All you need is access to the code, a recipe, and a
331 controlled area in which to do your work.</para>
332
333 <para>Within the diagram, three possible scenarios
334 feed into the <filename>devtool add</filename> workflow:
335 <itemizedlist>
336 <listitem><para><emphasis>Left</emphasis>:
337 The left scenario represents a common situation
338 where the source code does not exist locally
339 and needs to be extracted.
340 In this situation, you just let it get
341 extracted to the default workspace - you do not
342 want it in some specific location outside of the
343 workspace.
344 Thus, everything you need will be located in the
345 workspace:
346 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500347 $ devtool add <replaceable>recipe fetchuri</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600348 </literallayout>
349 With this command, <filename>devtool</filename>
350 creates a recipe and an append file in the
351 workspace as well as extracts the upstream
352 source files into a local Git repository also
353 within the <filename>sources</filename> folder.
354 </para></listitem>
355 <listitem><para><emphasis>Middle</emphasis>:
356 The middle scenario also represents a situation where
357 the source code does not exist locally.
358 In this case, the code is again upstream
359 and needs to be extracted to some
360 local area - this time outside of the default
361 workspace.
362 If required, <filename>devtool</filename>
363 always creates
364 a Git repository locally during the extraction.
365 Furthermore, the first positional argument
366 <replaceable>srctree</replaceable> in this case
367 identifies where the
368 <filename>devtool add</filename> command
369 will locate the extracted code outside of the
370 workspace:
371 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500372 $ devtool add <replaceable>recipe srctree fetchuri</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600373 </literallayout>
374 In summary, the source code is pulled from
375 <replaceable>fetchuri</replaceable> and extracted
376 into the location defined by
377 <replaceable>srctree</replaceable> as a local
378 Git repository.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500379
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600380 <para>Within workspace, <filename>devtool</filename>
381 creates both the recipe and an append file
382 for the recipe.
383 </para></listitem>
384 <listitem><para><emphasis>Right</emphasis>:
385 The right scenario represents a situation
386 where the source tree (srctree) has been
387 previously prepared outside of the
388 <filename>devtool</filename> workspace.
389 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500390
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600391 <para>The following command names the recipe
392 and identifies where the existing source tree
393 is located:
394 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500395 $ devtool add <replaceable>recipe srctree</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600396 </literallayout>
397 The command examines the source code and creates
398 a recipe for it placing the recipe into the
399 workspace.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500400
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600401 <para>Because the extracted source code already exists,
402 <filename>devtool</filename> does not try to
403 relocate it into the workspace - just the new
404 the recipe is placed in the workspace.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500405
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600406 <para>Aside from a recipe folder, the command
407 also creates an append folder and places an initial
408 <filename>*.bbappend</filename> within.
409 </para></listitem>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500410 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600411 </para></listitem>
412 <listitem><para><emphasis>Edit the Recipe</emphasis>:
413 At this point, you can use <filename>devtool edit-recipe</filename>
414 to open up the editor as defined by the
415 <filename>$EDITOR</filename> environment variable
416 and modify the file:
417 <literallayout class='monospaced'>
418 $ devtool edit-recipe <replaceable>recipe</replaceable>
419 </literallayout>
420 From within the editor, you can make modifications to the
421 recipe that take affect when you build it later.
422 </para></listitem>
423 <listitem><para><emphasis>Build the Recipe or Rebuild the Image</emphasis>:
424 At this point in the flow, the next step you
425 take depends on what you are going to do with
426 the new code.</para>
427 <para>If you need to take the build output and eventually
428 move it to the target hardware, you would use
429 <filename>devtool build</filename>:
430 <literallayout class='monospaced'>
431 $ devtool build <replaceable>recipe</replaceable>
432 </literallayout></para>
433 <para>On the other hand, if you want an image to
434 contain the recipe's packages for immediate deployment
435 onto a device (e.g. for testing purposes), you can use
436 the <filename>devtool build-image</filename> command:
437 <literallayout class='monospaced'>
438 $ devtool build-image <replaceable>image</replaceable>
439 </literallayout>
440 </para></listitem>
441 <listitem><para><emphasis>Deploy the Build Output</emphasis>:
442 When you use the <filename>devtool build</filename>
443 command to build out your recipe, you probably want to
444 see if the resulting build output works as expected on target
445 hardware.
446 <note>
447 This step assumes you have a previously built
448 image that is already either running in QEMU or
449 running on actual hardware.
450 Also, it is assumed that for deployment of the image
451 to the target, SSH is installed in the image and if
452 the image is running on real hardware that you have
453 network access to and from your development machine.
454 </note>
455 You can deploy your build output to that target hardware by
456 using the <filename>devtool deploy-target</filename> command:
457 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500458 $ devtool deploy-target <replaceable>recipe target</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600459 </literallayout>
460 The <replaceable>target</replaceable> is a live target machine
461 running as an SSH server.</para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500462
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600463 <para>You can, of course, also deploy the image you build
464 using the <filename>devtool build-image</filename> command
465 to actual hardware.
466 However, <filename>devtool</filename> does not provide a
467 specific command that allows you to do this.
468 </para></listitem>
469 <listitem><para>
470 <emphasis>Finish Your Work With the Recipe</emphasis>:
471 The <filename>devtool finish</filename> command creates
472 any patches corresponding to commits in the local
473 Git repository, moves the new recipe to a more permanent
474 layer, and then resets the recipe so that the recipe is
475 built normally rather than from the workspace.
476 <literallayout class='monospaced'>
477 $ devtool finish <replaceable>recipe layer</replaceable>
478 </literallayout>
479 <note>
480 Any changes you want to turn into patches must be
481 committed to the Git repository in the source tree.
482 </note></para>
483
484 <para>As mentioned, the <filename>devtool finish</filename>
485 command moves the final recipe to its permanent layer.
486 </para>
487
488 <para>As a final process of the
489 <filename>devtool finish</filename> command, the state
490 of the standard layers and the upstream source is
491 restored so that you can build the recipe from those
492 areas rather than the workspace.
493 <note>
494 You can use the <filename>devtool reset</filename>
495 command to put things back should you decide you
496 do not want to proceed with your work.
497 If you do use this command, realize that the source
498 tree is preserved.
499 </note>
500 </para></listitem>
501 </orderedlist>
502 </para>
503 </section>
504
505 <section id='sdk-devtool-use-devtool-modify-to-modify-the-source-of-an-existing-component'>
506 <title>Use <filename>devtool modify</filename> to Modify the Source of an Existing Component</title>
507
508 <para>
509 The <filename>devtool modify</filename> command prepares the
510 way to work on existing code that already has a recipe in
511 place.
512 The command is flexible enough to allow you to extract code,
513 specify the existing recipe, and keep track of and gather any
514 patch files from other developers that are
515 associated with the code.
516 </para>
517
518 <para>
519 Depending on your particular scenario, the arguments and options
520 you use with <filename>devtool modify</filename> form different
521 combinations.
522 The following diagram shows common development flows
523 you would use with the <filename>devtool modify</filename>
524 command:
525 </para>
526
527 <para>
528 <imagedata fileref="figures/sdk-devtool-modify-flow.png" align="center" />
529 </para>
530
531 <para>
532 <orderedlist>
533 <listitem><para><emphasis>Preparing to Modify the Code</emphasis>:
534 The top part of the flow shows three scenarios by which
535 you could use <filename>devtool modify</filename> to
536 prepare to work on source files.
537 Each scenario assumes the following:
538 <itemizedlist>
539 <listitem><para>The recipe exists in some layer external
540 to the <filename>devtool</filename> workspace.
541 </para></listitem>
542 <listitem><para>The source files exist upstream in an
543 un-extracted state or locally in a previously
544 extracted state.
545 </para></listitem>
546 </itemizedlist>
547 The typical situation is where another developer has
548 created some layer for use with the Yocto Project and
549 their recipe already resides in that layer.
550 Furthermore, their source code is readily available
551 either upstream or locally.
552 <itemizedlist>
553 <listitem><para><emphasis>Left</emphasis>:
554 The left scenario represents a common situation
555 where the source code does not exist locally
556 and needs to be extracted.
557 In this situation, the source is extracted
558 into the default workspace location.
559 The recipe, in this scenario, is in its own
560 layer outside the workspace
561 (i.e.
562 <filename>meta-</filename><replaceable>layername</replaceable>).
563 </para>
564
565 <para>The following command identifies the recipe
566 and by default extracts the source files:
567 <literallayout class='monospaced'>
568 $ devtool modify <replaceable>recipe</replaceable>
569 </literallayout>
570 Once <filename>devtool</filename>locates the recipe,
571 it uses the
572 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
573 variable to locate the source code and
574 any local patch files from other developers are
575 located.
576 <note>
577 You cannot provide an URL for
578 <replaceable>srctree</replaceable> when using the
579 <filename>devtool modify</filename> command.
580 </note>
581 With this scenario, however, since no
582 <replaceable>srctree</replaceable> argument exists, the
583 <filename>devtool modify</filename> command by default
584 extracts the source files to a Git structure.
585 Furthermore, the location for the extracted source is the
586 default area within the workspace.
587 The result is that the command sets up both the source
588 code and an append file within the workspace with the
589 recipe remaining in its original location.
590 </para></listitem>
591 <listitem><para><emphasis>Middle</emphasis>:
592 The middle scenario represents a situation where
593 the source code also does not exist locally.
594 In this case, the code is again upstream
595 and needs to be extracted to some
596 local area as a Git repository.
597 The recipe, in this scenario, is again in its own
598 layer outside the workspace.</para>
599
600 <para>The following command tells
601 <filename>devtool</filename> what recipe with
602 which to work and, in this case, identifies a local
603 area for the extracted source files that is outside
604 of the default workspace:
605 <literallayout class='monospaced'>
606 $ devtool modify <replaceable>recipe srctree</replaceable>
607 </literallayout>
608 As with all extractions, the command uses
609 the recipe's <filename>SRC_URI</filename> to locate the
610 source files.
611 Once the files are located, the command by default
612 extracts them.
613 Providing the <replaceable>srctree</replaceable>
614 argument instructs <filename>devtool</filename> where
615 place the extracted source.</para>
616
617 <para>Within workspace, <filename>devtool</filename>
618 creates an append file for the recipe.
619 The recipe remains in its original location but
620 the source files are extracted to the location you
621 provided with <replaceable>srctree</replaceable>.
622 </para></listitem>
623 <listitem><para><emphasis>Right</emphasis>:
624 The right scenario represents a situation
625 where the source tree
626 (<replaceable>srctree</replaceable>) exists as a
627 previously extracted Git structure outside of
628 the <filename>devtool</filename> workspace.
629 In this example, the recipe also exists
630 elsewhere in its own layer.
631 </para>
632
633 <para>The following command tells
634 <filename>devtool</filename> the recipe
635 with which to work, uses the "-n" option to indicate
636 source does not need to be extracted, and uses
637 <replaceable>srctree</replaceable> to point to the
638 previously extracted source files:
639 <literallayout class='monospaced'>
640 $ devtool modify -n <replaceable>recipe srctree</replaceable>
641 </literallayout>
642 </para>
643
644 <para>Once the command finishes, it creates only
645 an append file for the recipe in the workspace.
646 The recipe and the source code remain in their
647 original locations.
648 </para></listitem>
649 </itemizedlist>
650 </para></listitem>
651 <listitem><para><emphasis>Edit the Source</emphasis>:
652 Once you have used the <filename>devtool modify</filename>
653 command, you are free to make changes to the source
654 files.
655 You can use any editor you like to make and save
656 your source code modifications.
657 </para></listitem>
658 <listitem><para><emphasis>Build the Recipe</emphasis>:
659 Once you have updated the source files, you can build
660 the recipe.
661 </para></listitem>
662 <listitem><para><emphasis>Deploy the Build Output</emphasis>:
663 When you use the <filename>devtool build</filename>
664 command to build out your recipe, you probably want to see
665 if the resulting build output works as expected on target
666 hardware.
667 <note>
668 This step assumes you have a previously built
669 image that is already either running in QEMU or
670 running on actual hardware.
671 Also, it is assumed that for deployment of the image
672 to the target, SSH is installed in the image and if
673 the image is running on real hardware that you have
674 network access to and from your development machine.
675 </note>
676 You can deploy your build output to that target hardware by
677 using the <filename>devtool deploy-target</filename> command:
678 <literallayout class='monospaced'>
679 $ devtool deploy-target <replaceable>recipe target</replaceable>
680 </literallayout>
681 The <replaceable>target</replaceable> is a live target machine
682 running as an SSH server.</para>
683
684 <para>You can, of course, also deploy the image you build
685 using the <filename>devtool build-image</filename> command
686 to actual hardware.
687 However, <filename>devtool</filename> does not provide a
688 specific command that allows you to do this.
689 </para></listitem>
690 <listitem><para>
691 <emphasis>Finish Your Work With the Recipe</emphasis>:
692 The <filename>devtool finish</filename> command creates
693 any patches corresponding to commits in the local
694 Git repository, updates the recipe to point to them
695 (or creates a <filename>.bbappend</filename> file to do
696 so, depending on the specified destination layer), and
697 then resets the recipe so that the recipe is built normally
698 rather than from the workspace.
699 <literallayout class='monospaced'>
700 $ devtool finish <replaceable>recipe layer</replaceable>
701 </literallayout>
702 <note>
703 Any changes you want to turn into patches must be
704 committed to the Git repository in the source tree.
705 </note></para>
706
707 <para>Because there is no need to move the recipe,
708 <filename>devtool finish</filename> either updates the
709 original recipe in the original layer or the command
710 creates a <filename>.bbappend</filename> in a different
711 layer as provided by <replaceable>layer</replaceable>.
712 </para>
713
714 <para>As a final process of the
715 <filename>devtool finish</filename> command, the state
716 of the standard layers and the upstream source is
717 restored so that you can build the recipe from those
718 areas rather than the workspace.
719 <note>
720 You can use the <filename>devtool reset</filename>
721 command to put things back should you decide you
722 do not want to proceed with your work.
723 If you do use this command, realize that the source
724 tree is preserved.
725 </note>
726 </para></listitem>
727 </orderedlist>
728 </para>
729 </section>
730
731 <section id='sdk-devtool-use-devtool-upgrade-to-create-a-version-of-the-recipe-that-supports-a-newer-version-of-the-software'>
732 <title>Use <filename>devtool upgrade</filename> to Create a Version of the Recipe that Supports a Newer Version of the Software</title>
733
734 <para>
735 The <filename>devtool upgrade</filename> command updates
736 an existing recipe so that you can build it for an updated
737 set of source files.
738 The command is flexible enough to allow you to specify
739 source code revision and versioning schemes, extract code into
740 or out of the <filename>devtool</filename> workspace, and
741 work with any source file forms that the fetchers support.
742 </para>
743
744 <para>
745 Depending on your particular scenario, the arguments and options
746 you use with <filename>devtool upgrade</filename> form different
747 combinations.
748 The following diagram shows a common development flow
749 you would use with the <filename>devtool modify</filename>
750 command:
751 </para>
752
753 <para>
754 <imagedata fileref="figures/sdk-devtool-upgrade-flow.png" align="center" />
755 </para>
756
757 <para>
758 <orderedlist>
759 <listitem><para><emphasis>Initiate the Upgrade</emphasis>:
760 The top part of the flow shows a typical scenario by which
761 you could use <filename>devtool upgrade</filename>.
762 The following conditions exist:
763 <itemizedlist>
764 <listitem><para>The recipe exists in some layer external
765 to the <filename>devtool</filename> workspace.
766 </para></listitem>
767 <listitem><para>The source files for the new release
768 exist adjacent to the same location pointed to by
769 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
770 in the recipe (e.g. a tarball with the new version
771 number in the name, or as a different revision in
772 the upstream Git repository).
773 </para></listitem>
774 </itemizedlist>
775 A common situation is where third-party software has
776 undergone a revision so that it has been upgraded.
777 The recipe you have access to is likely in your own layer.
778 Thus, you need to upgrade the recipe to use the
779 newer version of the software:
780 <literallayout class='monospaced'>
781 $ devtool upgrade -V <replaceable>version recipe</replaceable>
782 </literallayout>
783 By default, the <filename>devtool upgrade</filename> command
784 extracts source code into the <filename>sources</filename>
785 directory in the workspace.
786 If you want the code extracted to any other location, you
787 need to provide the <replaceable>srctree</replaceable>
788 positional argument with the command as follows:
789 <literallayout class='monospaced'>
790 $ devtool upgrade -V <replaceable>version recipe srctree</replaceable>
791 </literallayout>
792 Also, in this example, the "-V" option is used to specify
793 the new version.
794 If the source files pointed to by the
795 <filename>SRC_URI</filename> statement in the recipe are
796 in a Git repository, you must provide the "-S" option and
797 specify a revision for the software.</para>
798
799 <para>Once <filename>devtool</filename> locates the recipe,
800 it uses the <filename>SRC_URI</filename> variable to locate
801 the source code and any local patch files from other
802 developers are located.
803 The result is that the command sets up the source
804 code, the new version of the recipe, and an append file
805 all within the workspace.
806 </para></listitem>
807 <listitem><para><emphasis>Resolve any Conflicts created by the Upgrade</emphasis>:
808 At this point, there could be some conflicts due to the
809 software being upgraded to a new version.
810 This would occur if your recipe specifies some patch files in
811 <filename>SRC_URI</filename> that conflict with changes
812 made in the new version of the software.
813 If this is the case, you need to resolve the conflicts
814 by editing the source and following the normal
815 <filename>git rebase</filename> conflict resolution
816 process.</para>
817 <para>Before moving onto the next step, be sure to resolve any
818 such conflicts created through use of a newer or different
819 version of the software.
820 </para></listitem>
821 <listitem><para><emphasis>Build the Recipe</emphasis>:
822 Once you have your recipe in order, you can build it.
823 You can either use <filename>devtool build</filename> or
824 <filename>bitbake</filename>.
825 Either method produces build output that is stored
826 in
827 <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>.
828 </para></listitem>
829 <listitem><para><emphasis>Deploy the Build Output</emphasis>:
830 When you use the <filename>devtool build</filename>
831 command or <filename>bitbake</filename> to build out your
832 recipe, you probably want to see if the resulting build
833 output works as expected on target hardware.
834 <note>
835 This step assumes you have a previously built
836 image that is already either running in QEMU or
837 running on actual hardware.
838 Also, it is assumed that for deployment of the image
839 to the target, SSH is installed in the image and if
840 the image is running on real hardware that you have
841 network access to and from your development machine.
842 </note>
843 You can deploy your build output to that target hardware by
844 using the <filename>devtool deploy-target</filename> command:
845 <literallayout class='monospaced'>
846 $ devtool deploy-target <replaceable>recipe target</replaceable>
847 </literallayout>
848 The <replaceable>target</replaceable> is a live target machine
849 running as an SSH server.</para>
850 <para>You can, of course, also deploy the image you build
851 using the <filename>devtool build-image</filename> command
852 to actual hardware.
853 However, <filename>devtool</filename> does not provide a
854 specific command that allows you to do this.
855 </para></listitem>
856 <listitem><para>
857 <emphasis>Finish Your Work With the Recipe</emphasis>:
858 The <filename>devtool finish</filename> command creates
859 any patches corresponding to commits in the local
860 Git repository, moves the new recipe to a more permanent
861 layer, and then resets the recipe so that the recipe is
862 built normally rather than from the workspace.
863 If you specify a destination layer that is the same as
864 the original source, then the old version of the
865 recipe and associated files will be removed prior to
866 adding the new version.
867 <literallayout class='monospaced'>
868 $ devtool finish <replaceable>recipe layer</replaceable>
869 </literallayout>
870 <note>
871 Any changes you want to turn into patches must be
872 committed to the Git repository in the source tree.
873 </note></para>
874 <para>As a final process of the
875 <filename>devtool finish</filename> command, the state
876 of the standard layers and the upstream source is
877 restored so that you can build the recipe from those
878 areas rather than the workspace.
879 <note>
880 You can use the <filename>devtool reset</filename>
881 command to put things back should you decide you
882 do not want to proceed with your work.
883 If you do use this command, realize that the source
884 tree is preserved.
885 </note>
886 </para></listitem>
887 </orderedlist>
888 </para>
889 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500890 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500891
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600892 <section id='sdk-a-closer-look-at-devtool-add'>
893 <title>A Closer Look at <filename>devtool add</filename></title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500894
895 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600896 The <filename>devtool add</filename> command automatically creates a
897 recipe based on the source tree with which you provide it.
898 Currently, the command has support for the following:
899 <itemizedlist>
900 <listitem><para>
901 Autotools (<filename>autoconf</filename> and
902 <filename>automake</filename>)
903 </para></listitem>
904 <listitem><para>
905 CMake
906 </para></listitem>
907 <listitem><para>
908 Scons
909 </para></listitem>
910 <listitem><para>
911 <filename>qmake</filename>
912 </para></listitem>
913 <listitem><para>
914 Plain <filename>Makefile</filename>
915 </para></listitem>
916 <listitem><para>
917 Out-of-tree kernel module
918 </para></listitem>
919 <listitem><para>
920 Binary package (i.e. "-b" option)
921 </para></listitem>
922 <listitem><para>
923 Node.js module
924 </para></listitem>
925 <listitem><para>
926 Python modules that use <filename>setuptools</filename>
927 or <filename>distutils</filename>
928 </para></listitem>
929 </itemizedlist>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500930 </para>
931
932 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600933 Apart from binary packages, the determination of how a source tree
934 should be treated is automatic based on the files present within
935 that source tree.
936 For example, if a <filename>CMakeLists.txt</filename> file is found,
937 then the source tree is assumed to be using
938 CMake and is treated accordingly.
939 <note>
940 In most cases, you need to edit the automatically generated
941 recipe in order to make it build properly.
942 Typically, you would go through several edit and build cycles
943 until you can build the recipe.
944 Once the recipe can be built, you could use possible further
945 iterations to test the recipe on the target device.
946 </note>
947 </para>
948
949 <para>
950 The remainder of this section covers specifics regarding how parts
951 of the recipe are generated.
952 </para>
953
954 <section id='sdk-name-and-version'>
955 <title>Name and Version</title>
956
957 <para>
958 If you do not specify a name and version on the command
959 line, <filename>devtool add</filename> attempts to determine
960 the name and version of the software being built from
961 various metadata within the source tree.
962 Furthermore, the command sets the name of the created recipe
963 file accordingly.
964 If the name or version cannot be determined, the
965 <filename>devtool add</filename> command prints an error and
966 you must re-run the command with both the name and version
967 or just the name or version specified.
968 </para>
969
970 <para>
971 Sometimes the name or version determined from the source tree
972 might be incorrect.
973 For such a case, you must reset the recipe:
974 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500975 $ devtool reset -n <replaceable>recipename</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600976 </literallayout>
977 After running the <filename>devtool reset</filename> command,
978 you need to run <filename>devtool add</filename> again and
979 provide the name or the version.
980 </para>
981 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500982
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600983 <section id='sdk-dependency-detection-and-mapping'>
984 <title>Dependency Detection and Mapping</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500985
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600986 <para>
987 The <filename>devtool add</filename> command attempts to
988 detect build-time dependencies and map them to other recipes
989 in the system.
990 During this mapping, the command fills in the names of those
991 recipes in the
992 <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>
993 value within the recipe.
994 If a dependency cannot be mapped, then a comment is placed in
995 the recipe indicating such.
996 The inability to map a dependency might be caused because the
997 naming is not recognized or because the dependency simply is
998 not available.
999 For cases where the dependency is not available, you must use
1000 the <filename>devtool add</filename> command to add an
1001 additional recipe to satisfy the dependency and then come
1002 back to the first recipe and add its name to
1003 <filename>DEPENDS</filename>.
1004 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001005
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001006 <para>
1007 If you need to add runtime dependencies, you can do so by
1008 adding the following to your recipe:
1009 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001010 RDEPENDS_${PN} += "dependency1 dependency2 ..."
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001011 </literallayout>
1012 <note>
1013 The <filename>devtool add</filename> command often cannot
1014 distinguish between mandatory and optional dependencies.
1015 Consequently, some of the detected dependencies might
1016 in fact be optional.
1017 When in doubt, consult the documentation or the configure
1018 script for the software the recipe is building for further
1019 details.
1020 In some cases, you might find you can substitute the
1021 dependency for an option to disable the associated
1022 functionality passed to the configure script.
1023 </note>
1024 </para>
1025 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001026
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001027 <section id='sdk-license-detection'>
1028 <title>License Detection</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001029
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001030 <para>
1031 The <filename>devtool add</filename> command attempts to
1032 determine if the software you are adding is able to be
1033 distributed under a common open-source license and sets the
1034 <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink>
1035 value accordingly.
1036 You should double-check this value against the documentation
1037 or source files for the software you are building and update
1038 that <filename>LICENSE</filename> value if necessary.
1039 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001040
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001041 <para>
1042 The <filename>devtool add</filename> command also sets the
1043 <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink>
1044 value to point to all files that appear to be license-related.
1045 However, license statements often appear in comments at the top
1046 of source files or within documentation.
1047 Consequently, you might need to amend the
1048 <filename>LIC_FILES_CHKSUM</filename> variable to point to one
1049 or more of those comments if present.
1050 Setting <filename>LIC_FILES_CHKSUM</filename> is particularly
1051 important for third-party software.
1052 The mechanism attempts to ensure correct licensing should you
1053 upgrade the recipe to a newer upstream version in future.
1054 Any change in licensing is detected and you receive an error
1055 prompting you to check the license text again.
1056 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001057
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001058 <para>
1059 If the <filename>devtool add</filename> command cannot
1060 determine licensing information, the
1061 <filename>LICENSE</filename> value is set to "CLOSED" and the
1062 <filename>LIC_FILES_CHKSUM</filename> value remains unset.
1063 This behavior allows you to continue with development but is
1064 unlikely to be correct in all cases.
1065 Consequently, you should check the documentation or source
1066 files for the software you are building to determine the actual
1067 license.
1068 </para>
1069 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001070
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001071 <section id='sdk-adding-makefile-only-software'>
1072 <title>Adding Makefile-Only Software</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001073
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001074 <para>
1075 The use of <filename>make</filename> by itself is very common
1076 in both proprietary and open source software.
1077 Unfortunately, Makefiles are often not written with
1078 cross-compilation in mind.
1079 Thus, <filename>devtool add</filename> often cannot do very
1080 much to ensure that these Makefiles build correctly.
1081 It is very common, for example, to explicitly call
1082 <filename>gcc</filename> instead of using the
1083 <ulink url='&YOCTO_DOCS_REF_URL;#var-CC'><filename>CC</filename></ulink>
1084 variable.
1085 Usually, in a cross-compilation environment,
1086 <filename>gcc</filename> is the compiler for the build host
1087 and the cross-compiler is named something similar to
1088 <filename>arm-poky-linux-gnueabi-gcc</filename> and might
1089 require some arguments (e.g. to point to the associated sysroot
1090 for the target machine).
1091 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001092
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001093 <para>
1094 When writing a recipe for Makefile-only software, keep the
1095 following in mind:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001096 <itemizedlist>
1097 <listitem><para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001098 You probably need to patch the Makefile to use
1099 variables instead of hardcoding tools within the
1100 toolchain such as <filename>gcc</filename> and
1101 <filename>g++</filename>.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001102 </para></listitem>
1103 <listitem><para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001104 The environment in which <filename>make</filename> runs
1105 is set up with various standard variables for
1106 compilation (e.g. <filename>CC</filename>,
1107 <filename>CXX</filename>, and so forth) in a similar
1108 manner to the environment set up by the SDK's
1109 environment setup script.
1110 One easy way to see these variables is to run the
1111 <filename>devtool build</filename> command on the
1112 recipe and then look in
1113 <filename>oe-logs/run.do_compile</filename>.
1114 Towards the top of this file you will see a list of
1115 environment variables that are being set.
1116 You can take advantage of these variables within the
1117 Makefile.
1118 </para></listitem>
1119 <listitem><para>
1120 If the Makefile sets a default for a variable using "=",
1121 that default overrides the value set in the environment,
1122 which is usually not desirable.
1123 In this situation, you can either patch the Makefile
1124 so it sets the default using the "?=" operator, or
1125 you can alternatively force the value on the
1126 <filename>make</filename> command line.
1127 To force the value on the command line, add the
1128 variable setting to
1129 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink>
1130 or
1131 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
1132 within the recipe.
1133 Here is an example using <filename>EXTRA_OEMAKE</filename>:
1134 <literallayout class='monospaced'>
1135 EXTRA_OEMAKE += "'CC=${CC}' 'CXX=${CXX}'"
1136 </literallayout>
1137 In the above example, single quotes are used around the
1138 variable settings as the values are likely to contain
1139 spaces because required default options are passed to
1140 the compiler.
1141 </para></listitem>
1142 <listitem><para>
1143 Hardcoding paths inside Makefiles is often problematic
1144 in a cross-compilation environment.
1145 This is particularly true because those hardcoded paths
1146 often point to locations on the build host and thus
1147 will either be read-only or will introduce
1148 contamination into the cross-compilation by virtue of
1149 being specific to the build host rather than the target.
1150 Patching the Makefile to use prefix variables or other
1151 path variables is usually the way to handle this.
1152 </para></listitem>
1153 <listitem><para>
1154 Sometimes a Makefile runs target-specific commands such
1155 as <filename>ldconfig</filename>.
1156 For such cases, you might be able to simply apply
1157 patches that remove these commands from the Makefile.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001158 </para></listitem>
1159 </itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001160 </para>
1161 </section>
1162
1163 <section id='sdk-adding-native-tools'>
1164 <title>Adding Native Tools</title>
1165
1166 <para>
1167 Often, you need to build additional tools that run on the
1168 build host system as opposed to the target.
1169 You should indicate this using one of the following methods
1170 when you run <filename>devtool add</filename>:
1171 <itemizedlist>
1172 <listitem><para>
1173 Specify the name of the recipe such that it ends
1174 with "-native".
1175 Specifying the name like this produces a recipe that
1176 only builds for the build host.
1177 </para></listitem>
1178 <listitem><para>
1179 Specify the "&dash;&dash;also-native" option with the
1180 <filename>devtool add</filename> command.
1181 Specifying this option creates a recipe file that still
1182 builds for the target but also creates a variant with
1183 a "-native" suffix that builds for the build host.
1184 </para></listitem>
1185 </itemizedlist>
1186 <note>
1187 If you need to add a tool that is shipped as part of a
1188 source tree that builds code for the target, you can
1189 typically accomplish this by building the native and target
1190 parts separately rather than within the same compilation
1191 process.
1192 Realize though that with the "&dash;&dash;also-native" option, you
1193 can add the tool using just one recipe file.
1194 </note>
1195 </para>
1196 </section>
1197
1198 <section id='sdk-adding-node-js-modules'>
1199 <title>Adding Node.js Modules</title>
1200
1201 <para>
1202 You can use the <filename>devtool add</filename> command two
1203 different ways to add Node.js modules: 1) Through
1204 <filename>npm</filename> and, 2) from a repository or local
1205 source.
1206 </para>
1207
1208 <para>
1209 Use the following form to add Node.js modules through
1210 <filename>npm</filename>:
1211 <literallayout class='monospaced'>
1212 $ devtool add "npm://registry.npmjs.org;name=forever;version=0.15.1"
1213 </literallayout>
1214 The name and version parameters are mandatory.
1215 Lockdown and shrinkwrap files are generated and pointed to by
1216 the recipe in order to freeze the version that is fetched for
1217 the dependencies according to the first time.
1218 This also saves checksums that are verified on future fetches.
1219 Together, these behaviors ensure the reproducibility and
1220 integrity of the build.
1221 <note><title>Notes</title>
1222 <itemizedlist>
1223 <listitem><para>
1224 You must use quotes around the URL.
1225 The <filename>devtool add</filename> does not require
1226 the quotes, but the shell considers ";" as a splitter
1227 between multiple commands.
1228 Thus, without the quotes,
1229 <filename>devtool add</filename> does not receive the
1230 other parts, which results in several "command not
1231 found" errors.
1232 </para></listitem>
1233 <listitem><para>
1234 In order to support adding
1235 Node.js modules, a
1236 <filename>nodejs</filename> recipe must be part of your
1237 SDK in order to provide Node.js
1238 itself.
1239 </para></listitem>
1240 </itemizedlist>
1241 </note>
1242 </para>
1243
1244 <para>
1245 As mentioned earlier, you can also add Node.js modules
1246 directly from a repository or local source tree.
1247 To add modules this way, use <filename>devtool add</filename> in
1248 the following form:
1249 <literallayout class='monospaced'>
1250 $ devtool add https://github.com/diversario/node-ssdp
1251 </literallayout>
1252 In this example, <filename>devtool</filename> fetches the specified
1253 Git repository, detects that the code is Node.js code, fetches
1254 dependencies using <filename>npm</filename>, and sets
1255 <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
1256 accordingly.
1257 </para>
1258 </section>
1259 </section>
1260
1261 <section id='sdk-working-with-recipes'>
1262 <title>Working With Recipes</title>
1263
1264 <para>
1265 When building a recipe with <filename>devtool build</filename> the
1266 typical build progression is as follows:
1267 <orderedlist>
1268 <listitem><para>
1269 Fetch the source
1270 </para></listitem>
1271 <listitem><para>
1272 Unpack the source
1273 </para></listitem>
1274 <listitem><para>
1275 Configure the source
1276 </para></listitem>
1277 <listitem><para>
1278 Compiling the source
1279 </para></listitem>
1280 <listitem><para>
1281 Install the build output
1282 </para></listitem>
1283 <listitem><para>
1284 Package the installed output
1285 </para></listitem>
1286 </orderedlist>
1287 For recipes in the workspace, fetching and unpacking is disabled
1288 as the source tree has already been prepared and is persistent.
1289 Each of these build steps is defined as a function, usually with a
1290 "do_" prefix.
1291 These functions are typically shell scripts but can instead be written
1292 in Python.
1293 </para>
1294
1295 <para>
1296 If you look at the contents of a recipe, you will see that the
1297 recipe does not include complete instructions for building the
1298 software.
1299 Instead, common functionality is encapsulated in classes inherited
1300 with the <filename>inherit</filename> directive, leaving the recipe
1301 to describe just the things that are specific to the software to be
1302 built.
1303 A <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-base'><filename>base</filename></ulink>
1304 class exists that is implicitly inherited by all recipes and provides
1305 the functionality that most typical recipes need.
1306 </para>
1307
1308 <para>
1309 The remainder of this section presents information useful when
1310 working with recipes.
1311 </para>
1312
1313 <section id='sdk-finding-logs-and-work-files'>
1314 <title>Finding Logs and Work Files</title>
1315
1316 <para>
1317 When you are debugging a recipe that you previously created using
1318 <filename>devtool add</filename> or whose source you are modifying
1319 by using the <filename>devtool modify</filename> command, after
1320 the first run of <filename>devtool build</filename>, you will
1321 find some symbolic links created within the source tree:
1322 <filename>oe-logs</filename>, which points to the directory in
1323 which log files and run scripts for each build step are created
1324 and <filename>oe-workdir</filename>, which points to the temporary
1325 work area for the recipe.
1326 You can use these links to get more information on what is
1327 happening at each build step.
1328 </para>
1329
1330 <para>
1331 These locations under <filename>oe-workdir</filename> are
1332 particularly useful:
1333 <itemizedlist>
1334 <listitem><para><filename>image/</filename>:
1335 Contains all of the files installed at the
1336 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1337 stage.
1338 Within a recipe, this directory is referred to by the
1339 expression
1340 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>.
1341 </para></listitem>
1342 <listitem><para><filename>sysroot-destdir/</filename>:
1343 Contains a subset of files installed within
1344 <filename>do_install</filename> that have been put into the
1345 shared sysroot.
1346 For more information, see the
1347 "<link linkend='sdk-sharing-files-between-recipes'>Sharing Files Between Recipes</link>"
1348 section.
1349 </para></listitem>
1350 <listitem><para><filename>packages-split/</filename>:
1351 Contains subdirectories for each package produced by the
1352 recipe.
1353 For more information, see the
1354 "<link linkend='sdk-packaging'>Packaging</link>" section.
1355 </para></listitem>
1356 </itemizedlist>
1357 </para>
1358 </section>
1359
1360 <section id='sdk-setting-configure-arguments'>
1361 <title>Setting Configure Arguments</title>
1362
1363 <para>
1364 If the software your recipe is building uses GNU autoconf,
1365 then a fixed set of arguments is passed to it to enable
1366 cross-compilation plus any extras specified by
1367 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink>
1368 or
1369 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
1370 set within the recipe.
1371 If you wish to pass additional options, add them to
1372 <filename>EXTRA_OECONF</filename> or
1373 <filename>PACKAGECONFIG_CONFARGS</filename>.
1374 Other supported build tools have similar variables
1375 (e.g.
1376 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink>
1377 for CMake,
1378 <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OESCONS'><filename>EXTRA_OESCONS</filename></ulink>
1379 for Scons, and so forth).
1380 If you need to pass anything on the <filename>make</filename>
1381 command line, you can use <filename>EXTRA_OEMAKE</filename> or the
1382 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink>
1383 variables to do so.
1384 </para>
1385
1386 <para>
1387 You can use the <filename>devtool configure-help</filename> command
1388 to help you set the arguments listed in the previous paragraph.
1389 The command determines the exact options being passed, and shows
1390 them to you along with any custom arguments specified through
1391 <filename>EXTRA_OECONF</filename> or
1392 <filename>PACKAGECONFIG_CONFARGS</filename>.
1393 If applicable, the command also shows you the output of the
1394 configure script's "&dash;&dash;help" option as a reference.
1395 </para>
1396 </section>
1397
1398 <section id='sdk-sharing-files-between-recipes'>
1399 <title>Sharing Files Between Recipes</title>
1400
1401 <para>
1402 Recipes often need to use files provided by other recipes on
1403 the build host.
1404 For example, an application linking to a common library needs
1405 access to the library itself and its associated headers.
1406 The way this access is accomplished within the extensible SDK is
1407 through the sysroot.
1408 One sysroot exists per "machine" for which the SDK is being built.
1409 In practical terms, this means a sysroot exists for the target
1410 machine, and a sysroot exists for the build host.
1411 </para>
1412
1413 <para>
1414 Recipes should never write files directly into the sysroot.
1415 Instead, files should be installed into standard locations
1416 during the
1417 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1418 task within the
1419 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>
1420 directory.
1421 A subset of these files automatically go into the sysroot.
1422 The reason for this limitation is that almost all files that go
1423 into the sysroot are cataloged in manifests in order to ensure
1424 they can be removed later when a recipe is modified or removed.
1425 Thus, the sysroot is able to remain free from stale files.
1426 </para>
1427 </section>
1428
1429 <section id='sdk-packaging'>
1430 <title>Packaging</title>
1431
1432 <para>
1433 Packaging is not always particularly relevant within the
1434 extensible SDK.
1435 However, if you examine how build output gets into the final image
1436 on the target device, it is important to understand packaging
1437 because the contents of the image are expressed in terms of
1438 packages and not recipes.
1439 </para>
1440
1441 <para>
1442 During the
1443 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-package'><filename>do_package</filename></ulink>
1444 task, files installed during the
1445 <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink>
1446 task are split into one main package, which is almost always named
1447 the same as the recipe, and several other packages.
1448 This separation is done because not all of those installed files
1449 are always useful in every image.
1450 For example, you probably do not need any of the documentation
1451 installed in a production image.
1452 Consequently, for each recipe the documentation files are separated
1453 into a <filename>-doc</filename> package.
1454 Recipes that package software that has optional modules or
1455 plugins might do additional package splitting as well.
1456 </para>
1457
1458 <para>
1459 After building a recipe you can see where files have gone by
1460 looking in the <filename>oe-workdir/packages-split</filename>
1461 directory, which contains a subdirectory for each package.
1462 Apart from some advanced cases, the
1463 <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>
1464 and
1465 <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>
1466 variables controls splitting.
1467 The <filename>PACKAGES</filename> variable lists all of the
1468 packages to be produced, while the <filename>FILES</filename>
1469 variable specifies which files to include in each package,
1470 using an override to specify the package.
1471 For example, <filename>FILES_${PN}</filename> specifies the files
1472 to go into the main package (i.e. the main package is named the
1473 same as the recipe and
1474 <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>
1475 evaluates to the recipe name).
1476 The order of the <filename>PACKAGES</filename> value is significant.
1477 For each installed file, the first package whose
1478 <filename>FILES</filename> value matches the file is the package
1479 into which the file goes.
1480 Defaults exist for both the <filename>PACKAGES</filename> and
1481 <filename>FILES</filename> variables.
1482 Consequently, you might find you do not even need to set these
1483 variables in your recipe unless the software the recipe is
1484 building installs files into non-standard locations.
1485 </para>
1486 </section>
1487 </section>
1488
1489 <section id='sdk-restoring-the-target-device-to-its-original-state'>
1490 <title>Restoring the Target Device to its Original State</title>
1491
1492 <para>
1493 If you use the <filename>devtool deploy-target</filename>
1494 command to write a recipe's build output to the target, and
1495 you are working on an existing component of the system, then you
1496 might find yourself in a situation where you need to restore the
1497 original files that existed prior to running the
1498 <filename>devtool deploy-target</filename> command.
1499 Because the <filename>devtool deploy-target</filename> command
1500 backs up any files it overwrites, you can use the
1501 <filename>devtool undeploy-target</filename> to restore those files
1502 and remove any other files the recipe deployed.
1503 Consider the following example:
1504 <literallayout class='monospaced'>
1505 $ devtool undeploy-target lighttpd root@192.168.7.2
1506 </literallayout>
1507 If you have deployed multiple applications, you can remove them
1508 all at once thus restoring the target device back to its
1509 original state:
1510 <literallayout class='monospaced'>
1511 $ devtool undeploy-target -a root@192.168.7.2
1512 </literallayout>
1513 Information about files deployed to the target as well as any
1514 backed up files are stored on the target itself.
1515 This storage of course requires some additional space
1516 on the target machine.
1517 <note>
1518 The <filename>devtool deploy-target</filename> and
1519 <filename>devtool undeploy-target</filename> command do not
1520 currently interact with any package management system on the
1521 target device (e.g. RPM or OPKG).
1522 Consequently, you should not intermingle operations
1523 <filename>devtool deploy-target</filename> and the package
1524 manager operations on the target device.
1525 Doing so could result in a conflicting set of files.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001526 </note>
1527 </para>
1528 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001529
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001530 <section id='sdk-installing-additional-items-into-the-extensible-sdk'>
1531 <title>Installing Additional Items Into the Extensible SDK</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001532
1533 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001534 The extensible SDK typically only comes with a small number of tools
1535 and libraries out of the box.
1536 If you have a minimal SDK, then it starts mostly empty and is
1537 populated on-demand.
1538 However, sometimes you will need to explicitly install extra items
1539 into the SDK.
1540 If you need these extra items, you can first search for the items
1541 using the <filename>devtool search</filename> command.
1542 For example, suppose you need to link to libGL but you are not sure
1543 which recipe provides it.
1544 You can use the following command to find out:
1545 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001546 $ devtool search libGL
1547 mesa A free implementation of the OpenGL API
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001548 </literallayout>
1549 Once you know the recipe (i.e. <filename>mesa</filename> in this
1550 example), you can install it:
1551 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001552 $ devtool sdk-install mesa
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001553 </literallayout>
1554 By default, the <filename>devtool sdk-install</filename> assumes the
1555 item is available in pre-built form from your SDK provider.
1556 If the item is not available and it is acceptable to build the item
1557 from source, you can add the "-s" option as follows:
1558 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001559 $ devtool sdk-install -s mesa
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001560 </literallayout>
1561 It is important to remember that building the item from source takes
1562 significantly longer than installing the pre-built artifact.
1563 Also, if no recipe exists for the item you want to add to the SDK, you
1564 must instead add it using the <filename>devtool add</filename> command.
1565 </para>
1566 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001567
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001568 <section id='sdk-updating-the-extensible-sdk'>
1569 <title>Updating the Extensible SDK</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001570
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001571 <para>
1572 If you are working with an extensible SDK that gets occasionally
1573 updated (e.g. typically when that SDK has been provided to you by
1574 another party), then you will need to manually pull down those
1575 updates to your installed SDK.
1576 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001577
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001578 <para>
1579 To update your installed SDK, run the following:
1580 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001581 $ devtool sdk-update
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001582 </literallayout>
1583 The previous command assumes your SDK provider has set the default
1584 update URL for you.
1585 If that URL has not been set, you need to specify it yourself as
1586 follows:
1587 <literallayout class='monospaced'>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001588 $ devtool sdk-update <replaceable>path_to_update_directory</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001589 </literallayout>
1590 <note>
1591 The URL needs to point specifically to a published SDK and not an
1592 SDK installer that you would download and install.
1593 </note>
1594 </para>
1595 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001596
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001597 <section id='sdk-creating-a-derivative-sdk-with-additional-components'>
1598 <title>Creating a Derivative SDK With Additional Components</title>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001599
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001600 <para>
1601 You might need to produce an SDK that contains your own custom
1602 libraries for sending to a third party (e.g., if you are a vendor with
1603 customers needing to build their own software for the target platform).
1604 If that is the case, then you can produce a derivative SDK based on
1605 the currently installed SDK fairly easily.
1606 Use these steps:
1607 <orderedlist>
1608 <listitem><para>If necessary, install an extensible SDK that
1609 you want to use as a base for your derivative SDK.
1610 </para></listitem>
1611 <listitem><para>Source the environment script for the SDK.
1612 </para></listitem>
1613 <listitem><para>Add the extra libraries or other components
1614 you want by using the <filename>devtool add</filename>
1615 command.
1616 </para></listitem>
1617 <listitem><para>Run the <filename>devtool build-sdk</filename>
1618 command.
1619 </para></listitem>
1620 </orderedlist>
1621 The above procedure takes the recipes added to the workspace and
1622 constructs a new SDK installer containing those recipes and the
1623 resulting binary artifacts.
1624 The recipes go into their own separate layer in the constructed
1625 derivative SDK, leaving the workspace clean and ready for users
1626 to add their own recipes.
1627 </para>
1628 </section>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001629</chapter>
1630<!--
1631vim: expandtab tw=80 ts=4
1632-->