📄 build.sgml
字号:
<!-- {{{ Banner --><!-- =============================================================== --><!-- --><!-- build.sgml --><!-- --><!-- Description of the build system. --><!-- --><!-- =============================================================== --><!-- ####COPYRIGHTBEGIN#### --><!-- --><!-- =============================================================== --><!-- Copyright (C) 2000, 2001, 2002 Red Hat, Inc. --><!-- --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/) --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission obtained from the copyright holder --><!-- =============================================================== --><!-- --> <!-- ####COPYRIGHTEND#### --><!-- =============================================================== --><!-- #####DESCRIPTIONBEGIN#### --><!-- --><!-- Author(s): bartv --><!-- Contact(s): bartv --><!-- Date: 2000/02/06 --><!-- Version: 0.01 --><!-- --><!-- ####DESCRIPTIONEND#### --><!-- =============================================================== --><!-- }}} --><chapter id="build"><title>The Build Process</title><!-- {{{ Introit --><para>Some &CDL; properties describe the consequences of manipulatingconfiguration options. There are two main types of consequences.Typically enabling a configuration option results in one or more<literal>#define's</literal> in a configuration header file, andproperties that affect this include &define;, &define-proc; and&no-define;. Enabling a configuration option can also affect the buildprocess, primarily determining which files get built and added to theappropriate library. Properties related to the build process include&compile; and &make;. This chapter describes the whole build process,including details such as compiler flags and custom build steps.</para><para>Part of the overall design of the &eCos; component framework is thatit can interact with a number of different build systems. The mostobvious of these is <application class="software">GNUmake</application>:the component framework can generate one or moremakefiles, and the user can then build the various packages simply byinvoking <application class="software">make</application>. However itshould also be possible to build &eCos; by other means: thecomponent framework can be queried about what is involved in buildinga given configuration, and this information can then be fed into thedesired build system. Component writers should be aware of thispossibility. Most packages will not be affected because the &compile;property can be used to provide all the required information, but carehas to be taken when writing custom build steps.</para><!-- }}} --><!-- {{{ Build Tree Generation --><sect1 id="build.outline"><title>Build Tree Generation</title><para>It is necessary to create an &eCos; configuration before anything canbe built. With some tools such as the graphical configuration toolthis configuration will be created in memory, and it is not essentialto produce an <filename>ecos.ecc</filename> savefile first (althoughit is still very desirable to generate such a savefile at some point,to allow the configuration to be re-loaded later on). With other toolsthe savefile is generated first, for example using<literal>ecosconfig new</literal>, and then a build tree isgenerated using <literal>ecosconfig tree</literal>. The savefilecontains all the information needed to recreate a configuration.</para><para>An &eCos; build actually involves three separate trees. The componentrepository acts as the source tree, and for application developersthis should be considered a read-only resource. The build tree iswhere all intermediate files, especially object files, are created.The install tree is where the main library<filename>libtarget.a</filename>, the exported header files, andsimilar files end up. Following a successful build it is possible totake just the install tree and use it for developing an application:none of the files in the component repository or the build tree areneeded for that. The build tree will be needed again only if the userchanges the configuration. However the install tree does not containcopies of all of the documentation for the various packages, insteadthe documentation is kept only in the component repository.</para><para>By default the build tree, the install tree, and the<filename>ecos.ecc</filename> savefile all reside in the samedirectory tree. This is not a requirement, both the install tree andthe savefile can be anywhere in the file system.</para><para>It is worth noting that the component framework does not separate theusual <literal>make</literal> and <literal>make install</literal>stages. A build always populates the install tree, and any<literal>make install</literal> step would be redundant.</para><para>The install tree will always begin with two directories, <filenameclass="directory">include</filename> for the exported header files and<filename class="directory">lib</filename> for the main library<filename class="directory">libtarget.a</filename> and other filessuch as the linker script. In addition there will be a subdirectory<filename class="directory">include/pkgconf</filename> containing theconfiguration header files, which are generated or updated at the sametime the build tree is created or updated. More details of header filegeneration are given below. Additional <filenameclass="directory">include</filename> subdirectories such as <filenameclass="directory">sys</filename> and <filenameclass="directory">cyg/kernel</filename> will be created during thefirst build, when each package's exported header files are copied tothe install tree. The install tree may also end up with additionalsubdirectories during a build, for example as a result of custom buildsteps. </para><para>The component framework does not define the structure of the buildtree, and this may vary between build systems. It can be assumed thateach package in the configuration will have its own directory in thebuild tree, and that this directory will be used for storing thepackage's object files and as the current directory for any buildsteps for that package. This avoids problems when custom build stepsfrom different packages generate intermediate files which happen tohave the same name.</para><para>Some build systems may allow application developers to copy a sourcefile from the component repository to the build tree and edit thecopy. This allows users to experiment with small changes, for exampleto add a couple of lines of debugging to a package, without having tomodify the master copy in the component repository which could beshared by several projects or several people. Functionality such asthis is transparent to component writers, and it is the responsibilityof the build system to make sure that the right thing happens.</para><note><para>There are some unresolved issues related to the build tree and installtree. Specifically, when updating an existing build or install tree,what should happen to unexpected files or directories? Suppose theuser started with a configuration that included the math library, andthe install tree contains header files <filenameclass="headerfile">include/math.h</filename> and <filenameclass="headerfile">include/sys/ieeefp.h</filename>. The user then removedthe math library from the configuration and is updating the buildtree. It is now desirable to remove these header files from theinstall tree, so that if any application code still attempts to usethe math library this will fail at compile time rather than at linktime. There will also be some object files in the existing<literal>libtarget.a</literal> library which are no longerappropriate, and there may be other files in the install tree as aresult of custom build steps. The build tree will still contain adirectory for the math library, which no longer serves any purpose.</para><para>However, it is also possible that some of the files in the build treeor the install tree were placed there by the user, in which caseremoving them automatically would be a bad idea.</para><para>At present the component framework does not keep track of exactly whatshould be present in the build and install trees, so it cannot readilydetermine which files or library members are obsolete and can safelybe removed, and which ones are unexpected and need to be reported tothe user. This will be addressed in a future release of the system.</para></note></sect1><!-- }}} --><!-- {{{ Header File Generation --><sect1 id="build.headers"><title>Configuration Header File Generation</title><para>Configuration options can affect a build in two main ways. First,enabling a configuration option or other &CDL; entity can result invarious files being built and added to a library, thus providingfunctionality to the application code. However this mechanism can onlyoperate at a rather coarse grain, at the level of entire source files.Hence the component framework also generates configuration headerfiles containing mainly C preprocessor <literal>#define</literal>directives. Package source code can then <literal>#include</literal>the appropriate header files and use <literal>#if</literal>,<literal>#ifdef</literal> and <literal>#ifndef</literal> directives toadapt accordingly. In this way configuration options can be used toenable or disable entire functions within a source file or just asingle line, whichever is appropriate.</para><para>The configuration header files end up in the <filenameclass="directory">include/pkgconf</filename> subdirectory of theinstall tree. There will be one header file for the system as a whole,<filename class="headerfile">pkgconf/system.h</filename>, and there willbe additional header files for each package, for example<filename class="headerfile">pkgconf/kernel.h</filename>. The header filesare generated when creating or updating the build and install trees,which needs to happen after every change to the configuration.</para><para>The component framework processes each package in the configurationone at a time. The exact order in which the packages are processed isnot defined, so the order in which <literal>#define's</literal> willend up in the global <filenameclass="headerfile">pkgconf/system.h</filename> header may vary. Howeverfor any given configuration the order should remain consistent untilpackages are added to or removed from the system. This avoidsunnecessary changes to the global header file and hence unnecessaryrebuilds of the packages and of application code because of headerfile dependency handling.</para><para>Within a given package the various components, options and interfaceswill be processed in the order in which they were defined in thecorresponding &CDL; scripts. Typically the data in the configurationheaders consists only of a sequence of <literal>#define's</literal> sothe order in which these are generated is irrelevant, but someproperties such as &define-proc; can be used to add arbitrary data toa configuration header and hence there may be dependencies on theorder. It should be noted that re-parenting an option below some otherpackage has no effect on which header file will contain thecorresponding <literal>#define</literal>: the preprocessor directiveswill always end up in the header file for the package that defines theoption, or in the global configuration header.</para><para>There are six properties which affect the process of generating headerfiles:<link linkend="ref.define-header">&define-header;</link>,<link linkend="ref.no-define">&no-define;</link>,<link linkend="ref.define-format">&define-format;</link>,<link linkend="ref.define">&define;</link>,<link linkend="ref.if-define">&if-define;</link>, and<link linkend="ref.define-proc">&define-proc;</link>.</para><para>The &define-header; property can only occur in the body of a&cdl-package; command and specifies the name of the header file whichshould contain the package's configuration data, for example:</para><programlisting width=72>cdl_package <some_package> { … define_header xyzzy.h}</programlisting><para>Given such a &define-header; property the component framework willuse the file <filename class="headerfile">pkgconf/xyzzy.h</filename> forthe package's configuration data. If a package does not havea &define-header; property then a suitable file name is constructedfrom the package's name. This involves:</para><orderedlist><listitem><para>All characters in the package name up to and including the firstunderscore are removed. For example <varname>CYGPKG_KERNEL</varname>is converted to <literal>KERNEL</literal>, and<varname>CYGPKG_HAL_ARM</varname> is converted to<literal>HAL_ARM</literal>.</para></listitem><listitem><para>Any upper case letters in the resulting string will be converted tolower case, yielding e.g. <literal>kernel</literal> and<literal>hal_arm</literal>.</para></listitem><listitem><para>A <literal>.h</literal> suffix is appended, yielding e.g.<literal>kernel.h</literal> and <literal>hal_arm.h</literal>.</para></listitem></orderedlist><para>Because of the naming restrictions on configuration options, thisshould result in a valid filename. There is a small possibility of afile name class, for example <varname>CYGPKG_PLUGH</varname> and<varname>CYGPKG_plugh</varname> would both end up trying to use thesame header file <filename class="headerfile">pkgconf/plugh.h</filename>,but the use of lower case letters for package names violates thenaming conventions. It is not legal to use the &define-header;property to put the configuration data for several packages in asingle header file. The resulting behaviour is undefined.</para><para>Once the name of the package's header file has been determined and thefile has been opened, the various components, options and interfacesin the package will be processed starting with the package itself. Thefollowing steps are involved:</para><orderedlist><listitem><para>If the current option or other &CDL; entity is inactive or disabled,the option is ignored for the purposes of header file generation.<literal>#define's</literal> are only generated for options that areboth active and enabled.</para></listitem><listitem>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -