+
+# Figure out which directory to build stuff into. We want to build into the
+# /shared directory by default because it is guaranteed to be local to the
+# current machine.
+#
+ifeq ($(LLVM_OBJ_DIR),.)
+BUILD_ROOT = $(LLVM_OBJ_DIR)
+BUILD_ROOT_TOP = $(LEVEL)
+else
+
+BUILD_ROOT := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(shell pwd))
+
+# Calculate the BUILD_ROOT_TOP variable, which is the top of the llvm/ tree.
+# Note that although this is just equal to $(BUILD_ROOT)/$(LEVEL), we cannot use
+# this expression because some of the directories on the source tree may not
+# exist in the build tree (for example the test/ heirarchy). Thus we evaluate
+# the directory to eliminate the ../'s
+#
+TOP_DIRECTORY := $(shell cd $(LEVEL); pwd)
+BUILD_ROOT_TOP := $(LLVM_OBJ_DIR)$(patsubst $(HOME)%,%,$(TOP_DIRECTORY))
+endif
+