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.3
GLIBC_VER=2.6.1
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.62.tar.bz2 e1fb8fe0b22e651240afdfa2be537a3c
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.3.tar.bz2 c18640c6ec31a169d351e3117ecce3ec
Bzip2 http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz 3c15a0c8d1d3ee1c46a1634d00617b1a
Coreutils http://ftp.gnu.org/gnu/coreutils/coreutils-6.10.tar.gz eca0de1bf7389694305d7e52cd76a472
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.40.8.tar.gz 450e2fb2461b2296fec770ff8fc147ed
Ed http://ftp.gnu.org/gnu/ed/ed-0.9.tar.bz2 fb0c1c63ec13d8516733dd1d85c76473
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.9.4.tar.gz c324eb1e157edad17d98b1b2c8b99e25
File ftp://ftp.astron.com/pub/file/file-4.24.tar.gz 1efef03c9aac5515538f04cf3fc73eba
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.4a.tar.gz bd8753d0b22e1f4ec87a553a73021adf
Gawk http://ftp.gnu.org/gnu/gawk/gawk-3.1.6.tar.bz2 c9926c0bc8c177cb9579708ce67f0d75
GCC (4.2.X) http://ftp.gnu.org/gnu/gcc/gcc-4.2.3/gcc-4.2.3.tar.bz2 ef2a4d9991b3644115456ea05b2b8163
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.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.2.tar.bz2 7ce52531644e6d12f16911b7e3151f3f
Grep http://ftp.gnu.org/gnu/grep/grep-2.5.3.tar.bz2 27061ce1fde82876970b6549a156da8b
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.5.tar.gz aeacd11d19bf25c89d4eff38346bdfb9
Kbd http://ftp.altlinux.com/pub/people/legion/kbd/kbd-1.13.tar.bz2 2639fdfe2412b29cbf6936d7db91cee3
Less http://www.greenwoodsoftware.com/less/less-418.tar.gz b5864d76c54ddf4627fd57ab333c88b4
Libtool http://ftp.gnu.org/gnu/libtool/libtool-1.5.26.tar.gz aa9c5107f3ec9ef4200eb6556f3b3c29
Linux Kernel http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.24.tar.bz2 3f23ad4b69d0a552042d1ed0f4399857
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.11.tar.bz2 96ec473c2a6f203976c028e896a01b28
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-2.79.tar.bz2 1775f4ab1529db175a95f83bacc562b0
Module-Init-Tools http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.2.tar.bz2 a1ad0a09d3231673f70d631f3f5040e9
MPFR [a] http://www.mpfr.org/mpfr-current/mpfr-2.3.1.tar.bz2 8352b619e04dcc73411a38b39dd855f6
Ncurses http://ftp.gnu.org/gnu/ncurses/ncurses-5.6.tar.gz b6593abe1089d6aab1551c105c9300e3
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.0.tar.bz2 dd6ca3ac424b447962d7a7af923b7bda
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.20.tar.bz2 1a7e17f27abf583b3b0bc059a827e68b
Tcl http://osdn.dl.sf.net/sourceforge/tcl/tcl8.4.19-src.tar.gz ade2c033a7b545ee108f3fdfeb629fcf
Texinfo http://ftp.gnu.org/gnu/texinfo/texinfo-4.11.tar.bz2 c6bf13df4fbeff8ce874aacd6a51e814
Util-Linux-ng http://www.kernel.org/pub/linux/utils/util-linux-ng/v2.13/util-linux-ng-2.13.1.tar.bz2 424badc1832e4b5291a2ec04e9e244f4
Vim http://ftp.vim.org/vim/unix/vim-7.1.tar.bz2 44c6b4914f38d6f9aa959640b89da329
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://www.diy-linux.org/downloads/patches/. Be sure to look in the "PM" subdirectory for Package Management related patches, "ppc" subdirectory for PowerPC related patches, etc.