]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/libcdl/doc/package.sgml
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / tools / src / libcdl / doc / package.sgml
1 <!-- {{{ Banner                 -->
2
3 <!-- =============================================================== -->
4 <!--                                                                 -->
5 <!--     package.sgml                                                -->
6 <!--                                                                 -->
7 <!--     How to write a package.                                     -->
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="package">
39 <title>Package Organization</title>
40
41 <!-- {{{ Introit                -->
42
43 <para>
44 For a package to be usable in the &eCos; component framework it must
45 conform to certain rules imposed by that framework. Packages must be
46 distributed in a form that is understood by the component repository
47 administration tool. There must be a top-level &CDL; script which
48 describes the package to the component framework. There are certain
49 limitations related to how a package gets built, so that the package
50 can still be used in a variety of host environments. In addition to
51 these rules, the component framework provides a number of guidelines.
52 Packages do not have to conform to the guidelines, but sticking to
53 them can simplify certain operations.
54 </para>
55 <para>
56 This chapter deals with the general organization of a package, for
57 example how to distinguish between private and exported header files.
58 <xref linkend="language"> describes the &CDL; language.
59 <xref linkend="build"> details the build process.
60 </para>
61
62 <!-- }}} -->
63 <!-- {{{ Repository             -->
64
65 <sect1 id="package.hierarchy">
66 <title>Packages and the Component Repository</title>
67
68 <para>
69 All &eCos; installations include a component repository. This is a
70 directory structure for all installed packages. The component
71 framework comes with an administration tool that allows new packages
72 or new versions of a package to be installed, old packages to be
73 removed, and so on. The component repository includes a simple
74 database, maintained by the administration tool, which contains
75 details of the various packages.
76 </para>
77
78 <informalfigure PgWide=1>
79 <mediaobject>
80 <imageobject>
81 <imagedata fileref="repo.eps" format="eps" Scalefit=1 Align="Center">
82 </imageobject>
83 <imageobject>
84 <imagedata fileref="repo.gif" format="gif" Align="Center">
85 </imageobject>
86 </mediaobject>
87 </informalfigure>
88
89 <para>
90 Each package has its own little directory hierarchy within the
91 component repository. Keeping several packages in a single directory
92 is illegal. The error, infra and kernel packages all live at the
93 top-level of the repository. For other types of packages there are
94 some pre-defined directories: <filename
95 class="directory">compat</filename> is used for compatibility
96 packages, which implement other interfaces such as &uITRON; or POSIX
97 using native &eCos; calls; <filename class="directory">hal</filename>
98 is used for packages that port &eCos; to different architectures or
99 platforms, and this directory is further organized on a
100 per-architecture basis; <filename class="directory">io</filename> is
101 intended for device drivers; <filename
102 class="directory">language</filename> is used for language support
103 libraries, for example the C library. There are no strict rules
104 defining where new packages should get installed. Obviously if an
105 existing top-level directory such as <filename
106 class="directory">compat</filename> is applicable then the new package
107 should go in there. If a new category is desirable then it is possible
108 to create a new sub-directory in the component repository. For
109 example, an organization planning to release a number of &eCos;
110 packages may want them all to appear below a sub-directory
111 corresponding to the organization's name&nbsp;&mdash; in the hope that
112 the name will not change too often. It is possible to add new packages
113 directly to the top-level of the component repository, but this should
114 be avoided.
115 </para>
116
117 <para>
118 The <database>ecos.db</database> file holds the component repository
119 database and is managed by the administration tool. The various
120 configuration tools read in this file when they start-up to obtain
121 information about the various packages that have been installed. When
122 developing a new package it is necessary to add some information to
123 the file, as described in <xref linkend="language.database">. The
124 <filename class="directory">templates</filename> directory holds
125 various configuration templates.
126 </para>
127
128 <note>
129 <para>
130 Earlier releases of &eCos; came with two separate files,
131 <filename>targets</filename> and <filename>packages</filename>. The
132 <database>ecos.db</database> database replaces both of these.
133 </para>
134 </note>
135
136 <caution>
137 <para>
138 The current <database>ecos.db</database> database does not yet provide
139 all of the information needed by the component framework. Its format
140 is subject to change in future releases, and the file may be replaced
141 completely if necessary. There are a number of other likely future
142 developments related to the component repository and the database. The
143 way targets are described is subject to change. Sometimes it is
144 desirable for component writers to do their initial development in a
145 directory outside the component repository, but there is no specific
146 support in the framework for that yet.
147 </para>
148 </caution>
149
150 </sect1>
151
152 <!-- }}} -->
153 <!-- {{{ Versioning             -->
154
155 <sect1 id="package.versions">
156 <title>Package Versioning</title>
157 <para>
158 Below each package directory there can be one or more version
159 sub-directories, named after the versions. This is a requirement of
160 the component framework: it must be possible for users to install
161 multiple versions of a package and select which one to use for any
162 given application. This has a number of advantages to users: most
163 importantly it allows a single component repository to be shared
164 between multiple users and multiple projects, as required; also it
165 facilitates experiments, for example it is relatively easy to try out
166 the latest version of some package and see if it makes any difference.
167 There is a potential disadvantage in terms of disk space. However
168 since &eCos; packages generally consist of source code intended for
169 small embedded systems, and given typical modern disk sizes, keeping a
170 number of different versions of a package installed will usually be
171 acceptable. The administration tool can be used to remove versions
172 that are no longer required.
173 </para>
174
175 <informalfigure PgWide=1>
176 <mediaobject>
177 <imageobject>
178 <imagedata fileref="version.eps" format="eps" Scalefit=1 Align="Center">
179 </imageobject>
180 <imageobject>
181 <imagedata fileref="version.gif" format="gif" Align="Center">
182 </imageobject>
183 </mediaobject>
184 </informalfigure>
185
186 <para>
187 The version <filename>current</filename> is special. Typically it
188 corresponds to the very latest version of the sources, obtained by
189 anonymous &CVS;. These sources may change frequently, unlike full
190 releases which do not change (or only when patches are produced).
191 Component writers may also want to work on the
192 <filename>current</filename> version.
193 </para>
194 <para>
195 All other subdirectories of a package correspond to specific releases
196 of that package. The component framework allows users to select the
197 particular version of a package they want to use, but by default the
198 most recent one will be used. This requires some rules for ordering
199 version numbers, a difficult task because of the wide variety of ways
200 in which versions can be identified.
201 </para>
202
203 <orderedlist>
204 <listitem>
205 <para>
206 The version <filename>current</filename> is always considered to be
207 the most recent version.
208 </para
209 </listitem>
210
211 <listitem>
212 <para>
213 If the first character of both strings are either <literal>v</literal>
214 or <literal>V</literal>, these are skipped because it makes little
215 sense to enforce case sensitivity here. Potentially this could result
216 in ambiguity if there are two version directories
217 <literal>V1.0</literal> and <literal>v1.0</literal>, but this will
218 match the confusion experienced by any users of such a package.
219 However if two subsequent releases are called <literal>V1.0</literal>
220 and <literal>v1.1</literal>, e.g. because of a minor mix-up when
221 making the distribution file, then the case difference is ignored.
222 </para>
223 </listitem>
224
225 <listitem>
226 <para>
227 Next the two version strings are compared one character at a time.
228 If both strings are currently at a digit then a string to number
229 conversion takes place, and the resulting numbers are compared.
230 For example <literal>v10</literal> is a more recent release than
231 <literal>v2</literal>. If the two numbers are the same then processing
232 continues, so for <literal>v2b</literal> and <literal>v2c</literal>
233 the version comparison code would move on to <literal>b</literal> and
234 <literal>c</literal>. 
235 </para>
236 </listitem>
237
238 <listitem>
239 <para>
240 The characters dot <literal>.</literal>, hyphen <literal>-</literal>
241 and underscore <literal>_</literal> are treated as equivalent
242 separators, so if one release goes out as <literal>v1_1</literal> and
243 the next goes out as <literal>v1.2</literal> the separator has no
244 effect.
245 </para>
246 </listitem>
247
248 <listitem>
249 <para>
250 If neither string has yet terminated but the characters are different,
251 ASCII comparison is used. For example <literal>V1.1b</literal> is
252 more recent than <literal>v1.1alpha</literal>.
253 </para>
254 </listitem>
255
256 <listitem>
257 <para>
258 If one version string terminates before the other, the current
259 character determines which is the more recent. If the other string is
260 currently at a separator character, for example
261 <literal>v1.3.1</literal> and <literal>v1.3</literal>, then the former
262 is assumed to be a minor release and hence more recent than the
263 latter. If the other string is not at a separator character, for
264 example <literal>v1.3beta</literal>, then it is treated as an
265 experimental version of the <literal>v1.3</literal> release and hence
266 older. 
267 </para>
268 </listitem>
269
270 <listitem>
271 <para>
272 There is no special processing of dates, so with two versions
273 <literal>ss-20000316</literal> and <literal>ss-20001111</literal>
274 the numerical values <literal>20001111</literal> and
275 <literal>20000316</literal> determine the result: larger values are
276 more recent. It is suggested that the full year be used in such cases
277 rather than a shorthand like <literal>00</literal>, to avoid
278 Y2100 problems.
279 </para>
280 </listitem>
281
282 <listitem>
283 <para>
284 There is no limit on how many levels of versioning are used, so
285 there could in theory be a <literal>v3.1.4.1.5.9.2.7</literal> release
286 of a package. However this is unlikely to be of benefit to typical
287 users of a package.
288 </para>
289 </listitem>
290
291 </orderedlist>
292
293 <para>
294 The version comparison rules of the component framework may not be
295 suitable for every version numbering scheme in existence, but they
296 should cope with many common cases.
297 </para>
298
299 <caution>
300 <para>
301 There are some issues still to be resolved before it is possible to
302 combine the <filename>current</filename> sources available via
303 anonymous &CVS and full releases of &eCos; and additional packages in
304 a single component repository. The first problem relates to the
305 <database>ecos.db</database> database: if a new package is added via
306 the CVS repository then this requires a database update, but the
307 administration tool is bypassed. The second problem arises if an
308 organization chooses to place its component repository under source
309 code control using &CVS;, in which case different directories will
310 belong to different &CVS; servers. These issues will be addressed in a
311 future release.
312 </para>
313 </caution>
314
315 </sect1>
316
317 <!-- }}} -->
318 <!-- {{{ Package contents       -->
319
320 <!-- {{{ Introit                -->
321
322 <sect1 id="package.contents">
323 <title>Package Contents and Layout</title>
324 <para>
325 A typical package contains the following:
326 </para>
327 <orderedlist>
328 <listitem>
329 <para>
330 Some number of source files which will end up in a library. The
331 application code will be linked with this library to produce an
332 executable. Some source files may serve other purposes, for example to
333 provide a linker script.
334 </para>
335 </listitem>
336 <listitem>
337 <para>
338 Exported header files which define the interface provided by the
339 package. 
340 </para>
341 </listitem>
342 <listitem>
343 <para>
344 On-line documentation, for example reference pages for each exported
345 function. 
346 </para>
347 </listitem>
348 <listitem>
349 <para>
350 Some number of test cases, shipped in source format, allowing users to
351 check that the package is working as expected on their particular
352 hardware and in their specific configuration.
353 </para>
354 </listitem>
355 <listitem>
356 <para>
357 One or more &CDL; scripts describing the package to the configuration
358 system.
359 </para>
360 </listitem>
361 </orderedlist>
362 <para>
363 It is also conventional to have a per-package
364 <filename>ChangeLog</filename> file used to keep track of changes to
365 that package. This is especially valuable to end users of the package
366 who may not have convenient access to the source code control system
367 used to manage the master copy of the package, and hence cannot find
368 out easily what has changed. Often it can be very useful to the main
369 developers as well.
370 </para>
371 <para>
372 Any given packages need not contain all of these. It is compulsory to
373 have at least one &CDL; script describing the package, otherwise the
374 component framework would be unable to process it. Some packages may
375 not have any source code: it is possible to have a package that merely
376 defines a common interface which can then be implemented by several
377 other packages, especially in the context of device drivers; however
378 it is still common to have some code in such packages to avoid
379 replicating shareable code in all of the implementation packages.
380 Similarly it is possible to have a package with no exported header
381 files, just source code that implements an existing interface: for
382 example an ethernet device driver might just implement a standard
383 interface and not provide any additional functionality. Packages do
384 not need to come with any on-line documentation, although this may
385 affect how many people will want to use the package. Much the same
386 applies to per-package test cases.
387 </para>
388
389 <para>
390 The component framework has a recommended per-package directory layout
391 which splits the package contents on a functional basis:
392 </para>
393
394 <informalfigure PgWide=1>
395 <mediaobject>
396 <imageobject>
397 <imagedata fileref="package.eps" format="eps" Scalefit=1 Align="Center">
398 </imageobject>
399 <imageobject>
400 <imagedata fileref="package.gif" format="gif" Align="Center">
401 </imageobject>
402 </mediaobject>
403 </informalfigure>
404
405 <para>
406 For example, if a package has an <filename
407 class="directory">include</filename> sub-directory then the component
408 framework will assume that all header files in and below that
409 directory are exported header files and will do the right thing at
410 build time. Similarly if there is &doc; property indicating the
411 location of on-line documentation then the component framework will
412 first look in the <filename class="directory">doc</filename>
413 sub-directory.
414 </para>
415
416 <para>
417 This directory layout is just a guideline, it is not enforced by the
418 component framework. For simple packages it often makes more sense to
419 have all of the files in just one directory. For example a package
420 could just contain the files <filename>hello.cxx</filename>,
421 <filename>hello.h</filename>, <filename>hello.html</filename> and
422 <filename>hello.cdl</filename>. By default
423 <filename>hello.h</filename> will be treated as an exported header
424 file, although this can be overridden with the <link
425 linkend="ref.include-files">&include-files;</link> property. Assuming
426 there is a &doc; property referring to <filename>hello.html</filename>
427 and there is no <filename class="directory">doc</filename>
428 sub-directory then the tools will search for this file relative to the
429 package's top-level and everything will just work. Much the same
430 applies to <filename>hello.cxx</filename> and
431 <filename>hello.cdl</filename>. 
432 </para>
433
434 <tip>
435 <para>
436 Older versions of the &eCos; build system only supported packages that
437 followed the directory structure exactly. Hence certain core packages
438 such as <filename>error</filename> implement the full directory
439 structure, even though that is a particularly simple package and the
440 full directory structure is inappropriate. Component writers can
441 decide for themselves whether or not the directory structure
442 guidelines are appropriate for their package.
443 </para>
444 </tip>
445
446 <!-- }}} -->
447 <!-- {{{ Build process          -->
448
449 <sect2 id="package.build">
450 <title>Outline of the Build Process</title>
451 <para>
452 The full build process is described in <xref linkend="build">, but 
453 a summary is appropriate here. A build involves three directory
454 structures: 
455 </para>
456
457 <orderedlist>
458 <listitem>
459 <para>
460 The component repository. This is where all the package source code is
461 held, along with &CDL; scripts, documentation, and so on. For build
462 purposes a component repository is read-only. Application developers
463 will only modify the component repository when installing or removing
464 packages, via the administration tool. Component writers will
465 typically work on just one package in the component repository.
466 </para>
467 </listitem>
468 <listitem>
469 <para>
470 The build tree. Each configuration has its own build tree, which can
471 be regenerated at any time using the configuration's
472 <filename>ecos.ecc</filename> savefile. The build tree contains only
473 intermediate files, primarily object files. Once a build is complete
474 the build tree contains no information that is useful for application
475 development and can be wiped, although this would slow down any
476 rebuilds following changes to the configuration.
477 </para>
478 </listitem>
479 <listitem>
480 <para>
481 The install tree. This is populated during a build, and contains all
482 the files relevant to application development. There will be a
483 <filename class="directory">lib</filename> sub-directory which
484 typically contains <filename>libtarget.a</filename>, a linker script,
485 start-up code, and so on. There will also be an <filename
486 class="directory">include</filename> sub-directory containing all the
487 header files exported by the various packages. There will also be a
488 <filename class="directory">include/pkgconf</filename> sub-directory
489 containing various configuration header files with
490 <literal>#define's</literal> for the options. Typically the install
491 tree is created within the build tree, but this is not a requirement.
492 </para>
493 </listitem>
494 </orderedlist>
495
496 <para>
497 The build process involves the following steps:
498 </para>
499 <orderedlist>
500 <listitem>
501 <para>
502 Given a configuration, the component framework is responsible for
503 creating all the directories in the build and install trees. If these
504 trees already exist then the component framework is responsible for
505 any clean-ups that may be necessary, for example if a package has been
506 removed then all related files should be expunged from the build and
507 install trees. The configuration header files will be generated at
508 this time. Depending on the host environment, the component framework
509 will also generate makefiles or some other way of building the various
510 packages. Every time the configuration is modified this step needs to
511 be repeated, to ensure that all option consequences take effect. Care
512 is taken that this will not result in unnecessary rebuilds.
513 </para>
514 <note>
515 <para>
516 At present this step needs to be invoked manually. In a future version
517 the generated makefile may if desired perform this step automatically,
518 using a dependency on the <filename>ecos.ecc</filename> savefile.
519 </para>
520 </note>
521 </listitem>
522 <listitem>
523 <para>
524 The first step in an actual build is to make sure that the install
525 tree contains all exported header files. All compilations will use
526 the install tree's <filename class="directory">include</filename>
527 directory as one of the places to search for header files.
528 </para>
529 </listitem>
530 <listitem>
531 <para>
532 All source files relevant to the current configuration get compiled.
533 This involves a set of compiler flags initialized on a per-target
534 basis, with each package being able to modify these flags, and with
535 the ability for the user to override the flags as well. Care has to be
536 taken here to avoid inappropriate target-dependencies in packages that
537 are intended to be portable. The component framework has built-in
538 knowledge of how to handle C, C++ and assembler source files &mdash;
539 other languages may be added in future, as and when necessary. The
540 <link linkend="ref.compile">&compile;</link> property is used to
541 list the files that should get compiled. All object files end up in
542 the build tree.
543 </para>
544 </listitem>
545 <listitem>
546 <para>
547 Once all the object files have been built they are collected into a
548 library, typically <filename>libtarget.a</filename>, which can then be
549 linked with application code. The library is generated in the install
550 tree. 
551 </para>
552 </listitem>
553 <listitem>
554 <para>
555 The component framework provides support for custom build steps, using
556 the <link linkend="ref.make-object">&make-object;</link> and
557 <link linkend="ref.make">&make;</link> properties. The results of
558 these custom build steps can either be object files that should end up
559 in a library, or other files such as a linker script. It is possible
560 to control the order in which these custom build steps take place, for
561 example it is possible to run a particular build step before any of
562 the compilations happen.
563 </para>
564 </listitem>
565 </orderedlist>
566
567 </sect2>
568
569 <!-- }}} -->
570 <!-- {{{ Sources                -->
571
572 <sect2 id="package.source">
573 <title>Configurable Source Code</title>
574 <para>
575 All packages should be totally portable to all target hardware (with
576 the obvious exceptions of HAL and device driver packages). They should
577 also be totally bug-free, require the absolute minimum amount of code
578 and data space, be so efficient that cpu time usage is negligible, and
579 provide lots of configuration options so that application developers
580 have full control over the behavior. The configuration options are
581 optional only if a package can meet the requirements of every
582 potential application without any overheads. It is not the purpose of
583 this guide to explain how to achieve all of these requirements.
584 </para>
585 <para>
586 The &eCos; component framework does have some important implications
587 for the source code: compiler flag dependencies; package interfaces
588 vs. implementations; and how configuration options affect source code.
589 </para>
590
591 <sect3 id="package.source.flags">
592 <title>Compiler Flag Dependencies</title>
593 <para>
594 Wherever possible component writers should avoid dependencies on
595 particular compiler flags. Any such dependencies are likely to impact
596 portability. For example, if one package needs to be built in
597 big-endian mode and another package needs to be built in little-endian
598 mode then usually it will not be possible for application developers
599 to use both packages at the same time; in addition the application
600 developer is no longer given a choice in the matter. It is far better
601 for the package source code to adapt the endianness at compile-time,
602 or possibly at run-time although that will involve code-size
603 overheads.
604 </para>
605 <note>
606 <para>
607 A related issue is that the current support for handling compiler
608 flags in the component framework is still limited and incapable of
609 handling flags at a very fine-grain. The support is likely to be
610 enhanced in future versions of the framework, but there are
611 non-trivial problems to be resolved.
612 </para>
613 </note>
614 </sect3>
615
616 <sect3 id="package.source.interfaces">
617 <title>Package Interfaces and Implementations</title>
618 <para>
619 The component framework provides encapsulation at the package level. A
620 package <literal>A</literal> has no way of accessing the
621 implementation details of another package <literal>B</literal> at
622 compile-time. In particular, if there is a private header file
623 somewhere in a package's <filename class="directory">src</filename>
624 sub-directory then this header file is completely invisible to other
625 packages. Any attempts to cheat by using relative pathnames beginning
626 with <filename class="directory">../..</filename> are generally doomed
627 to failure because of the presence of package version directories.
628 There are two ways in which one package can affect another: by means
629 of the exported header files, which define a public interface; or via
630 the &CDL; scripts.
631 </para>
632 <para>
633 This encapsulation is a deliberate aspect of the overall &eCos;
634 component framework design. In most cases it does not cause any
635 problems for component writers. In some cases enforcing a clean
636 separation between interface and implementation details can improve
637 the code. Also it reduces problems when a package gets upgraded:
638 component writers are free to do pretty much anything on the
639 implementation side, including renaming every single source file; care
640 has to be taken only with the exported header files and with the &CDL;
641 data, because those have the potential of impacting other packages.
642 Application code is similarly unable to access package implementation
643 details, only the exported interface.
644 </para>
645 <para>
646 Very occasionally the inability of one package to see implementation
647 details of another does cause problems. One example occurs in HAL
648 packages, where it may be desirable for the architectural, variant and
649 platform HAL's to share some information that should not be visible to
650 other packages or to application code. This may be addressed in the
651 future by introducing the concept of <literal>friend</literal>
652 packages, just as a C++ class can have <literal>friend</literal>
653 functions and classes which are allowed special access to a class
654 internals. It is not yet clear whether such cases are sufficiently
655 frequent to warrant introducing such a facility.
656 </para>
657 </sect3>
658
659 <sect3 id="package.source.config">
660 <title>Source Code and Configuration Options</title>
661 <para>
662 Configurability usually involves source code that needs to implement
663 different behavior depending on the settings of configuration
664 options. It is possible to write packages where the only consequence
665 associated with various configuration options is to control what gets
666 built, but this approach is limited and does not allow for
667 fine-grained configurability. There are three main ways in which
668 options could affect source code at build time:
669 </para>
670
671 <orderedlist>
672 <listitem>
673 <para>
674 The component code can be passed through a suitable preprocessor,
675 either an existing one such as <application
676 class="software">m4</application> or a new one specially designed with
677 configurability in mind. The original sources would reside in the
678 component repository and the processed sources would reside in the
679 build tree. These processed sources can then be compiled in the usual
680 way.
681 </para>
682 <para>
683 This approach has two main advantages. First, it is independent from
684 the programming language used to code the components, provided
685 reasonable precautions are taken to avoid syntax clashes between
686 preprocessor statements and actual code. This would make it easier in
687 future to support languages other than C and C++. Second, configurable
688 code can make use of advanced preprocessing facilities such as loops
689 and recursion. The disadvantage is that component writers would have
690 to learn about a new preprocessor and embed appropriate directives in
691 the code. This makes it much more difficult to turn existing code into
692 components, and it involves extra training costs for the component
693 writers.
694 </para>
695 </listitem>
696 <listitem>
697 <para>
698 Compiler optimizations can be used to elide code that should not be
699 present, for example:
700 </para>
701 <programlisting width=72>
702     &hellip;
703     if (CYGHWR_NUMBER_UARTS &gt; 0) {
704         &hellip;
705      }
706     &hellip;
707 </programlisting>
708 <para>
709 If the compiler knows that <varname>CYGHWR_NUMBER_UARTS</varname> is
710 the constant number 0 then it is a trivial operation to get rid of the
711 unnecessary code. The component framework still has to define this
712 symbol in a way that is acceptable to the compiler, typically by using
713 a <literal>const</literal> variable or a preprocessor symbol. In some
714 respects this is a clean approach to configurability, but it has
715 limitations. It cannot be used in the declarations of data structures
716 or classes, nor does it provide control over entire functions. In
717 addition it may not be immediately obvious that this code is affected
718 by configuration options, which may make it more difficult to
719 understand.
720 </para>
721 </listitem>
722 <listitem>
723 <para>
724 Existing language preprocessors can be used. In the case of C or C++
725 this would be the standard C preprocessor, and configurable code would
726 contain a number of <literal>#ifdef</literal> and
727 <literal>#if</literal> statements.
728 </para>
729 <programlisting width=72>
730 #if (CYGHWR_NUMBER_UARTS &gt; 0)
731      &hellip;
732 #endif
733 </programlisting>
734 <para>
735 This approach has the big advantage that the C preprocessor is a
736 technology that is both well-understood and widely used. There are
737 also disadvantages: it is not directly applicable to components
738 written in other languages such as Java (although it is possible to
739 use the C preprocessor as a stand-alone program); the preprocessing
740 facilities are rather limited, for example there is no looping
741 facility; and some people consider the technology to be ugly. Of
742 course it may be possible to get around the second objection by
743 extending the preprocessor that is used by gcc and g++.
744 </para>
745 </listitem>
746 </orderedlist>
747
748 <para>
749 The current component framework generates configuration header files
750 with C preprocessor <literal>#define's</literal> for each option
751 (typically, there various properties which can be used to control
752 this). It is up to component writers to decide whether to use
753 preprocessor <literal>#ifdef</literal> statements or language
754 constructs such as <literal>if</literal>. At present there is no
755 support for languages which do not involve the C preprocessor,
756 although such support can be added in future when the need arises.
757 </para>
758
759 </sect3>
760
761
762 </sect2>
763
764 <!-- }}} -->
765 <!-- {{{ Headers                -->
766
767 <sect2 id="package.headers">
768 <title>Exported Header Files</title>
769
770 <para>
771 A package's exported header files should specify the interface
772 provided by that package, and avoid any implementation details.
773 However there may be performance or other reasons why implementation
774 details occasionally need to be present in the exported headers.
775 </para>
776
777 <note>
778 <para>
779 Not all programming languages have the concept of a header file. In
780 some cases the component framework would need extensions to support
781 packages written in such languages. 
782 </para>
783 </note>
784
785 <para>
786 Configurability has a number of effects on the way exported header
787 files should be written. There may be configuration options which
788 affect the interface of a package, not just the implementation. It is
789 necessary to worry about nested <literal>#include's</literal> and how
790 this affects package and application builds. A special case of this
791 relates to whether or not exported header files should
792 <literal>#include</literal> configuration headers. These configuration
793 headers are exported, but should only be <literal>#include'd</literal>
794 when necessary.
795 </para>
796
797 <sect3 id="package.headers.functions">
798 <title>Configurable Functionality</title>
799
800 <para>
801 Many configuration options affect only the implementation of a
802 package, not the interface. However some options will affect the
803 interface as well, which means that the options have to be tested in
804 the exported header files. Some implementation choices, for example
805 whether or not a particular function should be inlined, also need to
806 be tested in the header file because of language limitations.
807 </para>
808 <para>
809 Consider a configuration option
810 <varname>CYGFUN_KERNEL_MUTEX_TIMEDLOCK</varname> which controls
811 whether or not a function <function>cyg_mutex_timedlock</function> is
812 provided. The exported kernel header file <filename
813 class="headerfile">cyg/kernel/kapi.h</filename> could contain the
814 following:
815 </para>
816
817 <programlisting width=72>
818 #include &lt;pkgconf/kernel.h&gt;
819 &hellip;
820 #ifdef CYGFUN_KERNEL_MUTEX_TIMEDLOCK
821 extern bool cyg_mutex_timedlock(cyg_mutex_t*);
822 #endif
823 </programlisting>
824
825 <para>
826 This is a correct header file, in that it defines the exact interface
827 provided by the package at all times. However is has a number of
828 implications. First, the header file is now dependent on <filename
829 class="headerfile">pkgconf/kernel.h</filename>, so any changes to
830 kernel configuration options will cause <filename
831 class="headerfile">cyg/kernel/kapi.h</filename> to be out of date, and
832 any source files that use the kernel interface will need rebuilding.
833 This may affect sources in the kernel package, in other packages, and
834 in application source code. Second, if the application makes use of
835 this function somewhere but the application developer has
836 misconfigured the system and disabled this functionality anyway then
837 there will now be a compile-time error when building the application.
838 Note that other packages should not be affected, since they should
839 impose appropriate constraints on
840 <varname>CYGFUN_KERNEL_MUTEX_TIMEDLOCK</varname> if they use that
841 functionality (although of course some dependencies like this may get
842 missed by component developers).
843 </para>
844 <para>
845 An alternative approach would be:
846 </para>
847
848 <programlisting width=72>
849 extern bool cyg_mutex_timedlock(cyg_mutex_t*);
850 </programlisting>
851
852 <para>
853 Effectively the header file is now lying about the functionality
854 provided by the package. The first result is that there is no longer a
855 dependency on the kernel configuration header. The second result is
856 that an application file using the timed-lock function will now
857 compile, but the application will fail to link. At this stage the
858 application developer still has to intervene, change the
859 configuration, and rebuild the system. However no application
860 recompilations are necessary, just a relink.
861 </para>
862
863 <para>
864 Theoretically it would be possible for a tool to analyze linker errors
865 and suggest possible configuration changes that would resolve the
866 problem, reducing the burden on the application developer. No such
867 tool is planned in the short term.
868 </para>
869
870 <para>
871 It is up to component writers to decide which of these two approaches
872 should be preferred. Note that it is not always possible to avoid
873 <literal>#include'ing</literal> a configuration header file in an
874 exported one, for example an option may affect a data structure rather
875 than just the presence or absence of a function. Issues like this will
876 vary from package to package.
877 </para>
878
879 </sect3>
880
881 <sect3 id="package.headers.includes">
882 <title>Nested <literal>#include's</literal></title>
883 <para>
884 As a general rule, unnecessary <literal>#include's</literal> should be
885 avoided. A header file should <literal>#include</literal> only those
886 header files which are absolutely needed for it to define its
887 interface. Any additional <literal>#include's</literal> make it more
888 likely that package or application source files become dependent on
889 configuration header files and will get rebuilt unnecessarily when
890 there are minor configuration changes.
891 </para>
892 </sect3>
893
894 <sect3 id="package.headers.configincludes">
895 <title>Including Configuration Headers</title>
896 <para>
897 Exported header files should avoid <literal>#include'ing</literal>
898 configuration header files unless absolutely necessary, to avoid
899 unnecessary rebuilding of both application code and other packages
900 when there are minor configuration changes. A
901 <literal>#include</literal> is needed only when a configuration option
902 affects the exported interface, or when it affects some implementation
903 details which is controlled by the header file such as whether or not
904 a particular function gets inlined.
905 </para>
906 <para>
907 There are a couple of ways in which the problem of unnecessary
908 rebuilding could be addressed. The first would require more
909 intelligent handling of header file dependency handling by the tools
910 (especially the compiler) and the build system. This would require
911 changes to various non-eCos tools. An alternative approach would be to
912 support finer-grained configuration header files, for example there
913 could be a file <filename
914 class="headerfile">pkgconf/libc/inline.h</filename> controlling which
915 functions should be inlined. This could be achieved by some fairly
916 simple extensions to the component framework, but it makes it more
917 difficult to get the package header files and source code correct:
918 a C preprocessor <literal>#ifdef</literal> directive does not
919 distinguish between a symbol not being defined because the option is
920 disabled, or the symbol not being defined because the appropriate
921 configuration header file has not been <literal>#include'd</literal>.
922 It is likely that a cross-referencing tool would have to be developed
923 first to catch problems like this, before the component framework
924 could support finer-grained configuration headers.
925 </para>
926 </sect3>
927
928 </sect2>
929
930 <!-- }}} -->
931 <!-- {{{ Documentation          -->
932
933 <sect2 id="package.documentation">
934 <title>Package Documentation</title>
935 <para>
936 On-line package documentation should be in HTML format. The component
937 framework imposes no special limitations: component writers can decide
938 which version of the HTML specification should be followed; they can
939 also decide on how best to cope with the limitations of different
940 browsers. In general it is a good idea to keep things simple.
941 </para>
942 </sect2>
943
944 <!-- }}} -->
945 <!-- {{{ Tests                  -->
946
947 <sect2 id="package.tests">
948 <title>Test Cases</title>
949 <para>
950 Packages should normally come with one or more test cases. This allows
951 application developers to verify that a given package works correctly
952 on their particular hardware and in their particular configuration,
953 making it slightly more likely that they will attempt to find bugs in
954 their own code rather than automatically blaming the component
955 writers.
956 </para>
957 <para>
958 At the time of writing the application developer support for building
959 and running test cases via the component framework is under review and
960 likely to change. Currently each test case should consist of a single
961 C or C++ source file that can be compiled with the package's set of
962 compiler flags and linked like any application program. Each test case
963 should use the testing API defined by the infrastructure. A
964 magically-named calculated configuration option of the form
965 <varname>CYGPKG_&lt;PACKAGE-NAME&gt;_TESTS</varname> lists the test
966 cases.
967 </para>
968 </sect2>
969
970 <!-- }}} -->
971 <!-- {{{ Host tools             -->
972
973 <sect2 id="package.host">
974 <title>Host-side Support</title>
975 <para>
976 On occasion it would be useful for an &eCos; package to be shipped
977 with host-side support. This could take the form of an additional tool
978 needed to build that package. It could be an application intended to
979 communicate with the target-side package code and display monitoring
980 information. It could be a utility needed for running the package test
981 cases, especially in the case of device drivers. The component
982 framework does not yet provide any such support for host-side
983 software, and there are obvious issues related to portability to the
984 different machines that can be used for hosts. This issue may get
985 addressed in some future release. In some cases custom build steps can
986 be subverted to do things on the host side rather than the target
987 side, but this is not recommended.
988 </para>
989 </sect2>
990
991 <!-- }}} -->
992
993 </sect1>
994
995 <!-- }}} -->
996 <!-- {{{ Package Distributions  -->
997
998 <sect1 id="package.distrib">
999 <title>Making a Package Distribution</title>
1000
1001 <para>
1002 Developers of new &eCos; packages are advised to distribute their
1003 packages in the form of &eCos; package distribution files. Packages
1004 distributed in this format may be added to existing &eCos; component
1005 repositories in a robust manner using the Package Administration Tool.
1006 This chapter describes the format of package distribution files and
1007 details how to prepare an eCos package for distribution in this format.
1008 </para>
1009
1010 <sect2 id="package.distrib.format">
1011 <title>The &eCos; package distribution file format</title>
1012
1013 <para>
1014 eCos package distribution files are gzipped GNU tar archives which
1015 contain both the source code for one or more &eCos; packages and a
1016 data file containing package information to be added to the component
1017 repository database. The distribution files are subject to the
1018 following rules:
1019 </para>
1020 <orderedlist numeration="Loweralpha">
1021 <listitem>
1022 <para>
1023 The data file must be named <filename>pkgadd.db</filename> and must be
1024 located in the root of the tar archive. It must contain data in a
1025 format suitable for appending to the eCos repository database
1026 (<database>ecos.db</database>). <xref linkend="language.database">
1027 describes this data format. Note that a database consistency check is
1028 performed by the &eCos; Administration Tool when
1029 <filename>pkgadd.db</filename> has been appended to the database. Any
1030 new target entries which refer to unknown packages will be removed at
1031 this stage.
1032 </para>
1033 </listitem>
1034 <listitem>
1035 <para>
1036 The package source code must be placed in one or more <filename
1037 class="directory">&lt;package-path&gt;/&lt;version&gt;</filename>
1038 directories in the tar archive, where each &lt;package-path&gt;
1039 directory path is specified as the directory attribute of one of the
1040 packages entries in <filename>pkgadd.db</filename>.
1041 </para>
1042 </listitem>
1043 <listitem>
1044 <para>
1045 An optional license agreement file named
1046 <filename>pkgadd.txt</filename> may be placed in the root of the tar
1047 archive. It should contain text with a maximum line length of 79
1048 characters. If this file exists, the contents will be presented to the
1049 user during installation of the package. The &eCos; Package
1050 Administration Tool will then prompt the user with the question
1051 <prompt>"Do you accept all the terms of the preceding license
1052 agreement?"</prompt>. The user must respond
1053 <userinput>"yes"</userinput> to this prompt in order to proceed with
1054 the installation.
1055 </para>
1056 </listitem>
1057 <listitem>
1058 <para>
1059 Optional template files may be placed in one or more <filename
1060 class="directory">templates/&lt;template_name&gt;</filename>
1061 directories in the tar archive. Note that such template files would be
1062 appropriate only where the packages to be distributed have a complex
1063 dependency relationship with other packages. Typically, a third party
1064 package can be simply added to an eCos configuration based on an
1065 existing core template and the provision of new templates would not be
1066 appropriate. <xref linkend="advanced.templates"> contains more
1067 information on templates.
1068 </para>
1069 </listitem>
1070 <listitem>
1071 <para>
1072 The distribution file must be given a <filename>.epk</filename> (not
1073 <filename>.tar.gz</filename>) file extension. The
1074 <filename>.epk</filename> file extension serves to distinguish &eCos;
1075 package distributions files from generic gzipped GNU tar archives. It
1076 also discourages users from attempting to extract the package from the
1077 archive manually. The file browsing dialog of the &eCos; Package
1078 Administration Tool lists only those files which have a
1079 <filename>.epk</filename> extension.
1080 </para>
1081 </listitem>
1082 <listitem>
1083 <para>
1084 No other files should be present in the archive.
1085 </para>
1086 </listitem>
1087 <listitem>
1088 <para>
1089 Files in the tar archive may use <literal>LF</literal> or
1090 <literal>CRLF</literal> line endings interchangably. The &eCos;
1091 Administration Tool ensures that the installed files are given the
1092 appropriate host-specific line endings.
1093 </para>
1094 </listitem>
1095 <listitem>
1096 <para>
1097 Binary files may be placed in the archive, but the distribution of
1098 object code is not recommended. All binary files must be given a
1099 <literal>.bin</literal> suffix in addition to any file extension they
1100 may already have. For example, the GIF image file
1101 <filename>myfile.gif</filename> must be named
1102 <filename>myfile.gif.bin</filename> in the archive. The
1103 <filename>.bin</filename> suffix is removed during file extraction and
1104 is used to inhibit the manipulation of line endings by the &eCos;
1105 Administration Tool.
1106 </para>
1107 </listitem>
1108 </orderedlist>
1109 </sect2>
1110
1111 <sect2 id="package.distrib.prepare">
1112 <title>Preparing eCos packages for distribution</title>
1113
1114 <para>
1115 Development of new &eCos; packages or new versions of existing &eCos;
1116 packages will take place in the context of an existing &eCos;
1117 component repository. This section details the steps involved in
1118 extracting new packages from a repository and generating a
1119 corresponding &eCos; package distribution file for distribution of the
1120 packages to other &eCos; users. The steps required are as follows:
1121 </para>
1122
1123 <orderedlist numeration="Loweralpha">
1124 <listitem>
1125 <para>
1126 Create a temporary directory <filename
1127 class="directory">$PKGTMP</filename> for manipulation of the package
1128 distribution file contents and copy the source files of the new
1129 packages into this directory, preserving the relative path to the
1130 package. In the case of a new package at <filename
1131 class="directory">mypkg/current</filename> in the repository:
1132 </para>
1133 <screen width=72>
1134     $ mkdir -p $PKGTMP/mypkg
1135     $ cp -p -R $ECOS_REPOSITORY/mypkg/current $PKGTMP/mypkg
1136 </screen>
1137 <para>
1138 Where more than one package is to be distributed in a single package
1139 distribution file, copy each package in the above manner. Note that
1140 multiple packages distributed in a single package distribution file
1141 cannot be installed separately. Where such flexibility is required,
1142 distribution of each new package in separate package distribution files
1143 is recommended.
1144 </para>
1145 </listitem>
1146 <listitem>
1147 <para>
1148 Copy any template files associated with the distributed packages into
1149 the temporary directory, preserving the relative path to the template.
1150 For example:
1151 </para>
1152 <screen width=72>
1153     $ mkdir -p $PKGTMP/templates
1154     $ cp -p -R $ECOS_REPOSITORY/templates/mytemplate $PKGTMP/templates
1155 </screen>
1156 </listitem>
1157 <listitem>
1158 <para>
1159 Remove any files from the temporary directory hierarchy which you do
1160 not want to distribute with the packages (eg object files, <filename
1161 class="directory">CVS</filename> directories).
1162 </para>
1163 </listitem>
1164 <listitem>
1165 <para>
1166 Add a <filename>.bin</filename> suffix to the name of any binary
1167 files. For example, if the packages contains GIF image files (*.gif)
1168 for documentation purposes, such files must be renamed to *.gif.bin as
1169 follows:
1170 </para>
1171 <screen width=72>
1172    $ find $PKGTMP -type f -name '*.gif' -exec mv {} {}.bin ';'
1173 </screen>
1174 <para>
1175 The <filename>.bin</filename> suffix is removed during file extraction
1176 and is used to inhibit the manipulation of line endings by the eCos
1177 Package Administration Tool.
1178 </para>
1179 </listitem>
1180 <listitem>
1181 <para>
1182 Extract the package records for the new packages from the package
1183 database file at <database>$ECOS_REPOSITORY/ecos.db</database> and
1184 create a new file containing these records at
1185 <filename>$PKGTMP/pkgadd.db</filename> (in the root of the temporary
1186 directory hierarchy). Any target records which reference the
1187 distributed packages must also be provided in pkgadd.db.
1188 </para>
1189 </listitem>
1190 <listitem>
1191 <para>
1192 Rename the version directories under <filename
1193 class="directory">$PKGTMP</filename> (typically <filename
1194 class="directory">current</filename> during development) to reflect
1195 the versions of the packages you are distributing. For example,
1196 version 1.0 of a package may use the version directory name <filename
1197 class="directory">v1_0</filename>:
1198 </para>
1199 <screen width=72>
1200     $ cd $PKGTMP/mypkg
1201     $ mv current v1_0
1202 </screen>
1203 <para>
1204 <xref linkend="package.versions"> describes the version naming
1205 conventions.
1206 </para>
1207 </listitem>
1208 <listitem>
1209 <para>
1210 Rename any template files under <filename
1211 class="directory">$PKGTMP</filename> (typically
1212 <filename>current.ect</filename> during development) to reflect the
1213 version of the template you are distributing. For example, version 1.0
1214 of a template may use the filename <filename>v1_0.ect</filename>:
1215 </para>
1216 <screen width=72>
1217     $ cd $PKGTMP/templates/mytemplate
1218     $ mv current.ect v1_0.ect
1219 </screen>
1220 <para>
1221 It is also important to edit the contents of the template file, changing
1222 the version of each referenced package to match that of the packages you
1223 are distributing. This step will eliminate version warnings during the
1224 subsequent loading of the template.
1225 </para>
1226 </listitem>
1227 <listitem>
1228 <para>
1229 Optionally create a licence agreement file at
1230 <filename>$PKGTMP/pkgadd.txt</filename> containing the licensing terms
1231 under which you are distributing the new packages. Limit each line in
1232 this file to a maximum of 79 characters.
1233 </para>
1234 </listitem>
1235 <listitem>
1236 <para>
1237 Create a GNU tar archive of the temporary directory hierarchy. By
1238 convention, this archive would have a name of the form
1239 <filename>&lt;package_name&gt;-&lt;version&gt;</filename>:
1240 </para>
1241 <screen width=72>
1242     $ cd $PKGTMP
1243     $ tar cf mypkg-1.0.tar *
1244 </screen>
1245 <para>
1246 Note that non-GNU version of tar may create archive files which exhibit
1247 subtle incompatibilities with GNU tar. For this reason, always use GNU
1248 tar to create the archive file.
1249 </para>
1250 </listitem>
1251 <listitem>
1252 <para>
1253 Compress the archive using gzip and give the resulting file a
1254 <filename>.epk</filename> file extension:
1255 </para>
1256 <screen width=72>
1257     $ gzip mypkg-1.0.tar
1258     $ mv mypkg-1.0.tar.gz mypkg-1.0.epk
1259 </screen>
1260 <para>
1261 The resulting eCos package distribution file (*.epk) is in a compressed
1262 format and may be distributed without further compression.
1263 </para>
1264 </listitem>
1265 </orderedlist>
1266
1267 </sect2>
1268
1269 </sect1>
1270
1271 <!-- }}} -->
1272
1273 </chapter>