OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [libcdl/] [doc/] [build.sgml] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
2
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
33
34
 
35
36
The Build Process
37
 
38
39
 
40
41
Some &CDL; properties describe the consequences of manipulating
42
configuration options. There are two main types of consequences.
43
Typically enabling a configuration option results in one or more
44
#define's in a configuration header file, and
45
properties that affect this include &define;, &define-proc; and
46
&no-define;. Enabling a configuration option can also affect the build
47
process, primarily determining which files get built and added to the
48
appropriate library. Properties related to the build process include
49
&compile; and &make;. This chapter describes the whole build process,
50
including details such as compiler flags and custom build steps.
51
52
53
Part of the overall design of the &eCos; component framework is that
54
it can interact with a number of different build systems. The most
55
obvious of these is GNU
56
make:the component framework can generate one or more
57
makefiles, and the user can then build the various packages simply by
58
invoking make. However it
59
should also be possible to build &eCos; by other means: the
60
component framework can be queried about what is involved in building
61
a given configuration, and this information can then be fed into the
62
desired build system. Component writers should be aware of this
63
possibility. Most packages will not be affected because the &compile;
64
property can be used to provide all the required information, but care
65
has to be taken when writing custom build steps.
66
67
 
68
69
70
 
71
72
Build Tree Generation
73
 
74
75
It is necessary to create an &eCos; configuration before anything can
76
be built. With some tools such as the graphical configuration tool
77
this configuration will be created in memory, and it is not essential
78
to produce an ecos.ecc savefile first (although
79
it is still very desirable to generate such a savefile at some point,
80
to allow the configuration to be re-loaded later on). With other tools
81
the savefile is generated first, for example using
82
ecosconfig new, and then a build tree is
83
generated using ecosconfig tree. The savefile
84
contains all the information needed to recreate a configuration.
85
86
87
An &eCos; build actually involves three separate trees. The component
88
repository acts as the source tree, and for application developers
89
this should be considered a read-only resource. The build tree is
90
where all intermediate files, especially object files, are created.
91
The install tree is where the main library
92
libtarget.a, the exported header files, and
93
similar files end up. Following a successful build it is possible to
94
take just the install tree and use it for developing an application:
95
none of the files in the component repository or the build tree are
96
needed for that. The build tree will be needed again only if the user
97
changes the configuration. However the install tree does not contain
98
copies of all of the documentation for the various packages, instead
99
the documentation is kept only in the component repository.
100
101
102
By default the build tree, the install tree, and the
103
ecos.ecc savefile all reside in the same
104
directory tree. This is not a requirement, both the install tree and
105
the savefile can be anywhere in the file system.
106
107
108
It is worth noting that the component framework does not separate the
109
usual make and make install
110
stages. A build always populates the install tree, and any
111
make install step would be redundant.
112
113
114
The install tree will always begin with two directories, 
115
class="directory">include for the exported header files and
116
lib for the main library
117
libtarget.a and other files
118
such as the linker script. In addition there will be a subdirectory
119
include/pkgconf containing the
120
configuration header files, which are generated or updated at the same
121
time the build tree is created or updated. More details of header file
122
generation are given below. Additional 
123
class="directory">include subdirectories such as 
124
class="directory">sys and 
125
class="directory">cyg/kernel will be created during the
126
first build, when each package's exported header files are copied to
127
the install tree. The install tree may also end up with additional
128
subdirectories during a build, for example as a result of custom build
129
steps.
130
131
132
The component framework does not define the structure of the build
133
tree, and this may vary between build systems. It can be assumed that
134
each package in the configuration will have its own directory in the
135
build tree, and that this directory will be used for storing the
136
package's object files and as the current directory for any build
137
steps for that package. This avoids problems when custom build steps
138
from different packages generate intermediate files which happen to
139
have the same name.
140
141
142
Some build systems may allow application developers to copy a source
143
file from the component repository to the build tree and edit the
144
copy. This allows users to experiment with small changes, for example
145
to add a couple of lines of debugging to a package, without having to
146
modify the master copy in the component repository which could be
147
shared by several projects or several people. Functionality such as
148
this is transparent to component writers, and it is the responsibility
149
of the build system to make sure that the right thing happens.
150
151
 
152
153
154
There are some unresolved issues related to the build tree and install
155
tree. Specifically, when updating an existing build or install tree,
156
what should happen to unexpected files or directories? Suppose the
157
user started with a configuration that included the math library, and
158
the install tree contains header files 
159
class="headerfile">include/math.h and 
160
class="headerfile">include/sys/ieeefp.h. The user then removed
161
the math library from the configuration and is updating the build
162
tree. It is now desirable to remove these header files from the
163
install tree, so that if any application code still attempts to use
164
the math library this will fail at compile time rather than at link
165
time. There will also be some object files in the existing
166
libtarget.a library which are no longer
167
appropriate, and there may be other files in the install tree as a
168
result of custom build steps. The build tree will still contain a
169
directory for the math library, which no longer serves any purpose.
170
171
172
However, it is also possible that some of the files in the build tree
173
or the install tree were placed there by the user, in which case
174
removing them automatically would be a bad idea.
175
176
177
At present the component framework does not keep track of exactly what
178
should be present in the build and install trees, so it cannot readily
179
determine which files or library members are obsolete and can safely
180
be removed, and which ones are unexpected and need to be reported to
181
the user. This will be addressed in a future release of the system.
182
183
184
 
185
186
 
187
188
189
 
190
191
Configuration Header File Generation
192
 
193
194
Configuration options can affect a build in two main ways. First,
195
enabling a configuration option or other &CDL; entity can result in
196
various files being built and added to a library, thus providing
197
functionality to the application code. However this mechanism can only
198
operate at a rather coarse grain, at the level of entire source files.
199
Hence the component framework also generates configuration header
200
files containing mainly C preprocessor #define
201
directives. Package source code can then #include
202
the appropriate header files and use #if,
203
#ifdef and #ifndef directives to
204
adapt accordingly. In this way configuration options can be used to
205
enable or disable entire functions within a source file or just a
206
single line, whichever is appropriate.
207
208
209
The configuration header files end up in the 
210
class="directory">include/pkgconf subdirectory of the
211
install tree. There will be one header file for the system as a whole,
212
pkgconf/system.h, and there will
213
be additional header files for each package, for example
214
pkgconf/kernel.h. The header files
215
are generated when creating or updating the build and install trees,
216
which needs to happen after every change to the configuration.
217
218
219
The component framework processes each package in the configuration
220
one at a time. The exact order in which the packages are processed is
221
not defined, so the order in which #define's will
222
end up in the global 
223
class="headerfile">pkgconf/system.h header may vary. However
224
for any given configuration the order should remain consistent until
225
packages are added to or removed from the system. This avoids
226
unnecessary changes to the global header file and hence unnecessary
227
rebuilds of the packages and of application code because of header
228
file dependency handling.
229
230
231
Within a given package the various components, options and interfaces
232
will be processed in the order in which they were defined in the
233
corresponding &CDL; scripts. Typically the data in the configuration
234
headers consists only of a sequence of #define's so
235
the order in which these are generated is irrelevant, but some
236
properties such as &define-proc; can be used to add arbitrary data to
237
a configuration header and hence there may be dependencies on the
238
order. It should be noted that re-parenting an option below some other
239
package has no effect on which header file will contain the
240
corresponding #define: the preprocessor directives
241
will always end up in the header file for the package that defines the
242
option, or in the global configuration header.
243
244
245
There are six properties which affect the process of generating header
246
files:
247
&define-header;,
248
&no-define;,
249
&define-format;,
250
&define;,
251
&if-define;, and
252
&define-proc;.
253
254
255
The &define-header; property can only occur in the body of a
256
&cdl-package; command and specifies the name of the header file which
257
should contain the package's configuration data, for example:
258
259
260
cdl_package <some_package> {
261
262
    define_header xyzzy.h
263
}
264
265
266
Given such a &define-header; property the component framework will
267
use the file pkgconf/xyzzy.h for
268
the package's configuration data. If a package does not have
269
a &define-header; property then a suitable file name is constructed
270
from the package's name. This involves:
271
272
273
274
275
All characters in the package name up to and including the first
276
underscore are removed. For example CYGPKG_KERNEL
277
is converted to KERNEL, and
278
CYGPKG_HAL_ARM is converted to
279
HAL_ARM.
280
281
282
283
284
Any upper case letters in the resulting string will be converted to
285
lower case, yielding e.g. kernel and
286
hal_arm.
287
288
289
290
291
A .h suffix is appended, yielding e.g.
292
kernel.h and hal_arm.h.
293
294
295
296
297
Because of the naming restrictions on configuration options, this
298
should result in a valid filename. There is a small possibility of a
299
file name class, for example CYGPKG_PLUGH and
300
CYGPKG_plugh would both end up trying to use the
301
same header file pkgconf/plugh.h,
302
but the use of lower case letters for package names violates the
303
naming conventions. It is not legal to use the &define-header;
304
property to put the configuration data for several packages in a
305
single header file. The resulting behaviour is undefined.
306
307
308
Once the name of the package's header file has been determined and the
309
file has been opened, the various components, options and interfaces
310
in the package will be processed starting with the package itself. The
311
following steps are involved:
312
313
314
315
316
If the current option or other &CDL; entity is inactive or disabled,
317
the option is ignored for the purposes of header file generation.
318
#define's are only generated for options that are
319
both active and enabled.
320
321
322
323
324
The next step is to generate a default #define for
325
the current option. If this option has a &no-define; property then the
326
default #define is suppressed, and processing
327
continues for &define;, &if-define; and &define-proc; properties.
328
329
330
331
332
The header file appropriate for the default #define
333
is determined. For a &cdl-package; this will be 
334
class="headerfile">pkgconf/system.h, for any other option this
335
will be the package's own header file. The intention here is that
336
packages and application code can always determine which packages are
337
in the configuration by #include'ing 
338
class="headerfile">pkgconf/system.h. The C preprocessor lacks
339
any facilities for including a header file only if it exists, and
340
taking appropriate action otherwise.
341
342
343
344
345
For options with the flavors bool or
346
none, a single #define will be
347
generated. This takes the form:
348
349
350
#define <option> 1
351
352
353
For example:
354
355
356
#define CYGFUN_LIBC_TIME_POSIX 1
357
358
359
Package source code can check whether or not an option is active and
360
enabled by using the #ifdef,
361
#ifndef or #if
362
defined(…)directives.
363
364
365
366
367
For options with the flavors data or
368
booldata, either one or two
369
#define's will be generated. The first of these may
370
be affected by a &define-format; property. If this property is not
371
defined then the first #define will take the form:
372
373
374
#define <option> <value>
375
376
377
For example:
378
379
380
#define CYGNUM_LIBC_ATEXIT_HANDLERS 32
381
382
383
Package source code can examine this value using the
384
#if directive, or by using the symbol in
385
code such as:
386
387
388
    for (i = 0; i < CYGNUM_LIBC_ATEXIT_HANDLERS; i++) {
389
390
    }
391
392
393
It must be noted that the #define will be generated
394
only if the corresponding option is both active and enabled. Options
395
with the data flavor are always enabled but may not
396
be active. Code like the above should be written only if it is known
397
that the symbol will always be defined, for example if the
398
corresponding source file will only get built if the containing
399
component is active and enabled. Otherwise the use of additional
400
#ifdef or similar directives will be necessary.
401
402
403
404
405
If there is a &define-format; property then this controls how the
406
option's value will appear in the header file. Given a format string
407
such as %08x and a value 42, the component
408
framework will execute the &Tcl; command
409
format %08x 42 and the result will be
410
used for the #define's value. It is the
411
responsibility of the component writer to make sure that this &Tcl;
412
command will be valid given the format string and the legal values for
413
the option.
414
415
416
417
418
In addition a second #define may or may not be
419
generated. This will take the form:
420
421
422
#define <option>_<value>
423
424
425
For example:
426
427
428
#define CYGNUM_LIBC_ATEXIT_HANDLERS_32
429
430
431
The #define will be generated only if it would
432
result in a valid C preprocessor symbol. If the value is a string such
433
as "/dev/ser0" then the #define
434
would be suppressed. This second #define is not
435
particularly useful for numerical data, but can be valuable in other
436
circumstances. For example if the legal values for an option
437
XXX_COLOR are red,
438
green and blue then code like
439
the following can be used:
440
441
442
#ifdef XXX_COLOR_red
443
444
#endif
445
#ifdef XXX_COLOR_green
446
447
#endif
448
#ifdef XXX_COLOR_blue
449
450
#endif
451
452
453
The expression syntax provided by the C preprocessor is limited to
454
numerical data and cannot perform string comparisons. By generating
455
two #define's in this way it is possible to work
456
around this limitation of the C preprocessor. However some care has to
457
be taken: if a component writer also defined a configuration option
458
XXX_COLOR_green then there will be confusion. Since
459
such a configuration option violates the naming conventions, the
460
problem is unlikely to arise in practice.
461
462
463
464
465
 
466
467
468
For some options it may be useful to generate one or more additional
469
#define's or, in conjunction with the &no-define;
470
property, to define a symbol with a name different from the option's
471
name. This can be achieved with the &define; property, which takes the
472
following form:
473
474
475
    define [-file=<filename>] [-format=<format>] <symbol>
476
477
478
For example:
479
480
481
    define FOPEN_MAX
482
483
484
This will result in something like:
485
486
487
#define FOPEN_MAX 8
488
#define FOPEN_MAX_8
489
490
491
The specified symbol must be a valid C preprocessor symbol. Normally
492
the #define will end up in the same header file as
493
the default one, in other words 
494
class="headerfile">pkgconf/system.h in the case of a
495
&cdl-package;, or the package's own header file for any other option.
496
The -file option can be used to change this. At
497
present the only legal value is system.h, for
498
example:
499
500
501
    define -file=system.h <symbol>
502
503
504
This will cause the #define to end up in the global
505
configuration header rather than in the package's own header. Use of
506
this facility should be avoided since it is very rarely necessary to
507
make options globally visible.
508
509
510
The &define; property takes another option,
511
-format, to provide a format string.
512
513
514
    define -format=%08x <symbol>
515
516
517
This should only be used for options with the data
518
or booldata flavor, and has the same effect as the
519
&define-format; property has on the default
520
#define.
521
522
523
&define; properties are processed in the same way the default
524
#define. For options with the
525
bool or none flavors a single
526
#define will be generated using the value
527
1. For options with the data or
528
booldata flavors either one or two
529
#define's will be generated.
530
531
532
 
533
534
535
After processing all &define; properties, the component framework will
536
look for any &if-define; properties. These take the following form:
537
538
539
    if_define [-file=<filename>] <symbol1> <symbol2>
540
541
542
For example:
543
544
545
    if_define CYGSRC_KERNEL CYGDBG_USE_ASSERTS
546
547
548
The following will be generated in the configuration header file:
549
550
551
#ifdef CYGSRC_KERNEL
552
# define CYGDBG_USE_ASSERTS
553
#endif
554
555
556
Typical kernel source code would begin with the following construct:
557
558
559
#define CYGSRC_KERNEL 1
560
#include <pkgconf/kernel.h>
561
#include <cyg/infra/cyg_ass.h>
562
563
564
The infrastructure header file 
565
class="headerfile">cyg/infra/cyg_ass.h only checks for symbols
566
such as CYGDBG_USE_ASSERTS, and has no special
567
knowledge of the kernel or any other package. The &if-define; property
568
will only affect code that defines the symbol
569
CYGSRC_KERNEL, so typically only kernel source
570
code. If the option is enabled then assertion support will be enabled
571
for the kernel source code only. If the option is inactive or disabled
572
then kernel assertions will be disabled. Assertions in other packages
573
are not affected. Thus the &if-define; property allows control over
574
assertions, tracing, and similar facilities at the level of individual
575
packages, or at finer levels such as components or even single source
576
files if desired.
577
578
579
580
Current &eCos; packages do not yet make use of this facility. Instead
581
there is a single global configuration option
582
CYGDBG_USE_ASSERTS which is used to enable or
583
disable assertions for all packages. This issue should be addressed in
584
a future release of the system.
585
586
587
588
As with the &define; property, the &if-define; property takes an
589
option -file with a single legal value
590
system.h. This allows the output to be redirected
591
to pkgconf/system.h if and when
592
necessary.
593
594
595
 
596
597
598
The final property that is relevant to configuration header file
599
generation is &define-proc;. This takes a single argument, a &Tcl;
600
fragment that can add arbitrary data to the global header 
601
class="headerfile">pkgconf/system.h and to the package's own
602
header. When the &define-proc; script is invoked two variables will be
603
set up to allow access to these headers: cdl_header
604
will be a channel to the package's own header file, for example
605
pkgconf/kernel.h;
606
cdl_system_header will be a channel to 
607
class="headerfile">pkgconf/system.h. A typical &define-proc;
608
script will use the &Tcl; puts command to output
609
data to one of these channels, for example:
610
611
612
cdl_option <name> {
613
614
    define_proc {
615
        puts $::cdl_header "#define XXX 1"
616
    }
617
}
618
619
620
621
In the current implementation the use of &define-proc; is limited
622
because the &Tcl; script cannot access any of the configuration data.
623
Therefore the script is limited to writing constant data to the
624
configuration headers. This is a major limitation which will be
625
addressed in a future release of the component framework.
626
627
628
 
629
630
 
631
632
 
633
634
635
Generating C header files with #define's for the
636
configuration data suffices for existing packages written in some
637
combination of C, C++ and assembler. It can also be used in
638
conjunction with some other languages, for example by first passing
639
the source code through the C preprocessor and feeding the result into
640
the appropriate compiler. In future versions of the component
641
framework additional programming languages such as Java may be
642
supported, and the configuration data may also be written to files in
643
some format other than C preprocessor directives.
644
645
646
 
647
648
649
At present there is no way for application or package source code to
650
get hold of all the configuration details related to the current
651
hardware. Instead that information is spread over various different
652
configuration headers for the HAL and device driver packages, with
653
some of the information going into 
654
class="headerfile">pkgconf/system.h. It is possible that in
655
some future release of the system there will be another global
656
configuration header file 
657
class="headerfile">pkgconf/hardware.h which either contains the
658
configuration details for the various hardware-specific packages or
659
which #include's all the hardware-specific
660
configuration headers. The desirability and feasibility of such a
661
scheme are still to be determined. To avoid future incompatibility
662
problems as a result of any such changes, it is recommended that all
663
hardware packages (in other packages containing the &hardware;
664
property) use the &define-header; property to specify explicitly which
665
configuration header should be generated.
666
667
668
 
669
670
The <filename class="headerfile">system.h</filename> Header
671
 
672
673
Typically configuration header files are #include'd
674
only by the package's source code at build time, or by a package's
675
exported header files if the interface provided by the package may be
676
affected by a configuration option. There should be no need for
677
application code to know the details of individual configuration
678
options, instead the configuration should specifically meet the needs
679
of the application.
680
681
682
There are always exceptions. Application code may want to adapt to
683
configuration options, for example to do different things for ROM and
684
RAM booting systems, or when it is necessary to support several
685
different target boards. This is especially true if the code in question
686
is really re-usable library code which has not been converted to an
687
eCos package, and hence cannot use any CDL facilities.
688
689
690
A major problem here is determining which packages are in the
691
configuration: attempting to #include a header file
692
such as pkgconf/net.h
693
when it is not known for certain that that particular package is part
694
of the configuration will result in compilation errors. The global
695
header file pkgconf/system.h
696
serves to provide such information, so application code can use
697
techniques like the following:
698
699
 
700
701
#include <pkgconf/system.h>
702
#ifdef CYGPKG_NET
703
# include <pkgconf/net.h>
704
#endif
705
706
 
707
708
This will compile correctly irrespective of the eCos configuration,
709
and subsequent code can use #ifdef or similar
710
directives on CYGPKG_NET or any of the
711
configuration options in that package.
712
713
714
In addition to determining whether or not a package is present, the
715
global configuration header file can also be used to find out the
716
specific version of a package that is being used. This can be useful
717
if a more recent version exports additional functionality. It may also
718
be necessary to adapt to incompatible changes in the exported
719
interface or to changes in behaviour. For each package the
720
configuration system will typically #define three
721
symbols, for example for a V1.3.1 release:
722
723
724
#define CYGNUM_NET_VERSION_MAJOR 1
725
#define CYGNUM_NET_VERSION_MINOR 3
726
#define CYGNUM_NET_VERSION_RELEASE 1
727
728
729
There are a number of problems associated with such version
730
#define's. The first restriction is that the
731
package must follow the standard naming conventions, so the package
732
name must be of the form xxxPKG_yyy. The three
733
characters immediately preceding the first underscore must be
734
PKG, and will be replaced with
735
NUM when generating the version
736
#define's. If a package does not follow the naming
737
convention then no version #define's will be
738
generated.
739
740
741
Assuming the package does follow the naming conventions, the
742
configuration tools will always generate three version
743
#define's for the major, minor, and release
744
numbers. The symbol names are obtained from the package name by
745
replacing PKG with NUM and
746
appending _VERSION_MAJOR,
747
_VERSION_MINOR and
748
_VERSION_RELEASE. It is assumed that the resulting
749
symbols will not clash with any configuration option names. The values
750
for the #define's are determined by searching the
751
version string for sequences of digits, optionally preceded by a minus
752
sign. It is possible that some or all of the numbers are absent in any
753
given version string, in which case -1 will be used
754
in the #define. For example, given a version string
755
of V1.12beta, the major version number is
756
1, the minor number is 12, and
757
the release number is -1. Given a version string of
758
beta all three numbers would be set to
759
-1.
760
761
762
There is special case code for the version current,
763
which typically corresponds to a development version obtained via
764
anonymous CVS or similar means. The configuration system has special
765
built-in knowledge of this version, and will assume it is more recent
766
than any specific release number. The global configuration header
767
defines a special symbol CYGNUM_VERSION_CURRENT,
768
and this will be used as the major version number when version
769
current of a package is used:
770
771
772
#define CYGNUM_VERSION_CURRENT 0x7fffff00
773
...
774
#define CYGNUM_INFRA_VERSION_MAJOR CYGNUM_VERSION_CURRENT
775
#define CYGNUM_INFRA_VERSION_MINOR -1
776
#define CYGNUM_INFRA_VERSION_RELEASE -1
777
778
 
779
780
The large number used for CYGNUM_VERSION_CURRENT
781
should ensure that major version comparisons work as expected, while
782
still allowing for a small amount of arithmetic in case that proves
783
useful.
784
785
786
It should be noted that this implementation of version
787
#define's will not cope with all version number
788
schemes. However for many cases it should suffice.
789
790
 
791
792
 
793
794
 
795
796
797
 
798
799
Building eCos
800
 
801
802
 
803
804
The primary goal of an eCos build is to produce the library
805
libtarget.a. A typical &eCos; build will also
806
generate a number of other targets: extras.o,
807
startup code vectors.o, and a linker script. Some
808
packages may cause additional libraries or targets to be generated.
809
The basic build process involves a number of different phases with
810
corresponding priorities. There are a number of predefined priorities:
811
812
813
814
815
816
817
  
818
    Priority
819
    Action
820
  
821
822
823
  
824
    0
825
    Export header files
826
  
827
  
828
    100
829
    Process &compile; properties
830
  
831
  
832
     
833
    and most &make-object; custom build steps
834
  
835
  
836
    200
837
    Generate libraries
838
  
839
  
840
    300
841
    Process &make; custom build steps
842
  
843
844
845
846
 
847
848
Generation of the extras.o file, the startup code
849
and the linker script actually happens via &make; custom build steps,
850
typically defined in appropriate HAL packages. The component framework
851
has no special knowledge of these targets.
852
853
854
By default custom build steps for a &make-object; property happen
855
during the same phase as most compilations, but this can be changed
856
using a -priority option. Similarly custom build
857
steps for a &make; property happen at the end of a build, but this can
858
also be changed with a -priority option. For
859
example a priority of 50 can be used to run a custom build step
860
between the header file export phase and the main compilation phase.
861
Custom build steps are discussed in more detail below.
862
863
864
Some build systems may run several commands of the same priority in
865
parallel. For example files listed in &compile; properties may get
866
compiled in parallel, concurrently with &make-object; custom build
867
steps with default priorities. Since most of the time for an &eCos;
868
build involves processing &compile; properties, this allows builds to
869
be speeded up on suitable host hardware. All build steps for a given
870
phase will complete before the next phase is started.
871
872
 
873
874
875
 
876
877
Updating the Build Tree
878
 
879
880
Some build systems may involve a phase before the header files get
881
exported, to update the build and install trees automatically when
882
there has been a change to the configuration savefile
883
ecos.ecc. This is useful mainly for application
884
developers using the command line tools: it would allow users to
885
create the build tree only once, and after any subsequent
886
configuration changes the tree would be updated automatically by the
887
build system. The facility would be analogous to the
888
--enable-maintainer-mode option provide by the
889
autoconf and 
890
class="software">automake programs. At present no &eCos;
891
build system implements this functionality, but it is likely to be
892
added in a future release.
893
894
 
895
896
 
897
898
899
 
900
901
Exporting Public Header Files
902
 
903
904
The first compulsory phase involves making sure that there is an up to
905
date set of header files in the install tree. Each package can contain
906
some number of header files defining the exported interface.
907
Applications should only use exported functionality. A package can
908
also contain some number of private header files which are only of
909
interest to the implementation, and which should not be visible to
910
application code. The various packages that go into a particular
911
configuration can be spread all over the component repository. In
912
theory it might be possible to make all the exported header files
913
accessible by having a lengthy -I header file
914
search path, but this would be inconvenient both for building eCos and
915
for building applications. Instead all the relevant header files are
916
copied to a single location, the 
917
class="directory">include subdirectory of the install tree.
918
The process involves the following:
919
920
 
921
922
923
924
The install tree, for example 
925
class="directory">/usr/local/ecos/install, and its 
926
class="directory">include subdirectory 
927
class="directory">/usr/local/ecos/install/include will typically be
928
created when the build tree is generated or updated. At the same time
929
configuration header files will be written to the 
930
class="directory">pkgconf subdirectory, for example
931
932
class="directory">/usr/local/ecos/include/pkgconf, so that
933
the configuration data is visible to all the packages and to
934
application code that may wish to examine some of the configuration
935
options.
936
937
938
939
940
Each package in the configuration is examined for exported header
941
files. The exact order in which the packages are processed is not
942
defined, but should not matter.
943
944
945
946
947
If the package has an 
948
linkend="ref.include-files">&include-files; property then this
949
lists all the exported header files:
950
951
952
cdl_package <some_package> {
953
954
    include_files header1.h header2.h
955
}
956
957
958
If no arguments are given then the package does not export any header
959
files.
960
961
962
cdl_package <some_package> {
963
964
    include_files
965
}
966
967
968
The listed files may be in an 
969
class="directory">include subdirectory within the package's
970
hierarchy, or they may be relative to the package's toplevel
971
directory. The &include-files; property is intended mainly for very
972
simple packages. It can also be useful when converting existing code
973
to an &eCos; package, to avoid rearranging the sources.
974
975
976
977
978
If there is no &include-files; property then the component framework
979
will look for an include
980
subdirectory in the package, as per the layout conventions. All files,
981
including those in subdirectories, will be treated as exported header
982
files. For example, the math library package contains files 
983
class="headerfile">include/math.h and 
984
class="headerfile">include/sys/ieeefp.h, both of which will
985
be exported to the install tree.
986
987
988
989
990
As a last resort, if there is neither an &include-files; property nor
991
an include subdirectory, the
992
component framework will search the package's toplevel directory and
993
all of its subdirectories for files with one of the following
994
suffixes: .h, .hxx,
995
.inl or .inc. All such files
996
will be interpreted as exported header files.
997
998
999
This last resort rule could cause confusion for packages which have no
1000
exported header files but which do contain one or more private header
1001
files. For example a typical device driver simply implements an
1002
existing interface rather than define a new one, so it does not need
1003
to export a header file. However it may still have one or more private
1004
header files. Such packages should use an &include-files; property
1005
with no arguments.
1006
1007
1008
1009
1010
1011
1012
If the package has one or more exported header files, the next step is
1013
to determine where the files should end up. By default all exported
1014
header files will just end up relative to the install tree's 
1015
class="directory">include subdirectory. For example the
1016
math library's math.h header
1017
would end up as /usr/local/ecos/include/math.h,
1018
and the sys/ieeefp.h header
1019
would end up as
1020
/usr/local/ecos/include/sys/ieeefp.h. This
1021
behaviour is correct for packages like the C library where the
1022
interface is defined by appropriate standards. For other packages this
1023
behaviour can lead to file name clashes, and the 
1024
linkend="ref.include-dir">&include-dir; property should be used
1025
to avoid this:
1026
1027
1028
cdl_package CYGPKG_KERNEL {
1029
    include_dir cyg/kernel
1030
}
1031
1032
1033
This means that the kernel's exported header file
1034
include/kapi.h should be copied to
1035
/usr/local/ecos/include/cyg/kernel/kapi.h, where
1036
it is very unlikely to clash with a header file from some other
1037
package.
1038
1039
1040
1041
1042
For typical application developers there will be little or no need for
1043
the installed header files to change after the first build. Changes
1044
will be necessary only if packages are added to or removed from the
1045
configuration. For component writers, the build system should detect
1046
changes to the master copy of the header file source code and update
1047
the installed copies automatically during the next build. The build
1048
system is expected to perform a header file dependency analysis, so
1049
any source files affected should get rebuilt as well.
1050
1051
1052
1053
1054
Some build systems may provide additional support for application
1055
developers who want to make minor changes to a package, especially for
1056
debugging purposes. A header file could be copied from the
1057
component repository (which for application developers is assumed to
1058
be a read-only resource) into the build tree and edited there. The
1059
build system would detect a more recent version of such a header file
1060
in the build tree and install it. Care would have to be taken to
1061
recover properly if the modified copy in the build tree is
1062
subsequently removed, in order to revert to the original behaviour.
1063
1064
1065
1066
1067
When updating the install tree's 
1068
class="directory">include subdirectory, the build tree may
1069
also perform a clean-up operation. Specifically, it may check for any
1070
files which do not correspond to known exported header files and
1071
delete them.
1072
1073
1074
1075
1076
1077
At present there is no defined support in the build system for
1078
defining custom build steps that generate exported header files. Any
1079
attempt to use the existing custom build step support may fall foul of
1080
unexpected header files being deleted automatically by the build
1081
system. This limitation will be addressed in a future release of the
1082
component framework, and may require changing the priority for
1083
exporting header files so that a custom build step can happen first.
1084
1085
1086
1087
 
1088
1089
1090
 
1091
1092
Compiling
1093
 
1094
1095
Once there are up to date copies of all the exported header files in
1096
the build tree, the main build can proceed. Most of this involves
1097
compiling source files listed in &compile; properties in the &CDL;
1098
scripts for the various packages, for example:
1099
1100
1101
cdl_package CYGPKG_ERROR {
1102
    display       "Common error code support"
1103
    compile       strerror.cxx
1104
1105
}
1106
1107
1108
&compile; properties may appear in the body of a &cdl-package;,
1109
&cdl-component;, &cdl-option; or &cdl-interface;. If the option or
1110
other &CDL; entity is active and enabled, the property takes effect.
1111
If the option is inactive or disabled the property is ignored. It is
1112
possible for a &compile; property to list multiple source files, and
1113
it is also possible for a given &CDL; entity to contain multiple
1114
&compile; properties. The following three examples are equivalent:
1115
1116
1117
cdl_option <some_option> {
1118
1119
    compile file1.c file2.c file3.c
1120
}
1121
 
1122
cdl_option <some_option> {
1123
1124
    compile file1.c
1125
    compile file2.c
1126
    compile file3.c
1127
}
1128
 
1129
cdl_option <some_option> {
1130
1131
    compile file1.c file2.c
1132
    compile file3.c
1133
}
1134
1135
1136
Packages that follow the directory layout conventions should have a
1137
subdirectory src, and the
1138
component framework will first look for the specified files there.
1139
Failing that it will look for the specified files relative to the
1140
package's root directory. For example if a package contains a source
1141
file strerror.cxx then the following two lines
1142
are equivalent:
1143
1144
1145
    compile strerror.cxx
1146
    compile src/strerror.cxx
1147
1148
1149
In the first case the component framework will find the file
1150
immediately in the packages src
1151
subdirectory. In the second case the framework will first look for a
1152
file src/src/strerror.cxx, and then for
1153
str/strerror.cxx relative to the package's root
1154
directory. The result is the same.
1155
1156
1157
The file names may be relative paths, allowing the source code to be
1158
split over multiple directories. For example if a package contains a
1159
file src/sync/mutex.cxx then the corresponding
1160
&CDL; entry would be:
1161
1162
1163
    compile sync/mutex.cxx
1164
1165
1166
All the source files relevant to the current configuration will be
1167
identified when the build tree is generated or updated, and added to
1168
the appropriate makefile (or its equivalent for other build systems).
1169
The actual build will involve a rule of the form:
1170
1171
1172
<object file> : <source file>
1173
        $(CC) -c $(INCLUDE_PATH) $(CFLAGS) -o $@ $<
1174
1175
 
1176
1177
The component framework has built-in knowledge for processing source
1178
files written in C, C++ or assembler. These should have a
1179
.c, .cxx and
1180
.S suffix respectively. The current implementation
1181
has no simple mechanism for extending this with support for other
1182
languages or for alternative suffixes, but this should be addressed in
1183
a future release.
1184
1185
1186
The compiler command that will be used is something like
1187
arm-elf-gcc. This consists of a command prefix, in
1188
this case arm-elf, and a specific command such as
1189
gcc. The command prefix will depend on the target
1190
architecture and is controlled by a configuration option in the
1191
appropriate HAL package. It will have a sensible default value for the
1192
current architecture, but users can modify this option when necessary.
1193
The command prefix cannot be changed on a per-package basis, since
1194
it is usually essential that all packages are built with a consistent
1195
set of tools.
1196
1197
1198
The $(INCLUDE_PATH) header file search path
1199
consists of at least the following:
1200
1201
1202
1203
1204
The include directory in the
1205
install tree. This allows source files to access the various header
1206
files exported by all the packages in the configuration, and also the
1207
configuration header files.
1208
1209
1210
1211
1212
The current package's root directory. This ensures that all files in
1213
the package are accessible at build time.
1214
1215
1216
1217
1218
The current package's src
1219
subdirectory, if it is present. Generally all files to be compiled are
1220
located in or below this directory. Typically this is used to access
1221
private header files containing implementation details only.
1222
1223
1224
1225
1226
The compiler flags $(CFLAGS) are determined in two
1227
steps. First the appropriate HAL package will provide a configuration
1228
option defining the global flags. Typically this includes flags that
1229
are needed for the target processor, for example
1230
-mcpu=arm9, various flags related to warnings,
1231
debugging and optimization, and flags such as
1232
-finit-priority which are needed by &eCos; itself.
1233
Users can modify the global flags option as required. In addition it
1234
is possible for existing flags to be removed from and new flags to be
1235
added to the current set on a per-package basis, again by means of
1236
user-modifiable configuration options. More details are given below.
1237
1238
1239
Component writers can assume that the build system will perform full
1240
header file dependency analysis, including dependencies on
1241
configuration headers, but the exact means by which this happens is
1242
implementation-defined. Typical application developers are unlikely to
1243
modify exported or private header files, but configuration headers are
1244
likely to change as the configuration is changed to better meet the
1245
needs of the application. Full header file dependency analysis also
1246
makes things easier for the component writers themselves.
1247
1248
1249
The current directory used during a compilation is an implementation
1250
detail of the build system. However it can be assumed that each
1251
package will have its own directory somewhere in the build tree, to
1252
prevent file name clashes, that this will be the current directory,
1253
and that intermediate object files will end up here.
1254
1255
 
1256
1257
 
1258
1259
1260
 
1261
1262
Generating the Libraries
1263
 
1264
1265
Once all the &compile; and &make-object; properties have been
1266
processed and the required object files have been built or rebuilt,
1267
these can be collected together in one or more libraries. The archiver
1268
will be the ar command
1269
corresponding to the current architecture, for example 
1270
class="software">powerpc-eabi-ar. By default al of the
1271
object files will end up in a single library
1272
libtarget.a. This can be changed on a per-package
1273
basis using the &library property
1274
in the body of the corresponding &cdl-package; command, for example:
1275
1276
1277
cdl_package <SOME_PACKAGE> {
1278
1279
    library  libSomePackage.a
1280
}
1281
1282
 
1283
1284
However using different libraries for each package should be avoided.
1285
It makes things more difficult for application developers since they
1286
now have to link the application code with more libraries, and
1287
possibly even change this set of libraries when packages are added to
1288
or removed from the configuration. The use of a single library
1289
libtarget.a avoids any complications.
1290
1291
1292
It is also possible to change the target library for individual files,
1293
using a -library option with the corresponding
1294
&compile; or &make-object; property. For example:
1295
1296
1297
    compile -library=libSomePackage.a hello.c
1298
    make_object -library=libSomePackage.a {
1299
1300
    }
1301
1302
1303
Again this should be avoided because it makes application development
1304
more difficult. There is one special library which can be used freely,
1305
libextras.a, which is used to generate the
1306
extras.o file as described below.
1307
1308
1309
The order in which object files end up in a library is not defined.
1310
Typically each library will be created directly in the install tree,
1311
since there is little point in generating a file in the build tree and
1312
then immediately copying it to the install tree.
1313
1314
 
1315
1316
 
1317
1318
1319
 
1320
1321
The <filename>extras.o</filename> file
1322
 
1323
1324
Package sources files normally get compiled and then added to a
1325
library, by default libtarget.a, which is then
1326
linked with the application code. Because of the usual rules for
1327
linking with libraries, augmented by the use of link-time garbage
1328
collection, this means that code will only end up in the final
1329
executable if there is a direct or indirect reference to it in the
1330
application. Usually this is the desired behaviour: if the application
1331
does not make any use of say kernel message boxes, directly or
1332
indirectly, then that code should not end up in the final executable
1333
taking up valuable memory space.
1334
1335
1336
In a few cases it is desirable for package code to end up in the final
1337
executable even if there are no direct or indirect references. For
1338
example, device driver functions are often not called directly.
1339
Instead the application will access the device via the string
1340
"/dev/xyzzy" and call the device functions
1341
indirectly. This will be impossible if the functions have been
1342
removed at link-time.
1343
1344
1345
Another example involves static C++ objects. It is possible to have a
1346
static C++ object, preferably with a suitable constructor priority,
1347
where all of the interesting work happens as a side effect of running
1348
the constructor. For example a package might include a monitoring
1349
thread or a garbage collection thread created from inside such a
1350
constructor. Without a reference by the application to the static
1351
object the latter will never get linked in, and the package will not
1352
function as expected.
1353
1354
1355
A third example would be copyright messages. A package vendor may want
1356
to insist that all products shipped using that package include a
1357
particular message in memory, even though many users of that package
1358
will object to such a restriction.
1359
1360
1361
To meet requirements such as these the build system provides support
1362
for a file extras.o, which always gets linked
1363
with the application code via the linker script. Because it is an
1364
object file rather than a library everything in the file will be
1365
linked in. The extras.o file is generated at the
1366
end of a build from a library libextras.a, so
1367
packages can put functions and variables in suitable source files and
1368
add them to that library explicitly:
1369
1370
1371
    compile -library=libextras.a xyzzy.c
1372
    compile xyzzy_support.c
1373
1374
1375
In this example xyzzy.o will end up in
1376
libextras.a, and hence in
1377
extras.o and in the final executable.
1378
xyzzy_support.o will end up in
1379
libtarget.a as usual, and is subject to linker
1380
garbage collection.
1381
1382
 
1383
1384
 
1385
1386
1387
 
1388
1389
Compilers and Flags
1390
 
1391
1392
1393
Some of the details of compiler selection and compiler flags described
1394
below are subject to change in future revisions of the component
1395
framework, although every reasonable attempt will be made to avoid
1396
breaking backwards compatibility.
1397
1398
1399
 
1400
1401
The build system needs to know what compiler to use, what compiler
1402
flags should be used for different stages of the build and so on. Much
1403
of this information will vary from target to target, although users
1404
should be able to override this when appropriate. There may also be a
1405
need for some packages to modify the compiler flags. All platform HAL
1406
packages should define a number of options with well-known names,
1407
along the following lines (any existing platform HAL package can be
1408
consulted for a complete example):
1409
1410
1411
cdl_component CYGBLD_GLOBAL_OPTIONS {
1412
    flavor  none
1413
    parent  CYGPKG_NONE
1414
1415
 
1416
    cdl_option CYGBLD_GLOBAL_COMMAND_PREFIX {
1417
        flavor  data
1418
        default_value { "arm-elf" }
1419
1420
    }
1421
    cdl_option CYGBLD_GLOBAL_CFLAGS {
1422
        flavor  data
1423
        default_value "-Wall -g -O2 …"
1424
1425
    }
1426
 
1427
    cdl_option CYGBLD_GLOBAL_LDFLAGS {
1428
        flavor  data
1429
        default_value "-g -nostdlib -Wl,--gc-sections …"
1430
1431
    }
1432
}
1433
1434
1435
The CYGBLD_GLOBAL_OPTIONS component serves to
1436
collect together all global build-related options. It has the flavor
1437
none since disabling all of these options would
1438
make it impossible to build anything and hence is not useful. It is
1439
parented immediately below the root of the configuration hierarchy,
1440
thus making sure that it is readily accessible in the graphical
1441
configuration tool and, for command line users, in the
1442
ecos.ecc save file.
1443
1444
1445
1446
Currently the &parent; property lists a parent of
1447
CYGPKG_NONE, rather than an empty string. This
1448
could be unfortunate if there was ever a package with that name. The
1449
issue will be addressed in a future release of the component
1450
framework.
1451
1452
1453
1454
The option CYGBLD_GLOBAL_COMMAND_PREFIX defines
1455
which tools should be used for the current target. Typically this is
1456
determined by the processor on the target hardware. In some cases a
1457
given target board may be able to support several different
1458
processors, in which case the &default-value; expression could select
1459
a different toolchain depending on some other option that is used to
1460
control which particular processor.
1461
CYGBLD_GLOBAL_COMMAND_PREFIX is modifiable rather
1462
than calculated, so users can override this when necessary.
1463
1464
1465
Given a command prefix such as arm-elf, all C
1466
source files will be compiled with arm-elf-gcc, all
1467
C++ sources will be built using arm-elf-g++,
1468
and arm-elf-ar will be used to generate the
1469
library. This is in accordance with the usual naming conventions for
1470
GNU cross-compilers and similar tools. For the purposes of custom
1471
build steps, tokens such as $(CC) will be set to
1472
arm-elf-gcc.
1473
1474
1475
The next option, CYGBLD_GLOBAL_CFLAGS, is used to
1476
provide the initial value of $(CFLAGS). Some
1477
compiler flags such as -Wall and
1478
-g are likely to be used on all targets. Other
1479
flags such as -mcpu=arm7tdmi will be
1480
target-specific. Again this is a modifiable option, so the user can
1481
switch from say -O2 to -Os if
1482
desired. The option CYGBLD_GLOBAL_LDFLAGS serves
1483
the same purpose for $(LDFLAGS) and linking. It is
1484
used primarily when building test cases or possibly for some custom
1485
build steps, since building eCos itself generally involves building
1486
one or more libraries rather than executables.
1487
1488
1489
Some packages may wish to add certain flags to the global set, or
1490
possibly remove some flags. This can be achieved by having
1491
appropriately named options in the package, for example:
1492
1493
1494
cdl_component CYGPKG_KERNEL_OPTIONS {
1495
    display "Kernel build options"
1496
    flavor  none
1497
1498
 
1499
    cdl_option CYGPKG_KERNEL_CFLAGS_ADD {
1500
        display "Additional compiler flags"
1501
        flavor  data
1502
        default_value { "" }
1503
1504
    }
1505
 
1506
    cdl_option CYGPKG_KERNEL_CFLAGS_REMOVE {
1507
        display "Suppressed compiler flags"
1508
        flavor  data
1509
        default_value { "" }
1510
1511
    }
1512
 
1513
    cdl_option CYGPKG_KERNEL_LDFLAGS_ADD {
1514
        display "Additional linker flags"
1515
        flavor  data
1516
        default_value { "" }
1517
1518
    }
1519
 
1520
    cdl_option CYGPKG_KERNEL_LDFLAGS_REMOVE {
1521
        display "Suppressed linker flags"
1522
        flavor  data
1523
        default_value { "" }
1524
1525
    }
1526
}
1527
1528
1529
In this example the kernel does not modify the global compiler flags
1530
by default, but it is possible for the users to modify the options if
1531
desired. The value of $(CFLAGS) that is used for
1532
the compilations and custom build steps in a given package is
1533
determined as follows:
1534
1535
1536
1537
1538
Start with the global settings from
1539
CYGBLD_GLOBAL_CFLAGS, for example
1540
-g -O2.
1541
1542
1543
1544
1545
Remove any flags specified in the per-package
1546
CFLAGS_REMOVE option, if any. For example
1547
if -O2 should be removed for this package then
1548
$(CFLAGS) would now have a value of just
1549
-g.
1550
1551
1552
1553
1554
Then concatenate the flags specified by the per-package
1555
CFLAGS_ADD option, if any. For example if
1556
-Os should be added for the current package then
1557
the final value of $(CFLAGS) will be
1558
-g -Os.
1559
1560
1561
1562
1563
$(LDFLAGS) is determined in much the same way.
1564
1565
 
1566
1567
1568
The way compiler flags are handled at present has numerous limitations
1569
that need to be addressed in a future release, although it should
1570
suffice for nearly all cases. For the time being custom build steps
1571
and in particular the &make-object; property can be used to work
1572
around the limitations.
1573
1574
1575
Amongst the issues, there is a specific problem with package
1576
encapsulation. For example the math library imposes some stringent
1577
requirements on the compiler in order to guarantee exact IEEE
1578
behavior, and may need special flags on a per-architecture basis. One
1579
way of handling this is to have
1580
CYGPKG_LIBM_CFLAGS_ADD and
1581
CYGPKG_LIBM_CFLAGS_REMOVE &default-value;
1582
expressions which depend on the target architecture, but such
1583
expressions may have to updated for each new architecture. An
1584
alternative approach would allow the architectural HAL package to
1585
modify the &default-value; expressions for the math library, but this
1586
breaks encapsulation. A third approach would allow some architectural
1587
HAL packages to define one or more special options with well-known
1588
names, and the math library could check if these options were defined
1589
and adjust the default values appropriately. Other packages with
1590
floating point requirements could do the same. This approach also has
1591
scalability issues, in particular how many such categories of options
1592
would be needed? It is not yet clear how best to resolve such issues.
1593
1594
1595
 
1596
1597
1598
When generating a build tree it would be desirable for the component
1599
framework to output details of the tools and compiler flags in a
1600
format that can be re-used for application builds, for example a
1601
makefile fragment. This would make it easier for application
1602
developers to use the same set of flags as were used for building eCos
1603
itself, thus avoiding some potential problems with incompatible
1604
compiler flags.
1605
1606
1607
 
1608
1609
 
1610
1611
1612
 
1613
1614
Custom Build Steps
1615
 
1616
1617
1618
Some of the details of custom build steps as described below are
1619
subject to change in future revisions of the component framework,
1620
although every reasonable attempt will be made to avoid breaking
1621
backwards compatibility.
1622
1623
1624
 
1625
1626
For most packages simply listing one or more source files in a
1627
&compile; property is sufficient. These files will get built using the
1628
appropriate compiler and compiler flags and added to a library, which
1629
then gets linked with application code. A package that can be built in
1630
this way is likely to be more portable to different targets and build
1631
environments, since it avoids build-time dependencies. However some
1632
packages have special needs, and the component framework supports
1633
custom build steps to allow for these needs. There are two properties
1634
related to this, &make; and &make-object;, and both take the following
1635
form:
1636
1637
1638
    make {
1639
        <target_filepath> : <dependency_filepath> …
1640
            <command>
1641
            ...
1642
    }
1643
1644
1645
Although this may look like makefile syntax, and although some build
1646
environments will indeed involve generating makefiles and running
1647
make, this is not
1648
guaranteed. It is possible for the component framework to be
1649
integrated with some other build system, and custom build steps should
1650
be written with that possibility in mind. Each custom build step
1651
involves a target, some number of dependency files, and some number of
1652
commands. If the target is not up to date with respect to one or more
1653
of the dependencies then the commands need to be executed.
1654
1655
 
1656
1657
 
1658
1659
1660
Only one target can be specified. For a &make-object; property this
1661
target must be an object file. For a &make; property it can be any
1662
file. In both cases it must refer to a physical file, the use of
1663
phony targets is not supported. The target should not be an absolute
1664
path name. If the generated file needs to end up in the install tree
1665
then this can be achieved using a <PREFIX>
1666
token, for example:
1667
1668
1669
    make {
1670
        <PREFIX>/lib/mytarget : …
1671
            ...
1672
    }
1673
1674
1675
When the build tree is generated and the custom build step is added to
1676
the makefile (or whatever build system is used)
1677
<PREFIX> will be replaced with the absolute
1678
path to the install tree.
1679
1680
1681
 
1682
1683
1684
All the dependencies must also refer to physical files, not to phony
1685
targets. These files may be in the source tree. The
1686
<PACKAGE> token can be used to indicate this:
1687
when the build tree is generated this token will be replaced with the
1688
absolute path to the package's root directory in the component
1689
repository, for example:
1690
1691
1692
    make_object {
1693
        xyzzy.o : <PACKAGE>/src/xyzzy.c
1694
1695
1696
1697
If the component repository was installed in 
1698
class="directory">/usr/local/ecos and this custom build
1699
step existed in version 1_5 of the kernel,
1700
<PACKAGE> would be replaced with
1701
/usr/local/ecos/packages/kernel/v1_5.
1702
1703
1704
Alternatively the dependencies may refer to files that are generated
1705
during the build. These may be object files resulting from &compile;
1706
properties or other &make-object; properties, or they may be other
1707
files resulting from a &make; property, for example:
1708
1709
1710
    compile plugh.c
1711
    make_object {
1712
        xyzzy.o : plugh.o
1713
1714
    }
1715
1716
1717
1718
1719
No other token or makefile variables may be used in the target or
1720
dependency file names. Also conditionals such as
1721
ifneq and similar makefile functionality must not
1722
be used.
1723
1724
1725
 
1726
1727
1728
Similarly the list of commands must not use any makefile conditionals
1729
or similar functionality. A number of tokens can be used to provide
1730
access to target-specific or environmental data. Note that these
1731
tokens look like makefile variables, unlike the
1732
<PREFIX> and
1733
<PACKAGE> tokens mentioned earlier:
1734
1735
 
1736
1737
1738
1739
  
1740
    Token
1741
    Purpose
1742
    Example value
1743
  
1744
1745
1746
  
1747
    $(AR)
1748
    the GNU archiver
1749
    mips-tx39-elf-ar
1750
  
1751
  
1752
    $(CC)
1753
    the GNU compiler
1754
    sh-elf-gcc
1755
  
1756
  
1757
    $(CFLAGS)
1758
    compiler flags
1759
    -O2 -Wall
1760
  
1761
  
1762
    $(COMMAND_PREFIX)
1763
    the triplet prefix
1764
    mn10300-elf-
1765
  
1766
  
1767
    $(INCLUDE_PATH>
1768
    header file search path
1769
    -I. -Isrc/misc
1770
  
1771
  
1772
    $(LDFLAGS)
1773
    linker flags
1774
    -nostdlib -Wl,-static
1775
  
1776
  
1777
    $(OBJCOPY)
1778
    the objcopy utility
1779
    arm-elf-objcopy
1780
  
1781
  
1782
    $(PREFIX)
1783
    location of the install tree
1784
    /home/fred/ecos-install
1785
  
1786
  
1787
    $(REPOSITORY)
1788
    location of the component repository
1789
    /home/fred/ecos/packages
1790
  
1791
1792
1793
1794
 
1795
1796
In addition commands in a custom build step may refer to the target
1797
and the dependencies using $@,
1798
$<, $^ and
1799
$*, all of which behave as per GNU make syntax. The
1800
commands will execute in a suitable directory in the build tree.
1801
1802
1803
 
1804
1805
1806
The current directory used during a custom build step is an
1807
implementation detail of the build system. However it can be assumed
1808
that each package will have its own directory somewhere in the build
1809
tree, to prevent file name clashes, and that this will be the current
1810
directory. In addition any object files generated as a result of
1811
&compile properties will be located here as well, which is useful for
1812
custom build steps that depend on a .o file
1813
previously generated.
1814
1815
1816
Any temporary files created by a custom build step should be generated
1817
in the build tree (in or under the current directory). Such files
1818
should be given a .tmp file extension to ensure
1819
that they are deleted during a make clean or
1820
equivalent operation.
1821
1822
1823
If a package contains multiple custom build steps with the same
1824
priority, it is possible that these build steps will be run
1825
concurrently. Therefore these custom build steps must not accidentally
1826
use the same file names for intermediate files.
1827
1828
1829
 
1830
1831
1832
Care has to be taken to make sure that the commands in a custom build
1833
step will run on all host platforms, including Windows NT as well as
1834
Linux and other Unix systems. For example, all file paths should use
1835
forward slashes as the directory separator. It can be assumed that
1836
Windows users will have a full set of CygWin tools installed and
1837
available on the path. The 
1838
url="http://www.gnu.org/prep/standards.html">GNU coding
1839
standards provide some useful guidelines for writing portable
1840
build rules.
1841
1842
1843
 
1844
1845
1846
A custom build step must not make any assumptions concerning the
1847
version of another package. This enforces package encapsulation,
1848
preventing one package from accessing the internals of another.
1849
1850
1851
 
1852
1853
1854
No assumptions should be made about the target platform, unless the
1855
package is inherently specific to that platform. Even then it is
1856
better to use the various tokens whenever possible, rather than
1857
hard-coding in details such as the compiler. For example, given a
1858
custom build step such as:
1859
1860
1861
    arm-elf-gcc -c -mcpu=arm7di -o $@ $<
1862
1863
1864
Even if this build step will only be invoked on ARM targets, it could
1865
cause problems. For example the toolchain may have been installed
1866
using a prefix other than arm-elf. Also, if the
1867
user changes the compiler flags then this would not be reflected in
1868
the build step. The correct way to write this rule would be:
1869
1870
1871
    $(CC) -c $(CFLAGS) -o $@ $<
1872
1873
1874
Some commands such as the compiler, the archiver, and objcopy are
1875
required sufficiently often to warrant their own tokens, for example
1876
$(CC) and $(OBJCOPY). Other
1877
target-specific commands are needed only rarely and the
1878
$(COMMAND_PREFIX) token can be used to construct
1879
the appropriate command name, for example:
1880
1881
1882
 
1883
    $(COMMAND_PREFIX)size $< > $@
1884
1885
1886
 
1887
1888
1889
Custom build steps should not be used to build host-side executables,
1890
even if those executables are needed to build parts of the target side
1891
code. Support for building host-side executables will be added in a
1892
future version of the component framework, although it will not
1893
necessarily involve these custom build steps.
1894
1895
1896
 
1897
1898
 
1899
1900
By default custom build steps defined in a &make-object; property
1901
have a priority of 100, which means that they will be executed
1902
in the same phase as compilations resulting from a &compile; property.
1903
It is possible to change the priority using a property option, for
1904
example:
1905
1906
1907
    make_object -priority 50 {
1908
1909
    }
1910
1911
1912
Specifying a priority smaller than a 100 means that the custom build
1913
step happens before the normal compilations. Priorities between 100
1914
and 200 happen after normal compilations but before the libraries are
1915
archived together. &make-object; properties should not specify a
1916
priority of 200 or later.
1917
1918
1919
Custom build steps defined in a &make; property have a default
1920
priority of 300, and so they will happen after the libraries have been
1921
built. Again this can be changed using a -priority
1922
property option.
1923
1924
 
1925
1926
 
1927
1928
1929
 
1930
1931
Startup Code
1932
 
1933
1934
Linking an application requires the application code, a linker script,
1935
the eCos library or libraries, the extras.o file,
1936
and some startup code. Depending on the target hardware and how the
1937
application gets booted, this startup code may do little more than
1938
branching to main(), or it may have to perform a
1939
considerable amount of hardware initialization. The startup code
1940
generally lives in a file vectors.o which is
1941
created by a custom build step in a HAL package. As far as application
1942
developers are concered the existence of this file is largely
1943
transparent, since the linker script ensures that the file is part of
1944
the final executable.
1945
1946
1947
This startup code is not generally of interest to component writers,
1948
only to HAL developers who are referred to one of the existing HAL
1949
packages for specific details. Other packages are not expected to
1950
modify the startup in any way. If a package needs some work performed
1951
early on during system initialization, before the application's main
1952
entry point gets invoked, this can be achieved using a static object
1953
with a suitable constructor priority.
1954
1955
 
1956
1957
1958
It is possible that the extras.o support, in
1959
conjunction with appropriate linker script directives, could be used
1960
to eliminate the need for a special startup file. The details are not
1961
yet clear.
1962
1963
1964
 
1965
1966
 
1967
1968
1969
 
1970
1971
The Linker Script
1972
 
1973
1974
1975
This section is not finished, and the details are subject to change in
1976
a future release. Arguably linker script issues should be documented
1977
in the HAL documentation rather than in this guide.
1978
1979
1980
 
1981
1982
Generating the linker script is the responsibility of the various HAL
1983
packages that are applicable to a given target. Developers of
1984
components other than HAL packages need not be concerned about what is
1985
involved. Developers of new HAL packages should use an existing HAL as
1986
a template.
1987
1988
 
1989
1990
1991
It may be desirable for some packages to have some control over the
1992
linker script, for example to add extra alignment details for a
1993
particular section. This can be risky because it can result in subtle
1994
portability problems, and the current component framework has no
1995
support for any such operations. The issue may be addressed in a
1996
future release.
1997
1998
1999
 
2000
2001
 
2002
2003
 
2004
2005
 
2006
2007
2008
 
2009
2010
Building Test Cases
2011
 
2012
2013
2014
The support in the current implementation of the component framework
2015
for building and running test cases is limited, and should be enhanced
2016
considerably in a future version. Compatibility with the existing
2017
mechanisms described below will be maintained if possible, but this
2018
cannot be guaranteed.
2019
2020
2021
 
2022
2023
Whenever possible packages should be shipped with one or more test
2024
cases. This allows users to check that all packages function correctly
2025
in their particular configuration and on their target, which may be
2026
custom hardware unavailable to the package developer. The component
2027
framework needs to provide a way of building such test cases. For
2028
example, if a makefile system is used then there could be a
2029
make tests target to build the test cases, or
2030
possibly a make check target to build and run
2031
the test cases and process all the results. Unfortunately there are
2032
various complications.
2033
2034
2035
Not every test case will be applicable to every configuration. For
2036
example if the user has disabled the C library's
2037
CYGPKG_LIBC_STDIO component then there is no point
2038
in building or running any of the test cases for that component. This
2039
implies that test cases need to be associated with configuration
2040
options somehow. It is possible for the test case to use one or more
2041
#ifdef statements to check whether or not it is
2042
applicable in the current configuration, and compile to a null program
2043
when not applicable. This is inefficient because the test case will
2044
still get built and possibly run, even though it will not provide any
2045
useful information.
2046
2047
2048
Many packages involve direct interaction with hardware, for example a
2049
serial line or an ethernet interface. In such cases it is only
2050
worthwhile building and running the test if there is suitable software
2051
running at the other end of the serial line or listening on the same
2052
ethernet segment, and that software would typically have to run on the
2053
host. Of course the serial line in question may be hooked up to a
2054
different piece of hardware which the application needs to talk to, so
2055
disconnecting it and then hooking it up to the host for running some
2056
tests may be undesirable. The decision as to whether or not to build
2057
the test depends not just on the eCos configuration but also on the
2058
hardware setup and the availability of suitable host software.
2059
2060
2061
There are different kinds of tests, and it is not always desirable to
2062
run all of them. For example a package may contain a number of stress
2063
tests intended to run for long periods of time, possibly days or
2064
longer. Such tests should certainly be distinguished somehow from
2065
ordinary test cases so that users will not run them accidentally and
2066
wonder how long they should wait for a pass message
2067
before giving up. Stress tests may also have dependencies on the
2068
hardware configuration and on host software, for example a network
2069
stress test may require lots of ethernet packets.
2070
2071
2072
In the current implementation of the component framework these issues
2073
are not yet addressed. Instead there is only very limited support for
2074
building test cases. Any package can define a calculated configuration
2075
option of the form
2076
CYGPKG_<package-name>_TESTS, whose value is a
2077
list of test cases. The &calculated; property can involve an
2078
expression so it is possible to adapt to a small number of
2079
configuration options, but this quickly becomes unwieldy. A typical
2080
example would be:
2081
2082
2083
        cdl_option CYGPKG_UITRON_TESTS {
2084
            display "uITRON tests"
2085
            flavor  data
2086
            no_define
2087
            calculated { "tests/test1 tests/test2 tests/test3 \
2088
                tests/test4 tests/test5 tests/test6 tests/test7 \
2089
                tests/test8 tests/test9 tests/testcxx tests/testcx2 \
2090
                tests/testcx3 tests/testcx4 tests/testcx5 \
2091
                tests/testcx6 tests/testcx7 tests/testcx8 \
2092
                tests/testcx9 tests/testintr" }
2093
            description   "
2094
This option specifies the set of tests for the uITRON compatibility layer."
2095
        }
2096
2097
 
2098
2099
This implies that there is a file tests/test1.c
2100
or tests/test1.cxx in the package's directory.
2101
The commands that will be used to build the test case will take the
2102
form:
2103
2104
2105
    $(CC) -c $(INCLUDE_PATH) $(CFLAGS) -o <build path>/test1.o \
2106
         <source path>/tests/test1.c
2107
    $(CC) $(LDFLAGS) -o <install path>/tests/test1 <build_path>/test1.o
2108
2109
2110
The variables $(CC) and so on are determined in the
2111
same way as for custom build steps. The various paths and the current
2112
directory will depend on the exact build system being used, and are
2113
subject to change. As usual the sources in the component repository
2114
are treated as a read-only resources, intermediate files live in the
2115
build tree, and the desired executables should end up in the install
2116
tree.
2117
2118
2119
Each test source file must be self-contained. It is not possible at
2120
present to build a little per-package library that can be used by the
2121
test cases, or to link together several object files to produce a
2122
single test executable. In some cases it may be possible to
2123
#include source code from a shared file in order to
2124
avoid unnecessary code replication. There is no support for
2125
manipulating compiler or linker flags for individual test cases: the
2126
flags that will be used for all files are $(CFLAGS)
2127
and $(LDFLAGS), as per custom build steps. Note
2128
that it is possible for a package to define options of the form
2129
CYGPKG_<PACKAGE-NAME>_LDFLAGS_ADD and
2130
CYGPKG_<PACKAGE-NAME>_LDFLAGS_REMOVE. These
2131
will affect test cases, but in the absence of custom build steps they
2132
will have no other effect on the build.
2133
2134
 
2135
2136
 
2137
2138
 
2139

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.