The very first task is to set up a sane environment in which to perform the build. These environmental settings apply to the initial Temptools phase, though most will also be carried through into the Chroot phase. But first, a lesson that many folks have learned the hard way:
Caution - Never build the Temptools phase as root! | |
---|---|
There is a government advertising campaign here in Australia that goes something like "If you drink and drive... you're a bloody idiot". Well, the same thing applies to building the Temptools phase as root. Never do it. The risk of trashing your host system is too great. |
Create a specific user and group in which to perform the build of the Temptools phase. Let's call them something creative like `build'. As root:
groupadd build useradd -s /bin/bash -g build -m -k /dev/null build passwd build
Decide where you want to build and install the system to. This doesn't have to be a partition, it can be anywhere, under $HOME, /mnt, /tmp or wherever you like, as long as there is plenty of space there (FIXME how much?). The location you've chosen to build the system will be assigned to the $SYSROOT variable below. Once the build has finished, the entire root file system image may be transferred to its intended final destination.
The following steps are taken to ensure a sane shell environment in which to work in. Your build script should, in practice, inherit these settings but it would be wise to at least sanity check the variables yourself when writing your script. Now login as user `build' and create the needed bash startup files and config.site. Then source the files:
Important | |
---|---|
Be sure to substitute the location you've chosen for the build in the $SYSROOT variable assignment below. You'll likely also want to amend the value of $TZ to match your local time zone. $DIY_TARGET is used to select the target architecture you are building for. It is vitally important to ensure that the vendor field of the target triplet is something other than "pc" or "unknown". This is because we want to force the pass 1 toolchain into cross compilation mode. For example, if your real target is i686-pc-linux-gnu, set $DIY_TARGET to i686-diy-linux-gnu or even i686-FAKE-linux-gnu. If your real target is x86_64-unknown-linux-gnu, set $DIY_TARGET to x86_64-diy-linux-gnu, and so forth. Feel free to tweak $TT_PFX if you don't care for the name "temptools". If you are building on SMP, uncomment the MAKEFLAGS line to take advantage of make's parallel execution feature. This is becoming more important as multi-core CPUs increase in popularity. Even on UP you can achieve quicker builds with export MAKEFLAGS="-j2" (at the expense of system responsiveness). If you are targeting x86_64 and also want the ability to compile and run 32-bit code (recommended) set $BIARCH to YES. This will provide a basic bi-arch (multilib) setup with 2 separate Glibc installations and the ability to compile the Grub bootloader which depends on 32-bit compilation. From this basic multilib setup, you then have the capability to build up a full-blown multilib development environment (not covered here), but be aware that going down this path can be a lot of trouble for your average DIY'er. Everything else should remain as is. If using the original (deprecated) build method, $DIY_ARCH is used to determine the target architecture ($DIY_TARGET and $BIARCH are ignored). Legal values for $DIY_ARCH are "i386", "ppc" and "x86_64" depending on which architecture you are building on. |
su - build cat > ~/.bash_profile << "EOF" exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash EOF cat > ~/.bashrc << "EOF" TT_PFX=/temptools CONFIG_SHELL=${TT_PFX}/bin/bash CONFIG_SITE=${HOME}/config.site DIY_TARGET=i686-diy-linux-gnu BIARCH=NO if [ "$BIARCH" = YES ]; then if ! echo $DIY_TARGET | grep ^x86_64 >/dev/null; then echo Warning: no BIARCH support for target $DIY_TARGET ! else export DIR_64=64 fi fi LC_ALL=C LDFLAGS="-s" PATH=${TT_PFX}/bin:/bin:/usr/bin SYSROOT=/mnt/sysroot TZ='Australia/Sydney' export TT_PFX CONFIG_SHELL CONFIG_SITE DIY_TARGET BIARCH LC_ALL LDFLAGS PATH SYSROOT TZ #export MAKEFLAGS="-j3" set +o hashall 2>/dev/null || set -o nohash umask 022 BINUTILS_VER=2.18 GCC_VER=4.2.4 GLIBC_VER=2.7 export BINUTILS_VER GCC_VER GLIBC_VER EOF cat > ~/config.site << "EOF" test "$prefix" = NONE && prefix=${TT_PFX} test -z "$CFLAGS" && CFLAGS="-O2 -pipe" test -z "$CXXFLAGS" && CXXFLAGS=${CFLAGS} enable_nls=no EOF source ~/.bash_profile
# Add this section ONLY when using the original (deprecated) build method! cat >> ~/.bashrc << "EOF" export DIY_ARCH=i386 EOF source ~/.bash_profile
FIXME explain rationale for each item above
Now become root and set up the sysroot area:
Important | |
---|---|
Ensure you are currently logged in as user `build' then become root using plain `su'. DO NOT use `su -' (ie: with the hyphen) because you'll lose the environment variables that are critical for these commands to work as intended. |
install -dv ${SYSROOT}${TT_PFX}/src/{tarballs,patches} ln -sv ${SYSROOT}${TT_PFX} / chown -Rv build ${SYSROOT}${TT_PFX}
Now exit the su (root) login and from this point onwards the environment should be sane enough to build the temptools phase whenever you login as user `build'. Dump all the needed tarballs and patches into their respective dirs. Now you're ready to rock.
Here is a list of source packages used in the build. This information is extracted into the aforementioned packagedata file for easy parsing and/or conversion into a wget script:
Patches used in the Reference Build can be downloaded from http://downloads.diy-linux.org/patches/. Be sure to look in the "PM" subdirectory for Package Management related patches, "ppc" subdirectory for PowerPC related patches, etc.