7. Chroot Phase - Original Build Method (Deprecated)

[Warning] Warning -- Original Build Method Now Deprecated

What follows is the original build method which is now deprecated. It no longer receives any testing from the author and it only receives mechanical updates which renders it essentially unmaintained. In particular, the original method will not be updated for GCC 4.3. Please note that it will be removed entirely in due course. The Next Generation build method is now the preferred option.

7.1. About $PM_DEST

As mentioned in the Introduction, Package Management (PM) is a goal of the Reference Build. Accordingly, all build commands in this Chroot phase strive to be "PM friendly". This is reflected in those individual commands associated with file installation. Commands associated with configuring and building remain exactly the same as when performing a "build in place" style installation.

You'll notice that a typical invocation of make install has now become make DESTDIR=$PM_DEST install. The expectation is this: if you're employing PM then you'll assign a value to the PM_DEST variable in your scripting environment that is equivalent to wherever your chosen Package Manager expects to find the installed files. Doing it this way ensures the installation commands remain generic. If you're not employing PM, that is you're performing a usual "build in place" style installation, you just have to ensure that the PM_DEST variable is nonexistent (or empty or unset), then the installation commands will work exactly as if `DESTDIR=$PM_DEST' weren't specified.

7.2. Enter Chroot Environment

[Important] Important

Earlier in the Temptools phase we installed a somewhat crippled `su' program from Coreutils (with a missing setuid bit). Therefore, in order to become root and enter the Chroot environment, you must call the host's `su' explicitly by running /bin/su or else you'll fail to gain root privilege.

Before entering the chroot environment, be sure to become root using plain `/bin/su'. DO NOT use `/bin/su -' (ie: with the hyphen) because you'll lose the environment variables that are critical for the following chroot command to work as intended. When including this chroot command in your script you'll need to make 2 adjustments: (a) you should omit the $PS1 variable because it is normally unset in non-interactive shells and (b) you'll want to execute a script instead of ${TT_PFX}/bin/bash --login +h (make sure your script does a set +h to switch off hashing).

${TT_PFX}/bin/chroot $SYSROOT \
	${TT_PFX}/bin/env -i \
	HOME=/root \
	PATH=/bin:/usr/bin:/sbin:/usr/sbin:${TT_PFX}/bin \
	PS1='\u-in-chroot:\w\$ ' \
	TERM=${TERM} \
	CONFIG_SITE=/etc/config.site \
	DIY_ARCH=${DIY_ARCH} \
	LC_ALL=C \
	LDFLAGS=${LDFLAGS} \
	${MAKEFLAGS+"MAKEFLAGS=$MAKEFLAGS"} \
	TT_PFX=${TT_PFX} \
	TZ=${TZ} \
	BINUTILS_VER=${BINUTILS_VER} \
	GCC_VER=${GCC_VER} \
	GLIBC_VER=${GLIBC_VER} \
	${TT_PFX}/bin/bash --login +h

7.3. Create Directories

mkdir -pv /{bin,etc,home,lib,proc,sys} \
	/dev/{pts,shm} \
	/usr/{bin,include,lib/locale,share/{man,doc,info}} \
	/var/{lock,log,mail,run}
#ln -sv share/{man,doc,info} /usr
install -dvm 0750 /root
install -dvm 1777 {,/var}/tmp

if [ "$DIY_ARCH" = x86_64 ]; then
	ln -sv lib /lib64
	ln -sv lib /usr/lib64
fi

Rationale Notes

  • There really shouldn't be any need to create a whole directory layout from the outset. Just create the bare minimum to get the build going then let the packages themselves create the rest. If you want a full FHS/LSB compliant layout then just add the missing bits after the build. Consider this experimental. FIXME

  • Current LFS inefficiently uses a raft of `install -d' commands for directory creation here. There is no need for this when `mkdir' is perfectly suited to the task. Only when custom permissions are required do we use `install -d'.

  • The command to create compatibility symlinks in /usr is commented out above. We force packages to install man and info files into proper FHS compliant locations by globally setting defaults in config.site (see below). Those few packages that don't pick up the defaults are taken care of individually in the build commands. Feel free to uncomment the above line if you still prefer to keep the compatibility symlinks.

7.4. Perform Mounts

test -r /etc/mtab || > /etc/mtab
mount proc /proc -t proc
mount devpts /dev/pts -t devpts
mount shm /dev/shm -t tmpfs
mount sysfs /sys -t sysfs

7.5. Create Symlinks

ln -sv ${TT_PFX}/bin/{bash,cat,echo,pwd} /bin
ln -sv ${TT_PFX}/bin/perl /usr/bin
ln -sv ${TT_PFX}/lib/lib{gcc_s.so.1,stdc++.so.6,fakeroot.so} /usr/lib
ln -sv bash /bin/sh

Rationale Notes

  • The `/bin/echo' symlink is required for the Glibc-2.6 (and above) testsuite to pass. More information here.

  • The `libstdc++.so.6' symlink is needed to satisfy the Glibc-2.4 (and above) testsuite. More information here.

  • The `libfakeroot.so.0' symlink is only needed if you installed the optional Fakeroot package. If you build Glibc under Fakeroot (not recommended) the build will fail in the absence of this symlink. Additionally, when Fakeroot is used to wrap file installation commands only (its preferred mode of operation), the symlink prevents some ugly non-fatal errors during Glibc and GCC installation eg: "ERROR: ld.so: object 'libfakeroot.so.0' from LD_PRELOAD cannot be preloaded: ignored."

7.6. Create Misc. Files

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF

cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
utmp:x:12:
EOF

echo "127.0.0.1 localhost $(hostname)" > /etc/hosts

touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chmod -v 644 /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/run/utmp

cat > $CONFIG_SITE << "EOF"
test "$prefix" = NONE && prefix=/usr
test "$mandir" = '${prefix}/man' && mandir='${prefix}/share/man'
test "$infodir" = '${prefix}/info' && infodir='${prefix}/share/info'
test -z "$CFLAGS" && CFLAGS="-O2 -pipe"
test -z "$CXXFLAGS" && CXXFLAGS=${CFLAGS}
EOF

Rationale Notes

  • A dummy `/etc/hosts' file is created here to satisfy the Perl testsuite later on.

7.7. Create Users

echo "pkgmgr:x:999:" >> /etc/group
echo "pkgmgr2:x:998:pkgmgr" >> /etc/group
echo "pkgmgr:x:999:999::/home/pkgmgr:/bin/bash" >> /etc/passwd
install -dv -o pkgmgr -g pkgmgr /home/pkgmgr

echo "dummy1:x:1000:" >> /etc/group
echo "dummy2:x:1001:dummy" >> /etc/group
echo "dummy:x:1000:1000::/home:/bin/bash" >> /etc/passwd

Rationale Notes

  • If you're employing Package Management, the chances are you'll probably want to build packages as a non-privileged user. Here we setup a user called "pkgmgr" for exactly this purpose. You can use the `su' program (installed earlier) to build packages as the Package Management User (PMU). To build a package as the PMU, something like: su pkgmgr -c "command-to-build-package" should achieve the desired effect. Creating the PMU is of course optional if you'd prefer to build the Chroot phase as root.

  • We also create a dummy user and some dummy groups for the benefit of those testsuites that need to be run as a non-privileged user. These entries should be removed upon completion of the build.

7.8. Makedev-1.7

bzcat ${TT_PFX}/src/tarballs/MAKEDEV-1.7.bz2 > $PM_DEST/dev/MAKEDEV
chmod -v 754 $PM_DEST/dev/MAKEDEV
cd $PM_DEST/dev
./MAKEDEV -v generic-nopty

Rationale Notes

  • We install MAKEDEV here primarily for the purpose of bootstrapping the Reference Build. That is, you don't have to deploy the MAKEDEV script and the "on disk" device special files it created in your final file system image. Some folks prefer to use the (now deprecated) kernel based Devfs facility to manage /dev. However, lately the general trend has moved towards the Udev system which runs entirely in userspace. Other options for populating /dev during the chroot phase of the Reference Build include: (a) performing a `mount --bind' of the host's /dev onto $SYSROOT/dev (b) manually mknod'ing the bare minimum device special files needed to satisfy the build or (c) running the `udevstart' program from Udev. All of these solutions are suboptimal in the author's opinion which is why using MAKEDEV here is recommended. What you do to manage /dev in the final deployed system is entirely your choice, but if you're after the latest and greatest, Udev would be your best bet.

7.9. Man-Pages-3.20

rm -fv man3/getspnam.3 man5/passwd.5
make DESTDIR=$PM_DEST install

Rationale Notes

  • In general terms, GNU prefers the Info documentation system over man pages. However, many GNU packages install both info pages and (in some cases, less than adequate) man pages. The man pages listed above will be installed later on by Coreutils, Diffutils and Shadow and are therefore superfluous. We suppress their installation here because some Package Managers will refuse to install an archive if a file conflict is detected. If you'd prefer to keep the copies here, omit the rm statements and somehow suppress the installation of said man pages when installing the 3 aforementioned packages later on.

7.10. Man-Pages-Posix-2003-a

make DESTDIR=$PM_DEST install

7.11. Linux-Kernel-Headers-2.6.27

[Warning] Warning

As mentioned earlier, the 2.6.18 kernel introduced the next generation method of obtaining sanitized kernel headers. When using the new technique you MUST SKIP the Linux-Libc-Headers step which follows next.

make mrproper
make headers_check || :
make headers_install INSTALL_HDR_PATH=temp
mkdir -pv $PM_DEST/usr
cp -rv temp/include $PM_DEST/usr

7.12. Linux-Libc-Headers-2.6.12.0 (Older toolchains only)

patch -p1 -i ${TT_PFX}/src/patches/linux-libc-headers-2.6.12.0-syscalls-3.patch
mkdir -pv $PM_DEST/usr/include
cp -Rv include/asm-${DIY_ARCH} $PM_DEST/usr/include/asm
cp -Rv include/linux $PM_DEST/usr/include

7.13. Glibc (2.3.6 through 2.7)

[Caution] Proceed with Caution!

Glibc is possibly the most critical piece of software you will compile in a base Reference Build. There is a high probability of something going wrong. Be sure to heed the advice contained in Section B, “Glibc General Advice” before taking on this monster.

case "$DIY_ARCH" in
  i386)   DL=/lib/ld-linux.so.2; MARCH="-march=i686"
	  [[ $GCC_VER > 4.1.9 ]] && MARCH="$MARCH -mtune=generic" ;;
  ppc)	  DL=/lib/ld.so.1 ;;
  x86_64) DL=/lib64/ld-linux-x86-64.so.2 ;;
esac

sed -i.bak \
	"s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=${DL} -o|" \
	scripts/test-installation.pl

[[ $GLIBC_VER == 2.4* ]] &&
sed -i.bak \
	'/shlib_handle = NULL/{n;n;n;s/else$/& if (step->__shlib_handle == NULL)/}' \
	iconv/gconv_db.c

[[ $GLIBC_VER > 2.5.9 ]] &&
	patch -p1 -i ${TT_PFX}/src/patches/glibc-2.6-x86-math-tests-1.patch

mkdir ../glibc-build
cd ../glibc-build

CFLAGS="-O3 $MARCH -pipe" ../glibc-${GLIBC_VER}/configure \
	--disable-profile \
	--enable-add-ons \
	--libexecdir=/usr/lib \
	--with-headers=/usr/include \
	--enable-kernel=2.6.0 \
	--enable-bind-now

[[ $GLIBC_VER == 2.3* && $DIY_ARCH == x86_64 ]] &&
	sed -i.bak '/combreloc/s/no/yes/' config.make

make
make -k check || :
make install_root=$PM_DEST install -j1
#make install_root=$PM_DEST localedata/install-locales
cp -v --remove-destination $PM_DEST/usr/share/zoneinfo/${TZ} $PM_DEST/etc/localtime

mkdir -pv $PM_DEST/usr/include/hacks/glibc/bits
cp -v `find ../glibc-${GLIBC_VER} -name stdio-lock.h | grep -v nptl` \
	$PM_DEST/usr/include/hacks/glibc/bits

cat > $PM_DEST/etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

cat > $PM_DEST/etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

/usr/local/lib

# End /etc/ld.so.conf
EOF

Rationale Notes

  • For an explanation of why we add `-mtune=generic' to CFLAGS in the x86 GCC-4.2 and above case, please read this mailing list post.

  • Whenever Glibc is installed directly into a prefix of /usr via `make install' (ie: the Makefile variable `install_root' is unset), a script called `test-installation.pl' is run to perform some basic sanity checks (compiling, linking, executing, etc) against the newly installed Glibc. If all goes well, a message "Your new glibc installation seems to be ok." will be shown. However, at the time the script is run our toolchain defaults are still pointing to $TT_PFX. In particular, ld's library search path is pointing to $TT_PFX/lib and gcc's dynamic linker spec is pointing to $TT_PFX${DL}. In actual fact, this means the checks are made against the wrong Glibc. The problem will usually go unnoticed because the Glibc's in $TT_PFX/lib and /usr/lib are functionally equivalent and the checks always pass. You can expose the problem by building different Glibc addons in each phase eg: configure the Temptools phase Glibc with `--enable-add-ons=nptl' and configure the Chroot phase Glibc with `--enable-add-ons=nptl,libidn' (assuming you have downloaded and unpacked the separate addon for Libidn). We work around the issue by using a sed to insert `-L/usr/lib -Wl,-dynamic-linker=${DL}' at an appropriate place. Note that ld's library search path and the gcc dynamic linker spec will be readjusted to point to the new Glibc in the next step.

  • The sed to iconv/gconv_db.c is required to fix a bug that is known to affect at least Samba (crash on startup). It essentially replicates this fix from upstream. More information here.

  • The sed to config.make on x86_64 fixes a subtle bug in the autoconfigury which arrives at a wrong result for the "-z combreloc" feature test. The issue is fixed in Glibc-2.4.x. More information here.

  • The command to install the localedata has been commented out above. If you need all the locales, unlikely as that may be, feel free to uncomment the relevant line. It used to be the case that some of these locales were required for the Libstdc++ testsuite to pass. But that is no longer true with the advent of GCC-3.4. More information about this issue is here. However, the Libstdc++ docs do recommend a minimum list of locales, so having them installed should result in wider Libstdc++ testsuite coverage. Note that you can install individual locales at any time using the `localedef' command ie: locale installation doesn't have to occur as part of the Glibc install. At the very least, you'll probably want to install a locale for your own country.

  • We install the generic version of `bits/stdio-lock.h' into a non-standard location because it gives us the capability of pursuading some legacy software to compile successfully, in particular, apps that define `_IO_MTSAFE_IO' eg: the libstdc+ library from GCC-2.95.x. Clearly, installing this header is a kludge and of course optional. More information about the issue is here. Note that we use `find' to locate the header because it changed location between Glibc-2.3.x and Glibc-2.4.x.

  • The warning in current LFS about unsetting CFLAGS and not overriding the default optimization for Glibc is a crock. Glibc is EXACTLY the kind of package that should be optimized - Refer Golden Rule No. 2 in Section B, “Glibc General Advice”. The warning in LFS dates back to times when clues were scarce and tools weren't as good.

[Tip] Tip -- Set up Dual Threading Libraries

Ever since the advent of NPTL most mainstream distros are set up with both NPTL and Linuxthreads enabled Glibc's installed side by side. This is for backwards compatibility reasons. NPTL is still relatively new and a lot of commercial software simply won't run under it. Be sure to check out Section B, “Dual Threading Libraries” if you need this backwards compatibility and want to set up your system to match the distros.

7.14. Readjust Toolchain

ln -sv ${TT_PFX}/bin/ld-new /usr/bin/ld

case "$DIY_ARCH" in
  i386)   DL=/lib/ld-linux.so.2 ;;
  ppc)	  DL=/lib/ld.so.1 ;;
  x86_64) DL=/lib64/ld-linux-x86-64.so.2 ;;
esac

gcc -dumpspecs | sed \
	-e '/^\*link:$/{n;s,$, -L/usr/lib,}' \
	-e "s,${TT_PFX}${DL},${DL}," \
	-e '/^\*cpp:$/{n;s,$, -isystem /usr/include,}' \
	> /tmp/myspecs

# Sanity checks.
echo 'main(){}' | cc \
	-x c \
	-specs=/tmp/myspecs \
	-B/usr/lib/ \
	-B/usr/bin/ \
	-Wl,--verbose \
	- &> foo

# 1. dynamic linker
readelf -l a.out | grep ": /lib"

# 2. start files
grep " /usr/lib/crt1.o succ" foo

# 3. libc
grep " /lib.*libc.so.6 succ" foo

# 4. deps found from DT_NEEDED
grep "^found.*at /lib.*/ld" foo

rm -fv a.out foo

7.15. GCC (3.4.6 through 4.2.4)

[Caution] Caution -- Check your GCC Testsuite Results!

Upon completion of the GCC Testsuite run, sanity check your results by comparing against a set of known good results as per the links in the following table:

i686-pc-linux-gnu powerpc-unknown-linux-gnu x86_64-unknown-linux-gnu
4.2.4 4.2.1 FIXME
4.1.2 4.1.2 4.1.1
4.0.4 4.0.4 4.0.3
3.4.6 3.4.6 3.4.6

Note: if you're using GCC-3.4.4 or earlier and running under a 2.6.12 kernel or above, a new kernel feature known as "address space randomization" will likely cause some PCH tests to fail as per these unsatisfactory results. The problem is now resolved in GCC-3.4.5 and above. However, if for some reason you need to use an old GCC version, the problem can be worked around by following the advice contained in this mailing list post.

sed -i.bak \
	's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

[[ $BINUTILS_VER == 2.18* && $GCC_VER > 4.1.9 && $GLIBC_VER > 2.5.9 ]] &&
	patch -p1 -i ${TT_PFX}/src/patches/gcc-4.2-branch-hash-style-gnu-1.patch

sed -i.bak \
	-e 's,\./fixinc\.sh,-c true,' \
	-e '/^LIBGCC2_DEBUG/d' gcc/Makefile.in

[[ $GCC_VER == 4.* && $DIY_ARCH == i386 ]] &&
	sed -i.bak2 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in

[[ $GCC_VER == 4.* ]] &&
	sed -i.bak '/dg-timeout/s/3\|10/20/' libmudflap/testsuite/libmudflap.cth/*.c

mkdir ../gcc-build
cd ../gcc-build

CC="gcc -specs=/tmp/myspecs -B/usr/lib/ -B/usr/bin/" \
	../gcc-${GCC_VER}/configure \
	--libexecdir=/usr/lib \
	--enable-shared \
	--disable-multilib \
	--disable-bootstrap \
	--enable-languages=c,c++ \
	--enable-clocale=gnu \
	--enable-threads=posix \
	--enable-__cxa_atexit

make \
	LDFLAGS=${LDFLAGS} \
	MAKEINFO=makeinfo \
	gcc_cv_prog_makeinfo_modern=yes

make -k check || :
../gcc-${GCC_VER}/contrib/test_summary
make DESTDIR=$PM_DEST install -j1

mkdir -pv $PM_DEST/lib
ln -sfv ../usr/bin/cpp $PM_DEST/lib
ln -sfv gcc $PM_DEST/usr/bin/cc

Rationale Notes

  • When building with GCC-4.x we use a sed to add `-fomit-frame-pointer' to the GCC Makefile to address a correctness issue. Please read this mailing list post for some rationale discussion.

  • When building with GCC-4.x we use a sed to increase the timeouts on 2 libmudflap tests to avoid spurious failures. The problem is most noticeable when running the GCC testsuite in parallel on SMP. Upstream have been notified of the issue. Note the timeouts were increased from 3 to 10 seconds as of GCC-4.1 but this is still not enough. The sed is compatible across all supported GCC versions.

  • We add "MAKEINFO=makeinfo" and "gcc_cv_prog_makeinfo_modern=yes" to the `make' invocation to ensure installation of the GCC info pages. Please read this mailing list post for background details.

7.16. Binutils (2.16.1 through 2.18)

rm -fv etc/standards.info
sed -i.bak '/^INFO/s/standards.info //' etc/Makefile.in
mkdir ../binutils-build
cd ../binutils-build

../binutils-${BINUTILS_VER}/configure \
	--enable-shared
echo "MAKEINFO = makeinfo" >> Makefile
make LDFLAGS=${LDFLAGS} tooldir=/usr
make -k check || :
make tooldir=/usr DESTDIR=$PM_DEST install
cp -v ../binutils-${BINUTILS_VER}/include/libiberty.h $PM_DEST/usr/include

Rationale Notes

  • A newer `standards.info' is installed later by the Autoconf package. Here we use `rm' and a Makefile sed to suppress installation of the unwanted file. The `rm' is needed when using FSF releases but is otherwise harmless when using HJL releases.

7.17. Sed-4.1.5

./configure \
	--bindir=/bin \
	--enable-html
make
make check
make DESTDIR=$PM_DEST install

7.18. E2fsprogs-1.41.4

sed -i.bak 's,/bin/rm,rm,' lib/blkid/test_probe.in

mkdir build
cd build

../configure \
	--with-root-prefix="" \
	--enable-elf-shlibs
make
make check
make DESTDIR=$PM_DEST install install-libs

Rationale Notes

  • The sed to `lib/blkid/test_probe.in' removes a hard-wired reference to /bin/rm in the testsuite. Without this sed (or a /bin/rm symlink) the testsuite will produce some non-fatal errors.

7.19. Coreutils-6.12

patch -p1 -i $TT_PFX/src/patches/coreutils-6.12-utimensat-1.patch
sed -i.bak 's,HOME",HOME /dev/shm",' tests/other-fs-tmpdir
sed -i.bak 's/test-getaddrinfo\$(EXEEXT) //' gnulib-tests/Makefile.in

./configure \
	--enable-no-install-program=kill,uptime \
	--enable-install-program=hostname,su
make

if [ `id -u` -eq 0 ]; then
	make NON_ROOT_USERNAME=dummy check-root
	chown -v dummy gnulib-tests/.deps
	su dummy -c "make RUN_EXPENSIVE_TESTS=yes check"
else
	make RUN_EXPENSIVE_TESTS=yes check
fi
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/{bin,usr/sbin}
mv -v $PM_DEST/usr/bin/{cat,chgrp,chmod,chown,cp,date} $PM_DEST/bin
mv -v $PM_DEST/usr/bin/{dd,df,echo,false,hostname,ln,ls} $PM_DEST/bin
mv -v $PM_DEST/usr/bin/{mkdir,mknod,mv,pwd,rm,rmdir,sleep} $PM_DEST/bin
mv -v $PM_DEST/usr/bin/{stty,su,sync,touch,true,uname} $PM_DEST/bin
mv -v $PM_DEST/usr/bin/chroot $PM_DEST/usr/sbin

Rationale Notes

  • For an explanation of the Makefile.in sed, configure switches and chown command, please read this mailing list post.

  • The sed to `tests/other-fs-tmpdir' adds /dev/shm as a location to search when the testsuite goes looking for a writable directory on a different disk partition. This allows some tests to run that would otherwise be skipped. Passing `CANDIDATE_TMP_DIRS=/dev/shm' would achieve the same effect but the sed saves us passing it twice.

  • A bunch of commands are moved to /bin as mandated by the FHS. In the case of `[' and `test', the FHS says they must be together in either /bin or /usr/bin. We leave them in /usr/bin to match the big distros. Even though `sleep' and `touch' are not mentioned by the FHS, we move them to /bin because: (a) they are commonly used in bootscripts, (b) they have always traditionally been there and (c) this matches the big distros. Please read this mailing list post for some rationale discussion.

  • We have opted to use the `su' from Coreutils rather than the one from Shadow. Please read this mailing list post for some rationale discussion. If you would rather use the `su' from Shadow, simply omit `su' from the --enable-install-program configure switch and the 4th mv command.

  • If you would like `uname' to print something useful for the `-p' and `-i' options instead of "unknown", 3rd party patches are known to exist (or at least have existed in the past) at the LFS and Gentoo projects. But before applying any such hacks, ask yourself this question: Why haven't these types of patches been integrated by the upstream Coreutils developers? Some insight into this issue can be found in this mailing list thread.

7.20. Zlib-1.2.3

sed -i.bak \
	'/SFL.*fPIC/s/${CFLAGS-"-fPIC -O3"}/"${CFLAGS-"-O3"} -fPIC"/' \
	configure

./configure \
	--prefix=/usr
make
mv -v {,x}libz.a
make clean

./configure \
	--prefix=/usr \
	--shared
make
make check
make prefix=$PM_DEST/usr install
cp -v xlibz.a $PM_DEST/usr/lib/libz.a
mkdir -pv $PM_DEST/lib
mv -v $PM_DEST/usr/lib/libz.so.* $PM_DEST/lib
ln -sfv ../../lib/libz.so.1 $PM_DEST/usr/lib/libz.so

Rationale Notes

  • The sed to `configure' replicates a fix from upstream which ensures the shared lib is always built with -fPIC. Currently, -fPIC is lost if CFLAGS happen to be set in the environment. More information in this mailing list post. Note: Zlib beta versions can be found here.

  • The reason for the mv -v {,x}libz.a etc. is to allow better locality of the "installation" commands. More rationale in this mailing list post.

7.21. Iana-Etc-2.30

make STRIP=yes
make test
make DESTDIR=$PM_DEST install

Rationale Notes

  • Note: You should be aware there are performance implications when using this package because it results in an enormous /etc/services file. Please read this mailing list post for some background discussion.

7.22. Gawk-3.1.6

./configure \
	--libexecdir=/usr/lib
make
make check
make DESTDIR=$PM_DEST install

7.23. Findutils-4.4.0

./configure \
	--libexecdir=/usr/lib/locate \
	--localstatedir=/var/lib/locate
make
make check
make DESTDIR=$PM_DEST install

7.24. Ncurses-5.7

./configure \
	--with-shared \
	--without-debug
make
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/lib
mv -v $PM_DEST/usr/lib/libncurses.so.5* $PM_DEST/lib
ln -sfv ../../lib/libncurses.so.5 $PM_DEST/usr/lib/libncurses.so
ln -sfv libncurses.so $PM_DEST/usr/lib/libcurses.so

7.25. Readline-5.2

patch -p1 -i ${TT_PFX}/src/patches/readline-5.2-official-012-combined-1.patch
./configure \
	bash_cv_func_ctype_nonascii=yes
make SHLIB_LIBS=-lcurses
sed -i.bak '/MV.*old/d' Makefile
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/lib
mv -v $PM_DEST/usr/lib/lib{readline,history}.so.5* $PM_DEST/lib
ln -sfv ../../lib/libhistory.so.5 $PM_DEST/usr/lib/libhistory.so
ln -sfv ../../lib/libreadline.so.5 $PM_DEST/usr/lib/libreadline.so

Rationale Notes

  • We add "bash_cv_func_ctype_nonascii=yes" to the `configure' invocation to force the correct result in scenarios where the en_US.ISO8859-1 locale is not present. More information here.

7.26. Vim-7.2

echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h

./configure
make
make test -j1
mkdir -pv $PM_DEST/etc
make DESTDIR=$PM_DEST install -j1
ln -sfv vim $PM_DEST/usr/bin/vi

cat > $PM_DEST/etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
syntax on

" End /etc/vimrc
EOF

Rationale Notes

  • Note: The Vim author makes available a number of patches to fix bugs discovered after the latest release which you may want to consider applying. The patches can be found here.

7.27. M4-1.4.13

./configure
make V=1
make check V=1
make DESTDIR=$PM_DEST install

7.28. Bison-2.4.1

./configure
make
make check
make DESTDIR=$PM_DEST install

7.29. Less-429

./configure \
	--sysconfdir=/etc
make
make DESTDIR=$PM_DEST install

7.30. Groff-1.19.2

PAGE=A4 ./configure
make -j1
mkdir -pv $PM_DEST/usr
make prefix=$PM_DEST/usr install
ln -sfv soelim $PM_DEST/usr/bin/zsoelim
ln -sfv eqn $PM_DEST/usr/bin/geqn
ln -sfv tbl $PM_DEST/usr/bin/gtbl

7.31. Flex-2.5.35

./configure
make
make check -j1
make DESTDIR=$PM_DEST install
ln -sfv flex $PM_DEST/usr/bin/lex
ln -sfv libfl.a $PM_DEST/usr/lib/libl.a

7.32. Gettext-0.17

./configure
make
make -k check || :
make DESTDIR=$PM_DEST install

Rationale Notes

  • The Gettext testsuite takes a painfully long time to run, and seeing as Gettext is not a critical component in the overall scheme of things, running this testsuite is considered optional. You can reduce the pain somewhat by only running the less time consuming parts of the testsuite like so: make -C gettext-tools check.

  • Note that the Gettext testsuite will gain wider coverage if you have a bunch of various locales installed (the testsuite will inform you of which ones are missing).

  • Note also that 2 tests will fail if Gettext is configured with `--disable-nls' and the fr_FR locale is installed. More information about this issue is here.

7.33. Net-Tools-1.60

sed -i.bak \
	-e '/PROGS/s/hostname //' \
	-e '/hostname.*bin/d' \
	Makefile
sed -i.bak 's/in 1 5/in 5/' man/Makefile
sed -i.bak '/default:/d' lib/inet_sr.c
sed -i.bak 's/of(x25/of(struct x25/' lib/x25_sr.c

yes "" | make config
make LOPTS=${LDFLAGS} -j1
make BASEDIR=$PM_DEST update

7.34. Inetutils-1.6

sed -i.bak '/man_MANS =/d' \
	{ftpd,inetd,logger,rexecd,rlogind,rshd,syslogd,talkd,telnetd,tftpd}/Makefile.in

./configure \
	--disable-servers \
	--disable-hostname \
	--disable-logger \
	--disable-whois \
	--disable-ifconfig \
	--libexecdir=/usr/sbin
make
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/bin
mv -v $PM_DEST/usr/bin/ping $PM_DEST/bin

7.35. Procps-3.2.7

make
make DESTDIR=$PM_DEST ldconfig=: install

7.36. Perl-5.10.0

sed -i.bak \
	"/if grep/a skip \"not testing setlogsock('stream'): _PATH_LOG unavailable\", 10 \
	unless -e Sys::Syslog::_PATH_LOG();" \
	ext/Sys/Syslog/t/syslog.t

./configure.gnu \
	-Dpager="/usr/bin/less -isR"

make BUILD_ZLIB=False
make test
make DESTDIR=$PM_DEST install

Rationale Notes

  • The sed replicates a testsuite fix from upstream. More background in this mailing list post.

  • BUILD_ZLIB=False is passed on the `make' command line in order to use the system installed Zlib. More background in this mailing list post.

7.37. Gzip-1.3.12

[[ $GLIBC_VER > 2.5.9 ]] &&
	sed -i.bak 's/futimens/gl_&/' gzip.c lib/utimens.{c,h}

./configure
make bindir=/bin
make check
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/bin
mv -v $PM_DEST/usr/bin/{gunzip,gzip,zcat} $PM_DEST/bin

Rationale Notes

  • Adding `bindir=/bin' to the make invocation is not strictly necessary. But it at least ensures the installed scripts have an optimal setting for PATH.

  • Some LFS versions add a `/bin/compress' symlink here. We believe this is technically incorrect. Please read this mailing list post for some rationale discussion.

7.38. Texinfo-4.13a

./configure
make
make check
make DESTDIR=$PM_DEST install

7.39. Grep-2.5.4

./configure \
	--bindir=/bin \
	--without-included-regex
make
make check
make DESTDIR=$PM_DEST install

7.40. File-5.00

./configure
make
make check
make DESTDIR=$PM_DEST install

7.41. Libtool-2.2.6a

./configure
make
make check
make DESTDIR=$PM_DEST install

7.42. Autoconf-2.63

./configure
make
make check
make DESTDIR=$PM_DEST install

7.43. Automake-1.10.1

./configure
make
make -k check || :
make DESTDIR=$PM_DEST install
  • This release of Automake contains an expected testsuite failure when run as root. More information here.

7.44. Bash-3.2

[Important] Important

The Bash testsuite is unlike most others in that it doesn't stop if errors are encountered. This means you have to physically examine the output and cannot rely on the exit status of the `make tests' command. It even tells you as much at the beginning of the run: "Any output from any test, unless otherwise noted, indicates a possible anomaly".

patch -p1 -i ${TT_PFX}/src/patches/bash-3.2-official-039-combined-1.patch
echo '#define NON_INTERACTIVE_LOGIN_SHELLS' >> config-top.h
./configure \
	--without-bash-malloc \
	--with-installed-readline
make

sed -i '/THIS/s,1$,1 </dev/tty,' tests/run-test

if [ `id -u` -eq 0 ]; then
	chown -R dummy .
	su dummy -c "make tests"
else
	make tests
fi
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/bin
mv -v $PM_DEST/usr/bin/bash $PM_DEST/bin

Rationale Notes

  • The sed to `tests/run-test' implements redirection of the input device to ensure this test passes when running su'd to non-root. More information in this mailing list post.

  • The Bash testsuite will issue warnings if you run it as root. We therefore take steps to run it as the dummy user.

  • The configure switch `--without-bash-malloc' causes Bash to use the system supplied malloc from Glibc rather than Bash's own malloc. Please read this mailing list post for some rationale discussion.

7.45. Bzip2-1.0.5

sed -i.bak \
	-e 's,X)/man,X)/share/man,g' \
	-e '/ln .*PREFIX/s,$(PREFIX)/bin/,,' \
	Makefile

make -f Makefile-libbz2_so
make clean
make
make PREFIX=$PM_DEST/usr install
mkdir -pv $PM_DEST/{bin,lib}
cp -v bzip2-shared $PM_DEST/bin/bzip2
cp -av libbz2.so* $PM_DEST/lib
ln -sfv ../../lib/libbz2.so.1.0 $PM_DEST/usr/lib/libbz2.so
rm -fv $PM_DEST/usr/bin/{bunzip2,bzcat,bzip2}
ln -sfv bzip2 $PM_DEST/bin/bunzip2
ln -sfv bzip2 $PM_DEST/bin/bzcat

Rationale Notes

  • The sed serves to (a) ensure man pages are installed into proper FHS compliant location and (b) fix a minor Makefile bug affecting "staged" installations. More information here.

7.46. Diffutils-2.8.1

./configure
make
make DESTDIR=$PM_DEST install

7.47. Ed-1.2

./configure \
	--prefix=/usr \
	--bindir=/bin
make
make check
make DESTDIR=$PM_DEST install

7.48. Kbd-1.14.1

sed -i.bak \
	's/ifdef OPTIONAL_PROGS/ifeq ($(OPTIONAL_PROGS),yes)/' \
	man/Makefile.in

sed -i.bak \
	's,@datadir@,&/kbd,' \
	{src,data}/Makefile.in

./configure \
	--enable-nls
make KEYCODES_PROGS=yes RESIZECONS_PROGS=yes
make KEYCODES_PROGS=yes RESIZECONS_PROGS=yes DESTDIR=$PM_DEST install

Rationale Notes

7.49. Man-1.6f

sed -i.bak 's/-is/&R/' configure
sed -i.bak 's%MANPATH./usr/man%#&%' src/man.conf.in
./configure \
	-default \
	-confdir=/etc
make
make DESTDIR=$PM_DEST install

7.50. Make-3.81

./configure
make
make check
make DESTDIR=$PM_DEST install

7.51. Module-Init-Tools-3.4.1

./configure
make check DOCBOOKTOMAN=:
make maintainer-clean
patch -p1 -i $TT_PFX/src/patches/module-init-tools-3.4-manpages-1.patch

./configure --exec-prefix=/ --enable-zlib
make
make INSTALL=install DESTDIR=$PM_DEST install

Rationale Notes

  • Testing kernel module handling in a live kernel cannot be done easily for obvious reasons. Therefore the Module-Init-Tools developers have devised a custom testsuite procedure that involves separately compiling the package with a set of stubs (see testing.h). The net result of this means we must first run the testsuite, perform a `make distclean' then compile the package for real.

  • Please read the mailing list thread starting with this post for some rationale behind the above build commands.

7.52. Patch-2.5.4

./configure
make
make prefix=$PM_DEST/usr install

7.53. Psmisc-22.6

./configure
make
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/bin
mv -v $PM_DEST/usr/bin/{fuser,killall} $PM_DEST/bin

7.54. Shadow-4.1.2.2

[[ $GLIBC_VER == 2.3* ]] &&
	sed -i.bak '1i #include <sys/types.h>' lib/{pw,group}io.h

./configure \
	--sysconfdir=/etc
make

find man -name Makefile | \
	xargs sed -i.bak \
		-e 's/groups\.1 //' \
		-e 's/su\.1\( \|$\)//' \
		-e 's/suauth\.5 //'
make DESTDIR=$PM_DEST bin_PROGRAMS=login suidbins= install
sed -i \
	-e 's%/var/spool/mail%/var/mail%' \
	-e 's%#MD5_CRYPT_ENAB.no%MD5_CRYPT_ENAB yes%' \
	$PM_DEST/etc/login.defs
sed -i \
	-e '/MAIL/s,yes,no,' \
	$PM_DEST/etc/default/useradd
mv -v $PM_DEST/usr/bin/passwd $PM_DEST/bin

Rationale Notes

  • The `bin_PROGRAMS=login suidbins=' addition to the `make install' invocation is used to suppress installation of `groups' and `su'. This is because we have opted to use the versions from Coreutils instead. In the case of `su', please read this mailing list post for some rationale discussion. If you would rather use the `su' from Shadow, replace the installation line above with make DESTDIR=$PM_DEST bin_PROGRAMS="login su" install. You would also want to adjust the sed to `man/Makefile' to ensure installation of the su related man pages.

7.55. Sysklogd-1.5

make
mkdir -pv $PM_DEST/{etc,usr/{share/man/man{5,8},sbin}}
make prefix=$PM_DEST install

cat > $PM_DEST/etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf

auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *

# End /etc/syslog.conf
EOF

7.56. Sysvinit-2.86

make -C src
mkdir -pv $PM_DEST/{{,s}bin,etc,usr/{{bin,include},share/man/man{1,5,8}}}
make -C src ROOT=$PM_DEST install

cat > $PM_DEST/etc/inittab << "EOF"
# Begin /etc/inittab
id:3:initdefault:

si::sysinit:/etc/rc.d/init.d/rc sysinit

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty tty1 9600
2:2345:respawn:/sbin/agetty tty2 9600
3:2345:respawn:/sbin/agetty tty3 9600
4:2345:respawn:/sbin/agetty tty4 9600
5:2345:respawn:/sbin/agetty tty5 9600
6:2345:respawn:/sbin/agetty tty6 9600
# End /etc/inittab
EOF

7.57. Tar-1.22

./configure \
	--bindir=/bin \
	--libexecdir=/usr/sbin
make
make check
make DESTDIR=$PM_DEST install

7.58. Util-Linux-ng-2.14.2

sed -i.bak \
	's@etc/adjtime@var/lib/hwclock/adjtime@' \
	hwclock/hwclock.c

./configure \
	--enable-arch \
	--enable-write \
	--disable-wall
make
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/var/lib/hwclock

Rationale Notes

7.59. Grub-0.97 (X86 Only)

sed -i.bak '/ufs2/d' stage2/size_test
patch -p1 -i $TT_PFX/src/patches/grub-0.97-ext-256byte-inode-1.patch

./configure default_CFLAGS=yes
make
make check
make DESTDIR=$PM_DEST install
mkdir -pv $PM_DEST/boot/grub
cp -v $PM_DEST/usr/lib/grub/i386-pc/stage{1,2} $PM_DEST/boot/grub

Rationale Notes

  • The sed to `stage2/size_test' is used to work around an issue with a failing ufs2 test. Just ignoring the failure is unsatisfactory because the `size_test' script bails out on the first failure and therefore doesn't test the remaining file systems (fat, e2fs, minix) 2 of which are clearly important.

  • The "256 byte inode" patch could be considered optional in some circumstances. But it's probably best to apply it. More detailed rationale discussion can be found in this mailing list thread.

  • The Grub build is sensitive to non-standard CFLAGS in the environment. Seeing as we have already set our CFLAGS globally in `config.site', we force Grub to use its own defaults by configuring with `default_CFLAGS=yes'.

7.60. Yaboot-1.3.14 (PPC Only)

sed -i 's@usr/local@usr@' Makefile etc/yaboot.conf man/*
make
make ROOT=$PM_DEST MANDIR=share/man install

7.61. Mac-Fdisk-0.1 (PPC Only)

patch -p1 -i ${TT_PFX}/src/patches/mac-fdisk-0.1.orig-debian-2.patch
make
mkdir -pv $PM_DEST/sbin
make DESTDIR=$PM_DEST install

7.62. Hfsutils-3.2.6 (PPC Only)

./configure
make
mkdir -pv $PM_DEST/usr/{bin,share/man/man1}
make prefix=$PM_DEST/usr install

7.63. Fakeroot-1.11 (Optional)

sed -i.bak 's,${srcdir}/tartest,true,' test/t.tar
./configure
make
make check
make DESTDIR=$PM_DEST install

7.64. Libtar-1.2.11 (Optional)

[Note] Note -- Optional Package Management with Pacman

As mentioned earlier in the Temptools phase, you only need the next 2 packages (Libtar and Pacman) if you've implemented Pacman based package management.

patch -p1 -i ${TT_PFX}/src/patches/libtar-1.2.11-2.patch
./configure
make
make DESTDIR=$PM_DEST install

7.65. Pacman-2.9.8 (Optional)

patch -p1 -i ${TT_PFX}/src/patches/pacman-2.9.8-custom-mods-2.patch
patch -p1 -i ${TT_PFX}/src/patches/pacman-2.9.8-sep_install-1.patch
./configure
make
make DESTDIR=$PM_DEST install

7.66. Ogdlutils-20041124 (Optional)

[Note] Note -- Optional Package Management with BPM

As mentioned earlier in the Temptools phase, you only need the next 3 packages (Ogdlutils, Cpio and BPM) if you've implemented BPM based package management.

make -C c libogdl gpath -j1
mkdir -pv $PM_DEST/usr/bin
cp -v c/gpath $PM_DEST/usr/bin

7.67. Cpio-2.9 (Optional)

./configure \
	--enable-mt \
	--with-rmt=/usr/sbin/rmt
make
make check
make DESTDIR=$PM_DEST rmtdir= install

7.68. BPM-1.7 (Optional)

make DESTDIR=$PM_DEST install