<commit_before>Index: LFS/master.sh
===================================================================
--- LFS/master.sh	(revision 2905)
+++ LFS/master.sh	(working copy)
@@ -173,6 +173,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If $this_script corresponds to a paco script, then skip it
+    case "${this_script}" in
+      *paco)       continue ;;
+    esac
+
     # We'll run the chroot commands differently than the others, so skip them in the
     # dependencies and target creation.
     case "${this_script}" in
@@ -180,6 +185,18 @@
       *stripping*) [[ "${STRIP}" = "0" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-libc-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-libc-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target
     name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
 
@@ -232,7 +249,9 @@
     # and not to use chroot.
     case "${this_script}" in
       *kernfs)  wrt_RunAsRoot    "${this_script}" "$file" ;;
-      *)        wrt_run_as_chroot1 "${this_script}" "$file" ;;
+      *)        wrt_paco_prep
+                wrt_run_as_chroot1 "${this_script}" "$file"
+                wrt_paco_log "$pkg_tarball" ;;
     esac
 
     # Remove the build directory(ies) except if the package build fails.
@@ -252,6 +271,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$chapter6
+
+    # Reinstalling paco after readsjusting the toolchain.
+    case "${this_script}" in
+      *readjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo ${this_script} | sed -e 's/readjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done # end for file in chapter06/*
 }
 
@@ -312,8 +341,15 @@
               else
                 wrt_run_as_chroot2 "$this_script" "$file"
               fi
+              wrt_paco_log "lfs-sysconf"
         ;;
+      *kernel | *bootscripts )
+              wrt_paco_prep
+              wrt_run_as_chroot2 "$this_script" "$file"
+              wrt_paco_log "$pkg_tarball"
+        ;;
       *)        wrt_run_as_chroot2 "$this_script" "$file"
+                wrt_paco_log "lfs-sysconf"
         ;;
     esac
 
Index: LFS/lfs.xsl
===================================================================
--- LFS/lfs.xsl	(revision 2905)
+++ LFS/lfs.xsl	(working copy)
@@ -39,6 +39,9 @@
   <!-- Locale settings -->
   <xsl:param name="lang" select="C"/>
 
+  <!-- Use paco? -->
+  <xsl:param name="use_paco" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -239,6 +242,33 @@
         <xsl:apply-templates/>
         <xsl:text> || true&#xA;</xsl:text>
       </xsl:when>
+      <!-- paco begin -->
+      <!-- General rule -->
+      <xsl:when test="$use_paco != '0' and
+                ancestor::chapter[@id != 'chapter-temporary-tools'] and
+                contains(string(),'make') and
+                contains(string(),'install')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- Linux-libc-headers -->
+      <xsl:when test="$use_paco != '0' and
+                ancestor::sect1[@id='ch-system-linux-libc-headers'] and
+                contains(string(),'install ')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- Unset LD_PRELOAD before second make in Zlib -->
+      <xsl:when test="$use_paco != '0' and
+                ancestor::sect1[@id='ch-system-zlib'] and
+                contains(string(),'make clean')">
+        <xsl:text>unset LD_PRELOAD&#xA;</xsl:text>
+        <xsl:apply-templates/>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- paco end -->
       <!-- The rest of commands -->
       <xsl:otherwise>
         <xsl:apply-templates/>
Index: CLFS/master.sh
===================================================================
--- CLFS/master.sh	(revision 2905)
+++ CLFS/master.sh	(working copy)
@@ -495,6 +495,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If $this_script corresponds to a paco script, then skip it
+    case "${this_script}" in
+      *paco)       continue ;;
+    esac
+
     # Test if the stripping phase must be skipped.
     # Skip alsp temp-perl for iterative runs
     case $this_script in
@@ -502,6 +507,18 @@
       *temp-perl*) [[ -n "$N" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target, strip id number, XXX-script
     name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
                                   -e 's@temp-@@' \
@@ -554,7 +571,9 @@
       [[ "$OPTIMIZE" != "0" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
     fi
     #
+    wrt_paco_prep
     wrt_run_as_chroot1 "${this_script}" "${file}"
+    wrt_paco_log "$pkg_tarball"
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
     #
@@ -569,6 +588,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$basicsystem
+
+    # Reinstalling paco after readsjusting the toolchain.
+    case "${this_script}" in
+      *adjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo ${this_script} | sed -e 's/adjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done  # for file in final-system/* ...
 }
 
@@ -605,6 +634,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If $this_script corresponds to a paco script, then skip it
+    case "${this_script}" in
+      *paco)       continue ;;
+    esac
+
     # Test if the stripping phase must be skipped
     # Skip alsp temp-perl for iterative runs
     case $this_script in
@@ -612,6 +646,18 @@
       *temp-perl*) [[ -n "$N" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target, strip id number, XXX-script
     name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
                                   -e 's@temp-@@' \
@@ -666,7 +712,9 @@
       [[ "$OPTIMIZE" != "0" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
     fi
     #
+    wrt_paco_prep
     wrt_run_as_root2 "${this_script}" "${file}"
+    wrt_paco_log "$pkg_tarball"
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs2 "${name}"
     #
@@ -681,6 +729,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$basicsystem
+
+    # Reinstalling paco after readsjusting the toolchain.
+    case "${this_script}" in
+      *adjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo ${this_script} | sed -e 's/adjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done  # for file in final-system/* ...
 }
 
@@ -729,7 +787,17 @@
     #
     [[ "$pkg_tarball" != "" ]] && wrt_unpack2 "$pkg_tarball"
     #
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_prep ;;
+    esac
     wrt_run_as_chroot1 "${this_script}" "${file}"
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_log "$pkg_tarball" ;;
+      *)
+        wrt_paco_log "clfs-sysconf" ;;
+    esac
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
     #
@@ -791,7 +859,17 @@
     #
     [[ "$pkg_tarball" != "" ]] && wrt_unpack3 "$pkg_tarball"
     #
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_prep ;;
+    esac
     wrt_run_as_root2 "${this_script}" "${file}"
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_log "$pkg_tarball" ;;
+      *)
+        wrt_paco_log "clfs-sysconf" ;;
+    esac
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs2 "${name}"
     #
@@ -863,8 +941,13 @@
                 else
                   wrt_run_as_chroot1  "${this_script}" "${file}"
                 fi
+                wrt_paco_log "clfs-sysconf"
           ;;
-      *)  wrt_run_as_chroot1  "${this_script}" "${file}"   ;;
+      *kernel)  wrt_paco_prep
+                wrt_run_as_chroot1  "${this_script}" "${file}"
+                wrt_paco_log "$pkg_tarball" ;;
+      *)  wrt_run_as_chroot1  "${this_script}" "${file}"
+          wrt_paco_log "clfs-sysconf" ;;
     esac
     #
     # Housekeeping...remove any build directory(ies) except if the package build fails.
@@ -942,8 +1025,13 @@
                 else
                   wrt_run_as_root2  "${this_script}" "${file}"
                 fi
+                wrt_paco_log "clfs-sysconf"
           ;;
-      *)  wrt_run_as_root2  "${this_script}" "${file}"   ;;
+      *kernel)  wrt_paco_prep
+                wrt_run_as_root2  "${this_script}" "${file}"
+                wrt_paco_log "$pkg_tarball"   ;;
+      *)  wrt_run_as_root2  "${this_script}" "${file}"
+          wrt_paco_log "clfs-sysconf"   ;;
     esac
     #
     # Housekeeping...remove any build directory(ies) except if the package build fails.
Index: CLFS/clfs.xsl
===================================================================
--- CLFS/clfs.xsl	(revision 2905)
+++ CLFS/clfs.xsl	(working copy)
@@ -45,6 +45,9 @@
   <!-- Locale settings -->
   <xsl:param name="lang" select="C"/>
 
+  <!-- Use paco? -->
+  <xsl:param name="use_paco" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -106,6 +109,25 @@
                 <xsl:text>tar -xvf ../vim-&vim-version;-lang.* --strip-components=1&#xA;</xsl:text>
               </xsl:if>
             </xsl:if>
+            <!-- paco begin -->
+            <!-- General rule -->
+            <xsl:if test="$use_paco != '0' and 
+                    @id='ch-scripts-bootscripts' or
+                    @id='ch-scripts-udev-rules' or
+                    @id='ch-bootable-kernel' or
+                    (../@id='chapter-building-system' and
+                    @id!='ch-system-temp-perl' and
+                    contains(string(),'make') and
+                    contains(string(),'install'))">
+              <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+            </xsl:if>
+            <!-- Linux headers -->
+            <xsl:if test="$use_paco != '0' and
+                    @id='ch-system-linux-headers' and
+                    contains(string(),'install')">
+              <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+            </xsl:if>
+            <!-- paco end -->
             <xsl:apply-templates select=".//para/userinput | .//screen"/>
             <xsl:text>exit</xsl:text>
           </exsl:document>
Index: common/paco-build-hlfs.sh
===================================================================
--- common/paco-build-hlfs.sh	(revision 0)
+++ common/paco-build-hlfs.sh	(revision 0)
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+cd $PKGDIR
+./configure --sysconfdir=/etc \
+	--enable-scripts \
+	--disable-gpaco \
+	--disable-static \
+	--with-pic &&
+make &&
+make install &&
+make logme
Index: common/config
===================================================================
--- common/config	(revision 2905)
+++ common/config	(working copy)
@@ -91,6 +91,23 @@
 #--- Run farce testing 0(no)/1(yes)
 RUN_FARCE=0
 
+#==== PACO VARIABLES ====
+#--- Use paco? 0(no)/1(yes)
+USE_PACO=1
+PACO_VERSION=1.10.10
+
+#--- Name of the Paco source package
+PACO_FILE=paco-$PACO_VERSION.tar.bz2   # (use .tar.gz if preferred)
+
+#--- Sourceforge mirror to use for Paco source download
+# Europe: heanet, belnet, puzzle, surfnet, switch, kent
+# North America: superb-east, superb-west, umn, easynews
+# South America: ufpr
+# Asia: nchc, jaist
+# Australia: optusnet
+PACO_MIRROR1=heanet
+PACO_MIRROR2=kent
+
 #==== INTERNAL VARIABLES ====
 # Don't edit it unless you know what you are doing
 
@@ -108,3 +125,9 @@
 
 #--- farce report log directory
 FARCELOGDIR=$LOGDIR/farce
+
+#--- Variables needed by paco
+PACO_INCLUDE=/
+PACO_EXCLUDE=/${SCRIPT_ROOT}
+PACO_TMPFILE=/tmp/paco.tmp
+LD_PRELOAD=/usr/lib/libpaco-log.so
Index: common/func_validate_configs.sh
===================================================================
--- common/func_validate_configs.sh	(revision 2905)
+++ common/func_validate_configs.sh	(working copy)
@@ -86,10 +86,10 @@
 inline_doc
 
   # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
-  local -r  hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL KEYMAP         PAGE TIMEZONE LANG LC_ALL LUSER LGROUP"
-  local -r  clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD  ARCH  TARGET  TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
-  local -r clfs2_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE         ARCH  TARGET                 OPTIMIZE REPORT                                      STRIP FSTAB             CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
-  local -r   lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE                       TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL        VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
+  local -r  hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE USE_PACO GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL KEYMAP         PAGE TIMEZONE LANG LC_ALL LUSER LGROUP"
+  local -r  clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE USE_PACO GETPKG RUNMAKE METHOD  ARCH  TARGET  TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
+  local -r clfs2_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE          GETPKG RUNMAKE         ARCH  TARGET                 OPTIMIZE REPORT                                      STRIP FSTAB             CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
+  local -r   lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE USE_PACO GETPKG RUNMAKE                       TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL        VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
 
   local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
   local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
@@ -179,6 +179,7 @@
                     [[ "$GETPKG" = "1" ]] && validate_against_str "x0x x1x"
                   fi ;;
       RUNMAKE)    validate_against_str "x0x x1x" ;;
+      USE_PACO)   validate_against_str "x0x x1x" ;;
       REPORT)     validate_against_str "x0x x1x"
                   if [[ "${!config_param}" = "1" ]]; then
                     if [[ `type -p bc` ]]; then
Index: common/paco-functions
===================================================================
--- common/paco-functions	(revision 0)
+++ common/paco-functions	(revision 0)
@@ -0,0 +1,311 @@
+#!/bin/bash
+
+#----------------------------#
+wrt_paco_inst() {            #
+#----------------------------#
+
+local paco_script="$1"
+
+check_build_model
+
+if [ $USE_PACO != 0 ]; then
+  case $PROGNAME in 
+    clfs )
+      paco_file="final-system/$paco_script"
+      basicsystem="$basicsystem $paco_script" ;;
+    * )
+      paco_file="chapter06/$paco_script"
+      chapter6="$chapter6 $paco_script" ;;
+  esac
+
+  # Copy the paco build script to the correct directory and make it executable
+  cp $JHALFSDIR/paco-build-$PROGNAME.sh $JHALFSDIR/${PROGNAME}-commands/$paco_file &&
+  chmod +x $JHALFSDIR/${PROGNAME}-commands/$paco_file
+
+  # Write target, dependency and unpack
+  if [ $CLFS_BOOT = 1 ]; then
+    wrt_target_boot "$paco_script" "$PREV"
+    wrt_unpack3 "$PACO_FILE"
+    wrt_run_as_root2 "${paco_script}" "${paco_file}"
+    wrt_remove_build_dirs2 "paco"
+  else 
+    wrt_target "$paco_script" "$PREV"
+    wrt_unpack2 "$PACO_FILE"
+    wrt_run_as_chroot1 "${paco_script}" "${paco_file}"
+    wrt_remove_build_dirs "paco"
+  fi
+
+  wrt_touch
+
+  # Override the PREV variable
+  PREV="$paco_script"
+fi
+}
+
+
+#----------------------------------#
+wrt_paco_prep() {                  # Export Paco variables
+#----------------------------------# and remove tmpfile
+
+local TMPFILEPATH
+
+check_build_model
+
+check_log_package
+
+if [ $USE_PACO != 0 ] && [ $LOG_PACKAGE != 0 ]; then
+  if [ $CLFS_BOOT = 1 ]; then
+    TMPFILEPATH="$PACO_TMPFILE"
+  else
+    TMPFILEPATH="\$(MOUNT_PT)$PACO_TMPFILE"
+  fi
+(
+cat  << EOF
+	@echo "export PACO_INCLUDE=$PACO_INCLUDE" >> envars && \\
+	echo "export PACO_EXCLUDE=\$(SRC):$PACO_EXCLUDE" >> envars && \\
+	echo "export PACO_TMPFILE=$PACO_TMPFILE" >> envars && \\
+	rm -f $TMPFILEPATH
+EOF
+) >> $MKFILE.tmp
+fi
+}
+
+
+#----------------------------------#
+wrt_paco_log() {                   # If the tmpfile exist, then log the current package
+#----------------------------------# and remove tempfile
+local PACKAGE
+
+# Extract package name and version from the tarball name
+PACKAGE=`echo $1 | sed -e 's/.tar.*//'`
+
+check_build_model
+
+# Check if the package should be logged
+check_log_package
+
+
+if [ $USE_PACO != 0 ]; then
+  if [ $LOG_PACKAGE != 0 ]; then
+    # Only use this if doing CLFS boot build
+    if [ $CLFS_BOOT = 1 ]; then
+(
+cat << EOF
+	@if [ -e $PACO_TMPFILE ]; then \\
+		paco -lp+ $PACKAGE < $PACO_TMPFILE && \\
+		rm -f $PACO_TMPFILE; \\
+	fi;
+EOF
+) >> $MKFILE.tmp
+    # All else should use these commands
+    else
+(
+cat << EOF
+	@if [ -e \$(MOUNT_PT)$PACO_TMPFILE ]; then \\
+		\$(CHROOT1) 'paco -lp+ $PACKAGE < $PACO_TMPFILE' && \\
+		rm -f \$(MOUNT_PT)$PACO_TMPFILE; \\
+	fi;
+EOF
+) >> $MKFILE.tmp
+    fi
+  fi
+  # Add missing files to the logs if needed
+  wrt_paco_add_log
+fi
+}
+
+
+#----------------------------------#
+fnc_add_log() {                    #
+#----------------------------------#
+
+MISSING_FILE=$1
+
+if [ $CLFS_BOOT = 1 ]; then
+  echo -e "\t@$MISSING_FILE | paco -lp+ $PACKAGE" >> $MKFILE.tmp
+else
+  echo -e "\t@\$(CHROOT1) '$MISSING_FILE | paco -lp+ $PACKAGE'" >> $MKFILE.tmp
+fi
+}
+
+
+#----------------------------------#
+wrt_paco_add_log() {               #
+#----------------------------------#
+# Some packages create files using bash redirection, which the LD_PRELOAD lib don't notice
+# These rules will add the missing files to the proper logs.
+# Most of these is not needed for HLFS, but they do no harm.
+if [ $USE_PACO != 0 ]; then
+ case $this_script in
+    *glibc)
+      fnc_add_log "find /lib -type l"
+      fnc_add_log "find /etc/{nsswitch.conf,ld.so.conf}"
+    ;;
+    *ncurses)
+      fnc_add_log "find /usr/lib/{libcurses.so,libncurses.so,libform.so,libpanel.so,libmenu.so}"
+    ;;
+    *bash)
+      fnc_add_log "echo /bin/sh"
+    ;;
+    *flex)
+      fnc_add_log "echo /usr/bin/lex"
+    ;;
+    *shadow)
+      fnc_add_log "echo /etc/login.defs"
+    ;;
+    *hotplug)
+      fnc_add_log "echo /var/log/hotplug"
+      fnc_add_log "echo /var/run/usb"
+    ;;
+    *sysklogd)
+      fnc_add_log "echo /etc/syslog.conf"
+    ;;
+    *sysvinit)
+      fnc_add_log "echo /etc/inittab"
+    ;;
+    *udev)
+      fnc_add_log "find /lib/udev/devices"
+      fnc_add_log "echo /lib/firmware"
+      fnc_add_log "find /etc/udev/rules.d -type f"
+    ;;
+    *util-linux)
+      fnc_add_log "echo /var/lib/hwclock"
+      fnc_add_log "echo /etc/nologin.txt"
+    ;;
+    *vim)
+      fnc_add_log "echo /etc/vimrc"
+    ;;
+    # Rules below here will log configuration files created in {C,H}LFS
+    # They will end up in a log named {c,h}lfs-sysconf
+    *setclock)
+      fnc_add_log "echo /etc/sysconfig/clock"
+    ;;
+    *inputrc)
+      fnc_add_log "echo /etc/inputrc"
+    ;;
+    *profile)
+      fnc_add_log "echo /etc/profile"
+    ;;
+    *hostname)
+      fnc_add_log "echo /etc/sysconfig/network"
+    ;;
+    *localnet)
+      fnc_add_log "echo /etc/sysconfig/network"
+    ;;
+    *hosts)
+      fnc_add_log "echo /etc/hosts"
+    ;;
+    *network)
+      fnc_add_log "echo /etc/sysconfig/network-devices/ifconfig.eth0/ipv4"
+      fnc_add_log "echo /etc/resolv.conf"
+    ;;
+    *fstab)
+      fnc_add_log "echo /etc/fstab"
+    ;;
+    *theend) # LFS and CLFS
+      fnc_add_log "echo /etc/$PROGNAME-release"
+    ;;
+    *finished) # HLFS
+      fnc_add_log "echo /etc/$PROGNAME-release"
+    ;;
+  esac
+fi
+}
+
+
+#----------------------------------#
+check_log_package() {              #
+#----------------------------------#
+# Maybe don't need this function, but it will avoid writing some
+# unnecessary paco commands in the Makefile.
+
+case $this_script in
+  *changingowner)   LOG_PACKAGE=0 ;;
+  *creatingdirs)    LOG_PACKAGE=0 ;;
+  *createfiles)     LOG_PACKAGE=0 ;;
+  *pwdgroup)        LOG_PACKAGE=0 ;;
+  *devices)         LOG_PACKAGE=0 ;;
+  *stripping)       LOG_PACKAGE=0 ;;
+  *strippingagain)  LOG_PACKAGE=0 ;;
+  *adjusting)       LOG_PACKAGE=0 ;;
+  *temp-perl)       LOG_PACKAGE=0 ;;
+  *readjusting)     LOG_PACKAGE=0 ;;
+  *setclock)        LOG_PACKAGE=0 ;;
+  *inputrc)         LOG_PACKAGE=0 ;;
+  *profile)         LOG_PACKAGE=0 ;;
+  *hostname)        LOG_PACKAGE=0 ;;
+  *localnet)        LOG_PACKAGE=0 ;;
+  *hosts)           LOG_PACKAGE=0 ;;
+  *network)         LOG_PACKAGE=0 ;;
+  *fstab)           LOG_PACKAGE=0 ;;
+  *theend)          LOG_PACKAGE=0 ;;
+  *finished)        LOG_PACKAGE=0 ;;
+  *)                LOG_PACKAGE=1 ;;
+esac
+}
+
+#----------------------------------#
+get_paco_src() {                   #
+#----------------------------------#
+# Download the paco sources
+# We don't do any MD5SUM checking as of yet
+# http://jaist.dl.sourceforge.net/sourceforge/paco/paco-1.10.10.tar.bz2
+
+local PACO_URL1="http://$PACO_MIRROR1.dl.sourceforge.net/sourceforge/paco/$PACO_FILE"
+local PACO_URL2="http://$PACO_MIRROR2.dl.sourceforge.net/sourceforge/paco/$PACO_FILE"
+
+# Test if paco is to be used
+[[ ! "$USE_PACO" = "1" ]] && return
+
+# If the file exists in the archive copy it to the $BUILDDIR/sources dir.
+if [ ! -z ${SRC_ARCHIVE} ] &&
+   [   -d ${SRC_ARCHIVE} ] &&
+   [   -f ${SRC_ARCHIVE}/$PACO_FILE ]; then
+  cp ${SRC_ARCHIVE}/$PACO_FILE .
+  echo "$PACO_FILE: -- copied from $SRC_ARCHIVE"
+  fromARCHIVE=1
+else
+  echo "${BOLD}${YELLOW}$PACO_FILE: not found in ${SRC_ARCHIVE}${OFF}"
+  fromARCHIVE=0
+  # If the file does not exist yet in /sources download a fresh one
+  if [ ! -f $PACO_FILE ] ; then
+    if ! wget $PACO_URL1 && ! wget $PACO_URL2 ; then
+      gs_wrt_message "$PACO_FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
+      continue
+    fi
+  fi
+fi
+
+# Copy the freshly downloaded file to the source archive.
+if [ ! -z ${SRC_ARCHIVE}  ] &&
+   [   -d ${SRC_ARCHIVE}  ] &&
+   [   -w ${SRC_ARCHIVE}  ] &&
+   [ "$fromARCHIVE" = "0" ] ; then
+     echo "Storing file:<$PACO_FILE> in the package archive"
+     cp -f $PACO_FILE ${SRC_ARCHIVE}
+fi
+}
+
+
+#----------------------------------#
+check_build_model() {              #
+#----------------------------------#
+# Check what script we're running, and set some switches accordingly
+
+CLFS_BOOT=0
+
+case $PROGNAME in
+  hlfs)
+    # Not using Paco with uClibc, even if requested
+    if [ "$MODEL" = "uclibc" ]; then
+      USE_PACO=0
+    fi
+  ;;
+  clfs)
+    # CLFS boot method require it's own commands
+    if [ "$METHOD" = "boot" ]; then
+      CLFS_BOOT=1
+    fi
+  ;;
+esac
+}
Index: common/paco-build-lfs.sh
===================================================================
--- common/paco-build-lfs.sh	(revision 0)
+++ common/paco-build-lfs.sh	(revision 0)
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+cd $PKGDIR
+./configure --sysconfdir=/etc \
+	--enable-scripts \
+	--disable-gpaco &&
+make &&
+make install &&
+make logme
Index: common/paco-build-clfs.sh
===================================================================
--- common/paco-build-clfs.sh	(revision 0)
+++ common/paco-build-clfs.sh	(revision 0)
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+cd $PKGDIR
+./configure --sysconfdir=/etc \
+	--enable-scripts \
+	--disable-gpaco &&
+make &&
+make install &&
+make logme
Index: common/common-functions
===================================================================
--- common/common-functions	(revision 2905)
+++ common/common-functions	(working copy)
@@ -69,6 +69,9 @@
         in the configuration file has the proper packages and patches for the
         book version being processed.
 
+${BOLD}  --no-paco${OFF}
+        dissables paco logging feature.
+
 ${BOLD}  -O, --optimize${OFF}
         Optimize [0-2]
           0 = no optimization
@@ -696,6 +699,7 @@
                  --stringparam page $PAGE \
                  --stringparam lang $LANG \
                  --stringparam keymap $KEYMAP \
+                 --stringparam use_paco $USE_PACO \
                  -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
       ;;
 
@@ -723,6 +727,7 @@
                  --stringparam lc_all $LC_ALL \
                  --stringparam keymap $KEYMAP \
                  --stringparam grsecurity_host $GRSECURITY_HOST \
+                 --stringparam use_paco $USE_PACO \
                  -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
       ;;
     lfs)
@@ -735,6 +740,7 @@
                  --stringparam timezone $TIMEZONE \
                  --stringparam page $PAGE \
                  --stringparam lang $LANG \
+                 --stringparam use_paco $USE_PACO \
                  -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
       ;;
     *) exit 1 ;;
@@ -801,6 +807,9 @@
     # Generate URLs file
   create_urls
 
+    # If Paco is to be used, then download the sources
+  get_paco_src
+
   IFS=$'\x0A'  # Modify the 'internal field separator' to break on 'LF' only
   for line in `cat urls.lst`; do
     IFS=$saveIFS  # Restore the system defaults
Index: HLFS/hlfs.xsl
===================================================================
--- HLFS/hlfs.xsl	(revision 2905)
+++ HLFS/hlfs.xsl	(working copy)
@@ -46,6 +46,9 @@
   <xsl:param name="lang" select="C"/>
   <xsl:param name="lc_all" select="C"/>
 
+  <!-- Use paco? -->
+  <xsl:param name="use_paco" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -192,6 +195,10 @@
       <!-- Fixing bootscripts installation -->
       <xsl:when test="ancestor::sect1[@id='bootable-bootscripts'] and
                 string() = 'make install'">
+        <!-- inserting LD_PRELOAD before installing bootscripts -->
+        <xsl:if test="$use_paco != '0' and $model != 'uclibc'">
+          <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        </xsl:if>
         <xsl:text>make install&#xA;</xsl:text>
         <xsl:text>cd ../blfs-bootscripts-&blfs-bootscripts-version;&#xA;</xsl:text>
       </xsl:when>
@@ -280,6 +287,25 @@
         <xsl:apply-templates/>
         <xsl:text> || true&#xA;</xsl:text>
       </xsl:when>
+      <!-- paco begin -->
+      <!-- General rule -->
+      <xsl:when test="$use_paco != '0' and $model != 'uclibc' and
+                ancestor::chapter[@id != 'chapter-temporary-tools'] and
+                contains(string(),'make') and
+                contains(string(),'install')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/> 
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- Linux-libc-headers -->
+      <xsl:when test="$use_paco != '0' and $model != 'uclibc' and
+                ancestor::sect1[@id='ch-system-linux-headers'] and
+                contains(string(),'install ')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/> 
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- paco end -->
       <!-- The rest of commands -->
       <xsl:otherwise>
         <xsl:apply-templates/>
Index: HLFS/master.sh
===================================================================
--- HLFS/master.sh	(revision 2905)
+++ HLFS/master.sh	(working copy)
@@ -40,7 +40,9 @@
 EOF
 ) >> $MKFILE.tmp
       [[ "$TEST" != "0" ]] && wrt_test_log2 "${this_script}"
+      wrt_paco_prep
       wrt_run_as_chroot1 "$toolchain" "$this_script"
+      wrt_paco_log "`echo $toolchain | sed -e 's@[0-9]\{3\}-@@'`"
       ;;
 
     *)
@@ -272,6 +274,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If this script is *-paco, then skip it
+    case $this_script in
+      *paco )     continue ;;
+    esac
+
     # Skip this script depending on jhalfs.conf flags set.
     case $this_script in
         # We'll run the chroot commands differently than the others, so skip them in the
@@ -281,6 +288,18 @@
       *-stripping* )  [[ "$STRIP" = "0" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target
     name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
 
@@ -346,7 +365,9 @@
         wrt_RunAsRoot "${this_script}" "${file}"
         ;;
       *)   # The rest of Chapter06
+        wrt_paco_prep
         wrt_run_as_chroot1 "${this_script}" "${file}"
+        wrt_paco_log "$pkg_tarball"
        ;;
     esac
     #
@@ -366,6 +387,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$chapter6
+
+    # Reinstall paco after the toolchain has been readjusted.
+    case "${this_script}" in
+      *readjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo $this_script | sed -e 's/readjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done # end for file in chapter06/*
 
 }
@@ -424,9 +455,19 @@
         else  # Initialize the log and run the script
           wrt_run_as_chroot2 "${this_script}" "${file}"
         fi
+        wrt_paco_log "hlfs-sysconf"
         ;;
+      *kernel)       wrt_paco_prep
+                     wrt_run_as_chroot2 "$this_script" "$file"
+                     wrt_paco_log "$(get_package_tarball_name "linux")"
+        ;;
+      *bootscripts)  wrt_paco_prep
+                     wrt_run_as_chroot2 "$this_script" "$file"
+                     wrt_paco_log "$(get_package_tarball_name "lfs-bootscripts")"
+        ;;
       *)  # All other scripts
         wrt_run_as_chroot2 "${this_script}" "${file}"
+        wrt_paco_log "hlfs-sysconf"
         ;;
     esac
 
Index: master.sh
===================================================================
--- master.sh	(revision 2905)
+++ master.sh	(working copy)
@@ -149,6 +149,8 @@
 
     --help | -h )  usage | more && exit  ;;
 
+    --no-paco )            USE_PACO=0    ;;
+
     --optimize | -O )
       test $# = 1 && eval "$exit_missing_arg"
       shift
@@ -444,6 +446,14 @@
   [[ $VERBOSITY > 0 ]] && echo "OK"
 fi
 #
+# paco module
+if [[ "$USE_PACO" = "1" ]]; then
+  [[ $VERBOSITY > 0 ]] && echo -n "Loading paco module..."
+  source $COMMON_DIR/paco-functions
+  [[ $? > 0 ]] && echo "$COMMON_DIR/paco-functions did not load.." && exit 2
+  [[ $VERBOSITY > 0 ]] && echo "OK"
+fi
+#
 # optimize module
 if [[ "$OPTIMIZE" != "0" ]]; then
   [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
@@ -490,6 +500,8 @@
 if [[ "$PWD" != "$JHALFSDIR" ]]; then
   cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
   #
+  [[ $USE_PACO != "0" ]] && cp $COMMON_DIR/paco-build-$PROGNAME.sh $JHALFSDIR/
+  #
   [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
   #
   if [[ "$COMPARE" != "0" ]] ; then
<commit_msg>Rediffied paco patch.<commit_after>Index: LFS/master.sh
===================================================================
--- LFS/master.sh	(revision 2916)
+++ LFS/master.sh	(working copy)
@@ -173,6 +173,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If $this_script corresponds to a paco script, then skip it
+    case "${this_script}" in
+      *paco)       continue ;;
+    esac
+
     # We'll run the chroot commands differently than the others, so skip them in the
     # dependencies and target creation.
     case "${this_script}" in
@@ -180,6 +185,18 @@
       *stripping*) [[ "${STRIP}" = "0" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-libc-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-libc-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target
     name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
 
@@ -232,7 +249,9 @@
     # and not to use chroot.
     case "${this_script}" in
       *kernfs)  wrt_RunAsRoot    "${this_script}" "$file" ;;
-      *)        wrt_run_as_chroot1 "${this_script}" "$file" ;;
+      *)        wrt_paco_prep
+                wrt_run_as_chroot1 "${this_script}" "$file"
+                wrt_paco_log "$pkg_tarball" ;;
     esac
 
     # Remove the build directory(ies) except if the package build fails.
@@ -252,6 +271,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$chapter6
+
+    # Reinstalling paco after readsjusting the toolchain.
+    case "${this_script}" in
+      *readjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo ${this_script} | sed -e 's/readjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done # end for file in chapter06/*
 }
 
@@ -312,8 +341,15 @@
               else
                 wrt_run_as_chroot2 "$this_script" "$file"
               fi
+              wrt_paco_log "lfs-sysconf"
         ;;
+      *kernel | *bootscripts )
+              wrt_paco_prep
+              wrt_run_as_chroot2 "$this_script" "$file"
+              wrt_paco_log "$pkg_tarball"
+        ;;
       *)        wrt_run_as_chroot2 "$this_script" "$file"
+                wrt_paco_log "lfs-sysconf"
         ;;
     esac
 
Index: LFS/lfs.xsl
===================================================================
--- LFS/lfs.xsl	(revision 2916)
+++ LFS/lfs.xsl	(working copy)
@@ -39,6 +39,9 @@
   <!-- Locale settings -->
   <xsl:param name="lang" select="C"/>
 
+  <!-- Use paco? -->
+  <xsl:param name="use_paco" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -239,6 +242,33 @@
         <xsl:apply-templates/>
         <xsl:text> || true&#xA;</xsl:text>
       </xsl:when>
+      <!-- paco begin -->
+      <!-- General rule -->
+      <xsl:when test="$use_paco != '0' and
+                ancestor::chapter[@id != 'chapter-temporary-tools'] and
+                contains(string(),'make') and
+                contains(string(),'install')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- Linux-libc-headers -->
+      <xsl:when test="$use_paco != '0' and
+                ancestor::sect1[@id='ch-system-linux-libc-headers'] and
+                contains(string(),'install ')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- Unset LD_PRELOAD before second make in Zlib -->
+      <xsl:when test="$use_paco != '0' and
+                ancestor::sect1[@id='ch-system-zlib'] and
+                contains(string(),'make clean')">
+        <xsl:text>unset LD_PRELOAD&#xA;</xsl:text>
+        <xsl:apply-templates/>
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- paco end -->
       <!-- The rest of commands -->
       <xsl:otherwise>
         <xsl:apply-templates/>
Index: CLFS/master.sh
===================================================================
--- CLFS/master.sh	(revision 2916)
+++ CLFS/master.sh	(working copy)
@@ -495,6 +495,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If $this_script corresponds to a paco script, then skip it
+    case "${this_script}" in
+      *paco)       continue ;;
+    esac
+
     # Test if the stripping phase must be skipped.
     # Skip alsp temp-perl for iterative runs
     case $this_script in
@@ -502,6 +507,18 @@
       *temp-perl*) [[ -n "$N" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target, strip id number, XXX-script
     name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
                                   -e 's@temp-@@' \
@@ -554,7 +571,9 @@
       [[ "$OPTIMIZE" != "0" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
     fi
     #
+    wrt_paco_prep
     wrt_run_as_chroot1 "${this_script}" "${file}"
+    wrt_paco_log "$pkg_tarball"
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
     #
@@ -569,6 +588,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$basicsystem
+
+    # Reinstalling paco after readsjusting the toolchain.
+    case "${this_script}" in
+      *adjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo ${this_script} | sed -e 's/adjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done  # for file in final-system/* ...
 }
 
@@ -605,6 +634,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If $this_script corresponds to a paco script, then skip it
+    case "${this_script}" in
+      *paco)       continue ;;
+    esac
+
     # Test if the stripping phase must be skipped
     # Skip alsp temp-perl for iterative runs
     case $this_script in
@@ -612,6 +646,18 @@
       *temp-perl*) [[ -n "$N" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target, strip id number, XXX-script
     name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' \
                                   -e 's@temp-@@' \
@@ -666,7 +712,9 @@
       [[ "$OPTIMIZE" != "0" ]] &&  wrt_optimize "$name" && wrt_makeflags "$name"
     fi
     #
+    wrt_paco_prep
     wrt_run_as_root2 "${this_script}" "${file}"
+    wrt_paco_log "$pkg_tarball"
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs2 "${name}"
     #
@@ -681,6 +729,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$basicsystem
+
+    # Reinstalling paco after readsjusting the toolchain.
+    case "${this_script}" in
+      *adjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo ${this_script} | sed -e 's/adjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done  # for file in final-system/* ...
 }
 
@@ -729,7 +787,17 @@
     #
     [[ "$pkg_tarball" != "" ]] && wrt_unpack2 "$pkg_tarball"
     #
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_prep ;;
+    esac
     wrt_run_as_chroot1 "${this_script}" "${file}"
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_log "$pkg_tarball" ;;
+      *)
+        wrt_paco_log "clfs-sysconf" ;;
+    esac
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs "${name}"
     #
@@ -791,7 +859,17 @@
     #
     [[ "$pkg_tarball" != "" ]] && wrt_unpack3 "$pkg_tarball"
     #
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_prep ;;
+    esac
     wrt_run_as_root2 "${this_script}" "${file}"
+    case $this_script in
+      *bootscripts* | *udev-rules )
+        wrt_paco_log "$pkg_tarball" ;;
+      *)
+        wrt_paco_log "clfs-sysconf" ;;
+    esac
     #
     [[ "$pkg_tarball" != "" ]] && wrt_remove_build_dirs2 "${name}"
     #
@@ -863,8 +941,13 @@
                 else
                   wrt_run_as_chroot1  "${this_script}" "${file}"
                 fi
+                wrt_paco_log "clfs-sysconf"
           ;;
-      *)  wrt_run_as_chroot1  "${this_script}" "${file}"   ;;
+      *kernel)  wrt_paco_prep
+                wrt_run_as_chroot1  "${this_script}" "${file}"
+                wrt_paco_log "$pkg_tarball" ;;
+      *)  wrt_run_as_chroot1  "${this_script}" "${file}"
+          wrt_paco_log "clfs-sysconf" ;;
     esac
     #
     # Housekeeping...remove any build directory(ies) except if the package build fails.
@@ -942,8 +1025,13 @@
                 else
                   wrt_run_as_root2  "${this_script}" "${file}"
                 fi
+                wrt_paco_log "clfs-sysconf"
           ;;
-      *)  wrt_run_as_root2  "${this_script}" "${file}"   ;;
+      *kernel)  wrt_paco_prep
+                wrt_run_as_root2  "${this_script}" "${file}"
+                wrt_paco_log "$pkg_tarball"   ;;
+      *)  wrt_run_as_root2  "${this_script}" "${file}"
+          wrt_paco_log "clfs-sysconf"   ;;
     esac
     #
     # Housekeeping...remove any build directory(ies) except if the package build fails.
Index: CLFS/clfs.xsl
===================================================================
--- CLFS/clfs.xsl	(revision 2916)
+++ CLFS/clfs.xsl	(working copy)
@@ -45,6 +45,9 @@
   <!-- Locale settings -->
   <xsl:param name="lang" select="C"/>
 
+  <!-- Use paco? -->
+  <xsl:param name="use_paco" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -106,6 +109,25 @@
                 <xsl:text>tar -xvf ../vim-&vim-version;-lang.* --strip-components=1&#xA;</xsl:text>
               </xsl:if>
             </xsl:if>
+            <!-- paco begin -->
+            <!-- General rule -->
+            <xsl:if test="$use_paco != '0' and 
+                    @id='ch-scripts-bootscripts' or
+                    @id='ch-scripts-udev-rules' or
+                    @id='ch-bootable-kernel' or
+                    (../@id='chapter-building-system' and
+                    @id!='ch-system-temp-perl' and
+                    contains(string(),'make') and
+                    contains(string(),'install'))">
+              <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+            </xsl:if>
+            <!-- Linux headers -->
+            <xsl:if test="$use_paco != '0' and
+                    @id='ch-system-linux-headers' and
+                    contains(string(),'install')">
+              <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+            </xsl:if>
+            <!-- paco end -->
             <xsl:apply-templates select=".//para/userinput | .//screen"/>
             <xsl:text>exit</xsl:text>
           </exsl:document>
Index: common/paco-build-hlfs.sh
===================================================================
--- common/paco-build-hlfs.sh	(revision 0)
+++ common/paco-build-hlfs.sh	(revision 0)
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+cd $PKGDIR
+./configure --sysconfdir=/etc \
+	--enable-scripts \
+	--disable-gpaco \
+	--disable-static \
+	--with-pic &&
+make &&
+make install &&
+make logme
Index: common/config
===================================================================
--- common/config	(revision 2916)
+++ common/config	(working copy)
@@ -91,6 +91,23 @@
 #--- Run farce testing 0(no)/1(yes)
 RUN_FARCE=0
 
+#==== PACO VARIABLES ====
+#--- Use paco? 0(no)/1(yes)
+USE_PACO=1
+PACO_VERSION=1.10.10
+
+#--- Name of the Paco source package
+PACO_FILE=paco-$PACO_VERSION.tar.bz2   # (use .tar.gz if preferred)
+
+#--- Sourceforge mirror to use for Paco source download
+# Europe: heanet, belnet, puzzle, surfnet, switch, kent
+# North America: superb-east, superb-west, umn, easynews
+# South America: ufpr
+# Asia: nchc, jaist
+# Australia: optusnet
+PACO_MIRROR1=heanet
+PACO_MIRROR2=kent
+
 #==== INTERNAL VARIABLES ====
 # Don't edit it unless you know what you are doing
 
@@ -108,3 +125,9 @@
 
 #--- farce report log directory
 FARCELOGDIR=$LOGDIR/farce
+
+#--- Variables needed by paco
+PACO_INCLUDE=/
+PACO_EXCLUDE=/${SCRIPT_ROOT}
+PACO_TMPFILE=/tmp/paco.tmp
+LD_PRELOAD=/usr/lib/libpaco-log.so
Index: common/func_validate_configs.sh
===================================================================
--- common/func_validate_configs.sh	(revision 2916)
+++ common/func_validate_configs.sh	(working copy)
@@ -86,10 +86,10 @@
 inline_doc
 
   # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
-  local -r  hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL KEYMAP         PAGE TIMEZONE LANG LC_ALL LUSER LGROUP"
-  local -r  clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD  ARCH  TARGET  TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
-  local -r clfs2_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE         ARCH  TARGET                 OPTIMIZE REPORT                                      STRIP FSTAB             CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
-  local -r   lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE                       TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL        VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
+  local -r  hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE USE_PACO GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL KEYMAP         PAGE TIMEZONE LANG LC_ALL LUSER LGROUP"
+  local -r  clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE USE_PACO GETPKG RUNMAKE METHOD  ARCH  TARGET  TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
+  local -r clfs2_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE          GETPKG RUNMAKE         ARCH  TARGET                 OPTIMIZE REPORT                                      STRIP FSTAB             CONFIG GETKERNEL KEYMAP VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
+  local -r   lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE USE_PACO GETPKG RUNMAKE                       TEST BOMB_TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG GETKERNEL        VIMLANG PAGE TIMEZONE LANG        LUSER LGROUP"
 
   local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
   local -r ERROR_MSG_pt2=' check the config file ${BOLD}${GREEN}\<$(echo $PROGNAME | tr [a-z] [A-Z])/config\> or \<common/config\>${OFF}'
@@ -179,6 +179,7 @@
                     [[ "$GETPKG" = "1" ]] && validate_against_str "x0x x1x"
                   fi ;;
       RUNMAKE)    validate_against_str "x0x x1x" ;;
+      USE_PACO)   validate_against_str "x0x x1x" ;;
       REPORT)     validate_against_str "x0x x1x"
                   if [[ "${!config_param}" = "1" ]]; then
                     if [[ `type -p bc` ]]; then
Index: common/paco-functions
===================================================================
--- common/paco-functions	(revision 0)
+++ common/paco-functions	(revision 0)
@@ -0,0 +1,311 @@
+#!/bin/bash
+
+#----------------------------#
+wrt_paco_inst() {            #
+#----------------------------#
+
+local paco_script="$1"
+
+check_build_model
+
+if [ $USE_PACO != 0 ]; then
+  case $PROGNAME in 
+    clfs )
+      paco_file="final-system/$paco_script"
+      basicsystem="$basicsystem $paco_script" ;;
+    * )
+      paco_file="chapter06/$paco_script"
+      chapter6="$chapter6 $paco_script" ;;
+  esac
+
+  # Copy the paco build script to the correct directory and make it executable
+  cp $JHALFSDIR/paco-build-$PROGNAME.sh $JHALFSDIR/${PROGNAME}-commands/$paco_file &&
+  chmod +x $JHALFSDIR/${PROGNAME}-commands/$paco_file
+
+  # Write target, dependency and unpack
+  if [ $CLFS_BOOT = 1 ]; then
+    wrt_target_boot "$paco_script" "$PREV"
+    wrt_unpack3 "$PACO_FILE"
+    wrt_run_as_root2 "${paco_script}" "${paco_file}"
+    wrt_remove_build_dirs2 "paco"
+  else 
+    wrt_target "$paco_script" "$PREV"
+    wrt_unpack2 "$PACO_FILE"
+    wrt_run_as_chroot1 "${paco_script}" "${paco_file}"
+    wrt_remove_build_dirs "paco"
+  fi
+
+  wrt_touch
+
+  # Override the PREV variable
+  PREV="$paco_script"
+fi
+}
+
+
+#----------------------------------#
+wrt_paco_prep() {                  # Export Paco variables
+#----------------------------------# and remove tmpfile
+
+local TMPFILEPATH
+
+check_build_model
+
+check_log_package
+
+if [ $USE_PACO != 0 ] && [ $LOG_PACKAGE != 0 ]; then
+  if [ $CLFS_BOOT = 1 ]; then
+    TMPFILEPATH="$PACO_TMPFILE"
+  else
+    TMPFILEPATH="\$(MOUNT_PT)$PACO_TMPFILE"
+  fi
+(
+cat  << EOF
+	@echo "export PACO_INCLUDE=$PACO_INCLUDE" >> envars && \\
+	echo "export PACO_EXCLUDE=\$(SRC):$PACO_EXCLUDE" >> envars && \\
+	echo "export PACO_TMPFILE=$PACO_TMPFILE" >> envars && \\
+	rm -f $TMPFILEPATH
+EOF
+) >> $MKFILE.tmp
+fi
+}
+
+
+#----------------------------------#
+wrt_paco_log() {                   # If the tmpfile exist, then log the current package
+#----------------------------------# and remove tempfile
+local PACKAGE
+
+# Extract package name and version from the tarball name
+PACKAGE=`echo $1 | sed -e 's/.tar.*//'`
+
+check_build_model
+
+# Check if the package should be logged
+check_log_package
+
+
+if [ $USE_PACO != 0 ]; then
+  if [ $LOG_PACKAGE != 0 ]; then
+    # Only use this if doing CLFS boot build
+    if [ $CLFS_BOOT = 1 ]; then
+(
+cat << EOF
+	@if [ -e $PACO_TMPFILE ]; then \\
+		paco -lp+ $PACKAGE < $PACO_TMPFILE && \\
+		rm -f $PACO_TMPFILE; \\
+	fi;
+EOF
+) >> $MKFILE.tmp
+    # All else should use these commands
+    else
+(
+cat << EOF
+	@if [ -e \$(MOUNT_PT)$PACO_TMPFILE ]; then \\
+		\$(CHROOT1) 'paco -lp+ $PACKAGE < $PACO_TMPFILE' && \\
+		rm -f \$(MOUNT_PT)$PACO_TMPFILE; \\
+	fi;
+EOF
+) >> $MKFILE.tmp
+    fi
+  fi
+  # Add missing files to the logs if needed
+  wrt_paco_add_log
+fi
+}
+
+
+#----------------------------------#
+fnc_add_log() {                    #
+#----------------------------------#
+
+MISSING_FILE=$1
+
+if [ $CLFS_BOOT = 1 ]; then
+  echo -e "\t@$MISSING_FILE | paco -lp+ $PACKAGE" >> $MKFILE.tmp
+else
+  echo -e "\t@\$(CHROOT1) '$MISSING_FILE | paco -lp+ $PACKAGE'" >> $MKFILE.tmp
+fi
+}
+
+
+#----------------------------------#
+wrt_paco_add_log() {               #
+#----------------------------------#
+# Some packages create files using bash redirection, which the LD_PRELOAD lib don't notice
+# These rules will add the missing files to the proper logs.
+# Most of these is not needed for HLFS, but they do no harm.
+if [ $USE_PACO != 0 ]; then
+ case $this_script in
+    *glibc)
+      fnc_add_log "find /lib -type l"
+      fnc_add_log "find /etc/{nsswitch.conf,ld.so.conf}"
+    ;;
+    *ncurses)
+      fnc_add_log "find /usr/lib/{libcurses.so,libncurses.so,libform.so,libpanel.so,libmenu.so}"
+    ;;
+    *bash)
+      fnc_add_log "echo /bin/sh"
+    ;;
+    *flex)
+      fnc_add_log "echo /usr/bin/lex"
+    ;;
+    *shadow)
+      fnc_add_log "echo /etc/login.defs"
+    ;;
+    *hotplug)
+      fnc_add_log "echo /var/log/hotplug"
+      fnc_add_log "echo /var/run/usb"
+    ;;
+    *sysklogd)
+      fnc_add_log "echo /etc/syslog.conf"
+    ;;
+    *sysvinit)
+      fnc_add_log "echo /etc/inittab"
+    ;;
+    *udev)
+      fnc_add_log "find /lib/udev/devices"
+      fnc_add_log "echo /lib/firmware"
+      fnc_add_log "find /etc/udev/rules.d -type f"
+    ;;
+    *util-linux)
+      fnc_add_log "echo /var/lib/hwclock"
+      fnc_add_log "echo /etc/nologin.txt"
+    ;;
+    *vim)
+      fnc_add_log "echo /etc/vimrc"
+    ;;
+    # Rules below here will log configuration files created in {C,H}LFS
+    # They will end up in a log named {c,h}lfs-sysconf
+    *setclock)
+      fnc_add_log "echo /etc/sysconfig/clock"
+    ;;
+    *inputrc)
+      fnc_add_log "echo /etc/inputrc"
+    ;;
+    *profile)
+      fnc_add_log "echo /etc/profile"
+    ;;
+    *hostname)
+      fnc_add_log "echo /etc/sysconfig/network"
+    ;;
+    *localnet)
+      fnc_add_log "echo /etc/sysconfig/network"
+    ;;
+    *hosts)
+      fnc_add_log "echo /etc/hosts"
+    ;;
+    *network)
+      fnc_add_log "echo /etc/sysconfig/network-devices/ifconfig.eth0/ipv4"
+      fnc_add_log "echo /etc/resolv.conf"
+    ;;
+    *fstab)
+      fnc_add_log "echo /etc/fstab"
+    ;;
+    *theend) # LFS and CLFS
+      fnc_add_log "echo /etc/$PROGNAME-release"
+    ;;
+    *finished) # HLFS
+      fnc_add_log "echo /etc/$PROGNAME-release"
+    ;;
+  esac
+fi
+}
+
+
+#----------------------------------#
+check_log_package() {              #
+#----------------------------------#
+# Maybe don't need this function, but it will avoid writing some
+# unnecessary paco commands in the Makefile.
+
+case $this_script in
+  *changingowner)   LOG_PACKAGE=0 ;;
+  *creatingdirs)    LOG_PACKAGE=0 ;;
+  *createfiles)     LOG_PACKAGE=0 ;;
+  *pwdgroup)        LOG_PACKAGE=0 ;;
+  *devices)         LOG_PACKAGE=0 ;;
+  *stripping)       LOG_PACKAGE=0 ;;
+  *strippingagain)  LOG_PACKAGE=0 ;;
+  *adjusting)       LOG_PACKAGE=0 ;;
+  *temp-perl)       LOG_PACKAGE=0 ;;
+  *readjusting)     LOG_PACKAGE=0 ;;
+  *setclock)        LOG_PACKAGE=0 ;;
+  *inputrc)         LOG_PACKAGE=0 ;;
+  *profile)         LOG_PACKAGE=0 ;;
+  *hostname)        LOG_PACKAGE=0 ;;
+  *localnet)        LOG_PACKAGE=0 ;;
+  *hosts)           LOG_PACKAGE=0 ;;
+  *network)         LOG_PACKAGE=0 ;;
+  *fstab)           LOG_PACKAGE=0 ;;
+  *theend)          LOG_PACKAGE=0 ;;
+  *finished)        LOG_PACKAGE=0 ;;
+  *)                LOG_PACKAGE=1 ;;
+esac
+}
+
+#----------------------------------#
+get_paco_src() {                   #
+#----------------------------------#
+# Download the paco sources
+# We don't do any MD5SUM checking as of yet
+# http://jaist.dl.sourceforge.net/sourceforge/paco/paco-1.10.10.tar.bz2
+
+local PACO_URL1="http://$PACO_MIRROR1.dl.sourceforge.net/sourceforge/paco/$PACO_FILE"
+local PACO_URL2="http://$PACO_MIRROR2.dl.sourceforge.net/sourceforge/paco/$PACO_FILE"
+
+# Test if paco is to be used
+[[ ! "$USE_PACO" = "1" ]] && return
+
+# If the file exists in the archive copy it to the $BUILDDIR/sources dir.
+if [ ! -z ${SRC_ARCHIVE} ] &&
+   [   -d ${SRC_ARCHIVE} ] &&
+   [   -f ${SRC_ARCHIVE}/$PACO_FILE ]; then
+  cp ${SRC_ARCHIVE}/$PACO_FILE .
+  echo "$PACO_FILE: -- copied from $SRC_ARCHIVE"
+  fromARCHIVE=1
+else
+  echo "${BOLD}${YELLOW}$PACO_FILE: not found in ${SRC_ARCHIVE}${OFF}"
+  fromARCHIVE=0
+  # If the file does not exist yet in /sources download a fresh one
+  if [ ! -f $PACO_FILE ] ; then
+    if ! wget $PACO_URL1 && ! wget $PACO_URL2 ; then
+      gs_wrt_message "$PACO_FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
+      continue
+    fi
+  fi
+fi
+
+# Copy the freshly downloaded file to the source archive.
+if [ ! -z ${SRC_ARCHIVE}  ] &&
+   [   -d ${SRC_ARCHIVE}  ] &&
+   [   -w ${SRC_ARCHIVE}  ] &&
+   [ "$fromARCHIVE" = "0" ] ; then
+     echo "Storing file:<$PACO_FILE> in the package archive"
+     cp -f $PACO_FILE ${SRC_ARCHIVE}
+fi
+}
+
+
+#----------------------------------#
+check_build_model() {              #
+#----------------------------------#
+# Check what script we're running, and set some switches accordingly
+
+CLFS_BOOT=0
+
+case $PROGNAME in
+  hlfs)
+    # Not using Paco with uClibc, even if requested
+    if [ "$MODEL" = "uclibc" ]; then
+      USE_PACO=0
+    fi
+  ;;
+  clfs)
+    # CLFS boot method require it's own commands
+    if [ "$METHOD" = "boot" ]; then
+      CLFS_BOOT=1
+    fi
+  ;;
+esac
+}
Index: common/paco-build-lfs.sh
===================================================================
--- common/paco-build-lfs.sh	(revision 0)
+++ common/paco-build-lfs.sh	(revision 0)
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+cd $PKGDIR
+./configure --sysconfdir=/etc \
+	--enable-scripts \
+	--disable-gpaco &&
+make &&
+make install &&
+make logme
Index: common/paco-build-clfs.sh
===================================================================
--- common/paco-build-clfs.sh	(revision 0)
+++ common/paco-build-clfs.sh	(revision 0)
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+cd $PKGDIR
+./configure --sysconfdir=/etc \
+	--enable-scripts \
+	--disable-gpaco &&
+make &&
+make install &&
+make logme
Index: common/common-functions
===================================================================
--- common/common-functions	(revision 2916)
+++ common/common-functions	(working copy)
@@ -69,6 +69,9 @@
         in the configuration file has the proper packages and patches for the
         book version being processed.
 
+${BOLD}  --no-paco${OFF}
+        dissables paco logging feature.
+
 ${BOLD}  -O, --optimize${OFF}
         Optimize [0-2]
           0 = no optimization
@@ -696,6 +699,7 @@
                  --stringparam page $PAGE \
                  --stringparam lang $LANG \
                  --stringparam keymap ${KEYMAP:-"none"} \
+                 --stringparam use_paco $USE_PACO \
                  -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
       ;;
 
@@ -723,6 +727,7 @@
                  --stringparam lc_all $LC_ALL \
                  --stringparam keymap ${KEYMAP:-"none"} \
                  --stringparam grsecurity_host $GRSECURITY_HOST \
+                 --stringparam use_paco $USE_PACO \
                  -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
       ;;
     lfs)
@@ -735,6 +740,7 @@
                  --stringparam timezone $TIMEZONE \
                  --stringparam page $PAGE \
                  --stringparam lang $LANG \
+                 --stringparam use_paco $USE_PACO \
                  -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
       ;;
     *) exit 1 ;;
@@ -801,6 +807,9 @@
     # Generate URLs file
   create_urls
 
+    # If Paco is to be used, then download the sources
+  get_paco_src
+
   IFS=$'\x0A'  # Modify the 'internal field separator' to break on 'LF' only
   for line in `cat urls.lst`; do
     IFS=$saveIFS  # Restore the system defaults
Index: HLFS/hlfs.xsl
===================================================================
--- HLFS/hlfs.xsl	(revision 2916)
+++ HLFS/hlfs.xsl	(working copy)
@@ -46,6 +46,9 @@
   <xsl:param name="lang" select="C"/>
   <xsl:param name="lc_all" select="C"/>
 
+  <!-- Use paco? -->
+  <xsl:param name="use_paco" select="1"/>
+
   <xsl:template match="/">
     <xsl:apply-templates select="//sect1"/>
   </xsl:template>
@@ -192,6 +195,10 @@
       <!-- Fixing bootscripts installation -->
       <xsl:when test="ancestor::sect1[@id='bootable-bootscripts'] and
                 string() = 'make install'">
+        <!-- inserting LD_PRELOAD before installing bootscripts -->
+        <xsl:if test="$use_paco != '0' and $model != 'uclibc'">
+          <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        </xsl:if>
         <xsl:text>make install&#xA;</xsl:text>
         <xsl:text>cd ../blfs-bootscripts-&blfs-bootscripts-version;&#xA;</xsl:text>
       </xsl:when>
@@ -280,6 +287,25 @@
         <xsl:apply-templates/>
         <xsl:text> || true&#xA;</xsl:text>
       </xsl:when>
+      <!-- paco begin -->
+      <!-- General rule -->
+      <xsl:when test="$use_paco != '0' and $model != 'uclibc' and
+                ancestor::chapter[@id != 'chapter-temporary-tools'] and
+                contains(string(),'make') and
+                contains(string(),'install')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/> 
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- Linux-libc-headers -->
+      <xsl:when test="$use_paco != '0' and $model != 'uclibc' and
+                ancestor::sect1[@id='ch-system-linux-headers'] and
+                contains(string(),'install ')">
+        <xsl:text>export LD_PRELOAD=/usr/lib/libpaco-log.so&#xA;</xsl:text>
+        <xsl:apply-templates/> 
+        <xsl:text>&#xA;</xsl:text>
+      </xsl:when>
+      <!-- paco end -->
       <!-- The rest of commands -->
       <xsl:otherwise>
         <xsl:apply-templates/>
Index: HLFS/master.sh
===================================================================
--- HLFS/master.sh	(revision 2916)
+++ HLFS/master.sh	(working copy)
@@ -40,7 +40,9 @@
 EOF
 ) >> $MKFILE.tmp
       [[ "$TEST" != "0" ]] && wrt_test_log2 "${this_script}"
+      wrt_paco_prep
       wrt_run_as_chroot1 "$toolchain" "$this_script"
+      wrt_paco_log "`echo $toolchain | sed -e 's@[0-9]\{3\}-@@'`"
       ;;
 
     *)
@@ -272,6 +274,11 @@
     # Keep the script file name
     this_script=`basename $file`
 
+    # If this script is *-paco, then skip it
+    case $this_script in
+      *paco )     continue ;;
+    esac
+
     # Skip this script depending on jhalfs.conf flags set.
     case $this_script in
         # We'll run the chroot commands differently than the others, so skip them in the
@@ -281,6 +288,18 @@
       *-stripping* )  [[ "$STRIP" = "0" ]] && continue ;;
     esac
 
+    # Install paco as the first package in ch6, before installing
+    # linux-libc-headers, except in iterartive builds
+    if [[ -z "$N" ]]; then
+      case $this_script in
+        *linux-headers)
+          TMP_SCRIPT="$this_script"
+          this_script=`echo $this_script | sed -e 's/linux-headers/a-paco/'`
+          wrt_paco_inst "$this_script"
+          this_script="$TMP_SCRIPT" ;;
+      esac
+    fi
+
     # Grab the name of the target
     name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
 
@@ -346,7 +365,9 @@
         wrt_RunAsRoot "${this_script}" "${file}"
         ;;
       *)   # The rest of Chapter06
+        wrt_paco_prep
         wrt_run_as_chroot1 "${this_script}" "${file}"
+        wrt_paco_log "$pkg_tarball"
        ;;
     esac
     #
@@ -366,6 +387,16 @@
     PREV=${this_script}${N}
     # Set system_build envar for iteration targets
     system_build=$chapter6
+
+    # Reinstall paco after the toolchain has been readjusted.
+    case "${this_script}" in
+      *readjusting)
+        TMP_SCRIPT="$this_script"
+        this_script=`echo $this_script | sed -e 's/readjusting/x-paco/'`
+        wrt_paco_inst "$this_script"
+        this_script="$TMP_SCRIPT" ;;
+    esac
+
   done # end for file in chapter06/*
 
 }
@@ -424,9 +455,19 @@
         else  # Initialize the log and run the script
           wrt_run_as_chroot2 "${this_script}" "${file}"
         fi
+        wrt_paco_log "hlfs-sysconf"
         ;;
+      *kernel)       wrt_paco_prep
+                     wrt_run_as_chroot2 "$this_script" "$file"
+                     wrt_paco_log "$(get_package_tarball_name "linux")"
+        ;;
+      *bootscripts)  wrt_paco_prep
+                     wrt_run_as_chroot2 "$this_script" "$file"
+                     wrt_paco_log "$(get_package_tarball_name "lfs-bootscripts")"
+        ;;
       *)  # All other scripts
         wrt_run_as_chroot2 "${this_script}" "${file}"
+        wrt_paco_log "hlfs-sysconf"
         ;;
     esac
 
Index: master.sh
===================================================================
--- master.sh	(revision 2916)
+++ master.sh	(working copy)
@@ -194,6 +194,8 @@
 
     --help | -h )  usage | more && exit  ;;
 
+    --no-paco )            USE_PACO=0    ;;
+
     --optimize | -O )
       test $# = 1 && eval "$exit_missing_arg"
       shift
@@ -489,6 +491,14 @@
   [[ $VERBOSITY > 0 ]] && echo "OK"
 fi
 #
+# paco module
+if [[ "$USE_PACO" = "1" ]]; then
+  [[ $VERBOSITY > 0 ]] && echo -n "Loading paco module..."
+  source $COMMON_DIR/paco-functions
+  [[ $? > 0 ]] && echo "$COMMON_DIR/paco-functions did not load.." && exit 2
+  [[ $VERBOSITY > 0 ]] && echo "OK"
+fi
+#
 # optimize module
 if [[ "$OPTIMIZE" != "0" ]]; then
   [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
@@ -535,6 +545,8 @@
 if [[ "$PWD" != "$JHALFSDIR" ]]; then
   cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
   #
+  [[ $USE_PACO != "0" ]] && cp $COMMON_DIR/paco-build-$PROGNAME.sh $JHALFSDIR/
+  #
   [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
   #
   if [[ "$COMPARE" != "0" ]] ; then

{'fraction_non_alphanumeric': 0.20035966946079306, 'fraction_numerical': 0.018310445276737412, 'mean_word_length': 2.3515142458657103, 'pattern_counts': {'":': 0, '<': 247, '<?xml version=': 0, '>': 295, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4006198', 'n_tokens_mistral': 25896, 'n_tokens_neox': 24095, 'n_words': 5028}