Author: jhuntwork
Date: 2012-04-19 14:17:38 -0600 (Thu, 19 Apr 2012)
New Revision: 9814

Modified:
   branches/jh/chapter01/changelog.xml
   branches/jh/chapter05/binutils-pass1.xml
   branches/jh/chapter05/binutils-pass2.xml
   branches/jh/chapter05/chapter05.xml
   branches/jh/chapter05/gcc-pass1.xml
   branches/jh/chapter05/gcc-pass2.xml
   branches/jh/chapter05/glibc.xml
Log:
Adjust build method to use sysroot

Modified: branches/jh/chapter01/changelog.xml
===================================================================
--- branches/jh/chapter01/changelog.xml 2012-04-19 14:58:06 UTC (rev 9813)
+++ branches/jh/chapter01/changelog.xml 2012-04-19 20:17:38 UTC (rev 9814)
@@ -37,6 +37,15 @@
 
 -->
     <listitem>
+      <para>2012-04-19</para>
+      <itemizedlist>
+        <listitem>
+          <para>[jhuntwork] - Adjust build method to use sysroot.</para>
+        </listitem>
+      </itemizedlist>
+    </listitem>
+
+    <listitem>
       <para>2012-04-15</para>
       <itemizedlist>
          <listitem>

Modified: branches/jh/chapter05/binutils-pass1.xml
===================================================================
--- branches/jh/chapter05/binutils-pass1.xml    2012-04-19 14:58:06 UTC (rev 
9813)
+++ branches/jh/chapter05/binutils-pass1.xml    2012-04-19 20:17:38 UTC (rev 
9814)
@@ -76,15 +76,43 @@
 
     <para>Now prepare Binutils for compilation:</para>
 
-<screen><userinput remap="configure">../binutils-&binutils-version;/configure 
--target=$LFS_TGT \
-                           --prefix=/tools   \
-                           --disable-nls     \
-                           --disable-werror</userinput></screen>
+<screen><userinput remap="configure">../binutils-&binutils-version;/configure  
 \
+  --prefix=/tools            \
+  --with-sysroot=$LFS        \
+  --with-lib-path=/tools/lib \
+  --target=$LFS_TGT          \
+  --disable-nls              \
+  --disable-werror</userinput></screen>
 
     <variablelist>
       <title>The meaning of the configure options:</title>
 
       <varlistentry>
+        <term><parameter>--prefix=/tools</parameter></term>
+        <listitem>
+          <para>This tells the configure script to prepare to install the
+          Binutils programs in the <filename 
class="directory">/tools</filename>
+          directory.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+         <term><parameter>--with-sysroot=$LFS</parameter></term>
+         <listitem>
+           <para>For cross compilation, this tells the build system to look in
+         $LFS for the target system libraries as needed.</para>
+         </listitem>
+       </varlistentry>
+ 
+       <varlistentry>
+         <term><parameter>--with-lib-path=/tools/lib</parameter></term>
+         <listitem>
+           <para>This specifies which library path the linker should be
+         configured to use.</para>
+         </listitem>
+       </varlistentry>
+ 
+       <varlistentry>
         <term><envar>--target=$LFS_TGT</envar></term>
         <listitem>
           <para>Because the machine description in the <envar>LFS_TGT</envar>
@@ -96,15 +124,6 @@
       </varlistentry>
 
       <varlistentry>
-        <term><parameter>--prefix=/tools</parameter></term>
-        <listitem>
-          <para>This tells the configure script to prepare to install the
-          Binutils programs in the <filename 
class="directory">/tools</filename>
-          directory.</para>
-        </listitem>
-      </varlistentry>
-
-      <varlistentry>
         <term><parameter>--disable-nls</parameter></term>
         <listitem>
           <para>This disables internationalization as i18n is not needed for 
the

Modified: branches/jh/chapter05/binutils-pass2.xml
===================================================================
--- branches/jh/chapter05/binutils-pass2.xml    2012-04-19 14:58:06 UTC (rev 
9813)
+++ branches/jh/chapter05/binutils-pass2.xml    2012-04-19 20:17:38 UTC (rev 
9814)
@@ -54,19 +54,19 @@
 
     <para>Prepare Binutils for compilation:</para>
 
-<screen><userinput remap="configure">CC="$LFS_TGT-gcc -B/tools/lib/" \
-AR=$LFS_TGT-ar                  \
-RANLIB=$LFS_TGT-ranlib          \
-../binutils-&binutils-version;/configure      \
-        --prefix=/tools         \
-        --disable-nls           \
-        --with-lib-path=/tools/lib</userinput></screen>
+<screen><userinput remap="configure">CC=$LFS_TGT-gcc              \
+  AR=$LFS_TGT-ar             \
+  RANLIB=$LFS_TGT-ranlib     \
+  ../binutils-&binutils-version;/configure \
+  --prefix=/tools            \
+  --disable-nls              \
+  --with-lib-path=/tools/lib</userinput></screen>
 
     <variablelist>
       <title>The meaning of the new configure options:</title>
 
       <varlistentry>
-        <term><parameter>CC="$LFS_TGT-gcc -B/tools/lib/" AR=$LFS_TGT-ar 
RANLIB=$LFS_TGT-ranlib</parameter></term>
+        <term><parameter>CC=$LFS_TGT-gcc AR=$LFS_TGT-ar 
RANLIB=$LFS_TGT-ranlib</parameter></term>
         <listitem>
           <para>Because this is really a native build of Binutils, setting 
these
           variables ensures that the build system uses the cross-compiler and

Modified: branches/jh/chapter05/chapter05.xml
===================================================================
--- branches/jh/chapter05/chapter05.xml 2012-04-19 14:58:06 UTC (rev 9813)
+++ branches/jh/chapter05/chapter05.xml 2012-04-19 20:17:38 UTC (rev 9814)
@@ -18,7 +18,6 @@
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; href="gcc-pass1.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; 
href="linux-headers.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; href="glibc.xml"/>
-  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; href="adjusting.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; 
href="binutils-pass2.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; href="gcc-pass2.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"; href="tcl.xml"/>

Modified: branches/jh/chapter05/gcc-pass1.xml
===================================================================
--- branches/jh/chapter05/gcc-pass1.xml 2012-04-19 14:58:06 UTC (rev 9813)
+++ branches/jh/chapter05/gcc-pass1.xml 2012-04-19 20:17:38 UTC (rev 9814)
@@ -62,6 +62,50 @@
 tar -zxf ../mpc-&mpc-version;.tar.gz
 mv -v mpc-&mpc-version; mpc</userinput></screen>
 
+    <para>The following command will change the location of GCC's default
+    dynamic linker to use the one installed in
+    <filename class="directory">/tools</filename>. It also removes <filename
+    class="directory">/usr/include</filename> from GCC's include search path.
+    Issue:</para>
+ 
+<screen><userinput remap="pre">for file in \
+ $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
+do
+  cp -uv $file{,.orig}
+  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&amp;@g' \
+  -e 's@/usr@/tools@g' $file.orig &gt; $file
+  echo '
+#undef STANDARD_STARTFILE_PREFIX_1
+#undef STANDARD_STARTFILE_PREFIX_2
+#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
+#define STANDARD_STARTFILE_PREFIX_2 ""' &gt;&gt; $file
+  touch $file.orig
+done</userinput></screen>
+    
+    <para>In case the above seems hard to follow, let's break it down a bit.
+    First we find all the files under the
+    <filename class="directory">gcc/config</filename> directory that are named
+    either <filename>linux.h</filename>, <filename>linux64.h</filename> or
+    <filename>sysv4.h</filename>.
+    For each file found, we copy it to a file of the same name but with an 
added
+    suffix of <quote>.orig</quote>. Then the first sed expression prepends
+    <quote>/tools</quote> to every instance of <quote>/lib/ld</quote>,
+    <quote>/lib64/ld</quote> or <quote>/lib32/ld</quote>, while the second one
+    replaces hard-coded instances of <quote>/usr</quote>. Next, we add our 
define
+    statements which alter the default startfile prefix
+    to the end of the file. Note that the trailing <quote>/</quote> in
+    <quote>/tools/lib/</quote> is required.
+    Finally, we use <command>touch</command> to update the timestamp on the 
copied files.
+    When used in conjunction with <command>cp -u</command>, this prevents 
unexpected
+    changes to the original files in case the commands are inadvertently run 
twice.
+    </para> 
+ 
+    <para>Set the location GCC will search for its system headers:</para>
+
+<screen><userinput remap="pre">cp gcc/Makefile.in{,.orig}
+sed '/^CROSS_SYSTEM_HEADER_DIR/s@= .*@= /tools/include@' \
+    gcc/Makefile.in.orig &gt; gcc/Makefile.in</userinput></screen>
+
     <para>The GCC documentation recommends building GCC outside of the
     source directory in a dedicated build directory:</para>
 
@@ -73,6 +117,10 @@
 <screen><userinput remap="configure">../gcc-&gcc-version;/configure         \
     --target=$LFS_TGT          \
     --prefix=/tools            \
+    --with-sysroot=$LFS        \
+    --with-newlib              \
+    --without-headers          \
+    --with-local-prefix=/tools \
     --disable-nls              \
     --disable-shared           \
     --disable-multilib         \
@@ -92,6 +140,35 @@
       <title>The meaning of the configure options:</title>
 
       <varlistentry>
+         <term><parameter>--with-newlib</parameter></term>
+         <listitem>
+           <para>Since a working C library is not yet available, this ensures
+           that the inhibit_libc constant is defined when building libgcc. 
This prevents
+           the compiling of any code that requires libc support.</para>
+         </listitem>
+       </varlistentry>
+ 
+       <varlistentry>
+         <term><parameter>--without-headers</parameter></term>
+         <listitem>
+           <para>When creating a complete cross-compiler, GCC requires
+           standard headers compatible with the target system. For our
+           purposes these headers will not be needed. This switch prevents
+           GCC from looking for them.</para>
+         </listitem>
+       </varlistentry>
+ 
+       <varlistentry>
+         <term><parameter>--with-local-prefix=/tools</parameter></term>
+         <listitem>
+           <para>The local prefix is the location in the system that GCC will 
search
+           for locally installed include files. The default is 
<filename>/usr/local</filename>.
+           Setting this to <filename>/tools</filename> helps keep the host 
location of
+           <filename>/usr/local</filename> out of this GCC's search 
path.</para>
+         </listitem>
+       </varlistentry>
+ 
+       <varlistentry>
         <term><parameter>--disable-shared</parameter></term>
         <listitem>
           <para>This switch forces GCC to link its internal libraries

Modified: branches/jh/chapter05/gcc-pass2.xml
===================================================================
--- branches/jh/chapter05/gcc-pass2.xml 2012-04-19 14:58:06 UTC (rev 9813)
+++ branches/jh/chapter05/gcc-pass2.xml 2012-04-19 20:17:38 UTC (rev 9814)
@@ -42,17 +42,21 @@
 
   <sect2 role="installation">
     <title>Installation of GCC</title>
+    <para>Our first build of GCC has installed a couple of internal system 
headers.
+    Normally one of them, <filename>limits.h</filename> will in turn include 
the
+    corresponding system <filename>limits.h</filename> header, in this case,
+    <filename>/tools/include/limits.h</filename>. However, at the time of the 
first
+    build of gcc <filename>/tools/include/limits.h</filename> did not exist, 
so the
+    internal header that GCC installed is a partial, self-contained file
+    and does not include the extended features of the system header. This was
+    adequate for building the temporary libc, but this build of GCC now 
requires
+    the full internal header.
+    Create a full version of the internal header using a command that is 
identical
+    to what the GCC build system does in normal circumstances:</para>
 
-    <para>Versions of GCC later than 4.3 will treat this build as if
-    it were a relocated compiler and disallow searching for startfiles in
-    the location specified by <parameter>--prefix</parameter>. Since this
-    will not be a relocated compiler, and the startfiles in
-    <filename class="directory">/tools</filename> are crucial to building
-    a working compiler linked to the libs in <filename 
class="directory">/tools</filename>,
-    apply the following patch which partially reverts GCC to its old 
behavior:</para>
+<screen><userinput remap="pre">cat gcc/limitx.h gcc/glimits.h gcc/limity.h 
&gt; \
+  `dirname $($LFS_TGT-gcc 
-print-libgcc-file-name)`/include-fixed/limits.h</userinput></screen>
 
-<screen><userinput remap="pre">patch -Np1 -i 
../&gcc-startfiles-patch;</userinput></screen>
-
     <para>Under normal circumstances the GCC <command>fixincludes</command> 
script
     is run in order to fix potentially broken header files. As 
GCC-&gcc-version;
     and Glibc-&glibc-version; have already been installed at this point, and
@@ -63,8 +67,8 @@
     directory. The running of the <command>fixincludes</command> script can
     be suppressed by issuing the following commands:</para>
 
-<screen><userinput remap="pre">cp -v gcc/Makefile.in{,.orig}
-sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig &gt; 
gcc/Makefile.in</userinput></screen>
+<screen><userinput remap="pre">cp -v gcc/Makefile.in{,.bak1}
+sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.bak1 &gt; 
gcc/Makefile.in</userinput></screen>
 
     <para>For x86 machines, a bootstrap build of GCC uses the
     <option>-fomit-frame-pointer</option> compiler flag.  Non-bootstrap builds
@@ -72,18 +76,13 @@
     that is exactly the same as if it were bootstrapped.  Apply the following
     <command>sed</command> command to force the build to use the flag:</para> 
 
-<screen><userinput remap="pre">cp -v gcc/Makefile.in{,.tmp}
-sed 's/^T_CFLAGS =$/&amp; -fomit-frame-pointer/' gcc/Makefile.in.tmp \
+<screen><userinput remap="pre">cp -v gcc/Makefile.in{,.bak2}
+sed 's/^T_CFLAGS =$/&amp; -fomit-frame-pointer/' gcc/Makefile.in.bak2 \
   &gt; gcc/Makefile.in</userinput></screen>
 
-    <para>The following command will change the location of GCC's default
-    dynamic linker to use the one installed in
-    <filename class="directory">/tools</filename>. It also removes <filename
-    class="directory">/usr/include</filename> from GCC's include search path.
-    Doing this now rather than adjusting the specs file after installation
-    ensures that the new dynamic linker is used during the actual build of
-    GCC. That is, all of the binaries created during the build will link
-    against the new Glibc. Issue:</para>
+    <para>Once again, change the location of GCC's default
+     dynamic linker to use the one installed in
+    <filename class="directory">/tools</filename>.</para>
 
 <screen><userinput remap="pre">for file in \
  $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
@@ -94,40 +93,17 @@
   echo '
 #undef STANDARD_STARTFILE_PREFIX_1
 #undef STANDARD_STARTFILE_PREFIX_2
-#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib"
+#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
 #define STANDARD_STARTFILE_PREFIX_2 ""' &gt;&gt; $file
   touch $file.orig
 done</userinput></screen>
 
-    <para>In case the above seems hard to follow, let's break it down a bit.
-    First we find all the files under the
-    <filename class="directory">gcc/config</filename> directory that are named
-    either <filename>linux.h</filename>, <filename>linux64.h</filename> or
-    <filename>sysv4.h</filename>.
-    For each file found, we copy it to a file of the same name but with an 
added
-    suffix of <quote>.orig</quote>. Then the first sed expression prepends
-    <quote>/tools</quote> to every instance of <quote>/lib/ld</quote>,
-    <quote>/lib64/ld</quote> or <quote>/lib32/ld</quote>, while the second one
-    replaces hard-coded instances of <quote>/usr</quote>. Then we add our 
define
-    statements which alter the include search path and the default startfile 
prefix
-    to the end of the file.
-    Finally, we use <command>touch</command> to update the timestamp on the 
copied files.
-    When used in conjunction with <command>cp -u</command>, this prevents 
unexpected
-    changes to the original files in case the commands are inadvertently run 
twice.
-    </para>
+    <para>Set the location GCC will search for its system headers:</para>
 
-    <para>On x86_64, unsetting the multilib spec for GCC ensures that it
-    won't attempt to link against libraries on the host:</para>
+<screen><userinput remap="pre">cp gcc/Makefile.in{,.bak3}
+sed '/^NATIVE_SYSTEM_HEADER_DIR/s@= .*@= /tools/include@' \
+    gcc/Makefile.in.bak3 &gt; gcc/Makefile.in</userinput></screen>
 
-<screen><userinput remap="pre">case $(uname -m) in
-  x86_64)
-    for file in $(find gcc/config -name t-linux64) ; do \
-      cp -v $file{,.orig}
-      sed '/MULTILIB_OSDIRNAMES/d' $file.orig &gt; $file
-    done
-  ;;
-esac</userinput></screen>
-
     <para>As in the first build of GCC it requires the GMP, MPFR and MPC
     packages. Unpack the tarballs and move them into the required directory
     names:</para>
@@ -149,10 +125,10 @@
 
     <para>Now prepare GCC for compilation:</para>
 
-<screen><userinput remap="configure">CC="$LFS_TGT-gcc -B/tools/lib/" \
+<screen><userinput remap="configure">CC=$LFS_TGT-gcc \
 AR=$LFS_TGT-ar                  \
 RANLIB=$LFS_TGT-ranlib          \
-../gcc-&gcc-version;/configure          \
+../gcc-&gcc-version;/configure  \
     --prefix=/tools             \
     --with-local-prefix=/tools  \
     --enable-clocale=gnu        \

Modified: branches/jh/chapter05/glibc.xml
===================================================================
--- branches/jh/chapter05/glibc.xml     2012-04-19 14:58:06 UTC (rev 9813)
+++ branches/jh/chapter05/glibc.xml     2012-04-19 20:17:38 UTC (rev 9814)
@@ -78,15 +78,15 @@
     <para>Next, prepare Glibc for compilation:</para>
 
 <screen><userinput remap="configure">../glibc-&glibc-version;/configure        
                     \
-      --prefix=/tools                                 \
-      --host=$LFS_TGT                                 \
+      --prefix=/tools                               \
+      --host=$LFS_TGT                               \
       --build=$(../glibc-&glibc-version;/scripts/config.guess) \
-      --disable-profile                               \
-      --enable-add-ons                                \
-      --enable-kernel=2.6.25                          \
-      --with-headers=/tools/include                   \
-      libc_cv_forced_unwind=yes                       \
-      libc_cv_ctors_header=yes                        \
+      --disable-profile                             \
+      --enable-add-ons                              \
+      --enable-kernel=2.6.25                        \
+      --with-headers=/tools/include                 \
+      libc_cv_forced_unwind=yes                     \
+      libc_cv_ctors_header=yes                      \
       libc_cv_c_cleanup=yes</userinput></screen>
 
     <variablelist>
@@ -202,6 +202,42 @@
 
 <screen><userinput remap="install">make install</userinput></screen>
 
+  <caution>
+    <para>At this point, it is imperative to stop and ensure that the basic
+    functions (compiling and linking) of the new toolchain are working as
+    expected. To perform a sanity check, run the following commands:</para>
+
+<screen><userinput>echo 'main(){}' &gt; dummy.c
+$LFS_TGT-gcc dummy.c
+readelf -l a.out | grep ': /tools'</userinput></screen>
+
+    <para>If everything is working correctly, there should be no errors,
+    and the output of the last command will be of the form:</para>
+
+<screen><computeroutput>[Requesting program interpreter: 
/tools/lib/ld-linux.so.2]</computeroutput></screen>
+
+    <para>Note that <filename class="directory">/tools/lib</filename>, or
+    <filename class="directory">/tools/lib64</filename> for 64-bit machines
+    appears as the prefix of the dynamic linker.</para>
+
+    <para>If the output is not shown as above or there was no output at all,
+    then something is wrong. Investigate and retrace the steps to find out
+    where the problem is and correct it. This issue must be resolved before
+    continuing on. Something may have gone wrong with the
+    specs file amendment above. In this case, redo the specs file amendment,
+    being careful to copy-and-paste the commands.</para>
+
+    <para>Once all is well, clean up the test files:</para>
+
+<screen><userinput>rm -v dummy.c a.out</userinput></screen>
+
+  </caution>
+
+  <note><para>Building Binutils in the next section will serve as an 
additional check that
+  the toolchain has been built properly. If Binutils fails to build, it is an
+  indication that something has gone wrong with the previous Binutils, GCC, or 
Glibc
+  installations.</para></note>
+
   </sect2>
 
   <sect2 role="content">

-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-book
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page

Reply via email to