Those people who have built an LFS system may be aware of the general principles of downloading and unpacking software. Some of that information is repeated here for those new to building their own software.
Each set of installation instructions contains a URL from which you can download the package. The patches; however, are stored on the LFS servers and are available via HTTP. These are referenced as needed in the installation instructions.
While you can keep the source files anywhere you like, we assume that you have unpacked the package and changed into the directory created by the unpacking process (the 'build' directory). We also assume you have uncompressed any required patches and they are in the directory immediately above the 'build' directory.
We can not emphasize strongly enough that you should start from a
clean source tree each time.
This means that if you have had an error during configuration or
compilation, it's usually best to delete the source tree and
re-unpack it before trying
again. This obviously doesn't apply if you're an advanced user used
to hacking Makefiles and C code, but if
in doubt, start from a clean tree.
The golden rule of Unix System Administration is to use your
superpowers only when necessary. Hence, BLFS recommends that you
build software as an unprivileged user and only become the
root user when installing the
software. This philosophy is followed in all the packages in this
book. Unless otherwise specified, all instructions should be
executed as an unprivileged user. The book will advise you on
instructions that need root
privileges.
If a file is in .tar format and
compressed, it is unpacked by running one of the following
commands:
tar -xvf filename.tar.gz tar -xvf filename.tgz tar -xvf filename.tar.Z tar -xvf filename.tar.bz2
You may omit using the v parameter in
the commands shown above and below if you wish to suppress the
verbose listing of all the files in the archive as they are
extracted. This can help speed up the extraction as well as make
any errors produced during the extraction more obvious to you.
You can also use a slightly different method:
bzcat filename.tar.bz2 | tar -xv
Finally, you sometimes need to be able to unpack patches which are
generally not in .tar format. The
best way to do this is to copy the patch file to the parent of the
'build' directory and then run one of the following commands
depending on whether the file is a .gz or .bz2 file:
gunzip -v patchname.gz bunzip2 -v patchname.bz2
Generally, to verify that the downloaded file is genuine and
complete, many package maintainers also distribute md5sums of the
files. To verify the md5sum of the downloaded files, download both
the file and the corresponding md5sum file to the same directory
(preferably from different on-line locations), and (assuming
file.md5sum is the md5sum file
downloaded) run the following command:
md5sum -c file.md5sum
If there are any errors, they will be reported. Note that the BLFS
book includes md5sums for all the source files also. To use the
BLFS supplied md5sums, you can create a file.md5sum (place the md5sum data and the exact
name of the downloaded file on the same line of a file, separated
by white space) and run the command shown above. Alternately,
simply run the command shown below and compare the output to the
md5sum data shown in the BLFS book.
md5sum <name_of_downloaded_file>
For larger packages, it is convenient to create log files instead
of staring at the screen hoping to catch a particular error or
warning. Log files are also useful for debugging and keeping
records. The following command allows you to create an installation
log. Replace <command> with the command
you intend to execute.
( <command> 2>&1 | tee compile.log && exit $PIPESTATUS )
2>&1 redirects error messages to
the same location as standard output. The tee command allows viewing of the
output while logging the results to a file. The parentheses around
the command run the entire command in a subshell and finally the
exit $PIPESTATUS
command ensures the result of the <command> is returned as the
result and not the result of the tee command.
For many modern systems with multiple processors (or cores) the compilation time for a package can be reduced by performing a "parallel make" by either setting an environment variable or telling the make program how many processors are available. For instance, a Core2Duo can support two simultaneous processes with:
export MAKEFLAGS='-j2'
or just building with:
make -j2
Generally the number of processes should not exceed the number of
cores supported by the CPU. To list the processors on your system,
issue: grep processor
/proc/cpuinfo.
In some cases, using multiple processors may result in a 'race' condition where the success of the build depends on the order of the commands run by the make program. For instance, if an executable needs File A and File B, attempting to link the program before one of the dependent components is available will result in a failure. This condition usually arises because the upstream developer has not properly designated all the prerequsites needed to accomplish a step in the Makefile.
If this occurs, the best way to proceed is to drop back to a single processor build. Adding '-j1' to a make command will override the similar setting in the MAKEFLAGS environment variable.
When running the package tests or the install portion of the package build process, we do not recommend using an option greater than '-j1' unless specified otherwise. The installation procedures or checks have not been validated using parallel procedures and may fail with issues that are difficult to debug.
There are times when automating the building of a package can come
in handy. Everyone has their own reasons for wanting to automate
building, and everyone goes about it in their own way. Creating
Makefiles, Bash scripts, Perl scripts or simply a list of commands used
to cut and paste are just some of the methods you can use to
automate building BLFS packages. Detailing how and providing
examples of the many ways you can automate the building of packages
is beyond the scope of this section. This section will expose you
to using file redirection and the yes command to help provide ideas
on how to automate your builds.
You will find times throughout your BLFS journey when you will come across a package that has a command prompting you for information. This information might be configuration details, a directory path, or a response to a license agreement. This can present a challenge to automate the building of that package. Occasionally, you will be prompted for different information in a series of questions. One method to automate this type of scenario requires putting the desired responses in a file and using redirection so that the program uses the data in the file as the answers to the questions.
Building the CUPS package is a good example of how redirecting a file as input to prompts can help you automate the build. If you run the test suite, you are asked to respond to a series of questions regarding the type of test to run and if you have any auxiliary programs the test can use. You can create a file with your responses, one response per line, and use a command similar to the one shown below to automate running the test suite:
make check < ../cups-1.1.23-testsuite_parms
This effectively makes the test suite use the responses in the file as the input to the questions. Occasionally you may end up doing a bit of trial and error determining the exact format of your input file for some things, but once figured out and documented you can use this to automate building the package.
Sometimes you will only need to provide one response, or provide the same response to many prompts. For these instances, the yes command works really well. The yes command can be used to provide a response (the same one) to one or more instances of questions. It can be used to simulate pressing just the Enter key, entering the Y key or entering a string of text. Perhaps the easiest way to show its use is in an example.
First, create a short Bash script by entering the following commands:
cat > blfs-yes-test1 << "EOF"
#!/bin/bash
echo -n -e "\n\nPlease type something (or nothing) and press Enter ---> "
read A_STRING
if test "$A_STRING" = ""; then A_STRING="Just the Enter key was pressed"
else A_STRING="You entered '$A_STRING'"
fi
echo -e "\n\n$A_STRING\n\n"
EOF
chmod 755 blfs-yes-test1
Now run the script by issuing ./blfs-yes-test1 from the command line. It will wait for a response, which can be anything (or nothing) followed by the Enter key. After entering something, the result will be echoed to the screen. Now use the yes command to automate the entering of a response:
yes | .