changeset 1116:2b68517f5b62

Break out simple-root-filesystem.sh and root-filesystem.sh (adding native-compiler.sh output), and use NO_NATIVE_COMPILER to determine which to use. Rename STATIC_CC_HOST to CROSS_HOST_ARCH.
author Rob Landley <rob@landley.net>
date Wed, 16 Jun 2010 08:11:51 -0500
parents 81bae2e7bc66
children 725e41d66379
files build.sh config root-filesystem.sh simple-cross-compiler.sh simple-root-filesystem.sh system-image.sh
diffstat 6 files changed, 141 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Wed Jun 16 08:03:12 2010 -0500
+++ b/build.sh	Wed Jun 16 08:11:51 2010 -0500
@@ -2,6 +2,12 @@
 
 # Run all the steps needed to build a system image from scratch.
 
+# Simplest: download, simple-cross-compiler, simple-root-filesystem,
+# system-image.
+
+# More likely: download, host-tools, simple-cross-compiler, cross-compiler,
+# native-compiler, simple-root-filesystem, root-filesystem, system-image
+
 # If run with no arguments, list architectures.
 
 if [ $# -ne 1 ]
@@ -17,7 +23,11 @@
 [ -z "$BUILD" ] && BUILD="build"
 
 # A function to skip stages that have already been done (because the
-# tarball they create is already there).
+# tarball they create is already there).  Stages delete the tarballs of
+# later stages as a simple form of dependency tracking.
+
+# If you need to rebuild a stage and everything after it, delete its
+# tarball out of "build" and re-run build.sh.
 
 not_already()
 {
@@ -30,12 +40,16 @@
   return 0
 }
 
-# Download source code and build host tools.
+# The first two stages (download.sh and host-tools.sh) are architecture
+# independent.  In order to allow multiple builds in parallel, re-running
+# them after they've already completed must be a safe NOP.
+
+# Download source code.
 
 time ./download.sh || exit 1
 
-# host-tools populates one directory with every command the build needs,
-# so we can ditch the old $PATH afterwards.
+# Build host tools.  This populates a single directory with every command the
+# build needs, so we can ditch the host's $PATH afterwards.
 
 time ./host-tools.sh || exit 1
 
@@ -45,43 +59,25 @@
 then
   # If we need to build cross compiler, assume root filesystem is stale.
 
-  rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2"
-  time ./simple-cross-compiler.sh "$ARCH" || exit 1
+  rm -rf "$BUILD/simple-root-filesystem-$ARCH.tar.bz2"
 
-  if [ ! -z "$CROSS_SMOKE_TEST" ]
-  then
-    sources/more/cross-smoke-test.sh "$ARCH" || exit 1
-  fi
+  time ./simple-cross-compiler.sh "$ARCH" || exit 1
 fi
 
 # Optionally, we can build a more capable statically linked compiler via
 # canadian cross.  (It's more powerful than we need here, but if you're going
 # to use the cross compiler in other contexts this is probably what you want.)
 
-if [ ! -z "$STATIC_CC_HOST" ] && not_already cross-compiler
+if [ ! -z "$CROSS_HOST_ARCH" ] && not_already cross-compiler
 then
-
-  # These are statically linked against uClibc on the host (for portability),
-  # built --with-shared, and have uClibc++ installed.
+  rm -rf "$BUILD/simple-root-filesystem-$ARCH.tar.bz2"
 
-  # To build each of these we need two existing cross compilers: one for
-  # the host (to build the executables) and one for the target (to build
-  # the libraries).
-
-  BUILD_STATIC=all HOST_ARCH="$STATIC_CC_HOST" STAGE_NAME=cross-compiler \
-    ./native-compiler.sh "$ARCH" || exit 1
-
-  if [ ! -z "$CROSS_SMOKE_TEST" ]
-  then
-    sources/more/cross-smoke-test.sh "$ARCH" || exit 1
-  fi
+  ./cross_compiler.sh "$ARCH" || exit 1
 fi
 
-# Build a native compiler.  It's statically linked by default so it can be
+# Build a native compiler.  It's statically linked by default so it can
 # run on an arbitrary host system.
 
-# If this compiler exists, root-filesystem will pick it up and incorpoate it.
-
 if not_already native-compiler && [ -z "$NO_NATIVE_COMPILER" ]
 then
   rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2"
@@ -91,29 +87,25 @@
 
 # Do we need to build the root filesystem?
 
-if not_already root-filesystem
+if not_already simple-root-filesystem
 then
+  # If we need to build root filesystem, assume root-filesystem and
+  # system-image are stale.
 
-  # If we need to build root filesystem, assume system image is stale.
+  rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2"
+  rm -rf "$BUILD/system-image-$ARCH.tar.bz2"
 
-  rm -rf "$BUILD/system-image-$ARCH.tar.bz2"
-  time ./root-filesystem.sh "$ARCH" || exit 1
+  time ./simple-root-filesystem.sh "$ARCH" || exit 1
+
 fi
 
 # Install the native compiler into the root filesystem (if any).
 
-if [ -d "$BUILD/native-compiler-$ARCH" ]
+if not_already root-filesystem && [ -z "$NO_NATIVE_COMPILER" ]
 then
-  # Remove shared libraries copied from cross compiler.
-
-  rm -rf "$BUILD/root-filesystem-$ARCH/usr/lib" 2>/dev/null
+  rm -rf "$BUILD/system-image-$ARCH.tar.bz2"
 
-  # Copy native compiler, but do not overwrite existing files (which could
-  # do bad things to busybox).
-
-  [ -z "$ROOT_NODIRS" ] && USRDIR="/usr" || USRDIR="" 
-  yes 'n' | cp -ia "$BUILD/native-compiler-$ARCH/." \
-    "$BUILD/root-filesystem-$ARCH$USRDIR" || dienow
+  time ./root-filesystem.sh "$ARCH" || exit 1
 fi
 
 if not_already system-image
--- a/config	Wed Jun 16 08:03:12 2010 -0500
+++ b/config	Wed Jun 16 08:11:51 2010 -0500
@@ -35,7 +35,7 @@
 # Note that most x86_64 systems can run a statically linked i686 binary even
 # if they don't have the 32-bit libraries installed, so that's a good default.
 
-# export STATIC_CC_HOST=i686
+# export CROSS_HOST_ARCH=i686
 
 # This may be set by the target's "details" file, but you can override it here.
 # You can set it to ext2, initramfs, or squashfs.  It defaults to squashfs
--- a/root-filesystem.sh	Wed Jun 16 08:03:12 2010 -0500
+++ b/root-filesystem.sh	Wed Jun 16 08:11:51 2010 -0500
@@ -1,76 +1,26 @@
 #!/bin/bash
 
-# Build a root filesystem for a given target.
+# Combine simple-root-filesystem and native-compiler.
 
-source sources/include.sh || exit 1
-read_arch_dir "$1"
-check_for_base_arch || exit 0
-check_prerequisite "${ARCH}-cc"
-
-# Announce start of stage.
-
-echo "=== Building $STAGE_NAME"
-
-# Determine which directory layout we're using
+. sources/include.sh || exit 1
 
-if [ -z "$ROOT_NODIRS" ]
-then
-  mkdir -p "$STAGE_DIR"/{tmp,proc,sys,dev,home,mnt} &&
-  chmod a+rwxt "$STAGE_DIR/tmp" || dienow
-  for i in bin sbin lib etc
-  do
-    mkdir -p "$STAGE_DIR/usr/$i" &&
-    ln -s "usr/$i" "$STAGE_DIR/$i" || dienow
-  done
-  ln -s share/man "$STAGE_DIR/usr/man" || dienow
+read_arch_dir "$1"
 
-  STAGE_DIR="$STAGE_DIR/usr"
-else
-  mkdir -p "$STAGE_DIR/bin" || dienow
-fi
-
-# Copy qemu setup script and so on.
-
-cp -r "${SOURCES}/native-root/." "$STAGE_DIR/" &&
-cp "$SRCDIR"/MANIFEST "$STAGE_DIR/src" || dienow
-
-# Build busybox and toybox
+[ ! -d "$BUILD/simple-root-filesystem-$ARCH" ] &&
+  echo "No $BUILD/simple-root-filesystem-$ARCH" >&2 &&
+  exit 1
 
-build_section busybox
-cp "$WORK"/config-busybox "$STAGE_DIR"/src || dienow
-build_section toybox
-
-# Put statically and dynamically linked hello world programs on there for
-# test purposes.
+[ ! -d "$BUILD/native-compiler-$ARCH" ] &&
+  echo "No $BUILD/native-compiler-$ARCH" >&2 &&
+  exit 1
 
-"${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -o "$STAGE_DIR/bin/hello-dynamic" || dienow
-
-if [ "$BUILD_STATIC" != none ]
-then
-  "${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -static -o "$STAGE_DIR/bin/hello-static" || dienow
-fi
-
-# Do we need shared libraries?
+# Remove shared libraries copied from cross compiler.
 
-if [ "$BUILD_STATIC" != all ]
-then
-  echo Copying compiler libraries...
-  mkdir -p "$STAGE_DIR/lib" || dienow
-  (path_search \
-     "$("$ARCH-cc" --print-search-dirs | sed -n 's/^libraries: =*//p')" \
-      "*.so*" 'cp -H "$DIR/$FILE" "$STAGE_DIR/lib/$FILE"' \
-      || dienow) | dotprogress
-fi
+rm -rf "$BUILD/root-filesystem-$ARCH/usr/lib" 2>/dev/null
 
-# Clean up and package the result
+# Copy native compiler, but do not overwrite existing files (which could
+# do bad things to busybox).
 
-if [ -z "$SKIP_STRIP" ]
-then
-  "${ARCH}-strip" "$STAGE_DIR"/{bin/*,sbin/*,libexec/gcc/*/*/*}
-  "${ARCH}-strip" --strip-unneeded "$STAGE_DIR"/lib/*.so
-fi
-
-create_stage_tarball
-
-# Color back to normal
-echo -e "\e[0mBuild complete"
+[ -z "$ROOT_NODIRS" ] && USRDIR="/usr" || USRDIR=""
+yes 'n' | cp -ia "$BUILD/native-compiler-$ARCH/." \
+  "$BUILD/root-filesystem-$ARCH$USRDIR" 2>/dev/null || dienow
--- a/simple-cross-compiler.sh	Wed Jun 16 08:03:12 2010 -0500
+++ b/simple-cross-compiler.sh	Wed Jun 16 08:11:51 2010 -0500
@@ -70,6 +70,13 @@
 "${ARCH}-gcc" -Os "${SOURCES}/toys/hello.c" -o "$WORK"/hello &&
 "${ARCH}-gcc" -Os -static "${SOURCES}/toys/hello.c" -o "$WORK"/hello || dienow
 
+# Does the hello world we just built actually run?
+
+if [ ! -z "$CROSS_SMOKE_TEST" ]
+then
+  sources/more/cross-smoke-test.sh "$ARCH" || exit 1
+fi
+
 # Tar it up
 
 create_stage_tarball
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simple-root-filesystem.sh	Wed Jun 16 08:11:51 2010 -0500
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Build a basic busybox+uClibc root filesystem for a given target.
+
+source sources/include.sh || exit 1
+read_arch_dir "$1"
+check_for_base_arch || exit 0
+check_prerequisite "${ARCH}-cc"
+
+# Announce start of stage.
+
+echo "=== Building $STAGE_NAME"
+
+# Determine which directory layout we're using
+
+if [ -z "$ROOT_NODIRS" ]
+then
+  mkdir -p "$STAGE_DIR"/{tmp,proc,sys,dev,home,mnt} &&
+  chmod a+rwxt "$STAGE_DIR/tmp" || dienow
+  for i in bin sbin lib etc
+  do
+    mkdir -p "$STAGE_DIR/usr/$i" &&
+    ln -s "usr/$i" "$STAGE_DIR/$i" || dienow
+  done
+  ln -s share/man "$STAGE_DIR/usr/man" || dienow
+
+  STAGE_DIR="$STAGE_DIR/usr"
+else
+  mkdir -p "$STAGE_DIR/bin" || dienow
+fi
+
+# Copy qemu setup script and so on.
+
+cp -r "${SOURCES}/native-root/." "$STAGE_DIR/" &&
+cp "$SRCDIR"/MANIFEST "$STAGE_DIR/src" || dienow
+
+# Build busybox and toybox
+
+build_section busybox
+cp "$WORK"/config-busybox "$STAGE_DIR"/src || dienow
+build_section toybox
+
+# Put statically and dynamically linked hello world programs on there for
+# test purposes.
+
+"${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -o "$STAGE_DIR/bin/hello-dynamic" || dienow
+
+if [ "$BUILD_STATIC" != none ]
+then
+  "${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -static -o "$STAGE_DIR/bin/hello-static" || dienow
+fi
+
+# Do we need shared libraries?
+
+if [ "$BUILD_STATIC" != all ]
+then
+  echo Copying compiler libraries...
+  mkdir -p "$STAGE_DIR/lib" || dienow
+  (path_search \
+     "$("$ARCH-cc" --print-search-dirs | sed -n 's/^libraries: =*//p')" \
+      "*.so*" 'cp -H "$DIR/$FILE" "$STAGE_DIR/lib/$FILE"' \
+      || dienow) | dotprogress
+fi
+
+# Clean up and package the result
+
+if [ -z "$SKIP_STRIP" ]
+then
+  "${ARCH}-strip" "$STAGE_DIR"/{bin/*,sbin/*,libexec/gcc/*/*/*}
+  "${ARCH}-strip" --strip-unneeded "$STAGE_DIR"/lib/*.so
+fi
+
+create_stage_tarball
+
+# Color back to normal
+echo -e "\e[0mBuild complete"
--- a/system-image.sh	Wed Jun 16 08:03:12 2010 -0500
+++ b/system-image.sh	Wed Jun 16 08:11:51 2010 -0500
@@ -11,7 +11,13 @@
 
 # Do we have our prerequisites?
 
-[ -z "$NATIVE_ROOT" ] && NATIVE_ROOT="$BUILD/root-filesystem-$ARCH"
+if [ -z "$NATIVE_ROOT" ]
+then
+  [ -z "$NO_NATIVE_COMPILER" ] &&
+    NATIVE_ROOT="$BUILD/root-filesystem-$ARCH" ||
+    NATIVE_ROOT="$BUILD/simple-root-filesystem-$ARCH"
+fi
+
 if [ ! -d "$NATIVE_ROOT" ]
 then
   [ -z "$FAIL_QUIET" ] && echo No "$NATIVE_ROOT" >&2