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