Automation From Scratch

LFS 6.1.1

Paul Estep

Copyright (c) 2005-2010, Paul Estep

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions in any form must retain the above copyright notice, this list of conditions and the following disclaimer

  • Neither the name of “Automation From Scratch” nor the names of its contributors may be used to endorse or promote products derived from this material without specific prior written permission

  • Any material derived from Automation From Scratch must contain a reference to the “Automation From Scratch” project

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Table of Contents

Preface

1. Forward

My adventures with Linux From Scratch,http://www.linuxfromscratch.org, (LFS) began in 2004 with version 5.0. Since then I have gone though four versions, 5.0, 6.0, 6.1, and now 6.1.1. Like most I have rebuilt each version a couple of times.

As many are aware there is a clear need to rebuild your LFS System either because once completing your first build you now know how you really want to configure your LFS system or you want to rebuild to update to a new minor version. After looking at all the other quite good methods of automating the LFS build process none seemed to fit the simplicity or elegance of the LFS Book's build process. So I developed my own method to automate the build process of LFS. An automated build process that is as simple as the LFS Book and which follows it both procedurally and in text as closely as possible. I believe this automated build process, Automation From Scratch, and its associated script file, afs, closely adheres to the LFS spirit of not providing you a finished system but documents how to build and customize your own system. In this case how to create and customize your automated LFS build process.

This booklet outlines the steps of how to automate your LFS build. It creates a BASH script that builds a LFS system. The AFS script structure follows the LFS Book and primarily uses the same commands as in the LFS Book. This allows you to use the LFS Book as a guide for the script's creation, modification, and customization. There is a one to one correspondence with the script to the LFS book. By looking at the script or the book you will know where to customize the script or where to reference the LFS Book for more information on the commands.

This booklet is formated as closely as possible to the LFS Book. It includes portions of the book where appropriate for easier comprehension.

Lastly, I want to thank Gerard Beekmans for the Linux From Scratch book and the Linux From Scratch community for all the support they have given to us Linux novices.

----
Paul Estep
paul@ponktv.com

2. Audience

This booklet is for anyone who has gone through their first LFS build and now desires a automated method to build their LFS system. The AFS script should not be a replacement for an initial build of a new LFS system. The AFS script requires the knowledge you gain from the initial build to create the script. Your system's LFS configuration is required.

3. Prerequisites

If you have built a LFS system then you should have all you the knowledge and tools needed to build the AFS script. If you have not built a LFS system, it is suggested you do so before creating and using an AFS script.

The AFS script primarily uses the same commands as documented in the LFS book. To understand the AFS script a basic knowledge of programming and shell (Bash) scripting is needed. To review the basics of Bash scripting read Part 2, “Basics” of the “Advanced Bash-Scripting Guide” (HOW-TO) at the Linux Documentation project site, http://tldp.org. For reference information on Bash you can read the GNU Bash Manual at GNU Manuals Online at http://www.gnu.org/manual/manual.html.

4. Host System Requirements

The AFS script can be built and executed on any system compatible with building a LFS system and supporting the Bash shell. Running the AFS script on other Linux distributions not based on LFS may require additional customization. The LFS Book should provide you with the information you need to modify the build commands. Additionally refer to your shell documentation when specific Bash functionality needs to be modified.

5. Typography

This booklet is formated as closely as possible to the LFS book. The purpose of this is to provide a consistence look between this booklet and the LFS Book.

From the LFS book.

To make things easier to follow, there are a few typographical conventions used throughout this book. This section contains some examples of the typographical format found throughout Linux From Scratch.

./configure --prefix=/usr

This form of text is designed to be typed exactly as seen unless otherwise noted in the surrounding text. It is also used in the explanation sections to identify which of the commands is being referenced.

install-info: unknown option '--dir-file=/mnt/lfs/usr/info/dir'

This form of text (fixed-width text) shows screen output, probably as the result of commands issued. This format is also used to show filenames, such as /etc/ld.so.conf.

Emphasis

This form of text is used for several purposes in the book. Its main purpose is to emphasize important points or items.

http://www.linuxfromscratch.org

This format is used for hyperlinks both within the LFS community and to external pages. It includes HOWTOs, download locations, and websites.

cat > $LFS/etc/group << "EOF"
root:x:0:
bin:x:1:
......
EOF

This format is used when creating configuration files. The first command tells the system to create the file $LFS/etc/group from whatever is typed on the following lines until the sequence end of file (EOF) is encountered. Therefore, this entire section is generally typed as seen.

[REPLACED TEXT]

This format is used to encapsulate text that is not to be typed as seen or copied-and-pasted.

passwd(5)

This format is used to refer to a specific manual page (hereinafter referred to simply as a “man” page). The number inside parentheses indicates a specific section inside of man. For example, passwd has two man pages. Per LFS installation instructions, those two man pages will be located at /usr/share/man/man1/passwd.1 and /usr/share/man/man5/passwd.5. Both man pages have different information in them. When the book uses passwd(5) it is specifically referring to /usr/share/man/man5/passwd.5. man passwd will print the first man page it finds that matches “passwd”, which will be /usr/share/man/man1/passwd.1. For this example, you will need to run man 5 passwd in order to read the specific page being referred to. It should be noted that most man pages do not have duplicate page names in different sections. Therefore, man [program name] is generally sufficient.

This booklet uses one other convention to distinguish between commands that are added or edited from commands already in the script.

  chmod -v a+wt $LFS/sources

  cp sources/* [chapter05 source directory]

#   ----

This format is used to highlight added script commands. The line cp sources/* $LFS/sources/ is to be added or changed between the lines chmod -v a+wt [chapter05 source directory] and # ----.

6. Structure

This booklet is divided into the following parts.

6.1. Part I

Part I provides the basics of the booklet. Who it is for, what you need to know to create an AFS script, the system requirements to run the script, and how the booklet is formated.

6.2. Part II

Part II explains how to create a AFS script template and the changes required to the LFS Book commands to create a AFS script.

6.3. Part III

Part III gives you hints, tips, and warnings about running and debugging your AFS script.

6.4. Part IV

Part IV expands on the AFS script concept suggesting modifications for further functionality including adding Beyond Linux From Scratch (BLFS) packages.

Introduction

Table of Contents

Chapter 1. Introduction

1.1. How to automate your LFS build

The first question that needs to be answered is where do you want to start. There are several starting points. You can start from the LFS book commands, from a XSL dump of LFS Book's XML files, or from a completed AFS script. Chapter 1 will show you what is needed for each starting point. Chapter 2 will describe the LFS Book commands that need to be modified to make the commands scriptable. Chapter 3 will describe techniques to test and debug your AFS script. And finally a chapter on building your LFS system. I have also included a chapter to discuss what can be done next with the AFS script concept and your completed AFS script.

1.2. Changelog

This is the initial writing of the AFS Booklet. You should be able to view or download the latest version from the AFS Project site, http://afslfs.sourceforge.net.

1.3. Resources

There are many resources you can use on the AFS Project site, http://afslfs.sourceforge.net, to help in creating your AFS script. Also the Linux From Scratch site, http://www.linuxfromscratch.org can provide additional resources. The LFS Book, section 1.3 “Resources”, documents many of them.

The AFS script requires a GNU Bash shell to execute. Some techniques used in AFS are Bash specific. The AFS script will not run on all Linux distributions. It is intended to run on a LFS system.

1.4. Help

If you have an problem or a question first determine if it is an AFS script question or a LFS build question. If your problem is with the LFS build process please use the many resources on the LFS Project site. However, if your problem is with the AFS script use the resources on the AFS Project site.

First search the forums on the AFS Project site. If you still have a problem you can post your question on the forums. In order to offer the best assistance please include as much information as you can with your question.

Creating the AFS script

Chapter 2. Introduction

2.1. Creating the AFS script template

There are three starting points for building an AFS script template. You can type in the LFS Book commands, you can extract a XSL dump of commands from the LFS Book's XML files, or you can use an already existing AFS script.

2.1.1. Creating the AFS script template from the LFS Book

Use your favorite editor and create a Bash executable file by adding the #!/bin/bash as the first line.

#!/bin/bash

Also add these additional commands to setup the AFS script environment.

#!/bin/bash

set -e +h
umask 022
export LFS=/mnt/lfs

set -e +h

Sets the Bash script to exit on a script error and not to hash previous commands.

umask 022

Sets the umask variable for file creation.

export LFS=/mnt/lfs

Sets the infamous $LFS variable, LFS Book section 4.1. “About $LFS”. This should be the only statement in the script that sets the LFS variable.

For each LFS Book section create a Bash function. You may want to add the LFS Book's section names as a comment and some comments bracketing where you will put the LFS Book commands. In this case between the # ---- lines.

Function names need to be unique and adhere to Bash function identifier rules. I suggest you use the LFS Book headings in lowercase replacing blanks with dashes.

# Section Name
function <section-name> ()
{
#   ----

#   ----
}

Type the LFS Book commands into each associated function. As an example the LFS Book section 2.4. “Mounting the New Partition” would look something like the following.

# Mounting the New Partition 
function chapter02-mounting () 
{ 
    echo "chapter02-mounting" 
#   ---- 

    export LFS=/mnt/lfs 
    mkdir -pv $LFS 
    mount -v /dev/[xxx] $LFS 
    mkdir -pv $LFS 
    mount -v /dev/[xxx] $LFS 
    mkdir -v $LFS/usr 
    mount -v /dev/[yyy] $LFS/usr 

#   ---- 
}

For all LFS Book sections that require you to unpack an archive package, add before the initial # ---- comment a command to change to the source directory, cd [chapter0X source directory], a command to unpack the archive, tar -jxf [package].tar.bz2, and a command to enter into the archive's build directory, cd [package source directory]. If you don't know the actual archive name and directory just add place marks for them. At the end of the function after the ending # ---- comment, add a change to the source directory, cd [chapter0X source directory], and removal of the archive directory, rm -rf [package source directory].

As an example the LFS Book section 5.10 “DejaGNU-1.4.4” would look something like the following.

# DejaGNU-1.4.4 
function chapter05-dejagnu () 
{ 
    echo "chapter05-dejagnu" 
    cd [chapter05 source directory] 
    tar -jxf [DejaGNU-1.4.4].tar.bz2 
    cd [DejaGNU-1.4.4 source directory]
#   ---- 
    ./configure --prefix=/tools 
    make install 
#   ---- 
    cd [chapter05 source directory] 
    rm -rf [DejaGNU-1.4.4 source directory]

}

Note the replacement of cd [chapter0X source directory] with cd [chapter05 source directory].

After all section functions have been added. Add functions for each of the LFS Book Chapters calling its associated LFS Book section functions. The Chapter 4 function is given as an example.

# Final Preparations 
function chapter04 () 
{ 
    chapter04-aboutlfs 
    chapter04-creatingtoolsdir 
    chapter04-addinguser 
    chapter04-settingenvironment 
    chapter04-aboutsbus 
    chapter04-abouttestsuites 
}

And an lfs function calling all the chapter functions.

# Linux From Scratch Version 6.1.1
function lfs ()
{
    prologue
    chapter01
    chapter02
    chapter03
    chapter04
    chapter05
    chapter06
    chapter07
    chapter08
    chapter09
}

At the end of the script add these additional lines.

if ! test -z "$1" 
then 
    $1 
    exit 
fi 

lfs

These commands will be explained later on in Section 3.14, “The Ending”.

The next starting place extracts a XSL dump of commands from the LFS Book's XML files also creates an AFS script template. Your AFS script template identifiers may be different and probably are but the AFS scripts should be similar.

2.1.2. Extracting an AFS script template from the LFS Book's XML files

Extracting an AFS script template from the LFS Book's XML files requires the LFS book's XML files, the packages to convert XML to HTML (text), and the AFS stylesheet, afs.xsl.

The packages required to convert the LFS Book's XML files are described in the LFS Book's INSTALL and README files.

From the LFS 6.1.1 Book's XML INSTALL file:

If you want to convert the XML to HTML, install the following:

* libxml2
  - http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html

* libxslt
  - http://www.linuxfromscratch.org/blfs/view/svn/general/libxslt.html

* DocBook DTD 
  - http://www.linuxfromscratch.org/blfs/view/svn/pst/xml.html

* DocBook XSL Stylesheets 
  - http://www.linuxfromscratch.org/blfs/view/svn/pst/docbook-xsl.html

* HTMLTidy
  - http://www.linuxfromscratch.org/blfs/view/svn/general/tidy.html

Reference Beyond Linux From Scratch (BLFS) on how to install the above packages.

To install the AFS stylesheet copy the afs.xsl file to the LFS Book's XML stylesheet directory.

In the LFS Book's XML directory:

xsltproc --xinclude --nonet stylesheets/afs.xsl index.xml > afs

This will create a file, afs, containing an AFS script template similar to the one produced from Section 2.1.1, “Creating the AFS script template from the LFS Book”.

If you look at the AFS script template, you will see there is still significant editing to be done. You have to add archive package file names, the directories they use, comment out unnecessary LFS book commands, and modify some commands so they can be run inside a Bash script without halting it.

The next starting place, Section 2.1.3, “Downloading a complete afs script”, has all the editing done except for system specific values.

2.1.3. Downloading a complete afs script

A nearly complete AFS script is provided in Appendix B, AFS Completed Example. Only system specific values need to be changed. You can start from this AFS script with only minimal changes.

The next Chapter will tell you what needs to be modified in an AFS script template to create a completed AFS script. It also serves as a way to explain the AFS script in Appendix B, AFS Completed Example.

Chapter 3. Customizing the script

3.1. Introduction

A few special notes about the AFS script.

The LFS Book section 3.1. “Introduction” suggests that a working directory called $LFS/sources be created to unpack the archive packages and build them in. AFS uses the suggested $LFS/sources directory. This directory is accessible for building Chapter 5 archive packages as $LFS/sources and Chapters 6, 7, 8, and 9 archive packages as /sources. In the AFS Booklet and the AFS script template the Chapter 5 sources directory is sometimes referred to as [Chapter 05 sources directory], Chapter 6 sources directory is sometimes referred to as [Chapter 06 sources directory], and so forth. Replace these references with the appropriate directories. If you wish to change these locations, make the appropriate changes to the LFS Book commands and the AFS script commands, substitute with your sources directories.

The LFS Book commands lead you though two types of mode changes, a change from root user to lfs user, and a change from root build to chroot build. Using the LFS Book commands to change to/from these modes causes the AFS script to halt. The AFS script has included these mode changes but in a way that does not halt the AFS script. The AFS script uses the same commands, su and chroot, but in a alternate way. Rather than entering into a mode and then performing all the LFS commands for that mode the script changes the mode before calling each section function. This is performed in the script's chapter functions.

Some of the LFS tests can cause fake errors, see the LFS Book for details. Not all tests may be desirable to perform. Also some of the LFS Book tests are interactive. In these cases alternate commands are given to work around these test issues.

To make understanding the AFS script easier, this booklet assumes all archive packages are in the bzip2 format. I suggest that all archive packages you download for your AFS scrip be converted into the bzip2 format. To convert an archive package, unpack it, gunzip [archive package name].gz in most cases, and pack it with bzip2 [archive package name].

3.2. At the beginning

At the beginning the AFS script assigns the $LFS variable as in the LFS Book's section 4.1. “About $LFS”. Ensure $LFS is set appropriately for your system.

#!/bin/bash

set -e +h
umask 022
export LFS=/mnt/lfs

The command export LFS=/mnt/lfs should be the only statement in the AFS script that sets the LFS variable.

This is the place to set any other script variables you may want.

3.3. Prologue functions

3.3.1. function prologue-typography

Comment out all the LFS Book commands. These are only examples given by the book and are not needed to make a LFS system.

3.4. Chapter 1 functions

No changes needed for Chapter 1 functions.

3.5. Chapter 2 functions

3.5.1. function chapter02-creatingfilesystem

Comment out the note commands and any commands that are not necessary for your build. Also include your device parameters. For example, my build requires a new file system on /dev/hda3 and does not require swap space.

# ----

    /sbin/mke2fs -v /dev/hda3

#   debugfs -R feature /dev/[xxx]
#
#   cd /tmp
#   tar -xjvf /path/to/sources/e2fsprogs-1.37.tar.bz2
#   cd e2fsprogs-1.37
#   mkdir -v build
#   cd build
#   ../configure
#   make #note that we intentionally don't 'make install' here!
#   ./misc/mke2fs -v /dev/[xxx]
#   cd /tmp
#   rm -rfv e2fsprogs-1.37

#   mkswap -v /dev/[yyy]

#   ----

3.5.2. function chapter02-mounting

Comment out the export LFS command and all other commands you do not need. Add your LFS system's configuration.

# ----

#   export LFS=/mnt/lfs

    mkdir -pv $LFS
    mount -v -t ext2 /dev/hda3 $LFS

#   mkdir -pv $LFS
#   mount -v /dev/[xxx] $LFS
#   mkdir -v $LFS/usr
#   mount -v /dev/[yyy] $LFS/usr

#   ----

3.6. Chapter 3 functions

3.6.1. function chapter03-introduction

Add the following to copy the archive packages to the LFS build directory.

    chmod -v a+wt $LFS/sources

    cp sources/* $LFS/sources/

#   ----

3.7. Chapter 4 functions

3.7.1. function chapter04-aboutlfs

Comment out export LFS=/mnt/lfs. The $LFS variable should only be assigned at the beginning of the script.

#   export LFS=/mnt/lfs

3.7.2. function chapter04-addinguser

Comment out passwd lfs. This is an interactive command that will halt the script until a password is typed in.

#   passwd lfs

Comment out the su - lfs command. Again this will halt the script. The script uses an alternate method of changing to lfs user.

#   su - lfs

Add two commands at the end of the function to copy the AFS script to the sources directory and change its ownership to lfs.

#   su - lfs

    cp afs $LFS/sources/afs
    chown -v lfs $LFS/sources/afs

#   ----

3.7.3. function chapter04-settingenvironment

Comment out the source ~/.bash_profile command. Since we did not login as lfs user executing this command would run a different .bashrc than was created in this section.

#   source ~/.bash_profile

3.8. Chapter 5 functions

Chapter 5 functions require additional scripting to support the unpacking of archives, changing to the archive's source directory, and at the end returning to the sources directory, and removing the archive's source directory.

For each of Chapter 5 functions that builds a package ensure at the beginning the function includes:

function <section-name> ()
{
    cd $LFS/sources
    tar -jxf [package-archive]
    cd [archive-directory]
#   ----

And at the ending the function includes:

#   ----
    cd $LFS/sources
    rm -rf [archive-directory]
}

As an example the LFS Book section 5.4. “GCC-3.4.3 - Pass 1” would be modified to the following.

function chapter05-gcc-pass1 ()
{ 
    echo "chapter05-gcc-pass1";
    cd $LFS/sources
    tar -jxf gcc-3.4.3.tar.bz2
    cd gcc-3.4.3
#   ----
    mkdir -v ../gcc-build
    cd ../gcc-build

    ../gcc-3.4.3/configure --prefix=/tools \
        --libexecdir=/tools/lib --with-local-prefix=/tools \
        --disable-nls --enable-shared --enable-languages=c

    make bootstrap

    make install

    ln -vs gcc /tools/bin/cc
#   ----
    cd $LFS/sources
    rm -rf gcc-build
    rm -rf gcc-3.4.3
}

At the beginning of the function:

cd $LFS/sources

Change to the sources directory. If you are using LFS Book's suggest sources directory this would be $LFS/sources.

tar -jxf gcc-3.4.3.tar.bz2

Unpack the gcc-3.4.3 archive. Remember to include the appropriate switches for the archive.

cd gcc-3.4.3

Change to the package directory. The package directory is not always the same as the package name. Unpack each package, use the -t option, and determine what directory it unpacks to.

At the ending of the function:

cd $LFS/sources

Return to the sources directory.

rm -rf gcc-build

Remove the build directory.

rm -rf gcc-3.4.3

Remove the archive package directory.

In most cases the archive package directory will be the only directory you need to remove. However, because gcc required a build directory it also has to be removed.

As you might remember from building your first LFS system there are several special cases. Not all the packages are built the same, some packages require you to keep directories for adjusting the tool chain, Binutils, and some functions do not unpack and build source code. Here are the exceptions and the script commands for them.

3.8.1. chapter05-binutils-pass1

Remember to keep the binutils directory and its build directory, binutils-build. Remove these directories in chapter05-adjusting function. You do not technically need the cd $LFS/sources command but it does not affect the AFS script. I leave it in anyway.

#   ----
    cd $LFS/sources
#   rm -rf [Binutils-2.15.94.0.2.2 - Pass 1 source directory]
}

3.8.2. function chapter05-glibc

Comment out the make check command. Running this test can be a problem for some systems as noted by the LFS Book. You can add the command; however, it may halt your build mistakenly if a false error is found.

#   make check

Comment out the locale code if you are not running the test.

#   make localedata/install-locales

 

#   mkdir -pv /tools/lib/locale
#   localedef -i de_DE -f ISO-8859-1 de_DE
#   localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
#   localedef -i en_HK -f ISO-8859-1 en_HK
#   localedef -i en_PH -f ISO-8859-1 en_PH
#   localedef -i en_US -f ISO-8859-1 en_US
#   localedef -i es_MX -f ISO-8859-1 es_MX
#   localedef -i fa_IR -f UTF-8 fa_IR
#   localedef -i fr_FR -f ISO-8859-1 fr_FR
#   localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
#   localedef -i it_IT -f ISO-8859-1 it_IT
#   localedef -i ja_JP -f EUC-JP ja_JP

3.8.3. chapter05-adjusting

Add the command to change to the Chapter 5 sources directory.

{
    echo "chapter05-adjusting"
    cd $LFS/sources
#   ----

Read the LFS book carefully. Some needed LFS commands are not provided as commands. One is the command to change to the binutils-build directory before executing make -C ld install and returning to the sources directory afterwards. Here are the script commands to add.

    cd $LFS/sources
#   ----

    cd binutils-build

    make -C ld install

    cd $LFS/sources
    rm -rf binutils-build
    rm -rf [Binutils-2.15.94.0.2.2 - Pass 1 source directory]

There is a tool chain test that requires manual inspection. Comment out the test lines and add theses script commands to automate the check.

    echo 'main(){}' > dummy.c
    cc dummy.c
#   readelf -l a.out | grep ': /tools'

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /tools/lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter05-adjusting"
        exit 1
    fi

    rm -v dummy.c a.out

The readelf -l a.out | grep ': /tools command is replaced with a grep of the required text to verify proper library linkage. The grep result is assigned to TOOLCHAIN_TEST. If TOOLCHAIN_TEST is null then report the error and exit the script with error code 1.

3.8.4. chapter05-tcl

Comment out export TCLPATH=`pwd`. Because of the method we are using to change to lfs user mode, shell variable value's between archive builds will not be saved.

    cd ..
#   export TCLPATH=`pwd`

    ln -sv tclsh8.4 /tools/bin/tclsh

Comment out the rm -rf [Tcl-8.4.9 source directory] command. The Expect archive package will need its internal headers.

#   ----
    cd $LFS/sources
#   rm -rf [Tcl-8.4.9 source directory]
}

3.8.5. chapter05-expect

Hard code the TCLPATH (../tcl8.4.9) in the configure command.

    patch -Np1 -i ../expect-5.43.0-spawn-1.patch

    ./configure --prefix=/tools --with-tcl=/tools/lib \
       --with-tclinclude=../tcl8.4.9 --with-x=no

    make

Comment out the unset TCLPATH since it was never used.

#   unset TCLPATH

You can now remove the tcl archive directory.

    rm -rf [Expect-5.43.0 source directory]
    rm -rf [Tcl-8.4.9 source directory]
}

3.8.6. function chapter05-gcc-pass2

Comment out the make -k check test and the command to receive a summary of the test results.

#    make -k check

#    ../gcc-3.4.3/contrib/test_summary

The LFS Book recommends to repeat the sanity check performed in chapter05-adjusting.

    make install

    echo 'main(){}' > dummy.c
    cc dummy.c

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /tools/lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter05-adjusting"
        exit 1
    fi

    rm -v dummy.c a.out

#   ----

3.8.7. function chapter05-binutils-pass2

The binutils-2.15.94.0.2.2 directory is need in 6.12. "Re-adjusting the Toolchain". Comment out the removal of the directory.

#   ----
    cd $LFS/sources
#   rm -rf [Binutils-2.15.94.0.2.2 - Pass 2 source directory]
}

3.8.8. function chapter05-stripping

The two strip commands return errors. This will halt the script. To avoid this use the set command to turn off script error exits and turn it back on after performing the strip commands.

    set +e

    strip --strip-debug /tools/lib/*
    strip --strip-unneeded /tools/{,s}bin/*

    set -e

3.8.9. The remaining Chapter functions

The remaining changes to the script commands for Chapter 5 can be modified in a manner similar to what has been shown. Remember to make sure you read the LFS Book thoroughly so you will pick up on all the necessary commands.

3.9. Chapter 6 functions

Chapter 6 modifications are very similar to Chapter 5's. Mainly unpacking archives, changing directories, and removing the archive directories.

As an example the LFS Book section 6.15. “Coreutils-5.2.1” would be modified to the following.

function chapter06-coreutils ()
{ 
    echo "chapter06-coreutils";
    cd /sources
    tar -jxf coreutils-5.2.1.tar.bz2
    cd coreutils-5.2.1
# ----
    patch -Np1 -i ../coreutils-5.2.1-uname-2.patch

    patch -Np1 -i ../coreutils-5.2.1-suppress_uptime_kill_su-1.patch

    DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/usr

    make

    echo "dummy1:x:1000:" >> /etc/group
    echo "dummy2:x:1001:dummy" >> /etc/group
    echo "dummy:x:1000:1000:::/bin/bash" >> /etc/passwd

    make NON_ROOT_USERNAME=dummy check-root

    src/su dummy -c "make RUN_EXPENSIVE_TESTS=yes check"

    sed -i '/dummy/d' /etc/passwd /etc/group

    make install

    mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
    mv -v /usr/bin/{false,hostname,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
    mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
    mv -v /usr/bin/chroot /usr/sbin

    mv -v /usr/bin/{head,sleep} /bin
#   ----
    cd /sources
    rm -rf coreutils-5.2.1
}

As in Chapter 5 there are some exceptions. Here are the exceptions that need to be handled.

3.9.1. function chapter06-chroot

Chapter 6 requires you to enter into chroot build mode. There are two ways to accomplish this. The first is to enter chroot and remain until all packages have been built. The second is to enter into chroot before each LFS Book section and exit chroot at the end after the package is built. This is the method the AFS script uses. Because of this, we do not need to perform the chroot command at this place in the script. Comment out all of chapter06-chroot.

#   chroot "$LFS" /tools/bin/env -i \
#       HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
#       PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
#       /tools/bin/bash --login +h

3.9.2. function chapter06-pwdgroup

To avoid having to set the password remove x in the password field of the passwd file.

    cat > /etc/passwd << "EOF"
root::0:0:root:/root:/bin/bash
EOF

Comment out the exec /tools/bin/bash --login +h command. Executing the next section function in Chapter 6 will assign a name.

#   exec /tools/bin/bash --login +h

3.9.3. chapter06-glibc

The LFS Book states, “In this section, the test suite for Glibc is considered critical. Do not skip it under any circumstance.” Also “The Glibc test suite is highly dependent on certain functions of the host system, in particular the kernel. In general, the Glibc test suite is always expected to pass. However, in certain circumstances, some failures are unavoidable.

Depending on the results of the test suite during your manual build, if it fails incorrectly, you may want to comment out the test suite commands.

#   make -k check >glibc-check-log 2>&1
#   grep Error glibc-check-log

Comment out the optional locale build you don't want. In the example all locales are installed.

  make localedata/install-locales

#   mkdir -pv /usr/lib/locale
#   localedef -i de_DE -f ISO-8859-1 de_DE
#   localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
#   localedef -i en_HK -f ISO-8859-1 en_HK
#   localedef -i en_PH -f ISO-8859-1 en_PH
#   localedef -i en_US -f ISO-8859-1 en_US
#   localedef -i es_MX -f ISO-8859-1 es_MX
#   localedef -i fa_IR -f UTF-8 fa_IR
#   localedef -i fr_FR -f ISO-8859-1 fr_FR
#   localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
#   localedef -i it_IT -f ISO-8859-1 it_IT
#   localedef -i ja_JP -f EUC-JP ja_JP

Comment out the tzselect command. It is only used to determine the timezone to configure your LFS system for. Add your timezone to the following command.

# End /etc/nsswitch.conf
EOF

#   tzselect

    cp -v --remove-destination /usr/share/zoneinfo/[xxx] \
        /etc/localtime

    cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

3.9.4. chapter06-readjusting

Change the chapter06-readjusting function as you did for chapter05-adjusting. Add the change to the Chapter 6 sources directory.

{
    echo "chapter06-readjusting"
    cd /sources
#   ----

Add in the change of directory to binutils-build before make -C ld INSTALL=/tools/bin/install install, and add the removing of the binutils package source directory and the binutils-build directory created in chapter05-binutils-pass2.

#   ----

    cd binutils-build

    make -C ld INSTALL=/tools/bin/install install

    cd /sources
    rm -rf binutils-build
    rm -rf [Binutils-2.15.94.0.2.2 - Pass 2 source directory]

    perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' \

For the tool chain test there is a difference, in chapter05-adjusting the grep looked for /tools, in chapter06-readjusting it should look for /lib.

    cc dummy.c
#   readelf -l a.out | grep ': /lib'

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter06-readjusting"
        exit 1
    fi

    rm -v dummy.c a.out

3.9.5. chapter06-gcc

Add the recommended LFS scripted sanity check from chapter06-readjusting. Do not forget to compile dummy.c before the test.

    ln -sv gcc /usr/bin/cc

    echo 'main(){}' > dummy.c
    cc dummy.c

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter06-readjusting"
        exit 1
    fi

    rm -v dummy.c a.out

#   ----

3.9.6. chapter06-vim

Add the optional unpacking of the vim-6.3-lang.tar archives into the directory as Vim-6.3 source directory.

    cd /sources
    tar -jxf [Vim-6.3].tar.bz2
    tar -jxf [Vim-6.3-lang].tar.bz2
    cd [Vim-6.3 source directory]
#   ----

3.9.7. chapter06-bash

Comment out running the newly compiled Bash program command, exec /bin/bash --login +h. The new Bash shell will be executed for all further mode chroot mode changes.

#    exec /bin/bash --login +h

3.9.8. chapter06-shadow

Comment out setting the root password. The passwd command is interactive an will halt the script. Be sure upon booting into your new LFS system you first set the root password.

#    passwd root

3.9.9. chapter06-strippingagain

Comment out the logout command. The logout command would halt the script.

#    logout

Comment out the new revised chroot command.

#    chroot $LFS /tools/bin/env -i \
#        HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
#        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
#        /tools/bin/bash --login

Add turn off exit on script error before striping. Turn it back on after stripping.

    set +e

    /tools/bin/find /{,usr/}{bin,lib,sbin} -type f \
       -exec /tools/bin/strip --strip-debug '{}' ';'

    set -e

3.9.10. chapter06-revisedchroot

Comment out the revised chroot command comment.

# chroot "$LFS" /usr/bin/env -i \
#     HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
#     PATH=/bin:/usr/bin:/sbin:/usr/sbin \
#     /bin/bash --login

If you wish add the command to remove the /tools directory.

    rm -rf /tools

3.10. Chapter 7 functions

The majority of Chapter 7 commands are to configure and customize a LFS system. Usually there are optional commands present. Only keep the commands for the configuration you want. Comment out the others that are not needed.

3.10.1. chapter07-udev

Comment out the device and module example.

# install snd-pcm modprobe -i snd-pcm ; modprobe \
#       snd-pcm-oss ; true

3.10.2. chapter07-console

Add your console configuration and comment out all other examples.

    cat >/etc/sysconfig/console <<"EOF"
KEYMAP="[arguments for loadkeys]"
FONT="[arguments for setfont]"
EOF

3.10.3. chapter07-profile

Comment out the locale command examples.

#   locale -a

 

#   LC_ALL=[locale name] locale charmap

 

#    LC_ALL=[locale name] locale country
#    LC_ALL=[locale name] locale language
#    LC_ALL=[locale name] locale charmap
#    LC_ALL=[locale name] locale int_curr_symbol
#    LC_ALL=[locale name] locale int_prefix

Add your locale configuration.

    cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=[ll]_[CC].[charmap]
export INPUTRC=/etc/inputrc

# End /etc/profile
EOF

3.10.4. chapter07-hosts

Configure your network connection and comment out all others.

If you are connecting to a network.

    cat > /etc/hosts << "EOF"
# Begin /etc/hosts (network card version)

127.0.0.1 localhost
[192.168.1.1] [<HOSTNAME>.example.org] [HOSTNAME]

# End /etc/hosts (network card version)
EOF

If you are not connecting to a network

    cat > /etc/hosts << "EOF"
# Begin /etc/hosts (no network card version)

127.0.0.1 [<HOSTNAME>.example.org] [HOSTNAME] localhost

# End /etc/hosts (no network card version)
EOF

3.10.5. chapter07-network

If you are connecting to a local LAN configure your network script.

    cd /etc/sysconfig/network-devices &&
    mkdir -v ifconfig.eth0 &&
    cat > ifconfig.eth0/ipv4 << "EOF"
ONBOOT=yes
SERVICE=ipv4-static
IP=192.168.1.1
GATEWAY=192.168.1.2
PREFIX=24
BROADCAST=192.168.1.255
EOF

Create the /etc/resolv.conf file.

    cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

domain {[Your Domain Name]}
nameserver [IP address of your primary nameserver]
nameserver [IP address of your secondary nameserver]

# End /etc/resolv.conf
EOF

3.11. Chapter 8 functions

Changes to Chapter 8 functions are primary system configuration commands with the exception of building the Linux kernel.

3.11.1. chapter08-fstab

Configure your fstab file.

    cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point  type   options         dump  fsck
#                                                        order

/dev/[xxx]     /            [fff]  defaults        1     1
/dev/[yyy]     swap         swap   pri=1           0     0
proc           /proc        proc   defaults        0     0
sysfs          /sys         sysfs  defaults        0     0
devpts         /dev/pts     devpts gid=4,mode=620  0     0
shm            /dev/shm     tmpfs  defaults        0     0
# End /etc/fstab
EOF

3.11.2. chapter08-kernel

If you decided to compile the keymap into the kernel, configure the loadkeys command.

   make mrproper

   loadkeys -m /usr/share/kbd/keymaps/[path to  keymap] > \
       drivers/char/defkeymap.c

   make menuconfig

To avoid running make menuconfig, copy a Linux kernel configuration file to .config in the Linux directory. In the script, run make oldconfig to load the new configuration. You can make a Linux kernel configuration file by running make menuconfig and saving the configuration file to lfs-kernel-[kernel version].cfg in your sources directory.

   loadkeys -m /usr/share/kbd/keymaps/[path to  keymap] > \
       drivers/char/defkeymap.c

#   make menuconfig
    cp ../lfs-kernel-[kernel version].cfg .config
    make oldconfig

    make

3.11.3. function chapter08-grub

Comment out the commands for making a GRUB boot floppy diskette. After your LFS System has been created, you can use the chroot command and run these commands. You can also run the commands outside of the chroot by adding the $LFS before the /boot/grub such as dd if=$LFS/boot/grub/stage1 of=/dev/fd0 bs=512 count=1.

#   dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1
#   dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1

Comment out the command to run Grub and the Grub commands.

#   grub
#   
#   root (hd0,3)
#   
#   setup (hd0)
#   
#   quit

Configure GRUB's boot menu and comment out all others.

    cat > /boot/grub/menu.lst << "EOF"
# Begin /boot/grub/menu.lst

# By default boot the first menu entry.
default 0

# Allow 30 seconds before booting the default.
timeout 30

# Use prettier colors.
color green/black light-green/black

# The first entry is for LFS.
title LFS 6.1.1
root (hd0,3)
kernel /boot/lfskernel-2.6.11.12 root=/dev/hda4
EOF

#  cat >> /boot/grub/menu.lst << "EOF"
#title Red Hat
#root (hd0,2)
#kernel /boot/kernel-2.6.5 root=/dev/hda3
#initrd /boot/initrd-2.6.5
#EOF

#   cat >> /boot/grub/menu.lst << "EOF"
#title Windows
#rootnoverify (hd0,0)
#chainloader +1
#EOF

If you wish, you can script Grub by using the grub-install command. However, this is not recommend since Grub changes your boot process and potentially can stop your computer from booting correctly. It is recommended you run the LFS Book Grub commands after the AFS script has been executed and you have checked the LFS system files. If you do not have Grub installed on the build system, you can enter the chroot build as documented in the LFS Book to run the LFS Book Grub commands.

From the LFS Book, 6.2. “Mounting Virtual Kernel File Systems”:

mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys

Remember that if for any reason you stop working on the LFS system and start again later, it is important to check that these file systems are mounted again before entering the chroot environment.

And from, 6.3. “Entering the Chroot Environment”:

It is important that all the commands throughout the remainder of this chapter and the following chapters are run from within the chroot environment. If you leave this environment for any reason (rebooting for example), remember to first mount the proc and devpts file systems (discussed in the previous section) and enter chroot again before continuing with the installations.

And from 6.62. “Cleaning Up”:

From now on, when reentering the chroot environment after exiting, use the following modified chroot command:

chroot "$LFS" /usr/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login

Replace the $LFS with your $LFS scripts value.

After entering into the chroot environment run /sbin/udevstart to populate the /dev directory before running grub.

3.12. Chapter 9 functions

Chapter 9 functions clean up after building your LFS system. However, it is recommended that you perform a reboot after building to protect your build system and your new LFS system files.

3.12.1. chapter09-reboot

Comment out the logout command.

#   logout

Comment out any unnecessary umount commands.

#   umount -v $LFS/usr
#   umount -v $LFS/home
#   umount -v $LFS

Comment out the shutdown command.

#   shutdown -r now

3.13. Chapter functions

If you have followed AFS so far, you should have several chapter functions that call the LFS Book section functions, the functions that contain the LFS Book commands. This is done to organize the AFS script and provide a place to control the mode changes needed.

For the chapter functions of Prologue, Chapter 1, Chapter 2 and Chapter 3 add a function call to each chapter's sections.

As an example the function for Chapter 2 would look something like the following.

# Preparing a New Partition
function chapter02 ()
{
    chapter02-introduction
    chapter02-creatingpartition
    chapter02-creatingfilesystem
    chapter02-mounting
}

For the other chapters we have to include the mode changes.

3.13.1. function chapter04

For the last three sections of Chapter 4 the LFS Book requires you to login as lfs user. The su - lfs command puts you into an interactive shell which would halt the AFS script. To modify the AFS script so the su command will run, use the su command with the -c option. This option runs the commands given to su and then returns. This is the script command for calling 4.4. “Setting Up the Environment” section function using the LFS Book's suggested source directory.

su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-settingenvironment"

Execute the AFS script function in lfs user mode.

su - lfs -c "<command>"

Run the command in quotes as the lfs user.

source ~/.bashrc

Run the lfs user's .bashrc file. This sets up the lfs environment as required by the LFS book.

$LFS/sources/afs chapter04-settingenvironment

Run the AFS script function for section 4.4 “Setting Up the Environment”.

The function for Chapter 4 should look similar to the following.

# Final Preparations
function chapter04 ()
{
    chapter04-aboutlfs
    chapter04-creatingtoolsdir
    chapter04-addinguser
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-settingenvironment"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-aboutsbus"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-abouttestsuites"
}

3.13.2. function chapter05

All Chapter 5 functions in the LFS book are executed in lfs user mode. As in some of the function calls in the Chapter 4 function, all calls in the Chapter 5 function to its sections must use the su - lfs -c command.

The Chapter 5 function should look similar to the following.

# Constructing a Temporary System
function chapter05 ()
{
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-introduction"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-toolchaintechnotes"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-binutils-pass1"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gcc-pass1"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-linux-libc-headers"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-glibc"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-adjusting"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-tcl"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-expect"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-dejagnu"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gcc-pass2"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-binutils-pass2"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gawk"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-coreutils"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-bzip2"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gzip"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-diffutils"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-findutils"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-make"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-grep"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-sed"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gettext"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-ncurses"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-patch"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-tar"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-texinfo"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-bash"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-m4"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-bison"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-flex"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-util-linux"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-perl"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-stripping"
}

3.13.3. function chapter06

Most section functions for Chapter 6 must be in chroot build mode. Like the mode change performed for lfs user we use a modified form of the chroot command.

To make the script more readable, the AFS script assigns the chroot command to a Bash variable which Bash expands before executing.

CHRTLFS="chroot $LFS /tools/bin/env -i HOME=/root \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
   /tools/bin/bash --login "

As you can see it is almost the same as the LFS Book command. The TERM="$TERM" PS1='\u:\w\$ ' has been removed because it is not necessary when running a non-interactive bash shell.

The CHRTLFS variable is used to execute the function. The command also uses the LFS Book's suggested sources directory.

$CHRTLFS /sources/afs chapter06-changingowner

Execute the AFS script function in chroot build mode.

$CHRTLFS

Expand the assigned value, the chroot command.

/sources/afs

Run the AFS script.

chapter06-changingowner

The AFS script uses the first command line value to run the function given. Run the function called chapter06-changingowner.

The Chapter 6 function should look similar to the following.

# Installing Basic System Software
function chapter06 ()
{
     CHRTLFS="chroot $LFS /tools/bin/env -i HOME=/root \
       PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
       /tools/bin/bash --login "

    chapter06-introduction
    chapter06-kernfs
    chapter06-chroot

    $CHRTLFS /sources/afs chapter06-changingowner
    $CHRTLFS /sources/afs chapter06-creatingdirs
    $CHRTLFS /sources/afs chapter06-createfiles
    $CHRTLFS /sources/afs chapter06-pwdgroup
    $CHRTLFS /sources/afs chapter06-devices
    $CHRTLFS /sources/afs chapter06-linux-libc-headers
    $CHRTLFS /sources/afs chapter06-man-pages
    $CHRTLFS /sources/afs chapter06-glibc
    $CHRTLFS /sources/afs chapter06-readjusting
    $CHRTLFS /sources/afs chapter06-binutils
    $CHRTLFS /sources/afs chapter06-gcc
    $CHRTLFS /sources/afs chapter06-coreutils
    $CHRTLFS /sources/afs chapter06-zlib
    $CHRTLFS /sources/afs chapter06-mktemp
    $CHRTLFS /sources/afs chapter06-iana-etc
    $CHRTLFS /sources/afs chapter06-findutils
    $CHRTLFS /sources/afs chapter06-gawk
    $CHRTLFS /sources/afs chapter06-ncurses
    $CHRTLFS /sources/afs chapter06-readline
    $CHRTLFS /sources/afs chapter06-vim
    $CHRTLFS /sources/afs chapter06-m4
    $CHRTLFS /sources/afs chapter06-bison
    $CHRTLFS /sources/afs chapter06-less
    $CHRTLFS /sources/afs chapter06-groff
    $CHRTLFS /sources/afs chapter06-sed
    $CHRTLFS /sources/afs chapter06-flex
    $CHRTLFS /sources/afs chapter06-gettext
    $CHRTLFS /sources/afs chapter06-inetutils
    $CHRTLFS /sources/afs chapter06-iproute2
    $CHRTLFS /sources/afs chapter06-perl
    $CHRTLFS /sources/afs chapter06-texinfo
    $CHRTLFS /sources/afs chapter06-autoconf
    $CHRTLFS /sources/afs chapter06-automake
    $CHRTLFS /sources/afs chapter06-bash
    $CHRTLFS /sources/afs chapter06-file
    $CHRTLFS /sources/afs chapter06-libtool
    $CHRTLFS /sources/afs chapter06-bzip2
    $CHRTLFS /sources/afs chapter06-diffutils
    $CHRTLFS /sources/afs chapter06-kbd
    $CHRTLFS /sources/afs chapter06-e2fsprogs
    $CHRTLFS /sources/afs chapter06-grep
    $CHRTLFS /sources/afs chapter06-grub
    $CHRTLFS /sources/afs chapter06-gzip
    $CHRTLFS /sources/afs chapter06-hotplug
    $CHRTLFS /sources/afs chapter06-man
    $CHRTLFS /sources/afs chapter06-make
    $CHRTLFS /sources/afs chapter06-module-init-tools
    $CHRTLFS /sources/afs chapter06-patch
    $CHRTLFS /sources/afs chapter06-procps
    $CHRTLFS /sources/afs chapter06-psmisc
    $CHRTLFS /sources/afs chapter06-shadow
    $CHRTLFS /sources/afs chapter06-sysklogd
    $CHRTLFS /sources/afs chapter06-sysvinit
    $CHRTLFS /sources/afs chapter06-tar
    $CHRTLFS /sources/afs chapter06-udev
    $CHRTLFS /sources/afs chapter06-util-linux
    $CHRTLFS /sources/afs chapter06-aboutdebug

    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /tools/bin/bash --login "

    $CHRT /sources/afs chapter06-strippingagain

    chapter06-revisedchroot
}

LFS Book sections 6.1. “Introduction” (chapter06-introduction), 6.2. “Mounting Virtual Kernel File Systems” (chapter06-kernfs), 6.3. “Entering the Chroot Environment” (chapter06-chroot), and 6.62. “Cleaning Up” (chapter06-revisedchroot) are not required to be in the chroot environment. LFS Book section 6.61. “Stripping Again” requires a different chroot command.

3.13.4. function chapter07

Like Chapter 6, Chapter 7 must also enter into the chroot build mode. However, the chroot command is different but is handled in the same way as Chapter 6. Assign the chroot command to a Bash variable and execute the AFS script function. In Chapter 7 all LFS Book sections must be executed in the chroot build mode.

# Setting Up System Bootscripts
function chapter07 ()
{
    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /tools/bin/bash --login "

    $CHRT /sources/afs chapter07-introduction
    $CHRT /sources/afs chapter07-bootscripts
    $CHRT /sources/afs chapter07-usage
    $CHRT /sources/afs chapter07-udev
    $CHRT /sources/afs chapter07-setclock
    $CHRT /sources/afs chapter07-console
    $CHRT /sources/afs chapter07-sysklogd
    $CHRT /sources/afs chapter07-inputrc
    $CHRT /sources/afs chapter07-profile
    $CHRT /sources/afs chapter07-hostname
    $CHRT /sources/afs chapter07-hosts
    $CHRT /sources/afs chapter07-network
}

3.13.5. function chapter08

All Chapter 8 functions must be executed in chroot build mode.

# Making the LFS System Bootable
function chapter08 ()
{
    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
       /tools/bin/bash --login "

    $CHRT /sources/afs chapter08-introduction
    $CHRT /sources/afs chapter08-fstab
    $CHRT /sources/afs chapter08-kernel
    $CHRT /sources/afs chapter08-grub
}

3.13.6. function chapter09

Some Chapter 9 section functions must be executed in chroot build mode but with a different chroot command. Sections 9.3. “Rebooting the System” (chapter09-reboot) and 9.4. “What Now?” (chapter09-whatnow) do not.

# The End
function chapter09 ()
{
    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /tools/bin/bash --login "

    $CHRT /sources/afs chapter09-theend
    $CHRT /sources/afs chapter09-getcounted

    chapter09-reboot
    chapter09-whatnow
}

3.13.7. function lfs

The last AFS script function, lfs, calls all the AFS script functions that build your LFS system.

# Linux From Scratch Version 6.1.1
function lfs ()
{
    prologue
    chapter01
    chapter02
    chapter03
    chapter04
    chapter05
    chapter06
    chapter07
    chapter08
    chapter09
}

3.14. The Ending

During execution of a Bash scrip all functions are ignored until called. Thus the AFS script must call the lfs function to start the build.

The AFS script will execute with an AFS script function as the first parameter. With an AFS function the script will execute that function; without it, the script will execute lfs and start the LFS build.


if ! test -z "$1"
then
    $1
    exit
fi

lfs

#End afs (Automating From Scratch) - Linux From Scratch Version 6.1.1
if ! test -z "$1"

Tests if the first parameter to the AFS script is an empty string.

$1

Execute the AFS script function in $1, the first parameter to the AFS script. This is how AFS script functions are executed.

exit

Exit the AFS script

lfs

Execute the lfs function. This starts the LFS build.

This completes the AFS script. Save the AFS script as afs and close your editor. To make the script executable use chmod u+x afs.

3.15. Checking Your AFS Script

Before running the script it is recommend you review and check that you have made all the appropriate changes.

Check that you

  • used the appropriate build partition and file system commands in:

    • Section 2.3. “Creating a File System on the Partition”,

    • and section 2.4. “Mounting the New Partition”,

    It is critical the partition and file system commands are correct so as not to damage your build system.

  • did not remove package source directories in:

    • 5.3. “Binutils-2.15.94.0.2.2 - Pass 1” - binutils-2.15.94.0.2.2 and binutils-build directories,

    • 5.8. “Tcl-8.4.9” - tcl8.4.9 directory,

    • and 5.12. “Binutils-2.15.94.0.2.2 - Pass 2” - binutils-2.15.94.0.2.2 and binutils-build directories,

  • removed directories in:

    • 5.4. “GCC-3.4.3” - Pass 1 - gcc-build directory,

    • 5.6. “Glibc-2.3.4” - glibc-build directory,

    • 5.7. “Adjusting the Toolchain” - binutils-build directories,

    • 5.9. “Expect-5.43.0” - tcl8.4.9 directory,

    • 5.11. “GCC-3.4.3” - Pass 2 - gcc-build directory,

    • 6.11. “Glibc-2.3.4” - glibc-build directory,

    • 6.12. “Re-adjusting the Toolchain” - binutils-2.15.94.0.2.2 and binutils-build directories,

    • 6.13. “Binutils-2.15.94.0.2.2” - binutils-2.15.94.0.2.2 and binutils-build directories,

    • and 6.14. “GCC-3.4.3” - gcc-build,

  • change to the sources directory in:

    • 5.7. “Adjusting the Toolchain”,

    • and 6.12. “Re-adjusting the Toolchain”,

  • commented out the optional commands in:

    • 5.6. “Glibc-2.3.4”,

    • 6.11. “Glibc-2.3.4”,

    • 6.23. “Vim-6.3”,

    • and 6.34. “Texinfo-4.8”,

  • commented out the tests commands in:

    • 5.6. “Glibc-2.3.4”,

    • 5.11. “GCC-3.4.3 - Pass 2”,

    • 5.12. “Binutils-2.15.94.0.2.2 - Pass 2”,

    • 6.11. “Glibc-2.3.4”,

    • 6.13. “Binutils-2.15.94.0.2.2”,

    • 6.14. “GCC-3.4.3”,

    • 6.15. “Coreutils-5.2.1”,

    • 6.33. “Perl-5.8.7”,

    • and 6.50. “Module-Init-Tools-3.1”,

  • copied the udev-config-4.rules file to the sources directory,

  • copied your Linux kernel config file, lfs-kernel-[kernel version].cfg, to the sources directory,

  • replaced all references to [chapter05 source directory], [chapter06 source directory], [chapter07 source directory], and [chapter08 source directory] with your sources directory. If you are using the LFS Book's suggested sources directory then[chapter05 source directory] should be $LFS/sources and [chapter06 source directory], [chapter07 source directory], and [chapter08 source directory] should be /sources,

  • and replaced all the archive package names with the appropriate file names. Also check that the tar command is using the correct parameter for unpacking the archive, -z for gz and -j for bz2.

Building your LFS system

Table of Contents

Chapter 4. Debugging the afs script

4.1. Introduction

You should have a complete AFS script. All that is left is to do is run and debug the script. To run the AFS script type, ./afs, as root while in the directory with the AFS script and a directory of source archive packages and patches. Be sure to also include your kernel configuration file in the sources directory.

Running the AFS script could damage your existing build system if any of the scripts numerous damaging commands are not executed in the appropriate mode. Ensure you have a backup and a rescue method, boot floppy or cd, to recover your build system from any problems.

There is one overall good method to use when testing the script, adding, removing, and commenting out AFS script commands. Add commands to the AFS script to determine what it is doing and to control the scripts program flow as needed for debugging.

4.2. Restarting the afs script

You can use the scripts main commands to run an AFS script function. However, be sure you are in the appropriate mode, root user, lfs user or chroot build, before executing the script function. In most cases, If you are running Chapter 5 functions, be sure you are logged in as lfs user. If you are running Chapter 6,7, and 8 functions, be sure you are in the appropriate chroot build mode. The LFS Book gives you the commands you need to change into the right mode. You can also look at the AFS script to determine which mode you should be in. To run an AFS script function type:./afs <function-name>.

4.3. Using the read command

You can use the Bash builtin read command to temporarily halt the AFS script. Then log onto the system in another terminal (pressing Alt-<digit>) to review any logs, evaluate any files, or enter the appropriate mode and test a command. Include the -p option with read to provide a prompt to display why you stopped. When you are done checking return to the original terminal and press Enter to continue.

4.4. Using the false command

The AFS script is setup to halt on any error. You can use the Bash false builtin command to halt the AFS script by forcing an error.

4.5. Using logs

If you are not sure what is going on, you can use the echo command to create a log file. Echo some text to a file: echo "chapter 6 gcc build step 1" >> gccbuild. Note that when in Chapter 5 the log will be placed in the building system and when in Chapter 6, 7, and 8 the log will be placed in the chroot system.

Chapter 5. Building the System

5.1. Introduction

You should now have an AFS script to build your LFS system. Type ./afs as root while in the AFS directory to build your LFS system. Be sure the directory also has all the source archive packages and patches in a sources directory. The sources directory should also have your kernel configuration file to build your Linux kernel.

5.2. Cleaning Up

The LFS Book commands do not completely clean up all the root build system changes. Most notably lfs user is still defined. To delete lfs user execute userdel lfs. The /tools directory may not be deleted, see the LFS Book's section 6.62. “Cleaning Up”. To delete /tools execute rm -rf /tools.

Afterwards

Table of Contents

Chapter 6. Additional functions and modifications

6.1. Introduction

The AFS script is for building your LFS system - customise it.

You can start modifying your AFS script to further customize your LFS system. Add in package logging, add in building BLFS packages, or add in other build options. It is up to you to. Here are some suggestions.

6.2. Logging Packages

In an LFS 5.1 makefile by Christophe Devine/Jeremy Utley, I first used to automate my LFS build, the authors used a simple package management system based on the timestamp of a file. Here is a modification of that idea you can use in an AFS script for package management.

# Log a package for afs
function log-package ()
{
    rm -f /var/lib/packages/${1}

    find /{bin,lib,sbin,usr} -cnewer /tmp/timestamp -type f -print \
        -exec sh -c " strip -g {} 2>/dev/null; \
        md5sum {} >>/var/lib/packages/${1} " \;

    touch /tmp/timestamp
}

At the beginning of a sequence of functions that install packages add touch /tmp/timestamp. At the ending of the function add log-package <package-name>. Also in the section 6.5. “Creating directories” function create the /var/log/packages directory to hold the log files in.

6.3. Adding afs Command Options

You can modify the main AFS commands to execute other command options other than just an AFS script function. As an example you can add an option to log packages built outside of the AFS script.

Add the logpkg function to the AFS script.

# Log a package
function logpkg ()
{
    if test -z "${1}"
    then
        echo "Expected a package name."
        echo "usage: logpkg <package name>"
        exit 1
    fi

    if ! test -f /tmp/timestamp
    then
        echo "*** Can't find previous /tmp/timestamp"
        exit 1
    fi

    log-package ${1}

    rm -f /tmp/timestamp
}

Add the following commands to the ending of the AFS script.

if test "$1" = "logpkg"
then
    logpkg $2
    exit
fi

if ! test -z "$1"
then
    $1
    exit
fi

lfs

The added commands test for the logpkg literal. If found it calls the log-package function with the second parameter passed to the AFS script.

To use logpkg, execute touch /tmp/timestamp before a package installation. After installation execute ./afs logpkg [package name].

6.4. Adding BLFS Packages

To add packages from BLFS, create a blfs function that calls the BLFS package functions you want to build. Then call the blfs function after LFS has been built. The blfs function would be similar to the Chapter 6 function and the blfs package functions will be similar to the Chapter 6 section functions.

The blfs function.

function blfs ()
{
    mount -vt proc proc build/proc
    mount -vt sysfs sysfs build/sys

    mount -vft tmpfs tmpfs build/dev
    mount -vft tmpfs tmpfs build/dev/shm
    mount -vft devpts -o gid=4,mode=620 devpts build/dev/pts

    CHRT="chroot build /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /bin/bash --login "

    $CHRT /usr/src/ponktv/pktvafs blfs-enter

    $CHRT /usr/src/ponktv/pktvafs blfs-openssl

    [other blfs packages]

#   From chapter09-reboot

    umount -v build/dev/pts
    umount -v build/dev/shm
    umount -v build/dev
    umount -v build/proc
    umount -v build/sys
}

The blfs-enter function.

You also need to remount the devices from Chapter 6 and reinitialize them. I place these commands into a function called blfs-enter.

function blfs-enter ()
{
    echo "Enter BLFS chroot environment"
    cd $LFS
#   ----

    mount -nvt tmpfs none /dev

    mknod -m 622 /dev/console c 5 1
    mknod -m 666 /dev/null c 1 3
    mknod -m 666 /dev/zero c 1 5
    mknod -m 666 /dev/ptmx c 5 2
    mknod -m 666 /dev/tty c 5 0
    mknod -m 444 /dev/random c 1 8
    mknod -m 444 /dev/urandom c 1 9
    chown -v root:tty /dev/{console,ptmx,tty}

    ln -sv /proc/self/fd /dev/fd
    ln -sv /proc/self/fd/0 /dev/stdin
    ln -sv /proc/self/fd/1 /dev/stdout
    ln -sv /proc/self/fd/2 /dev/stderr
    ln -sv /proc/kcore /dev/core
    mkdir -v /dev/pts
    mkdir -v /dev/shm

    mount -vt devpts -o gid=4,mode=620 none /dev/pts
    mount -vt tmpfs none /dev/shm

#   ----
}

The main AFS commands.

if ! test -z "$1"
then
    $1
    exit
fi

lfs
blfs

As an example the blfs package function for building OpenSSL would look something like the following.

function chapter06-openssl ()
{
    echo "chapter06-openssl"
    cd [chapter06 source directory]
    tar -jxf [OpenSSL-0.9.7g].tar.bz2
    cd [OpenSSL-0.9.7g source directory]
#   ----

    patch -Np1 -i ../openssl-0.9.7g-fix_manpages-1.patch

    ./config --openssldir=/etc/ssl --prefix=/usr shared

    make MANDIR=/usr/share/man install

    cp -v -r certs /etc/ssl

#   ----
    cd [chapter06 source directory]
    rm -rf [OpenSSL-0.9.7g source directory]
}

Appendices

Appendix A. AFS LFS-6.1.1 Template

The AFS script template extracted with afs.xsl, Appendix C, AFS XSL stylesheet, from Linux From Scratch 6.1.1 Book's XML files. Copy to the file afs.

#!/bin/bash
#Begin afs (Automation From Scratch) - Linux From Scratch Version 6.1.1

# Set global environment settings and variables.
set -e +h
umask 022

# The all knowing LFS variable.
export LFS=/mnt/lfs



# Foreword
function prologue-foreword ()
{
    echo "prologue-foreword"
#   ----

#   ----
}

# Audience
function prologue-audience ()
{
    echo "prologue-audience"
#   ----

#   ----
}

# Prerequisites
function prologue-prerequisites ()
{
    echo "prologue-prerequisites"
#   ----

#   ----
}

# Host System Requirements
function prologue-hostreqs ()
{
    echo "prologue-hostreqs"
#   ----

cat /proc/version

#   ----
}

# Typography
function prologue-typography ()
{
    echo "prologue-typography"
#   ----

./configure --prefix=/usr

cat > $LFS/etc/group << "EOF"
root:x:0:
bin:x:1:
......
EOF

#   ----
}

# Structure
function prologue-organization ()
{
    echo "prologue-organization"
#   ----

#   ----
}

# Errata
function prologue-errata ()
{
    echo "prologue-errata"
#   ----

#   ----
}

# How to Build an LFS System
function chapter01-how ()
{
    echo "chapter01-how"
#   ----

#   ----
}

# Changelog
function chapter01-changelog ()
{
    echo "chapter01-changelog"
#   ----

#   ----
}

# Resources
function chapter01-resources ()
{
    echo "chapter01-resources"
#   ----

#   ----
}

# Help
function chapter01-askforhelp ()
{
    echo "chapter01-askforhelp"
#   ----

#   ----
}

# Introduction
function chapter02-introduction ()
{
    echo "chapter02-introduction"
#   ----

#   ----
}

# Creating a New Partition
function chapter02-creatingpartition ()
{
    echo "chapter02-creatingpartition"
#   ----

#   ----
}

# Creating a File System on the Partition
function chapter02-creatingfilesystem ()
{
    echo "chapter02-creatingfilesystem"
#   ----

mke2fs -v /dev/[xxx]

debugfs -R feature /dev/[xxx]

cd /tmp
tar -xjvf /path/to/sources/e2fsprogs-1.37.tar.bz2
cd e2fsprogs-1.37
mkdir -v build
cd build
../configure
make #note that we intentionally don't 'make install' here!
./misc/mke2fs -v /dev/[xxx]
cd /tmp
rm -rfv e2fsprogs-1.37

mkswap -v /dev/[yyy]

#   ----
}

# Mounting the New Partition
function chapter02-mounting ()
{
    echo "chapter02-mounting"
#   ----

export LFS=/mnt/lfs

mkdir -pv $LFS
mount -v /dev/[xxx] $LFS

mkdir -pv $LFS
mount -v /dev/[xxx] $LFS
mkdir -v $LFS/usr
mount -v /dev/[yyy] $LFS/usr

#   ----
}

# Introduction
function chapter03-introduction ()
{
    echo "chapter03-introduction"
#   ----

mkdir -v $LFS/sources

chmod -v a+wt $LFS/sources

#   ----
}

# All Packages
function chapter03-packages ()
{
    echo "chapter03-packages"
#   ----

#   ----
}

# Needed Patches
function chapter03-patches ()
{
    echo "chapter03-patches"
#   ----

#   ----
}

# About $LFS
function chapter04-aboutlfs ()
{
    echo "chapter04-aboutlfs"
#   ----

echo $LFS

export LFS=/mnt/lfs

#   ----
}

# Creating the $LFS/tools Directory
function chapter04-creatingtoolsdir ()
{
    echo "chapter04-creatingtoolsdir"
#   ----

mkdir -v $LFS/tools

ln -sv $LFS/tools /

#   ----
}

# Adding the LFS User
function chapter04-addinguser ()
{
    echo "chapter04-addinguser"
#   ----

groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs

passwd lfs

chown -v lfs $LFS/tools

chown -v lfs $LFS/sources

su - lfs

#   ----
}

# Setting Up the Environment
function chapter04-settingenvironment ()
{
    echo "chapter04-settingenvironment"
#   ----

cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF

cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL PATH
EOF

source ~/.bash_profile

#   ----
}

# About SBUs
function chapter04-aboutsbus ()
{
    echo "chapter04-aboutsbus"
#   ----

#   ----
}

# About the Test Suites
function chapter04-abouttestsuites ()
{
    echo "chapter04-abouttestsuites"
#   ----

#   ----
}

# Introduction
function chapter05-introduction ()
{
    echo "chapter05-introduction"
#   ----

echo $LFS

#   ----
}

# Toolchain Technical Notes
function chapter05-toolchaintechnotes ()
{
    echo "chapter05-toolchaintechnotes"
#   ----

#   ----
}

# Binutils-2.15.94.0.2.2 - Pass 1
function chapter05-binutils-pass1 ()
{
    echo "chapter05-binutils-pass1"
    cd [chapter05 source directory]
    tar -jxf [Binutils-2.15.94.0.2.2 - Pass 1].tar.bz2
    cd [Binutils-2.15.94.0.2.2 - Pass 1 source directory]
#   ----

patch -Np1 -i ../binutils-2.15.94.0.2.2-gcc4-1.patch

mkdir -v ../binutils-build
cd ../binutils-build

../binutils-2.15.94.0.2.2/configure --prefix=/tools --disable-nls

make

make install

make -C ld clean
make -C ld LIB_PATH=/tools/lib

#   ----
    cd [chapter05 source directory]
    rm -rf [Binutils-2.15.94.0.2.2 - Pass 1 source directory]
}

# GCC-3.4.3 - Pass 1
function chapter05-gcc-pass1 ()
{
    echo "chapter05-gcc-pass1"
    cd [chapter05 source directory]
    tar -jxf [GCC-3.4.3 - Pass 1].tar.bz2
    cd [GCC-3.4.3 - Pass 1 source directory]
#   ----

mkdir -v ../gcc-build
cd ../gcc-build

../gcc-3.4.3/configure --prefix=/tools \
    --libexecdir=/tools/lib --with-local-prefix=/tools \
    --disable-nls --enable-shared --enable-languages=c

make bootstrap

make install

ln -vs gcc /tools/bin/cc

#   ----
    cd [chapter05 source directory]
    rm -rf [GCC-3.4.3 - Pass 1 source directory]
}

# Linux-Libc-Headers-2.6.11.2
function chapter05-linux-libc-headers ()
{
    echo "chapter05-linux-libc-headers"
    cd [chapter05 source directory]
    tar -jxf [Linux-Libc-Headers-2.6.11.2].tar.bz2
    cd [Linux-Libc-Headers-2.6.11.2 source directory]
#   ----

cp -Rv include/asm-i386 /tools/include/asm
cp -Rv include/linux /tools/include

#   ----
    cd [chapter05 source directory]
    rm -rf [Linux-Libc-Headers-2.6.11.2 source directory]
}

# Glibc-2.3.4
function chapter05-glibc ()
{
    echo "chapter05-glibc"
    cd [chapter05 source directory]
    tar -jxf [Glibc-2.3.4].tar.bz2
    cd [Glibc-2.3.4 source directory]
#   ----

patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch

mkdir -v ../glibc-build
cd ../glibc-build

../glibc-2.3.4/configure --prefix=/tools \
    --disable-profile --enable-add-ons \
    --enable-kernel=2.6.0 --with-binutils=/tools/bin \
    --without-gd --with-headers=/tools/include \
    --without-selinux

make

make check

mkdir -v /tools/etc
touch /tools/etc/ld.so.conf

make install

make localedata/install-locales

mkdir -pv /tools/lib/locale
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i ja_JP -f EUC-JP ja_JP

#   ----
    cd [chapter05 source directory]
    rm -rf [Glibc-2.3.4 source directory]
}

# Adjusting the Toolchain
function chapter05-adjusting ()
{
    echo "chapter05-adjusting"
#   ----

make -C ld install

SPECFILE=`gcc --print-file specs` &&
sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \
    $SPECFILE > tempspecfile &&
mv -f tempspecfile $SPECFILE &&
unset SPECFILE

rm -vf /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}

echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools'

rm -v dummy.c a.out

#   ----
}

# Tcl-8.4.9
function chapter05-tcl ()
{
    echo "chapter05-tcl"
    cd [chapter05 source directory]
    tar -jxf [Tcl-8.4.9].tar.bz2
    cd [Tcl-8.4.9 source directory]
#   ----

cd unix
./configure --prefix=/tools

make

make install

cd ..
export TCLPATH=`pwd`

ln -sv tclsh8.4 /tools/bin/tclsh

#   ----
    cd [chapter05 source directory]
    rm -rf [Tcl-8.4.9 source directory]
}

# Expect-5.43.0
function chapter05-expect ()
{
    echo "chapter05-expect"
    cd [chapter05 source directory]
    tar -jxf [Expect-5.43.0].tar.bz2
    cd [Expect-5.43.0 source directory]
#   ----

patch -Np1 -i ../expect-5.43.0-spawn-1.patch

./configure --prefix=/tools --with-tcl=/tools/lib \
   --with-tclinclude=$TCLPATH --with-x=no

make

make SCRIPTS="" install

unset TCLPATH

#   ----
    cd [chapter05 source directory]
    rm -rf [Expect-5.43.0 source directory]
}

# DejaGNU-1.4.4
function chapter05-dejagnu ()
{
    echo "chapter05-dejagnu"
    cd [chapter05 source directory]
    tar -jxf [DejaGNU-1.4.4].tar.bz2
    cd [DejaGNU-1.4.4 source directory]
#   ----

./configure --prefix=/tools

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [DejaGNU-1.4.4 source directory]
}

# GCC-3.4.3 - Pass 2
function chapter05-gcc-pass2 ()
{
    echo "chapter05-gcc-pass2"
    cd [chapter05 source directory]
    tar -jxf [GCC-3.4.3 - Pass 2].tar.bz2
    cd [GCC-3.4.3 - Pass 2 source directory]
#   ----

expect -c "spawn ls"

patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch
patch -Np1 -i ../gcc-3.4.3-specs-2.patch

mkdir -v ../gcc-build
cd ../gcc-build

../gcc-3.4.3/configure --prefix=/tools \
    --libexecdir=/tools/lib --with-local-prefix=/tools \
    --enable-clocale=gnu --enable-shared \
    --enable-threads=posix --enable-__cxa_atexit \
    --enable-languages=c,c++ --disable-libstdcxx-pch

make

make -k check

../gcc-3.4.3/contrib/test_summary

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [GCC-3.4.3 - Pass 2 source directory]
}

# Binutils-2.15.94.0.2.2 - Pass 2
function chapter05-binutils-pass2 ()
{
    echo "chapter05-binutils-pass2"
    cd [chapter05 source directory]
    tar -jxf [Binutils-2.15.94.0.2.2 - Pass 2].tar.bz2
    cd [Binutils-2.15.94.0.2.2 - Pass 2 source directory]
#   ----

mkdir -v ../binutils-build
cd ../binutils-build

../binutils-2.15.94.0.2.2/configure --prefix=/tools \
    --disable-nls --enable-shared --with-lib-path=/tools/lib

make

make check

make install

make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib

#   ----
    cd [chapter05 source directory]
    rm -rf [Binutils-2.15.94.0.2.2 - Pass 2 source directory]
}

# Gawk-3.1.4
function chapter05-gawk ()
{
    echo "chapter05-gawk"
    cd [chapter05 source directory]
    tar -jxf [Gawk-3.1.4].tar.bz2
    cd [Gawk-3.1.4 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Gawk-3.1.4 source directory]
}

# Coreutils-5.2.1
function chapter05-coreutils ()
{
    echo "chapter05-coreutils"
    cd [chapter05 source directory]
    tar -jxf [Coreutils-5.2.1].tar.bz2
    cd [Coreutils-5.2.1 source directory]
#   ----

DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Coreutils-5.2.1 source directory]
}

# Bzip2-1.0.3
function chapter05-bzip2 ()
{
    echo "chapter05-bzip2"
    cd [chapter05 source directory]
    tar -jxf [Bzip2-1.0.3].tar.bz2
    cd [Bzip2-1.0.3 source directory]
#   ----

make

make PREFIX=/tools install

#   ----
    cd [chapter05 source directory]
    rm -rf [Bzip2-1.0.3 source directory]
}

# Gzip-1.3.5
function chapter05-gzip ()
{
    echo "chapter05-gzip"
    cd [chapter05 source directory]
    tar -jxf [Gzip-1.3.5].tar.bz2
    cd [Gzip-1.3.5 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Gzip-1.3.5 source directory]
}

# Diffutils-2.8.1
function chapter05-diffutils ()
{
    echo "chapter05-diffutils"
    cd [chapter05 source directory]
    tar -jxf [Diffutils-2.8.1].tar.bz2
    cd [Diffutils-2.8.1 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Diffutils-2.8.1 source directory]
}

# Findutils-4.2.23
function chapter05-findutils ()
{
    echo "chapter05-findutils"
    cd [chapter05 source directory]
    tar -jxf [Findutils-4.2.23].tar.bz2
    cd [Findutils-4.2.23 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Findutils-4.2.23 source directory]
}

# Make-3.80
function chapter05-make ()
{
    echo "chapter05-make"
    cd [chapter05 source directory]
    tar -jxf [Make-3.80].tar.bz2
    cd [Make-3.80 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Make-3.80 source directory]
}

# Grep-2.5.1a
function chapter05-grep ()
{
    echo "chapter05-grep"
    cd [chapter05 source directory]
    tar -jxf [Grep-2.5.1a].tar.bz2
    cd [Grep-2.5.1a source directory]
#   ----

./configure --prefix=/tools \
    --disable-perl-regexp

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Grep-2.5.1a source directory]
}

# Sed-4.1.4
function chapter05-sed ()
{
    echo "chapter05-sed"
    cd [chapter05 source directory]
    tar -jxf [Sed-4.1.4].tar.bz2
    cd [Sed-4.1.4 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Sed-4.1.4 source directory]
}

# Gettext-0.14.3
function chapter05-gettext ()
{
    echo "chapter05-gettext"
    cd [chapter05 source directory]
    tar -jxf [Gettext-0.14.3].tar.bz2
    cd [Gettext-0.14.3 source directory]
#   ----

./configure --prefix=/tools --disable-libasprintf \
    --without-csharp

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Gettext-0.14.3 source directory]
}

# Ncurses-5.4
function chapter05-ncurses ()
{
    echo "chapter05-ncurses"
    cd [chapter05 source directory]
    tar -jxf [Ncurses-5.4].tar.bz2
    cd [Ncurses-5.4 source directory]
#   ----

./configure --prefix=/tools --with-shared \
    --without-debug --without-ada --enable-overwrite

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Ncurses-5.4 source directory]
}

# Patch-2.5.4
function chapter05-patch ()
{
    echo "chapter05-patch"
    cd [chapter05 source directory]
    tar -jxf [Patch-2.5.4].tar.bz2
    cd [Patch-2.5.4 source directory]
#   ----

CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Patch-2.5.4 source directory]
}

# Tar-1.15.1
function chapter05-tar ()
{
    echo "chapter05-tar"
    cd [chapter05 source directory]
    tar -jxf [Tar-1.15.1].tar.bz2
    cd [Tar-1.15.1 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Tar-1.15.1 source directory]
}

# Texinfo-4.8
function chapter05-texinfo ()
{
    echo "chapter05-texinfo"
    cd [chapter05 source directory]
    tar -jxf [Texinfo-4.8].tar.bz2
    cd [Texinfo-4.8 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Texinfo-4.8 source directory]
}

# Bash-3.0
function chapter05-bash ()
{
    echo "chapter05-bash"
    cd [chapter05 source directory]
    tar -jxf [Bash-3.0].tar.bz2
    cd [Bash-3.0 source directory]
#   ----

patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch

./configure --prefix=/tools --without-bash-malloc

make

make install

ln -vs bash /tools/bin/sh

#   ----
    cd [chapter05 source directory]
    rm -rf [Bash-3.0 source directory]
}

# M4-1.4.3
function chapter05-m4 ()
{
    echo "chapter05-m4"
    cd [chapter05 source directory]
    tar -jxf [M4-1.4.3].tar.bz2
    cd [M4-1.4.3 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [M4-1.4.3 source directory]
}

# Bison-2.0
function chapter05-bison ()
{
    echo "chapter05-bison"
    cd [chapter05 source directory]
    tar -jxf [Bison-2.0].tar.bz2
    cd [Bison-2.0 source directory]
#   ----

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Bison-2.0 source directory]
}

# Flex-2.5.31
function chapter05-flex ()
{
    echo "chapter05-flex"
    cd [chapter05 source directory]
    tar -jxf [Flex-2.5.31].tar.bz2
    cd [Flex-2.5.31 source directory]
#   ----

patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch

touch doc/flex.1

./configure --prefix=/tools

make

make install

#   ----
    cd [chapter05 source directory]
    rm -rf [Flex-2.5.31 source directory]
}

# Util-linux-2.12q
function chapter05-util-linux ()
{
    echo "chapter05-util-linux"
    cd [chapter05 source directory]
    tar -jxf [Util-linux-2.12q].tar.bz2
    cd [Util-linux-2.12q source directory]
#   ----

sed -i 's@/usr/include@/tools/include@g' configure

./configure

make -C lib

make -C mount mount umount
make -C text-utils more

cp mount/{,u}mount text-utils/more /tools/bin

#   ----
    cd [chapter05 source directory]
    rm -rf [Util-linux-2.12q source directory]
}

# Perl-5.8.7
function chapter05-perl ()
{
    echo "chapter05-perl"
    cd [chapter05 source directory]
    tar -jxf [Perl-5.8.7].tar.bz2
    cd [Perl-5.8.7 source directory]
#   ----

patch -Np1 -i ../perl-5.8.7-libc-1.patch

./configure.gnu --prefix=/tools -Dstatic_ext='IO Fcntl POSIX'

make perl utilities

cp -v perl pod/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.8.7
cp -Rv lib/* /tools/lib/perl5/5.8.7

#   ----
    cd [chapter05 source directory]
    rm -rf [Perl-5.8.7 source directory]
}

# Stripping
function chapter05-stripping ()
{
    echo "chapter05-stripping"
#   ----

strip --strip-debug /tools/lib/*
strip --strip-unneeded /tools/{,s}bin/*

rm -rf /tools/{info,man}

#   ----
}

# Introduction
function chapter06-introduction ()
{
    echo "chapter06-introduction"
#   ----

#   ----
}

# Mounting Virtual Kernel File Systems
function chapter06-kernfs ()
{
    echo "chapter06-kernfs"
#   ----

mkdir -pv $LFS/{proc,sys}

mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys

mount -vft tmpfs tmpfs $LFS/dev
mount -vft tmpfs tmpfs $LFS/dev/shm
mount -vft devpts -o gid=4,mode=620 devpts $LFS/dev/pts

#   ----
}

# Entering the Chroot Environment
function chapter06-chroot ()
{
    echo "chapter06-chroot"
#   ----

chroot "$LFS" /tools/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h

#   ----
}

# Changing Ownership
function chapter06-changingowner ()
{
    echo "chapter06-changingowner"
#   ----

chown -R 0:0 /tools

#   ----
}

# Creating Directories
function chapter06-creatingdirs ()
{
    echo "chapter06-creatingdirs"
#   ----

install -dv /{bin,boot,dev,etc/opt,home,lib,mnt}
install -dv /{sbin,srv,usr/local,var,opt}
install -dv /root -m 0750
install -dv /tmp /var/tmp -m 1777
install -dv /media/{floppy,cdrom}
install -dv /usr/{bin,include,lib,sbin,share,src}
ln -sv share/{man,doc,info} /usr
install -dv /usr/share/{doc,info,locale,man}
install -dv /usr/share/{misc,terminfo,zoneinfo}
install -dv /usr/share/man/man{1,2,3,4,5,6,7,8}
install -dv /usr/local/{bin,etc,include,lib,sbin,share,src}
ln -sv share/{man,doc,info} /usr/local
install -dv /usr/local/share/{doc,info,locale,man}
install -dv /usr/local/share/{misc,terminfo,zoneinfo}
install -dv /usr/local/share/man/man{1,2,3,4,5,6,7,8}
install -dv /var/{lock,log,mail,run,spool}
install -dv /var/{opt,cache,lib/{misc,locate},local}
install -dv /opt/{bin,doc,include,info}
install -dv /opt/{lib,man/man{1,2,3,4,5,6,7,8}}

#   ----
}

# Creating Essential Symlinks
function chapter06-createfiles ()
{
    echo "chapter06-createfiles"
#   ----

ln -sv /tools/bin/{bash,cat,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv bash /bin/sh

#   ----
}

# Creating the passwd, group, and log Files
function chapter06-pwdgroup ()
{
    echo "chapter06-pwdgroup"
#   ----

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF

cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
EOF

exec /tools/bin/bash --login +h

touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/run/utmp /var/log/lastlog
chmod -v 664 /var/run/utmp /var/log/lastlog

#   ----
}

# Populating /dev
function chapter06-devices ()
{
    echo "chapter06-devices"
#   ----

mknod -m 600 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3

mount -nvt tmpfs none /dev

mknod -m 622 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
mknod -m 666 /dev/ptmx c 5 2
mknod -m 666 /dev/tty c 5 0
mknod -m 444 /dev/random c 1 8
mknod -m 444 /dev/urandom c 1 9
chown -v root:tty /dev/{console,ptmx,tty}

ln -sv /proc/self/fd /dev/fd
ln -sv /proc/self/fd/0 /dev/stdin
ln -sv /proc/self/fd/1 /dev/stdout
ln -sv /proc/self/fd/2 /dev/stderr
ln -sv /proc/kcore /dev/core
mkdir -v /dev/pts
mkdir -v /dev/shm

mount -vt devpts -o gid=4,mode=620 none /dev/pts
mount -vt tmpfs none /dev/shm

#   ----
}

# Linux-Libc-Headers-2.6.11.2
function chapter06-linux-libc-headers ()
{
    echo "chapter06-linux-libc-headers"
    cd [chapter06 source directory]
    tar -jxf [Linux-Libc-Headers-2.6.11.2].tar.bz2
    cd [Linux-Libc-Headers-2.6.11.2 source directory]
#   ----

cp -Rv include/asm-i386 /usr/include/asm
cp -Rv include/linux /usr/include

chown -Rv root:root /usr/include/{asm,linux}

find /usr/include/{asm,linux} -type d -exec chmod -v 755 {} \;
find /usr/include/{asm,linux} -type f -exec chmod -v 644 {} \;

#   ----
    cd [chapter06 source directory]
    rm -rf [Linux-Libc-Headers-2.6.11.2 source directory]
}

# Man-pages-2.01
function chapter06-man-pages ()
{
    echo "chapter06-man-pages"
    cd [chapter06 source directory]
    tar -jxf [Man-pages-2.01].tar.bz2
    cd [Man-pages-2.01 source directory]
#   ----

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Man-pages-2.01 source directory]
}

# Glibc-2.3.4
function chapter06-glibc ()
{
    echo "chapter06-glibc"
    cd [chapter06 source directory]
    tar -jxf [Glibc-2.3.4].tar.bz2
    cd [Glibc-2.3.4 source directory]
#   ----

tar -xjvf ../glibc-linuxthreads-2.3.4.tar.bz2

patch -Np1 -i ../glibc-2.3.4-rtld_search_dirs-1.patch

patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch

patch -Np1 -i ../glibc-2.3.4-tls_assert-1.patch

mkdir -v ../glibc-build
cd ../glibc-build

../glibc-2.3.4/configure --prefix=/usr \
    --disable-profile --enable-add-ons \
    --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc

make

make -k check >glibc-check-log 2>&1
grep Error glibc-check-log

touch /etc/ld.so.conf

make install

make localedata/install-locales

mkdir -pv /usr/lib/locale
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i ja_JP -f EUC-JP ja_JP

make -C ../glibc-2.3.4/linuxthreads/man

make -C ../glibc-2.3.4/linuxthreads/man install

cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

tzselect

cp -v --remove-destination /usr/share/zoneinfo/[xxx] \
    /etc/localtime

cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF

#   ----
    cd [chapter06 source directory]
    rm -rf [Glibc-2.3.4 source directory]
}

# Re-adjusting the Toolchain
function chapter06-readjusting ()
{
    echo "chapter06-readjusting"
#   ----

make -C ld INSTALL=/tools/bin/install install

perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' \
    -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;' \
        `gcc --print-file specs`

echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /lib'

rm -v dummy.c a.out

#   ----
}

# Binutils-2.15.94.0.2.2
function chapter06-binutils ()
{
    echo "chapter06-binutils"
    cd [chapter06 source directory]
    tar -jxf [Binutils-2.15.94.0.2.2].tar.bz2
    cd [Binutils-2.15.94.0.2.2 source directory]
#   ----

expect -c "spawn ls"

mkdir -v ../binutils-build
cd ../binutils-build

../binutils-2.15.94.0.2.2/configure --prefix=/usr \
    --enable-shared

make tooldir=/usr

make check

make tooldir=/usr install

cp -v ../binutils-2.15.94.0.2.2/include/libiberty.h /usr/include

#   ----
    cd [chapter06 source directory]
    rm -rf [Binutils-2.15.94.0.2.2 source directory]
}

# GCC-3.4.3
function chapter06-gcc ()
{
    echo "chapter06-gcc"
    cd [chapter06 source directory]
    tar -jxf [GCC-3.4.3].tar.bz2
    cd [GCC-3.4.3 source directory]
#   ----

patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch

patch -Np1 -i ../gcc-3.4.3-linkonce-1.patch

sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

mkdir -v ../gcc-build
cd ../gcc-build

../gcc-3.4.3/configure --prefix=/usr \
    --libexecdir=/usr/lib --enable-shared \
    --enable-threads=posix --enable-__cxa_atexit \
    --enable-clocale=gnu --enable-languages=c,c++

make

make -k check

make install

ln -sv ../usr/bin/cpp /lib

ln -sv gcc /usr/bin/cc

#   ----
    cd [chapter06 source directory]
    rm -rf [GCC-3.4.3 source directory]
}

# Coreutils-5.2.1
function chapter06-coreutils ()
{
    echo "chapter06-coreutils"
    cd [chapter06 source directory]
    tar -jxf [Coreutils-5.2.1].tar.bz2
    cd [Coreutils-5.2.1 source directory]
#   ----

patch -Np1 -i ../coreutils-5.2.1-uname-2.patch

patch -Np1 -i ../coreutils-5.2.1-suppress_uptime_kill_su-1.patch

DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/usr

make

echo "dummy1:x:1000:" >> /etc/group
echo "dummy2:x:1001:dummy" >> /etc/group
echo "dummy:x:1000:1000:::/bin/bash" >> /etc/passwd

make NON_ROOT_USERNAME=dummy check-root

src/su dummy -c "make RUN_EXPENSIVE_TESTS=yes check"

sed -i '/dummy/d' /etc/passwd /etc/group

make install

mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
mv -v /usr/bin/{false,hostname,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
mv -v /usr/bin/chroot /usr/sbin

mv -v /usr/bin/{head,sleep} /bin

#   ----
    cd [chapter06 source directory]
    rm -rf [Coreutils-5.2.1 source directory]
}

# Zlib-1.2.3
function chapter06-zlib ()
{
    echo "chapter06-zlib"
    cd [chapter06 source directory]
    tar -jxf [Zlib-1.2.3].tar.bz2
    cd [Zlib-1.2.3 source directory]
#   ----

./configure --prefix=/usr --shared --libdir=/lib

make

make install

rm -v /lib/libz.so
ln -sfv ../../lib/libz.so.1.2.3 /usr/lib/libz.so

make clean
./configure --prefix=/usr
make

make install

chmod -v 644 /usr/lib/libz.a

#   ----
    cd [chapter06 source directory]
    rm -rf [Zlib-1.2.3 source directory]
}

# Mktemp-1.5
function chapter06-mktemp ()
{
    echo "chapter06-mktemp"
    cd [chapter06 source directory]
    tar -jxf [Mktemp-1.5].tar.bz2
    cd [Mktemp-1.5 source directory]
#   ----

patch -Np1 -i ../mktemp-1.5-add_tempfile-2.patch

./configure --prefix=/usr --with-libc

make

make install
make install-tempfile

#   ----
    cd [chapter06 source directory]
    rm -rf [Mktemp-1.5 source directory]
}

# Iana-Etc-1.04
function chapter06-iana-etc ()
{
    echo "chapter06-iana-etc"
    cd [chapter06 source directory]
    tar -jxf [Iana-Etc-1.04].tar.bz2
    cd [Iana-Etc-1.04 source directory]
#   ----

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Iana-Etc-1.04 source directory]
}

# Findutils-4.2.23
function chapter06-findutils ()
{
    echo "chapter06-findutils"
    cd [chapter06 source directory]
    tar -jxf [Findutils-4.2.23].tar.bz2
    cd [Findutils-4.2.23 source directory]
#   ----

./configure --prefix=/usr --libexecdir=/usr/lib/locate \
    --localstatedir=/var/lib/locate

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Findutils-4.2.23 source directory]
}

# Gawk-3.1.4
function chapter06-gawk ()
{
    echo "chapter06-gawk"
    cd [chapter06 source directory]
    tar -jxf [Gawk-3.1.4].tar.bz2
    cd [Gawk-3.1.4 source directory]
#   ----

./configure --prefix=/usr --libexecdir=/usr/lib

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Gawk-3.1.4 source directory]
}

# Ncurses-5.4
function chapter06-ncurses ()
{
    echo "chapter06-ncurses"
    cd [chapter06 source directory]
    tar -jxf [Ncurses-5.4].tar.bz2
    cd [Ncurses-5.4 source directory]
#   ----

./configure --prefix=/usr --with-shared --without-debug

make

make install

chmod -v 755 /usr/lib/*.5.4

chmod -v 644 /usr/lib/libncurses++.a

mv -v /usr/lib/libncurses.so.5* /lib

ln -sfv ../../lib/libncurses.so.5 /usr/lib/libncurses.so
ln -sfv libncurses.so /usr/lib/libcurses.so

#   ----
    cd [chapter06 source directory]
    rm -rf [Ncurses-5.4 source directory]
}

# Readline-5.0
function chapter06-readline ()
{
    echo "chapter06-readline"
    cd [chapter06 source directory]
    tar -jxf [Readline-5.0].tar.bz2
    cd [Readline-5.0 source directory]
#   ----

patch -Np1 -i ../readline-5.0-fixes-1.patch

./configure --prefix=/usr --libdir=/lib

make SHLIB_XLDFLAGS=-lncurses

make install

chmod -v 755 /lib/lib{readline,history}.so*

mv -v /lib/lib{readline,history}.a /usr/lib

rm -v /lib/lib{readline,history}.so
ln -sfv ../../lib/libreadline.so.5 /usr/lib/libreadline.so
ln -sfv ../../lib/libhistory.so.5 /usr/lib/libhistory.so

#   ----
    cd [chapter06 source directory]
    rm -rf [Readline-5.0 source directory]
}

# Vim-6.3
function chapter06-vim ()
{
    echo "chapter06-vim"
    cd [chapter06 source directory]
    tar -jxf [Vim-6.3].tar.bz2
    cd [Vim-6.3 source directory]
#   ----

echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h

patch -Np1 -i ../vim-6.3-security_fix-2.patch

./configure --prefix=/usr --enable-multibyte

make

make install

ln -sv vim /usr/bin/vi

cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF

vim -c ':options'

#   ----
    cd [chapter06 source directory]
    rm -rf [Vim-6.3 source directory]
}

# M4-1.4.3
function chapter06-m4 ()
{
    echo "chapter06-m4"
    cd [chapter06 source directory]
    tar -jxf [M4-1.4.3].tar.bz2
    cd [M4-1.4.3 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [M4-1.4.3 source directory]
}

# Bison-2.0
function chapter06-bison ()
{
    echo "chapter06-bison"
    cd [chapter06 source directory]
    tar -jxf [Bison-2.0].tar.bz2
    cd [Bison-2.0 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Bison-2.0 source directory]
}

# Less-382
function chapter06-less ()
{
    echo "chapter06-less"
    cd [chapter06 source directory]
    tar -jxf [Less-382].tar.bz2
    cd [Less-382 source directory]
#   ----

./configure --prefix=/usr --bindir=/bin --sysconfdir=/etc

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Less-382 source directory]
}

# Groff-1.19.1
function chapter06-groff ()
{
    echo "chapter06-groff"
    cd [chapter06 source directory]
    tar -jxf [Groff-1.19.1].tar.bz2
    cd [Groff-1.19.1 source directory]
#   ----

PAGE=[paper_size] ./configure --prefix=/usr

make

make install

ln -sv soelim /usr/bin/zsoelim
ln -sv eqn /usr/bin/geqn
ln -sv tbl /usr/bin/gtbl

#   ----
    cd [chapter06 source directory]
    rm -rf [Groff-1.19.1 source directory]
}

# Sed-4.1.4
function chapter06-sed ()
{
    echo "chapter06-sed"
    cd [chapter06 source directory]
    tar -jxf [Sed-4.1.4].tar.bz2
    cd [Sed-4.1.4 source directory]
#   ----

sed -i 's@/doc@&/sed-4.1.4@' doc/Makefile.in

./configure --prefix=/usr --bindir=/bin

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Sed-4.1.4 source directory]
}

# Flex-2.5.31
function chapter06-flex ()
{
    echo "chapter06-flex"
    cd [chapter06 source directory]
    tar -jxf [Flex-2.5.31].tar.bz2
    cd [Flex-2.5.31 source directory]
#   ----

patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch

touch doc/flex.1

./configure --prefix=/usr

make

make install

ln -sv libfl.a /usr/lib/libl.a

cat > /usr/bin/lex << "EOF"
#!/bin/sh
# Begin /usr/bin/lex

exec /usr/bin/flex -l "$@"

# End /usr/bin/lex
EOF
chmod -v 755 /usr/bin/lex

#   ----
    cd [chapter06 source directory]
    rm -rf [Flex-2.5.31 source directory]
}

# Gettext-0.14.3
function chapter06-gettext ()
{
    echo "chapter06-gettext"
    cd [chapter06 source directory]
    tar -jxf [Gettext-0.14.3].tar.bz2
    cd [Gettext-0.14.3 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Gettext-0.14.3 source directory]
}

# Inetutils-1.4.2
function chapter06-inetutils ()
{
    echo "chapter06-inetutils"
    cd [chapter06 source directory]
    tar -jxf [Inetutils-1.4.2].tar.bz2
    cd [Inetutils-1.4.2 source directory]
#   ----

patch -Np1 -i ../inetutils-1.4.2-kernel_headers-1.patch

patch -Np1 -i ../inetutils-1.4.2-no_server_man_pages-1.patch

./configure --prefix=/usr --libexecdir=/usr/sbin \
    --sysconfdir=/etc --localstatedir=/var \
    --disable-logger --disable-syslogd \
    --disable-whois --disable-servers

make

make install

mv -v /usr/bin/ping /bin

#   ----
    cd [chapter06 source directory]
    rm -rf [Inetutils-1.4.2 source directory]
}

# IPRoute2-2.6.11-050330
function chapter06-iproute2 ()
{
    echo "chapter06-iproute2"
    cd [chapter06 source directory]
    tar -jxf [IPRoute2-2.6.11-050330].tar.bz2
    cd [IPRoute2-2.6.11-050330 source directory]
#   ----

sed -i '/^TARGETS/s@arpd@@g' misc/Makefile

./configure 

make SBINDIR=/sbin

make SBINDIR=/sbin install

#   ----
    cd [chapter06 source directory]
    rm -rf [IPRoute2-2.6.11-050330 source directory]
}

# Perl-5.8.7
function chapter06-perl ()
{
    echo "chapter06-perl"
    cd [chapter06 source directory]
    tar -jxf [Perl-5.8.7].tar.bz2
    cd [Perl-5.8.7 source directory]
#   ----

./configure.gnu --prefix=/usr -Dpager="/bin/less -isR"

make

echo "127.0.0.1 localhost $(hostname)" > /etc/hosts

make test

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Perl-5.8.7 source directory]
}

# Texinfo-4.8
function chapter06-texinfo ()
{
    echo "chapter06-texinfo"
    cd [chapter06 source directory]
    tar -jxf [Texinfo-4.8].tar.bz2
    cd [Texinfo-4.8 source directory]
#   ----

patch -Np1 -i ../texinfo-4.8-tempfile_fix-1.patch

./configure --prefix=/usr

make

make install

make TEXMF=/usr/share/texmf install-tex

cd /usr/share/info
rm dir
for f in *
do install-info $f dir 2>/dev/null
done

#   ----
    cd [chapter06 source directory]
    rm -rf [Texinfo-4.8 source directory]
}

# Autoconf-2.59
function chapter06-autoconf ()
{
    echo "chapter06-autoconf"
    cd [chapter06 source directory]
    tar -jxf [Autoconf-2.59].tar.bz2
    cd [Autoconf-2.59 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Autoconf-2.59 source directory]
}

# Automake-1.9.5
function chapter06-automake ()
{
    echo "chapter06-automake"
    cd [chapter06 source directory]
    tar -jxf [Automake-1.9.5].tar.bz2
    cd [Automake-1.9.5 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Automake-1.9.5 source directory]
}

# Bash-3.0
function chapter06-bash ()
{
    echo "chapter06-bash"
    cd [chapter06 source directory]
    tar -jxf [Bash-3.0].tar.bz2
    cd [Bash-3.0 source directory]
#   ----

tar -xvf ../bash-doc-3.0.tar.gz &&
sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/bash-3.0|" \
    Makefile.in

patch -Np1 -i ../bash-3.0-fixes-3.patch

patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch

./configure --prefix=/usr --bindir=/bin \
    --without-bash-malloc --with-installed-readline

make

make install

exec /bin/bash --login +h

#   ----
    cd [chapter06 source directory]
    rm -rf [Bash-3.0 source directory]
}

# File-4.13
function chapter06-file ()
{
    echo "chapter06-file"
    cd [chapter06 source directory]
    tar -jxf [File-4.13].tar.bz2
    cd [File-4.13 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [File-4.13 source directory]
}

# Libtool-1.5.14
function chapter06-libtool ()
{
    echo "chapter06-libtool"
    cd [chapter06 source directory]
    tar -jxf [Libtool-1.5.14].tar.bz2
    cd [Libtool-1.5.14 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Libtool-1.5.14 source directory]
}

# Bzip2-1.0.3
function chapter06-bzip2 ()
{
    echo "chapter06-bzip2"
    cd [chapter06 source directory]
    tar -jxf [Bzip2-1.0.3].tar.bz2
    cd [Bzip2-1.0.3 source directory]
#   ----

patch -Np1 -i ../bzip2-1.0.3-install_docs-1.patch

patch -Np1 -i ../bzip2-1.0.3-bzgrep_security-1.patch

make -f Makefile-libbz2_so
make clean

make

make install

cp -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat

#   ----
    cd [chapter06 source directory]
    rm -rf [Bzip2-1.0.3 source directory]
}

# Diffutils-2.8.1
function chapter06-diffutils ()
{
    echo "chapter06-diffutils"
    cd [chapter06 source directory]
    tar -jxf [Diffutils-2.8.1].tar.bz2
    cd [Diffutils-2.8.1 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Diffutils-2.8.1 source directory]
}

# Kbd-1.12
function chapter06-kbd ()
{
    echo "chapter06-kbd"
    cd [chapter06 source directory]
    tar -jxf [Kbd-1.12].tar.bz2
    cd [Kbd-1.12 source directory]
#   ----

./configure

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Kbd-1.12 source directory]
}

# E2fsprogs-1.37
function chapter06-e2fsprogs ()
{
    echo "chapter06-e2fsprogs"
    cd [chapter06 source directory]
    tar -jxf [E2fsprogs-1.37].tar.bz2
    cd [E2fsprogs-1.37 source directory]
#   ----

sed -i -e 's/-DTEST/$(ALL_CFLAGS) &/' lib/e2p/Makefile.in

mkdir -v build
cd build

../configure --prefix=/usr --with-root-prefix="" \
    --enable-elf-shlibs --disable-evms

make

make install

make install-libs

#   ----
    cd [chapter06 source directory]
    rm -rf [E2fsprogs-1.37 source directory]
}

# Grep-2.5.1a
function chapter06-grep ()
{
    echo "chapter06-grep"
    cd [chapter06 source directory]
    tar -jxf [Grep-2.5.1a].tar.bz2
    cd [Grep-2.5.1a source directory]
#   ----

./configure --prefix=/usr --bindir=/bin

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Grep-2.5.1a source directory]
}

# GRUB-0.96
function chapter06-grub ()
{
    echo "chapter06-grub"
    cd [chapter06 source directory]
    tar -jxf [GRUB-0.96].tar.bz2
    cd [GRUB-0.96 source directory]
#   ----

./configure --prefix=/usr

make

make install
mkdir -v /boot/grub
cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub

#   ----
    cd [chapter06 source directory]
    rm -rf [GRUB-0.96 source directory]
}

# Gzip-1.3.5
function chapter06-gzip ()
{
    echo "chapter06-gzip"
    cd [chapter06 source directory]
    tar -jxf [Gzip-1.3.5].tar.bz2
    cd [Gzip-1.3.5 source directory]
#   ----

patch -Np1 -i ../gzip-1.3.5-security_fixes-1.patch

./configure --prefix=/usr

sed -i 's@"BINDIR"@/bin@g' gzexe.in

make

make install

mv -v /usr/bin/gzip /bin
rm -v /usr/bin/{gunzip,zcat}
ln -sv gzip /bin/gunzip
ln -sv gzip /bin/zcat
ln -sv gzip /bin/compress
ln -sv gunzip /bin/uncompress

#   ----
    cd [chapter06 source directory]
    rm -rf [Gzip-1.3.5 source directory]
}

# Hotplug-2004_09_23
function chapter06-hotplug ()
{
    echo "chapter06-hotplug"
    cd [chapter06 source directory]
    tar -jxf [Hotplug-2004_09_23].tar.bz2
    cd [Hotplug-2004_09_23 source directory]
#   ----

make install

cp -v etc/hotplug/pnp.distmap /etc/hotplug

rm -rfv /etc/init.d

rm -fv /etc/hotplug/net.agent

mkdir -v /lib/firmware

#   ----
    cd [chapter06 source directory]
    rm -rf [Hotplug-2004_09_23 source directory]
}

# Man-1.5p
function chapter06-man ()
{
    echo "chapter06-man"
    cd [chapter06 source directory]
    tar -jxf [Man-1.5p].tar.bz2
    cd [Man-1.5p source directory]
#   ----

sed -i 's@-is@&R@g' configure

sed -i 's@MANPATH./usr/man@#&@g' src/man.conf.in

./configure -confdir=/etc

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Man-1.5p source directory]
}

# Make-3.80
function chapter06-make ()
{
    echo "chapter06-make"
    cd [chapter06 source directory]
    tar -jxf [Make-3.80].tar.bz2
    cd [Make-3.80 source directory]
#   ----

./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Make-3.80 source directory]
}

# Module-Init-Tools-3.1
function chapter06-module-init-tools ()
{
    echo "chapter06-module-init-tools"
    cd [chapter06 source directory]
    tar -jxf [Module-Init-Tools-3.1].tar.bz2
    cd [Module-Init-Tools-3.1 source directory]
#   ----

touch modprobe.conf.5

tar -xvf ../module-init-tools-testsuite-3.1.tar.bz2 --strip-path=1 &&
./configure &&
make check &&
make distclean

./configure --prefix="" --enable-zlib

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Module-Init-Tools-3.1 source directory]
}

# Patch-2.5.4
function chapter06-patch ()
{
    echo "chapter06-patch"
    cd [chapter06 source directory]
    tar -jxf [Patch-2.5.4].tar.bz2
    cd [Patch-2.5.4 source directory]
#   ----

CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/usr

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Patch-2.5.4 source directory]
}

# Procps-3.2.5
function chapter06-procps ()
{
    echo "chapter06-procps"
    cd [chapter06 source directory]
    tar -jxf [Procps-3.2.5].tar.bz2
    cd [Procps-3.2.5 source directory]
#   ----

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Procps-3.2.5 source directory]
}

# Psmisc-21.6
function chapter06-psmisc ()
{
    echo "chapter06-psmisc"
    cd [chapter06 source directory]
    tar -jxf [Psmisc-21.6].tar.bz2
    cd [Psmisc-21.6 source directory]
#   ----

./configure --prefix=/usr --exec-prefix=""

make

make install

mv -v /bin/pstree* /usr/bin

ln -sv killall /bin/pidof

#   ----
    cd [chapter06 source directory]
    rm -rf [Psmisc-21.6 source directory]
}

# Shadow-4.0.9
function chapter06-shadow ()
{
    echo "chapter06-shadow"
    cd [chapter06 source directory]
    tar -jxf [Shadow-4.0.9].tar.bz2
    cd [Shadow-4.0.9 source directory]
#   ----

./configure --libdir=/lib --enable-shared

sed -i 's/groups$(EXEEXT) //' src/Makefile
sed -i '/groups/d' man/Makefile

make

make install

cp -v etc/{limits,login.access} /etc

sed -e's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \
    -e 's@/var/spool/mail@/var/mail@' \
    etc/login.defs.linux > /etc/login.defs

mv -v /usr/bin/passwd /bin

mv -v /lib/libshadow.*a /usr/lib
rm -v /lib/libshadow.so
ln -sfv ../../lib/libshadow.so.0 /usr/lib/libshadow.so

mkdir -v /etc/default

pwconv

grpconv

passwd root

#   ----
    cd [chapter06 source directory]
    rm -rf [Shadow-4.0.9 source directory]
}

# Sysklogd-1.4.1
function chapter06-sysklogd ()
{
    echo "chapter06-sysklogd"
    cd [chapter06 source directory]
    tar -jxf [Sysklogd-1.4.1].tar.bz2
    cd [Sysklogd-1.4.1 source directory]
#   ----

patch -Np1 -i ../sysklogd-1.4.1-fixes-1.patch

make

make install

cat > /etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf

auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *

# log the bootscript output:
local2.* -/var/log/boot.log

# End /etc/syslog.conf
EOF

#   ----
    cd [chapter06 source directory]
    rm -rf [Sysklogd-1.4.1 source directory]
}

# Sysvinit-2.86
function chapter06-sysvinit ()
{
    echo "chapter06-sysvinit"
    cd [chapter06 source directory]
    tar -jxf [Sysvinit-2.86].tar.bz2
    cd [Sysvinit-2.86 source directory]
#   ----

sed -i 's@Sending processes@& started by init@g' \
    src/init.c

make -C src

make -C src install

cat > /etc/inittab << "EOF"
# Begin /etc/inittab

id:3:initdefault:

si::sysinit:/etc/rc.d/init.d/rc sysinit

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty -I '\033(K' tty1 9600
2:2345:respawn:/sbin/agetty -I '\033(K' tty2 9600
3:2345:respawn:/sbin/agetty -I '\033(K' tty3 9600
4:2345:respawn:/sbin/agetty -I '\033(K' tty4 9600
5:2345:respawn:/sbin/agetty -I '\033(K' tty5 9600
6:2345:respawn:/sbin/agetty -I '\033(K' tty6 9600

# End /etc/inittab
EOF

#   ----
    cd [chapter06 source directory]
    rm -rf [Sysvinit-2.86 source directory]
}

# Tar-1.15.1
function chapter06-tar ()
{
    echo "chapter06-tar"
    cd [chapter06 source directory]
    tar -jxf [Tar-1.15.1].tar.bz2
    cd [Tar-1.15.1 source directory]
#   ----

patch -Np1 -i ../tar-1.15.1-sparse_fix-1.patch

./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin

make

make install

#   ----
    cd [chapter06 source directory]
    rm -rf [Tar-1.15.1 source directory]
}

# Udev-056
function chapter06-udev ()
{
    echo "chapter06-udev"
    cd [chapter06 source directory]
    tar -jxf [Udev-056].tar.bz2
    cd [Udev-056 source directory]
#   ----

make udevdir=/dev

make DESTDIR=/ udevdir=/dev install

cp -v ../udev-config-4.rules /etc/udev/rules.d/25-lfs.rules

/sbin/udevstart

#   ----
    cd [chapter06 source directory]
    rm -rf [Udev-056 source directory]
}

# Util-linux-2.12q
function chapter06-util-linux ()
{
    echo "chapter06-util-linux"
    cd [chapter06 source directory]
    tar -jxf [Util-linux-2.12q].tar.bz2
    cd [Util-linux-2.12q source directory]
#   ----

sed -i 's@etc/adjtime@var/lib/hwclock/adjtime@g' \
    hwclock/hwclock.c
mkdir -p /var/lib/hwclock

patch -Np1 -i ../util-linux-2.12q-cramfs-1.patch

patch -Np1 -i ../util-linux-2.12q-umount_fix-1.patch

./configure

make HAVE_KILL=yes HAVE_SLN=yes

make HAVE_KILL=yes HAVE_SLN=yes install
mv /usr/bin/logger /bin

#   ----
    cd [chapter06 source directory]
    rm -rf [Util-linux-2.12q source directory]
}

# About Debugging Symbols
function chapter06-aboutdebug ()
{
    echo "chapter06-aboutdebug"
#   ----

#   ----
}

# Stripping Again
function chapter06-strippingagain ()
{
    echo "chapter06-strippingagain"
#   ----

logout

chroot $LFS /tools/bin/env -i \
    HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /tools/bin/bash --login

/tools/bin/find /{,usr/}{bin,lib,sbin} -type f \
   -exec /tools/bin/strip --strip-debug '{}' ';'

#   ----
}

# Cleaning Up
function chapter06-revisedchroot ()
{
    echo "chapter06-revisedchroot"
#   ----

chroot "$LFS" /usr/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login

#   ----
}

# Introduction
function chapter07-introduction ()
{
    echo "chapter07-introduction"
#   ----

#   ----
}

# LFS-Bootscripts-3.2.1
function chapter07-bootscripts ()
{
    echo "chapter07-bootscripts"
    cd [chapter07 source directory]
    tar -jxf [LFS-Bootscripts-3.2.1].tar.bz2
    cd [LFS-Bootscripts-3.2.1 source directory]
#   ----

make install

#   ----
    cd [chapter07 source directory]
    rm -rf [LFS-Bootscripts-3.2.1 source directory]
}

# How Do These Bootscripts Work?
function chapter07-usage ()
{
    echo "chapter07-usage"
#   ----

#   ----
}

# Device and Module Handling on an LFS System
function chapter07-udev ()
{
    echo "chapter07-udev"
#   ----

install snd-pcm modprobe -i snd-pcm ; modprobe \
    snd-pcm-oss ; true

#   ----
}

# Configuring the setclock Script
function chapter07-setclock ()
{
    echo "chapter07-setclock"
#   ----

cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock

UTC=1

# End /etc/sysconfig/clock
EOF

#   ----
}

# Configuring the Linux Console
function chapter07-console ()
{
    echo "chapter07-console"
#   ----

cat >/etc/sysconfig/console <<"EOF"
KEYMAP="[arguments for loadkeys]"
FONT="[arguments for setfont]"
EOF

cat >/etc/sysconfig/console <<"EOF"
KEYMAP="es euro2"
FONT="lat9-16 -u iso01"
EOF

FONT="lat1-16"

zgrep '\W14\W' [/path/to/your/keymap]

mkdir -pv /etc/kbd && cat > /etc/kbd/bs-sends-del <<"EOF"
                  keycode  14 = Delete Delete Delete Delete
              alt keycode  14 = Meta_Delete
        altgr alt keycode  14 = Meta_Delete
                  keycode 111 = Remove
    altgr control keycode 111 = Boot
      control alt keycode 111 = Boot
altgr control alt keycode 111 = Boot
EOF

cat >>/etc/sysconfig/console <<"EOF"
KEYMAP_CORRECTIONS="/etc/kbd/bs-sends-del"
EOF

#   ----
}

# Configuring the sysklogd script
function chapter07-sysklogd ()
{
    echo "chapter07-sysklogd"
#   ----

#   ----
}

# Creating the /etc/inputrc File
function chapter07-inputrc ()
{
    echo "chapter07-inputrc"
#   ----

cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <roryo@roryo.dynup.net>

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the
# value contained inside the 1st argument to the
# readline specific functions

"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF

#   ----
}

# The Bash Shell Startup Files
function chapter07-profile ()
{
    echo "chapter07-profile"
#   ----

locale -a

LC_ALL=[locale name] locale charmap

LC_ALL=[locale name] locale country
LC_ALL=[locale name] locale language
LC_ALL=[locale name] locale charmap
LC_ALL=[locale name] locale int_curr_symbol
LC_ALL=[locale name] locale int_prefix

cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=[ll]_[CC].[charmap]
export INPUTRC=/etc/inputrc

# End /etc/profile
EOF

#   ----
}

# Configuring the localnet Script
function chapter07-hostname ()
{
    echo "chapter07-hostname"
#   ----

echo "HOSTNAME=[lfs]" > /etc/sysconfig/network

#   ----
}

# Creating the /etc/hosts File
function chapter07-hosts ()
{
    echo "chapter07-hosts"
#   ----

cat > /etc/hosts << "EOF"
# Begin /etc/hosts (network card version)

127.0.0.1 localhost
[192.168.1.1] [<HOSTNAME>.example.org] [HOSTNAME]

# End /etc/hosts (network card version)
EOF

cat > /etc/hosts << "EOF"
# Begin /etc/hosts (no network card version)

127.0.0.1 [<HOSTNAME>.example.org] [HOSTNAME] localhost

# End /etc/hosts (no network card version)
EOF

#   ----
}

# Configuring the network Script
function chapter07-network ()
{
    echo "chapter07-network"
#   ----

cd /etc/sysconfig/network-devices &&
mkdir -v ifconfig.eth0 &&
cat > ifconfig.eth0/ipv4 << "EOF"
ONBOOT=yes
SERVICE=ipv4-static
IP=192.168.1.1
GATEWAY=192.168.1.2
PREFIX=24
BROADCAST=192.168.1.255
EOF

cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

domain {[Your Domain Name]}
nameserver [IP address of your primary nameserver]
nameserver [IP address of your secondary nameserver]

# End /etc/resolv.conf
EOF

#   ----
}

# Introduction
function chapter08-introduction ()
{
    echo "chapter08-introduction"
#   ----

#   ----
}

# Creating the /etc/fstab File
function chapter08-fstab ()
{
    echo "chapter08-fstab"
#   ----

cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point  type   options         dump  fsck
#                                                        order

/dev/[xxx]     /            [fff]  defaults        1     1
/dev/[yyy]     swap         swap   pri=1           0     0
proc           /proc        proc   defaults        0     0
sysfs          /sys         sysfs  defaults        0     0
devpts         /dev/pts     devpts gid=4,mode=620  0     0
shm            /dev/shm     tmpfs  defaults        0     0
# End /etc/fstab
EOF

#   ----
}

# Linux-2.6.11.12
function chapter08-kernel ()
{
    echo "chapter08-kernel"
    cd [chapter08 source directory]
    tar -jxf [Linux-2.6.11.12].tar.bz2
    cd [Linux-2.6.11.12 source directory]
#   ----

make mrproper

loadkeys -m /usr/share/kbd/keymaps/[path to  keymap] > \
    drivers/char/defkeymap.c

make menuconfig

make

make modules_install

cp -v arch/i386/boot/bzImage /boot/lfskernel-2.6.11.12

cp -v System.map /boot/System.map-2.6.11.12

cp -v .config /boot/config-2.6.11.12

#   ----
    cd [chapter08 source directory]
    rm -rf [Linux-2.6.11.12 source directory]
}

# Making the LFS System Bootable
function chapter08-grub ()
{
    echo "chapter08-grub"
#   ----

dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1
dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1

grub

root (hd0,3)

setup (hd0)

quit

cat > /boot/grub/menu.lst << "EOF"
# Begin /boot/grub/menu.lst

# By default boot the first menu entry.
default 0

# Allow 30 seconds before booting the default.
timeout 30

# Use prettier colors.
color green/black light-green/black

# The first entry is for LFS.
title LFS 6.1.1
root (hd0,3)
kernel /boot/lfskernel-2.6.11.12 root=/dev/hda4
EOF

cat >> /boot/grub/menu.lst << "EOF"
title Red Hat
root (hd0,2)
kernel /boot/kernel-2.6.5 root=/dev/hda3
initrd /boot/initrd-2.6.5
EOF

cat >> /boot/grub/menu.lst << "EOF"
title Windows
rootnoverify (hd0,0)
chainloader +1
EOF

mkdir -v /etc/grub &&
ln -sv /boot/grub/menu.lst /etc/grub

#   ----
}

# The End
function chapter09-theend ()
{
    echo "chapter09-theend"
#   ----

echo 6.1.1 > /etc/lfs-release

#   ----
}

# Get Counted
function chapter09-getcounted ()
{
    echo "chapter09-getcounted"
#   ----

#   ----
}

# Rebooting the System
function chapter09-reboot ()
{
    echo "chapter09-reboot"
#   ----

logout

umount -v $LFS/dev/pts
umount -v $LFS/dev/shm
umount -v $LFS/dev
umount -v $LFS/proc
umount -v $LFS/sys

umount -v $LFS

umount -v $LFS/usr
umount -v $LFS/home
umount -v $LFS

shutdown -r now

#   ----
}

# What Now?
function chapter09-whatnow ()
{
    echo "chapter09-whatnow"
#   ----

#   ----
}

# Preface
function prologue ()
{
    prologue-foreword
    prologue-audience
    prologue-prerequisites
    prologue-hostreqs
    prologue-typography
    prologue-organization
    prologue-errata
}

# Introduction
function chapter01 ()
{
    chapter01-how
    chapter01-changelog
    chapter01-resources
    chapter01-askforhelp
}

# Preparing a New Partition
function chapter02 ()
{
    chapter02-introduction
    chapter02-creatingpartition
    chapter02-creatingfilesystem
    chapter02-mounting
}

# Packages and Patches
function chapter03 ()
{
    chapter03-introduction
    chapter03-packages
    chapter03-patches
}

# Final Preparations
function chapter04 ()
{
    chapter04-aboutlfs
    chapter04-creatingtoolsdir
    chapter04-addinguser
    chapter04-settingenvironment
    chapter04-aboutsbus
    chapter04-abouttestsuites
}

# Constructing a Temporary System
function chapter05 ()
{
    chapter05-introduction
    chapter05-toolchaintechnotes
    chapter05-binutils-pass1
    chapter05-gcc-pass1
    chapter05-linux-libc-headers
    chapter05-glibc
    chapter05-adjusting
    chapter05-tcl
    chapter05-expect
    chapter05-dejagnu
    chapter05-gcc-pass2
    chapter05-binutils-pass2
    chapter05-gawk
    chapter05-coreutils
    chapter05-bzip2
    chapter05-gzip
    chapter05-diffutils
    chapter05-findutils
    chapter05-make
    chapter05-grep
    chapter05-sed
    chapter05-gettext
    chapter05-ncurses
    chapter05-patch
    chapter05-tar
    chapter05-texinfo
    chapter05-bash
    chapter05-m4
    chapter05-bison
    chapter05-flex
    chapter05-util-linux
    chapter05-perl
    chapter05-stripping
}

# Installing Basic System Software
function chapter06 ()
{
    chapter06-introduction
    chapter06-kernfs
    chapter06-chroot
    chapter06-changingowner
    chapter06-creatingdirs
    chapter06-createfiles
    chapter06-pwdgroup
    chapter06-devices
    chapter06-linux-libc-headers
    chapter06-man-pages
    chapter06-glibc
    chapter06-readjusting
    chapter06-binutils
    chapter06-gcc
    chapter06-coreutils
    chapter06-zlib
    chapter06-mktemp
    chapter06-iana-etc
    chapter06-findutils
    chapter06-gawk
    chapter06-ncurses
    chapter06-readline
    chapter06-vim
    chapter06-m4
    chapter06-bison
    chapter06-less
    chapter06-groff
    chapter06-sed
    chapter06-flex
    chapter06-gettext
    chapter06-inetutils
    chapter06-iproute2
    chapter06-perl
    chapter06-texinfo
    chapter06-autoconf
    chapter06-automake
    chapter06-bash
    chapter06-file
    chapter06-libtool
    chapter06-bzip2
    chapter06-diffutils
    chapter06-kbd
    chapter06-e2fsprogs
    chapter06-grep
    chapter06-grub
    chapter06-gzip
    chapter06-hotplug
    chapter06-man
    chapter06-make
    chapter06-module-init-tools
    chapter06-patch
    chapter06-procps
    chapter06-psmisc
    chapter06-shadow
    chapter06-sysklogd
    chapter06-sysvinit
    chapter06-tar
    chapter06-udev
    chapter06-util-linux
    chapter06-aboutdebug
    chapter06-strippingagain
    chapter06-revisedchroot
}

# Setting Up System Bootscripts
function chapter07 ()
{
    chapter07-introduction
    chapter07-bootscripts
    chapter07-usage
    chapter07-udev
    chapter07-setclock
    chapter07-console
    chapter07-sysklogd
    chapter07-inputrc
    chapter07-profile
    chapter07-hostname
    chapter07-hosts
    chapter07-network
}

# Making the LFS System Bootable
function chapter08 ()
{
    chapter08-introduction
    chapter08-fstab
    chapter08-kernel
    chapter08-grub
}

# The End
function chapter09 ()
{
    chapter09-theend
    chapter09-getcounted
    chapter09-reboot
    chapter09-whatnow
}

# Linux From Scratch Version 6.1.1
function lfs ()
{
    prologue
    chapter01
    chapter02
    chapter03
    chapter04
    chapter05
    chapter06
    chapter07
    chapter08
    chapter09
}


if ! test -z "$1"
then
    $1
    exit
fi

lfs

#End afs (Automation From Scratch) - Linux From Scratch Version 6.1.1

Appendix B. AFS Completed Example

A completed AFS script without required system values. The required system values must be added for the script to run. Copy to the file afs.

#!/bin/bash
#Begin afs (Automation From Scratch) - Linux From Scratch Version 6.1.1

# Set global environment settings and variables.
set -e +h
umask 022

# The all knowing LFS variable.
export LFS=/mnt/lfs



# Foreword
function prologue-foreword ()
{
    echo "prologue-foreword"
#   ----

#   ----
}

# Audience
function prologue-audience ()
{
    echo "prologue-audience"
#   ----

#   ----
}

# Prerequisites
function prologue-prerequisites ()
{
    echo "prologue-prerequisites"
#   ----

#   ----
}

# Host System Requirements
function prologue-hostreqs ()
{
    echo "prologue-hostreqs"
#   ----

    cat /proc/version

#   ----
}

# Typography
function prologue-typography ()
{
    echo "prologue-typography"
#   ----

#   ./configure --prefix=/usr

#   cat > $LFS/etc/group << "EOF"
#root:x:0:
#bin:x:1:
#......
#EOF

#   ----
}

# Structure
function prologue-organization ()
{
    echo "prologue-organization"
#   ----

#   ----
}

# Errata
function prologue-errata ()
{
    echo "prologue-errata"
#   ----

#   ----
}

# How to Build an LFS System
function chapter01-how ()
{
    echo "chapter01-how"
#   ----

#   ----
}

# Changelog
function chapter01-changelog ()
{
    echo "chapter01-changelog"
#   ----

#   ----
}

# Resources
function chapter01-resources ()
{
    echo "chapter01-resources"
#   ----

#   ----
}

# Help
function chapter01-askforhelp ()
{
    echo "chapter01-askforhelp"
#   ----

#   ----
}

# Introduction
function chapter02-introduction ()
{
    echo "chapter02-introduction"
#   ----

#   ----
}

# Creating a New Partition
function chapter02-creatingpartition ()
{
    echo "chapter02-creatingpartition"
#   ----

#   ----
}

# Creating a File System on the Partition
function chapter02-creatingfilesystem ()
{
    echo "chapter02-creatingfilesystem"
#   ----

#   mke2fs -v /dev/[xxx]

#   debugfs -R feature /dev/[xxx]

#   cd /tmp
#   tar -xjvf /path/to/sources/e2fsprogs-1.37.tar.bz2
#   cd e2fsprogs-1.37
#   mkdir -v build
#   cd build
#   ../configure
#   make #note that we intentionally don't 'make install' here!
#   ./misc/mke2fs -v /dev/[xxx]
#   cd /tmp
#   rm -rfv e2fsprogs-1.37

#   mkswap -v /dev/[yyy]

#   ----
}

# Mounting the New Partition
function chapter02-mounting ()
{
    echo "chapter02-mounting"
#   ----

#   export LFS=/mnt/lfs

    mkdir -pv $LFS
#   mount -v /dev/[xxx] $LFS

#   mkdir -pv $LFS
#   mount -v /dev/[xxx] $LFS
#   mkdir -v $LFS/usr
#   mount -v /dev/[yyy] $LFS/usr

#   ----
}

# Introduction
function chapter03-introduction ()
{
    echo "chapter03-introduction"
#   ----

    mkdir -v $LFS/sources

    chmod -v a+wt $LFS/sources

    cp sources/* $LFS/sources/

#   ----
}

# All Packages
function chapter03-packages ()
{
    echo "chapter03-packages"
#   ----

#   ----
}

# Needed Patches
function chapter03-patches ()
{
    echo "chapter03-patches"
#   ----

#   ----
}

# About $LFS
function chapter04-aboutlfs ()
{
    echo "chapter04-aboutlfs"
#   ----

    echo $LFS

#   export LFS=/mnt/lfs

#   ----
}

# Creating the $LFS/tools Directory
function chapter04-creatingtoolsdir ()
{
    echo "chapter04-creatingtoolsdir"
#   ----

    mkdir -v $LFS/tools

    ln -sv $LFS/tools /

#   ----
}

# Adding the LFS User
function chapter04-addinguser ()
{
    echo "chapter04-addinguser"
#   ----

    groupadd lfs
    useradd -s /bin/bash -g lfs -m -k /dev/null lfs

#   passwd lfs

    chown -v lfs $LFS/tools

    chown -v lfs $LFS/sources

#   su - lfs

    cp afs $LFS/sources/afs
    chown -v lfs $LFS/sources/afs

#   ----
}

# Setting Up the Environment
function chapter04-settingenvironment ()
{
    echo "chapter04-settingenvironment"
#   ----

    cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF

    cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL PATH
EOF

#   source ~/.bash_profile

#   ----
}

# About SBUs
function chapter04-aboutsbus ()
{
    echo "chapter04-aboutsbus"
#   ----

#   ----
}

# About the Test Suites
function chapter04-abouttestsuites ()
{
    echo "chapter04-abouttestsuites"
#   ----

#   ----
}

# Introduction
function chapter05-introduction ()
{
    echo "chapter05-introduction"
#   ----

    echo $LFS

#   ----
}

# Toolchain Technical Notes
function chapter05-toolchaintechnotes ()
{
    echo "chapter05-toolchaintechnotes"
#   ----

#   ----
}

# Binutils-2.15.94.0.2.2 - Pass 1
function chapter05-binutils-pass1 ()
{
    echo "chapter05-binutils-pass1"
    cd $LFS/sources
    tar -jxf binutils-2.15.94.0.2.2.tar.bz2
    cd binutils-2.15.94.0.2.2
#   ----

    patch -Np1 -i ../binutils-2.15.94.0.2.2-gcc4-1.patch

    mkdir -v ../binutils-build
    cd ../binutils-build

    ../binutils-2.15.94.0.2.2/configure --prefix=/tools --disable-nls

    make

    make install

    make -C ld clean
    make -C ld LIB_PATH=/tools/lib

#   ----
    cd $LFS/sources
#   rm -rf binutils-2.15.94.0.2.2
}

# GCC-3.4.3 - Pass 1
function chapter05-gcc-pass1 ()
{
    echo "chapter05-gcc-pass1"
    cd $LFS/sources
    tar -jxf gcc-3.4.3.tar.bz2
    cd gcc-3.4.3
#   ----

    mkdir -v ../gcc-build
    cd ../gcc-build

    ../gcc-3.4.3/configure --prefix=/tools \
        --libexecdir=/tools/lib --with-local-prefix=/tools \
        --disable-nls --enable-shared --enable-languages=c

    make bootstrap

    make install

    ln -vs gcc /tools/bin/cc

#   ----
    cd $LFS/sources
    rm -rf gcc-build
    rm -rf gcc-3.4.3
}

# Linux-Libc-Headers-2.6.11.2
function chapter05-linux-libc-headers ()
{
    echo "chapter05-linux-libc-headers"
    cd $LFS/sources
    tar -jxf linux-libc-headers-2.6.11.2.tar.bz2
    cd linux-libc-headers-2.6.11.2
#   ----

    cp -Rv include/asm-i386 /tools/include/asm
    cp -Rv include/linux /tools/include

#   ----
    cd $LFS/sources
    rm -rf linux-libc-headers-2.6.11.2
}

# Glibc-2.3.4
function chapter05-glibc ()
{
    echo "chapter05-glibc"
    cd $LFS/sources
    tar -jxf glibc-2.3.4.tar.bz2
    cd glibc-2.3.4
#   ----

    patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch

    mkdir -v ../glibc-build
    cd ../glibc-build

    ../glibc-2.3.4/configure --prefix=/tools \
        --disable-profile --enable-add-ons \
        --enable-kernel=2.6.0 --with-binutils=/tools/bin \
        --without-gd --with-headers=/tools/include \
        --without-selinux

    make

#   make check

    mkdir -v /tools/etc
    touch /tools/etc/ld.so.conf

    make install

#   make localedata/install-locales

#   mkdir -pv /tools/lib/locale
#   localedef -i de_DE -f ISO-8859-1 de_DE
#   localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
#   localedef -i en_HK -f ISO-8859-1 en_HK
#   localedef -i en_PH -f ISO-8859-1 en_PH
#   localedef -i en_US -f ISO-8859-1 en_US
#   localedef -i es_MX -f ISO-8859-1 es_MX
#   localedef -i fa_IR -f UTF-8 fa_IR
#   localedef -i fr_FR -f ISO-8859-1 fr_FR
#   localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
#   localedef -i it_IT -f ISO-8859-1 it_IT
#   localedef -i ja_JP -f EUC-JP ja_JP

#   ----
    cd $LFS/sources
    rm -rf glibc-build
    rm -rf glibc-2.3.4
}

# Adjusting the Toolchain
function chapter05-adjusting ()
{
    echo "chapter05-adjusting"
    cd $LFS/sources
#   ----

    cd binutils-build

    make -C ld install

    cd $LFS/sources
    rm -rf binutils-build
    rm -rf binutils-2.15.94.0.2.2

    SPECFILE=`gcc --print-file specs` &&
    sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \
        $SPECFILE > tempspecfile &&
    mv -f tempspecfile $SPECFILE &&
    unset SPECFILE

    rm -vf /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}

    echo 'main(){}' > dummy.c
    cc dummy.c
#   readelf -l a.out | grep ': /tools'

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /tools/lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter05-adjusting"
        exit 1
    fi

    rm -v dummy.c a.out

#   ----
}

# Tcl-8.4.9
function chapter05-tcl ()
{
    echo "chapter05-tcl"
    cd $LFS/sources
    tar -jxf tcl8.4.9-src.tar.bz2
    cd tcl8.4.9
#   ----

    cd unix
    ./configure --prefix=/tools

    make

    make install

    cd ..
#   export TCLPATH=`pwd`

    ln -sv tclsh8.4 /tools/bin/tclsh

#   ----
    cd $LFS/sources
#   rm -rf tcl8.4.9
}

# Expect-5.43.0
function chapter05-expect ()
{
    echo "chapter05-expect"
    cd $LFS/sources
    tar -jxf expect-5.43.0.tar.bz2
    cd expect-5.43
#   ----

    patch -Np1 -i ../expect-5.43.0-spawn-1.patch

    ./configure --prefix=/tools --with-tcl=/tools/lib \
       --with-tclinclude=../tcl8.4.9 --with-x=no

    make

    make SCRIPTS="" install

#   unset TCLPATH

#   ----
    cd $LFS/sources
    rm -rf expect-5.43
    rm -rf tcl8.4.9
}

# DejaGNU-1.4.4
function chapter05-dejagnu ()
{
    echo "chapter05-dejagnu"
    cd $LFS/sources
    tar -jxf dejagnu-1.4.4.tar.bz2
    cd dejagnu-1.4.4
#   ----

    ./configure --prefix=/tools

    make install

#   ----
    cd $LFS/sources
    rm -rf dejagnu-1.4.4
}

# GCC-3.4.3 - Pass 2
function chapter05-gcc-pass2 ()
{
    echo "chapter05-gcc-pass2"
    cd $LFS/sources
    tar -jxf gcc-3.4.3.tar.bz2
    cd gcc-3.4.3
#   ----

    expect -c "spawn ls"

    patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch
    patch -Np1 -i ../gcc-3.4.3-specs-2.patch

    mkdir -v ../gcc-build
    cd ../gcc-build

    ../gcc-3.4.3/configure --prefix=/tools \
        --libexecdir=/tools/lib --with-local-prefix=/tools \
        --enable-clocale=gnu --enable-shared \
        --enable-threads=posix --enable-__cxa_atexit \
        --enable-languages=c,c++ --disable-libstdcxx-pch

    make

#   make -k check

#   ../gcc-3.4.3/contrib/test_summary

    make install

    echo 'main(){}' > dummy.c
    cc dummy.c

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /tools/lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter05-adjusting"
        exit 1
    fi

    rm -v dummy.c a.out

#   ----
    cd $LFS/sources
    rm -rf gcc-build
    rm -rf gcc-3.4.3
}

# Binutils-2.15.94.0.2.2 - Pass 2
function chapter05-binutils-pass2 ()
{
    echo "chapter05-binutils-pass2"
    cd $LFS/sources
    tar -jxf binutils-2.15.94.0.2.2.tar.bz2
    cd binutils-2.15.94.0.2.2
#   ----

    mkdir -v ../binutils-build
    cd ../binutils-build

    ../binutils-2.15.94.0.2.2/configure --prefix=/tools \
        --disable-nls --enable-shared --with-lib-path=/tools/lib

    make

#   make check

    make install

    make -C ld clean
    make -C ld LIB_PATH=/usr/lib:/lib

#   ----
    cd $LFS/sources
#   rm -rf binutils-2.15.94.0.2.2
}

# Gawk-3.1.4
function chapter05-gawk ()
{
    echo "chapter05-gawk"
    cd $LFS/sources
    tar -jxf gawk-3.1.4.tar.bz2
    cd gawk-3.1.4
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf gawk-3.1.4
}

# Coreutils-5.2.1
function chapter05-coreutils ()
{
    echo "chapter05-coreutils"
    cd $LFS/sources
    tar -jxf coreutils-5.2.1.tar.bz2
    cd coreutils-5.2.1
#   ----

    DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf coreutils-5.2.1
}

# Bzip2-1.0.3
function chapter05-bzip2 ()
{
    echo "chapter05-bzip2"
    cd $LFS/sources
    tar -jxf bzip2-1.0.3.tar.bz2
    cd bzip2-1.0.3
#   ----

    make

    make PREFIX=/tools install

#   ----
    cd $LFS/sources
    rm -rf bzip2-1.0.3
}

# Gzip-1.3.5
function chapter05-gzip ()
{
    echo "chapter05-gzip"
    cd $LFS/sources
    tar -jxf gzip-1.3.5.tar.bz2
    cd gzip-1.3.5
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf gzip-1.3.5
}

# Diffutils-2.8.1
function chapter05-diffutils ()
{
    echo "chapter05-diffutils"
    cd $LFS/sources
    tar -jxf diffutils-2.8.1.tar.bz2
    cd diffutils-2.8.1
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf diffutils-2.8.1
}

# Findutils-4.2.23
function chapter05-findutils ()
{
    echo "chapter05-findutils"
    cd $LFS/sources
    tar -jxf findutils-4.2.23.tar.bz2
    cd findutils-4.2.23
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf findutils-4.2.23
}

# Make-3.80
function chapter05-make ()
{
    echo "chapter05-make"
    cd $LFS/sources
    tar -jxf make-3.80.tar.bz2
    cd make-3.80
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf make-3.80
}

# Grep-2.5.1a
function chapter05-grep ()
{
    echo "chapter05-grep"
    cd $LFS/sources
    tar -jxf grep-2.5.1a.tar.bz2
    cd grep-2.5.1a
#   ----

    ./configure --prefix=/tools \
        --disable-perl-regexp

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf grep-2.5.1a
}

# Sed-4.1.4
function chapter05-sed ()
{
    echo "chapter05-sed"
    cd $LFS/sources
    tar -jxf sed-4.1.4.tar.bz2
    cd sed-4.1.4
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf sed-4.1.4
}

# Gettext-0.14.3
function chapter05-gettext ()
{
    echo "chapter05-gettext"
    cd $LFS/sources
    tar -jxf gettext-0.14.3.tar.bz2
    cd gettext-0.14.3
#   ----

    ./configure --prefix=/tools --disable-libasprintf \
        --without-csharp

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf gettext-0.14.3
}

# Ncurses-5.4
function chapter05-ncurses ()
{
    echo "chapter05-ncurses"
    cd $LFS/sources
    tar -jxf ncurses-5.4.tar.bz2
    cd ncurses-5.4
#   ----

./configure --prefix=/tools --with-shared \
    --without-debug --without-ada --enable-overwrite

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf ncurses-5.4
}

# Patch-2.5.4
function chapter05-patch ()
{
    echo "chapter05-patch"
    cd $LFS/sources
    tar -jxf patch-2.5.4.tar.bz2
    cd patch-2.5.4
#   ----

    CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf patch-2.5.4
}

# Tar-1.15.1
function chapter05-tar ()
{
    echo "chapter05-tar"
    cd $LFS/sources
    tar -jxf tar-1.15.1.tar.bz2
    cd tar-1.15.1
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf tar-1.15.1
}

# Texinfo-4.8
function chapter05-texinfo ()
{
    echo "chapter05-texinfo"
    cd $LFS/sources
    tar -jxf texinfo-4.8.tar.bz2
    cd texinfo-4.8
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf texinfo-4.8
}

# Bash-3.0
function chapter05-bash ()
{
    echo "chapter05-bash"
    cd $LFS/sources
    tar -jxf bash-3.0.tar.bz2
    cd bash-3.0
#   ----

    patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch

    ./configure --prefix=/tools --without-bash-malloc

    make

    make install

    ln -vs bash /tools/bin/sh

#   ----
    cd $LFS/sources
    rm -rf bash-3.0
}

# M4-1.4.3
function chapter05-m4 ()
{
    echo "chapter05-m4"
    cd $LFS/sources
    tar -jxf m4-1.4.3.tar.bz2
    cd m4-1.4.3
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf m4-1.4.3
}

# Bison-2.0
function chapter05-bison ()
{
    echo "chapter05-bison"
    cd $LFS/sources
    tar -jxf bison-2.0.tar.bz2
    cd bison-2.0
#   ----

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf bison-2.0
}

# Flex-2.5.31
function chapter05-flex ()
{
    echo "chapter05-flex"
    cd $LFS/sources
    tar -jxf flex-2.5.31.tar.bz2
    cd flex-2.5.31
#   ----

    patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch

    touch doc/flex.1

    ./configure --prefix=/tools

    make

    make install

#   ----
    cd $LFS/sources
    rm -rf flex-2.5.31
}

# Util-linux-2.12q
function chapter05-util-linux ()
{
    echo "chapter05-util-linux"
    cd $LFS/sources
    tar -jxf util-linux-2.12q.tar.bz2
    cd util-linux-2.12q
#   ----

    sed -i 's@/usr/include@/tools/include@g' configure

    ./configure

    make -C lib

    make -C mount mount umount
    make -C text-utils more

    cp mount/{,u}mount text-utils/more /tools/bin

#   ----
    cd $LFS/sources
    rm -rf util-linux-2.12q
}

# Perl-5.8.7
function chapter05-perl ()
{
    echo "chapter05-perl"
    cd $LFS/sources
    tar -jxf perl-5.8.7.tar.bz2
    cd perl-5.8.7
#   ----

    patch -Np1 -i ../perl-5.8.7-libc-1.patch

    ./configure.gnu --prefix=/tools -Dstatic_ext='IO Fcntl POSIX'

    make perl utilities

    cp -v perl pod/pod2man /tools/bin
    mkdir -pv /tools/lib/perl5/5.8.7
    cp -Rv lib/* /tools/lib/perl5/5.8.7

#   ----
    cd $LFS/sources
    rm -rf perl-5.8.7
}

# Stripping
function chapter05-stripping ()
{
    echo "chapter05-stripping"
#   ----

    set +e

    strip --strip-debug /tools/lib/*
    strip --strip-unneeded /tools/{,s}bin/*

    set -e

rm -rf /tools/{info,man}

#   ----
}

# Introduction
function chapter06-introduction ()
{
    echo "chapter06-introduction"
#   ----

#   ----
}

# Mounting Virtual Kernel File Systems
function chapter06-kernfs ()
{
    echo "chapter06-kernfs"
#   ----

    mkdir -pv $LFS/{proc,sys}

    mount -vt proc proc $LFS/proc
    mount -vt sysfs sysfs $LFS/sys

    mount -vft tmpfs tmpfs $LFS/dev
    mount -vft tmpfs tmpfs $LFS/dev/shm
    mount -vft devpts -o gid=4,mode=620 devpts $LFS/dev/pts

#   ----
}

# Entering the Chroot Environment
function chapter06-chroot ()
{
    echo "chapter06-chroot"
#   ----

#   chroot "$LFS" /tools/bin/env -i \
#       HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
#       PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
#       /tools/bin/bash --login +h

#   ----
}

# Changing Ownership
function chapter06-changingowner ()
{
    echo "chapter06-changingowner"
#   ----

    chown -R 0:0 /tools

#   ----
}

# Creating Directories
function chapter06-creatingdirs ()
{
    echo "chapter06-creatingdirs"
#   ----

    install -dv /{bin,boot,dev,etc/opt,home,lib,mnt}
    install -dv /{sbin,srv,usr/local,var,opt}
    install -dv /root -m 0750
    install -dv /tmp /var/tmp -m 1777
    install -dv /media/{floppy,cdrom}
    install -dv /usr/{bin,include,lib,sbin,share,src}
    ln -sv share/{man,doc,info} /usr
    install -dv /usr/share/{doc,info,locale,man}
    install -dv /usr/share/{misc,terminfo,zoneinfo}
    install -dv /usr/share/man/man{1,2,3,4,5,6,7,8}
    install -dv /usr/local/{bin,etc,include,lib,sbin,share,src}
    ln -sv share/{man,doc,info} /usr/local
    install -dv /usr/local/share/{doc,info,locale,man}
    install -dv /usr/local/share/{misc,terminfo,zoneinfo}
    install -dv /usr/local/share/man/man{1,2,3,4,5,6,7,8}
    install -dv /var/{lock,log,mail,run,spool}
    install -dv /var/{opt,cache,lib/{misc,locate},local}
    install -dv /opt/{bin,doc,include,info}
    install -dv /opt/{lib,man/man{1,2,3,4,5,6,7,8}}

#   ----
}

# Creating Essential Symlinks
function chapter06-createfiles ()
{
    echo "chapter06-createfiles"
#   ----

    ln -sv /tools/bin/{bash,cat,pwd,stty} /bin
    ln -sv /tools/bin/perl /usr/bin
    ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
    ln -sv bash /bin/sh

#   ----
}

# Creating the passwd, group, and log Files
function chapter06-pwdgroup ()
{
    echo "chapter06-pwdgroup"
#   ----

    cat > /etc/passwd << "EOF"
root::0:0:root:/root:/bin/bash
EOF

cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
EOF

#   exec /tools/bin/bash --login +h

    touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
    chgrp -v utmp /var/run/utmp /var/log/lastlog
    chmod -v 664 /var/run/utmp /var/log/lastlog

#   ----
}

# Populating /dev
function chapter06-devices ()
{
    echo "chapter06-devices"
#   ----

    mknod -m 600 /dev/console c 5 1
    mknod -m 666 /dev/null c 1 3

    mount -nvt tmpfs none /dev

    mknod -m 622 /dev/console c 5 1
    mknod -m 666 /dev/null c 1 3
    mknod -m 666 /dev/zero c 1 5
    mknod -m 666 /dev/ptmx c 5 2
    mknod -m 666 /dev/tty c 5 0
    mknod -m 444 /dev/random c 1 8
    mknod -m 444 /dev/urandom c 1 9
    chown -v root:tty /dev/{console,ptmx,tty}

    ln -sv /proc/self/fd /dev/fd
    ln -sv /proc/self/fd/0 /dev/stdin
    ln -sv /proc/self/fd/1 /dev/stdout
    ln -sv /proc/self/fd/2 /dev/stderr
    ln -sv /proc/kcore /dev/core
    mkdir -v /dev/pts
    mkdir -v /dev/shm

    mount -vt devpts -o gid=4,mode=620 none /dev/pts
    mount -vt tmpfs none /dev/shm

#   ----
}

# Linux-Libc-Headers-2.6.11.2
function chapter06-linux-libc-headers ()
{
    echo "chapter06-linux-libc-headers"
    cd /sources
    tar -jxf linux-libc-headers-2.6.11.2.tar.bz2
    cd linux-libc-headers-2.6.11.2
#   ----

    cp -Rv include/asm-i386 /usr/include/asm
    cp -Rv include/linux /usr/include

    chown -Rv root:root /usr/include/{asm,linux}

    find /usr/include/{asm,linux} -type d -exec chmod -v 755 {} \;
    find /usr/include/{asm,linux} -type f -exec chmod -v 644 {} \;

#   ----
    cd /sources
    rm -rf linux-libc-headers-2.6.11.2
}

# Man-pages-2.01
function chapter06-man-pages ()
{
    echo "chapter06-man-pages"
    cd /sources
    tar -jxf man-pages-2.01.tar.bz2
    cd man-pages-2.01
#   ----

    make install

#   ----
    cd /sources
    rm -rf man-pages-2.01
}

# Glibc-2.3.4
function chapter06-glibc ()
{
    echo "chapter06-glibc"
    cd /sources
    tar -jxf glibc-2.3.4.tar.bz2
    cd glibc-2.3.4
#   ----

    tar -xjvf ../glibc-linuxthreads-2.3.4.tar.bz2

    patch -Np1 -i ../glibc-2.3.4-rtld_search_dirs-1.patch

    patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch

    patch -Np1 -i ../glibc-2.3.4-tls_assert-1.patch

    mkdir -v ../glibc-build
    cd ../glibc-build

    ../glibc-2.3.4/configure --prefix=/usr \
        --disable-profile --enable-add-ons \
        --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc

    make

#   make -k check >glibc-check-log 2>&1
#   grep Error glibc-check-log

    touch /etc/ld.so.conf

    make install

    make localedata/install-locales

#   mkdir -pv /usr/lib/locale
#   localedef -i de_DE -f ISO-8859-1 de_DE
#   localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
#   localedef -i en_HK -f ISO-8859-1 en_HK
#   localedef -i en_PH -f ISO-8859-1 en_PH
#   localedef -i en_US -f ISO-8859-1 en_US
#   localedef -i es_MX -f ISO-8859-1 es_MX
#   localedef -i fa_IR -f UTF-8 fa_IR
#   localedef -i fr_FR -f ISO-8859-1 fr_FR
#   localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
#   localedef -i it_IT -f ISO-8859-1 it_IT
#   localedef -i ja_JP -f EUC-JP ja_JP

    make -C ../glibc-2.3.4/linuxthreads/man

    make -C ../glibc-2.3.4/linuxthreads/man install

    cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

#   tzselect

    cp -v --remove-destination /usr/share/zoneinfo/[xxx] \
        /etc/localtime

    cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF

#   ----
    cd /sources
    rm -rf glibc-build
    rm -rf glibc-2.3.4
}

# Re-adjusting the Toolchain
function chapter06-readjusting ()
{
    echo "chapter06-readjusting"
    cd /sources
#   ----

    cd binutils-build

    make -C ld INSTALL=/tools/bin/install install

    cd /sources
    rm -rf binutils-build
    rm -rf binutils-2.15.94.0.2.2

    perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' \
        -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;' \
        `gcc --print-file specs`

    echo 'main(){}' > dummy.c
    cc dummy.c
#   readelf -l a.out | grep ': /lib'

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter06-readjusting"
        exit 1
    fi

    rm -v dummy.c a.out

#   ----
}

# Binutils-2.15.94.0.2.2
function chapter06-binutils ()
{
    echo "chapter06-binutils"
    cd /sources
    tar -jxf binutils-2.15.94.0.2.2.tar.bz2
    cd binutils-2.15.94.0.2.2
#   ----

    expect -c "spawn ls"

    mkdir -v ../binutils-build
    cd ../binutils-build

    ../binutils-2.15.94.0.2.2/configure --prefix=/usr \
        --enable-shared

    make tooldir=/usr

#   make check

    make tooldir=/usr install

    cp -v ../binutils-2.15.94.0.2.2/include/libiberty.h /usr/include

#   ----
    cd /sources
    rm -rf binutils-build
    rm -rf binutils-2.15.94.0.2.2
}

# GCC-3.4.3
function chapter06-gcc ()
{
    echo "chapter06-gcc"
    cd /sources
    tar -jxf gcc-3.4.3.tar.bz2
    cd gcc-3.4.3
#   ----

    patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch

    patch -Np1 -i ../gcc-3.4.3-linkonce-1.patch

    sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

    mkdir -v ../gcc-build
    cd ../gcc-build

    ../gcc-3.4.3/configure --prefix=/usr \
        --libexecdir=/usr/lib --enable-shared \
        --enable-threads=posix --enable-__cxa_atexit \
        --enable-clocale=gnu --enable-languages=c,c++

    make

#   make -k check

    make install

    ln -sv ../usr/bin/cpp /lib

    ln -sv gcc /usr/bin/cc

    echo 'main(){}' > dummy.c
    cc dummy.c

    TOOLCHAIN_TEST=`readelf -l a.out | \
        grep "\[Requesting program interpreter: /lib/ld-linux.so.2\]"`

    if test -z "$TOOLCHAIN_TEST"
    then
        echo "*** FATAL ERROR: Failed tool chain test, chapter06-readjusting"
        exit 1
    fi

    rm -v dummy.c a.out

#   ----
    cd /sources
    rm -rf gcc-build
    rm -rf gcc-3.4.3
}

# Coreutils-5.2.1
function chapter06-coreutils ()
{
    echo "chapter06-coreutils"
    cd /sources
    tar -jxf coreutils-5.2.1.tar.bz2
    cd coreutils-5.2.1
#   ----

    patch -Np1 -i ../coreutils-5.2.1-uname-2.patch

    patch -Np1 -i ../coreutils-5.2.1-suppress_uptime_kill_su-1.patch

    DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/usr

    make

#   echo "dummy1:x:1000:" >> /etc/group
#   echo "dummy2:x:1001:dummy" >> /etc/group
#   echo "dummy:x:1000:1000:::/bin/bash" >> /etc/passwd

#   make NON_ROOT_USERNAME=dummy check-root

#   src/su dummy -c "make RUN_EXPENSIVE_TESTS=yes check"

#   sed -i '/dummy/d' /etc/passwd /etc/group

    make install

    mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
    mv -v /usr/bin/{false,hostname,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
    mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
    mv -v /usr/bin/chroot /usr/sbin

    mv -v /usr/bin/{head,sleep} /bin

#   ----
    cd /sources
    rm -rf coreutils-5.2.1
}

# Zlib-1.2.3
function chapter06-zlib ()
{
    echo "chapter06-zlib"
    cd /sources
    tar -jxf zlib-1.2.3.tar.bz2
    cd zlib-1.2.3
#   ----

    ./configure --prefix=/usr --shared --libdir=/lib

    make

    make install

    rm -v /lib/libz.so
    ln -sfv ../../lib/libz.so.1.2.3 /usr/lib/libz.so

    make clean
    ./configure --prefix=/usr
    make

    make install

    chmod -v 644 /usr/lib/libz.a

#   ----
    cd /sources
    rm -rf zlib-1.2.3
}

# Mktemp-1.5
function chapter06-mktemp ()
{
    echo "chapter06-mktemp"
    cd /sources
    tar -jxf mktemp-1.5.tar.bz2
    cd mktemp-1.5
#   ----

    patch -Np1 -i ../mktemp-1.5-add_tempfile-2.patch

    ./configure --prefix=/usr --with-libc

    make

    make install
    make install-tempfile

#   ----
    cd /sources
    rm -rf mktemp-1.5
}

# Iana-Etc-1.04
function chapter06-iana-etc ()
{
    echo "chapter06-iana-etc"
    cd /sources
    tar -jxf iana-etc-1.04.tar.bz2
    cd iana-etc-1.04
#   ----

    make

    make install

#   ----
    cd /sources
    rm -rf iana-etc-1.04
}

# Findutils-4.2.23
function chapter06-findutils ()
{
    echo "chapter06-findutils"
    cd /sources
    tar -jxf findutils-4.2.23.tar.bz2
    cd findutils-4.2.23
#   ----

    ./configure --prefix=/usr --libexecdir=/usr/lib/locate \
        --localstatedir=/var/lib/locate

    make

    make install

#   ----
    cd /sources
    rm -rf findutils-4.2.23
}

# Gawk-3.1.4
function chapter06-gawk ()
{
    echo "chapter06-gawk"
    cd /sources
    tar -jxf gawk-3.1.4.tar.bz2
    cd gawk-3.1.4
#   ----

    ./configure --prefix=/usr --libexecdir=/usr/lib

    make

    make install

#   ----
    cd /sources
    rm -rf gawk-3.1.4
}

# Ncurses-5.4
function chapter06-ncurses ()
{
    echo "chapter06-ncurses"
    cd /sources
    tar -jxf ncurses-5.4.tar.bz2
    cd ncurses-5.4
#   ----

    ./configure --prefix=/usr --with-shared --without-debug

    make

    make install

    chmod -v 755 /usr/lib/*.5.4

    chmod -v 644 /usr/lib/libncurses++.a

    mv -v /usr/lib/libncurses.so.5* /lib

    ln -sfv ../../lib/libncurses.so.5 /usr/lib/libncurses.so
    ln -sfv libncurses.so /usr/lib/libcurses.so

#   ----
    cd /sources
    rm -rf ncurses-5.4
}

# Readline-5.0
function chapter06-readline ()
{
    echo "chapter06-readline"
    cd /sources
    tar -jxf readline-5.0.tar.bz2
    cd readline-5.0
#   ----

    patch -Np1 -i ../readline-5.0-fixes-1.patch

    ./configure --prefix=/usr --libdir=/lib

    make SHLIB_XLDFLAGS=-lncurses

    make install

    chmod -v 755 /lib/lib{readline,history}.so*

    mv -v /lib/lib{readline,history}.a /usr/lib

    rm -v /lib/lib{readline,history}.so
    ln -sfv ../../lib/libreadline.so.5 /usr/lib/libreadline.so
    ln -sfv ../../lib/libhistory.so.5 /usr/lib/libhistory.so

#   ----
    cd /sources
    rm -rf readline-5.0
}

# Vim-6.3
function chapter06-vim ()
{
    echo "chapter06-vim"
    cd /sources
    tar -jxf vim-6.3.tar.bz2
    tar -jxf vim-6.3-lang.tar.bz2
    cd vim63
#   ----

    echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h

    patch -Np1 -i ../vim-6.3-security_fix-2.patch

    ./configure --prefix=/usr --enable-multibyte

    make

    make install

    ln -sv vim /usr/bin/vi

    cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF

#   vim -c ':options'

#   ----
    cd /sources
    rm -rf vim63
}

# M4-1.4.3
function chapter06-m4 ()
{
    echo "chapter06-m4"
    cd /sources
    tar -jxf m4-1.4.3.tar.bz2
    cd m4-1.4.3
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf m4-1.4.3
}

# Bison-2.0
function chapter06-bison ()
{
    echo "chapter06-bison"
    cd /sources
    tar -jxf bison-2.0.tar.bz2
    cd bison-2.0
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf bison-2.0
}

# Less-382
function chapter06-less ()
{
    echo "chapter06-less"
    cd /sources
    tar -jxf less-382.tar.bz2
    cd less-382
#   ----

    ./configure --prefix=/usr --bindir=/bin --sysconfdir=/etc

    make

    make install

#   ----
    cd /sources
    rm -rf less-382
}

# Groff-1.19.1
function chapter06-groff ()
{
    echo "chapter06-groff"
    cd /sources
    tar -jxf groff-1.19.1.tar.bz2
    cd groff-1.19.1
#   ----

    PAGE=[paper_size] ./configure --prefix=/usr

    make

    make install

    ln -sv soelim /usr/bin/zsoelim
    ln -sv eqn /usr/bin/geqn
    ln -sv tbl /usr/bin/gtbl

#   ----
    cd /sources
    rm -rf groff-1.19.1
}

# Sed-4.1.4
function chapter06-sed ()
{
    echo "chapter06-sed"
    cd /sources
    tar -jxf sed-4.1.4.tar.bz2
    cd sed-4.1.4
#   ----

    sed -i 's@/doc@&/sed-4.1.4@' doc/Makefile.in

    ./configure --prefix=/usr --bindir=/bin

    make

    make install

#   ----
    cd /sources
    rm -rf sed-4.1.4
}

# Flex-2.5.31
function chapter06-flex ()
{
    echo "chapter06-flex"
    cd /sources
    tar -jxf flex-2.5.31.tar.bz2
    cd flex-2.5.31
#   ----

    patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch

    touch doc/flex.1

    ./configure --prefix=/usr

    make

    make install

    ln -sv libfl.a /usr/lib/libl.a

    cat > /usr/bin/lex << "EOF"
#!/bin/sh
# Begin /usr/bin/lex

exec /usr/bin/flex -l "$@"

# End /usr/bin/lex
EOF
    chmod -v 755 /usr/bin/lex

#   ----
    cd /sources
    rm -rf flex-2.5.31
}

# Gettext-0.14.3
function chapter06-gettext ()
{
    echo "chapter06-gettext"
    cd /sources
    tar -jxf gettext-0.14.3.tar.bz2
    cd gettext-0.14.3
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf gettext-0.14.3
}

# Inetutils-1.4.2
function chapter06-inetutils ()
{
    echo "chapter06-inetutils"
    cd /sources
    tar -jxf inetutils-1.4.2.tar.bz2
    cd inetutils-1.4.2
#   ----

    patch -Np1 -i ../inetutils-1.4.2-kernel_headers-1.patch

    patch -Np1 -i ../inetutils-1.4.2-no_server_man_pages-1.patch

    ./configure --prefix=/usr --libexecdir=/usr/sbin \
        --sysconfdir=/etc --localstatedir=/var \
        --disable-logger --disable-syslogd \
        --disable-whois --disable-servers

    make

    make install

    mv -v /usr/bin/ping /bin

#   ----
    cd /sources
    rm -rf inetutils-1.4.2
}

# IPRoute2-2.6.11-050330
function chapter06-iproute2 ()
{
    echo "chapter06-iproute2"
    cd /sources
    tar -jxf iproute2-2.6.11-050330.tar.bz2
    cd iproute2-2.6.11
#   ----

    sed -i '/^TARGETS/s@arpd@@g' misc/Makefile

    ./configure 

    make SBINDIR=/sbin

    make SBINDIR=/sbin install

#   ----
    cd /sources
    rm -rf iproute2-2.6.11
}

# Perl-5.8.7
function chapter06-perl ()
{
    echo "chapter06-perl"
    cd /sources
    tar -jxf perl-5.8.7.tar.bz2
    cd perl-5.8.7
#   ----

    ./configure.gnu --prefix=/usr -Dpager="/bin/less -isR"

    make

#   echo "127.0.0.1 localhost $(hostname)" > /etc/hosts

#   make test

    make install

#   ----
    cd /sources
    rm -rf perl-5.8.7
}

# Texinfo-4.8
function chapter06-texinfo ()
{
    echo "chapter06-texinfo"
    cd /sources
    tar -jxf texinfo-4.8.tar.bz2
    cd texinfo-4.8
#   ----

    patch -Np1 -i ../texinfo-4.8-tempfile_fix-1.patch

    ./configure --prefix=/usr

    make

    make install

    make TEXMF=/usr/share/texmf install-tex

#   cd /usr/share/info
#   rm dir
#   for f in *
#   do install-info $f dir 2>/dev/null
#   done

#   ----
    cd /sources
    rm -rf texinfo-4.8
}

# Autoconf-2.59
function chapter06-autoconf ()
{
    echo "chapter06-autoconf"
    cd /sources
    tar -jxf autoconf-2.59.tar.bz2
    cd autoconf-2.59
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf autoconf-2.59
}

# Automake-1.9.5
function chapter06-automake ()
{
    echo "chapter06-automake"
    cd /sources
    tar -jxf automake-1.9.5.tar.bz2
    cd automake-1.9.5
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf automake-1.9.5
}

# Bash-3.0
function chapter06-bash ()
{
    echo "chapter06-bash"
    cd /sources
    tar -jxf bash-3.0.tar.bz2
    cd bash-3.0
#   ----

    tar -xvf ../bash-doc-3.0.tar.gz &&
    sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/bash-3.0|" \
        Makefile.in

    patch -Np1 -i ../bash-3.0-fixes-3.patch

    patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch

    ./configure --prefix=/usr --bindir=/bin \
        --without-bash-malloc --with-installed-readline

    make

    make install

#   exec /bin/bash --login +h

#   ----
    cd /sources
    rm -rf bash-3.0
}

# File-4.13
function chapter06-file ()
{
    echo "chapter06-file"
    cd /sources
    tar -jxf file-4.13.tar.bz2
    cd file-4.13
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf file-4.13
}

# Libtool-1.5.14
function chapter06-libtool ()
{
    echo "chapter06-libtool"
    cd /sources
    tar -jxf libtool-1.5.14.tar.bz2
    cd libtool-1.5.14
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf libtool-1.5.14
}

# Bzip2-1.0.3
function chapter06-bzip2 ()
{
    echo "chapter06-bzip2"
    cd /sources
    tar -jxf bzip2-1.0.3.tar.bz2
    cd bzip2-1.0.3
#   ----

    patch -Np1 -i ../bzip2-1.0.3-install_docs-1.patch

    patch -Np1 -i ../bzip2-1.0.3-bzgrep_security-1.patch

    make -f Makefile-libbz2_so
    make clean

    make

    make install

    cp -v bzip2-shared /bin/bzip2
    cp -av libbz2.so* /lib
    ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
    rm -v /usr/bin/{bunzip2,bzcat,bzip2}
    ln -sv bzip2 /bin/bunzip2
    ln -sv bzip2 /bin/bzcat

#   ----
    cd /sources
    rm -rf bzip2-1.0.3
}

# Diffutils-2.8.1
function chapter06-diffutils ()
{
    echo "chapter06-diffutils"
    cd /sources
    tar -jxf diffutils-2.8.1.tar.bz2
    cd diffutils-2.8.1
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf diffutils-2.8.1
}

# Kbd-1.12
function chapter06-kbd ()
{
    echo "chapter06-kbd"
    cd /sources
    tar -jxf kbd-1.12.tar.bz2
    cd kbd-1.12
#   ----

    ./configure

    make

    make install

#   ----
    cd /sources
    rm -rf kbd-1.12
}

# E2fsprogs-1.37
function chapter06-e2fsprogs ()
{
    echo "chapter06-e2fsprogs"
    cd /sources
    tar -jxf e2fsprogs-1.37.tar.bz2
    cd e2fsprogs-1.37
#   ----

    sed -i -e 's/-DTEST/$(ALL_CFLAGS) &/' lib/e2p/Makefile.in

    mkdir -v build
    cd build

    ../configure --prefix=/usr --with-root-prefix="" \
        --enable-elf-shlibs --disable-evms

    make

    make install

    make install-libs

#   ----
    cd /sources
    rm -rf e2fsprogs-1.37
}

# Grep-2.5.1a
function chapter06-grep ()
{
    echo "chapter06-grep"
    cd /sources
    tar -jxf grep-2.5.1a.tar.bz2
    cd grep-2.5.1a
#   ----

    ./configure --prefix=/usr --bindir=/bin

    make

    make install

#   ----
    cd /sources
    rm -rf grep-2.5.1a
}

# GRUB-0.96
function chapter06-grub ()
{
    echo "chapter06-grub"
    cd /sources
    tar -jxf grub-0.96.tar.bz2
    cd grub-0.96
#   ----

    ./configure --prefix=/usr

    make

    make install
    mkdir -v /boot/grub
    cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub

#   ----
    cd /sources
    rm -rf grub-0.96
}

# Gzip-1.3.5
function chapter06-gzip ()
{
    echo "chapter06-gzip"
    cd /sources
    tar -jxf gzip-1.3.5.tar.bz2
    cd gzip-1.3.5
#   ----

    patch -Np1 -i ../gzip-1.3.5-security_fixes-1.patch

    ./configure --prefix=/usr

    sed -i 's@"BINDIR"@/bin@g' gzexe.in

    make

    make install

    mv -v /usr/bin/gzip /bin
    rm -v /usr/bin/{gunzip,zcat}
    ln -sv gzip /bin/gunzip
    ln -sv gzip /bin/zcat
    ln -sv gzip /bin/compress
    ln -sv gunzip /bin/uncompress

#   ----
    cd /sources
    rm -rf gzip-1.3.5
}

# Hotplug-2004_09_23
function chapter06-hotplug ()
{
    echo "chapter06-hotplug"
    cd /sources
    tar -jxf hotplug-2004_09_23.tar.bz2
    cd hotplug-2004_09_23
#   ----

    make install

    cp -v etc/hotplug/pnp.distmap /etc/hotplug

    rm -rfv /etc/init.d

    rm -fv /etc/hotplug/net.agent

    mkdir -v /lib/firmware

#   ----
    cd /sources
    rm -rf hotplug-2004_09_23
}

# Man-1.5p
function chapter06-man ()
{
    echo "chapter06-man"
    cd /sources
    tar -jxf man-1.5p.tar.bz2
    cd man-1.5p
#   ----

    sed -i 's@-is@&R@g' configure

    sed -i 's@MANPATH./usr/man@#&@g' src/man.conf.in

    ./configure -confdir=/etc

    make

    make install

#   ----
    cd /sources
    rm -rf man-1.5p
}

# Make-3.80
function chapter06-make ()
{
    echo "chapter06-make"
    cd /sources
    tar -jxf make-3.80.tar.bz2
    cd make-3.80
#   ----

    ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf make-3.80
}

# Module-Init-Tools-3.1
function chapter06-module-init-tools ()
{
    echo "chapter06-module-init-tools"
    cd /sources
    tar -jxf module-init-tools-3.1.tar.bz2
    cd module-init-tools-3.1
#   ----

    touch modprobe.conf.5

#   tar -xvf ../module-init-tools-testsuite-3.1.tar.bz2 --strip-path=1 &&
#   ./configure &&
#   make check &&
#   make distclean

    ./configure --prefix="" --enable-zlib

    make

    make install

#   ----
    cd /sources
    rm -rf module-init-tools-3.1
}

# Patch-2.5.4
function chapter06-patch ()
{
    echo "chapter06-patch"
    cd /sources
    tar -jxf patch-2.5.4.tar.bz2
    cd patch-2.5.4
#   ----

    CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/usr

    make

    make install

#   ----
    cd /sources
    rm -rf patch-2.5.4
}

# Procps-3.2.5
function chapter06-procps ()
{
    echo "chapter06-procps"
    cd /sources
    tar -jxf procps-3.2.5.tar.bz2
    cd procps-3.2.5
#   ----

    make

    make install

#   ----
    cd /sources
    rm -rf procps-3.2.5
}

# Psmisc-21.6
function chapter06-psmisc ()
{
    echo "chapter06-psmisc"
    cd /sources
    tar -jxf psmisc-21.6.tar.bz2
    cd psmisc-21.6
#   ----

    ./configure --prefix=/usr --exec-prefix=""

    make

    make install

    mv -v /bin/pstree* /usr/bin

    ln -sv killall /bin/pidof

#   ----
    cd /sources
    rm -rf psmisc-21.6
}

# Shadow-4.0.9
function chapter06-shadow ()
{
    echo "chapter06-shadow"
    cd /sources
    tar -jxf shadow-4.0.9.tar.bz2
    cd shadow-4.0.9
#   ----

    ./configure --libdir=/lib --enable-shared

    sed -i 's/groups$(EXEEXT) //' src/Makefile
    sed -i '/groups/d' man/Makefile

    make

    make install

    cp -v etc/{limits,login.access} /etc

    sed -e's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \
        -e 's@/var/spool/mail@/var/mail@' \
        etc/login.defs.linux > /etc/login.defs

    mv -v /usr/bin/passwd /bin

    mv -v /lib/libshadow.*a /usr/lib
    rm -v /lib/libshadow.so
    ln -sfv ../../lib/libshadow.so.0 /usr/lib/libshadow.so

    mkdir -v /etc/default

    pwconv

    grpconv

#   passwd root

#   ----
    cd /sources
    rm -rf shadow-4.0.9
}

# Sysklogd-1.4.1
function chapter06-sysklogd ()
{
    echo "chapter06-sysklogd"
    cd /sources
    tar -jxf sysklogd-1.4.1.tar.bz2
    cd sysklogd-1.4.1
#   ----

    patch -Np1 -i ../sysklogd-1.4.1-fixes-1.patch

    make

    make install

    cat > /etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf

auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *

# log the bootscript output:
local2.* -/var/log/boot.log

# End /etc/syslog.conf
EOF

#   ----
    cd /sources
    rm -rf sysklogd-1.4.1
}

# Sysvinit-2.86
function chapter06-sysvinit ()
{
    echo "chapter06-sysvinit"
    cd /sources
    tar -jxf sysvinit-2.86.tar.bz2
    cd sysvinit-2.86
#   ----

    sed -i 's@Sending processes@& started by init@g' \
        src/init.c

    make -C src

    make -C src install

    cat > /etc/inittab << "EOF"
# Begin /etc/inittab

id:3:initdefault:

si::sysinit:/etc/rc.d/init.d/rc sysinit

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty -I '\033(K' tty1 9600
2:2345:respawn:/sbin/agetty -I '\033(K' tty2 9600
3:2345:respawn:/sbin/agetty -I '\033(K' tty3 9600
4:2345:respawn:/sbin/agetty -I '\033(K' tty4 9600
5:2345:respawn:/sbin/agetty -I '\033(K' tty5 9600
6:2345:respawn:/sbin/agetty -I '\033(K' tty6 9600

# End /etc/inittab
EOF

#   ----
    cd /sources
    rm -rf sysvinit-2.86
}

# Tar-1.15.1
function chapter06-tar ()
{
    echo "chapter06-tar"
    cd /sources
    tar -jxf tar-1.15.1.tar.bz2
    cd tar-1.15.1
#   ----

    patch -Np1 -i ../tar-1.15.1-sparse_fix-1.patch

    ./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin

    make

    make install

#   ----
    cd /sources
    rm -rf tar-1.15.1
}

# Udev-056
function chapter06-udev ()
{
    echo "chapter06-udev"
    cd /sources
    tar -jxf udev-056.tar.bz2
    cd udev-056
#   ----

    make udevdir=/dev

    make DESTDIR=/ udevdir=/dev install

    cp -v ../udev-config-4.rules /etc/udev/rules.d/25-lfs.rules

    /sbin/udevstart

#   ----
    cd /sources
    rm -rf udev-056
}

# Util-linux-2.12q
function chapter06-util-linux ()
{
    echo "chapter06-util-linux"
    cd /sources
    tar -jxf util-linux-2.12q.tar.bz2
    cd util-linux-2.12q
#   ----

    sed -i 's@etc/adjtime@var/lib/hwclock/adjtime@g' \
        hwclock/hwclock.c
    mkdir -p /var/lib/hwclock

    patch -Np1 -i ../util-linux-2.12q-cramfs-1.patch

    patch -Np1 -i ../util-linux-2.12q-umount_fix-1.patch

    ./configure

    make HAVE_KILL=yes HAVE_SLN=yes

    make HAVE_KILL=yes HAVE_SLN=yes install
    mv /usr/bin/logger /bin

#   ----
    cd /sources
    rm -rf util-linux-2.12q
}

# About Debugging Symbols
function chapter06-aboutdebug ()
{
    echo "chapter06-aboutdebug"
#   ----

#   ----
}

# Stripping Again
function chapter06-strippingagain ()
{
    echo "chapter06-strippingagain"
#   ----

#   logout

#   chroot $LFS /tools/bin/env -i \
#       HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
#       PATH=/bin:/usr/bin:/sbin:/usr/sbin \
#       /tools/bin/bash --login

    set +e

    /tools/bin/find /{,usr/}{bin,lib,sbin} -type f \
       -exec /tools/bin/strip --strip-debug '{}' ';'

    set -e

#   ----
}

# Cleaning Up
function chapter06-revisedchroot ()
{
    echo "chapter06-revisedchroot"
#   ----

#   chroot "$LFS" /usr/bin/env -i \
#       HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
#       PATH=/bin:/usr/bin:/sbin:/usr/sbin \
#       /bin/bash --login

    rm -rf /tools

#   ----
}

# Introduction
function chapter07-introduction ()
{
    echo "chapter07-introduction"
#   ----

#   ----
}

# LFS-Bootscripts-3.2.1
function chapter07-bootscripts ()
{
    echo "chapter07-bootscripts"
    cd /sources
    tar -jxf lfs-bootscripts-3.2.1.tar.bz2
    cd lfs-bootscripts-3.2.1
#   ----

    make install

#   ----
    cd /sources
    rm -rf lfs-bootscripts-3.2.1
}

# How Do These Bootscripts Work?
function chapter07-usage ()
{
    echo "chapter07-usage"
#   ----

#   ----
}

# Device and Module Handling on an LFS System
function chapter07-udev ()
{
    echo "chapter07-udev"
#   ----

#   install snd-pcm modprobe -i snd-pcm ; modprobe \
#       snd-pcm-oss ; true

#   ----
}

# Configuring the setclock Script
function chapter07-setclock ()
{
    echo "chapter07-setclock"
#   ----

    cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock

UTC=1

# End /etc/sysconfig/clock
EOF

#   ----
}

# Configuring the Linux Console
function chapter07-console ()
{
    echo "chapter07-console"
#   ----

    cat >/etc/sysconfig/console <<"EOF"
KEYMAP="[arguments for loadkeys]"
FONT="[arguments for setfont]"
EOF

#   cat >/etc/sysconfig/console <<"EOF"
#KEYMAP="es euro2"
#FONT="lat9-16 -u iso01"
#EOF

#   FONT="lat1-16"

#   zgrep '\W14\W' [/path/to/your/keymap]

#   mkdir -pv /etc/kbd && cat > /etc/kbd/bs-sends-del <<"EOF"
#                  keycode  14 = Delete Delete Delete Delete
#              alt keycode  14 = Meta_Delete
#        altgr alt keycode  14 = Meta_Delete
#                  keycode 111 = Remove
#    altgr control keycode 111 = Boot
#      control alt keycode 111 = Boot
#altgr control alt keycode 111 = Boot
# EOF

#   cat >>/etc/sysconfig/console <<"EOF"
#KEYMAP_CORRECTIONS="/etc/kbd/bs-sends-del"
#EOF

#   ----
}

# Configuring the sysklogd script
function chapter07-sysklogd ()
{
    echo "chapter07-sysklogd"
#   ----

#   ----
}

# Creating the /etc/inputrc File
function chapter07-inputrc ()
{
    echo "chapter07-inputrc"
#   ----

    cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <roryo@roryo.dynup.net>

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the
# value contained inside the 1st argument to the
# readline specific functions

"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF

#   ----
}

# The Bash Shell Startup Files
function chapter07-profile ()
{
    echo "chapter07-profile"
#   ----

#   locale -a

#   LC_ALL=[locale name] locale charmap

#   LC_ALL=[locale name] locale country
#   LC_ALL=[locale name] locale language
#   LC_ALL=[locale name] locale charmap
#   LC_ALL=[locale name] locale int_curr_symbol
#   LC_ALL=[locale name] locale int_prefix

    cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=[ll]_[CC].[charmap]
export INPUTRC=/etc/inputrc

# End /etc/profile
EOF

#   ----
}

# Configuring the localnet Script
function chapter07-hostname ()
{
    echo "chapter07-hostname"
#   ----

echo "HOSTNAME=[lfs]" > /etc/sysconfig/network

#   ----
}

# Creating the /etc/hosts File
function chapter07-hosts ()
{
    echo "chapter07-hosts"
#   ----

    cat > /etc/hosts << "EOF"
# Begin /etc/hosts (network card version)

127.0.0.1 localhost
[192.168.1.1] [<HOSTNAME>.example.org] [HOSTNAME]

# End /etc/hosts (network card version)
EOF

#   cat > /etc/hosts << "EOF"
## Begin /etc/hosts (no network card version)
#   
#127.0.0.1 [<HOSTNAME>.example.org] [HOSTNAME] localhost
#   
## End /etc/hosts (no network card version)
#EOF

#   ----
}

# Configuring the network Script
function chapter07-network ()
{
    echo "chapter07-network"
#   ----

    cd /etc/sysconfig/network-devices &&
    mkdir -v ifconfig.eth0 &&
    cat > ifconfig.eth0/ipv4 << "EOF"
ONBOOT=yes
SERVICE=ipv4-static
IP=192.168.1.1
GATEWAY=192.168.1.2
PREFIX=24
BROADCAST=192.168.1.255
EOF

    cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

domain {[Your Domain Name]}
nameserver [IP address of your primary nameserver]
nameserver [IP address of your secondary nameserver]

# End /etc/resolv.conf
EOF

#   ----
}

# Introduction
function chapter08-introduction ()
{
    echo "chapter08-introduction"
#   ----

#   ----
}

# Creating the /etc/fstab File
function chapter08-fstab ()
{
    echo "chapter08-fstab"
#   ----

    cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point  type   options         dump  fsck
#                                                        order

/dev/[xxx]     /            [fff]  defaults        1     1
/dev/[yyy]     swap         swap   pri=1           0     0
proc           /proc        proc   defaults        0     0
sysfs          /sys         sysfs  defaults        0     0
devpts         /dev/pts     devpts gid=4,mode=620  0     0
shm            /dev/shm     tmpfs  defaults        0     0
# End /etc/fstab
EOF

#   ----
}

# Linux-2.6.11.12
function chapter08-kernel ()
{
    echo "chapter08-kernel"
    cd /sources
    tar -jxf linux-2.6.11.12.tar.bz2
    cd linux-2.6.11.12
#   ----

    make mrproper

   loadkeys -m /usr/share/kbd/keymaps/[path to  keymap] > \
       drivers/char/defkeymap.c

#   make menuconfig
    cp ../lfs-kernel-[kernel version].cfg .config
    make oldconfig

    make

    make modules_install

    cp -v arch/i386/boot/bzImage /boot/lfskernel-2.6.11.12

    cp -v System.map /boot/System.map-2.6.11.12

    cp -v .config /boot/config-2.6.11.12

#   ----
    cd /sources
    rm -rf linux-2.6.11.12
}

# Making the LFS System Bootable
function chapter08-grub ()
{
    echo "chapter08-grub"
#   ----

#dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1
#dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1

#grub

#root (hd0,3)

#setup (hd0)

#quit

    cat > /boot/grub/menu.lst << "EOF"
# Begin /boot/grub/menu.lst

# By default boot the first menu entry.
default 0

# Allow 30 seconds before booting the default.
timeout 30

# Use prettier colors.
color green/black light-green/black

# The first entry is for LFS.
title LFS 6.1.1
root (hd0,3)
kernel /boot/lfskernel-2.6.11.12 root=/dev/hda4
EOF

#   cat >> /boot/grub/menu.lst << "EOF"
#title Red Hat
#root (hd0,2)
#kernel /boot/kernel-2.6.5 root=/dev/hda3
#initrd /boot/initrd-2.6.5
#EOF

#   cat >> /boot/grub/menu.lst << "EOF"
#title Windows
#rootnoverify (hd0,0)
#chainloader +1
#EOF

    mkdir -v /etc/grub &&
    ln -sv /boot/grub/menu.lst /etc/grub

#   ----
}

# The End
function chapter09-theend ()
{
    echo "chapter09-theend"
#   ----

    echo 6.1.1 > /etc/lfs-release

#   ----
}

# Get Counted
function chapter09-getcounted ()
{
    echo "chapter09-getcounted"
#   ----

#   ----
}

# Rebooting the System
function chapter09-reboot ()
{
    echo "chapter09-reboot"
#   ----

#   logout

    umount -v $LFS/dev/pts
    umount -v $LFS/dev/shm
    umount -v $LFS/dev
    umount -v $LFS/proc
    umount -v $LFS/sys

#   umount -v $LFS

#   umount -v $LFS/usr
#   umount -v $LFS/home
#   umount -v $LFS

#   shutdown -r now

#   ----
}

# What Now?
function chapter09-whatnow ()
{
    echo "chapter09-whatnow"
#   ----

#   ----
}

# Preface
function prologue ()
{
    prologue-foreword
    prologue-audience
    prologue-prerequisites
    prologue-hostreqs
    prologue-typography
    prologue-organization
    prologue-errata
}

# Introduction
function chapter01 ()
{
    chapter01-how
    chapter01-changelog
    chapter01-resources
    chapter01-askforhelp
}

# Preparing a New Partition
function chapter02 ()
{
    chapter02-introduction
    chapter02-creatingpartition
    chapter02-creatingfilesystem
    chapter02-mounting
}

# Packages and Patches
function chapter03 ()
{
    chapter03-introduction
    chapter03-packages
    chapter03-patches
}

# Final Preparations
function chapter04 ()
{
    chapter04-aboutlfs
    chapter04-creatingtoolsdir
    chapter04-addinguser
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-settingenvironment"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-aboutsbus"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs     chapter04-abouttestsuites"
}

# Constructing a Temporary System
function chapter05 ()
{
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-introduction"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-toolchaintechnotes"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-binutils-pass1"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gcc-pass1"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-linux-libc-headers"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-glibc"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-adjusting"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-tcl"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-expect"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-dejagnu"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gcc-pass2"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-binutils-pass2"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gawk"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-coreutils"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-bzip2"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gzip"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-diffutils"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-findutils"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-make"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-grep"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-sed"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-gettext"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-ncurses"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-patch"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-tar"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-texinfo"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-bash"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-m4"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-bison"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-flex"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-util-linux"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-perl"
    su - lfs -c "source ~/.bashrc; $LFS/sources/afs chapter05-stripping"
}

# Installing Basic System Software
function chapter06 ()
{
     CHRTLFS="chroot $LFS /tools/bin/env -i HOME=/root \
       PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
       /tools/bin/bash --login "

    chapter06-introduction
    chapter06-kernfs
    chapter06-chroot

    $CHRTLFS /sources/afs chapter06-changingowner
    $CHRTLFS /sources/afs chapter06-creatingdirs
    $CHRTLFS /sources/afs chapter06-createfiles
    $CHRTLFS /sources/afs chapter06-pwdgroup
    $CHRTLFS /sources/afs chapter06-devices
    $CHRTLFS /sources/afs chapter06-linux-libc-headers
    $CHRTLFS /sources/afs chapter06-man-pages
    $CHRTLFS /sources/afs chapter06-glibc
    $CHRTLFS /sources/afs chapter06-readjusting
    $CHRTLFS /sources/afs chapter06-binutils
    $CHRTLFS /sources/afs chapter06-gcc
    $CHRTLFS /sources/afs chapter06-coreutils
    $CHRTLFS /sources/afs chapter06-zlib
    $CHRTLFS /sources/afs chapter06-mktemp
    $CHRTLFS /sources/afs chapter06-iana-etc
    $CHRTLFS /sources/afs chapter06-findutils
    $CHRTLFS /sources/afs chapter06-gawk
    $CHRTLFS /sources/afs chapter06-ncurses
    $CHRTLFS /sources/afs chapter06-readline
    $CHRTLFS /sources/afs chapter06-vim
    $CHRTLFS /sources/afs chapter06-m4
    $CHRTLFS /sources/afs chapter06-bison
    $CHRTLFS /sources/afs chapter06-less
    $CHRTLFS /sources/afs chapter06-groff
    $CHRTLFS /sources/afs chapter06-sed
    $CHRTLFS /sources/afs chapter06-flex
    $CHRTLFS /sources/afs chapter06-gettext
    $CHRTLFS /sources/afs chapter06-inetutils
    $CHRTLFS /sources/afs chapter06-iproute2
    $CHRTLFS /sources/afs chapter06-perl
    $CHRTLFS /sources/afs chapter06-texinfo
    $CHRTLFS /sources/afs chapter06-autoconf
    $CHRTLFS /sources/afs chapter06-automake
    $CHRTLFS /sources/afs chapter06-bash
    $CHRTLFS /sources/afs chapter06-file
    $CHRTLFS /sources/afs chapter06-libtool
    $CHRTLFS /sources/afs chapter06-bzip2
    $CHRTLFS /sources/afs chapter06-diffutils
    $CHRTLFS /sources/afs chapter06-kbd
    $CHRTLFS /sources/afs chapter06-e2fsprogs
    $CHRTLFS /sources/afs chapter06-grep
    $CHRTLFS /sources/afs chapter06-grub
    $CHRTLFS /sources/afs chapter06-gzip
    $CHRTLFS /sources/afs chapter06-hotplug
    $CHRTLFS /sources/afs chapter06-man
    $CHRTLFS /sources/afs chapter06-make
    $CHRTLFS /sources/afs chapter06-module-init-tools
    $CHRTLFS /sources/afs chapter06-patch
    $CHRTLFS /sources/afs chapter06-procps
    $CHRTLFS /sources/afs chapter06-psmisc
    $CHRTLFS /sources/afs chapter06-shadow
    $CHRTLFS /sources/afs chapter06-sysklogd
    $CHRTLFS /sources/afs chapter06-sysvinit
    $CHRTLFS /sources/afs chapter06-tar
    $CHRTLFS /sources/afs chapter06-udev
    $CHRTLFS /sources/afs chapter06-util-linux
    $CHRTLFS /sources/afs chapter06-aboutdebug

    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /tools/bin/bash --login "

    $CHRT /sources/afs chapter06-strippingagain

    chapter06-revisedchroot
}

# Setting Up System Bootscripts
function chapter07 ()
{
    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /tools/bin/bash --login "

    $CHRT /sources/afs chapter07-introduction
    $CHRT /sources/afs chapter07-bootscripts
    $CHRT /sources/afs chapter07-usage
    $CHRT /sources/afs chapter07-udev
    $CHRT /sources/afs chapter07-setclock
    $CHRT /sources/afs chapter07-console
    $CHRT /sources/afs chapter07-sysklogd
    $CHRT /sources/afs chapter07-inputrc
    $CHRT /sources/afs chapter07-profile
    $CHRT /sources/afs chapter07-hostname
    $CHRT /sources/afs chapter07-hosts
    $CHRT /sources/afs chapter07-network
}

# Making the LFS System Bootable
function chapter08 ()
{
    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
       /tools/bin/bash --login "

    $CHRT /sources/afs chapter08-introduction
    $CHRT /sources/afs chapter08-fstab
    $CHRT /sources/afs chapter08-kernel
    $CHRT /sources/afs chapter08-grub
}

# The End
function chapter09 ()
{
    CHRT="chroot $LFS /tools/bin/env -i HOME=/root \
        PATH=/bin:/usr/bin:/sbin:/usr/sbin \
        /tools/bin/bash --login "

    $CHRT /sources/afs chapter09-theend
    $CHRT /sources/afs chapter09-getcounted

    chapter09-reboot
    chapter09-whatnow
}

# Linux From Scratch Version 6.1.1
function lfs ()
{
    prologue
    chapter01
    chapter02
    chapter03
    chapter04
    chapter05
    chapter06
    chapter07
    chapter08
    chapter09
}


if ! test -z "$1"
then
    $1
    exit
fi

lfs

#End afs (Automation From Scratch) - Linux From Scratch Version 6.1.1

Appendix C. AFS XSL stylesheet

The AFS XSL stylesheet to extract a AFS script template from the Linux From Scratch 6.1.1 Book's XML files. The XSL stylesheet may with no or very little change be used for other versions of Linux From Scratch. Copy to the file afs.xsl.

<?xml version="1.0"?>
<!DOCTYPE doc [
  <!ENTITY % general-entities SYSTEM "../general.ent">
  %general-entities;
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    extension-element-prefixes="exsl"
    version="1.0">

 <xsl:output method = "text"/>

<!-- XSLT stylesheet to extract commands from LFS books. -->

    <xsl:template match="/">
        <!-- script header/comment -->
        <xsl:text>#!/bin/bash&#xA;</xsl:text>
        <xsl:text>#Begin afs (Automation From Scratch) - </xsl:text>
        <xsl:value-of select="/book/bookinfo/title"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="/book/bookinfo/subtitle"/>
        <xsl:text>&#xA;</xsl:text>

        <!-- script environment setting and variables -->
        <xsl:text>&#xA;</xsl:text>
        <xsl:text># Set global environment settings and variables.&#xA;</xsl:text>
        <xsl:text>set -e +h&#xA;</xsl:text>
        <xsl:text>umask 022&#xA;</xsl:text>
        <xsl:text>&#xA;</xsl:text>

        <xsl:text># The all knowing LFS variable.&#xA;</xsl:text>
        <xsl:text>export LFS=/mnt/lfs&#xA;</xsl:text>

        <xsl:text>&#xA;</xsl:text>
        <xsl:text>&#xA;</xsl:text>

        <!-- definitions of section functions -->
        <xsl:apply-templates select="//sect1"/>

        <!-- definitions of preface and chapter functions -->
        <xsl:apply-templates select="/book/preface" mode="chapters"/>
        <xsl:apply-templates select="/book/part/chapter" mode="chapters"/>

        <xsl:text>&#xA;</xsl:text>

        <!-- definition of lfs function -->
        <xsl:text># </xsl:text>
        <xsl:value-of select="/book/bookinfo/title"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="/book/bookinfo/subtitle"/>
        <xsl:text>&#xA;</xsl:text>

        <xsl:text>function lfs ()&#xA;</xsl:text>
        <xsl:text>{&#xA;</xsl:text>
        <xsl:apply-templates select="/book/preface|/book/part/chapter" mode="lfs"/>
        <xsl:text>}&#xA;</xsl:text>

        <xsl:text>&#xA;</xsl:text>
        <xsl:text>&#xA;</xsl:text>

        <!-- main -->
        <xsl:text>if ! test -z "$1"&#xA;</xsl:text>
        <xsl:text>then&#xA;</xsl:text>
        <xsl:text>    $1&#xA;</xsl:text>
        <xsl:text>    exit&#xA;</xsl:text>
        <xsl:text>fi&#xA;</xsl:text>
        <xsl:text>&#xA;</xsl:text>
        <xsl:text>lfs&#xA;</xsl:text>

        <!-- ending comment -->
        <xsl:text>&#xA;</xsl:text>
        <xsl:text>#End afs (Automation From Scratch) - </xsl:text>
        <xsl:value-of select="/book/bookinfo/title"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="/book/bookinfo/subtitle"/>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>

    <xsl:template match="sect1">
        <!-- The dirs names -->
        <xsl:variable name="pi-dir" select="../processing-instruction('dbhtml')"/>
        <xsl:variable name="pi-dir-value" select="substring-after($pi-dir,'dir=')"/>
        <xsl:variable name="quote-dir" select="substring($pi-dir-value,1,1)"/>
        <xsl:variable name="dirname" select="substring-before(substring($pi-dir-value,2),$quote-dir)"/>
        <!-- The file names -->
        <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
        <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
        <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>

        <!-- section comment -->
        <xsl:text>&#xA;</xsl:text>
        <xsl:text># </xsl:text>
        <xsl:value-of select="title"/>
        <xsl:text>&#xA;</xsl:text>

        <!-- section function -->
        <xsl:text>function </xsl:text>
        <xsl:value-of select="$dirname"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="$filename"/>
        <xsl:text> ()&#xA;</xsl:text>
        <xsl:text>{&#xA;</xsl:text>
        <xsl:text>    echo "</xsl:text>
        <xsl:value-of select="$dirname"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="$filename"/>
        <xsl:text>"&#xA;</xsl:text>

        <xsl:if test="sect2[@role='package']">
            <xsl:text>    cd [</xsl:text>
            <xsl:value-of select="$dirname"/>
            <xsl:text> source directory]&#xA;</xsl:text>
            <xsl:text>    tar -jxf </xsl:text>
            <xsl:text>[</xsl:text>
            <xsl:value-of select="title"/>
            <xsl:text>]</xsl:text>
            <xsl:text>.tar.bz2&#xA;</xsl:text>
            <xsl:text>    cd </xsl:text>
            <xsl:text>[</xsl:text>
            <xsl:value-of select="title"/>
            <xsl:text> source directory]</xsl:text>
            <xsl:text>&#xA;</xsl:text>
        </xsl:if>
        <xsl:text>#   ----&#xA;</xsl:text>

        <xsl:apply-templates select=".//screen"/>

        <xsl:text>&#xA;</xsl:text>
        <xsl:text>#   ----&#xA;</xsl:text>

        <xsl:if test="sect2[@role='package']">
            <xsl:text>    cd [</xsl:text>
            <xsl:value-of select="$dirname"/>
            <xsl:text> source directory]&#xA;</xsl:text>
            <xsl:text>    rm -rf </xsl:text>
            <xsl:text>[</xsl:text>
            <xsl:value-of select="title"/>
            <xsl:text> source directory]</xsl:text>
            <xsl:text>&#xA;</xsl:text>
        </xsl:if>
        <xsl:text>}&#xA;</xsl:text>

    </xsl:template>

    <xsl:template match="screen">
        <xsl:if test="child::* = userinput">
            <xsl:text></xsl:text>
            <xsl:apply-templates select="userinput"/>
        </xsl:if>
    </xsl:template>

    <xsl:template match="userinput">
        <xsl:text>&#xA;</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>

    <!-- preface and chapters functions -->
    <xsl:template match="preface|chapter" mode="chapters">
        <!-- The dirs name -->
        <xsl:variable name="pi-dir" select="processing-instruction('dbhtml')"/>
        <xsl:variable name="pi-dir-value" select="substring-after($pi-dir,'dir=')"/>
        <xsl:variable name="quote-dir" select="substring($pi-dir-value,1,1)"/>
        <xsl:variable name="dirname" select="substring-before(substring($pi-dir-value,2),$quote-dir)"/>

        <xsl:text>&#xA;</xsl:text>

        <xsl:text># </xsl:text>
        <xsl:value-of select="title"/>
        <xsl:text>&#xA;</xsl:text>

        <xsl:text>function </xsl:text>
        <xsl:value-of select="$dirname"/>
        <xsl:text> ()</xsl:text>
        <xsl:text>&#xA;</xsl:text>
        <xsl:text>{</xsl:text>
        <xsl:text>&#xA;</xsl:text>

        <xsl:for-each select="sect1">
            <!-- The file name -->
            <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
            <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
            <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>

            <xsl:text>    </xsl:text>
            <xsl:value-of select="$dirname"/>
            <xsl:text>-</xsl:text>
            <xsl:value-of select="$filename"/>
            <xsl:text>&#xA;</xsl:text>
        </xsl:for-each>

        <xsl:text>}</xsl:text>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>

    <!-- lfs function -->
    <xsl:template match="preface|chapter" mode="lfs">
        <!-- The dirs name -->
        <xsl:variable name="pi-dir" select="processing-instruction('dbhtml')"/>
        <xsl:variable name="pi-dir-value" select="substring-after($pi-dir,'dir=')"/>
        <xsl:variable name="quote-dir" select="substring($pi-dir-value,1,1)"/>
        <xsl:variable name="dirname" select="substring-before(substring($pi-dir-value,2),$quote-dir)"/>

        <xsl:text>    </xsl:text>
        <xsl:value-of select="$dirname"/>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>
</xsl:stylesheet>