<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../general.ent">
  %general-entities;
]>

<sect1 id="ch-tools-binutils-pass1" role="wrap">
  <?dbhtml filename="binutils-pass1.html"?>

  <sect1info condition="script">
    <productname>binutils</productname>
    <productnumber>&binutils-version;</productnumber>
    <address>&binutils-url;</address>
  </sect1info>

  <title>Binutils-&binutils-version; - 第一遍</title>

  <indexterm zone="ch-tools-binutils-pass1">
    <primary sortas="a-Binutils">Binutils</primary>
    <secondary>tools, pass 1</secondary>
  </indexterm>

  <sect2 role="package">
    <title/>

    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
    href="../chapter06/binutils.xml"
    xpointer="xpointer(/sect1/sect2[1]/para[1])"/>

    <segmentedlist>
      <segtitle>&buildtime;</segtitle>
      <segtitle>&diskspace;</segtitle>

      <seglistitem>
        <seg>&binutils-ch5p1-sbu;</seg>
        <seg>&binutils-ch5p1-du;</seg>
      </seglistitem>
    </segmentedlist>

  </sect2>

  <sect2 role="installation">
    <title>安装交叉工具链中的 Binutils</title>

    <note><!--para>Go back and re-read the notes in the previous section.
    Understanding the notes labeled important will save you a lot
	of problems later.</para-->
    <para>返回并重新阅读上一节。仔细理解那些标为 <quote>重要</quote>
        	的说明，以防止之后出现问题。</para>
	</note>

    <!--para>It is important that Binutils be the first package compiled
    because both Glibc and GCC perform various tests on the available
    linker and assembler to determine which of their own features to
    enable.</para-->
    <para>首先构建 Binutils 相当重要，
		因为 Glibc 和 GCC 都会对可用的链接器和汇编器进行测试，
		以决定可以启用它们自带的哪些特性。</para>

    <!--para>The Binutils documentation recommends building Binutils 
    in a dedicated build directory:</para-->
    <para>Binutils 文档推荐在一个专用的目录中构建 Binutils：</para>

<screen><userinput remap="pre">mkdir -v build
cd       build</userinput></screen>

    <note>
      <!--para>In order for the SBU values listed in the rest of the book
      to be of any use, measure the time it takes to build this package from
      the configuration, up to and including the first install. To achieve
      this easily, wrap the commands in a <command>time</command>
      command like this: <userinput>time { ./configure ... &amp;&amp; ...
      &amp;&amp; make install; }</userinput>.</para-->
	  <para>为了衡量本书其余部分使用的 SBU 值，
		  需要测量本软件包从配置开始直到第一次安装花费的时间。
		  为了容易地完成测量，可以将命令包装在 <command>time</command>
		  命令中，就像这样：
		  <userinput>time {./configure ... &amp;&amp; ... &amp;&amp;
			  make install; }</userinput>。</para>
    </note>

    <note><!--para>The approximate build SBU values and required disk space
		in Chapter&nbsp;5 does not include test suite data.</para-->
        <para>第 5 章中估计的 SBU 值和所需磁盘空间都不包含测试套件的数据。
        </para>
    </note>

    <para>现在，准备编译 Binutils ：</para>

<screen><userinput remap="configure">../configure --prefix=/tools            \
             --with-sysroot=$LFS        \
             --with-lib-path=/tools/lib \
             --target=$LFS_TGT          \
             --disable-nls              \
             --disable-werror</userinput></screen>

    <variablelist>
      <title>配置选项的含义：</title>

      <varlistentry>
        <term><parameter>--prefix=/tools</parameter></term>
        <listitem>
          <para>这告诉配置脚本准备将 Binutils 程序安装在
          	  <filename class="directory">/tools</filename> 目录中。</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--with-sysroot=$LFS</parameter></term>
        <listitem>
          <para>该选项告诉构建系统，交叉编译时在 $LFS 中寻找目标系统的库。
          </para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--with-lib-path=/tools/lib</parameter></term>
        <listitem>
          <para>该选项指定链接器应该使用的库文件搜索路径。</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><envar>--target=$LFS_TGT</envar></term>
        <listitem>
          <para>由于 <envar>LFS_TGT</envar> 变量中的机器描述和
			  <command>config.guess</command> 脚本的输出略有不同, 
			  这个开关使得 <command>configure</command> 脚本调整 Binutils
			  的构建系统，以构建交叉链接器。</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-nls</parameter></term>
        <listitem>
          <para>该选项禁用临时工具不需要的国际化功能。</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><parameter>--disable-werror</parameter></term>
        <listitem>
          <para>该选项防止宿主系统编译器警告导致构建失败。</para>
        </listitem>
      </varlistentry>

    </variablelist>

    <para>然后编译该软件包：</para>

<screen><userinput remap="make">make</userinput></screen>

    <!--para>Compilation is now complete. Ordinarily we would now run the
    test suite, but at this early stage the test suite framework (Tcl,
    Expect, and DejaGNU) is not yet in place. The benefits of running the
    tests at this point are minimal since the programs from this
    first pass will soon be replaced by those from the second.</para-->
    <para>现在编译已经完成，一般来说我们应该执行测试套件，
		但在当前的早期构建阶段，测试套件框架 (Tcl、Expect 和 DejaGNU)
		尚不可用。另外，由于第一遍构建的程序很快会被第二遍构建的程序替代，
		运行测试的收益极小。</para>

    <para>如果在 x86_64 上编译，创建一个符号链接以保证工具链的完整性：
    </para>

<screen><userinput remap="install">case $(uname -m) in
  x86_64) mkdir -v /tools/lib &amp;&amp; ln -sv lib /tools/lib64 ;;
esac</userinput></screen>

    <para>安装该软件包：</para>

<screen><userinput remap="install">make install</userinput></screen>

  </sect2>

  <sect2 role="content">
    <title/>

    <para>这个软件包的细节在
		<xref linkend="contents-binutils"/> 中可以找到。</para>

  </sect2>

</sect1>
