changeset 685:90ab1a1f4db5

Teach build not to rebuild base architecture toolchains. Factor out some common code while there.
author Rob Landley <rob@landley.net>
date Wed, 01 Apr 2009 04:11:44 -0500
parents 222886c9b3f5
children 17f24bc1214d
files cross-compiler.sh mini-native.sh sources/functions.sh
diffstat 3 files changed, 57 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/cross-compiler.sh	Wed Apr 01 00:06:08 2009 -0500
+++ b/cross-compiler.sh	Wed Apr 01 04:11:44 2009 -0500
@@ -6,12 +6,14 @@
 
 CROSS="${BUILD}/cross-compiler-${ARCH}"
 
-rm -rf "${CROSS}"
-mkdir -p "${CROSS}" || dienow
+check_for_base_arch cross-compiler || exit 0
 
 echo -e "$CROSS_COLOR"
 echo "=== Building cross compiler"
 
+rm -rf "${CROSS}"
+mkdir -p "${CROSS}" || dienow
+
 [ -z "$CROSS_BUILD_STATIC" ] || STATIC_FLAGS='--static'
 
 # Build and install binutils
@@ -128,23 +130,7 @@
 
 # Tar it up
 
-if [ -z "$SKIP_STAGE_TARBALLS" ]
-then
-  echo -n creating "build/cross-compiler-${ARCH}".tar.bz2 &&
-  cd "${BUILD}" || dienow
-  { tar cjvf "cross-compiler-${ARCH}".tar.bz2 cross-compiler-"${ARCH}" || dienow
-  } | dotprogress
-
-  # If we're building something with a $BASE_ARCH, symlink to actual target.
-
-  if [ "$ARCH" != "$ARCH_NAME" ]
-  then
-    rm -rf "cross-compiler-$ARCH_NAME"{,.tar.bz2} &&
-    ln -s cross-compiler-"$ARCH" cross-compiler-"$ARCH_NAME" &&
-    ln -s cross-compiler-"$ARCH".tar.bz2 cross-compiler-"$ARCH_NAME".tar.bz2 ||
-      dienow
-  fi
-fi
+create_stage_tarball cross-compiler
 
 # A quick hello world program to test the cross-compiler out.
 # Build hello.c dynamic, then static, to verify header/library paths.
--- a/mini-native.sh	Wed Apr 01 00:06:08 2009 -0500
+++ b/mini-native.sh	Wed Apr 01 04:11:44 2009 -0500
@@ -6,6 +6,9 @@
 
 # Purple.  And why not?
 echo -e "$NATIVE_COLOR"
+
+check_for_base_arch mini-native || exit 0
+
 echo "=== Building minimal native development environment"
 
 rm -rf "${NATIVE_ROOT}"
@@ -302,24 +305,7 @@
 "${ARCH}-strip" "${TOOLS}"/{bin/*,sbin/*,libexec/gcc/*/*/*}
 "${ARCH}-strip" --strip-unneeded "${TOOLS}"/lib/*.so
 
-if [ -z "$SKIP_STAGE_TARBALLS" ]
-then
-  echo -n creating mini-native-"${ARCH}".tar.bz2 &&
-  cd "${BUILD}" &&
-  { tar cjvf "mini-native-${ARCH}.tar.bz2" "mini-native-${ARCH}" || dienow
-  } | dotprogress
-
-  # If we're building something with a $BASE_ARCH, symlink to target name.
-
-  if [ "$ARCH" != "$ARCH_NAME" ]
-  then
-    rm -rf "mini-native-$ARCH_NAME"{,.tar.bz2} &&
-    ln -s mini-native-"$ARCH" mini-native-"$ARCH_NAME" &&
-    ln -s mini-native-"$ARCH".tar.bz2 mini-native-"$ARCH_NAME".tar.bz2 ||
-      dienow
-  fi
-fi
-
+create_stage_tarball mini-native
 
 # Color back to normal
 echo -e "\e[0mBuild complete"
--- a/sources/functions.sh	Wed Apr 01 00:06:08 2009 -0500
+++ b/sources/functions.sh	Wed Apr 01 04:11:44 2009 -0500
@@ -416,3 +416,51 @@
     uClibc++ (http://cxx.uclibc.org) $(identify_release uClibc++)
 EOF
 }
+
+# When building with a base architecture, symlink to the base arch name.
+
+function link_arch_name()
+{
+  [ "$ARCH" == "$ARCH_NAME" ] && return 0
+
+  rm -rf "$BUILD/$2" &&
+  ln -s "$1" "$BUILD/$2" || dienow
+}
+
+# Check if this target has a base architecture that's already been built.
+# If so, just tar it up and exit now.
+
+function check_for_base_arch()
+{
+  # If we're building something with a base architecture, symlink to actual
+  # target.
+
+  if [ "$ARCH" != "$ARCH_NAME" ] && [ -e "$BUILD/$1-$ARCH" ]
+  then
+    echo === Using existing $1-"$ARCH"
+
+    link_arch_name $1-{"$ARCH","$ARCH_NAME"}
+    [ -e $1-"$ARCH".tar.bz2 ] &&
+      link_arch_name $1-{"$ARCH","$ARCH_NAME"}.tar.bz2
+
+    return 1
+  fi
+}
+
+function create_stage_tarball()
+{
+  # Handle linking to base architecture if we just built a derivative target.
+
+  cd "$BUILD" || dienow
+  link_arch_name $1-{$ARCH,$ARCH_NAME}
+
+  if [ -z "$SKIP_STAGE_TARBALLS" ]
+  then
+    echo -n creating "$1-${ARCH}".tar.bz2
+
+    { tar cjvf "$1-${ARCH}".tar.bz2 "$1-${ARCH}" || dienow
+    } | dotprogress
+
+    link_arch_name $1-{$ARCH,$ARCH_NAME}.tar.bz2
+  fi
+}