3.2. Setting Up the Environment

export ${CLFS}=/mnt/clfs

To ensure a clean separation between host and build environments we will create a custom .bashrc file. This file will be read when invoking a non-login instance of bash.

The new instance of the shell is a non-login shell, which does not read the /etc/profile or .bash_profile files, but rather reads the .bashrc file instead. Create the .bashrc file now:

cat > ${CLFS}/.bashrc << "EOF"
set +h
umask 022
CLFS=/mnt/clfs
HOME=/mnt/clfs
PS1='clfs-\u:\w\$ '
LC_ALL=POSIX
PATH=${CLFS}/cross-tools/bin:/bin:/usr/bin
export CLFS LC_ALL PATH
EOF

The set +h command turns off bash's hash function. Hashing is ordinarily a useful feature—bash uses a hash table to remember the full path of executable files to avoid searching the PATH time and again to find the same executable. However, the new tools should be used as soon as they are installed. By switching off the hash function, the shell will always search the PATH when a program is to be run. As such, the shell will find the newly compiled tools in ${CLFS}/cross-tools as soon as they are available without remembering a previous version of the same program in a different location.

Setting the user file-creation mask (umask) to 022 ensures that newly created files and directories are only writable by their owner, but are readable and executable by anyone (assuming default modes are used by the open(2) system call, new files will end up with permission mode 644 and directories with mode 755).

The CLFS variable should be set to the chosen mount point.

The LC_ALL variable controls the localization of certain programs, making their messages follow the conventions of a specified country. If the host system uses a version of Glibc older than 2.2.4, having LC_ALL set to something other than “POSIX” or “C” (during this chapter) may cause issues if you exit the chroot environment and wish to return later. Setting LC_ALL to “POSIX” or “C” (the two are equivalent) ensures that everything will work as expected in the chroot environment.

By putting ${CLFS}/cross-tools/bin at the beginning of the PATH, the cross-compiler built in Constructing Cross-Compile Tools will be picked up by the build process for the temp-system packages before anything that may be installed on the host. This, combined with turning off hashing, helps to ensure that you will be using the cross-compile tools to build the temp-system in /tools.

Finally, to have the environment fully prepared for building the temporary tools, source the just-created user profile:

 
To access the special environment launch the bash shell as follows: 
    export CLFS=/mnt/clfs; bash --rcfile ${CLFS}/.bashrc 
    
To use this environment in a shell script do as follows:    
    export CLFS=/mnt/clfs ; source ${CLFS}/.bashrc
 
The following script will make it easier to open a shell with the desired environment:

cat > ${CLFS}/launch.sh << "EOF"
#!/bin/sh

bash --rcfile `dirname $0`/.bashrc
EOF

chmod +x ${CLFS}/launch.sh