+if ($#LLVMDIR == 0 || ! -d "$LLVMDIR") then
+ echo "Unable to find LLVM src-root directory or directory is invalid."
+ echo "Are you within a valid LLVM directory for running gmake?"
+ exit 1
+endif
+
+## Try to determine the obj-root directory automatically if not specified
+##
+set OBJROOTDIRLIST = ( ${LLVMDIR} $OBJROOTDIRLIST ) ## add src dir
+if ($?OBJROOT == 0) then
+ ## Try to determine object root directory by looking for Makefile.config
+ foreach objdir ( $OBJROOTDIRLIST )
+ if (-f "${objdir}/Makefile.config") then
+ set OBJROOT = ${objdir}
+ break
+ endif
+ end
+ if ($?OBJROOT == 0) then
+ echo "FATAL: Could not choose an obj-root directory from these choices:"
+ echo " ${OBJROOTDIRLIST}."
+ echo " You can specify it explicitly using '-obj obj-root'."
+ exit 1
+ endif
+ echo "Using OBJ-ROOT = ${OBJROOT} (specify '-obj obj-root' to override)."
+endif
+if (${OBJROOT} == ${LLVMDIR}) then
+ # run make in the source directory itself
+ set BUILDROOT = .
+else
+ # run make in the in the obj-root tree, in the directory for $cwd
+ set SRCROOT = `sh -c "cd $LLVMDIR; pwd | sed 's/\//\\\//g'"`
+ set CURSRCDIR = `echo $cwd | sed -e "s/${SRCROOT}//"`
+ set BUILDROOT = ${OBJROOT}/${CURSRCDIR}
+ unset SRCROOT CURSRCDIR
+endif
+if ($DEBUG) then
+ echo "DEBUG: BUILDROOT = $BUILDROOT"
+endif
+if (! -d $BUILDROOT) then
+ echo "FATAL: Invalid build directory: ${BUILDROOT}"