source: BOOK/final-preps/common/settingenviron.xml @ 1552c51

Last change on this file since 1552c51 was 1552c51, checked in by William Harrington <kb0iic@…>, 7 years ago

Some hosts may set PKG_CONFIG_PATH in /etc/profile or /etc/profile.d and will be used after 'su - clfs'. Unset PKG_CONFIG_PATH variable will make sure only pkgconfig in /tools will be used and no packages will be picked up from the host i.e. guile or ncursesw.

  • Property mode set to 100644
File size: 4.6 KB
[3f8be484]1<?xml version="1.0" encoding="ISO-8859-1"?>
[aa18ac0]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3  "" [
[5585711]4  <!ENTITY % general-entities SYSTEM "../../general.ent">
[3f8be484]5  %general-entities;
8<sect1 id="ch-final-preps-settingenviron">
9  <?dbhtml filename="settingenvironment.html"?>
11  <title>Setting Up the Environment</title>
[cedcdaa]13  <para os="a">Set up a good working environment by creating two new startup
[3f8be484]14  files for the <command>bash</command> shell. While logged in as user
[95112ed]15  <systemitem class="username">clfs</systemitem>, issue the following
[3f8be484]16  command to create a new <filename>.bash_profile</filename>:</para>
[cedcdaa]18<screen os="b"><userinput>cat &gt; ~/.bash_profile &lt;&lt; "EOF"
[040521bc]19<literal>exec env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$ ' /bin/bash</literal>
[95112ed]22  <para os="c">When logged on as user <systemitem class="username">clfs</systemitem>,
[3f8be484]23  the initial shell is usually a <emphasis>login</emphasis> shell which
24  reads the <filename>/etc/profile</filename> of the host (probably
25  containing some settings and environment variables) and then
26  <filename>.bash_profile</filename>. The
27  <command>exec env -i.../bin/bash</command> command in the
28  <filename>.bash_profile</filename> file replaces the running shell with
29  a new one with a completely empty environment, except for the
30  <envar>HOME</envar>, <envar>TERM</envar>, and <envar>PS1</envar> variables.
31  This ensures that no unwanted and potentially hazardous environment
32  variables from the host system leak into the build environment. The
33  technique used here achieves the goal of ensuring a clean environment.</para>
[cedcdaa]35  <para os="d">The new instance of the shell is a <emphasis>non-login</emphasis>
[3f8be484]36  shell, which does not read the <filename>/etc/profile</filename> or
37  <filename>.bash_profile</filename> files, but rather reads the
38  <filename>.bashrc</filename> file instead. Create the
39  <filename>.bashrc</filename> file now:</para>
[cedcdaa]41<screen os="e"><userinput>cat &gt; ~/.bashrc &lt;&lt; "EOF"
[3f8be484]42<literal>set +h
43umask 022
[1a24f05]47export CLFS LC_ALL PATH
[1552c51]48unset CFLAGS CXXFLAGS PKG_CONFIG_PATH</literal>
[307e31eb]51  <para os="f">The <command>set +h</command> command turns off
[3f8be484]52  <command>bash</command>'s hash function. Hashing is ordinarily a useful
53  feature&mdash;<command>bash</command> uses a hash table to remember the
54  full path of executable files to avoid searching the <envar>PATH</envar>
55  time and again to find the same executable. However, the new tools should
56  be used as soon as they are installed. By switching off the hash function,
57  the shell will always search the <envar>PATH</envar> when a program is to
58  be run. As such, the shell will find the newly compiled tools in
[bc2e3fa]59  <filename class="directory">/cross-tools</filename> as soon as they are
[3f8be484]60  available without remembering a previous version of the same program in a
61  different location.</para>
[cedcdaa]63  <para os="g">Setting the user file-creation mask (umask) to 022 ensures that
[3f8be484]64  newly created files and directories are only writable by their owner,
65  but are readable and executable by anyone (assuming default modes are
66  used by the open(2) system call, new files will end up with permission
67  mode 644 and directories with mode 755).</para>
[95112ed]69  <para os="h">The <envar>CLFS</envar> variable should be set to the
[3f8be484]70  chosen mount point.</para>
[a266616]72  <para os="i">The <envar>LC_ALL</envar> variable controls the localization
73  of certain programs, making their messages follow the conventions of a
[cb50526]74  specified country. Setting <envar>LC_ALL</envar> to <quote>POSIX</quote>
75  or <quote>C</quote> (the two are equivalent) ensures that everything will
76  work as expected in the temporary build environment.</para>
[bc2e3fa]78  <para os="j">By putting <filename class="directory">/cross-tools/bin</filename>
[e97d7d3]79  at the beginning of the <envar>PATH</envar>, the cross-compiler
80  built in <xref linkend="chapter-cross-tools"/> will be picked up by
81  the build process for the temp-system packages before anything that
82  may be installed on the host. This, combined with turning off
83  hashing, helps to ensure that you will be using the cross-compile
[bc2e3fa]84  tools to build the temp-system in /tools.</para>
[1552c51]86  <para os="k">The <envar>CFLAGS</envar>, <envar>CXXFLAGS</envar> and
87  <envar>PKG_CONFIG_PATH</envar> variables should not be set while building the
88  temporary system, so we unset them.</para>
90  <para os="l">Finally, to have the environment fully prepared for building the
[3f8be484]91  temporary tools, source the just-created user profile:</para>
[1a24f05]93<screen os="m"><userinput>source ~/.bash_profile</userinput></screen>
Note: See TracBrowser for help on using the repository browser.