From d4aae43e79251801c6ac9e8c67eefac9dbc185e8 Mon Sep 17 00:00:00 2001
From: Duncan Sands <baldrick@free.fr>
Date: Fri, 23 Jan 2009 08:42:38 +0000
Subject: [PATCH] Patch to build llvm with srcdir != objdir from llvm-top.  By
 Michael Schuerig, with some small tweaks to make the "don't configure if
 already configured" logic work.

llvm-svn: 62842
---
 llvm/ModuleInfo.txt        |  4 ++--
 llvm/build-for-llvm-top.sh | 18 ++++++++++++++----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/llvm/ModuleInfo.txt b/llvm/ModuleInfo.txt
index ec9da652cb8f..5a1d8b85ad0b 100644
--- a/llvm/ModuleInfo.txt
+++ b/llvm/ModuleInfo.txt
@@ -1,4 +1,4 @@
 DepModule: 
 BuildCmd: ./build-for-llvm-top.sh
-CleanCmd: make clean
-InstallCmd: make install
+CleanCmd: make clean -C ../build.llvm
+InstallCmd: make install -C ../build.llvm
diff --git a/llvm/build-for-llvm-top.sh b/llvm/build-for-llvm-top.sh
index 2a68c79965b8..78e3ed87f092 100755
--- a/llvm/build-for-llvm-top.sh
+++ b/llvm/build-for-llvm-top.sh
@@ -9,9 +9,16 @@
 # variables. 
 process_arguments "$@"
 
+# First, see if the build directory is there. If not, create it.
+build_dir="$LLVM_TOP/build.llvm"
+if test ! -d "$build_dir" ; then
+  mkdir -p "$build_dir"
+fi
+
 # See if we have previously been configured by sensing the presence
 # of the config.status scripts
-if test ! -x "config.status" ; then
+config_status="$build_dir/config.status"
+if test ! -f "$config_status" -o "$config_status" -ot "$0" ; then
   # We must configure so build a list of configure options
   config_options="--prefix=$PREFIX --with-llvmgccdir=$PREFIX"
   if test "$OPTIMIZED" -eq 1 ; then
@@ -45,12 +52,15 @@ if test ! -x "config.status" ; then
     config_options="$config_options --disable-threads"
   fi
   config_options="$config_options $OPTIONS_DASH $OPTIONS_DASH_DASH"
+  src_dir=`pwd`
+  cd "$build_dir"
   msg 0 Configuring $module with:
-  msg 0 "  ./configure" $config_options
-  $LLVM_TOP/llvm/configure $config_options || \
-    die $? "Configuring llvm module failed"
+  msg 0 "  $src_dir/configure" $config_options
+  $src_dir/configure $config_options || \
+    die $? "Configuring $module module failed"
 else
   msg 0 Module $module already configured, ignoring configure options.
+  cd "$build_dir"
 fi
 
 msg 0 Building $module with: