-ifndef BUILD_ROOT
-LOGIN_NAME := $(shell whoami)
-CUR_DIRECTORY := $(shell pwd)
-BUILD_ROOT := /shared/$(LOGIN_NAME)$(patsubst $(HOME)%,%,$(CUR_DIRECTORY))
+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))