2. Getting Started

2.1. Environment

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] 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] 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] 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.

2.2. Tarballs

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:

Package Download URL md5sum
Autoconf http://ftp.gnu.org/gnu/autoconf/autoconf-2.63.tar.bz2 7565809ed801bb5726da0631ceab3699
Automake http://ftp.gnu.org/gnu/automake/automake-1.10.1.tar.bz2 4510391e6b3edaa4cffb3ced87c9560c
Bash http://ftp.gnu.org/gnu/bash/bash-3.2.tar.gz 00bfa16d58e034e3c2aa27f390390d30
Binutils (2.18.X) http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2 9d22ee4dafa3a194457caf4706f9cf01
Binutils (2.17.X) http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2 e26e2e06b6e4bf3acf1dc8688a94c0d1
Binutils (2.16.X) http://ftp.gnu.org/gnu/binutils/binutils-2.16.1.tar.bz2 6a9d529efb285071dad10e1f3d2b2967
Bison http://ftp.gnu.org/gnu/bison/bison-2.4.1.tar.bz2 84e80a2a192c1a4c02d43fbf2bcc4ca4
Bzip2 http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz 3c15a0c8d1d3ee1c46a1634d00617b1a
Coreutils http://ftp.gnu.org/gnu/coreutils/coreutils-6.12.tar.gz 2ca9ac69823dbd567b905a9e9f53c4f6
DejaGnu http://ftp.gnu.org/gnu/dejagnu/dejagnu-1.4.4.tar.gz 053f18fd5d00873de365413cab17a666
Diffutils http://ftp.gnu.org/gnu/diffutils/diffutils-2.8.1.tar.gz 71f9c5ae19b60608f6c7f162da86a428
E2fsprogs http://osdn.dl.sf.net/sourceforge/e2fsprogs/e2fsprogs-1.41.4.tar.gz 59033388df36987d2b9c9bbf7e19bd57
Ed http://ftp.gnu.org/gnu/ed/ed-1.2.tar.gz 3d42ac815b2dfd9c82a89dbd03151519
Expect http://expect.nist.gov/src/expect-5.43.0.tar.bz2 e6aaab98967f6410099b40f2b3ddebb4
Fakeroot http://ftp.debian.org/debian/pool/main/f/fakeroot/fakeroot_1.11.tar.gz b95de26a01338eec7a9b372d0fb24507
File ftp://ftp.astron.com/pub/file/file-5.00.tar.gz fd0b4ce55a756151629e06eaa3411e0c
Findutils http://ftp.gnu.org/gnu/findutils/findutils-4.4.0.tar.gz 49e769ac4382fae6f104f99d54d0a112
Flex http://osdn.dl.sf.net/sourceforge/flex/flex-2.5.35.tar.bz2 10714e50cea54dc7a227e3eddcd44d57
Gawk http://ftp.gnu.org/gnu/gawk/gawk-3.1.6.tar.bz2 c9926c0bc8c177cb9579708ce67f0d75
GCC (4.3.X) http://ftp.gnu.org/gnu/gcc/gcc-4.3.3/gcc-4.3.3.tar.bz2 cc3c5565fdb9ab87a05ddb106ba0bd1f
GCC (4.2.X) http://ftp.gnu.org/gnu/gcc/gcc-4.2.4/gcc-4.2.4.tar.bz2 d79f553e7916ea21c556329eacfeaa16
GCC (4.1.X) http://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2 a4a3eb15c96030906d8494959eeda23c
GCC (4.0.X) http://ftp.gnu.org/gnu/gcc/gcc-4.0.4/gcc-4.0.4.tar.bz2 8970debbc55bea85ee80961d733080f0
GCC (3.4.X) http://ftp.gnu.org/gnu/gcc/gcc-3.4.6/gcc-3.4.6.tar.bz2 4a21ac777d4b5617283ce488b808da7b
Gettext http://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz 58a2bc6d39c0ba57823034d55d65d606
Glibc (2.8.X) http://ftp.gnu.org/gnu/glibc/glibc-2.8.tar.bz2 39c75f96a712c56482018d5626306f5f
Glibc (2.7.X) http://ftp.gnu.org/gnu/glibc/glibc-2.7.tar.bz2 065c5952b439deba40083ccd67bcc8f7
Glibc (2.6.X) http://ftp.gnu.org/gnu/glibc/glibc-2.6.1.tar.bz2 11cf6d3fc86dbe0890b8d00372eb6286
Glibc (2.5.X) http://ftp.gnu.org/gnu/glibc/glibc-2.5.1.tar.bz2 10ea72e2c4d56c6aa13dabb7c4f9b195
Glibc (2.4.X) http://ftp.gnu.org/gnu/glibc/glibc-2.4.tar.bz2 7e9a88dcd41fbc53801dbe5bdacaf245
Glibc (2.3.X) http://ftp.gnu.org/gnu/glibc/glibc-2.3.6.tar.bz2 bfdce99f82d6dbcb64b7f11c05d6bc96
GMP [a] http://ftp.gnu.org/gnu/gmp/gmp-4.2.4.tar.bz2 fc1e3b3a2a5038d4d74138d0b9cf8dbe
Grep http://ftp.gnu.org/gnu/grep/grep-2.5.4.tar.bz2 5650ee2ae6ea4b39e9459d7d0585b315
Groff http://ftp.gnu.org/gnu/groff/groff-1.19.2.tar.gz f7c9cf2e4b9967d3af167d7c9fadaae4
Grub (X86 Only) ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz cd3f3eb54446be6003156158d51f4884
Gzip http://ftp.gnu.org/gnu/gzip/gzip-1.3.12.tar.gz b5bac2d21840ae077e0217bc5e4845b1
Hfsutils (PPC Only) ftp://ftp.mars.org/pub/hfs/hfsutils-3.2.6.tar.gz fa572afd6da969e25c1455f728750ec4
Iana-Etc http://www.sethwklein.net/iana-etc-2.30.tar.bz2 3ba3afb1d1b261383d247f46cb135ee8
Inetutils http://ftp.gnu.org/gnu/inetutils/inetutils-1.6.tar.gz 23cc24bc77751bf77d50a07a7395f9b3
Kbd http://ftp.altlinux.com/pub/people/legion/kbd/kbd-1.14.1.tar.gz 0f4e474032c992c05650924f29a06a92
Less http://www.greenwoodsoftware.com/less/less-429.tar.gz 206f2f13b9b0a35e45df660fcb6af31d
Libtool http://ftp.gnu.org/gnu/libtool/libtool-2.2.6a.tar.gz 8ca1ea241cd27ff9832e045fe9afe4fd
Linux Kernel http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.tar.bz2 b3e78977aa79d3754cb7f8143d7ddabd
Linux-Libc-Headers http://ep09.pld-linux.org/~mmazur/linux-libc-headers/linux-libc-headers-2.6.12.0.tar.bz2 eae2f562afe224ad50f65a6acfb4252c
M4 http://ftp.gnu.org/gnu/m4/m4-1.4.13.tar.bz2 28f9ccd3ac4da45409251008b911d677
Mac-Fdisk (PPC Only) http://ftp.debian.org/debian/pool/main/m/mac-fdisk/mac-fdisk_0.1.orig.tar.gz 24476329fe86ef6ccf222e233e2a99f1
Make http://ftp.gnu.org/gnu/make/make-3.81.tar.bz2 354853e0b2da90c527e35aabb8d6f1e6
Makedev http://downloads.linuxfromscratch.org/MAKEDEV-1.7.bz2 6ad9f744b586b2dad42958f1c0d334d9
Man http://primates.ximian.com/~flucifredi/man/man-1.6f.tar.gz 67aaaa6df35215e812fd7d89472c44b6
Man-Pages http://www.kernel.org/pub/linux/docs/manpages/man-pages-3.20.tar.bz2 e2e1063265231090b80e1503773f45a0
Man-Pages-Posix http://www.kernel.org/pub/linux/docs/manpages/man-pages-posix/man-pages-posix-2003-a.tar.bz2 7c78aff03c0a6767ba483d34f19e4b09
Module-Init-Tools http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.4.1.tar.bz2 e253b066a1bab1d727ca0d54f001b49c
MPFR [a] http://www.mpfr.org/mpfr-2.4.1/mpfr-2.4.1.tar.bz2 c5ee0a8ce82ad55fe29ac57edd35d09e
Ncurses http://ftp.gnu.org/gnu/ncurses/ncurses-5.7.tar.gz cce05daf61a64501ef6cd8da1f727ec6
Net-Tools http://www.tazenda.demon.co.uk/phil/net-tools/net-tools-1.60.tar.bz2 888774accab40217dde927e21979c165
Patch http://ftp.gnu.org/gnu/patch/patch-2.5.4.tar.gz ee5ae84d115f051d87fcaaef3b4ae782
Perl http://ftp.funet.fi/pub/CPAN/src/perl-5.10.0.tar.gz d2c39b002ebfd2c3c5dba589365c5a71
Procps http://procps.sourceforge.net/procps-3.2.7.tar.gz f490bca772b16472962c7b9f23b1e97d
Psmisc http://osdn.dl.sf.net/sourceforge/psmisc/psmisc-22.6.tar.gz 2e81938855cf5cc38856bd4a31d79a4c
Readline http://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz e39331f32ad14009b9ff49cc10c5e751
Sed http://ftp.gnu.org/gnu/sed/sed-4.1.5.tar.gz 7a1cbbbb3341287308e140bd4834c3ba
Shadow ftp://pkg-shadow.alioth.debian.org/pub/pkg-shadow/shadow-4.1.2.2.tar.bz2 3d26d990d4c3add1b7f8387eec1d1fde
Sysklogd http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.tar.gz e053094e8103165f98ddafe828f6ae4b
Sysvinit ftp://ftp.cistron.nl/pub/people/miquels/software/sysvinit-2.86.tar.gz 7d5d61c026122ab791ac04c8a84db967
Tar http://ftp.gnu.org/gnu/tar/tar-1.22.tar.bz2 07fa517027f426bb80f5f5ff91b63585
Tcl http://osdn.dl.sf.net/sourceforge/tcl/tcl8.4.19-src.tar.gz ade2c033a7b545ee108f3fdfeb629fcf
Texinfo http://ftp.gnu.org/gnu/texinfo/texinfo-4.13a.tar.gz 71ba711519209b5fb583fed2b3d86fcb
Util-Linux-ng http://www.kernel.org/pub/linux/utils/util-linux-ng/v2.14/util-linux-ng-2.14.2.tar.bz2 b9d0053a22cfcbf0b9c0aa6d6eccfbc8
Vim http://ftp.vim.org/vim/unix/vim-7.2.tar.bz2 f0901284b338e448bfd79ccca0041254
Yaboot (PPC Only) http://yaboot.ozlabs.org/releases/yaboot-1.3.14.tar.gz 9b1246c474eeb37f61081ad762563b35
Zlib http://www.zlib.net/zlib-1.2.3.tar.bz2 dee233bf288ee795ac96a98cc2e369b6
     
Libtar (Optional) ftp://ftp.feep.net/pub/software/libtar/libtar-1.2.11.tar.gz 604238e8734ce6e25347a58c4f1a1d7e
Pacman (Optional) ftp://ftp.archlinux.org/other/pacman/pacman-2.9.8.tar.gz 5d5e19c159d1fba7c7a6bb93b5bc14bd
     
Ogdlutils (Optional) http://osdn.dl.sf.net/sourceforge/ogdl/ogdlutils-20041124.tgz 45c7c81805480698c8c86881ab9be65c
Cpio (Optional) http://ftp.gnu.org/gnu/cpio/cpio-2.9.tar.bz2 e387abfdae3a0b9a8a5f762db653a96d
BPM (Optional) http://bent.latency.net/bent/darcs/bpm-1.7/src/bpm-1.7.tar.bz2 326eb2408e70414d10938fefa69a358a

[a] Only for GCC-4.3 and above.

2.3. Patches

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.