Index: LFS/lfs.xsl
===================================================================
--- LFS/lfs.xsl	(revision 5a4f6a7a9f1b0b4fb6bd51632a488e3fb9d0ce9b)
+++ LFS/lfs.xsl	(revision f5f857df482ed232194daf462a943f492f083147)
@@ -48,4 +48,5 @@
 
 <!-- ########### NAMED USER TEMPLATES TO ALLOW CUSTOMIZATIONS ############## -->
+<!-- ############ Maybe should be placed on a separate file ################ -->
 
     <!-- Hock for user header additions -->
@@ -145,5 +146,6 @@
 
     <!-- Hock for creating a custom tools directory containing scripts
-         to be run after the system has been built -->
+         to be run after the system has been built
+         (to be moved to a separate file) -->
   <xsl:template name="custom-tools">
       <!-- Fixed directory and ch_order values -->
@@ -246,13 +248,9 @@
          and reset the seconds counter -->
   <xsl:template name="unpack">
-    <xsl:choose>
-      <xsl:when test="ancestor::chapter[@id='chapter-temporary-tools']">
-        <xsl:text>cd $SRCDIR</xsl:text>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:text>cd /sources</xsl:text>
-      </xsl:otherwise>
-    </xsl:choose>
-    <xsl:text>
+    <xsl:text>cd </xsl:text>
+    <xsl:if test="ancestor::chapter[@id='chapter-temporary-tools']">
+      <xsl:text>$LFS</xsl:text>
+    </xsl:if>
+    <xsl:text>/sources
 PKGDIR=`tar -tf $TARBALL | head -n1 | sed -e 's@^./@@;s@/.*@@'`
 if [ -d $PKGDIR ]; then
@@ -292,13 +290,9 @@
     <!-- Remove sources and build dirs, skipping it from seconds meassurament -->
   <xsl:template name="clean_sources">
-    <xsl:choose>
-      <xsl:when test="ancestor::chapter[@id='chapter-temporary-tools']">
-        <xsl:text>cd $SRCDIR</xsl:text>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:text>cd /sources</xsl:text>
-      </xsl:otherwise>
-    </xsl:choose>
-    <xsl:text>
+    <xsl:text>cd </xsl:text>
+    <xsl:if test="ancestor::chapter[@id='chapter-temporary-tools']">
+      <xsl:text>$LFS</xsl:text>
+    </xsl:if>
+    <xsl:text>/sources
 SECS=$SECONDS
 rm -rf $PKGDIR
@@ -368,5 +362,28 @@
 
 
-    <!-- Adds blfs-tool support scripts -->
+    <!-- Check if a package testsuite must be run -->
+  <xsl:template name="run_this_test">
+    <xsl:choose>
+      <xsl:when test=".//userinput[@remap='test']">
+        <xsl:choose>
+            <!-- No testsuites run on level 0 -->
+          <xsl:when test="$testsuite = '0'">0</xsl:when>
+            <!-- On level 1, only final system toolchain testsuites are run -->
+          <xsl:when test="$testsuite = '1' and
+                          not(@id='ch-system-gcc') and
+                          not(@id='ch-system-glibc') and
+                          not(@id='ch-system-binutils')">0</xsl:when>
+            <!-- On level 2, temp tools testsuites are not run -->
+          <xsl:when test="$testsuite = '2' and
+                          ../@id='chapter-temporary-tools'">0</xsl:when>
+          <xsl:otherwise>1</xsl:otherwise>
+        </xsl:choose>
+      </xsl:when>
+      <xsl:otherwise>0</xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+
+    <!-- Adds blfs-tool support scripts (to be moved to a separate file) -->
   <xsl:template name="blfs-tool">
       <!-- Fixed directory and ch_order values -->
@@ -476,4 +493,8 @@
         <!-- Script build order -->
       <xsl:variable name="order" select="concat($dirname,'/',$ch_order,'_',$sect1_order)"/>
+        <!-- Must the package test suite, if any, be run? -->
+      <xsl:variable name="run_this_test">
+        <xsl:call-template name="run_this_test"/>
+      </xsl:variable>
         <!-- Hock to insert scripts before the current one -->
       <xsl:call-template name="insert_script_before">
@@ -487,4 +508,6 @@
         <xsl:apply-templates select="sect1info[@condition='script']">
           <xsl:with-param name="phase" select="$filename"/>
+          <xsl:with-param name="run_this_test" select="$run_this_test"/>
+          <xsl:with-param name="testlogfile" select="concat($ch_order,'_',$sect1_order,'-',$filename)"/>
         </xsl:apply-templates>
         <xsl:call-template name="disk_usage"/>
@@ -494,5 +517,7 @@
         <xsl:call-template name="user_pre_commands"/>
         <xsl:call-template name="pre_commands"/>
-        <xsl:apply-templates select=".//screen"/>
+        <xsl:apply-templates select=".//screen">
+          <xsl:with-param name="run_this_test" select="$run_this_test"/>
+        </xsl:apply-templates>
         <xsl:call-template name="post_commands"/>
         <xsl:call-template name="user_footer"/>
@@ -514,4 +539,7 @@
     <!-- sect1info -->
   <xsl:template match="sect1info">
+      <!-- Used to set and initialize the testuite log file -->
+    <xsl:param name="testlogfile" select="foo"/>
+    <xsl:param name="run_this_test" select="foo"/>
       <!-- Build phase (base file name) to be used for PM -->
     <xsl:param name="phase" select="foo"/>
@@ -524,4 +552,13 @@
       <!-- Tarball name -->
     <xsl:apply-templates select="address"/>
+    <xsl:if test="$run_this_test = '1'">
+      <xsl:text>&#xA;TEST_LOG=</xsl:text>
+      <xsl:if test="ancestor::chapter[@id='chapter-temporary-tools']">
+        <xsl:text>$LFS</xsl:text>
+      </xsl:if>
+      <xsl:text>/jhalfs/test-logs/</xsl:text>
+      <xsl:value-of select="$testlogfile"/>
+      <xsl:text>&#xA;echo -e "\n`date`\n" > $TEST_LOG</xsl:text>
+    </xsl:if>
     <xsl:text>&#xA;&#xA;</xsl:text>
   </xsl:template>
@@ -568,10 +605,22 @@
     <!-- screen -->
   <xsl:template match="screen">
+    <xsl:param name="run_this_test" select="foo"/>
     <xsl:if test="child::* = userinput and not(@role = 'nodump')">
       <xsl:call-template name="top_screen_build_fixes"/>
-      <xsl:apply-templates/>
+      <xsl:apply-templates>
+        <xsl:with-param name="run_this_test" select="$run_this_test"/>
+      </xsl:apply-templates>
       <xsl:call-template name="bottom_screen_build_fixes"/>
       <xsl:text>&#xA;</xsl:text>
     </xsl:if>
+  </xsl:template>
+
+
+    <!-- userinput @remap='test' -->
+  <xsl:template match="userinput[@remap='test']">
+    <xsl:param name="run_this_test" select="foo"/>
+    <xsl:apply-templates select="." mode="test">
+      <xsl:with-param name="run_this_test" select="$run_this_test"/>
+    </xsl:apply-templates>
   </xsl:template>
 
@@ -592,10 +641,4 @@
   <xsl:template match="userinput[@remap='make']">
     <xsl:apply-templates select="." mode="make"/>
-  </xsl:template>
-
-
-    <!-- userinput @remap='test' -->
-  <xsl:template match="userinput[@remap='test']">
-    <xsl:apply-templates select="." mode="test"/>
   </xsl:template>
 
@@ -670,71 +713,59 @@
     <!-- mode test  -->
   <xsl:template match="userinput" mode="test">
-    <xsl:choose>
-        <!-- No testsuites run on level 0 -->
-      <xsl:when test="$testsuite = '0'"/>
-        <!-- On level 1, only final system toolchain testsuites are run -->
-      <xsl:when test="$testsuite = '1' and
-                      not(ancestor::sect1[@id='ch-system-gcc']) and
-                      not(ancestor::sect1[@id='ch-system-glibc']) and
-                      not(ancestor::sect1[@id='ch-system-binutils'])"/>
-        <!-- On level 2, temp tools testsuites are not run -->
-      <xsl:when test="$testsuite = '2' and
-                      ancestor::chapter[@id='chapter-temporary-tools']"/>
-        <!-- Start testsuites command fixes -->
-      <xsl:otherwise>
-        <xsl:choose>
-            <!-- Final system Glibc -->
-          <xsl:when test="contains(string(),'glibc-check-log')">
-            <xsl:value-of select="substring-before(string(),'2&gt;&amp;1')"/>
-            <xsl:text>&gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
-          </xsl:when>
-            <!-- Module-Init-Tools -->
-          <xsl:when test="ancestor::sect1[@id='ch-system-module-init-tools']
-                          and contains(string(),'make check')">
-            <xsl:value-of select="substring-before(string(),' check')"/>
-            <xsl:if test="$bomb-testsuite = 'n'">
-              <xsl:text> -k</xsl:text>
-            </xsl:if>
-            <xsl:text> check &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
-            <xsl:if test="$bomb-testsuite = 'n'">
-              <xsl:text> || true</xsl:text>
-            </xsl:if>
-            <xsl:value-of select="substring-after(string(),' check')"/>
-          </xsl:when>
-            <!-- If the book uses -k, the testsuite should never bomb -->
-          <xsl:when test="contains(string(),'make -k ')">
-            <xsl:apply-templates select="." mode="default"/>
-            <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
-          </xsl:when>
-            <!-- Extra commands in Binutils and GCC -->
-          <xsl:when test="contains(string(),'test_summary') or
-                          contains(string(),'expect -c')">
-            <xsl:apply-templates select="." mode="default"/>
-            <xsl:text> &gt;&gt; $TEST_LOG</xsl:text>
-          </xsl:when>
-            <!-- Remaining extra testsuite commads that don't need be hacked -->
-          <xsl:when test="not(contains(string(),'make '))">
-            <xsl:apply-templates select="." mode="default"/>
-          </xsl:when>
-            <!-- Normal testsites run -->
-          <xsl:otherwise>
-            <xsl:choose>
-                <!-- No bomb on failures -->
-              <xsl:when test="$bomb-testsuite = 'n'">
-                <xsl:value-of select="substring-before(string(),'make ')"/>
-                <xsl:text>make -k </xsl:text>
-                <xsl:value-of select="substring-after(string(),'make ')"/>
-                <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
-              </xsl:when>
-                <!-- Bomb at the first failure -->
-              <xsl:otherwise>
-                <xsl:apply-templates select="." mode="default"/>
-                <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
-              </xsl:otherwise>
-            </xsl:choose>
-          </xsl:otherwise>
-        </xsl:choose>
-      </xsl:otherwise>
-    </xsl:choose>
+    <xsl:param name="run_this_test" select="foo"/>
+    <xsl:if test="$run_this_test = '1'">
+      <xsl:choose>
+          <!-- Final system Glibc -->
+        <xsl:when test="contains(string(),'glibc-check-log')">
+          <xsl:value-of select="substring-before(string(),'2&gt;&amp;1')"/>
+          <xsl:text>&gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
+        </xsl:when>
+          <!-- Module-Init-Tools -->
+        <xsl:when test="ancestor::sect1[@id='ch-system-module-init-tools']
+                        and contains(string(),'make check')">
+          <xsl:value-of select="substring-before(string(),' check')"/>
+          <xsl:if test="$bomb-testsuite = 'n'">
+            <xsl:text> -k</xsl:text>
+          </xsl:if>
+          <xsl:text> check &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
+          <xsl:if test="$bomb-testsuite = 'n'">
+            <xsl:text> || true</xsl:text>
+          </xsl:if>
+          <xsl:value-of select="substring-after(string(),' check')"/>
+        </xsl:when>
+          <!-- If the book uses -k, the testsuite should never bomb -->
+        <xsl:when test="contains(string(),'make -k ')">
+          <xsl:apply-templates select="." mode="default"/>
+          <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
+        </xsl:when>
+          <!-- Extra commands in Binutils and GCC -->
+        <xsl:when test="contains(string(),'test_summary') or
+                        contains(string(),'expect -c')">
+          <xsl:apply-templates select="." mode="default"/>
+          <xsl:text> &gt;&gt; $TEST_LOG</xsl:text>
+        </xsl:when>
+          <!-- Remaining extra testsuite commads that don't need be hacked -->
+        <xsl:when test="not(contains(string(),'make '))">
+          <xsl:apply-templates select="." mode="default"/>
+        </xsl:when>
+          <!-- Normal testsites run -->
+        <xsl:otherwise>
+          <xsl:choose>
+              <!-- No bomb on failures -->
+            <xsl:when test="$bomb-testsuite = 'n'">
+              <xsl:value-of select="substring-before(string(),'make ')"/>
+              <xsl:text>make -k </xsl:text>
+              <xsl:value-of select="substring-after(string(),'make ')"/>
+              <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1 || true</xsl:text>
+            </xsl:when>
+              <!-- Bomb at the first failure -->
+            <xsl:otherwise>
+              <xsl:apply-templates select="." mode="default"/>
+              <xsl:text> &gt;&gt; $TEST_LOG 2&gt;&amp;1</xsl:text>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:if>
   </xsl:template>
 
Index: LFS/master.sh
===================================================================
--- LFS/master.sh	(revision 5a4f6a7a9f1b0b4fb6bd51632a488e3fb9d0ce9b)
+++ LFS/master.sh	(revision f5f857df482ed232194daf462a943f492f083147)
@@ -52,12 +52,9 @@
 	echo "umask 022" >> \$(LUSER_HOME)/.bashrc && \\
 	echo "LFS=\$(MOUNT_PT)" >> \$(LUSER_HOME)/.bashrc && \\
-	echo "SRCDIR=\$(MOUNT_PT)/sources" >> \$(LUSER_HOME)/.bashrc && \\
 	echo "LC_ALL=POSIX" >> \$(LUSER_HOME)/.bashrc && \\
 	echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
 	echo "export LFS LC_ALL PATH" >> \$(LUSER_HOME)/.bashrc && \\
 	echo "source $JHALFSDIR/envars" >> \$(LUSER_HOME)/.bashrc && \\
-	chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc && \\
-	touch envars && \\
-	chown \$(LUSER) envars
+	chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc
 	@\$(call housekeeping)
 EOF
@@ -96,7 +93,4 @@
     esac
 
-    # Grab the package name, if the script is building a package
-    name=`grep "^PACKAGE=" ${file} | sed -e 's@PACKAGE=@@'`
-
     # Set the dependency for the first target.
     if [ -z $PREV ] ; then PREV=04_04-settingenvironment ; fi
@@ -109,12 +103,4 @@
     # as a dependency. Also call the echo_message function.
     LUSER_wrt_target "${this_script}" "$PREV"
-
-    # If $name isn't empty, we've got a package...
-    if [ "$name" != "" ] ; then
-      # If the testsuites must be run, initialize the log file
-      [[ "$TEST" = "3" ]] && LUSER_wrt_test_log "${this_script}"
-      # If using optimizations, write the instructions
-      [[ "$OPTIMIZE" = "2" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
-    fi
 
     # Run the script.
@@ -176,5 +162,5 @@
     esac
 
-    # Grab the name of the target.
+    # Grab the name of the package, if any.
     name=`grep "^PACKAGE=" ${file} | sed -e 's@PACKAGE=@@'`
 
@@ -208,22 +194,8 @@
     esac
 
-    # If $name isn't empty, we've got a package...
-    if [ "$name" != "" ] ; then
-      # Touch timestamp file if installed files logs will be created.
-      # But only for the firt build when running iterative builds.
-      if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
-        CHROOT_wrt_TouchTimestamp
-      fi
-      # If the testsuites must be run, initialize the log file
-      case $name in
-        binutils | gcc | glibc )
-          [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
-          ;;
-        * )
-          [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
-          ;;
-      esac
-      # If using optimizations, write the instructions
-      [[ "$OPTIMIZE" != "0" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
+    # Touch timestamp file if installed files logs will be created.
+    # But only for the firt build when running iterative builds.
+    if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
+      CHROOT_wrt_TouchTimestamp
     fi
 
@@ -363,4 +335,5 @@
             sed -e "s@chroot@$CHROOT_LOC@" \
                 -e 's@ \\\@ @g' \
+                -e 's/  */ /g' \
                 -e 's|\\$|&&|g' \
                 -e 's|"$$LFS"|$(MOUNT_PT)|' \
Index: common/libs/func_wrt_Makefile
===================================================================
--- common/libs/func_wrt_Makefile	(revision 5a4f6a7a9f1b0b4fb6bd51632a488e3fb9d0ce9b)
+++ common/libs/func_wrt_Makefile	(revision f5f857df482ed232194daf462a943f492f083147)
@@ -59,5 +59,5 @@
 
 #----------------------------------#
-LUSER_wrt_target() {               # Create target and initialize envars file
+LUSER_wrt_target() {               # Create target
 #----------------------------------#
   local i=$1
@@ -69,5 +69,4 @@
 	@\$(call echo_message, Building)
 	@export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
-	@rm -f envars && touch envars
 EOF
 ) >> $MKFILE.tmp
@@ -85,34 +84,4 @@
 	@\$(call echo_message, Building)
 	@export BASHBIN=\$(SHELL) && \$(SHELL) progress_bar.sh \$@ \$\$PPID &
-	@rm -f envars && touch envars
-EOF
-) >> $MKFILE.tmp
-}
-
-#=======================
-
-
-#===== TESTS LOGS ======
-
-#----------------------------------#
-LUSER_wrt_test_log() {             # Initialize testsuite log file
-#----------------------------------#
-  local TESTLOGFILE=$1
-(
-cat  << EOF
-	@echo "export  TEST_LOG=\$(TESTLOGDIR)/$TESTLOGFILE" >> envars && \\
-	echo "\$(nl_)\`date\`\$(nl_)" > \$(TESTLOGDIR)/\$@
-EOF
-) >> $MKFILE.tmp
-}
-
-#----------------------------------#
-CHROOT_wrt_test_log() {            #
-#----------------------------------#
-  local TESTLOGFILE=$1
-(
-cat  << EOF
-	@echo "export TEST_LOG=\$(crTESTLOGDIR)/$TESTLOGFILE" >> envars && \\
-	echo "\$(nl_)\`date\`\$(nl_)" > test-logs/\$@
 EOF
 ) >> $MKFILE.tmp
@@ -153,5 +122,5 @@
 (
 cat << EOF
-	@source ~/.bashrc && \$(CMDSDIR)/`dirname $file`/\$@ > logs/\$@ 2>&1
+	@\$(CMDSDIR)/`dirname $file`/\$@ > logs/\$@ 2>&1
 EOF
 ) >> $MKFILE.tmp
@@ -164,5 +133,5 @@
 (
 cat << EOF
-	@source envars && \$(crCMDSDIR)/`dirname $file`/\$@ > logs/\$@ 2>&1
+	@\$(crCMDSDIR)/`dirname $file`/\$@ > logs/\$@ 2>&1
 EOF
 ) >> $MKFILE.tmp
