changeset 796:5f793a1ca658

Teach host-tools.sh to create multiple symlinks in fallback directories for ccache and distcc.
author Rob Landley <rob@landley.net>
date Fri, 07 Aug 2009 23:52:55 -0500
parents c1bf33329d1f
children bb8333b7a553
files host-tools.sh sources/functions.sh sources/include.sh
diffstat 3 files changed, 61 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/host-tools.sh	Fri Aug 07 13:08:59 2009 -0500
+++ b/host-tools.sh	Fri Aug 07 23:52:55 2009 -0500
@@ -1,6 +1,26 @@
 #!/bin/bash
 
-# Get lots of predefined environment variables and shell functions.
+# This script sets up a known host environment.  It serves a similar purpose
+# to the temporary chroot system in Linux From Scratch chapter 5, isolating
+# the new build from the host system so information from the host doesn't
+# accidentally leak into the target.
+
+# This script populates a build/host directory with busybox and symlinks to
+# the host's toolchain, then adds the other packages (genext2fs, e2fsprogs,
+# squashfs-tools, distcc, and qemu) that might be needed to package and run
+# a system image.  This lets the rest of the build run with the $PATH pointing
+# at the new build/host directory and nothing else.
+
+# The tools provided by this stage are as similar as possible to the ones
+# provided in the final system image.  The fact the system can build under
+# these tools is a good indication that it should be able to rebuild itself
+# under itself.
+
+# This script is optional.  The build runs fine without it, assuming the
+# host has all the necessary packages installed and doesn't have any extra
+# packages (such as libtool, pkg-config, python...) that might provide
+# false information to autoconf or attach themselves as dependencies to
+# the newly generated programs.  (In practice, this can be quite fiddly.)
 
 source sources/include.sh || exit 1
 
@@ -119,16 +139,34 @@
   # and we don't really want to have to care what the host type is, so
   # just use the toolchain that's already there.
 
+  # This is a little more complicated than it needs to be, because the host
+  # toolchain may be using ccache and/or distcc, which means we need every
+  # instance of these tools that occurs in the $PATH, in order, each in its
+  # own fallback directory.
+
   for i in ar as nm cc make ld gcc
   do
-    [ ! -f "${HOSTTOOLS}/$i" ] &&
-      (ln -sf `PATH="$OLDPATH" $HOSTTOOLS/which $i` "${HOSTTOOLS}/$i" || dienow)
+    if [ ! -f "${HOSTTOOLS}/$i" ]
+    then
+      # Loop through each instance, populating fallback directories.
+
+      X=0
+      FALLBACK="$HOSTTOOLS"
+      PATH="$OLDPATH" "$HOSTTOOLS/which" -a "$i" | while read j
+      do
+        mkdir -p "$FALLBACK" &&
+        ln -sf "$j" "$FALLBACK/$i" || dienow
+
+        X=$[$X+1]
+        FALLBACK="$HOSTTOOLS/fallback-$X"
+      done
+    fi
   done
 
   # We now have all the tools we need in $HOSTTOOLS, so trim the $PATH to
   # remove the old ones.
 
-  PATH="${HOSTTOOLS}"
+  PATH="$(hosttools_path)"
 fi
 
 # This is optionally used by root-filesystem to accelerate native builds when
--- a/sources/functions.sh	Fri Aug 07 13:08:59 2009 -0500
+++ b/sources/functions.sh	Fri Aug 07 23:52:55 2009 -0500
@@ -591,3 +591,19 @@
     kill $KIDS 2>/dev/null
   fi
 }
+
+# Create colon-separated path for $HOSTTOOLS and all fallback directories
+# (Fallback directories are to support ccache and distcc on the host.)
+
+function hosttools_path()
+{
+  local X
+
+  echo -n "$HOSTTOOLS"
+  X=1
+  while [ -e "$HOSTTOOLS/fallback-$X" ]
+  do
+    echo -n ":$HOSTTOOLS/fallback-$X"
+    X=$[$X+1]
+  done
+}
--- a/sources/include.sh	Fri Aug 07 13:08:59 2009 -0500
+++ b/sources/include.sh	Fri Aug 07 23:52:55 2009 -0500
@@ -46,13 +46,13 @@
 
 # Adjust $PATH
 
-if [ "$PATH" != "$HOSTTOOLS" ]
+if [ "$PATH" != "$(hosttools_path)" ]
 then
   if [ -f "$HOSTTOOLS/busybox" ]
   then
-    PATH="$HOSTTOOLS"
+    PATH="$(hosttools_path)"
   else
-    PATH="${HOSTTOOLS}:$PATH"
+    PATH="$(hosttools_path):$PATH"
   fi
 fi