]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/libcdl/doc/language.sgml
Initial revision
[karo-tx-redboot.git] / tools / src / libcdl / doc / language.sgml
1 <!-- {{{ Banner                 -->
2
3 <!-- =============================================================== -->
4 <!--                                                                 -->
5 <!--     language.sgml                                               -->
6 <!--                                                                 -->
7 <!--     The CDL language.                                           -->
8 <!--                                                                 -->
9 <!-- =============================================================== -->
10 <!-- ####COPYRIGHTBEGIN####                                          -->
11 <!--                                                                 -->
12 <!-- =============================================================== -->
13 <!-- Copyright (C) 2000, 2001, 2002 Red Hat, Inc.                    -->
14 <!--                                                                 -->
15 <!-- This material may be distributed only subject to the terms      -->
16 <!-- and conditions set forth in the Open Publication License, v1.0  -->
17 <!-- or later (the latest version is presently available at          -->
18 <!-- http://www.opencontent.org/openpub/)                            -->
19 <!-- Distribution of the work or derivative of the work in any       -->
20 <!-- standard (paper) book form is prohibited unless prior           -->
21 <!-- permission obtained from the copyright holder                   -->
22 <!-- =============================================================== -->
23 <!--                                                                 -->      
24 <!-- ####COPYRIGHTEND####                                            -->
25 <!-- =============================================================== -->
26 <!-- #####DESCRIPTIONBEGIN####                                       -->
27 <!--                                                                 -->
28 <!-- Author(s):   bartv                                              -->
29 <!-- Contact(s):  bartv                                              -->
30 <!-- Date:        2000/02/06                                         -->
31 <!-- Version:     0.01                                               -->
32 <!--                                                                 -->
33 <!-- ####DESCRIPTIONEND####                                          -->
34 <!-- =============================================================== -->
35
36 <!-- }}} -->
37
38 <chapter id="language">
39 <title>The CDL Language</title>
40
41 <!-- {{{ Introit                -->
42
43 <para>
44 The &CDL; language is a key part of the &eCos; component framework.
45 All packages must come with at least one &CDL; script, to describe
46 that package to the framework. The information in that script includes
47 details of all the configuration options and how to build the package.
48 Implementing a new component or turning some existing code into an
49 &eCos; component always involves writing corresponding &CDL;. This
50 chapter provides a description of the &CDL; language. Detailed
51 information on specific parts of the language can be found in <xref
52 linkend="reference">.
53 </para>
54
55 <!-- }}} -->
56 <!-- {{{ Language overview      -->
57
58 <sect1 id="language.overview">
59 <title>Language Overview</title>
60 <para>
61 A very simple &CDL; script would look like this:
62 </para>
63 <programlisting width=72>
64 cdl_package CYGPKG_ERROR {
65     display       "Common error code support"
66     compile       strerror.cxx
67     include_dir   cyg/error
68     description   "
69         This package contains the common list of error and
70         status codes. It is held centrally to allow
71         packages to interchange error codes and status
72         codes in a common way, rather than each package
73         having its own conventions for error/status
74         reporting. The error codes are modelled on the
75         POSIX style naming e.g. EINVAL etc. This package
76         also provides the standard strerror() function to
77         convert error codes to textual representation."
78 }
79 </programlisting>
80 <para>
81 This describes a single package, the error code package, which does
82 not have any sub-components or configuration options. The package has
83 an internal name, <varname>CYGPKG_ERROR</varname>, which can be
84 referenced in other &CDL; scripts using e.g.
85 <literal>requires&nbsp;CYGPKG_ERROR</literal>. There will also be a
86 <literal>#define</literal> for this symbol in a configuration header
87 file. In addition to the package name, this script provides a number
88 of properties for the package as a whole. The &display; property
89 provides a short description. The &description; property involves a
90 rather longer one, for when users need a bit more information. The
91 &compile; and &include-dir; properties list the consequences of this
92 package at build-time. The package appears to lack any on-line
93 documentation. 
94 </para>
95 <para>
96 Packages could be even simpler than this. If the package only provides
97 an interface and there are no files to be compiled then there is no
98 need for a &compile; property. Alternatively if there are no exported
99 header files, or if the exported header files should go to the
100 top-level of the <filename
101 class="directory">install/include</filename> directory, then there is
102 no need for an &include-dir; property. Strictly speaking the
103 &description; and &display; properties are optional as well, although
104 application developers would not appreciate the resulting lack of
105 information about what the package is supposed to do.
106 </para>
107 <para>
108 However many packages tend to be a bit more complicated than the error
109 package, containing various sub-components and configuration options.
110 These are also defined in the &CDL; scripts and in much the same way
111 as the package. For example, the following excerpt comes from the
112 infrastructure package:
113 </para>
114 <programlisting width=72>
115 cdl_component CYGDBG_INFRA_DEBUG_TRACE_ASSERT_BUFFER {
116     display       "Buffered tracing"
117     default_value 1
118     active_if     CYGDBG_USE_TRACING
119     description   "
120         An output module which buffers output from tracing and
121         assertion events. The stored messages are output when an
122         assert fires, or CYG_TRACE_PRINT() (defined in
123         &lt;cyg/infra/cyg_trac.h&gt;) is called. Of course, there will
124         only be stored messages if tracing per se (CYGDBG_USE_TRACING)
125         is enabled above."
126
127     cdl_option CYGDBG_INFRA_DEBUG_TRACE_BUFFER_SIZE {
128         display       "Trace buffer size"
129         flavor        data
130         default_value 32
131         legal_values  5 to 65535
132         description   "
133             The size of the trace buffer. This counts the number of
134             trace records stored. When the buffer fills it either
135             wraps, stops recording, or generates output."
136     }
137
138     &hellip;
139 }
140 </programlisting>
141 <para>
142 Like a &cdl-package;, a &cdl-component; has a name and a body. The
143 body contains various properties for that component, and may also
144 contain sub-components or options. Similarly a &cdl-option; has a
145 name and a body of properties. This example lists a number of
146 new properties: &default-value;, &active-if;, &flavor; and
147 &legal-values;. The meaning of most of these should be fairly obvious.
148 The next sections describe the various &CDL; commands and properties. 
149 </para>
150 <para>
151 There is one additional and very important point: &CDL; is not a
152 completely new language; instead it is implemented as an extension of
153 the existing &Tcl; scripting language. The syntax of a &CDL; script is
154 &Tcl; syntax, which is described below. In addition some of the more
155 advanced facilities of &CDL; involve embedded fragments of &Tcl; code,
156 for example there is a &define-proc; property which specifies some
157 code that needs to be executed when the component framework generates
158 the configuration header files.
159 </para>
160
161 </sect1>
162
163 <!-- }}} -->
164 <!-- {{{ CDL commands           -->
165
166 <sect1 id="language.commands">
167 <title>CDL Commands</title>
168 <para>
169 There are four &CDL;-related commands which can occur at the top-level
170 of a &CDL; script: &cdl-package;, &cdl-component;, &cdl-option; and
171 &cdl-interface;. These correspond to the basic building blocks of the
172 language (CDL interfaces are described in <xref
173 linkend="language.interface">). All of these take the same basic form:
174 </para>
175 <programlisting width=72>
176 cdl_package &lt;name&gt; {
177     &hellip;
178 }
179
180 cdl_component &lt;name&gt; {
181     &hellip;
182 }
183
184 cdl_option &lt;name&gt; {
185     &hellip;
186 }
187
188 cdl_interface &lt;name&gt; {
189     &hellip;
190 }
191 </programlisting>
192 <para>
193 The command is followed by a name and by a body of properties, the
194 latter enclosed in braces. Packages and components can contain other
195 entities, so the &cdl-package; and &cdl-component; can also have
196 nested commands in their bodies. All names must be unique within a
197 given configuration. If say the C library package and a TCP/IP stack
198 both defined an option with the same name then it would not be
199 possible to load both of them into a single configuration. There is a
200 <link linkend="language.naming">naming convention</link> which should
201 make accidental name clashes very unlikely.
202 </para>
203 <para>
204 It is possible for two packages to use the same name if there are no
205 reasonable circumstances under which both packages could be loaded at
206 the same time. One example would be architectural HAL packages: a
207 given &eCos; configuration can be used on only one processor, so the
208 architectural HAL packages <varname>CYGPKG_HAL_ARM</varname> and
209 <varname>CYGPKG_HAL_I386</varname> can re-use option names; in fact
210 in some cases they are expected to.
211 </para>
212 <para>
213 Each package has one top-level &CDL; script, which is specified in the
214 packages <link
215 linkend="language.database"><database>ecos.db</database> database
216 entry</link>. Typically the name of this top-level script is related to
217 the package, so the kernel package uses
218 <filename>kernel.cdl</filename>, but this is just a convention. The
219 first command in the top-level script should be &cdl-package;, and the
220 name used should be the same as in the <database>ecos.db</database>
221 database. There should be only one &cdl-package; command per package.
222 </para>
223 <para>
224 The various &CDL; entities live in a hierarchy. For example the kernel
225 package contains a scheduling component, a synchronization primitives
226 component, and a number of others. The synchronization component
227 contains various options such as whether or not mutex priority
228 inheritance is enabled. There is no upper bound on how far components
229 can be nested, but it is rarely necessary to go more than three or
230 four levels deeper than the package level. Since the naming convention
231 incorporates bits of the hierarchy, this has the added advantage of
232 keeping the names down to a more manageable size.
233 </para>
234 <para>
235 The hierarchy serves two purposes. It allows options to be controlled
236 en masse, so disabling a component automatically disables all the
237 options below it in the hierarchy. It also permits a much simpler
238 representation of the configuration in the graphical configuration
239 tool, facilitating navigation and modification.
240 </para>
241 <para>
242 By default a package is placed at the top-level of the hierarchy, but
243 it is possible to override this using a &parent; property. For example
244 an architectural HAL package such as <varname>CYGPKG_HAL_SH</varname>
245 typically re-parents itself below <varname>CYGPKG_HAL</varname>, and a
246 platform HAL package would then re-parent itself below the
247 architectural HAL. This makes it a little bit easier for users to
248 navigate around the hierarchy. Components, options and interfaces can
249 also be re-parented, but this is less common.
250 </para>
251 <para>
252 All components, options and interfaces that are defined directly in
253 the top-level script will be placed below the package in the hierarchy.
254 Alternatively they can be nested in the body of the &cdl-package;
255 command. The following two script fragments are equivalent:
256 </para>
257 <programlisting width=72>
258 cdl_package CYGPKG_LIBC {
259     &hellip;
260 }
261
262 cdl_component CYGPKG_LIBC_STRING {
263     &hellip;
264 }
265
266 cdl_option CYGPKG_LIBC_CTYPE_INLINES {
267     &hellip;
268 }
269 </programlisting>
270 <para>
271 and:
272 </para>
273 <programlisting width=72>
274 cdl_package CYGPKG_LIBC {
275     &hellip;
276
277     cdl_component CYGPKG_LIBC_STRING {
278         &hellip;
279     }
280
281     cdl_option CYGPKG_LIBC_CTYPE_INLINES {
282         &hellip;
283     }
284 }
285 </programlisting>
286 <para>
287 If a script defines options both inside and outside the body of the
288 &cdl-package; then the ones inside will be processed first. Language
289 purists may argue that it would have been better if all contained
290 options and components had to go into the body, but in practice it is
291 often convenient to be able to skip this level of nesting and the
292 resulting behavior is still well-defined.
293 </para>
294 <para>
295 Components can also contain options and other &CDL; entities, in fact
296 that is what distinguishes them from options. These can be defined in
297 the body of the &cdl-component; command:
298 </para>
299 <programlisting width=72>
300 cdl_component CYGPKG_LIBC_STDIO {
301
302     cdl_component CYGPKG_LIBC_STDIO_FLOATING_POINT {
303         &hellip;
304     }
305
306     cdl_option CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS {
307         &hellip;
308     }
309 }
310 </programlisting>
311 <para>
312 Nesting options inside the bodies of components like this is fine for
313 simple packages with only a limited number of configuration options,
314 but it becomes unsatisfactory as the number of options increases.
315 Instead it is possible to split the &CDL; data into multiple &CDL;
316 scripts, on a per-component basis. The &script; property should be
317 used for this. For example, in the case of the C library all
318 stdio-related configuration options could be put into
319 <filename>stdio.cdl</filename>, and the top-level CDL script
320 <filename>libc.cdl</filename> would contain the following:
321 </para>
322 <programlisting width=72>
323 cdl_package CYGPKG_LIBC {
324     &hellip;
325
326     cdl_component CYGPKG_LIBC_STDIO {
327         &hellip;
328         script stdio.cdl
329     }
330 }
331 </programlisting>
332 <para>
333 The <varname>CYGPKG_LIBC_STDIO_FLOATING_POINT</varname> component and
334 the <varname>CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS</varname> option
335 can then be placed at the top-level of <filename>stdio.cdl</filename>.
336 It is possible to have some options nested in the body of a
337 &cdl-component; command and other options in a separate file accessed
338 by the &script; property. In such a case the nested options would be
339 processed first, and then the other script would be read in. A script
340 specified by a &script; property should only define new options,
341 components or interfaces: it should not contain any additional
342 properties for the current component.
343 </para>
344 <para>
345 It is possible for a component's &CDL; script to have a sub-component
346 which also has a &script; property, and so on. In practice excessive
347 nesting like this is rarely useful. It is also possible to ignore the
348 &CDL; language support for constructing hierarchies automatically and
349 use the &parent; property explicitly for every single option and
350 component. Again this is not generally useful.
351 </para>
352 <note>
353 <para>
354 At the time of writing interfaces cannot act as containers. This may
355 change in a future version of the component framework. If the change
356 is made then interfaces would support the &script; property, just like
357 components.
358 </para>
359 </note>
360
361 </sect1>
362
363 <!-- }}} -->
364 <!-- {{{ CDL properties         -->
365
366 <!-- {{{ Introit                -->
367
368 <sect1 id="language.properties">
369 <title>CDL Properties</title>
370 <para>
371 Each package, component, option, and interface has a body of
372 properties, which provide the component framework with information
373 about how to handle each option. For example there is a property for a
374 descriptive text message which can be displayed to a user who is
375 trying to figure out just what effect manipulating the option would
376 have on the target application. There is another property for the
377 default value, for example whether a particular option should be
378 enabled or disabled by default.
379 </para>
380 <para>
381 All of the properties are optional, it is legal to define a
382 configuration option which has an empty body. However some properties
383 are more optional than others: users will not appreciate having to
384 manipulate an option if they are not given any sort of description or
385 documentation. Other properties are intended only for very specific
386 purposes, for example &make-object; and &include-files;, and are used
387 only rarely.
388 </para>
389 <para>
390 Because different properties serve very different purposes, their
391 syntax is not as uniform as the top-level commands. Some properties
392 take no arguments at all. Other properties take a single argument such
393 as a description string, or a list of arguments such as a &compile;
394 property which specifies the file or files that should be compiled if
395 a given option is active and enabled. The &define-proc; property takes
396 as argument a snippet of &Tcl; code. The &active-if;, &calculated;,
397 &default-value;, &legal-values; and &requires; properties take various
398 expressions. Additional properties may be defined in future which take
399 new kinds of arguments.
400 </para>
401 <para>
402 All property parsing code supports options for every property,
403 although at present the majority of properties do not yet take any
404 options. Any initial arguments that begin with a hyphen character
405 <literal>-</literal> will be interpreted as an option, for example:
406 </para>
407 <programlisting width=72>
408 cdl_package CYGPKG_HAL_ARM {
409     &hellip;
410     make -priority 1 {
411         &hellip;
412     }
413 }
414 </programlisting>
415 <para>
416 If the option involves additional data, as for the
417 <literal>-priority</literal> example above, then this can be written
418 as either <literal>-priority=1</literal> or as
419 <literal>-priority&nbsp;1</literal>. On occasion the option parsing
420 code can get in the way, for example:
421 </para>
422 <programlisting width=72>
423 cdl_option CYGNUM_LIBC_TIME_DST_DEFAULT_STATE {
424     &hellip;
425     legal_values -1 to 1
426     default_value -1
427 }
428 </programlisting>
429 <para>
430 Neither the &legal-values; nor the &default-value; property will
431 accept <literal>-1</literal> as a valid option, so this will result in
432 syntax errors when the &CDL; script is read in by the component
433 framework. To avoid problems, the option parsing code will recognize
434 the string <literal>--</literal> and will not attempt to interpret any
435 subsequent arguments. Hence this option should be written as:
436 </para>
437 <programlisting width=72>
438 cdl_option CYGNUM_LIBC_TIME_DST_DEFAULT_STATE {
439     &hellip;
440     legal_values  -- -1 to 1
441     default_value -- -1
442 }
443 </programlisting>
444 <para>
445 The property parsing code involves a recursive invocation of the Tcl
446 interpreter that is used to parse the top-level commands. This means
447 that some characters in the body of an option will be treated
448 specially. The <literal>#</literal> character can be used for
449 comments. The backslash character <literal>\</literal>, the
450 dollar character <literal>$</literal>, square brackets
451 <literal>[</literal> and <literal>]</literal>, braces
452 <literal>{</literal> and <literal>}</literal>, and the quote character
453 <literal>"</literal> may all receive special treatment. Most of the
454 time this is not a problem because these characters are not useful for
455 most properties. On occasion having a &Tcl; interpreter around
456 performing the parser can be very powerful. For more details of
457 how the presence of a &Tcl; interpreter can affect &CDL; scripts,
458 see <xref linkend="language.tcl">.
459 </para>
460 <para>
461 Many of the properties can be used in any of &cdl-package;,
462 &cdl-component;, &cdl-option; or &cdl-interface;. Other properties are
463 more specific. The &script; property is only relevant to components.
464 The &define-header;, &hardware;, &include-dir;, &include-files;, and
465 &library; properties apply to a package as a whole, so can only occur
466 in the body of a &cdl-package; command. The &calculated;,
467 &default-value;, &legal-values; and &flavor; properties are not
468 relevant to packages, as will be explained later. The &calculated; and
469 &default-value; properties are also not relevant to interfaces.
470 </para>
471 <para>
472 This section lists the various properties, grouped by purpose. Each
473 property also has a full reference page in <xref linkend="reference">.
474 Properties related to values and expressions are described in more
475 detail in <xref linkend="language.values">. Properties related to
476 header file generation and to the build process are described in
477 <xref linkend="build">.
478 </para>
479
480 <!-- }}} -->
481 <!-- {{{ User-visible           -->
482
483 <sect2 id="language.properties.user">
484 <title>Information-providing Properties</title>
485 <para>
486 Users can only be expected to manipulate configuration options
487 sensibly if they are given sufficient information about these options.
488 There are three properties which serve to explain an option in plain
489 text: the <link linkend="ref.display">&display;</link> property gives
490 a textual alias for an option, which is usually more comprehensible
491 than something like <literal>CYGPKG_LIBC_TIME_ZONES`</literal>; the
492 <link linkend="ref.description">&description;</link> property gives a
493 longer description, typically a paragraph or so; the <link
494 linkend="ref.doc">&doc;</link> property specifies the location of
495 additional on-line documentation related to a configuration option. In
496 the context of a graphical tool the &display; string will be the
497 primary way for users to identify configuration options; the
498 &description; paragraph will be visible whenever the option is
499 selected; the on-line documentation will only be accessed when the
500 user explicitly requests it.
501 </para>
502 <programlisting width=72>
503 cdl_package CYGPKG_UITRON {
504     display       "uITRON compatibility layer"
505     doc           ref/ecos-ref.a.html
506     description   "
507         eCos supports a uITRON Compatibility Layer, providing
508         full Level S (Standard) compliance with Version 3.02 of
509         the uITRON Standard, plus many Level E (Extended) features.
510         uITRON is the premier Japanese embedded RTOS standard."
511     &hellip;
512 }
513 </programlisting>
514 <para>
515 All three properties take a single argument. For &display; and
516 &description; this argument is just a string. For &doc; it should be a
517 pointer to a suitable HTML file, optionally including an anchor within
518 that page. If the <link linkend="package.hierarchy">directory layout
519 conventions</link> are observed then the component framework will look
520 for the HTML file in the package's <filename
521 class="directory">doc</filename> sub-directory, otherwise the &doc;
522 filename will be treated as relative to the package's top-level directory.
523 </para>
524 </sect2>
525
526 <!-- }}} -->
527 <!-- {{{ Hierarchy              -->
528
529 <sect2 id="language.properties.hierarchy">
530 <title>The Configuration Hierarchy</title>
531 <para>
532 There are two properties related to the hierarchical organization of
533 components and options: <link linkend="ref.parent">&parent;</link> and
534 <link linkend="ref.script">&script;</link>.
535 </para>
536 <para>
537 The &parent; property can be used to move a &CDL; entity somewhere
538 else in the hierarchy. The most common use is for packages, to avoid
539 having all the packages appear at the top-level of the configuration
540 hierarchy. For example an architectural HAL package such as
541 <varname>CYGPKG_HAL_SH</varname> is placed below the common HAL
542 package <varname>CYGPKG_HAL</varname> using a &parent; property.
543 </para>
544 <programlisting width=72>
545 cdl_package CYGPKG_HAL_SH {
546     display       "SH architecture"
547     parent        CYGPKG_HAL
548     &hellip;
549 }
550 </programlisting>
551 <para>
552 The &parent; property can also be used in the body of a
553 &cdl-component;, &cdl-option; or &cdl-interface;, but this is less
554 common. However care has to be taken since excessive re-parenting can
555 be confusing. Care also has to be taken when reparenting below some
556 other package that may not actually be loaded in a given
557 configuration, since the resulting behavior is undefined.
558 </para>
559 <para>
560 As a special case, if the parent is the empty string then the
561 &CDL; entity is placed at the root of the hierarchy. This is useful
562 for global preferences, default compiler flags, and other settings
563 that may affect every package.
564 </para>
565 <para>
566 The &script; property can only be used in the body of a
567 &cdl-component; command. The property takes a single filename as
568 argument, and this should be another &CDL; script containing
569 additional options, sub-components and interfaces that should go below
570 the current component in the hierarchy. If the <link
571 linkend="package.hierarchy">directory layout conventions</link> are
572 observed then the component framework will look for the specified file
573 relative to the <filename class="directory">cdl</filename>
574 subdirectory of the package, otherwise the filename will be treated as
575 relative to the package's top-level directory.
576 </para>
577 <programlisting width=72>
578 cdl_component CYGPKG_LIBC_STDIO {
579     display       "Standard input/output functions"
580     flavor        bool
581     requires      CYGPKG_IO
582     requires      CYGPKG_IO_SERIAL_HALDIAG
583     default_value 1
584     description   "
585         This enables support for standard I/O functions from &lt;stdio.h&gt;."
586
587     script        stdio.cdl
588 }
589 </programlisting>
590
591 </sect2>
592
593 <!-- }}} -->
594 <!-- {{{ Value                  -->
595
596 <sect2 id="language.properties.value">
597 <title>Value-related Properties</title>
598 <para>
599 There are seven properties which are related to option values and
600 state: <link linkend="ref.flavor">&flavor;</link>,
601 <link linkend="ref.calculated">&calculated;</link>,
602 <link linkend="ref.default-value">&default-value;</link>,
603 <link linkend="ref.legal-values">&legal-values;</link>,
604 <link linkend="ref.active-if">&active-if;</link>,
605 <link linkend="ref.implements">&implements;</link>, and
606 <link linkend="ref.requires">&requires;</link>. More detailed
607 information can be found in <xref linkend="language.values">.
608 </para>
609 <para>
610 In the context of configurability, the concept of an option's value is
611 somewhat non-trivial. First an option may or may not be loaded: it is
612 possible to build a configuration which has the math library but not
613 the kernel; however the math library's &CDL; scripts still reference
614 kernel options, for example
615 <varname>CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE</varname> has a
616 &requires; constraint on
617 <varname>CYGVAR_KERNEL_THREADS_DATA</varname>. Even if an option is
618 loaded it may or may not be active, depending on what is happening
619 higher up in the hierarchy: if the C library's
620 <varname>CYGPKG_LIBC_STDIO</varname> component is disabled then some
621 other options such as <varname>CYGNUM_LIBC_STDIO_BUFSIZE</varname>
622 become irrelevant. In addition each option has both a boolean
623 enabled/disabled flag and a data part. For many options only the
624 boolean flag is of interest, while for others only the data part is of
625 interest. The &flavor; property can be used to control this:
626 </para>
627 <variablelist>
628 <varlistentry>
629 <term><literal>flavor none</literal></term>
630 <listitem>
631 <para>
632 This flavor indicates that neither the boolean nor the data parts are
633 user-modifiable: the option is always enabled and the data is always
634 set to <literal>1</literal>. The most common use for this is to have a
635 component that just acts as a placeholder in the hierarchy, allowing
636 various options to be grouped below it.
637 </para>
638 </listitem>
639 </varlistentry>
640 <varlistentry>
641 <term><literal>flavor bool</literal></term>
642 <listitem>
643 <para>
644 Only the boolean part of the option is user-modifiable. The data part
645 is fixed at <literal>1</literal>.
646 </para>
647 </listitem>
648 </varlistentry>
649 <varlistentry>
650 <term><literal>flavor data</literal></term>
651 <listitem>
652 <para>
653 Only the data part of the option is user-modifiable. The boolean part
654 is fixed at enabled.
655 </para>
656 </listitem>
657 </varlistentry>
658 <varlistentry>
659 <term><literal>flavor booldata</literal></term>
660 <listitem>
661 <para>
662 Both the boolean and the data part of the option are user-modifiable.
663 </para>
664 </listitem>
665 </varlistentry>
666 </variablelist>
667 <para>
668 For more details of &CDL; flavors and how a flavor affects expression
669 evaluation, and other consequences, see <xref
670 linkend="language.values">. The &flavor; property cannot be used for a
671 package because packages always have the <literal>booldata</literal>
672 flavor. Options and components have the <literal>bool</literal> flavor
673 by default, since most configuration choices are simple yes-or-no
674 choices. Interfaces have the <literal>data</literal> flavor by default.
675 </para>
676 <para>
677 The &calculated; property can be used for options which should not be
678 user-modifiable, but which instead are fixed by the target hardware or
679 determined from the current values of other options. In general
680 &calculated; options should be avoided, since they can be confusing to
681 users who need to figure out whether or not a particular option can
682 actually be changed. There are a number of valid uses for &calculated;
683 options, and quite a few invalid ones as well. The <link
684 linkend="ref.calculated">reference packages</link> should be consulted
685 for further details. The property takes an <link
686 linkend="language.expression">ordinary &CDL; expression</link> as
687 argument, for example:
688 </para>
689 <programlisting width=72>
690 # A constant on some target hardware, perhaps user-modifiable on other
691 # targets.
692 cdl_option CYGNUM_HAL_RTC_PERIOD {
693     display       "Real-time clock period"
694     flavor        data
695     calculated    12500
696 }
697 </programlisting>
698 <para>
699 The &calculated; property cannot be used for packages or interfaces.
700 The value of a package always corresponds to the version of that
701 package which is loaded, and this is under user control. Interfaces
702 are implicitly calculated, based on the number of active and enabled
703 implementors.
704 </para>
705 <para>
706 The &default-value; property is similar to &calculated;, but only
707 specifies a default value which users can modify. Again this property
708 is not relevant to packages or interfaces. A typical example would be:
709 </para>
710 <programlisting width=72>
711 cdl_option CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT {
712     display       "Include GDB multi-threading debug support"
713     requires      CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
714     default_value CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
715     &hellip;
716 }
717 </programlisting>
718 <para>
719 The &legal-values; property imposes a constraint on the possible
720 values of the data part of an option. Hence it is only applicable to
721 options with the <literal>data</literal> or
722 <literal>booldata</literal> flavors. It cannot be used for a package
723 since the only valid value for a package is its version number. The
724 arguments to the &legal-values; property should constitute a <link
725 linkend="language.list-expression">&CDL; list expression</link>.
726 </para>
727 <programlisting width=72>
728 cdl_option CYGNUM_LIBC_TIME_STD_DEFAULT_OFFSET {
729     display       "Default Standard Time offset"
730     flavor        data
731     legal_values  -- -90000 to 90000
732     default_value -- 0
733     &hellip;
734 }
735 </programlisting>
736 <para>
737 The &active-if; property does not relate directly to an option's
738 value, but rather to its active state. Usually this is controlled via
739 the configuration hierarchy: if the
740 <varname>CYGPKG_LIBC_STDIO</varname> component is disabled then all
741 options below it are inactive and do not have any consequences.
742 In some cases the hierarchy does not provide sufficient control, for
743 example an option should only be active if two disjoint sets of
744 conditions are satisfied: the hierarchy could be used for one of these
745 conditions, and an additional &active-if; property could be used for
746 the other one. The arguments to &active-if; should constitute a
747 <link linkend="language.goal-expression">&CDL; goal expression</link>.
748 </para>
749 <programlisting width=72>
750 # Do not provide extra semaphore debugging if there are no semaphores
751 cdl_option CYGDBG_KERNEL_INSTRUMENT_BINSEM {
752     active_if CYGPKG_KERNEL_SYNCH
753     &hellip;
754 }
755 </programlisting>
756 <para>
757 The &implements; property is related to the concept of <link
758 linkend="language.interface">&CDL; interfaces</link>. If an option is
759 active and enabled and it implements a particular interface then it
760 contributes <literal>1</literal> to that interface's value.
761 </para>
762 <programlisting width=72>
763 cdl_package CYGPKG_NET_EDB7XXX_ETH_DRIVERS {
764     display       "Cirrus Logic ethernet driver"
765     implements    CYGHWR_NET_DRIVERS
766     implements    CYGHWR_NET_DRIVER_ETH0
767     &hellip;
768 }
769 </programlisting>
770 <para>
771 The &requires; property is used to impose constraints on the user's
772 choices. For example it is unreasonable to expect the C library to
773 provide thread-safe implementations of certain functions if the
774 underlying kernel support has been disabled, or even if the kernel is
775 not being used at all.
776 </para>
777 <programlisting width=72>
778 cdl_option CYGSEM_LIBC_PER_THREAD_ERRNO {
779     display       "Per-thread errno"
780     doc           ref/ecos-ref.15.html
781     requires      CYGVAR_KERNEL_THREADS_DATA
782     default_value 1
783     &hellip;
784 }
785 </programlisting>
786 <para>
787 The arguments to the &requires; property should be a <link
788 linkend="language.goal-expression">&CDL; goal expression</link>.
789 </para>
790
791 </sect2>
792
793 <!-- }}} -->
794 <!-- {{{ Header file generation -->
795
796 <sect2 id="language.properties.define">
797 <title>Generating the Configuration Header Files</title>
798 <para>
799 When creating or updating a build tree the component framework will
800 also generate configuration header files, one per package. By default
801 it will generate a <literal>#define</literal> for each option,
802 component or interface that is active and enabled. For options with
803 the <literal>data</literal> or <literal>booldata</literal> flavors the
804 <literal>#define</literal> will use the option's data part, otherwise
805 it will use the constant <literal>1</literal>. Typical output would
806 include:
807 </para>
808 <programlisting width=72>
809 #define CYGFUN_LIBC_TIME_POSIX 1
810 #define CYGNUM_LIBC_TIME_DST_DEFAULT_STATE -1
811 </programlisting>
812 <para>
813 There are six properties which can be used to control the header file
814 generation process:
815 <link linkend="ref.define-header">&define-header;</link>,
816 <link linkend="ref.no-define">&no-define;</link>,
817 <link linkend="ref.define-format">&define-format;</link>,
818 <link linkend="ref.define">&define;</link>,
819 <link linkend="ref.if-define">&if-define;</link>, and
820 <link linkend="ref.define-proc">&define-proc;</link>.
821 </para>
822 <para>
823 By default the component framework will generate a configuration
824 header file for each package based on the package's name: everything
825 up to and including the first underscore is discarded, the rest of the
826 name is lower-cased, and a <literal>.h</literal> suffix is appended.
827 For example the configuration header file for the kernel package
828 <varname>CYGPKG_KERNEL</varname> is <filename
829 class="headerfile">pkgconf/kernel.h</filename>. The &define-header;
830 property can be used to specify an alternative filename. This applies
831 to all the components and options within a package, so it can only be
832 used in the body of a &cdl-package; command. For example the following
833 specifies that the configuration header file for the SPARClite HAL
834 package is <filename
835 class="headerfile">pkgconf/hal_sparclite.h</filename>.
836 </para>
837 <programlisting width=72>
838 cdl_package CYGPKG_HAL_SPARCLITE {
839     display "SPARClite architecture"
840     parent        CYGPKG_HAL
841     hardware
842     define_header hal_sparclite.h
843     &hellip;
844 }
845 </programlisting>
846 <note>
847 <para>
848 At present the main use for the &define-header; property is related 
849 to hardware packages, see the <link linkend="ref.hardware">reference
850 pages</link> for more details.
851 </para>
852 </note>
853 <para>
854 The &no-define; property is used to suppress the generation of the
855 default <literal>#define</literal>. This can be useful if an option's
856 consequences are all related to the build process or to constraints,
857 and the option is never actually checked in any source code. It can
858 also be useful in conjunction with the &define;, &if-define; or
859 &define-proc; properties. The &no-define; property does not take any
860 arguments. 
861 </para>
862 <programlisting width=72>
863 cdl_component CYG_HAL_STARTUP {
864     display       "Startup type"
865     flavor        data
866     legal_values  { "RAM" "ROM" }
867     default_value {"RAM"}
868     no_define
869     define -file system.h CYG_HAL_STARTUP
870     &hellip;
871 }
872 </programlisting>
873 <para>
874 This example also illustrates the &define; property, which can be used
875 to generate a <literal>#define</literal> in addition to the default
876 one. It takes a single argument, the name of the symbol to be defined.
877 It also takes options to control the configuration header file in
878 which the symbol should be defined and the format to be used.
879 </para>
880 <para>
881 The &define-format; property can be used to control how the value part
882 of the default <literal>#define</literal> gets formatted. For example
883 a format string of  <literal>"0x%04x"</literal> could be used to
884 generate a four-digit hexadecimal number. 
885 </para>
886 <para>
887 The &if-define; property is intended for use primarily to control
888 assertions, tracing, and similar functionality. It supports a specific
889 implementation model for these, allowing control at the grain of
890 packages or even individual source files. The <link
891 linkend="ref.if-define">reference pages</link> provide additional
892 information.
893 </para>
894 <para>
895 The &define-proc; property provides an escape mechanism for those
896 cases where something special has to happen at configuration header
897 file generation time. It takes a single argument, a fragment of &Tcl;
898 code, which gets executed when the header file is generated. This code
899 can output arbitrary data to the header file, or perform any other
900 actions that might be appropriate.
901 </para>
902
903 </sect2>
904
905 <!-- }}} -->
906 <!-- {{{ Builds                 -->
907
908 <sect2 id="language.properties.build">
909 <title>Controlling what gets Built</title>
910 <para>
911 There are six properties which affect the build process:
912 <link linkend="ref.compile">&compile;</link>,
913 <link linkend="ref.make">&make;</link>,
914 <link linkend="ref.make-object">&make-object;</link>,
915 <link linkend="ref.library">&library;</link>,
916 <link linkend="ref.include-dir">&include-dir;</link>, and
917 <link linkend="ref.include-files">&include-files;</link>.
918 The last three apply to a package as a whole, and can only occur in
919 the body of a &cdl-package; command.
920 </para>
921 <para>
922 Most of the source files that go into a package should simply be
923 compiled with the appropriate compiler, selected by the target
924 architecture, and with the appropriate flags, with an additional set
925 defined by the target hardware and possible modifications on a
926 per-package basis. The resulting object files will go into the library
927 <filename>libtarget.a</filename>, which can then be linked against
928 application code. The &compile; property is used to list these source
929 files: 
930 </para>
931 <programlisting width=72>
932 cdl_package CYGPKG_ERROR {
933     display       "Common error code support"
934     compile       strerror.cxx
935     include_dir   cyg/error
936     &hellip;
937 }
938 </programlisting>
939 <para>
940 The arguments to the &compile; property should be one or more source
941 files. Typically most of the sources will be needed for the package as
942 a whole, and hence they will be listed in one or more &compile;
943 properties in the body of the &cdl-package;. Some sources may be
944 specific to particular configuration options, in other words there is
945 no point in compiling them unless that option is enabled, in which
946 case the sources should be listed in a &compile; property in the
947 corresponding &cdl-option;, &cdl-component; or &cdl-interface; body.
948 </para>
949 <para>
950 Some packages may have more complicated build requirements, for
951 example they may involve a special target such as a linker script
952 which should not end up in the usual library, or they may involve
953 special build steps for generating an object file. The &make; and
954 &make-object; properties provide support for such requirements, for
955 example:
956 </para>
957 <programlisting>
958 cdl_package CYGPKG_HAL_MN10300_AM33 {
959     display       "MN10300 AM33 variant"
960     &hellip;
961     make {
962         &lt;PREFIX&gt;/lib/target.ld: &lt;PACKAGE&gt;/src/mn10300_am33.ld
963         $(CC) -E -P -Wp,-MD,target.tmp -DEXTRAS=1 -xc $(INCLUDE_PATH) \
964             $(CFLAGS) -o $@ $&lt;
965         @echo $@ ": \\" &gt; $(notdir $@).deps
966         @tail +2 target.tmp &gt;&gt; $(notdir $@).deps
967         @echo &gt;&gt; $(notdir $@).deps
968         @rm target.tmp
969     }
970 }
971 </programlisting>
972 <para>
973 For full details of custom build steps and the build process
974 generally, see <xref linkend="build">.
975 </para>
976 <para>
977 By default all object files go into the library
978 <filename>libtarget.a</filename>. It is possible to override this at
979 the package level using the &library; property, but this should be
980 avoided since it complicates application development: instead of just
981 linking with a single library for all &eCos;-related packages, it
982 suddenly becomes necessary to link with several libraries.
983 </para>
984 <para>
985 The &include-dir; and &include-files; properties relate to a package's
986 exported header files. By default a package's header files will be
987 exported to the <filename class="directory">install/include</filename>
988 directory. This is the desired behavior for some packages like the C
989 library, since headers like <filename
990 class="headerfile">stdio.h</filename> should exist at that level.
991 However if all header files were to end up in that directory then
992 there would be a significant risk of a name clash. Instead it is
993 better for packages to specify some sub-directory for their exported
994 header files, for example:
995 </para>
996 <programlisting width=72>
997 cdl_package CYGPKG_INFRA {
998     display       "Infrastructure"
999     include_dir   cyg/infra
1000     &hellip;
1001 }
1002 </programlisting>
1003 <para>
1004 The various header files exported by the infrastructure, for example
1005 <filename class="headerfile">cyg_ass.h</filename> and <filename
1006 class="headerfile">cyg_trac.h</filename> will now end up in the
1007 <filename class="directory">install/include/cyg/infra</filename>
1008 sub-directory, where a name clash is very unlikely.
1009 </para>
1010 <para>
1011 For packages which follow the <link
1012 linkend="package.hierarchy">directory layout conventions</link> the
1013 component framework will assume that the package's
1014 <filename class="directory">include</filename> sub-directory contains
1015 all exported header files. If this is not the case, for example
1016 because the package is sufficiently simple that the layout convention
1017 is inappropriate, then the exported header files can be listed
1018 explicitly in an &include-files; property.
1019 </para>
1020
1021 </sect2>
1022
1023 <!-- }}} -->
1024 <!-- {{{ Miscellaneous          -->
1025
1026 <sect2 id="language.properties.miscellaneous">
1027 <title>Miscellaneous Properties</title>
1028 <para>
1029 The <link linkend="ref.hardware">&hardware;</link> property is
1030 only relevant to packages. Some packages such as device drivers and
1031 HAL packages are hardware-specific, and generally it makes no sense to
1032 add such packages to a configuration unless the corresponding hardware
1033 is present on your target system. Typically hardware package selection
1034 happens automatically when you select your target. The &hardware;
1035 property should be used to identify a hardware-specific package, and
1036 does not take any arguments.
1037 </para>
1038 <programlisting width=72>
1039 cdl_package CYGPKG_HAL_MIPS {
1040     display "MIPS architecture"
1041     parent        CYGPKG_HAL
1042     hardware
1043     include_dir   cyg/hal
1044     define_header hal_mips.h
1045     &hellip;
1046 }
1047 </programlisting>
1048 <para>
1049 At present the &hardware; property is largely ignored by the component
1050 framework. This may change in future releases.
1051 </para>
1052 </sect2>
1053
1054 <!-- }}} -->
1055
1056 </sect1>
1057
1058 <!-- }}} -->
1059 <!-- {{{ Naming conventions     -->
1060
1061 <sect1 id="language.naming">
1062 <title>Option Naming Convention</title>
1063 <para>
1064 All the options in a given configuration live in the same namespace.
1065 Furthermore it is not possible for two separate options to have the
1066 same name, because this would make any references to those options in
1067 &CDL; expressions ambiguous. A naming convention exists to avoid
1068 problems. It is recommended that component writers observe some or all
1069 of this convention to reduce the probability of name clashes with
1070 other packages.
1071 </para>
1072 <para>
1073 There is an important restriction on option names. Typically the
1074 component framework will output a <literal>#define</literal> for every
1075 active and enabled option, using the name as the symbol being defined.
1076 This requires that all names are valid C preprocessor symbols, a
1077 limitation that is enforced even for options which have the
1078 &no-define; property. Preprocessor symbols can be any sequence of
1079 lower case letters <literal>a</literal>-<literal>z</literal>, upper
1080 case letters, <literal>A</literal>-<literal>Z</literal>, the
1081 underscore character <literal>_</literal>, and the digits
1082 <literal>0</literal>-<literal>9</literal>. The first character must be
1083 a non-digit. Using an underscore as the first character is
1084 discouraged, because that may clash with reserved language
1085 identifiers. In addition there is a convention that preprocessor
1086 symbols only use upper case letters, and some component writers may
1087 wish to follow this convention.
1088 </para>
1089 <para>
1090 A typical option name could be something like
1091 <varname>CYGSEM_KERNEL_SCHED_BITMAP</varname>. This name consists of
1092 several different parts:
1093 </para>
1094 <orderedlist>
1095 <listitem>
1096 <para>
1097 The first few characters, in this case the three letters
1098 <literal>CYG</literal>, are used to identify the organization that
1099 produced the package. For historical reasons packages produced by Red
1100 Hat tend to use the prefix <literal>CYG</literal> rather than
1101 <literal>RHAT</literal>. Component writers should use their own
1102 prefix: even when cutting and pasting from an existing &CDL; script
1103 the prefix should be changed to something appropriate to their
1104 organization. 
1105 </para>
1106 <para>
1107 It can be argued that a short prefix, often limited to upper case
1108 letters, is not sufficiently long to eliminate the possibility of
1109 name clashes. A longer prefix could be used, for example one based on
1110 internet domain names. However the C preprocessor has no concept of
1111 namespaces or <literal>import</literal> directives, so it would always
1112 be necessary to use the full option name in component source code
1113 which gets tedious - option names tend to be long enough as it is.
1114 There is a small increased risk of name clashes, but this risk is felt
1115 to be acceptable.
1116 </para>
1117 </listitem>
1118 <listitem>
1119 <para>
1120 The next three characters indicate the nature of the option, for
1121 example whether it affects the interface or just the implementation. A
1122 list of common tags is given below.
1123 </para>
1124 </listitem>
1125 <listitem>
1126 <para>
1127 The <literal>KERNEL_SCHED</literal> part indicates the location of the
1128 option within the overall hierarchy. In this case the option is part of
1129 the scheduling component of the kernel package. Having the hierarchy
1130 details as part of the option name can help in understanding
1131 configurable code and further reduces the probability of a name clash.
1132 </para>
1133 </listitem>
1134 <listitem>
1135 <para>
1136 The final part, <literal>BITMAP</literal>, identifies the option
1137 itself. 
1138 </para>
1139 </listitem>
1140 </orderedlist>
1141 <para>
1142 The three-character tag is intended to provide some additional
1143 information about the nature of the option. There are a number of
1144 pre-defined tags. However for many options there is a choice:
1145 options related to the platform should normally use
1146 <literal>HWR</literal>, but numerical options should normally use
1147 <literal>NUM</literal>; a platform-related numerical option such as
1148 the size of an interrupt stack could therefore use either tag.
1149 There are no absolute rules, and it is left to component writers to
1150 interpret the following guidelines:
1151 </para>
1152 <variablelist>
1153 <varlistentry>
1154 <term><literal>xxxARC_</literal></term>
1155 <listitem><para>
1156 The <literal>ARC</literal> tag is intended for options related
1157 to the processor architecture. Typically such options will only occur
1158 in architectural or variant HAL packages.
1159 </para></listitem>
1160 </varlistentry>
1161 <varlistentry>
1162 <term><literal>xxxHWR_</literal></term>
1163 <listitem><para>
1164 The <literal>HWR</literal> tag is intended for options related to
1165 the specific target board. Typically such options will only occur in
1166 platform HAL packages.
1167 </para></listitem>
1168 </varlistentry>
1169 <varlistentry>
1170 <term><literal>xxxPKG_</literal></term>
1171 <listitem><para>
1172 This tag is intended for packages or components, in other words
1173 options which extend the configuration hierarchy. Arguably a
1174 <literal>COM</literal> tag would be more appropriate for
1175 components, but this could be confusing because of the considerable
1176 number of computing terms that begin with com.
1177 </para></listitem>
1178 </varlistentry>
1179 <varlistentry>
1180 <term><literal>xxxGLO_</literal></term>
1181 <listitem><para>
1182 This is intended for global configuration options, especially
1183 preferences.
1184 </para></listitem>
1185 </varlistentry>
1186 <varlistentry>
1187 <term><literal>xxxDBG_</literal></term>
1188 <listitem><para>
1189 The <literal>DBG</literal> tag indicates that the option is in
1190 some way related to debugging, for example it may enable assertions in
1191 some part of the system.
1192 </para></listitem>
1193 </varlistentry>
1194 <varlistentry>
1195 <term><literal>xxxTST_</literal></term>
1196 <listitem><para>
1197 This tag is for testing-related options. Typically these do not
1198 affect actual application code, instead they control the interaction
1199 between target-side test cases and a host-side testing infrastructure.
1200 </para></listitem>
1201 </varlistentry>
1202 <varlistentry>
1203 <term><literal>xxxFUN_</literal></term>
1204 <listitem><para>
1205 This is for configuration options which affect the interface of a
1206 package. There are a number of related tag which are also
1207 interface-related. <literal>xxxFUN_</literal> is intended primarily
1208 for options that control whether or not one or more functions are
1209 provided by the package, but can also be used if none of the other
1210 interface-related tags is applicable.
1211 </para></listitem>
1212 </varlistentry>
1213 <varlistentry>
1214 <term><literal>xxxVAR_</literal></term>
1215 <listitem><para>
1216 This is analogous to <literal>FUN</literal> but controls the presence
1217 or absence of one or more variables or objects.
1218 </para></listitem>
1219 </varlistentry>
1220 <varlistentry>
1221 <term><literal>xxxCLS_</literal></term>
1222 <listitem><para>
1223 The <literal>CLS</literal> tag is intended only for packages that
1224 provide an object-oriented interface, and controls the presence or
1225 absence of an entire class.
1226 </para></listitem>
1227 </varlistentry>
1228 <varlistentry>
1229 <term><literal>xxxMFN_</literal></term>
1230 <listitem><para>
1231 This is also for object-orientated interfaces, and indicates the
1232 presence or absence of a member function rather than an entire class.
1233 </para></listitem>
1234 </varlistentry>
1235 <varlistentry>
1236 <term><literal>xxxSEM_</literal></term>
1237 <listitem><para>
1238 A <literal>SEM</literal> option does not affect the interface (or if
1239 does affect the interface, this is incidental). Instead it is used for
1240 options which have a fundamental effect on the semantic behavior of a
1241 package. For example the choice of kernel schedulers is semantic in
1242 nature: it does not affect the interface, in particular the function
1243 <function>cyg_thread_create</function> exists irrespective of which
1244 scheduler has been selected. However it does have a major impact on
1245 the system's behavior.
1246 </para></listitem>
1247 </varlistentry>
1248 <varlistentry>
1249 <term><literal>xxxIMP_</literal></term>
1250 <listitem><para>
1251 <literal>IMP</literal> is for implementation options. These do not
1252 affect either the interface or the semantic behavior (with the
1253 possible exception of timing-related changes). A typical
1254 implementation option controls whether or not a particular function or
1255 set of functions should get inlined.
1256 </para></listitem>
1257 </varlistentry>
1258 <varlistentry>
1259 <term><literal>xxxNUM_</literal></term>
1260 <listitem><para>
1261 This tag is for numerical options, for example the number of
1262 scheduling priority levels.
1263 </para></listitem>
1264 </varlistentry>
1265 <varlistentry>
1266 <term><literal>xxxDAT_</literal></term>
1267 <listitem><para>
1268 This is for data items that are not numerical in nature, for example a
1269 device name.
1270 </para></listitem>
1271 </varlistentry>
1272 <varlistentry>
1273 <term><literal>xxxBLD_</literal></term>
1274 <listitem><para>
1275 The <literal>BLD</literal> tag indicates an option that affects
1276 the build process, for example compiler flag settings.
1277 </para></listitem>
1278 </varlistentry>
1279 <varlistentry>
1280 <term><literal>xxxINT_</literal></term>
1281 <listitem><para>
1282 This should normally be used for &CDL; interfaces, which is a language
1283 construct that is largely independent from the interface exported by a
1284 package via its header files. For more details of &CDL; interfaces
1285 see <xref linkend="language.interface">.
1286 </para></listitem>
1287 </varlistentry>
1288 <varlistentry>
1289 <term><literal>xxxPRI_</literal></term>
1290 <listitem><para>
1291 This tag is not normally used for configuration options. Instead
1292 it is used by &CDL; scripts to pass additional private information to
1293 the source code via the configuration header files, typically inside a
1294 &define-proc; property.
1295 </para></listitem>
1296 </varlistentry>
1297 <varlistentry>
1298 <term><literal>xxxSRC_</literal></term>
1299 <listitem><para>
1300 This tag is not normally used for configuration options. Instead
1301 it can be used by package source code to interact with such options,
1302 especially in the context of the &if-define; property.
1303 </para></listitem>
1304 </varlistentry>
1305 </variablelist>
1306
1307 <para>
1308 There is one special case of a potential name clash that is worth
1309 mentioning here. When the component framework generates a
1310 configuration header file for a given package, by default it will use
1311 a name derived from the package name (the &define-header; property can
1312 be used to override this). The file name is constructed from the
1313 package name by removing everything up to and including the first
1314 underscore, converting the remainder of the name to lower case, and
1315 appending a <literal>.h</literal> suffix. For example the kernel
1316 package <varname>CYGPKG_KERNEL</varname> will involve a header file
1317 <filename class="headerfile">pkgconf/kernel.h</filename>. If a
1318 configuration contained some other package
1319 <varname>XYZPKG_KERNEL</varname> then this would attempt to use the
1320 same configuration header file, with unfortunate effects. Case
1321 sensitivity could introduce problems as well, so a package
1322 <varname>xyzpkg_kernel</varname> would involve the same problem. Even
1323 if the header file names preserved the case of the package name, not
1324 all file systems are case sensitive. There is no simple solution to
1325 this problem. Changing the names of the generated configuration header
1326 files would involve a major incompatible change to the interface, to
1327 solve a problem which is essentially hypothetical in nature.
1328 </para>
1329
1330 </sect1>
1331
1332 <!-- }}} -->
1333 <!-- {{{ Introduction to Tcl    -->
1334
1335 <sect1 id="language.tcl">
1336 <title>An Introduction to Tcl</title>
1337
1338 <para>
1339 All &CDL; scripts are implemented as &Tcl; scripts, and are read in by
1340 running the data through a standard &Tcl; interpreter, extended with a
1341 small number of additional commands such as
1342 <literal>cdl_option</literal> and <literal>cdl_component</literal>.
1343 Often it is not necessary to know the full details of &Tcl; syntax.
1344 Instead it is possible to copy an existing script, perform some copy
1345 and paste operations, and make appropriate changes to names and to
1346 various properties. However there are also cases where an
1347 understanding of &Tcl; syntax is very desirable, for example:
1348 </para>
1349
1350 <programlisting width=72>
1351 cdl_option CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS {
1352     display       "Externs for initialization"
1353     flavor        data
1354     default_value {"static char fpool1[ 2000 ], \\\n\
1355                                 fpool2[ 2000 ], \\\n\
1356                                 fpool3[ 2000 ];"}
1357     &hellip;
1358 }
1359 </programlisting>
1360
1361 <para>
1362 This causes the &cdl-option; command to be executed, which in turn
1363 evaluates its body in a recursive invocation of the &Tcl; interpreter.
1364 When the &default-value; property is encountered the braces around the
1365 value part are processed by the interpreter, stopping it from doing
1366 further processing of the braced contents (except for backslash
1367 processing at the end of a line, that is special). In particular it
1368 prevents command substitution for
1369 <literal>[&nbsp;2000&nbsp;]</literal>. A single argument will be
1370 passed to the &default-value; command which expects a &CDL;
1371 expression, so the expression parsing code is passed the following:
1372 </para>
1373
1374 <screen width=72>
1375 "static char fpool1[ 2000 ], \\\n fpool2[ 2000 ], \\\n fpool3[ 2000 ];"
1376 </screen>
1377
1378 <para>
1379 The &CDL; expression parsing code will treat this as a simple string
1380 constant, as opposed to a more complicated expression involving other
1381 options and various operators. The string parsing code will perform
1382 the usual backslash substitutions so the actual default value will be:
1383 </para>
1384 <screen width=72>
1385 static char fpool1[ 2000 ], \
1386  fpool2[ 2000 ], \
1387  fpool3[ 2000 ];
1388 </screen>
1389
1390 <para>
1391 If the user does not modify the option's value then the following
1392 will be generated in the appropriate configuration header file:
1393 </para>
1394 <programlisting width=72>
1395 #define CYGDAT_UITRON_MEMPOOLFIXED_EXTERNS static char fpool1[ 2000 ], \
1396  fpool2[ 2000 ], \
1397  fpool3[ 2000 ];
1398 </programlisting>
1399
1400 <para>
1401 Getting this desired result usually requires an understanding of both
1402 &Tcl; syntax and &CDL; expression syntax. Sometimes it is possible to
1403 substitute a certain amount of trial and error instead, but this may
1404 prove frustrating. It is also worth pointing out that many &CDL;
1405 scripts do not involve this level of complexity. On the other hand,
1406 some of the more advanced features of the &CDL; language involve
1407 fragments of &Tcl; code, for example the &define-proc; property. To
1408 use these component writers will need to know about the full &Tcl;
1409 language as well as the syntax.
1410 </para>
1411 <para>
1412 Although the current example may seem to suggest that &Tcl; is rather
1413 complicated, it is actually a very simple yet powerful scripting
1414 language: the syntax is defined by just eleven rules. On occasion this
1415 simplicity means that Tcl's behavior is subtly different from other
1416 languages, which can confuse newcomers.
1417 </para>
1418 <para>
1419 When the Tcl interpreter is passed some data such as
1420 <literal>puts&nbsp;Hello</literal>, it splits this data into a command
1421 and its arguments. The command will be terminated by a newline or by a
1422 semicolon, unless one of the quoting mechanisms is used. The command
1423 and each of its arguments are separated by white space. So in the
1424 following example:
1425 </para>
1426 <screen width=72>
1427 puts Hello
1428 set x 42
1429 </screen>
1430 <para>
1431 This will result in two separate commands being executed. The first
1432 command is <literal>puts</literal> and is passed a single argument,
1433 <literal>Hello</literal>. The second command is <literal>set</literal>
1434 and is passed two arguments, <literal>x</literal> and
1435 <literal>42</literal>. The intervening newline character serves to
1436 terminate the first command, and a semi-colon separator could be used
1437 instead: 
1438 </para>
1439 <screen width=72>
1440 puts Hello;set x 42
1441 </screen>
1442 <para>
1443 Any white space surrounding the semicolon is just ignored because it
1444 does not serve to separate arguments.
1445 </para>
1446 <para>
1447 Now consider the following:
1448 </para>
1449 <screen width=72>
1450 set x Hello world
1451 </screen>
1452 <para>
1453 This is not valid &Tcl;. It is an attempt to invoke the
1454 <literal>set</literal> command with three arguments:
1455 <literal>x</literal>, <literal>Hello</literal>, and
1456 <literal>world</literal>. The <literal>set</literal> only takes two
1457 arguments, a variable name and a value, so it is necessary to combine
1458 the data into a single argument by quoting:
1459 </para>
1460 <screen width=72>
1461 set x "Hello world"
1462 </screen>
1463 <para>
1464 When the &Tcl; interpreter encounters the first quote character it
1465 treats all subsequent data up to but not including the closing quote
1466 as part of the current argument. The quote marks are removed by the
1467 interpreter, so the second argument passed to the
1468 <literal>set</literal> command is just <literal>Hello world</literal>
1469 without the quote characters. This can be significant in the context
1470 of &CDL; scripts. For example:
1471 </para>
1472 <programlisting width=72>
1473 cdl_option CYG_HAL_STARTUP {
1474     &hellip;
1475     default_value "RAM"
1476 }
1477 </programlisting>
1478 <para>
1479 The &Tcl; interpreter strips off the quote marks so the &CDL;
1480 expression parsing code sees <literal>RAM</literal> instead of
1481 <literal>"RAM"</literal>. It will treat this as a reference to
1482 some unknown option <varname>RAM</varname> rather than as a string
1483 constant, and the expression evaluation code will use a value of
1484 <literal>0</literal> when it encounters an option that is not
1485 currently loaded. Therefore the option
1486 <varname>CYG_HAL_STARTUP</varname> ends up with a default value of
1487 <literal>0</literal>. Either braces or backslashes should be used to
1488 avoid this, for example
1489 <literal>default_value&nbsp;{&nbsp;"RAM"&nbsp;}</literal>. 
1490 </para>
1491 <note>
1492 <para>
1493 There are long-term plans to implement some sort of &CDL; validation
1494 utility <application class="software">cdllint</application> which
1495 could catch common errors like this one.
1496 </para>
1497 </note>
1498 <para>
1499 A quoted argument continues until the closing quote character is
1500 encountered, which means that it can span multiple lines. Newline or
1501 semicolon characters do not terminate the current command in such
1502 cases. &description; properties usually make use of this:
1503 </para>
1504 <programlisting width=72>
1505 cdl_package CYGPKG_ERROR {
1506     description   "
1507         This package contains the common list of error and
1508         status codes. It is held centrally to allow
1509         packages to interchange error codes and status
1510         codes in a common way, rather than each package
1511         having its own conventions for error/status
1512         reporting. The error codes are modelled on the
1513         POSIX style naming e.g. EINVAL etc. This package
1514         also provides the standard strerror() function to
1515         convert error codes to textual representation."
1516     &hellip;
1517 }
1518 </programlisting>
1519 <para>
1520 The &Tcl; interpreter supports much the same forms of backslash
1521 substitution as other common programming languages. Some backslash
1522 sequences such as <literal>\n</literal> will be replaced by the
1523 appropriate character. The sequence <literal>\\</literal> will be
1524 replaced by a single backslash. A backslash at the very end of a line
1525 will cause that backslash, the newline character, and any white space
1526 at the start of the next line to be replaced by a single space. Hence
1527 the following two Tcl commands are equivalent:
1528 </para>
1529 <programlisting width=72>
1530 puts  "Hello\nworld\n"
1531 puts \
1532 "Hello
1533 world
1534 "
1535 </programlisting>
1536 <para>
1537 If a &description; string needs to contain quote marks or other
1538 special characters then backslash escapes can be used. In addition to
1539 quote and backslash characters, the Tcl interpreter treats square
1540 brackets, the <literal>$</literal> character, and braces specially.
1541 Square brackets are used for command substitution, for example:
1542 </para>
1543 <screen width=72>
1544 puts "The answer is [expr 6 * 9]"
1545 </screen>
1546 <para>
1547 When the Tcl interpreter encounters the square brackets it will treat
1548 the contents as another command that should be executed first, and the
1549 result of executing that is used when continuing to process the
1550 script. In this case the Tcl interpreter will execute the command
1551 <literal>expr 6 * 9</literal>, yielding a result of 42
1552 <footnote>
1553 <para>
1554 It is possible that some versions of the Tcl interpreter will instead
1555 produce a result of 54 when asked to multiply six by nine. Appropriate
1556 <ulink url="http://www.douglasadams.com/creations/hhgg.html">reference
1557 documentation</ulink> should be consulted for more information on why
1558 42 is in fact the correct answer.
1559 </para>
1560 </footnote>
1561 and then the
1562 Tcl interpreter will execute <literal>puts "The answer is 42"</literal>.
1563 It should be noted that the interpreter performs only one level
1564 of substitution: if the result of performing command substitution
1565 performs further special characters such as square brackets then these
1566 will not be treated specially.
1567 </para>
1568 <para>
1569 Command substitution will not prove useful for many &CDL; scripts,
1570 except for e.g. a &define-proc; property which involves a fragment of
1571 &Tcl; code. Potentially there are some interesting uses, for example
1572 to internationalize &display; strings. However care does have to be
1573 taken to avoid unexpected command substitution, for example if an
1574 option description involves square brackets then typically these would
1575 require backslash-escapes.
1576 </para>
1577 <para>
1578 The <literal>$</literal> character is used in Tcl scripts to perform
1579 variable substitution:
1580 </para>
1581 <programlisting width=72>
1582 set x [expr 6 * 9]
1583 puts "The answer is $x"
1584 </programlisting>
1585 <para>
1586 Variable substitution, like command substitution, is unlikely to
1587 prove useful for many &CDL; scripts except in the context of
1588 &Tcl; fragments. If it is necessary to have a <literal>$</literal>
1589 character then a backslash escape may have to be used.
1590 </para>
1591 <para>
1592 Braces are used to collect a sequence of characters into a single
1593 argument, just like quotes. The difference is that variable, command
1594 and backslash substitution do not occur inside braces (with the
1595 sole exception of backslash substitution at the end of a line).
1596 Therefore given a line in a &CDL; script such as:
1597 </para>
1598 <programlisting width=72>
1599 default_value {"RAM"}
1600 </programlisting>
1601 <para>
1602 The braces are stripped off by the &Tcl; interpreter, leaving
1603 <literal>"RAM"</literal> which will be handled as a string constant by
1604 the expression parsing code. The same effect could be achieved using
1605 one of the following:
1606 </para>
1607 <programlisting width=72>
1608 default_value \"RAM\"
1609 default_value "\"RAM\""
1610 </programlisting>
1611 <para>
1612 Generally the use of braces is less confusing. At this stage it is
1613 worth noting that the basic format of &CDL; data makes use of
1614 braces:
1615 </para>
1616 <programlisting width=72>
1617 cdl_option &lt;name&gt; {
1618      &hellip;
1619 };
1620 </programlisting>
1621 <para>
1622 The &cdl-option; command is passed two arguments, a name and a body,
1623 where the body consists of everything inside the braces but not the
1624 braces themselves. This body can then be executed in a recursive
1625 invocation of the &Tcl; interpreter. If a &CDL; script contains
1626 mismatched braces then the interpreter is likely to get rather
1627 confused and the resulting diagnostics may be difficult to understand. 
1628 </para>
1629 <para>
1630 Comments in Tcl scripts are introduced by a hash character
1631 <literal>#</literal>. However, a hash character only introduces a
1632 comment if it occurs where a command is expected. Consider the
1633 following:
1634 </para>
1635 <programlisting width=72>
1636 # This is a comment
1637 puts "Hello" # world
1638 </programlisting>
1639 <para>
1640 The first line is a valid comment, since the hash character occurs
1641 right at the start where a command name is expected. The second line
1642 does not contain a comment. Instead it is an attempt to invoke the
1643 <literal>puts</literal> command with three arguments:
1644 <literal>Hello</literal>, <literal>#</literal> and
1645 <literal>world</literal>. These are not valid arguments for the
1646 <literal>puts</literal> command so an error will be raised.
1647 If the second line was rewritten as:
1648 </para>
1649 <programlisting width=72>
1650 puts "Hello"; # world
1651 </programlisting>
1652 <para>
1653 then this is a valid Tcl script. The semicolon identifies the end of
1654 the current command, so the hash character occurs at a point where the
1655 next command would start and hence it is interpreted as the start of a
1656 comment.
1657 </para>
1658 <para>
1659 This handling of comments can lead to subtle behavior. Consider the
1660 following:
1661 </para>
1662 <programlisting width=72>
1663 cdl_option WHATEVER {
1664 # This is a comment }
1665     default_value 0
1666     &hellip;
1667 }
1668 </programlisting>
1669 <para>
1670 Consider the way the Tcl interpreter processes this. The command name
1671 and the first argument do not pose any special difficulties. The
1672 opening brace is interpreted as the start of the next argument, which
1673 continues until a closing brace is encountered. In this case the
1674 closing brace occurs on the second line, so the second argument passed
1675 to <literal>cdl_option</literal> is
1676 <literal>\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;This&nbsp;is&nbsp;a&nbsp;comment
1677 </literal>. This second argument is processed in a recursive
1678 invocation of the Tcl interpreter and does not contain any commands,
1679 just a comment. Top-level script processing then resumes, and the next
1680 command that is encountered is <literal>default_value</literal>. Since
1681 the parser is not currently processing a configuration option this is
1682 an error. Later on the Tcl interpreter would encounter a closing brace
1683 by itself, which is also an error.
1684 </para>
1685 <para>
1686 For component writers who need more information about &Tcl;,
1687 especially about the language rather than the syntax, various
1688 resources are available. A reasonable starting point is the
1689 <ulink url="http://www.tcl.tk/scripting/">Scriptics developer
1690 web site</ulink>.
1691 </para>
1692 </sect1>
1693
1694 <!-- }}} -->
1695 <!-- {{{ Values and Expressions -->
1696
1697 <sect1 id="language.values">
1698 <title>Values and Expressions</title>
1699
1700 <!-- {{{ Introit                -->
1701
1702 <para>
1703 It is fairly reasonable to expect that enabling or disabling a
1704 configuration option such as
1705 <varname>CYGVAR_KERNEL_THREADS_DATA</varname> in some way affects its
1706 <emphasis>value</emphasis>. This will have an effect on any
1707 expressions that reference this option such as
1708 <literal>requires&nbsp;CYGVAR_KERNEL_THREADS_DATA</literal>. It will
1709 also affect the consequences of that option: how it affects the build
1710 process and what happens to any constraints that
1711 <varname>CYGVAR_KERNEL_THREADS_DATA</varname> may impose (as opposed
1712 to constraints on this option imposed by others).
1713 </para>
1714 <para>
1715 In a language like C the handling of variables is relatively
1716 straightforward. If a variable <varname>x</varname> gets referenced in
1717 an expression such as <literal>if&nbsp;(x&nbsp;!=&nbsp;0)</literal>,
1718 and that variable is not defined anywhere, then the code will fail to
1719 build, typically with an unresolved error at link-time. Also in C
1720 a variable <varname>x</varname> does not live in any hierarchy, so its
1721 value for the purposes of expression evaluation is not affected by
1722 anything else. C variables also have a clear type such as
1723 <literal>int</literal> or <literal>long&nbsp;double</literal>. 
1724 </para>
1725 <para>
1726 In &CDL; things are not so straightforward.
1727 </para>
1728
1729 <!-- }}} -->
1730 <!-- {{{ Option Values          -->
1731
1732 <sect2 id="language.values.value">
1733 <!-- {{{ Introit       -->
1734
1735 <title>Option Values</title>
1736
1737 <para>
1738 There are four factors which go into an option's value:
1739 </para>
1740 <orderedlist>
1741 <listitem>
1742 <para>
1743 An option may or may not be loaded.
1744 </para>
1745 </listitem>
1746 <listitem>
1747 <para>
1748 If the option is loaded, it may or may not be active.
1749 </para>
1750 </listitem>
1751 <listitem>
1752 <para>
1753 Even if the option is active, it may or may not be enabled.
1754 </para>
1755 </listitem>
1756 <listitem>
1757 <para>
1758 If the option is loaded, active and enabled then it will have some
1759 associated data which constitutes its value.
1760 </para>
1761 </listitem>
1762 </orderedlist>
1763
1764 <!-- }}} -->
1765 <!-- {{{ Loaded        -->
1766
1767 <sect3 id="language.values.value.loaded">
1768 <title>Is the Option Loaded?</title>
1769
1770 <para>
1771 At any one time a configuration will contain only a subset of all
1772 possible packages. In fact it is impossible to combine certain
1773 packages in a single configuration. For example architectural HAL
1774 packages should contain a set of options defining endianness, the
1775 sizes of basic data types and so on (many of which will of course be
1776 constant for any given architecture). Any attempt to load two
1777 architectural HAL packages into a configuration will fail because of
1778 the resulting name clash. Since &CDL; expressions can reference
1779 options in other packages, and often need to do so, it is essential to
1780 define the resulting behavior.
1781 </para>
1782 <para>
1783 One complication is that the component framework does not know about
1784 every single option in every single package. Obviously it cannot know
1785 about packages from arbitrary third parties which have not been
1786 installed. Even for packages which have been installed, the current
1787 repository database does not hold details of every option, only of the
1788 packages themselves. If a &CDL; expression contains a reference to
1789 some option <varname>CYGSEM_KERNEL_SCHED_TIMESLICE</varname> then the
1790 component framework will only know about this option if the kernel
1791 package is actually loaded into the current configuration. If the
1792 package is not loaded then theoretically the framework might guess
1793 that the option is somehow related to the kernel by examining the
1794 option name but this would not be robust: the option could easily be
1795 part of some other package that violates the naming convention.
1796 </para>
1797 <para>
1798 Assume that the user is building a minimal configuration which does
1799 not contain the kernel package, but does have other packages which
1800 contain the following constraints:
1801 </para>
1802 <programlisting width=72>
1803     requires CYGPKG_KERNEL
1804     requires CYGPKG_KERNEL_THREADS_DATA
1805     requires !CYGSEM_KERNEL_SCHED_TIMESLICE
1806 </programlisting>
1807 <para>
1808 Clearly the first constraint is not satisfied because the kernel is
1809 not loaded. The second constraint is also not satisfied. The third
1810 constraint is trivially satisfied: if there is no kernel then the
1811 kernel's timeslicing support cannot possibly be enabled. 
1812 </para>
1813 <para>
1814 Any options which are not in the current configuration are handled as
1815 follows: 
1816 </para>
1817 <orderedlist>
1818 <listitem>
1819 <para>
1820 Any references to that option will evaluate to <literal>0</literal>,
1821 so <literal>requires&nbsp;!CYGSEM_KERNEL_SCHED_TIMESLICE</literal> will
1822 be satisfied but
1823 <literal>requires&nbsp;CYGSEM_KERNEL_THREADS_DATA</literal> will not
1824 be satisfied.
1825 </para>
1826 </listitem>
1827 <listitem>
1828 <para>
1829 An option that is not loaded has no consequences on the build process.
1830 It cannot directly result in any <literal>#define's</literal> in a
1831 configuration header file, nor in any files being compiled. This is
1832 only reasonable: if the option is not loaded then the component
1833 framework has no way of knowing about any &compile; or similar
1834 properties. An option that is not loaded can have indirect
1835 consequences by being referenced in &CDL; expressions.
1836 </para>
1837 </listitem>
1838 <listitem>
1839 <para>
1840 An option that is not loaded cannot impose any constraints on the rest
1841 of the configuration. Again this is the only reasonable behavior: if
1842 the option is not loaded then any associated &requires; or
1843 &legal-values; properties will not be known.
1844 </para>
1845 </listitem>
1846 </orderedlist>
1847
1848 </sect3>
1849
1850 <!-- }}} -->
1851 <!-- {{{ Active        -->
1852
1853 <sect3 id="language.values.value.active">
1854 <title>Is the Option Active</title>
1855
1856 <para>
1857 The next issue to consider is whether or not a particular option is
1858 active. Configuration options are organized in a hierarchy of
1859 components and sub-components. For example the C library package
1860 contains a component <varname>CYGPKG_LIBC_STDIO</varname> containing
1861 all the options related to standard I/O. If a user disables the
1862 component as a whole then all the options below it become inactive: it
1863 makes no sense to disable all stdio functionality and then manipulate
1864 the buffer sizes.
1865 </para>
1866 <para>
1867 Inactive is not quite the same as disabled, although the effects are
1868 similar. The value of an inactive option is preserved. If the user
1869 modifies a buffer size option, then disables the whole stdio
1870 component, the buffer size value remains in case the stdio component
1871 is re-enabled later on. Some tools such as the graphical configuration
1872 tool will treat inactive options specially, for example such options
1873 may be grayed out.
1874 </para>
1875 <para>
1876 The active or inactive state of an option may affect other packages.
1877 For example a package may use the <function>sprintf</function>
1878 function and require support for floating point conversions, a
1879 constraint that is not satisfied if the relevant option is inactive.
1880 It is necessary to define exactly what it means for an option to be
1881 inactive:
1882 </para>
1883 <orderedlist>
1884 <listitem>
1885 <para>
1886 An option is inactive if its parent is either inactive or disabled.
1887 For example if <varname>CYGPKG_LIBC_STDIO</varname> is disabled then
1888 all the options and sub-components become inactive; since
1889 <varname>CYGPKG_LIBC_STDIO_FLOATING_POINT</varname> is now inactive,
1890 <varname>CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT</varname> is inactive
1891 as well.
1892 </para>
1893 </listitem>
1894 <listitem>
1895 <para>
1896 Options may also be inactive as a result of an &active-if; property.
1897 This is useful if a particular option is only relevant if two or more
1898 disjoint sets of conditions need to be satisfied, since the
1899 hierarchical structure can only cope with at most one such set.
1900 </para>
1901 </listitem>
1902 <listitem>
1903 <para>
1904 If an option is inactive then any references to that option in &CDL;
1905 expressions will evaluate to <literal>0</literal>. Hence a constraint
1906 of the form
1907 <literal>requires&nbsp;CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT</literal>
1908 is not satisfied if the entire stdio component is disabled.
1909 </para>
1910 </listitem>
1911 <listitem>
1912 <para>
1913 An option that is inactive has no consequences on the build process.
1914 No <literal>#define</literal> will be generated. Any &compile; or
1915 similar properties will be ignored.
1916 </para>
1917 </listitem>
1918 <listitem>
1919 <para>
1920 An option that is inactive cannot impose any constraints on the rest
1921 of the configuration. For example
1922 <varname>CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT</varname> has a
1923 dependency <literal>requires&nbsp;CYGPKG_LIBM</literal>, but if all of
1924 the stdio functionality is disabled then this constraint is ignored
1925 (although of course there may be other packages which have a
1926 dependency on <varname>CYGPKG_LIBM</varname>.
1927 </para>
1928 </listitem>
1929 </orderedlist>
1930 </sect3>
1931
1932 <!-- }}} -->
1933 <!-- {{{ Enabled/data  -->
1934
1935 <sect3 id="language.values.value.enabled">
1936 <title>Is the Option Enabled? What is the Data?</title>
1937
1938 <para>
1939 The majority of configuration options are boolean in nature, so the
1940 user can either enable or disable some functionality. Some options are
1941 different. For example <varname>CYGNUM_LIBC_STDIO_BUFSIZE</varname> is
1942 a number, and <varname>CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE</varname> is
1943 a string corresponding to a device name. A few options like
1944 <varname>CYGDAT_UITRON_TASK_EXTERNS</varname> can get very
1945 complicated. &CDL; has to cope with this variety, and define the exact
1946 behavior of the system in terms of constraints and build-time
1947 consequences. 
1948 </para>
1949 <para>
1950 In &CDL; the value of an option consists of two parts. There is a
1951 boolean part, controlling whether or not the option is enabled. There
1952 is also a data part, providing additional information. For most
1953 options one of these parts is fixed, as controlled by the option's
1954 &flavor; property:
1955 </para>
1956 <informaltable frame="all" colsep=1 rowsep=1 pgwide=0 tocentry=0>
1957 <tgroup cols=3 colsep=1 rowsep=1 align=left>
1958 <thead>
1959   <row>
1960     <entry>Flavor</entry>
1961     <entry>Enabled</entry>
1962     <entry>Data</entry>
1963   </row
1964 </thead>
1965 <tbody>
1966   <row>
1967     <entry><literal>none</literal></entry>
1968     <entry>Always enabled</entry>
1969     <entry><literal>1</literal>, not modifiable</entry>
1970   </row>
1971   <row>
1972     <entry><literal>bool</literal></entry>
1973     <entry>User-modifiable</entry>
1974     <entry><literal>1</literal>, not modifiable</entry>
1975   </row>
1976   <row>
1977     <entry><literal>data</literal></entry>
1978     <entry>Always enabled</entry>
1979     <entry>User-modifiable</entry>
1980   </row>
1981   <row>
1982     <entry><literal>booldata</literal></entry>
1983     <entry>User-modifiable</entry>
1984     <entry>User-modifiable</entry>
1985   </row>
1986 </tbody>
1987 </tgroup>
1988 </informaltable>
1989 <para>
1990 The effects of the boolean and data parts are as follows:
1991 </para>
1992 <orderedlist>
1993 <listitem>
1994 <para>
1995 If an option is disabled, in other words if the boolean part is false,
1996 then any references to that option in &CDL; expressions will evaluate
1997 to <literal>0</literal>. This is the same behavior as for inactive
1998 options. The data part is not relevant. The <literal>none</literal>
1999 and <literal>data</literal> flavors specify that the option is always
2000 enabled, in which case this rule is not applicable.
2001 </para>
2002 </listitem>
2003 <listitem>
2004 <para>
2005 If an option is enabled then any references to that option in &CDL;
2006 expressions will evaluate to the option's data part. For two of the
2007 flavors, <literal>none</literal> and <literal>bool</literal>, this
2008 data part is fixed to the constant <literal>1</literal> which
2009 generally has the expected result.
2010 </para>
2011 </listitem>
2012 <listitem>
2013 <para>
2014 If a component or package is disabled then all sub-components and
2015 options immediately below it in the hierarchy are inactive. By a
2016 process of recursion this will affect all the nodes in the subtree.
2017 </para>
2018 </listitem>
2019 <listitem>
2020 <para>
2021 If an option is disabled then it can impose no constraints on the rest
2022 of the configuration, in particular &requires; and &legal-values;
2023 properties will be ignored. If an option is enabled then its
2024 constraints should be satisfied, or the component framework will
2025 report various conflicts. Note that the &legal-values; constraint only
2026 applies to the data part of the option's value, so it is only useful
2027 with the <literal>data</literal> and <literal>booldata</literal>
2028 flavors. Options with the <literal>none</literal> and
2029 <literal>data</literal> flavors are always enabled so their
2030 constraints always have to be satisfied (assuming the option is
2031 active). 
2032 </para>
2033 </listitem>
2034 <listitem>
2035 <para>
2036 If an option is disabled then it has no direct consequences at
2037 build-time: no <literal>#define</literal> will be generated, no files
2038 will get compiled, and so on. If an option is active and enabled then
2039 all the consequences take effect. The option name and data part are
2040 used to generate the <literal>#define</literal> in the appropriate
2041 configuration header file, subject to various properties such as
2042 &no-define;, but the data part has no other effects on the build
2043 system. 
2044 </para>
2045 </listitem>
2046 </orderedlist>
2047 <para>
2048 By default all options and components have the <literal>bool</literal>
2049 flavor: most options are boolean in nature, so making this the default
2050 allows for slightly more compact &CDL; scripts. Packages have the
2051 <literal>booldata</literal> flavor, where the data part always
2052 corresponds to the version of the package that is loaded into the
2053 configuration: changing this value corresponds to unloading the old
2054 version and loading in a different one.
2055 </para>
2056
2057 <note>
2058 <title>&CDL; Flavors</title>
2059 <para>
2060 The concept of &CDL; flavors tends to result in various discussions
2061 about why it is unnecessarily complicated, and would it not have been
2062 easier to do&nbsp;&hellip; However there are very good reasons why CDL
2063 works the way it does.
2064 </para>
2065 <para>
2066 The first common suggestion is that there is no need to have separate
2067 flavors <literal>bool</literal>, <literal>data</literal>, and so on. A
2068 boolean option could just be handled as a data option with legal
2069 values <literal>0</literal> and <literal>1</literal>. The counter
2070 arguments are as follows:
2071 </para>
2072 <orderedlist>
2073 <listitem>
2074 <para>
2075 It would actually make &CDL; scripts more verbose. By default all
2076 options and components have the <literal>bool</literal> flavor, since
2077 most options are boolean in nature. Without a <literal>bool</literal>
2078 flavor it would be necessary to indicate explicitly what the legal
2079 values are somehow, e.g. with a &legal-values; property.
2080 </para>
2081 </listitem>
2082 <listitem>
2083 <para>
2084 The boolean part of an option's value has a very different effect from
2085 the data part. If an option is disabled then it has no consequences at
2086 build time, and can impose no constraints. A <literal>data</literal>
2087 option always has consequences and can impose constraints. To get the
2088 desired effect it would be necessary to add &CDL; data indicating that
2089 a value of <literal>0</literal> should be treated specially. Arguably
2090 this could be made built-in default behavior, although that would
2091 complicate options where <literal>0</literal> is a perfectly legal
2092 number, for example
2093 <varname>CYGNUM_LIBC_TIME_STD_DEFAULT_OFFSET</varname>. 
2094 </para>
2095 </listitem>
2096 <listitem>
2097 <para>
2098 There would no replacement for a <literal>booldata</literal> option
2099 for which <literal>0</literal> is a valid value. Again some additional
2100 &CDL; syntax would be needed to express such a concept.
2101 </para>
2102 </listitem>
2103 </orderedlist>
2104 <para>
2105 Although initially it may seem confusing that an option's value has
2106 both a boolean and a data part, it is an accurate reflection of how
2107 configuration options actually work. The various alternatives would
2108 all make it harder to write &CDL; scripts.
2109 </para>
2110 <para>
2111 The next common suggestion is that the data part of a value should be
2112 typed in much the same way as C or C++ data types. For example it
2113 should be possible to describe
2114 <varname>CYGNUM_LIBC_STDIO_BUFSIZE</varname> as an integer value,
2115 rather than imposing &legal-values; constraints. Again there are very
2116 good reasons why this approach was not taken:
2117 </para>
2118 <orderedlist>
2119 <listitem>
2120 <para>
2121 The possible legal values for an integer are rarely correct for a
2122 &CDL; option. A constraint such as
2123 <literal>1&nbsp;to&nbsp;0x7fffffff</literal> is a bit more accurate,
2124 although if this option indicates a buffer size it is still not
2125 particularly good&nbsp;&mdash; very few targets will have enough
2126 memory for such a buffer. Forcing &CDL; writers to list the
2127 &legal-values; constraints explicitly should make them think a bit
2128 more about what values are actually sensible. For example
2129 <varname>CYGNUM_LIBC_TIME_DST_DEFAULT_OFFSET</varname> has legal
2130 values in the range <literal>-90000&nbsp;to&nbsp;90000</literal>,
2131 which helps the user to set a sensible value.
2132 </para>
2133 </listitem>
2134 <listitem>
2135 <para>
2136 Not all options correspond to simple data types such as integers.
2137 <varname>CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE</varname> is a C string,
2138 and would have to be expressed using something like
2139 <literal>char&nbsp;[]</literal>. This introduces plenty of
2140 opportunities for confusion, especially since square brackets may get
2141 processed by the &Tcl; interpreter for command substitution.
2142 </para>
2143 </listitem>
2144 <listitem>
2145 <para>
2146 Some configuration options can get very complicated indeed, for
2147 example the default value of
2148 <varname>CYGDAT_UITRON_TASK_INITIALIZERS</varname> is:
2149 </para>
2150 <programlisting width=72>
2151 CYG_UIT_TASK( "t1", 1, task1, &amp;stack1, CYGNUM_UITRON_STACK_SIZE ), \
2152 CYG_UIT_TASK( "t2", 2, task2, &amp;stack2, CYGNUM_UITRON_STACK_SIZE ), \ 
2153 CYG_UIT_TASK( "t3", 3, task3, &amp;stack3, CYGNUM_UITRON_STACK_SIZE ), \
2154 CYG_UIT_TASK( "t4", 4, task4, &amp;stack4, CYGNUM_UITRON_STACK_SIZE )
2155 </programlisting>
2156 <para>
2157 This would require &CDL; knowing about C macros, structures, arrays,
2158 static initializers, and so on. Adding such detailed knowledge about
2159 the C language to the component framework is inappropriate.
2160 </para>
2161 </listitem>
2162 <listitem>
2163 <para>
2164 &CDL; needs to be usable with languages other than C. At present this
2165 includes C++, in future it may include languages such as Java. Each
2166 language adds new data types and related complications, for example
2167 C++ classes and inheritance. Making &CDL; support a union of all data
2168 types in all possible languages is not sensible.
2169 </para>
2170 </listitem>
2171 </orderedlist>
2172 <para>
2173 The &CDL; approach of treating all data as a sequence of characters,
2174 possibly constrained by a &legal-values; property or other means, has
2175 the great advantage of simplicity. It also fits in with the &Tcl;
2176 language that underlies &CDL;.
2177 </para>
2178 </note>
2179
2180 </sect3>
2181
2182 <!-- }}} -->
2183 <!-- {{{ Examples      -->
2184
2185 <sect3 id="language.values.value.examples">
2186 <title>Some Examples</title>
2187
2188 <para>
2189 The following excerpt from the C library's &CDL; scripts can be used
2190 to illustrate how values and flavors work in practice:
2191 </para>
2192 <programlisting width=72>
2193 cdl_component CYGPKG_LIBC_RAND {
2194     flavor        none
2195     compile       stdlib/rand.cxx
2196
2197     cdl_option CYGSEM_LIBC_PER_THREAD_RAND {
2198         requires      CYGVAR_KERNEL_THREADS_DATA
2199         default_value 0
2200     }
2201
2202     cdl_option CYGNUM_LIBC_RAND_SEED {
2203         flavor        data
2204         legal_values  0 to 0x7fffffff
2205         default_value 1
2206     }
2207
2208     cdl_option CYGNUM_LIBC_RAND_TRACE_LEVEL {
2209         flavor        data
2210         legal_values  0 to 1
2211         default_value 0
2212     }
2213 }
2214 </programlisting>
2215 <para>
2216 If the application does not require any C library functionality then
2217 it is possible to have a configuration where the C library is not
2218 loaded. This can be achieved by starting with the minimal template, or
2219 by starting with another template such as the default one and then
2220 explicitly unloading the C library package. If this package is not
2221 loaded then any references to the <varname>CYGPKG_LIBC_RAND</varname>
2222 component or any of its options will have a value of
2223 <literal>0</literal> for the purposes of expression evaluation. No
2224 <literal>#define's</literal> will be generated for the component or
2225 any of its options, and the file <filename>stdlib/rand.cxx</filename>
2226 will not get compiled. There is nothing special about the C library
2227 here, exactly the same would apply for say a device driver that does
2228 not correspond to any of the devices on the target hardware.
2229 </para>
2230 <para>
2231 Assuming the C library is loaded, the next thing to consider is
2232 whether or not the component and its options are active. The component
2233 is layered immediately below the C library package itself, so if the
2234 package is loaded then it is safe to assume that the package is also
2235 enabled. Therefore the parent of <varname>CYGPKG_LIBC_RAND</varname>
2236 is active and enabled, and in the absence of any &active-if;
2237 properties <varname>CYGPKG_LIBC_RAND</varname> will be active as well.
2238 </para>
2239 <para>
2240 The component <varname>CYGPKG_LIBC_RAND</varname> has the flavor
2241 <literal>none</literal>. This means the component cannot be disabled.
2242 Therefore all the options in this component have an active and enabled
2243 parent, and in the absence of any &active-if; properties they are all
2244 active as well.
2245 </para>
2246 <para>
2247 The component's flavor <literal>none</literal> serves to group
2248 together all of the configuration options related to random number
2249 generation. This is particularly useful in the context of the
2250 graphical configuration tool, but it also helps when it comes to
2251 naming the options: all of the options begin with
2252 <literal>CYGxxx_LIBC_RAND</literal>, giving a clear hint about both
2253 the package and the component within that package. The flavor means
2254 that the component is always enabled and has the value
2255 <literal>1</literal> for the purposes of expression evaluation. There
2256 will always be a single <literal>#define</literal> of the form:
2257 </para>
2258 <programlisting width=72>
2259 #define CYGPKG_LIBC_RAND 1
2260 </programlisting>
2261 <para>
2262 In addition the file <filename>stdlib/rand.cxx</filename> will always
2263 get built. If the component had the default <literal>bool</literal>
2264 flavor then users would be able to disable the whole component,
2265 and one less file would need to be built. However random number
2266 generation is relatively simple, so the impact on eCos build times are
2267 small. Furthermore by default the code has no dependencies on other
2268 parts of the system, so compiling the code has no unexpected side
2269 effects. Even if it was possible to disable the component, the
2270 sensible default for most applications would still leave it enabled.
2271 The net result is that the flavor <literal>none</literal> is probably
2272 the most sensible one for this component. For other components the
2273 default <literal>bool</literal> flavor or one of the other flavors
2274 might be more appropriate.
2275 </para>
2276 <para>
2277 Next consider option <varname>CYGSEM_LIBC_PER_THREAD_RAND</varname>
2278 which can be used to get a per-thread random number seed, possibly
2279 useful if the application needs a consistent sequence of random
2280 numbers. In the absence of a &flavor; property this option will be
2281 boolean, and the &default-value; property means that it is disabled by
2282 default&nbsp;&mdash; reasonable since few applications need this
2283 particular functionality, and it does impose a constraint on the rest
2284 of the system. If the option is left disabled then no
2285 <literal>#define</literal> will be generated, and if there were any
2286 &compile; or similar properties these would not take effect. If the
2287 option is enabled then a <literal>#define</literal> will be generated,
2288 using the option's data part which is fixed at <literal>1</literal>:
2289 </para>
2290 <programlisting width=72>
2291 #define CYGSEM_LIBC_PER_THREAD_RAND 1
2292 </programlisting>
2293 <para>
2294 The <varname>CYGSEM_LIBC_PER_THREAD_RAND</varname> option has a
2295 &requires; constraint on
2296 <varname>CYGVAR_KERNEL_THREADS_DATA</varname>. If the C library option
2297 is enabled then the constraint should be satisfied, or else the
2298 configuration contains a conflict. If the configuration does not
2299 include the kernel package then
2300 <varname>CYGVAR_KERNEL_THREADS_DATA</varname> will evaluate to
2301 <literal>0</literal> and the constraint is not satisfied. Similarly if
2302 the option is inactive or disabled the constraint will not be
2303 satisfied.
2304 </para>
2305 <para>
2306 <varname>CYGNUM_LIBC_RAND_SEED</varname> and
2307 <varname>CYGNUM_LIBC_RAND_TRACE_LEVEL</varname> both have the
2308 <literal>data</literal> flavor, so they are always enabled and the
2309 component framework will generate appropriate
2310 <literal>#define's</literal>:
2311 </para>
2312 <programlisting width=72>
2313 #define CYGNUM_LIBC_RAND_SEED 1
2314 #define CYGNUM_LIBC_RAND_SEED_1
2315 #define CYGNUM_LIBC_RAND_TRACE_LEVEL 0
2316 #define CYGNUM_LIBC_RAND_TRACE_LEVEL_0
2317 </programlisting>
2318 <para>
2319 Neither option has a &compile; or similar property, but any such
2320 properties would take effect. Any references to these options in &CDL;
2321 expressions would evaluate to the data part, so a hypothetical
2322 constraint of the form
2323 <literal>{&nbsp;requires&nbsp;CYGNUM_LIBC_RAND_SEED&nbsp;&gt;&nbsp;42&nbsp;}</literal>
2324 would not be satisfied with the default values. Both options use a
2325 simple constant for the &default-value; expression. It would be
2326 possible to use a more complicated expression, for example the default
2327 for <varname>CYGNUM_LIBC_RAND_TRACE_LEVEL</varname> could be
2328 determined from some global debugging option or from a debugging
2329 option that applies to the C library as a whole. Both options also
2330 have a &legal-values; constraint, which must be satisfied since the
2331 options are active and enabled. 
2332 </para>
2333 <note>
2334 <para>
2335 The value <literal>0</literal> is legal for both
2336 <varname>CYGNUM_LIBC_RAND_SEED</varname> and
2337 <varname>CYGNUM_LIBC_RAND_TRACE_LEVEL</varname>, so in a &CDL;
2338 expression there is no easy way of distinguishing between the options
2339 being absent or having that particular value. This will be addressed
2340 by future enhancements to the expression syntax.
2341 </para>
2342 </note>
2343
2344 </sect3>
2345
2346 <!-- }}} -->
2347 </sect2>
2348
2349 <!-- }}} -->
2350 <!-- {{{ Expressions            -->
2351
2352 <sect2 id="language.expression">
2353 <title>Ordinary Expressions</title>
2354
2355 <para>
2356 Expressions in &CDL; follow a conventional syntax, for example:
2357 </para>
2358 <programlisting width=72>
2359     default_value CYGGLO_CODESIZE &gt; CYGGLO_SPEED
2360     default_value { (CYG_HAL_STARTUP == "RAM" &&
2361                      !CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS &&
2362                      !CYGINT_HAL_USE_ROM_MONITOR_UNSUPPORTED &&
2363                      !CYGSEM_HAL_POWERPC_COPY_VECTORS) ? 1 : 0 }
2364     default_value { "\"/dev/ser0\"" }
2365 </programlisting>
2366 <para>
2367 However there is a complication in that the various arguments to a
2368 &default-value; property will first get processed by a &Tcl;
2369 interpreter, so special characters like quotes and square brackets may
2370 get processed. Such problems can be avoided by enclosing non-trivial
2371 expressions in braces, as in the second example above. The way
2372 expression parsing actually works is as follows:
2373 </para>
2374 <orderedlist>
2375 <listitem>
2376 <para>
2377 The &Tcl; interpreter splits the line or lines into a command and its
2378 arguments. In the first &default-value; expression above the command
2379 is <literal>default_value</literal> and there are three arguments,
2380 <literal>CYGGLO_CODESIZE</literal>, <literal>&gt;</literal> and
2381 <literal>CYGGLO_SPEED</literal>. In the second and third examples
2382 there is just one argument, courtesy of the braces.
2383 </para>
2384 </listitem>
2385 <listitem>
2386 <para>
2387 Next option processing takes place, so any initial arguments that
2388 begin with a hyphen will be interpreted as options. This can cause
2389 problems if the expression involves a negative number, so the
2390 special argument <literal>--</literal> can be used to prevent option
2391 processing on the subsequent arguments.
2392 </para>
2393 </listitem>
2394 <listitem>
2395 <para>
2396 All of the arguments are now concatenated, with a single space in
2397 between each one. Hence the following two expressions are equivalent,
2398 even though they will have been processed differently up to this point.
2399 </para>
2400 <programlisting>
2401     default_value CYGGLO_CODESIZE &gt; CYGGLO_SPEED
2402     default_value {CYGGLO_CODESIZE &gt; CYGGLO_SPEED}
2403 </programlisting>
2404 </listitem>
2405 <listitem>
2406 <para>
2407 The expression parsing code now has a single string to process.
2408 </para>
2409 </listitem>
2410 </orderedlist>
2411 <para>
2412 &CDL; expressions consist of four types of element: references to
2413 configuration options, constant strings, integers, and floating point
2414 numbers. These are combined using a conventional set of operators: the
2415 unary operators <literal>-</literal>, <literal>~</literal> and
2416 <literal>!</literal>; the arithmetic operators <literal>+</literal>,
2417 <literal>-</literal>, <literal>*</literal>, <literal>/</literal> and
2418 <literal>%</literal>; the shift operators <literal>&lt;&lt;</literal>
2419 and <literal>&gt;&gt;</literal>; the comparison operators
2420 <literal>==</literal>, <literal>!=</literal>, <literal>&lt;</literal>,
2421 <literal>&lt;=</literal>, <literal>&gt;</literal> and
2422 <literal>&gt;=</literal>; the bitwise operators
2423 <literal>&amp;</literal>, <literal>^</literal> and
2424 <literal>|</literal>; the logical operators <literal>&&</literal> and
2425 <literal>||</literal>; the string concatenation operator
2426 <literal>.</literal>; and the ternary conditional operator
2427 <literal>A&nbsp;?&nbsp;B&nbsp;:&nbsp;C</literal>. There is also support for
2428 some less widely available operators for logical equivalence and
2429 implication, and for a set of function-style operations. Bracketed
2430 sub-expressions are supported, and the operators have the usual
2431 precedence:
2432 </para>
2433 <informaltable frame="all" pgwide=0 colsep=1 rowsep=1>
2434 <tgroup cols=3 align="left" colsep=1 rowsep=1>
2435 <colspec colnum=1 align="center">
2436 <colspec colnum=2 align="center">
2437 <colspec colnum=3 align="center">
2438 <thead>
2439   <row>
2440     <entry>Priority</entry>
2441     <entry>Operators</entry>
2442     <entry>Category</entry>
2443   </row>
2444 </thead>
2445 <tbody>
2446   <row>
2447     <entry>16</entry>
2448     <entry>references, constants</entry>
2449     <entry>basic elements</entry>
2450   </row>
2451   <row>
2452     <entry>15</entry>
2453     <entry><literal>f(a, b, c)</literal></entry>
2454     <entry>function calls</entry>
2455   </row>
2456   <row>
2457     <entry>14</entry>
2458     <entry><literal>~</literal></entry>
2459     <entry>bitwise not</entry>
2460   </row>
2461   <row>
2462     <entry>14</entry>
2463     <entry><literal>!</literal></entry>
2464     <entry>logical not</entry>
2465   </row>
2466   <row>
2467     <entry>14</entry>
2468     <entry><literal>-</literal></entry>
2469     <entry>arithmetic negation</entry>
2470   </row>
2471   <row>
2472     <entry>13</entry>
2473     <entry><literal>* / %</literal></entry>
2474     <entry>multiplicative arithmetic</entry>
2475   </row>
2476   <row>
2477     <entry>12</entry>
2478     <entry><literal>+ - .</literal></entry>
2479     <entry>additive arithmetic and string concatenation</entry>
2480   </row>
2481   <row>
2482     <entry>11</entry>
2483     <entry><literal>&lt;&lt; &gt;&gt;</literal></entry>
2484     <entry>bitwise shifts</entry>
2485   </row>
2486   <row>
2487     <entry>10</entry>
2488     <entry><literal>&lt;= &lt; &gt; &gt;=</literal></entry>
2489     <entry>inequality</entry>
2490   </row>
2491   <row>
2492     <entry>9</entry>
2493     <entry><literal>== !=</literal></entry>
2494     <entry>comparison</entry>
2495   </row>
2496   <row>
2497     <entry>8</entry>
2498     <entry><literal>&</literal></entry>
2499     <entry>bitwise and</entry>
2500   </row>
2501   <row>
2502     <entry>7</entry>
2503     <entry><literal>^</literal></entry>
2504     <entry>bitwise xor</entry>
2505   </row>
2506   <row>
2507     <entry>6</entry>
2508     <entry><literal>|</literal></entry>
2509     <entry>bitwise or</entry>
2510   </row>
2511   <row>
2512     <entry>5</entry>
2513     <entry><literal>&&</literal></entry>
2514     <entry>logical and</entry>
2515   </row>
2516   <row>
2517     <entry>4</entry>
2518     <entry><literal>||</literal></entry>
2519     <entry>logical or</entry>
2520   </row>
2521   <row>
2522     <entry>3</entry>
2523     <entry><literal>xor, eqv</literal></entry>
2524     <entry>logical equivalance</entry>
2525   </row>
2526   <row>
2527     <entry>2</entry>
2528     <entry><literal>implies</literal></entry>
2529     <entry>logical implication</entry>
2530   </row>
2531   <row>
2532     <entry>1</entry>
2533     <entry><literal>? :</literal></entry>
2534     <entry>conditional</entry>
2535   </row>
2536 </tbody>
2537 </tgroup>
2538 </informaltable>
2539
2540 <para>
2541 Function calls have the usual format of a name, an opening bracket,
2542 one or more arguments separated by commas, and a closing bracket. For
2543 example:
2544 </para>
2545 <programlisting width=72>
2546     requires { !is_substr(CYGBLD_GLOBAL_CFLAGS, " -fno-rtti") }
2547 </programlisting>
2548 <para>
2549 Functions will differ in the number of arguments and may impose
2550 restrictions on some or all of their arguments. For example it may be
2551 necessary for the first argument to be a reference to a configuration
2552 option. The available functions are described in <xref
2553 linkend="language.functions">. 
2554 </para>
2555 <para>
2556 The logical <literal>xor</literal> operator evaluates to true if
2557 either the left hand side or the right hand side but not both evaluate
2558 to true The logical <literal>eqv</literal> operator evaluates to true
2559 if both the left and right hand sides evaluate to true, or if both
2560 evaluate to false. The <literal>implies</literal> operator evaluates
2561 to true either if the left hand side is false or if the right hand
2562 side is true, in other words <literal>A&nbsp;implies&nbsp;B</literal>
2563 has the same meaning as <literal>!A&nbsp;||&nbsp;B</literal>. An
2564 example use would be:
2565 </para>
2566 <programlisting width=72>
2567     requires { is_active(CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE) implies
2568                    (CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE >= (16 * 1024)) }
2569 </programlisting>
2570 <para>
2571 This constraint would be satisfied if either the support for a main
2572 stack size is disabled, or if that stack is at least 16K. However if
2573 such a stack were in use but was too small, a conflict would be raised.
2574 </para>
2575 <para>
2576 A valid &CDL; identifier in an expression, for example
2577 <varname>CYGGLO_SPEED</varname>, will be interpreted as a reference to
2578 a configuration option by that name. The option does not have to be
2579 loaded into the current configuration. When the component framework
2580 evaluates the expression it will substitute in a suitable value that
2581 depends on whether or not the option is loaded, active, and enabled.
2582 The exact rules are described in <xref
2583 linkend="language.values.value">.
2584 </para>
2585 <para>
2586 A constant string is any sequence of characters enclosed in quotes.
2587 Care has to be taken that these quotes are not stripped off by the
2588 &Tcl; interpreter before the &CDL; expression parser sees them.
2589 Consider the following:
2590 </para>
2591 <programlisting width=72>
2592     default_value "RAM"
2593 </programlisting>
2594 <para>
2595 The quote marks will be stripped before the &CDL; expression parser
2596 sees the data, so the expression will be interpreted as a reference to
2597 a configuration option <varname>RAM</varname>. There is unlikely to be
2598 such an option, so the actual default value will be
2599 <literal>0</literal>. Careful use of braces or other &Tcl; quoting
2600 mechanisms can be used to avoid such problems.
2601 </para>
2602 <para>          
2603 String constants consist of the data inside the quotes. If the data
2604 itself needs to contain quote characters then appropriate quoting is
2605 again necessary, for example:
2606 </para>
2607 <programlisting width=72>
2608     default_value { "\"/dev/ser0\"" }
2609 </programlisting>
2610 <para>
2611 An integer constant consists of a sequence of digits, optionally
2612 preceeded with the unary <literal>+</literal> or <literal>-</literal>
2613 operators. As usual the sequence <literal>0x</literal> or
2614 <literal>0X</literal> can be used for hexadecimal data, and a leading
2615 <literal>0</literal> indicates octal data. Internally the component
2616 framework uses 64-bit arithmetic for integer data. If a constant is
2617 too large then double precision arithmetic will be used instead.
2618 Traditional syntax is also used for double precision numbers, for
2619 example <literal>3.141592</literal> or <literal>-3E6</literal>. 
2620 </para>
2621 <para>
2622 Of course this is not completely accurate: &CDL; is not a typed
2623 language, all data is treated as if it were a string. For example the
2624 following two lines are equivalent:
2625 </para>
2626 <programlisting width=72>
2627     requires CYGNUM_UITRON_SEMAS > 10
2628     requires { CYGNUM_UITRON_SEMAS > "10" }
2629 </programlisting>
2630 <para>
2631 When an expression gets evaluated the operators will attempt
2632 appropriate conversions. The <literal>&gt;</literal> comparison
2633 operator can be used on either integer or double precision numbers, so
2634 it will begin by attempting a string to integer conversion of both
2635 operands. If that fails it will attempt string to double conversions.
2636 If that fails as well then the component framework will report a
2637 conflict, an evaluation exception. If the conversions from string to
2638 integer are successful then the result will be either the string
2639 <literal>0</literal> or the string <literal>1</literal>, both of which
2640 can be converted to integers or doubles as required.
2641 </para>
2642 <para>
2643 It is worth noting that the expression
2644 <literal>CYGNUM_UITRON_SEMAS&nbsp;&gt;10</literal> is not ambiguous.
2645 &CDL; identifiers can never begin with a digit, so it is not possible
2646 for <literal>10</literal> to be misinterpreted as a reference to an
2647 identifier instead of as a string.
2648 </para>
2649 <para>
2650 Of course the implementation is slightly different again. The &CDL;
2651 language definition is such that all data is treated as if it were a
2652 string, with conversions to integer, double or boolean as and when
2653 required. The implementation is allowed to avoid conversions until
2654 they are necessary. For example, given
2655 <literal>CYGNUM_UITRON_SEMAS&nbsp;&gt;&nbsp;10</literal> the
2656 expression parsing code will perform an immediate conversion from
2657 string to integer, storing the integer representation, and there is no
2658 need for a conversion by the comparison operator when the expression
2659 gets evaluated. Given
2660 <literal>{&nbsp;CYGNUM_UITRON_SEMAS&nbsp;&gt;&nbsp;"10"&nbsp;}</literal>
2661 the parsing code will store the string representation and a conversion
2662 happens the first time the expression is evaluated. All of this is an
2663 implementation detail, and does not affect the semantics of the
2664 language. 
2665 </para>
2666 <para>
2667 Different operators have different requirements, for example the
2668 bitwise or operator only makes sense if both operands have an integer
2669 representation. For operators which can work with either integer or
2670 double precision numbers, integer arithmetic will be preferred.
2671 </para>
2672 <para>
2673 The following operators only accept integer operands:
2674 unary <literal>~</literal> (bitwise not), the shift operators
2675 <literal>&lt;&lt;</literal> and <literal>&gt;&gt;</literal>, and the
2676 bitwise operators <literal>&</literal>, <literal>|</literal> and
2677 <literal>^</literal>.
2678 </para>
2679 <para>
2680 The following operators will attempt integer arithmetic first, then
2681 double precision arithmetic: unary <literal>-</literal>,
2682 the arithmetic operators <literal>+</literal>, <literal>-</literal>,
2683 <literal>*</literal>, <literal>/</literal>, and <literal>%</literal>;
2684 and the comparision operators <literal>&lt;</literal>,
2685 <literal>&lt;=</literal>, <literal>&gt;</literal> and
2686 <literal>&gt;=</literal>. 
2687 </para>
2688 <para>
2689 The equality <literal>==</literal> and inequality
2690 <literal>!=</literal> operators will first attempt integer conversion
2691 and comparison. If that fails then double precision will be attempted
2692 (although arguably using these operators on double precision data is
2693 not sensible). As a last resort string comparison will be used.
2694 </para>
2695 <para>
2696 The operators <literal>!</literal>, <literal>&&</literal> and
2697 <literal>||</literal> all work with boolean data. Any string that can
2698 be converted to the integer <literal>0</literal> or the double
2699 <literal>0.0</literal> is treated as false, as is the empty string or
2700 the constant string <literal>false</literal>. Anything else is
2701 interpreted as true. The result is either <literal>0</literal> or
2702 <literal>1</literal>.
2703 </para>
2704 <para>
2705 The conditional operator <literal>?&nbsp;:</literal> will interpret
2706 its first operand as a boolean. It does not perform any processing on
2707 the second or third operands.
2708 </para>
2709 <para>
2710 In practice it is rarely necessary to worry about any of these
2711 details. In nearly every case &CDL; expressions just work as expected,
2712 and there is no need to understand the full details.
2713 </para>
2714
2715 <note>
2716 <para>
2717 The current expression syntax does not meet all the needs of component
2718 writers. Some future enhancements will definitely be made, others are
2719 more controversial. The list includes the following:
2720 </para>
2721 <orderedlist>
2722 <listitem>
2723 <para>
2724 An option's value is determined by several different factors: whether
2725 or not it is loaded, whether or not it is active, whether or not it is
2726 enabled, and the data part. Currently there is no way of querying
2727 these individually. This is very significant in the context of options
2728 with the <literal>bool</literal> or <literal>booldata</literal>
2729 flavors, because there is no way of distinguishing between the option
2730 being absent/inactive/disabled or it being enabled with a data field
2731 of <literal>0</literal>. There should be unary operators that allow
2732 any of the factors to be checked.
2733 </para>
2734 </listitem>
2735 <listitem>
2736 <para>
2737 Only the <literal>==</literal> and <literal>!=</literal> operators can
2738 be used for string data. More string-related facilities are needed.
2739 </para>
2740 </listitem>
2741 <listitem>
2742 <para>
2743 An implies operator would be useful for many goal expression, where
2744 <literal>A&nbsp;implies&nbsp;B</literal> is equivalent to
2745 <literal>!A&nbsp;||B</literal>.
2746 </para>
2747 </listitem>
2748 <listitem>
2749 <para>
2750 Similarly there is inadequate support for lists. On occasion it would
2751 be useful to write expressions involving say the list of implementors
2752 of a given CDL interface, for example a sensible default value could
2753 be the first implementor. Associated with this is a need for an
2754 indirection operator.
2755 </para>
2756 </listitem>
2757 <listitem>
2758 <para>
2759 Arguably extending the basic &CDL; expression syntax with lots of new
2760 operators is unnecessary, instead expressions should just support
2761 &Tcl; command substitution and then component writers could escape
2762 into &Tcl; scripts for complicated operations. This has some major
2763 disadvantages. First, the inference engine would no longer have any
2764 sensible way of interpreting an expression to resolve a conflict.
2765 Second, the component framework's value propagation code keeps track
2766 of which options get referenced in which expressions and avoids
2767 unnecessary re-evaluation of expressions; if expressions can involve
2768 arbitrary &Tcl; code then there is no simple way to eliminate
2769 unnecessary recalculations, with a potentially major impact on
2770 performance.
2771 </para>
2772 </listitem>
2773 </orderedlist>
2774 </note>
2775
2776 <note>
2777 <para>
2778 The current implementation of the component framework uses 64 bit
2779 arithmetic on all host platforms. Although this is adequate for
2780 current target architectures, it may cause problems in future. At some
2781 stage it is likely that an arbitrary precision integer arithmetic
2782 package will be used instead.
2783 </para>
2784 </note>
2785
2786 </sect2>
2787
2788 <!-- }}} -->
2789 <!-- {{{ Functions              -->
2790
2791 <sect2 id="language.functions">
2792 <title>Functions</title>
2793
2794 <para>
2795 CDL expressions can contain calls to a set of built-in functions
2796 using the usual syntax, for example;
2797 </para>
2798 <programlisting width=72>
2799     requires { !is_substr(CYGBLD_GLOBAL_CFLAGS, "-fno-rtti") }
2800 </programlisting>
2801 <para>
2802 The available function calls are as follows:
2803 </para>
2804
2805 <variablelist>
2806
2807 <!-- {{{ get_data()             -->
2808
2809   <varlistentry>
2810     <term><literal>get_data(option)</literal></term>
2811     <listitem>
2812 <para>
2813 This function can be used to obtain just the data part of a loaded
2814 configuration option, ignoring other factors such as whether or not
2815 the option is active and enabled. It takes a single argument which
2816 should be the name of a configuration option. If the specified option
2817 is not loaded in the current configuration then the function returns
2818 0, otherwise it returns the data part. Typically this function will
2819 only be used in conjunction with <function>is_active</function> and
2820 <function>is_enabled</function> for fine-grained control over the
2821 various factors that make up an option's value.
2822 </para>
2823     </listitem>
2824   </varlistentry>
2825
2826 <!-- }}} -->
2827 <!-- {{{ is_active()            -->
2828
2829   <varlistentry>
2830     <term><literal>is_active(option)</literal></term>
2831     <listitem>
2832 <para>
2833 This function can be used to determine whether or not a particular
2834 configuration option is active. It takes a single argument which
2835 should be the name of an option, and returns a boolean. If the
2836 specified option is not loaded then the function will return false.
2837 Otherwise it will consider the state of the option's parents and
2838 evaluate any &active-if; properties, and return the option's current
2839 active state. A typical use might be:
2840 </para>
2841 <programlisting width=72>
2842     requires { is_active(CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE) implies
2843                    (CYGNUM_LIBC_MAIN_DEFAULT_STACK_SIZE >= (16 * 1024)) }
2844 </programlisting>
2845 <para>
2846 In other words either the specified configuration option must be
2847 inactive, for example because the current application does not use
2848 any related C library or POSIX functionality, or the stack size must
2849 be at least 16K.
2850 </para>
2851 <para>
2852 The configuration system's inference engine can attempt to satisfy
2853 constraints involving <function>is_active</function> in various
2854 different ways, for example by enabling or disabling parent
2855 components, or by examining &active-if; properties and manipulating
2856 terms in the associated expressions.
2857 </para>
2858     </listitem>
2859   </varlistentry>
2860
2861 <!-- }}} -->
2862 <!-- {{{ is_enabled()           -->
2863
2864   <varlistentry>
2865     <term><literal>is_enabled(option)</literal></term>
2866     <listitem>
2867 <para>
2868 This function can be used to determine whether or not a particular
2869 configuration option is enabled. It takes a single argument which
2870 should be the name of an option, and returns a boolean. If the
2871 specified option is not loaded then the function will return false.
2872 Otherwise it will return the current boolean part of the option's
2873 value. The option's active or inactive state is ignored. Typically
2874 this function will be used in conjunction with
2875 <function>is_active</function> and possibly
2876 <function>get_data</function> to provide fine-grained control over the
2877 various factors that make up an option's value.
2878 </para>
2879     </listitem>
2880   </varlistentry>
2881
2882 <!-- }}} -->
2883 <!-- {{{ is_loaded()            -->
2884
2885   <varlistentry>
2886     <term><literal>is_loaded(option)</literal></term>
2887     <listitem>
2888 <para>
2889 This function can be used to determine whether or not a particular
2890 configuration option is loaded. It takes a single argument which
2891 should be the name of an option, and returns a boolean. If the
2892 argument is a package then the <function>is_loaded</function> function
2893 provides little or no extra information, for example the following two
2894 constraints are usually equivalent:
2895 </para>
2896 <programlisting width=72>
2897     requires { CYGPKG_KERNEL }
2898     requires { is_loaded(CYGPKG_KERNEL) }
2899 </programlisting>
2900 <para>
2901 However if the specified package is loaded but re-parented below a
2902 disabled component, or inactive as a result of an &active-if;
2903 property, then the first constraint would not be satisfied but the
2904 second constraint would. In other words the
2905 <function>is_loaded</function> makes it possible to consider in
2906 isolation one of the factors that are considered when CDL expressions
2907 are evaluated.
2908 </para>
2909 <para>
2910 The configuration system's inference engine will not automatically
2911 load or unload packages to satisfy <function>is_loaded</function>
2912 constraints. 
2913 </para>
2914     </listitem>
2915   </varlistentry>
2916
2917 <!-- }}} -->
2918 <!-- {{{ is_substr()            -->
2919
2920   <varlistentry>
2921     <term><literal>is_substr(haystack,&nbsp;needle)</literal></term>
2922     <listitem>
2923 <para>
2924 This can be used to check whether or not a particular string is
2925 present in another string. It is used mainly for manipulating compiler
2926 flags. The function takes two arguments, both of which can be
2927 arbitrary expressions, and returns a boolean.
2928 </para>
2929 <para>
2930 <function>is_substr</function> has some understanding of word
2931 boundaries. If the second argument starts with a space character then
2932 that will match either a real space or the start of the string.
2933 Similarly if the second argument ends with a space character then that
2934 will match a real space or the end of the string. For example, all of
2935 the following conditions are satisfied:
2936 </para>
2937 <programlisting width=72>
2938     is_substr("abracadabra", "abra")
2939     is_substr("abracadabra", " abra")
2940     is_substr("hocus pocus", " pocus")
2941     is_substr("abracadabra", "abra ")
2942 </programlisting>
2943 <para>
2944 The first is an exact match. The second is a match because the leading
2945 space matches the start of the string. The third is an exact match,
2946 with the leading space matching an actual space. The fourth is a match
2947 because the trailing space matches the end of the string. However, the
2948 following condition is not satisfied.
2949 </para>
2950 <programlisting width=72>
2951     is_substr("abracadabra", " abra ")
2952 </programlisting>
2953 <para>
2954 This fails to match at the start of the string because the trailing
2955 space is not matched by either a real space or the end of the string.
2956 Similarly it fails to match at the end of the string.
2957 </para>
2958 <para>
2959 If a constraint involving <function>is_substr</function> is not
2960 satisfied and the first argument is a reference to a configuration
2961 option, the inference engine will attempt to modify that option's
2962 value. This can be achieved either by appending the second argument to
2963 the current value, or by removing all occurrences of that argument
2964 from the current value.
2965 </para>
2966 <programlisting width=72>
2967     requires { !is_substr(CYGBLD_GLOBAL_CFLAGS, " -fno-rtti ") }
2968     requires { is_substr(CYGBLD_GLOBAL_CFLAGS, " -frtti ") }
2969 </programlisting>
2970 <para>
2971 When data is removed the leading and trailing spaces will be left. For
2972 example, given an initial value of
2973 <<varname>CYGBLD_GLOBAL_CFLAGS</varname> of
2974 <literal>-g&nbsp;-fno-rtti&nbsp;-O2</literal> the result will be
2975 <literal>-g&nbsp;&nbsp;-O2</literal> rather than <literal>-g-O2</literal>.
2976 </para>
2977 <para>
2978 If exact matches are needed, the function
2979 <function>is_xsubstr</function> can be used instead.
2980 </para>
2981     </listitem>
2982   </varlistentry>
2983
2984 <!-- }}} -->
2985 <!-- {{{ is_xsubstr()           -->
2986
2987   <varlistentry>
2988     <term><literal>is_xsubstr(haystack,&nbsp;needle)</literal></term>
2989     <listitem>
2990 <para>
2991 This function checks whether or not the pattern string is an exact
2992 substring of the string being searched. It is similar to
2993 <function>is_substr</function> but uses exact matching only. In other
2994 words, leading or trailing spaces have to match exactly and will not
2995 match the beginning or end of the string being searched. The function
2996 takes two arguments, both of which can be arbitrary expressions, and
2997 returns a boolean. The difference between
2998 <function>is_substr</function> and <function>is_xsubstr</function> is
2999 illustrated by the following examples:
3000 </para>
3001 <programlisting width=72>
3002     cdl_option MAGIC {
3003         flavor data
3004         default_value { "abracadabra" }
3005     }
3006     &hellip;
3007     requires { is_substr(MAGIC,  " abra") }
3008     requires { is_xsubstr(MAGIC, " abra") }
3009 </programlisting>
3010 <para>
3011 The first goal will be satisfied because the leading space in the
3012 pattern matches the beginning of the string. The second goal will not
3013 be satisfied initialy because there is no exact match, so the
3014 inference engine is likely to update the value of
3015 <varname>MAGIC</varname> to <literal>abracadabra abra</literal> which
3016 does give an exact match.
3017 </para>
3018     </listitem>
3019   </varlistentry>
3020
3021 <!-- }}} -->
3022 <!-- {{{ version_cmp()          -->
3023
3024   <varlistentry>
3025     <term><literal>version_cmp(A,&nbsp;B)</literal></term>
3026     <listitem>
3027 <para>
3028 This function is used primarily to check that a sufficiently recent
3029 <link linkend="package.versions">version</link> of some other package
3030 is being used. It takes two arguments, both of which can be arbitrary
3031 expressions. In practice usually one of the arguments will be a
3032 reference to a package and the other will be a constant version
3033 string. The return value is -1 if the first argument is a more recent
3034 version then the second, 0 if the two arguments correspond to
3035 identical versions, and 1 if the first argument is an older version.
3036 For example the following constraint can be used to indicate that the
3037 current package depends on kernel functionality that only became
3038 available in version 1.3:
3039 </para>
3040 <programlisting width=72>
3041     requires { version_cmp(CYGPKG_KERNEL, "v1.3") <= 0 }
3042 </programlisting>
3043     </listitem>
3044   </varlistentry>
3045
3046 <!-- }}} -->
3047
3048
3049 </variablelist>
3050 <note>
3051 <para>
3052 At this time it is not possible to define new functions inside a CDL
3053 script. Instead functions can only be added at the C++ level, usually
3054 by extending libcdl itself. This is partly because there is more to
3055 CDL functions than simple evaluation: associated with most functions
3056 is support for the inference engine, so that if a constraint involving
3057 a function is not currently satisfied the system may be able to find a
3058 solution automatically.
3059 </para>
3060 </note>
3061        
3062 </sect2>
3063
3064 <!-- }}} -->
3065 <!-- {{{ Goal expressions       -->
3066
3067 <sect2 id="language.goal-expression">
3068 <title>Goal Expressions</title>
3069
3070 <para>
3071 The arguments to certain properties, notably &requires; and
3072 &active-if;, constitute a goal expression. As with an ordinary
3073 expression, all of the arguments get combined and then the expression
3074 parser takes over. The same care has to be taken with constant strings
3075 and anything else that may get processed by the Tcl interpreter, so
3076 often a goal expression is enclosed entirely in braces and the
3077 expression parsing code sees just a single argument.
3078 </para>
3079 <para>
3080 A goal expression is basically just a sequence of ordinary
3081 expressions, for example:
3082 </para>
3083 <programlisting width=72>
3084     requires { CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
3085                !CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
3086                !CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT }
3087 </programlisting>
3088 <para>
3089 This consists of three separate expressions, all of which should
3090 evaluate to a non-zero result. The same expression could be written
3091 as: 
3092 </para>
3093 <programlisting width=72>
3094     requires { CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS  &&
3095                !CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT &&
3096                !CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT }
3097 </programlisting>
3098 <para>
3099 Alternatively the following would have much the same effect:
3100 </para>
3101 <programlisting width=72>
3102     requires CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
3103     requires !CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
3104     requires !CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
3105 </programlisting>
3106 <para>
3107 Selecting between these alternatives is largely a stylistic choice.
3108 The first is slightly more concise than the others. The second is more
3109 likely to appeal to mathematical purists. The third is more amenable
3110 to cutting and pasting.
3111 </para>
3112 <para>
3113 The result of evaluating a goal expression is a boolean. If any part
3114 of the goal expression evaluates to the integer <literal>0</literal>
3115 or an equivalent string then the result is false, otherwise it is
3116 true. 
3117 </para>
3118 <para>
3119 The term &ldquo;goal&nbsp;expression&rdquo; relates to the component
3120 framework's inference engine: it is a description of a goal that
3121 should be satisfied for a conflict-free configuration. If a &requires;
3122 constraint is not satisfied then the inference engine will examine the
3123 goal expression: if there is some way of changing the configuration
3124 that does not introduce new conflicts and that will cause the goal
3125 expression to evaluate to true, the conflict can be resolved.
3126 </para>
3127 <para>
3128 The inference engine works with one conflict and hence one goal
3129 expression at a time. This means that there can be slightly different
3130 behavior if a constraint is specified using a single &requires;
3131 property or several different ones. Given the above example, suppose
3132 that none of the three conditions are satisfied. If a single goal
3133 expression is used then the inference engine might be able to satisfy
3134 only two of the three parts, but since the conflict as a whole cannot
3135 be resolved no part of the solution will be applied. Instead the user
3136 will have to resolve the entire conflict. If three separate goal
3137 expressions are used then the inference engine might well find
3138 solutions to two of them, leaving less work for the user. On the other
3139 hand, if a single goal expression is used then the inference engine
3140 has a bit more information to work with, and it might well find a
3141 solution to the entire conflict where it would be unable to find
3142 separate solutions for the three parts. Things can get very
3143 complicated, and in general component writers should not worry about
3144 the subtleties of the inference engine and how to manipulate its
3145 behavior. 
3146 </para>
3147 <para>
3148 It is possible to write ambiguous goal expressions, for example:
3149 </para>
3150 <programlisting width=72>
3151     requires CYGNUM_LIBC_RAND_SEED -CYGNUM_LIBC_RAND_TRACE_LEVEL &gt; 5
3152 </programlisting>
3153 <para>
3154 This could be parsed in two ways:
3155 </para>
3156 <programlisting width=72>
3157     requires ((CYGNUM_LIBC_RAND_SEED - CYGNUM_LIBC_RAND_TRACE_LEVEL) &gt; 5)
3158     requires CYGNUM_LIBC_RAND_SEED &amp;&amp; ((-CYGNUM_LIBC_RAND_TRACE_LEVEL) &gt; 5)
3159 </programlisting>
3160 <para>
3161 The goal expression parsing code will always use the largest ordinary
3162 expression for each goal, so the first interpretation will be used.
3163 In such cases it is a good idea to use brackets and avoid possible
3164 confusion. 
3165 </para>
3166
3167 </sect2>
3168
3169 <!-- }}} -->
3170 <!-- {{{ List expressions       -->
3171
3172 <sect2 id="language.list-expression">
3173 <title>List Expressions</title>
3174
3175 <para>
3176 The arguments to the &legal-values; property constitute a goal
3177 expression. As with an ordinary and goal expressions, all of the
3178 arguments get combined and then the expression parser takes over. The
3179 same care has to be taken with constant strings and anything else that
3180 may get processed by the Tcl interpreter, so often a list expression
3181 is enclosed entirely in braces and the expression parsing code sees
3182 just a single argument.
3183 </para>
3184 <para>
3185 Most list expressions take one of two forms:
3186 </para>
3187 <programlisting width=72>
3188     legal_values &lt;expr1&gt; &lt;expr2&gt; &lt;expr3&gt; ...
3189     legal_values &lt;expr1&gt; to &lt;expr2&gt;
3190 </programlisting>
3191 <para>
3192 <literal>expr1</literal>, <literal>expr2</literal> and so on are
3193 ordinary expressions. Often these will be constants or references to
3194 calculated options in the architectural HAL package, but it is
3195 possible to use arbitrary expressions when necessary. The first syntax
3196 indicates a list of possible values, which need not be numerical. The
3197 second syntax indicates a numerical range: both sides of the
3198 <literal>to</literal> must evaluate to a numerical value; if either
3199 side involves a floating point number then any floating point number
3200 in that range is legal; otherwise only integer values are legal;
3201 ranges are inclusive, so <literal>4</literal> is a valid value given a
3202 list expression <literal>1&nbsp;to&nbsp;</literal>; if one or both
3203 sides of the <literal>to</literal> does not evaluate to a numerical
3204 value then this will result in a run-time conflict. The following
3205 examples illustrate these possibilities:
3206 </para>
3207 <programlisting width=72>
3208     legal_values { "red" "green" "blue" }
3209     legal_values 1 2 4 8 16
3210     legal_values 1 to CYGARC_MAXINT
3211     legal_values 1.0 to 2.0
3212 </programlisting>
3213 <para>
3214 It is possible to combine the two syntaxes, for example:
3215 </para>
3216 <programlisting width=72>
3217     legal_values 1 2 4 to CYGARC_MAXINT -1024 -20.0 to -10
3218 </programlisting>
3219 <para>
3220 This indicates three legal values <literal>1</literal>,
3221 <literal>2</literal> and <literal>-1024</literal>, one
3222 integer range <literal>4&nbsp;to&nbsp;CYGARC_MAXINT</literal>, and one
3223 floating point range <literal>-20.0&nbsp;to&nbsp;-10.0</literal>. In
3224 practice such list expressions are rarely useful.
3225 </para>
3226 <para>
3227 The identifier <varname>to</varname> is not reserved, so it is
3228 possible to have a configuration option with that name (although it
3229 violates every naming convention). Using that option in a list
3230 expression may however give unexpected results.
3231 </para>
3232 <para>
3233 The graphical configuration tool uses the &legal-values; list
3234 expression to determine how best to let users manipulate the option's
3235 value. Different widgets will be appropriate for different lists, so
3236 <literal>{&nbsp;"red"&nbsp;"green"&nbsp;"blue"&nbsp;}</literal> might
3237 involve a pull-down option menu, and
3238 <literal>1&nbsp;to&nbsp;16</literal> could involve a spinner. The
3239 exact way in which &legal-values; lists get mapped on to GUI widgets
3240 is not defined and is subject to change at any time.
3241 </para>
3242 <para>
3243 As with goal expressions, list expressions can be ambiguous. Consider
3244 the following hypothetical example:
3245 </para>
3246 <programlisting width=72>
3247     legal_values CYGNUM_LIBC_RAND_SEED -CYGNUM_LIBC_RAND_TRACE_LEVEL
3248 </programlisting>
3249 <para>
3250 This could be parsed in two ways:
3251 </para>
3252 <programlisting width=72>
3253     legal_values (CYGNUM_LIBC_RAND_SEED - CYGNUM_LIBC_RAND_TRACE_LEVEL)
3254     legal_values (CYGNUM_LIBC_RAND_SEED) (-CYGNUM_LIBC_RAND_TRACE_LEVEL)
3255 </programlisting>
3256 <para>
3257 Both are legal. The list expression parsing code will always use the
3258 largest ordinary expression for each element, so the first
3259 interpretation will be used. In cases like this it is a good idea to
3260 use brackets and avoid possible confusion.
3261 </para>
3262
3263 </sect2>
3264
3265 <!-- }}} -->
3266 </sect1>
3267
3268 <!-- }}} -->
3269 <!-- {{{ Interfaces             -->
3270
3271 <!-- FIXME: Maybe the use of interfaces in generic drivers should be
3272 used - if only because interfaces are not really a good solution for
3273 what we need there (the generic driver cannot contain the
3274 cdl_interface and be active_if on it, since it'll result in other
3275 packages not being able to implement the interface.) -->
3276
3277 <sect1 id="language.interface">
3278 <title>Interfaces</title>
3279
3280 <para>
3281 For many configurability requirements, options provide sufficient
3282 expressive power. However there are times when a higher level of
3283 abstraction is appropriate. As an example, suppose that some package
3284 relies on the presence of code that implements the standard kernel
3285 scheduling interface. However the requirement is no more stringent
3286 than this, so the constraint can be satisfied by the mlqueue
3287 scheduler, the bitmap scheduler, or any additional schedulers that may
3288 get implemented in future. A first attempt at expressing the
3289 dependency might be:
3290 </para>
3291 <programlisting width=72>
3292     requires CYGSEM_KERNEL_SCHED_MLQUEUE || CYGSEM_KERNEL_SCHED_BITMAP
3293 </programlisting>
3294 <para>
3295 This constraint will work with the current release, but it is limited.
3296 Suppose there is a new release of the kernel which adds another
3297 scheduler such as a deadline scheduler, or suppose that there is a new
3298 third party package which adds such a scheduler. The package
3299 containing the limited constraint would now have to be updated and
3300 another release made, with possible knock-on effects.
3301 </para>
3302 <para>
3303 &CDL; interfaces provide an abstraction mechanism: constraints can be
3304 expressed in terms of an abstract concept, for example
3305 &ldquo;scheduler&rdquo;, rather than specific implementations such as
3306 <varname>CYGSEM_KERNEL_SCHED_MLQUEUE</varname> and
3307 <varname>CYGSEM_KERNEL_SCHED_BITMAP</varname>. Basically an interface
3308 is a calculated configuration option:
3309 </para>
3310 <programlisting width=72>
3311 cdl_interface CYGINT_KERNEL_SCHEDULER {
3312     display  "Number of schedulers in this configuration"
3313     &hellip;
3314 }
3315 </programlisting>
3316 <para>
3317 The individual schedulers can then implement this interface:
3318 </para>
3319 <programlisting width=72>
3320 cdl_option CYGSEM_KERNEL_SCHED_MLQUEUE {
3321     display       "Multi-level queue scheduler"
3322     default_value 1
3323     implements    CYGINT_KERNEL_SCHEDULER
3324     &hellip;
3325 }
3326
3327 cdl_option CYGSEM_KERNEL_SCHED_BITMAP {
3328     display       "Bitmap scheduler"
3329     default_value 0
3330     implements    CYGINT_KERNEL_SCHEDULER
3331     &hellip;
3332 }
3333 </programlisting>
3334 <para>
3335 Future schedulers can also implement this interface. The value of an
3336 interface, for the purposes of expression evaluation, is the number of
3337 active and enabled options which implement this interface. Packages
3338 which rely on the presence of a scheduler can impose constraints such
3339 as:
3340 </para>
3341 <programlisting width=72>
3342     requires CYGINT_KERNEL_SCHEDULER
3343 </programlisting>
3344 <para>
3345 If none of the schedulers are enabled, or if the kernel package is not
3346 loaded, then <varname>CYGINT_KERNEL_SCHEDULER</varname> will evaluate
3347 to <literal>0</literal>. If at least one scheduler is active and
3348 enabled then the constraint will be satisfied.
3349 </para>
3350 <para>
3351 Because interfaces have a calculated value determined by the
3352 implementors, the &default-value; and &calculated; properties are not
3353 applicable and should not appear in the body of a &cdl-interface;
3354 command. Interfaces have the <literal>data</literal> flavor by
3355 default, but the <literal>bool</literal> and
3356 <literal>booldata</literal> flavors may be specified instead. A
3357 <literal>bool</literal> interface is disabled if there are no active
3358 and enabled implementors, otherwise it is enabled. A
3359 <literal>booldata</literal> interface is disabled if there are no
3360 active and enabled implementors, otherwise it is enabled and has a
3361 value corresponding to the number of these implementors. Other
3362 properties such as &requires; and &compile; can be used as normal.
3363 </para>
3364 <para>
3365 Some component writers will not want to use interfaces in this way.
3366 The reasoning is that their code will only have been tested with the
3367 existing schedulers, so the &requires; constraint needs to be
3368 expressed in terms of those schedulers; it is possible that the
3369 component will still work with a new scheduler, but there are no
3370 guarantees. Other component writers may take a more optimistic view
3371 and assume that their code will work with any scheduler until proven
3372 otherwise. It is up to individual component writers to decide which
3373 approach is most appropriate in any given case.
3374 </para>
3375 <para>
3376 One common use for interfaces is to describe the hardware
3377 functionality provided by a given target. For example the &CDL;
3378 scripts for a TCP/IP package might want to know whether or not the
3379 target hardware has an ethernet interface. Generally it is not
3380 necessary for the TCP/IP stack to know exactly which ethernet hardware
3381 is present, since there should be a device driver which implements the
3382 appropriate functionality. In &CDL; terms the device drivers should
3383 implement an interface <varname>CYGHWR_NET_DRIVERS</varname>, and the
3384 &CDL; scripts for the TCP/IP stack can use this in appropriate
3385 expressions. 
3386 </para>
3387 <note>
3388 <para>
3389 Using the term <emphasis>interface</emphasis> for this concept is
3390 sometimes confusing, since the term has various other meanings as
3391 well. In practice, it is often correct. If there is a configuration
3392 option that implements a given &CDL; interface, then usually this
3393 option will enable some code that provides a particular interface at
3394 the C or C++ level. For example an ethernet device driver implements
3395 the &CDL; interface <varname>CYGHWR_NET_DRIVERS</varname>, and also
3396 implements a set of C functions that can be used by the TCP/IP stack.
3397 Similarly <varname>CYGSEM_KERNEL_SCHED_MLQUEUE</varname> implements
3398 the &CDL; interface <varname>CYGINT_KERNEL_SCHEDULER</varname> and
3399 also provides the appropriate scheduling functions.
3400 </para>
3401 </note>
3402
3403 </sect1>
3404
3405 <!-- }}} -->
3406 <!-- {{{ Package database       -->
3407
3408 <sect1 id="language.database">
3409 <title>Updating the <database>ecos.db</database> database</title>
3410
3411 <para>
3412 The current implementation of the component framework requires that
3413 all packages be present in a single component repository and listed in
3414 that repository's <database>ecos.db</database> database. This is not
3415 generally a problem for application developers who can consider the
3416 component repository a read-only resource, except when adding or
3417 removing packages via the administration tool. However it means that
3418 component writers need to do their development work inside a
3419 component repository as well, and update the database with details of
3420 their new package or packages. Future enhancements to the component
3421 framework may allow new components to be developed outside a
3422 repository. 
3423 </para>
3424 <para>
3425 Like most files related to the component framework, the
3426 <database>ecos.db</database> database is actually a &Tcl; script.
3427 Typical package entries would look like this:
3428 </para>
3429 <programlisting width=72>
3430 package CYGPKG_LIBC {
3431         alias           { "C library" libc clib clibrary }
3432         directory       language/c/libc
3433         script          libc.cdl
3434         description  "
3435 This package enables compatibility with the ISO C standard - ISO/IEC
3436 9899:1990. This allows the user application to use well known standard
3437 C library functions, and in eCos starts a thread to invoke the user
3438 function main()"
3439 }
3440
3441 package CYGPKG_IO_PCI   {
3442         alias           { "PCI configuration library" io_pci }
3443         directory       io/pci
3444         script          io_pci.cdl
3445         hardware
3446         description "
3447            This package contains the PCI configuration library."
3448 }
3449 </programlisting>
3450 <para>
3451 The <literal>package</literal> command takes two arguments, a name and
3452 a body. The name must be the same as in the &cdl-package; command in
3453 the package's top-level &CDL; script. The body can contain the
3454 following five commands: <literal>alias</literal>,
3455 <literal>directory</literal>, <literal>script</literal>,
3456 <literal>hardware</literal> and <literal>description</literal>.
3457 </para>
3458
3459 <variablelist>
3460 <varlistentry>
3461 <term><literal>alias</literal></term>
3462 <listitem>
3463 <para>
3464 Each package should have one or more aliases. The first alias is
3465 typically used when listing the known packages, because a string like
3466 <literal>C&nbsp;library</literal> is a bit easier to read and
3467 understand than <varname>CYGPKG_LIBC</varname>. The other aliases are
3468 not used for output, but are accepted on input. For example the
3469 <application class="software">ecosconfig</application> command-line
3470 tool will accept <literal>add&nbsp;libc</literal> as an option, as well
3471 as <literal>add&nbsp;CYGPKG_LIBC</literal>.
3472 </para>
3473 </listitem>
3474 </varlistentry>
3475
3476 <varlistentry>
3477 <term><literal>directory</literal></term>
3478 <listitem>
3479 <para>
3480 This is used to specify the location of the package relative to the
3481 root of the component repository. It should be noted that in the
3482 current component framework this location cannot be changed in
3483 subsequent releases of the package: if for some reason it is desirable
3484 to install a new release elsewhere in the repository, all the old
3485 versions must first be uninstalled; the database cannot hold two
3486 separate locations for one package.
3487 </para>
3488 </listitem>
3489 </varlistentry>
3490
3491 <varlistentry>
3492 <term><literal>script</literal></term>
3493 <listitem>
3494 <para>
3495 The <literal>script</literal> command specifies the location of the
3496 package's top-level &CDL; script, in other words the one containing the
3497 &cdl-package; definition. If the package follows the <link
3498 linkend="package.hierarchy">directory layout conventions</link> then
3499 this script will be in the <filename class="directory">cdl</filename>
3500 sub-directory, otherwise it will be relative to the package's top-level
3501 directory. Again once a release has been made this file should not
3502 change in later releases. In practice the top-level script is generally
3503 named after the package itself, so changing its name is unlikely to be
3504 useful. 
3505 </para>
3506 </listitem>
3507 </varlistentry>
3508
3509 <varlistentry>
3510 <term><literal>hardware</literal></term>
3511 <listitem>
3512 <para>
3513 Packages which are tied to specific hardware, for example device
3514 drivers and HAL packages, should indicate this in both the
3515 &cdl-package; command of the &CDL; script and in the database entry.
3516 </para>
3517 </listitem>
3518 </varlistentry>
3519
3520 <varlistentry>
3521 <term><literal>description</literal></term>
3522 <listitem>
3523 <para>
3524 This should give a brief description of the package. Typically the
3525 text for the &description; property in the &cdl-package; command will
3526 be re-used.
3527 </para>
3528 </listitem>
3529 </varlistentry>
3530 </variablelist>
3531
3532 <note>
3533 <para>
3534 Most of the information in the <database>ecos.db</database> file could
3535 be obtained by a relatively simple utility. This would be passed a
3536 single argument identifying a package's top-level &CDL; script. The
3537 directory path relative to the component repository root could be
3538 determined from the filename. The name, <literal>description</literal>
3539 and <literal>hardware</literal> fields could be obtained from the
3540 script's &cdl-package; command. The &display; property would supply
3541 the first alias, additional aliases could be obtained by extending the
3542 syntax of that property or by other means. Something along these lines
3543 may be provided by a future release of the component framework.
3544 </para>
3545 </note>
3546 <para>
3547 Currently the <database>ecos.db</database> database also holds
3548 information about the various targets. When porting to a new target it
3549 will be necessary to add information about the target to the database,
3550 as well as the details of the new platform HAL package and any related
3551 packages. 
3552 </para>
3553
3554 </sect1>
3555
3556 <!-- }}} -->
3557
3558 </chapter>