changeset 744:759adf5a0fe9

Refactor so include.sh mostly just sets environment variables. Move read_arch_dir to function and call it explicitly (no more need for $NO_ARCH). Make blank_tempdir a function, called explicitly by stages when needed, with some sanity checks. Insert prerequisite tests to later stages so they can detect failure early and provide an explicit erro rmessage, and have those tests happen before blanking $WORK dir, to preserve debugging info. Make buildall.sh depend on prerequisite tests rather than trying to avoid calling later stages (and thus do flow control from asynchronous context). Add FAIL_QUIET option so buildall.sh doesn't spam the log with the new prerequisite error messages.
author Rob Landley <rob@landley.net>
date Thu, 11 Jun 2009 05:42:51 -0500
parents 5e745e03408a
children 4abea1d0914f
files build.sh buildall.sh cross-compiler.sh download.sh host-tools.sh root-filesystem.sh run-from-build.sh sources/functions.sh sources/include.sh system-image.sh
diffstat 10 files changed, 171 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/build.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -5,7 +5,9 @@
 if [ $# -eq 0 ]
 then
   echo "Usage: $0 ARCH [ARCH...]"
-  sources/include.sh
+  . sources/include.sh
+  read_arch_dir
+  
   exit 1
 fi
 
--- a/buildall.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/buildall.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -11,6 +11,7 @@
   ARCHES="$(cd sources/targets/; ls | grep -v '^hw-')"
 [ -z "$ALLARCHES" ] &&
   ALLARCHES="${ARCHES} $(cd sources/targets; ls | grep '^hw-')"
+export FAIL_QUIET=1
 
 DO_SKIP_STAGE_TARBALLS="$SKIP_STAGE_TARBALLS"
 [ ! -z "$CROSS_COMPILERS_EH" ] && DO_SKIP_STAGE_TARBALLS=1
@@ -83,7 +84,7 @@
 
   for i in ${ARCHES}
   do
-    mv build/{root-filesystem-$i,cross-compiler-$i} &&
+    mv build/{root-filesystem-$i,cross-compiler-$i} 2>/dev/null &&
     doforklog tar cjfC build/cross-compiler-$i.tar.bz2 build cross-compiler-$i
   done
 
@@ -107,7 +108,7 @@
 
   for i in ${ARCHES}
   do
-    mv build/{root-filesystem-$i,natemp-$i} &&
+    mv build/{root-filesystem-$i,natemp-$i} 2>/dev/null &&
     doforklog tar cjfC build/native-compiler-$i.tar.bz2 build/natemp-"$i" .
   done
 
@@ -120,8 +121,7 @@
 
 for i in ${ARCHES}
 do
-  [ -f "build/cross-compiler-$i.tar.bz2" ] &&
-    LOG=build/root-filesystem-$i.txt doforklog ./root-filesystem.sh $i
+  LOG=build/root-filesystem-$i.txt doforklog ./root-filesystem.sh $i
 done
 
 wait4background
@@ -133,4 +133,11 @@
   LOG=build/system-image-$i.txt doforklog ./system-image.sh $i
 done
 
+# Run smoketest.sh for each non-hw target.
+
+for i in ${ARCHES}
+do
+  LOG=build/smoketest-$i.txt doforklog ./smoketest.sh $i
+done
+
 wait4background 0
--- a/cross-compiler.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/cross-compiler.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -4,15 +4,22 @@
 
 source sources/include.sh || exit 1
 
-CROSS="${BUILD}/cross-compiler-${ARCH}"
+# Parse the sources/targets/$1 directory
+
+read_arch_dir "$1"
+
+# If this target has a base architecture that's already been built, use that.
 
 check_for_base_arch cross-compiler || exit 0
 
+# Ok, we have work to do.  Announce start of stage.
+
 echo -e "$CROSS_COLOR"
 echo "=== Building cross compiler"
 
-rm -rf "${CROSS}"
-mkdir -p "${CROSS}" || dienow
+CROSS="${BUILD}/cross-compiler-${ARCH}"
+blank_tempdir "$CROSS"
+blank_tempdir "$WORK"
 
 # Build and install binutils
 
--- a/download.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/download.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -1,15 +1,14 @@
 #!/bin/bash
 
+# Download everything we haven't already got a copy of.
+
 # Use "./download.sh --extract" to extract all tarballs.
 
-NO_ARCH=none
+[ "$1" == "--extract" ] && EXTRACT_ALL=yes
+
 source sources/include.sh || exit 1
 
-[ "$1" == "--extract" ] && EXTRACT_ALL=yes
-
-# Download everything we haven't already got a copy of.
-
-# Note: set SHA1= blank to skip checksum validation.
+mkdir -p "$SRCDIR" || dienow
 
 echo -e "$DOWNLOAD_COLOR"
 echo "=== Download source code."
@@ -18,8 +17,10 @@
 
 MIRROR_LIST="http://impactlinux.com/firmware/mirror http://landley.net/code/firmware/mirror http://127.0.0.1/code/firmware/mirror"
 
-# Note: a blank SHA1 value means accept anything, and the download script
-# prints out the sha1 of such files after downloading it, so to update to
+# Note: set SHA1= blank to skip checksum validation.
+
+# A blank SHA1 value means accept anything, and the download script
+# prints out the sha1 of such files after downloading it.  So to update to
 # a new version of a file, set SHA1= and update the URL, run ./download.sh,
 # then cut and paste the sha1 from the output and run it again to confirm.
 
--- a/host-tools.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/host-tools.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -2,11 +2,6 @@
 
 # Get lots of predefined environment variables and shell functions.
 
-# Tell bash not to cache the $PATH to anything, so busybox/toybox utilities
-# get used immediately even if a different executable was found last lookup.
-set +h
-
-NO_ARCH=1
 source sources/include.sh || exit 1
 
 echo -e "$HOST_COLOR"
@@ -14,10 +9,11 @@
 
 export LC_ALL=C
 
+blank_tempdir "${WORK}"
 mkdir -p "${HOSTTOOLS}" || dienow
 
 # If we want to record the host command lines, so we know exactly what commands
-# the build uses.
+# the build uses, set up a wrapper that does that.
 
 if [ ! -z "$RECORD_COMMANDS" ]
 then
@@ -26,8 +22,7 @@
     echo setup wrapdir
 
     # Build the wrapper and install it into build/wrapdir/wrappy
-    rm -rf "$BUILD/wrapdir"
-    mkdir "$BUILD/wrapdir" &&
+    blank_tempdir "$BUILD/wrapdir"
     $CC -Os "$SOURCES/toys/wrappy.c" -o "$BUILD/wrapdir/wrappy"  || dienow
 
     # Loop through each $PATH element and create a symlink to the wrapper with
@@ -75,7 +70,7 @@
   # compiler for the target, but we don't build a host toolchain.  We use the
   # one that's already there.
 
-  for i in ar as nm cc gcc make ld
+  for i in ar as nm cc make ld gcc
   do
     [ ! -f "${HOSTTOOLS}/$i" ] &&
       (ln -s `PATH="$OLDPATH" which $i` "${HOSTTOOLS}/$i" || dienow)
--- a/root-filesystem.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/root-filesystem.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -4,14 +4,29 @@
 
 source sources/include.sh || exit 1
 
-# Purple.  And why not?
-echo -e "$NATIVE_COLOR"
+# Parse the sources/targets/$1 directory
+
+read_arch_dir "$1"
+
+# If this target has a base architecture that's already been built, use that.
 
 check_for_base_arch root-filesystem || exit 0
 
+# Die if our prerequisite isn't there.
+
+if [ -z "$(which "$ARCH-cc")" ]
+then
+  [ -z "$FAIL_QUIET" ] && echo No "$ARCH-cc" in '$PATH'. >&2
+  exit 1
+fi
+
+# Announce start of stage.
+
+echo -e "$NATIVE_COLOR"
 echo "=== Building minimal native development environment"
 
-rm -rf "${NATIVE_ROOT}"
+blank_tempdir "$WORK"
+blank_tempdir "$NATIVE_ROOT"
 
 # Determine which directory layout we're using
 
--- a/run-from-build.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/run-from-build.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -2,7 +2,15 @@
 
 source sources/include.sh || exit 1
 
-cd "${BUILD}/system-image-$ARCH_NAME" || exit 1
+SYSDIR="${BUILD}/system-image-$ARCH_NAME"
+
+if [ ! -f "$SYSDIR/run-emulator.sh" ]
+then
+  [ -z "$FAIL_QUIET" ] && echo "No $SYSDIR/run-emulator.sh" >&2
+  exit 1
+fi
+
+cd "$SYSDIR" || exit 1
 
 # A little paranoia.
 [ -f "image-${ARCH}.ext2" ] && fsck.ext2 -y "image-${ARCH}.ext2" </dev/null
--- a/sources/functions.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/sources/functions.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -1,5 +1,75 @@
 # Lots of reusable functions.  This file is sourced, not run.
 
+function read_arch_dir()
+{
+  # Get target platform from first command line argument.
+
+  ARCH_NAME="$1"
+  if [ ! -f "${TOP}/sources/targets/${ARCH_NAME}/settings" ]
+  then
+    echo "Supported architectures: "
+    (cd "${TOP}/sources/targets" && ls)
+
+    exit 1
+  fi
+
+  # Read the relevant config file.
+
+  ARCH="$ARCH_NAME"
+  CONFIG_DIR="${TOP}/sources/targets"
+  source "${CONFIG_DIR}/${ARCH}/settings"
+
+  # Which platform are we building for?
+
+  export WORK="${BUILD}/temp-$ARCH_NAME"
+
+  # Say "unknown" in two different ways so it doesn't assume we're NOT
+  # cross compiling when the host and target are the same processor.  (If host
+  # and target match, the binutils/gcc/make builds won't use the cross compiler
+  # during root-filesystem.sh, and the host compiler links binaries against the
+  # wrong libc.)
+  [ -z "$CROSS_HOST" ] && export CROSS_HOST=`uname -m`-walrus-linux
+  if [ -z "$CROSS_TARGET" ]
+  then
+    export CROSS_TARGET=${ARCH}-unknown-linux
+  else
+    [ -z "$FROM_HOST" ] && FROM_HOST="${CROSS_TARGET}"
+  fi
+
+  # Override FROM_ARCH to perform a canadian cross in root-filesystem.sh
+
+  if [ -z "$FROM_ARCH" ]
+  then
+    FROM_ARCH="${ARCH}"
+  else
+    [ -z "$PROGRAM_PREFIX" ] && PROGRAM_PREFIX="${ARCH}-"
+  fi
+  [ -z "$FROM_HOST" ] && FROM_HOST="${FROM_ARCH}-thingy-linux"
+
+  # Setup directories and add the cross compiler to the start of the path.
+
+  [ -z "$NATIVE_ROOT" ] && export NATIVE_ROOT="${BUILD}/root-filesystem-$ARCH"
+  export PATH="${BUILD}/cross-compiler-$ARCH/bin:$PATH"
+  [ "$FROM_ARCH" != "$ARCH" ] &&
+    PATH="${BUILD}/cross-compiler-${FROM_ARCH}/bin:$PATH"
+
+  [ ! -z "${NATIVE_TOOLSDIR}" ] && TOOLS="${NATIVE_ROOT}/tools" ||
+    TOOLS="${NATIVE_ROOT}/usr"
+
+  return 0
+}
+
+function blank_tempdir()
+{
+  # sanity test: never rm -rf something we don't own.
+  [ -z "$1" ] && dienow
+  touch -c "$1" || dienow
+
+  # Delete old directory, create new one.
+  rm -rf "$1"
+  mkdir -p "$1" || dienow
+}
+
 # Figure out if we're using the stable or unstable versions of a package.
 
 function unstable()
--- a/sources/include.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/sources/include.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -1,9 +1,19 @@
 #!/bin/bash
 
+umask 022
+
+# Tell bash not to cache the $PATH because we modify it.  Without this, bash
+# won't find new executables added after startup.
+set +h
+
+# Include two other files:
 
 [ -e config ] && source config
+source sources/functions.sh
 
-source sources/functions.sh
+# The rest of this file is devoted to setting environment variables.
+
+unset CFLAGS CXXFLAGS
 
 # What host compiler should we use?
 
@@ -17,10 +27,7 @@
   [ "$CPUS" -lt 1 ] && CPUS=1
 fi
 
-umask 022
-unset CFLAGS CXXFLAGS
-
-# Find/create directories
+# Where are our working directories?
 
 TOP=`pwd`
 export SOURCES="${TOP}/sources"
@@ -28,7 +35,10 @@
 export BUILD="${TOP}/build"
 export HOSTTOOLS="${BUILD}/host"
 
-mkdir -p "${SRCDIR}" || dienow
+# Set a default non-arch
+
+ARCH_NAME=host
+export WORK="${BUILD}/host-temp"
 
 # Retain old $PATH in case we re-run host-tools.sh with different options.
 
@@ -61,77 +71,6 @@
   PATH="$BUILD/wrapdir"
 fi
 
-# Tell bash not to cache the $PATH because we modify it.  Without this, bash
-# won't find new executables added after startup.
-set +h
-
-# Get target platform from first command line argument.
-
-if [ -z "$NO_ARCH" ]
-then
-  ARCH_NAME="$1"
-  if [ ! -f "${TOP}/sources/targets/${ARCH_NAME}/settings" ]
-  then
-    echo "Supported architectures: "
-    (cd "${TOP}/sources/targets" && ls)
-    exit 1
-  fi
-
-  # Read the relevant config file.
-
-  ARCH="$ARCH_NAME"
-  CONFIG_DIR="${TOP}/sources/targets"
-  source "${CONFIG_DIR}/${ARCH}/settings"
-
-  # Which platform are we building for?
-
-  export WORK="${BUILD}/temp-$ARCH_NAME"
-  rm -rf "${WORK}"
-  mkdir -p "${WORK}" || dienow
-
-  # Say "unknown" in two different ways so it doesn't assume we're NOT
-  # cross compiling when the host and target are the same processor.  (If host
-  # and target match, the binutils/gcc/make builds won't use the cross compiler
-  # during root-filesystem.sh, and the host compiler links binaries against the
-  # wrong libc.)
-  [ -z "$CROSS_HOST" ] && export CROSS_HOST=`uname -m`-walrus-linux
-  if [ -z "$CROSS_TARGET" ]
-  then
-    export CROSS_TARGET=${ARCH}-unknown-linux
-  else
-    [ -z "$FROM_HOST" ] && FROM_HOST="${CROSS_TARGET}"
-  fi
-
-  # Override FROM_ARCH to perform a canadian cross in root-filesystem.sh
-
-  if [ -z "$FROM_ARCH" ]
-  then
-    FROM_ARCH="${ARCH}"
-  else
-    [ -z "$PROGRAM_PREFIX" ] && PROGRAM_PREFIX="${ARCH}-"
-  fi
-  [ -z "$FROM_HOST" ] && FROM_HOST="${FROM_ARCH}-thingy-linux"
-
-  # Setup directories and add the cross compiler to the start of the path.
-
-  [ -z "$NATIVE_ROOT" ] && export NATIVE_ROOT="${BUILD}/root-filesystem-$ARCH"
-  export PATH="${BUILD}/cross-compiler-$ARCH/bin:$PATH"
-  [ "$FROM_ARCH" != "$ARCH" ] &&
-    PATH="${BUILD}/cross-compiler-${FROM_ARCH}/bin:$PATH"
-
-  if [ ! -z "${NATIVE_TOOLSDIR}" ]
-  then
-    TOOLS="${NATIVE_ROOT}/tools"
-  else
-    TOOLS="${NATIVE_ROOT}/usr"
-  fi
-else
-  HW_ARCH=host
-  export WORK="${BUILD}/host-temp"
-  mkdir -p "${WORK}" || dienow
-fi
-
-
 [ ! -z "$BUILD_VERBOSE" ] && VERBOSITY="V=1"
 
 # This is an if instead of && so the exit code of include.sh is reliably 0
--- a/system-image.sh	Thu Jun 11 00:26:15 2009 -0500
+++ b/system-image.sh	Thu Jun 11 05:42:51 2009 -0500
@@ -4,6 +4,27 @@
 
 source sources/include.sh || exit 1
 
+# Parse the sources/targets/$1 directory
+
+read_arch_dir "$1"
+
+# Do we have our prerequisites?
+
+if [ ! -d "$NATIVE_ROOT" ]
+then
+  [ -z "$FAIL_QUIET" ] && echo No "$NATIVE_ROOT" >&2
+  exit 1
+fi
+
+# Announce start of stage.
+
+echo -e "$PACKAGE_COLOR"
+echo "=== Packaging system image from root-filesystem"
+
+SYSIMAGE="${BUILD}/system-image-${ARCH_NAME}"
+blank_tempdir "$SYSIMAGE"
+blank_tempdir "$WORK"
+
 # A little song and dance so we run in our own session, to prevent the "kill 0"
 # below from taking down the shell that called us.
 
@@ -19,21 +40,11 @@
   exec "$WORK/mysetsid" "$0" "$@"
 fi
 
-echo -e "$PACKAGE_COLOR"
-echo "=== Packaging system image from root-filesystem"
-
 [ -z "$SYSIMAGE_TYPE" ] && SYSIMAGE_TYPE=squashfs
 
-SYSIMAGE="${BUILD}/system-image-${ARCH_NAME}"
-
 TOOLSDIR=tools
 [ -z "$NATIVE_TOOLSDIR" ] && TOOLSDIR=usr
 
-# Flush old system-image directory
-
-rm -rf "${SYSIMAGE}"
-mkdir -p "${SYSIMAGE}" || dienow
-
 # This next bit is a little complicated; we generate the root filesystem image
 # in the middle of building a kernel.  This is necessary to embed an
 # initramfs in the kernel, and allows us to parallelize the kernel build with