source: rtems-docs/user/rsb/configuration.rst @ e94ed6d

5
Last change on this file since e94ed6d was e94ed6d, checked in by Gedare Bloom <gedare@…>, on 04/05/20 at 20:56:38

rsb/configuration: add my copyright

  • Property mode set to 100644
File size: 53.9 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 2020 Gedare Bloom <gedare@rtems.org>
4.. Copyright (C) 2012, 2016 Chris Johns <chrisj@rtems.org>
5
6.. _Configuration:
7
8Configuration
9-------------
10
11The RTEMS Source Builder has two types of configuration data:
12
13- Build Sets
14
15- Package Build Configurations
16
17By default these files can be located in two separate directories and
18searched. The first directory is ``config`` in your current working directory
19(``_topdir``) and the second is ``config`` located in the base directory of the
20RTEMS Source Builder command you run (``_sbdir``). The RTEMS directory
21``rtems``` located at the top of the RTEMS Source Builder source code is an
22example of a specific build configuration directory. You can create custom or
23private build configurations and if you run the RTEMS Source Builder command
24from that directory your configurations will be used.
25
26The configuration search path is a macro variable and is reference as
27``%{_configdir}``. It's default is defined as:
28
29.. code-block:: spec
30
31    _configdir   : dir  optional  %{_topdir}/config:%{_sbdir}/config
32
33.. topic:: Items:
34
35  1. The ``_topdir`` is the directory you run the command from and ``_sbdir``
36     is the location of the RTEMS Source Builder command.
37
38  2. A macro definition in a macro file has 4 fields, the label, type,
39     constraint and the definition.
40
41Build set files have the file extension ``.bset`` and the package build
42configuration files have the file extension of ``.cfg``. The ``sb-set-builder``
43command will search for *build sets* and the ``sb-builder`` commands works with
44package build configuration files.
45
46Both types of configuration files use the ``#`` character as a comment
47character. Anything after this character on the line is ignored. There is no
48block comment.
49
50Source and Patches
51^^^^^^^^^^^^^^^^^^
52
53The RTEMS Source Builder provides a flexible way to manage source. Source and
54patches are declare in configurations file using the ``source`` and ``patch``
55directives. These are a single line containing a Universal Resource Location or
56URL and can contain macros and shell expansions. The :ref:`prep` section
57details the *source* and *patch* directives
58
59The URL can reference remote and local source and patch resources. The
60following schemes are provided:
61
62``http``:
63  Remote access using the HTTP protocol.
64
65``https``:
66  Remote access using the Secure HTTP protocol.
67
68``ftp``:
69  Remote access using the FTP protocol.
70
71``git``:
72  Remote access to a GIT repository.
73
74``pm``:
75  Remote access to a patch management repository.
76
77``file``:
78 Local access to an existing source directory.
79
80HTTP, HTTPS, and FTP
81~~~~~~~~~~~~~~~~~~~~
82
83Remote access to TAR or ZIP files is provided using HTTP, HTTPS and FTP
84protocols. The full URL provided is used to access the remote file including
85any query components. The URL is parsed to extract the file component and the
86local source directory is checked for that file. If the file is located locally
87the remote file is not downloaded. Currently no other checks are made. If a
88download fails you need to manually remove the file from the source directory
89and start the build process again.
90
91The URL can contain macros. These are expanded before issuing the request to
92download the file. The standard GNU GCC compiler source URL is:
93
94.. code-block:: spec
95
96    %source set gcc ftp://ftp.gnu.org/gnu/gcc/gcc-%{gcc_version}/gcc-%{gcc_version}.tar.bz2
97
98.. topic:: Items:
99
100  1. The ``%source`` command's ``set`` command sets the source. The
101     first is set and following sets are ignored.
102
103  2. The source package is part of the ``gcc`` group.
104
105The type of compression is automatically detected from the file extension. The
106supported compression formats are:
107
108``gz``:
109  GNU ZIP
110
111``bzip2``:
112  BZIP2
113
114``zip``:
115  ZIP
116
117``xz``:
118  XZ
119
120The output of the decompression tool is fed to the standard ``tar`` utility if
121not a ZIP file and unpacked into the build directory. ZIP files are unpacked by
122the decompression tool and all other files must be in the tar file format.
123
124The ``%source`` directive typically supports a single source file tar or zip
125file. The ``set`` command is used to set the URL for a specific source
126group. The first set command encountered is registered and any further set
127commands are ignored. This allows you to define a base standard source location
128and override it in build and architecture specific files. You can also add
129extra source files to a group. This is typically done when a collection of
130source is broken down in a number of smaller files and you require the full
131package. The source's ``setup`` command must reside in the ``%prep:`` section
132and it unpacks the source code ready to be built.
133
134If the source URL references the GitHub API server https://api.github.com/ a
135tarball of the specified version is download. For example the URL for the
136STLINK project on GitHub and version is:
137
138.. code-block:: spec
139
140    %define stlink_version 3494c11
141    %source set stlink https://api.github.com/repos/texane/stlink/texane-stlink-%{stlink_version}.tar.gz
142
143GIT
144~~~
145
146A GIT repository can be cloned and used as source. The GIT repository resides
147in the 'source' directory under the ``git`` directory. You can edit, update and
148use the repository as you normally do and the results will used to build the
149tools. This allows you to prepare and test patches in the build environment the
150tools are built in. The GIT URL only supports the GIT protocol. You can control
151the repository via the URL by appending options and arguments to the GIT
152path. The options are delimited by ``?`` and option arguments are delimited
153from the options with ``=``. The options are:
154
155``protocol``:
156  Use a specific protocol. The supported values are ``ssh``, ``git``, ``http``,
157  ``https``, ``ftp``, ``ftps``, ``rsync``, and ``none``.
158
159``branch``:
160  Checkout the specified branch.
161
162``pull``:
163  Perform a pull to update the repository.
164
165``fetch``:
166  Perform a fetch to get any remote updates.
167
168``reset``:
169  Reset the repository. Useful to remove any local changes. You can pass the
170  ``hard`` argument to force a hard reset.
171
172An example is:
173
174.. code-block:: spec
175
176    %source set gcc git://gcc.gnu.org/git/gcc.git?branch=gcc-4_7-branch?reset=hard
177
178This will clone the GCC git repository and checkout the 4.7-branch and perform
179a hard reset. You can select specific branches and apply patches. The
180repository is cleaned up before each build to avoid various version control
181errors that can arise.
182
183The protocol option lets you set a specific protocol. The ``git://`` prefix
184used by the RSB to select a git repository can be removed using *none* or
185replaced with one of the standard git protocols.
186
187CVS
188~~~
189
190A CVS repository can be checked out. CVS is more complex than GIT to handle
191because of the modules support. This can effect the paths the source ends up
192in. The CVS URL only supports the CVS protocol. You can control the repository
193via the URL by appending options and arguments to the CVS path. The options are
194delimited by ``?`` and option arguments are delimited from the options with
195``=``. The options are:
196
197``module``:
198  The module to checkout.
199
200``src-prefix``:
201  The path into the source where the module starts.
202
203``tag``:
204  The CVS tag to checkout.
205
206``date``:
207  The CVS date to checkout.
208
209The following is an example of checking out from a CVS repository:
210
211.. code-block:: spec
212
213    %source set newlib cvs://pserver:anoncvs@sourceware.org/cvs/src?module=newlib?src-prefix=src
214
215Macros and Defaults
216^^^^^^^^^^^^^^^^^^^
217
218The RTEMS Source Builder uses tables of *macros* read in when the tool
219runs. The initial global set of macros is called the *defaults*. These values
220are read from a file called ``defaults.mc`` and modified to suite your
221host. This host specific adaption lets the Source Builder handle differences in
222the build hosts.
223
224Build set and configuration files can define new values updating and extending
225the global macro table. For example builds are given a release number. This is
226typically a single number at the end of the package name. For example:
227
228.. code-block:: spec
229
230    %define release 1
231
232Once defined if can be accessed in a build set or package configuration file
233with:
234
235.. code-block:: spec
236
237    %{release}
238
239The ``sb-defaults`` command lists the defaults for your host. I will not include
240the output of this command because of its size:
241
242.. code-block:: none
243
244    $ ../source-builder/sb-defaults
245
246A nested build set is given a separate copy of the global macro maps. Changes
247in one change set are not seen in other build sets. That same happens with
248configuration files unless inline includes are used. Inline includes are seen
249as part of the same build set and configuration and changes are global to that
250build set and configuration.
251
252Macro Maps and Files
253~~~~~~~~~~~~~~~~~~~~
254
255Macros are read in from files when the tool starts. The default settings are
256read from the defaults macro file called ``defaults.mc`` located in the top
257level RTEMS Source Builder command directory. User macros can be read in at
258start up by using the ``--macros`` command line option.
259
260The format for a macro in macro files is:
261
262.. code-block:: ini
263
264  Name Type Attribute String
265
266where ``Name`` is a case insensitive macro name, the ``Type`` field is:
267
268``none``:
269  Nothing, ignore.
270
271``dir``:
272  A directory path.
273
274``exe``:
275  An executable path.
276
277``triplet``:
278  A GNU style architecture, platform, operating system string.
279
280the ``Attribute`` field is:
281
282``none``:
283  Nothing, ignore
284
285``required``:
286  The host check must find the executable or path.
287
288``optional``:
289  The host check generates a warning if not found.
290
291``override``:
292  Only valid outside of the ``global`` map to indicate this macro overrides the
293  same one in the ``global`` map when the map containing it is selected.
294
295``undefine``:
296  Only valid outside of the ``global`` map to undefine the macro if it exists
297  in the ``global`` map when the map containing it is selected. The ``global``
298  map's macro is not visible but still exists.
299
300and the ``String`` field is a single or tripled multiline quoted string. The
301'String' can contain references to other macros. Macro that loop are not
302currently detected and will cause the tool to lock up.
303
304Maps are declared anywhere in the map using the map directive:
305
306.. code-block:: ini
307
308    # Comments
309    [my-special-map] <1>
310    _host:  none, override, 'abc-xyz'
311    multiline: none, override, '''First line,
312    second line,
313    and finally the last line'''
314
315.. topic:: Items:
316
317  1. The map is set to ``my-special-map``.
318
319Any macro definitions following a map declaration are placed in that map and the
320default map is ``global`` when loading a file. Maps are selected in
321configuration files by using the ``%select`` directive:
322
323.. code-block:: spec
324
325    %select my-special-map
326
327Selecting a map means all requests for a macro first check the selected map and
328if present return that value else the ``global`` map is used. Any new macros or
329changes update only the ``global`` map. This may change in future releases so
330please make sure you use the ``override`` attribute.
331
332The macro files specified on the command line are looked for in the
333``_configdir`` paths. See the definition of ``_configdir`` in
334:ref:`Configuration` for details. Included files need to add the
335``%{_configdir}`` macro to the start of the file.
336
337Macro map files can include other macro map files using the ``%include``
338directive. The macro map to build *binutils*, *gcc*, *newlib*, *gdb* and
339RTEMS from version control heads is:
340
341.. code-block:: spec
342
343    #
344    # Build all tool parts from version control head.
345    #
346    %include %{_configdir}/snapshots/binutils-head.mc
347    %include %{_configdir}/snapshots/gcc-head.mc
348    %include %{_configdir}/snapshots/newlib-head.mc
349    %include %{_configdir}/snapshots/gdb-head.mc
350
351.. topic:: Items:
352
353  1. The file is ``config/snapshots/binutils-gcc-newlib-gdb-head.mc``.
354
355The macro map defaults to ``global`` at the start of each included file and the
356map setting of the macro file including the other macro files does not change.
357
358Personal Macros
359~~~~~~~~~~~~~~~
360
361When the tools start to run they will load personal macros. Personal macros are
362in the standard format for macros in a file. There are two places personal
363macros can be configured. The first is the environment variable
364``RSB_MACROS``. If present the macros from the file the environment variable
365points to are loaded. The second is a file called ``.rsb_macros`` in your home
366directory. You need to have the environment variable ``HOME`` defined for this
367work.
368
369Configuration Reports
370^^^^^^^^^^^^^^^^^^^^^
371
372A configuration report detailing a build configuration is generated by the
373``sb-set-builder`` command. The report can also be generated separately from
374the build process by invoking the ``sb-report`` command on the build set used
375for the build, for example:
376
377.. code-block:: shell
378
379  cd rtems
380  ../source-builder/sb-reports 5/rtems-sparc
381  less 5-rtems-sparc.txt
382
383Report Mailing
384~~~~~~~~~~~~~~
385
386Configuration reports from a build can be mailed to a specific email address
387for logging and monitoring. Mailing requires a number of parameters to
388function. These are:
389
390- To mail address
391
392- From mail address
393
394- SMTP host
395
396.. _To Mail Address:
397
398The ``to`` mail address is taken from the macro ``%{_mail_tools_to}`` and the
399default is *rtems-tooltestresults at rtems.org*. You can override the default
400with a personal or user macro file or via the command line option
401``--mail-to``.
402
403.. _From Mail Address:
404
405The ``from`` mail address is taken from:
406
407- GIT configuration
408
409- User ``.mailrc`` file
410
411- Command line
412
413If you have configured an email and name in git it will be used used. If you do
414not a check is made for a ``.mailrc`` file. The environment variable ``MAILRC``
415is used if present else your home directory is check. If found the file is
416scanned for the ``from`` setting:
417
418.. code-block:: shell
419
420  set from="Foo Bar <foo@bar>"
421
422You can also support a from address on the command line with the ``--mail-from``
423option.
424
425The SMTP host is taken from the macro ``%{_mail_smtp_host}`` and the
426default is ``localhost``. You can override the default with a personal
427or user macro file or via the command line option ``--smtp-host``.
428
429Build Set Files
430^^^^^^^^^^^^^^^
431
432Build set files lets you list the packages in the build set you are defining
433and have a file extension of ``.bset``. Build sets can define macro variables,
434inline include other files and reference other build set or package
435configuration files.
436
437Defining macros is performed with the ``%define`` macro:
438
439.. code-block:: spec
440
441    %define _target m32r-rtems4.11
442
443Inline including another file with the ``%include`` macro continues processing
444with the specified file returning to carry on from just after the include
445point:
446
447.. code-block:: spec
448
449    %include rtems-4.11-base.bset
450
451This includes the RTEMS 4.11 base set of defines and checks. The configuration
452paths as defined by ``_configdir`` are scanned. The file extension is optional.
453
454You reference build set or package configuration files by placing the file name
455on a single line:
456
457.. code-block:: spec
458
459    tools/rtems-binutils-2.22-1
460
461The ``_configdir`` path is scanned for ``tools/rtems-binutils-2.22-1.bset`` or
462``tools/rtems-binutils-2.22-1.cfg``. Build set files take precedent over
463package configuration files. If ``tools/rtems-binutils-2.22-1`` is a build set
464a new instance of the build set processor is created and if the file is a
465package configuration the package is built with the package builder. This all
466happens once the build set file has finished being scanned.
467
468Configuration Control
469^^^^^^^^^^^^^^^^^^^^^
470
471The RTEMS Souce Builder is designed to fit within most verification and
472validation processes. All of the RTEMS Source Builder is source code. The
473Python code is source and comes with a commercial friendly license. All
474configuration data is text and can be read or parsed with standard text based
475tools.
476
477File naming provides configuration management. A specific version of a package
478is captured in a specific set of configuration files. The top level
479configuration file referenced in a *build set* or passed to the ``sb-builder``
480command relates to a specific configuration of the package being built. For
481example the RTEMS configuration file ``rtems-gcc-4.7.2-newlib-2.0.0-1.cfg``
482creates an RTEMS GCC and Newlib package where the GCC version is 4.7.2, the
483Newlib version is 2.0.0, plus any RTEMS specific patches that related to this
484version. The configuration defines the version numbers of the various parts
485that make up this package:
486
487.. code-block:: spec
488
489    %define gcc_version    4.7.2
490    %define newlib_version 2.0.0
491    %define mpfr_version   3.0.1
492    %define mpc_version    0.8.2
493    %define gmp_version    5.0.5
494
495The package build options, if there are any are also defined:
496
497.. code-block:: spec
498
499    %define with_threads 1
500    %define with_plugin  0
501    %define with_iconv   1
502
503The generic configuration may provide defaults in case options are not
504specified. The patches this specific version of the package requires can be
505included:
506
507.. code-block:: spec
508
509    Patch0: gcc-4.7.2-rtems4.11-20121026.diff
510
511Finally including the GCC 4.7 configuration script:
512
513.. code-block:: spec
514
515    %include %{_configdir}/gcc-4.7-1.cfg
516
517The ``gcc-4.7-1.cfg`` file is a generic script to build a GCC 4.7 compiler with
518Newlib. It is not specific to RTEMS. A bare no operating system tool set can be
519built with this file.
520
521The ``-1`` part of the file names is a revision. The GCC 4.7 script maybe
522revised to fix a problem and if this fix effects an existing script the file is
523copied and given a ``-2`` revision number. Any dependent scripts referencing
524the earlier revision number will not be effected by the change. This locks down
525a specific configuration over time.
526
527Personal Configurations
528^^^^^^^^^^^^^^^^^^^^^^^
529
530The RSB supports personal configurations. You can view the RTEMS support in the
531``rtems`` directory as a private configuration tree that resides within the RSB
532source. There is also the ``bare`` set of configurations. You can create your
533own configurations away from the RSB source tree yet use all that the RSB
534provides.
535
536To create a private configuration change to a suitable directory:
537
538.. code-block:: none
539
540    $ cd ~/work
541    $ mkdir test
542    $ cd test
543    $ mkdir config
544
545and create a ``config`` directory. Here you can add a new configuration or
546build set file. The section 'Adding New Configurations' details how to add a
547new confguration.
548
549New Configurations
550^^^^^^^^^^^^^^^^^^
551
552This section describes how to add a new configuration to the RSB. We will add a
553configuration to build the Device Tree Compiler. The Device Tree Compiler or
554DTC is part of the Flattened Device Tree project and compiles Device Tree
555Source (DTS) files into Device Tree Blobs (DTB). DTB files can be loaded by
556operating systems and used to locate the various resources such as base
557addresses of devices or interrupt numbers allocated to devices. The Device Tree
558Compiler source code can be downloaded from http://www.jdl.com/software. The
559DTC is supported in the RSB and you can find the configuration files under the
560``bare/config`` tree. I suggest you have a brief look over these files.
561
562Layering by Including
563~~~~~~~~~~~~~~~~~~~~~
564
565Configurations can be layered using the ``%include`` directive. The user
566invokes the outer layers which include inner layers until all the required
567configuration is present and the package can be built. The outer layers can
568provide high level details such as the version and the release and the inner
569layers provide generic configuration details that do not change from one
570release to another. Macro variables are used to provide the specific
571configuration details.
572
573Configuration File Numbering
574~~~~~~~~~~~~~~~~~~~~~~~~~~~~
575
576Configuration files have a number at the end. This is a release number for that
577configuration and it gives us the ability to track a specific configuration for
578a specific version. For example lets say the developers of the DTC package
579change the build system from a single makefile to autoconf and automake between
580version 1.3.0 and version 1.4.0. The configuration file used to build the
581package would change have to change. If we did not number the configuration
582files the ability to build 1.1.0, 1.2.0 or 1.3.0 would be lost if we update a
583common configuration file to build an autoconf and automake version. For
584version 1.2.0 the same build script can be used so we can share the same
585configuration file between version 1.1.0 and version 1.2.0. An update to any
586previous release lets us still build the package.
587
588Common Configuration Scripts
589~~~~~~~~~~~~~~~~~~~~~~~~~~~~
590
591Common configuration scripts that are independent of version, platform and
592architecture are useful to everyone. These live in the Source Builder's
593configuration directory. Currently there are scripts to build binutils, expat,
594DTC, GCC, GDB and libusb. These files contain the recipes to build these
595package without the specific details of the versions or patches being
596built. They expect to be wrapped by a configuration file that ties the package
597to a specific version and optionally specific patches.
598
599DTC Example
600~~~~~~~~~~~
601
602We will be building the DTC for your host rather than a package for RTEMS. We
603will create a file called ``source-builder/config/dtc-1-1.cfg``. This is a
604common script that can be used to build a specific version using a general
605recipe. The file name is ``dtc-1-1.cfg`` where the ``cfg`` extension indicates
606this is a configuration file. The first ``1`` says this is for the major
607release 1 of the package and the last ``1`` is the build configuration version.
608
609The file starts with some comments that detail the configuration. If there is
610anything unusual about the configuration it is a good idea to add something in
611the comments here. The comments are followed by a check for the release. In
612this case if a release is not provided a default of 1 is used:
613
614.. code-block:: spec
615
616    #
617    # DTC 1.x.x Version 1.
618    #
619    # This configuration file configure's, make's and install's DTC.
620    #
621
622    %if %{release} == %{nil}
623    %define release 1
624    %endif
625
626The next section defines some information about the package. It does not effect
627the build and is used to annotate the reports. It is recommended this
628information is kept updated and accurate:
629
630.. code-block:: spec
631
632    Name:      dtc-%{dtc_version}-%{_host}-%{release}
633    Summary:   Device Tree Compiler v%{dtc_version} for target %{_target} on host %{_host}
634    Version:   %{dtc_version}
635    Release:   %{release}
636    URL:           http://www.jdl.com/software/
637    BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
638
639The next section defines the source and any patches. In this case there is a
640single source package and it can be downloaded using the HTTP protocol. The RSB
641knows this is GZip'ped tar file. If more than one package is needed, add
642them increasing the index. The ``gcc-4.8-1.cfg`` configuration contains
643examples of more than one source package as well as conditionally including
644source packages based on the outer configuration options:
645
646.. code-block:: spec
647
648    #
649    # Source
650    #
651    %source set dtc http://www.jdl.com/software/dtc-v%{dtc_version}.tgz
652
653The remainder of the script is broken in to the various phases of a build. They
654are:
655
656. Preparation
657. Building
658. Installing, and
659. Cleaning
660
661Preparation is the unpacking of the source, applying any patches as well as any
662package specific set ups. This part of the script is a standard Unix shell
663script. Be careful with the use of ``%`` and ``$``. The RSB uses ``%`` while
664the shell scripts use ``$``.
665
666A standard pattern you will observe is the saving of the build's top
667directory. This is used instead of changing into a subdirectory and then
668changing to the parent when finished. Some hosts will change in a subdirectory
669that is a link however changing to the parent does not change back to the
670parent of the link rather it changes to the parent of the target of the link
671and that is something the RSB nor you can track easily. The RSB configuration
672script's are a collection of various subtle issues so please ask if you are
673unsure why something is being done a particular way.
674
675The preparation phase will often include source and patch setup commands. Outer
676layers can set the source package and add patches as needed while being able to
677use a common recipe for the build. Users can override the standard build and
678supply a custom patch for testing using the user macro command line interface:
679
680.. code-block:: spec
681
682    #
683    # Prepare the source code.
684    #
685    %prep
686      build_top=$(pwd)
687
688      %source setup dtc -q -n dtc-v%{dtc_version}
689      %patch setup dtc -p1
690
691      cd ${build_top}
692
693The configuration file ``gcc-common-1.cfg`` is a complex example of source
694preparation. It contains a number of source packages and patches and it
695combines these into a single source tree for building. It uses links to map
696source into the GCC source tree so GCC can be built using the *single source
697tree* method. It also shows how to fetch source code from version
698control. Newlib is taken directly from its CVS repository.
699
700Next is the building phase and for the DTC example this is simply a matter of
701running ``make``. Note the use of the RSB macros for commands. In the case of
702``%{__make}`` it maps to the correct make for your host. In the case of BSD
703systems we need to use the BSD make and not the GNU make.
704
705If your package requires a configuration stage you need to run this before the
706make stage. Again the GCC common configuration file provides a detailed example:
707
708.. code-block:: spec
709
710    %build
711      build_top=$(pwd)
712
713      cd dtc-v%{dtc_version}
714
715      %{build_build_flags}
716
717      %{__make} PREFIX=%{_prefix}
718
719      cd ${build_top}
720
721You can invoke make with the macro ``%{?_smp_flags}`` as a command line
722argument. This macro is controlled by the ``--jobs`` command line option and
723the host CPU detection support in the RSB. If you are on a multicore host you
724can increase the build speed using this macro. It also lets you disabled
725building on multicores to aid debugging when testing.
726
727Next is the install phase. This phase is a little more complex because you may
728be building a tar file and the end result of the build is never actually
729installed into the prefix on the build host and you may not even have
730permissions to perform a real install. Most packages install to the ``prefix``
731and the prefix is typically supplied via the command to the RSB or the
732package's default is used. The default can vary depending on the host's
733operating system. To install to a path that is not the prefix the ``DESTDIR``
734make variable is used. Most packages should honour the ``DISTDIR`` make
735variables and you can typically specify it on the command line to make when
736invoking the install target. This results in the package being installed to a
737location that is not the prefix but one you can control. The RSB provides a
738shell variable called ``SB_BUILD_ROOT`` you can use. In a build set where you
739are building a number of packages you can collect all the built packages in a
740single tree that is captured in the tar file.
741
742Also note the use of the macro ``%{__rmdir}``. The use of these macros allow
743the RSB to vary specific commands based on the host. This can help on hosts
744like Windows where bugs can effect the standard commands such as ``rm``. There
745are many many macros to help you. You can find these listed in the
746``defaults.mc`` file and in the trace output. If you are new to creating and
747editing configurations learning these can take a little time:
748
749.. code-block:: spec
750
751    %install
752      build_top=$(pwd)
753
754      %{__rmdir} -rf $SB_BUILD_ROOT
755
756      cd dtc-v%{dtc_version}
757      %{__make} DESTDIR=$SB_BUILD_ROOT PREFIX=%{_prefix} install
758
759      cd ${build_top}
760
761Finally there is an optional clean section. The RSB will run this section if
762``--no-clean`` has not been provided on the command line. The RSB does clean up
763for you.
764
765Once we have the configuration files we can execute the build using the
766``sb-builder`` command. The command will perform the build and create a tar file
767in the ``tar`` directory:
768
769.. code-block:: none
770
771    $  ../source-builder/sb-builder --prefix=/usr/local \
772         --log=log_dtc devel/dtc-1.2.0
773    RTEMS Source Builder, Package Builder v0.2.0
774    config: devel/dtc-1.2.0
775    package: dtc-1.2.0-x86_64-freebsd9.1-1
776    download: http://www.jdl.com/software/dtc-v1.2.0.tgz -> sources/dtc-v1.2.0.tgz
777    building: dtc-1.2.0-x86_64-freebsd9.1-1
778    $ ls tar
779    dtc-1.2.0-x86_64-freebsd9.1-1.tar.bz2
780
781If you want to have the package installed automatically you need to create a
782build set. A build set can build one or more packages from their configurations
783at once to create a single package. For example the GNU tools is typically seen
784as binutils, GCC and GDB and a build set will build each of these packages and
785create a single build set tar file or install the tools on the host into the
786prefix path.
787
788The DTC build set file is called ``dtc.bset`` and contains:
789
790.. code-block:: spec
791
792    #
793    # Build the DTC.
794    #
795
796    %define release 1
797
798    devel/dtc-1.2.0.cfg
799
800To build this you can use something similar to:
801
802.. code-block:: none
803
804    $ ../source-builder/sb-set-builder --prefix=/usr/local --log=log_dtc \
805       --trace --bset-tar-file --no-install dtc
806    RTEMS Source Builder - Set Builder, v0.2.0
807    Build Set: dtc
808    config: devel/dtc-1.2.0.cfg
809    package: dtc-1.2.0-x86_64-freebsd9.1-1
810    building: dtc-1.2.0-x86_64-freebsd9.1-1
811    tarball: tar/x86_64-freebsd9.1-dtc-set.tar.bz2
812    cleaning: dtc-1.2.0-x86_64-freebsd9.1-1
813    Build Set: Time 0:00:02.865758
814    $ ls tar
815    dtc-1.2.0-x86_64-freebsd9.1-1.tar.bz2   x86_64-freebsd9.1-dtc-set.tar.bz2
816
817The build is for a FreeBSD host and the prefix is for user installed
818packages. In this example I cannot let the source builder perform the install
819because I never run the RSB with root privileges so a build set or bset tar
820file is created. This can then be installed using root privileges.
821
822The command also supplies the ``--trace`` option. The output in the log file
823will contain all the macros.
824
825Debugging
826~~~~~~~~~
827
828New configuration files require debugging. There are two types of
829debugging. The first is debugging RSB script bugs. The ``--dry-run`` option is
830used here. Suppling this option will result in most of the RSB processing to be
831performed and suitable output placed in the log file. This with the ``--trace``
832option should help you resolve any issues.
833
834The second type of bug to fix are related to the execution of one of
835phases. These are usually a mix of shell script bugs or package set up or
836configuration bugs. Here you can use any normal shell script type debug
837technique such as ``set +x`` to output the commands or ``echo``
838statements. Debugging package related issues may require you start a build with
839the RSB and supply ``--no-clean`` option and then locate the build directories
840and change directory into them and manually run commands until to figure what
841the package requires.
842
843Scripting
844^^^^^^^^^
845
846Configuration files specify how to build a package. Configuration files are
847scripts and have a ``.cfg`` file extension. The script format is based loosely
848on the RPM spec file format however the use and purpose in this tool does not
849compare with the functionality and therefore the important features of the spec
850format RPM needs and uses.
851
852The script language is implemented in terms of macros. The built-in list is:
853
854``%{}``:
855  Macro expansion with conditional logic.
856
857``%()``:
858  Shell expansion.
859
860``%prep``:
861  The source preparation shell commands.
862
863``%build``:
864  The build shell commands.
865
866``%install``:
867  The package install shell commands.
868
869``%clean``:
870  The package clean shell commands.
871
872``%include``:
873  Inline include another configuration file.
874
875``%name``:
876  The name of the package.
877
878``%summary``:
879  A brief package description. Useful when reporting about a build.
880
881``%release``:
882  The package release. A number that is the release as built by this tool.
883
884``%version``:
885  The package's version string.
886
887``%buildarch``:
888  The build architecture.
889
890``%source``:
891  Define a source code package. This macro has a number appended.
892
893``%patch``:
894  Define a patch. This macro has a number appended.
895
896``%hash``:
897  Define a checksum for a source or patch file.
898
899``%{echo message}``:
900  Print the following string as a message.
901
902``%{warning message}``:
903  Print the following string as a warning and continue.
904
905``%{error message}``:
906  Print the following string as an error and exit.
907
908``%select``:
909  Select the macro map. If there is no map nothing is reported.
910
911``%define``:
912  Define a macro. Macros cannot be redefined, you must first undefine it.
913
914``%undefine``:
915  Undefine a macro.
916
917``%if``:
918  Start a conditional logic block that ends with a ``%endif``.
919
920``%ifn``:
921  Inverted start of a conditional logic block.
922
923``%ifarch``:
924  Test the architecture against the following string.
925
926``%ifnarch``:
927  Inverted test of the architecture
928
929``%ifos``:
930  Test the host operating system.
931
932``%else``:
933  Start the *else* conditional logic block.
934
935``%endfi``:
936  End the conditional logic block.
937
938``%bconf_with``:
939  Test the build condition *with* setting. This is the ``--with-*`` command
940  line option.
941
942``%bconf_without``:
943  Test the build condition *without* setting. This is the ``--without-*``
944  command line option.
945
946Expanding
947~~~~~~~~~
948
949A macro can be ``%{string}`` or the equivalent of ``%string``. The following macro
950expansions supported are:
951
952``%{string}``:
953  Expand the 'string' replacing the entire macro text with the text in the
954  table for the entry 'string . For example if 'var' is 'foo' then ``${var}``
955  would become ``foo``.
956
957``%{expand: string}``:
958  Expand the 'string' and then use it as a ``string`` to the macro expanding
959  the macro. For example if ``foo`` is set to ``bar`` and ``bar`` is set to
960  ``foobar`` then ``%{expand:foo}`` would result in ``foobar``. Shell expansion
961  can also be used.
962
963``%{with string}``:
964  Expand the macro to ``1`` if the macro ``with_string`` is defined else expand
965  to ``0``. Macros with the name ``with_string`` can be define with command
966  line arguments to the RTEMS Source Builder commands.
967
968``%{defined string}``:
969  Expand the macro to ``1`` if a macro of name ``string`` is defined else
970  expand to '0'.
971
972``%{?string: expression}``:
973  Expand the macro to ``expression`` if a macro of name ``string`` is defined
974  else expand to ``%{nil}``.
975
976``%{!?string: expression}``:
977  Expand the macro to ``expression`` if a macro of name ``string`` is not
978  defined. If the macro is define expand to ``%{nil}``.
979
980``%(expression)``:
981  Expand the macro to the result of running the ``expression`` in a host
982  shell. It is assumed this is a Unix type shell. For example ``%(whoami)``
983  will return your user name and ``%(date)`` will return the current date
984  string.
985
986.. _prep:
987
988%prep
989~~~~~
990
991The `%prep` macro starts a block that continues until the next block macro. The
992*prep* or preparation block defines the setup of the package's source and is a
993mix of RTEMS Source Builder macros and shell scripting. The sequence is
994typically `%source` macros for source, `%patch` macros to patch the source
995mixed with some shell commands to correct any source issues:
996
997.. code-block:: spec
998
999    %source setup gcc -q -c -T -n %{name}-%{version}
1000
1001.. topic:: Items:
1002
1003  1. The source group to set up is ``gcc``.
1004
1005  2. The source's name is the macro ``%{name}``.
1006
1007  3. The version of the source is the macro ``%{version}``.
1008
1009The source set up are declared with the source ``set`` and ``add`` commands. For
1010example:
1011
1012.. code-block:: spec
1013
1014    %source set gdb http://ftp.gnu.org/gnu/gdb/gdb-%{gdb_version}.tar.bz2
1015
1016This URL is the primary location of the GNU GDB source code and the RTEMS
1017Source Builder can download the file from this location and by inspecting the
1018file extension use ``bzip2`` decompression with `tar`. When the ``%prep``
1019section is processed a check of the local ``source`` directory is made to see
1020if the file has already been downloaded. If not found in the source cache
1021directory the package is downloaded from the URL. You can append other base
1022URLs via the command line option ``--url``. This option accepts a comma
1023delimited list of sites to try.
1024
1025You could optionally have a few source files that make up the package. For
1026example GNU's GCC was a few tar files for a while and it is now a single tar
1027file. Support for multiple source files can be conditionally implemented with
1028the following scripting:
1029
1030.. code-block:: spec
1031
1032    %source set gcc ftp://ftp.gnu.org/gnu/gcc/gcc-%{gcc_version}/gcc-code-%{gcc_version}.tar.bz2
1033    %source add gcc ftp://ftp.gnu.org/gnu/gcc/gcc-%{gcc_version}/gcc-g++-%{gcc_version}.tar.bz2
1034    %source setup gcc -q -T -D -n gcc-%{gcc_version}
1035
1036Separate modules use separate source groups. The GNU GCC compiler for RTEMS
1037uses Newlib, MPFR, MPC, and GMP source packages. You define the source with:
1038
1039.. code-block:: spec
1040
1041    %source set gcc ftp://ftp.gnu.org/gnu/gcc/gcc-%{gcc_version}/gcc-%{gcc_version}.tar.bz2
1042    %source set newlib ftp://sourceware.org/pub/newlib/newlib-%{newlib_version}.tar.gz
1043    %source set mpfr http://www.mpfr.org/mpfr-%{mpfr_version}/mpfr-%{mpfr_version}.tar.bz2
1044    %source set mpc http://www.multiprecision.org/mpc/download/mpc-%{mpc_version}.tar.gz
1045    %source set gmp ftp://ftp.gnu.org/gnu/gmp/gmp-%{gmp_version}.tar.bz2
1046
1047and set up with:
1048
1049.. code-block:: spec
1050
1051    %source setup gcc -q -n gcc-%{gcc_version}
1052    %source setup newlib -q -D -n newlib-%{newlib_version}
1053    %source setup mpfr -q -D -n mpfr-%{mpfr_version}
1054    %source setup mpc -q -D -n mpc-%{mpc_version}
1055    %source setup gmp -q -D -n gmp-%{gmp_version}
1056
1057Patching also occurs during the preparation stage. Patches are handled in a
1058similar way to the source packages except you only ``add`` patches. Patches are
1059applied using the `setup` command. The `setup` command takes the default patch
1060option. You can provide options with each patch by adding them as arguments
1061before the patch URL. Patches with no options uses the `setup` default.
1062
1063.. code-block:: spec
1064
1065    %patch add gdb %{rtems_gdb_patches}/gdb-sim-arange-inline.diff
1066    %patch add gdb -p0 %{rtems_gdb_patches}/gdb-sim-cgen-inline.diff
1067
1068.. topic:: Items:
1069
1070  1. This patch has the custom option of ``-p0``.
1071
1072To apply these patches:
1073
1074.. code-block:: spec
1075
1076    %patch setup gdb -p1
1077
1078.. topic:: Items:
1079
1080  1. The default options for ``gdb`` set up.
1081
1082.. _build:
1083
1084%build
1085~~~~~~
1086
1087The ``%build`` macro starts a block that continues until the next block
1088macro. The build block is a series of shell commands that execute to build the
1089package. It assumes all source code has been unpacked, patch and adjusted so
1090the build will succeed.
1091
1092The following is an example take from the GitHub STLink project. The STLink is
1093a JTAG debugging device for the ST ARM family of processors:
1094
1095.. code-block:: spec
1096
1097    %build
1098      export PATH="%{_bindir}:${PATH}"
1099
1100      cd texane-stlink-%{stlink_version}
1101
1102      ./autogen.sh
1103
1104    %if "%{_build}" != "%{_host}"
1105      CFLAGS_FOR_BUILD="-g -O2 -Wall" \
1106    %endif
1107      CPPFLAGS="-I $SB_TMPPREFIX/include/libusb-1.0" \
1108      CFLAGS="$SB_OPT_FLAGS" \
1109      LDFLAGS="-L $SB_TMPPREFIX/lib" \
1110      ./configure \
1111        --build=%{_build} --host=%{_host} \
1112        --verbose \
1113        --prefix=%{_prefix} --bindir=%{_bindir} \
1114        --exec-prefix=%{_exec_prefix} \
1115        --includedir=%{_includedir} --libdir=%{_libdir} \
1116        --mandir=%{_mandir} --infodir=%{_infodir}
1117
1118      %{__make} %{?_smp_mflags} all
1119
1120      cd ..
1121
1122.. topic:: Items:
1123
1124  1. Set up the PATH environment variable by setting the ``PATH`` environment
1125     variable. This is not always needed.
1126
1127  2. This package builds in the source tree
1128     ``texane-stlink-%{stlink_version}`` so enter it before building.
1129
1130  3. The package is actually checked directly out from the github project and
1131     so it needs its ``autoconf`` and ``automake`` files generated. Invoke the
1132     provided script ``autogen.sh``
1133
1134  4. If the build machine and host are not the same the build is a
1135     cross-compile. Update the flags for a cross-compiled build.
1136
1137  5. The flags set in the environment before ``configure`` are various
1138     settings that need to be passed to customise the build. In this example
1139     an include path is being set to the install point of ``libusb``. This
1140     package requires ``libusb`` is built before it.
1141
1142  6. The ``configure`` command. The RTEMS Source Builder provides all the
1143     needed paths as macro variables. You just need to provide them to
1144     ``configure``.
1145
1146  7. Run ``make``. Do not use ``make`` directly, use the RTEMS Source
1147     Builder's defined value. This value is specific to the host. A large
1148     number of packages need GNU make and on BSD systems this is
1149     ``gmake``. You can optionally add the SMP flags if the packages build
1150     system can handle parallel building with multiple jobs. The
1151     ``_smp_mflags`` value is automatically setup for SMP hosts to match the
1152     number of cores the host has.
1153
1154%install
1155~~~~~~~~
1156
1157The ``%install`` macro starts a block that continues until the next block
1158macro. The install block is a series of shell commands that execute to install
1159the package. You can assume the package has built correctly when this block
1160starts executing.
1161
1162Never install the package to the actual *prefix* the package was built
1163with. Always install to the RTEMS Source Builder's temporary path defined in
1164the macro variable ``__tmpdir``. The RTEMS Source Builder sets up a shell
1165environment variable called ``SB_BUILD_ROOT`` as the standard install point. Most
1166packages support adding ``DESTDIR=`` to the ``make install`` command.
1167
1168Looking at the same example as in :ref:`build`:
1169
1170.. code-block:: spec
1171
1172    %install
1173      export PATH="%{_bindir}:${PATH}" <1>
1174      rm -rf $SB_BUILD_ROOT <2>
1175
1176      cd texane-stlink-%{stlink_version} <3>
1177      %{__make} DESTDIR=$SB_BUILD_ROOT install <4>
1178
1179      cd ..
1180
1181.. topic:: Items:
1182
1183  1. Setup the PATH environment variable. This is not always needed.
1184
1185  2. Clean any installed files. This makes sure the install is just what the
1186     package installs and not any left over files from a broken build or
1187     install.
1188
1189  3. Enter the build directory. In this example it just happens to be the
1190     source directory.
1191
1192  4. Run ``make install`` to install the package overriding the ``DESTDIR``
1193     make variable.
1194
1195%clean
1196~~~~~~
1197
1198The ``%clean`` macro starts a block that continues until the next block
1199macro. The clean block is a series of shell commands that execute to clean up
1200after a package has been built and install. This macro is currenly not been
1201used because the RTEMS Source Builder automatically cleans up.
1202
1203%include
1204~~~~~~~~
1205
1206The ``%include`` macro inline includes the specific file. The ``__confdir``
1207path is searched. Any relative path component of the include file is appended
1208to each part of the ``__configdir``. Adding an extension is optional as files
1209with ``.bset`` and ``.cfg`` are automatically searched for.
1210
1211Inline including means the file is processed as part of the configuration at
1212the point it is included. Parsing continues from the next line in the
1213configuration file that contains the ``%include`` macro.
1214
1215Including files allow a kind of configuration file reuse. The outer
1216configuration files provide specific information such as package version
1217numbers and patches and then include a generic configuration script which
1218builds the package:
1219
1220.. code-block:: spec
1221
1222    %include %{_configdir}/gcc-4.7-1.cfg
1223
1224%name
1225~~~~~
1226
1227The name of the package being built. The name typically contains the components
1228of the package and their version number plus a revision number. For the GCC
1229with Newlib configuration the name is typically::
1230
1231    Name: %{_target}-gcc-%{gcc_version}-newlib-%{newlib_version}-%{release}
1232
1233%summary
1234~~~~~~~~
1235
1236The ``%summary`` is a brief description of the package. It is useful when
1237reporting. This information is not capture in the package anywhere. For the GCC
1238with Newlib configuration the summary is typically:
1239
1240.. code-block:: spec
1241
1242    Summary: GCC v%{gcc_version} and Newlib v%{newlib_version} for target %{_target} on host %{_host}
1243
1244%release
1245~~~~~~~~
1246
1247The ``%release`` is a packaging number that allows revisions of a package to
1248happen where no package versions change. This value typically increases when
1249the configuration building the package changes:
1250
1251.. code-block:: spec
1252
1253    %define release 1
1254
1255%version
1256~~~~~~~~
1257
1258The ``%version`` macro sets the version the package. If the package is a single
1259component it tracks that component's version number. For example in the
1260``libusb`` configuration the ``%version`` is the same as ``%libusb_version``,
1261however in a GCC with Newlib configuration there is no single version
1262number. In this case the GCC version is used:
1263
1264.. code-block:: spec
1265
1266    Version: %{gcc_version}
1267
1268%buildarch
1269~~~~~~~~~~
1270
1271The ``%buildarch`` macro is set to the architecture the package contains. This
1272is currently not used in the RTEMS Source Builder and may go away. This macro
1273is more important in a real packaging system where the package could end up on
1274the wrong architecture.
1275
1276%source
1277~~~~~~~
1278
1279The ``%source`` macro has 3 commands that controls what it does. You can
1280``set`` the source files, ``add`` source files to a source group, and ``setup``
1281the source file group getting it ready to be used.
1282
1283Source files are source code files in tar or zip files that are unpacked,
1284copied or symbolically linked into the package's build tree. Building a package
1285requires one or more dependent packages. These are typically the packages
1286source code plus dependent libraries or modules. You can create any number of
1287these source groups and set each of them up with a separate source group for
1288each needed library or module. Each source group normally has a single tar, zip
1289or repository and the ``set`` defines this. Some projects split the source code
1290into separate tar or zip files and you install them by using the ``add``
1291command.
1292
1293The first instance of a ``set`` command creates the source group and sets the
1294source files to be set up. Subsequent ``set`` commands for the same source
1295group are ignored. this lets you define the standard source files and override
1296them for specific releases or snapshots. To set a source file group:
1297
1298.. code-block:: spec
1299
1300    %source set gcc ftp://ftp.gnu.org/gnu/gcc/gcc-%{gcc_version}/gcc-%{gcc_version}.tar.bz2
1301
1302.. topic:: Items:
1303
1304  1. The source group is ``gcc``.
1305
1306To add another source package to be installed into the same source tree you use
1307the ``add`` command:
1308
1309.. code-block:: spec
1310
1311    %source add gcc ftp://ftp.gnu.org/gnu/gcc/gcc-%{gcc_version}/g++-%{gcc_version}.tar.bz2
1312
1313The source ``setup`` command can only be issued in the ``%prep:`` section. The
1314setup is:
1315
1316.. code-block:: spec
1317
1318    %source gcc setup -q -T -D -n %{name}-%{version}
1319
1320Accepted options are:
1321
1322``-n``:
1323  The ``-n`` option is used to set the name of the software's build
1324  directory. This is necessary only when the source archive unpacks into a
1325  directory named other than ``<name>-<version>``.
1326
1327``-c``:
1328  The ``-c`` option is used to direct ``%setup`` to create the top-level build
1329  directory before unpacking the sources.
1330
1331``-D``:
1332  The ``-D`` option is used to direct ``%setup`` to not delete the build
1333  directory prior to unpacking the sources. This option is used when more than
1334  one source archive is to be unpacked into the build directory, normally with
1335  the ``-b`` or ``-a`` options.
1336
1337``-T``:
1338   The ``-T`` option is used to direct %setup to not perform the default
1339   unpacking of the source archive specified by the first ``Source:`` macro. It
1340   is used with the ``-a`` or ``-b`` options.
1341
1342``-b <n>``:
1343  The ``-b`` option is used to direct ``%setup`` to unpack the source archive
1344  specified on the nth ``Source:`` macro line before changing directory into
1345  the build directory.
1346
1347%patch
1348~~~~~~
1349
1350The ``%patch`` macro has the same 3 command as the ``%source`` command however
1351the ``set`` commands is not really that useful with the ``%patch`` command. You
1352add patches with the ``add`` command and ``setup`` applies the patches. Patch
1353options can be added to each patch by placing them before the patch URL. If no
1354patch option is provided the default options passed to the ``setup`` command
1355are used. An option starts with a ``-``. The ``setup`` command must reside
1356inside the ``%prep`` section.
1357
1358Patches are grouped in a similar way to the ``%source`` macro so you can
1359control applying a group of patches to a specific source tree.
1360
1361The ``__patchdir`` path is searched.
1362
1363To add a patch:
1364
1365.. code-block:: spec
1366
1367    %patch add gcc  gcc-4.7.2-rtems4.11-20121026.diff
1368    %patch add gcc -p0  gcc-4.7.2-rtems4.11-20121101.diff
1369
1370.. topic:: Items:
1371
1372  1. The patch group is ``gcc``.
1373
1374  2. Option ``-p0`` is this specific to this patch.
1375
1376Placing ``%patch setup`` in the ``%prep`` section will apply the groups
1377patches::
1378
1379.. code-block:: spec
1380
1381    %patch setup gcc  -p1
1382
1383  1. The patch group is ``gcc``.
1384
1385  2. The default option used to apply the patch is ``-p1``.
1386
1387%hash
1388~~~~~
1389
1390The ``%hash`` macro requires 3 arguments and defines a checksum for a specific
1391file. The checksum is not applied until the file is checked before downloading
1392and once downloaded. A patch or source file that does not have a hash defined
1393generates a warning.
1394
1395A file to be checksummed must be unique in the source and patch directories.
1396The basename of the file is used as the key for the hash.
1397
1398The hash algorthim can be ``md5``, ``sha1``, ``sha224``, ``sha256``,
1399``sha384``, and ``sha512`` and we typically use ``md5``.
1400
1401To add a hash:
1402
1403.. code-block:: spec
1404
1405    %hash md5 <1> net-snmp-%{net_snmp_version}.tar.gz <2> 7db683faba037249837b226f64d566d4 <3>
1406
1407.. topic:: Items:
1408
1409  1. The type of checksum.
1410
1411  2. The file to checksum. It can contain macros that are expanded for you.
1412
1413  3. The MD5 hash for the Net-SNMP file ``net-snmp-5.7.2.1.tar.gz``.
1414
1415Do not include a path with the file name. Only the basename is required. Files
1416can be searched for from a number of places and having a path conponent would
1417create confusion. This does mean files with hashes must be unique.
1418
1419Downloading off repositories such as git and cvs cannot be checksummed. It is
1420assumed those protocols and tools manage the state of the files.
1421
1422%echo
1423~~~~~
1424
1425The ``%echo`` macro outputs the following string to stdout. This can also be used
1426as ``%{echo: message}``.
1427
1428%warning
1429~~~~~~~~
1430
1431The ``%warning`` macro outputs the following string as a warning. This can also
1432be used as ``%{warning: message}``.
1433
1434%error
1435~~~~~~
1436
1437The ``%error`` macro outputs the follow string as an error and exits the RTEMS
1438Source Builder. This can also be used as ``%{error: message}``.
1439
1440%select
1441~~~~~~~
1442
1443The ``%select`` macro selects the map specified. If there is no map no error or
1444warning is generated. Macro maps provide a simple way for a user to override
1445the settings in a configuration file without having to edit it. The changes are
1446recorded in the build report so they can be traced.
1447
1448Configurations use different maps so macro overrides can target a specific
1449package.
1450
1451The default map is ``global``:
1452
1453.. code-block:: spec
1454
1455    %select gcc-4.8-snapshot <1>
1456    %define one_plus_one 2 <2>
1457
1458.. topic:: Items:
1459
1460  1. The map switches to ``gcc-4.8-snapshot``. Any overrides in this map will
1461     be used.
1462
1463  2. Defining macros only updates the ``global`` map and not the selected map.
1464
1465%define
1466~~~~~~~
1467
1468The ``%define`` macro defines a new macro or updates an existing one. If no
1469value is given it is assumed to be ``1``:
1470
1471.. code-block:: spec
1472
1473    %define foo bar
1474    %define one_plus_one 2
1475    %define one <1>
1476
1477.. topic:: Items:
1478
1479  1. The macro _one_ is set to 1.
1480
1481%undefine
1482~~~~~~~~~
1483
1484The ``%undefine`` macro removes a macro if it exists. Any further references to
1485it will result in an undefine macro error.
1486
1487%if
1488~~~
1489
1490The ``%if`` macro starts a conditional logic block that can optionally have a
1491*else* section. A test follows this macro and can have the following operators:
1492
1493.. list-table::
1494
1495  * - **%{}**
1496    - Check the macro is set or *true*, ie non-zero:
1497
1498      .. code-block:: spec
1499
1500         %if ${foo}
1501          %warning The test passes, must not be empty or is non-zero
1502         %else
1503          %error The test fails, must be empty or zero
1504         %endif
1505
1506  * - **\!**
1507    - The *not* operator inverts the test of the macro:
1508
1509      .. code-block:: spec
1510
1511         %if ! ${foo}
1512          %warning The test passes, must be empty or zero
1513         %else
1514          %error The test fails, must not be empty or is non-zero
1515         %endif
1516
1517  * - **==**
1518    - The left hand size must equal the right hand side. For example:
1519
1520      .. code-block:: spec
1521
1522         %define one 1
1523         %if ${one} == 1
1524          %warning The test passes
1525         %else
1526          %error The test fails
1527         %endif
1528
1529      You can also check to see if a macro is empty:
1530
1531      .. code-block:: spec
1532
1533         %if ${nothing} == %{nil}
1534          %warning The test passes
1535         %else
1536          %error The test fails
1537
1538  * - **!=**
1539    - The left hand size does not equal the right hand side. For example:
1540
1541      .. code-block:: spec
1542
1543         #
1544         # Check a value not being equal.
1545         #
1546         %define one 1
1547         %if ${one} != 2
1548          %warning The test passes
1549         %else
1550          %error The test fails
1551         %endif
1552         #
1553         # Check if a macro is set.
1554         #
1555         %if ${something} != %{nil}
1556           %warning The test passes
1557         %else
1558          %error The test fails
1559         %endif
1560
1561  * - **>**
1562    - The left hand side is numerically greater than the right hand side.
1563
1564  * - **>**
1565    - The left hand side is numerically greater than or equal to the
1566      right hand side.
1567
1568  * - **<**
1569    - The left hand side is numerically less than the right hand side.
1570
1571  * - **<=**
1572    - The left hand side is numerically less than or equal to the
1573      right hand side.
1574
1575%ifn
1576~~~~
1577
1578The ``%ifn`` macro inverts the normal ``%if`` logic. It avoids needing to provide
1579empty *if* blocks followed by *else* blocks. It is useful when checking if a
1580macro is defined:
1581
1582.. code-block:: spec
1583
1584    %ifn %{defined foo}
1585     %define foo bar
1586    %endif
1587
1588%ifarch
1589~~~~~~~
1590
1591The ``%ifarch`` is a short cut for ``%if %{_arch} == i386``. Currently not used.
1592
1593%ifnarch
1594~~~~~~~~
1595
1596The ``%ifnarch`` is a short cut for ``%if %{_arch} != i386``. Currently not
1597used.
1598
1599%ifos
1600~~~~~
1601
1602The ``%ifos`` is a short cut for ``%if %{_os} != mingw32``. It allows
1603conditional support for various operating system differences when building
1604packages.
1605
1606%else
1607~~~~~
1608
1609The ``%else`` macro starts the conditional *else* block.
1610
1611%endfi
1612~~~~~~
1613
1614The ``%endif`` macro ends a conditional logic block.
1615
1616%bconf_with
1617~~~~~~~~~~~
1618
1619The ``%bconf_with`` macro provides a way to test if the user has passed a
1620specific option on the command line with the ``--with-<label>`` option. This
1621option is only available with the ``sb-builder`` command.
1622
1623%bconf_without
1624~~~~~~~~~~~~~~
1625
1626The ``%bconf_without`` macro provides a way to test if the user has passed a
1627specific option on the command line with the ``--without-<label>`` option. This
1628option is only available with the ``sb-builder`` command.
Note: See TracBrowser for help on using the repository browser.