+my ($RUN_DIR) = ($0 =~ /^(.*)\/.*$/);
+
+# Find the unix pwd program: we don't want to use the bash builtin, as it does
+# not look through symlinks etc.
+my $PWD = `which pwd`;
+chomp($PWD);
+$PWD = "pwd" if (!-e $PWD);
+
+# Turn the directory into an absolute directory on the file system, also pop up
+# from "bin" into the build or prefix dir.
+my $ABS_RUN_DIR = `cd $RUN_DIR/..; $PWD`;
+chomp($ABS_RUN_DIR);
+
+# Compute the absolute object directory build, e.g. "foo/llvm/Debug".
+my $ABS_OBJ_ROOT = "$LLVM_OBJ_ROOT/$LLVM_BUILDMODE";
+$ABS_OBJ_ROOT = `cd $ABS_OBJ_ROOT; $PWD` if (-d $ABS_OBJ_ROOT);
+chomp($ABS_OBJ_ROOT);
+
+my $INCLUDEDIR = "$ABS_RUN_DIR/include";
+my $INCLUDEOPTION = "-I$INCLUDEDIR";
+my $LIBDIR = "$ABS_RUN_DIR/lib";
+my $BINDIR = "$ABS_RUN_DIR/bin";
+if ($ABS_RUN_DIR eq $ABS_OBJ_ROOT) {
+ # If we are running out of the build directory, the include dir is in the
+ # srcdir.
+ $INCLUDEDIR = "$LLVM_SRC_ROOT/include";
+ # We need include files from both the srcdir and objdir.
+ $INCLUDEOPTION = "-I$INCLUDEDIR -I$LLVM_OBJ_ROOT/include"
+} else {
+ # If installed, ignore the prefix the tree was configured with, use the
+ # current prefix.
+ $PREFIX = $ABS_RUN_DIR;
+}