⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 build.sgml

📁 ecos实时嵌入式操作系统
💻 SGML
📖 第 1 页 / 共 5 页
字号:
<para>The next step is to generate a default <literal>#define</literal> forthe current option. If this option has a &no-define; property then thedefault <literal>#define</literal> is suppressed, and processingcontinues for &define;, &if-define; and &define-proc; properties.</para><orderedlist><listitem><para>The header file appropriate for the default <literal>#define</literal>is determined. For a &cdl-package; this will be <filenameclass="headerfile">pkgconf/system.h</filename>, for any other option thiswill be the package's own header file. The intention here is thatpackages and application code can always determine which packages arein the configuration by <literal>#include'ing</literal> <filenameclass="headerfile">pkgconf/system.h</filename>. The C preprocessor lacksany facilities for including a header file only if it exists, andtaking appropriate action otherwise.</para></listitem><listitem><para>For options with the flavors <literal>bool</literal> or<literal>none</literal>, a single <literal>#define</literal> will begenerated. This takes the form:</para><programlisting width=72>#define &lt;option&gt; 1</programlisting><para>For example:</para><programlisting width=72>#define CYGFUN_LIBC_TIME_POSIX 1</programlisting><para>Package source code can check whether or not an option is active andenabled by using the <literal>#ifdef</literal>,<literal>#ifndef</literal> or <literal>#ifdefined(&hellip;)</literal>directives.</para></listitem><listitem><para>For options with the flavors <literal>data</literal> or<literal>booldata</literal>, either one or two<literal>#define's</literal> will be generated. The first of these maybe affected by a &define-format; property. If this property is notdefined then the first <literal>#define</literal> will take the form:</para><programlisting width=72>#define &lt;option&gt; &lt;value&gt;</programlisting><para>For example:</para><programlisting width=72>#define CYGNUM_LIBC_ATEXIT_HANDLERS 32</programlisting><para>Package source code can examine this value using the<literal>#if</literal> directive, or by using the symbol incode such as:</para><programlisting width=72>    for (i = 0; i < CYGNUM_LIBC_ATEXIT_HANDLERS; i++) {        &hellip;    }</programlisting><para>It must be noted that the <literal>#define</literal> will be generatedonly if the corresponding option is both active and enabled. Optionswith the <literal>data</literal> flavor are always enabled but may notbe active. Code like the above should be written only if it is knownthat the symbol will always be defined, for example if thecorresponding source file will only get built if the containingcomponent is active and enabled. Otherwise the use of additional<literal>#ifdef</literal> or similar directives will be necessary.</para></listitem><listitem><para>If there is a &define-format; property then this controls how theoption's value will appear in the header file. Given a format stringsuch as <literal>%08x</literal> and a value 42, the componentframework will execute the &Tcl; command<literal>format&nbsp;%08x&nbsp;42</literal> and the result will beused for the <literal>#define's</literal> value. It is theresponsibility of the component writer to make sure that this &Tcl;command will be valid given the format string and the legal values forthe option.</para></listitem><listitem><para>In addition a second <literal>#define</literal> may or may not begenerated. This will take the form:</para><programlisting width=72>#define &lt;option&gt;_&lt;value&gt;</programlisting><para>For example:</para><programlisting width=72>#define CYGNUM_LIBC_ATEXIT_HANDLERS_32</programlisting><para>The <literal>#define</literal> will be generated only if it wouldresult in a valid C preprocessor symbol. If the value is a string suchas <literal>"/dev/ser0"</literal> then the <literal>#define</literal>would be suppressed. This second <literal>#define</literal> is notparticularly useful for numerical data, but can be valuable in othercircumstances. For example if the legal values for an option<literal>XXX_COLOR</literal> are <literal>red</literal>,<literal>green</literal> and <literal>blue</literal> then code likethe following can be used:</para><programlisting width=72>#ifdef XXX_COLOR_red    &hellip;#endif#ifdef XXX_COLOR_green    &hellip;#endif#ifdef XXX_COLOR_blue    &hellip;#endif</programlisting><para>The expression syntax provided by the C preprocessor is limited tonumerical data and cannot perform string comparisons. By generatingtwo <literal>#define's</literal> in this way it is possible to workaround this limitation of the C preprocessor. However some care has tobe taken: if a component writer also defined a configuration option<literal>XXX_COLOR_green</literal> then there will be confusion. Sincesuch a configuration option violates the naming conventions, theproblem is unlikely to arise in practice.</para></listitem></orderedlist></listitem><listitem><para>For some options it may be useful to generate one or more additional<literal>#define's</literal> or, in conjunction with the &no-define;property, to define a symbol with a name different from the option'sname. This can be achieved with the &define; property, which takes thefollowing form:</para><programlisting width=72>    define [-file=&lt;filename&gt;] [-format=&lt;format&gt;] &lt;symbol&gt;</programlisting><para>For example:</para><programlisting width=72>    define FOPEN_MAX</programlisting><para>This will result in something like:</para><programlisting width=72>#define FOPEN_MAX 8#define FOPEN_MAX_8</programlisting><para>The specified symbol must be a valid C preprocessor symbol. Normallythe <literal>#define</literal> will end up in the same header file asthe default one, in other words <filenameclass="headerfile">pkgconf/system.h</filename> in the case of a&cdl-package;, or the package's own header file for any other option.The <literal>-file</literal> option can be used to change this. Atpresent the only legal value is <literal>system.h</literal>, forexample:</para><programlisting width=72>    define -file=system.h &lt;symbol&gt;</programlisting><para>This will cause the <literal>#define</literal> to end up in the globalconfiguration header rather than in the package's own header. Use ofthis facility should be avoided since it is very rarely necessary tomake options globally visible.</para><para>The &define; property takes another option,<literal>-format</literal>, to provide a format string.</para><programlisting width=72>    define -format=%08x &lt;symbol&gt;</programlisting><para>This should only be used for options with the <literal>data</literal>or <literal>booldata</literal> flavor, and has the same effect as the&define-format; property has on the default<literal>#define</literal>.</para><para>&define; properties are processed in the same way the default<literal>#define</literal>. For options with the<literal>bool</literal> or <literal>none</literal> flavors a single<literal>#define</literal> will be generated using the value<literal>1</literal>. For options with the <literal>data</literal> or<literal>booldata</literal> flavors either one or two<literal>#define's</literal> will be generated.</para></listitem><listitem><para>After processing all &define; properties, the component framework willlook for any &if-define; properties. These take the following form:</para><programlisting width=72>    if_define [-file=&lt;filename&gt;] &lt;symbol1&gt; &lt;symbol2&gt;</programlisting><para>For example:</para><programlisting width=72>    if_define CYGSRC_KERNEL CYGDBG_USE_ASSERTS</programlisting><para>The following will be generated in the configuration header file:</para><programlisting width=72>#ifdef CYGSRC_KERNEL# define CYGDBG_USE_ASSERTS#endif</programlisting><para>Typical kernel source code would begin with the following construct:</para><programlisting width=72>#define CYGSRC_KERNEL 1#include &lt;pkgconf/kernel.h&gt;#include &lt;cyg/infra/cyg_ass.h&gt;</programlisting><para>The infrastructure header file <filenameclass="headerfile">cyg/infra/cyg_ass.h</filename> only checks for symbolssuch as <literal>CYGDBG_USE_ASSERTS</literal>, and has no specialknowledge of the kernel or any other package. The &if-define; propertywill only affect code that defines the symbol<literal>CYGSRC_KERNEL</literal>, so typically only kernel sourcecode. If the option is enabled then assertion support will be enabledfor the kernel source code only. If the option is inactive or disabledthen kernel assertions will be disabled. Assertions in other packagesare not affected. Thus the &if-define; property allows control overassertions, tracing, and similar facilities at the level of individualpackages, or at finer levels such as components or even single sourcefiles if desired.</para><note><para>Current &eCos; packages do not yet make use of this facility. Insteadthere is a single global configuration option<varname>CYGDBG_USE_ASSERTS</varname> which is used to enable ordisable assertions for all packages. This issue should be addressed ina future release of the system.</para></note><para>As with the &define; property, the &if-define; property takes anoption <literal>-file</literal> with a single legal value<literal>system.h</literal>. This allows the output to be redirectedto <filename class="headerfile">pkgconf/system.h</filename> if and whennecessary. </para></listitem><listitem><para>The final property that is relevant to configuration header filegeneration is &define-proc;. This takes a single argument, a &Tcl;fragment that can add arbitrary data to the global header <filenameclass="headerfile">pkgconf/system.h</filename> and to the package's ownheader. When the &define-proc; script is invoked two variables will beset up to allow access to these headers: <literal>cdl_header</literal>will be a channel to the package's own header file, for example<filename class="headerfile">pkgconf/kernel.h</filename>;<literal>cdl_system_header</literal> will be a channel to <filenameclass="headerfile">pkgconf/system.h</filename>. A typical &define-proc;script will use the &Tcl; <literal>puts</literal> command to outputdata to one of these channels, for example:</para><programlisting width=72>cdl_option &lt;name&gt; {    &hellip;    define_proc {        puts $::cdl_header "#define XXX 1"    }}</programlisting><note><para>In the current implementation the use of &define-proc; is limitedbecause the &Tcl; script cannot access any of the configuration data.Therefore the script is limited to writing constant data to theconfiguration headers. This is a major limitation which will beaddressed in a future release of the component framework.</para></note></listitem></orderedlist><note><para>Generating C header files with <literal>#define's</literal> for theconfiguration data suffices for existing packages written in somecombination of C, C++ and assembler. It can also be used inconjunction with some other languages, for example by first passingthe source code through the C preprocessor and feeding the result intothe appropriate compiler. In future versions of the componentframework additional programming languages such as Java may besupported, and the configuration data may also be written to files insome format other than C preprocessor directives. </para></note><note>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -