Makefile: Switch Clang Makefiles to always include the top-level Clang Makefile.
 - This eliminates most dependencies on how Clang is installed relative to LLVM.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105637 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Makefile b/Makefile
index 39cf9c6..7b2a365 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,19 @@
-LEVEL = ../..
+##===- Makefile --------------------------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+# If CLANG_LEVEL is not set, then we are the top-level Makefile. Otherwise, we
+# are being included from a subdirectory makefile.
+
+ifndef CLANG_LEVEL
+
+IS_TOP_LEVEL := 1
+CLANG_LEVEL := .
 DIRS := include lib tools docs
 
 PARALLEL_DIRS :=
@@ -6,9 +21,22 @@
 ifeq ($(BUILD_EXAMPLES),1)
   PARALLEL_DIRS += examples
 endif
+endif
 
+###
+# Common Makefile code, shared by all Clang Makefiles.
+
+# Set LLVM source root level.
+LEVEL := $(CLANG_LEVEL)/../..
+
+# Include LLVM common makefile.
 include $(LEVEL)/Makefile.common
 
+###
+# Clang Top Level specific stuff.
+
+ifeq ($(IS_TOP_LEVEL),1)
+
 ifneq ($(PROJ_SRC_ROOT),$(PROJ_OBJ_ROOT))
 $(RecursiveTargets)::
 	$(Verb) if [ ! -f test/Makefile ]; then \
@@ -37,3 +65,5 @@
 	                    -or -name '*.h' > cscope.files
 
 .PHONY: test report clean cscope.files
+
+endif
diff --git a/docs/Makefile b/docs/Makefile
index e9bbb28..053b263 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -7,7 +7,7 @@
 # 
 ##===----------------------------------------------------------------------===##
 
-LEVEL      := ../../..
+CLANG_LEVEL := ..
 DIRS       := tools
 
 ifdef BUILD_FOR_WEBSITE
@@ -22,7 +22,7 @@
 	  -e 's/@abs_top_builddir@/../g' > $@
 endif
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 HTML       := $(wildcard $(PROJ_SRC_DIR)/*.html) \
               $(wildcard $(PROJ_SRC_DIR)/*.css)
diff --git a/docs/tools/Makefile b/docs/tools/Makefile
index 91bc447..4cffc45 100644
--- a/docs/tools/Makefile
+++ b/docs/tools/Makefile
@@ -37,8 +37,8 @@
 else
 
 # Otherwise, if not in BUILD_FOR_WEBSITE mode, use the project info.
-LEVEL := ../../../..
-include $(LEVEL)/Makefile.common
+CLANG_LEVEL := ../..
+include $(CLANG_LEVEL)/Makefile
 
 CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../VER)
 
diff --git a/examples/Makefile b/examples/Makefile
index 869197d..c4af252 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -7,8 +7,8 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../..
+CLANG_LEVEL := ..
 
 PARALLEL_DIRS := clang-interpreter PrintFunctionNames wpa
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
diff --git a/examples/PrintFunctionNames/Makefile b/examples/PrintFunctionNames/Makefile
index 57d3ba9..4136a98 100644
--- a/examples/PrintFunctionNames/Makefile
+++ b/examples/PrintFunctionNames/Makefile
@@ -7,7 +7,7 @@
 # 
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME = PrintFunctionNames
 
 CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
@@ -15,7 +15,7 @@
 # Include this here so we can get the configuration of the targets that have
 # been configured for construction. We have to do this early so we can set up
 # LINK_COMPONENTS before including Makefile.rules
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_LIBS_IN_SHARED = 1
 SHARED_LIBRARY = 1
@@ -24,4 +24,4 @@
 USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \
 	   clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
diff --git a/examples/clang-interpreter/Makefile b/examples/clang-interpreter/Makefile
index 397a1f9..6683a57 100644
--- a/examples/clang-interpreter/Makefile
+++ b/examples/clang-interpreter/Makefile
@@ -7,7 +7,7 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 
 TOOLNAME = clang-interpreter
 CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
@@ -19,7 +19,7 @@
 # Include this here so we can get the configuration of the targets that have
 # been configured for construction. We have to do this early so we can set up
 # LINK_COMPONENTS before including Makefile.rules
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_COMPONENTS := jit interpreter nativecodegen bitreader bitwriter ipo \
 	selectiondag asmparser
@@ -27,4 +27,4 @@
            clangChecker.a clangAnalysis.a clangRewrite.a  clangAST.a \
            clangParse.a clangLex.a clangBasic.a
 
-include $(LLVM_SRC_ROOT)/Makefile.rules
+include $(CLANG_LEVEL)/Makefile
diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile
index b266cd1..16f9280 100644
--- a/examples/wpa/Makefile
+++ b/examples/wpa/Makefile
@@ -7,7 +7,7 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 
 TOOLNAME = clang-wpa
 CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
@@ -19,10 +19,10 @@
 # Include this here so we can get the configuration of the targets that have
 # been configured for construction. We have to do this early so we can set up
 # LINK_COMPONENTS before including Makefile.rules
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_COMPONENTS := asmparser bitreader mc core
 USEDLIBS = clangIndex.a clangFrontend.a clangDriver.a clangSema.a \
 	   clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
 
-include $(LLVM_SRC_ROOT)/Makefile.rules
+include $(CLANG_LEVEL)/Makefile
diff --git a/include/Makefile b/include/Makefile
index f686d6a..79b9adf 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -1,4 +1,4 @@
-LEVEL = ../../..
+CLANG_LEVEL := ..
 DIRS := clang clang-c
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
diff --git a/include/clang-c/Makefile b/include/clang-c/Makefile
index 5e3522f..98ea719 100644
--- a/include/clang-c/Makefile
+++ b/include/clang-c/Makefile
@@ -1,7 +1,7 @@
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 DIRS :=
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 install-local::
 	$(Echo) Installing Clang C API include files
diff --git a/include/clang/AST/Makefile b/include/clang/AST/Makefile
index 9aad990..6e3dd89 100644
--- a/include/clang/AST/Makefile
+++ b/include/clang/AST/Makefile
@@ -1,10 +1,10 @@
-LEVEL = ../../../../..
+CLANG_LEVEL := ../../..
 BUILT_SOURCES = StmtNodes.inc DeclNodes.inc
 TD_SRC_DIR = $(PROJ_SRC_DIR)/../Basic
 
 TABLEGEN_INC_FILES_COMMON = 1
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 INPUT_TDS = $(TD_SRC_DIR)/StmtNodes.td $(TD_SRC_DIR)/DeclNodes.td
 
diff --git a/include/clang/Basic/Makefile b/include/clang/Basic/Makefile
index 48f7f9d..1553a79 100644
--- a/include/clang/Basic/Makefile
+++ b/include/clang/Basic/Makefile
@@ -1,4 +1,4 @@
-LEVEL = ../../../../..
+CLANG_LEVEL := ../../..
 BUILT_SOURCES = DiagnosticAnalysisKinds.inc DiagnosticASTKinds.inc \
 	DiagnosticCommonKinds.inc DiagnosticDriverKinds.inc \
 	DiagnosticFrontendKinds.inc DiagnosticLexKinds.inc \
@@ -7,7 +7,7 @@
 
 TABLEGEN_INC_FILES_COMMON = 1
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 INPUT_TDS = $(wildcard $(PROJ_SRC_DIR)/Diagnostic*.td)
 
diff --git a/include/clang/Driver/Makefile b/include/clang/Driver/Makefile
index b462aaa..d829166 100644
--- a/include/clang/Driver/Makefile
+++ b/include/clang/Driver/Makefile
@@ -1,9 +1,9 @@
-LEVEL = ../../../../..
+CLANG_LEVEL := ../../..
 BUILT_SOURCES = Options.inc CC1Options.inc CC1AsOptions.inc
 
 TABLEGEN_INC_FILES_COMMON = 1
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 $(ObjDir)/Options.inc.tmp : Options.td OptParser.td $(TBLGEN) $(ObjDir)/.dir
 	$(Echo) "Building Clang Driver Option tables with tblgen"
diff --git a/include/clang/Makefile b/include/clang/Makefile
index 6abe375..e366e4e 100644
--- a/include/clang/Makefile
+++ b/include/clang/Makefile
@@ -1,7 +1,7 @@
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 DIRS := AST Basic Driver
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 install-local::
 	$(Echo) Installing Clang include files
diff --git a/lib/AST/Makefile b/lib/AST/Makefile
index ede2577..a4bb9aa 100644
--- a/lib/AST/Makefile
+++ b/lib/AST/Makefile
@@ -11,11 +11,11 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangAST
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Analysis/Makefile b/lib/Analysis/Makefile
index 9b47380..e9950fc 100644
--- a/lib/Analysis/Makefile
+++ b/lib/Analysis/Makefile
@@ -11,11 +11,11 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangAnalysis
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Basic/Makefile b/lib/Basic/Makefile
index 58ac7eb..f36a1bc 100644
--- a/lib/Basic/Makefile
+++ b/lib/Basic/Makefile
@@ -11,7 +11,7 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangBasic
 BUILD_ARCHIVE = 1
 
@@ -20,7 +20,7 @@
 CPPFLAGS += -DCLANG_VENDOR='"$(CLANG_VENDOR) "'
 endif
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 SVN_REVISION := $(shell $(LLVM_SRC_ROOT)/utils/GetSourceVersion $(PROJ_SRC_DIR)/../..)
 
diff --git a/lib/Checker/Makefile b/lib/Checker/Makefile
index c45ab29..fc2bc50 100644
--- a/lib/Checker/Makefile
+++ b/lib/Checker/Makefile
@@ -11,11 +11,11 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangChecker
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/CodeGen/Makefile b/lib/CodeGen/Makefile
index 3cea6bb..cfa0217 100644
--- a/lib/CodeGen/Makefile
+++ b/lib/CodeGen/Makefile
@@ -12,7 +12,7 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangCodeGen
 BUILD_ARCHIVE = 1
 
@@ -21,5 +21,5 @@
 CPP.Flags += -DCLANG_VENDOR='"$(CLANG_VENDOR) "'
 endif
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Driver/Makefile b/lib/Driver/Makefile
index 371bda7..5ee4abc 100644
--- a/lib/Driver/Makefile
+++ b/lib/Driver/Makefile
@@ -7,10 +7,10 @@
 # 
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangDriver
 BUILD_ARCHIVE = 1
 
 CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
diff --git a/lib/Frontend/Makefile b/lib/Frontend/Makefile
index 9e1a864..962568b 100644
--- a/lib/Frontend/Makefile
+++ b/lib/Frontend/Makefile
@@ -7,11 +7,11 @@
 # 
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangFrontend
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Headers/Makefile b/lib/Headers/Makefile
index fea59d6..c93294a 100644
--- a/lib/Headers/Makefile
+++ b/lib/Headers/Makefile
@@ -7,12 +7,12 @@
 # 
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 
 BUILT_SOURCES = arm_neon.h.inc
 TABLEGEN_INC_FILES_COMMON = 1
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../VER)
 
@@ -30,7 +30,7 @@
 $(HeaderDir)/arm_neon.h: $(BUILT_SOURCES)
 	$(Verb) cp $< $@
 	$(Echo) Copying $(notdir $<) to build dir
-	
+
 # Hook into the standard Makefile rules.
 all-local:: $(OBJHEADERS)
 
diff --git a/lib/Index/Makefile b/lib/Index/Makefile
index 4d86713..191e9d4 100644
--- a/lib/Index/Makefile
+++ b/lib/Index/Makefile
@@ -11,8 +11,8 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
-include $(LEVEL)/Makefile.config
+CLANG_LEVEL := ../..
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LIBRARYNAME := clangIndex
 BUILD_ARCHIVE = 1
@@ -23,5 +23,5 @@
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Lex/Makefile b/lib/Lex/Makefile
index bd3c7a8..9845214 100644
--- a/lib/Lex/Makefile
+++ b/lib/Lex/Makefile
@@ -11,8 +11,8 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
-include $(LEVEL)/Makefile.config
+CLANG_LEVEL := ../..
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LIBRARYNAME := clangLex
 BUILD_ARCHIVE = 1
@@ -23,5 +23,5 @@
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Makefile b/lib/Makefile
index 538bf43..eb5a5a6 100755
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -6,10 +6,10 @@
 # License. See LICENSE.TXT for details.
 # 
 ##===----------------------------------------------------------------------===##
-LEVEL = ../../..
+CLANG_LEVEL := ..
 
 PARALLEL_DIRS = Headers Runtime Basic Lex Parse AST Sema CodeGen Analysis \
                 Checker Rewrite Frontend Index Driver
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Parse/Makefile b/lib/Parse/Makefile
index 6a5540f..e6bac34 100644
--- a/lib/Parse/Makefile
+++ b/lib/Parse/Makefile
@@ -11,11 +11,11 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangParse
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Rewrite/Makefile b/lib/Rewrite/Makefile
index 04c3530..29e0595 100644
--- a/lib/Rewrite/Makefile
+++ b/lib/Rewrite/Makefile
@@ -11,11 +11,11 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangRewrite
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/lib/Runtime/Makefile b/lib/Runtime/Makefile
index 580215a..1b25818 100644
--- a/lib/Runtime/Makefile
+++ b/lib/Runtime/Makefile
@@ -13,8 +13,8 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
-include $(LEVEL)/Makefile.common
+CLANG_LEVEL := ../..
+include $(CLANG_LEVEL)/Makefile
 
 CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../VER)
 ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)
diff --git a/lib/Sema/Makefile b/lib/Sema/Makefile
index 3a5a99a..6e13327 100644
--- a/lib/Sema/Makefile
+++ b/lib/Sema/Makefile
@@ -12,11 +12,11 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME := clangSema
 BUILD_ARCHIVE = 1
 
 CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
diff --git a/test/Makefile b/test/Makefile
index c3b3eab..5bb50c6 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,5 +1,5 @@
-LEVEL = ../../..
-include $(LEVEL)/Makefile.common
+CLANG_LEVEL := ..
+include $(CLANG_LEVEL)/Makefile
 
 # Test in all immediate subdirectories if unset.
 ifdef TESTSUITE
diff --git a/tools/Makefile b/tools/Makefile
index 8407dfd..c1e6163 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -7,13 +7,13 @@
 #
 ##===----------------------------------------------------------------------===##
 
-LEVEL := ../../..
+CLANG_LEVEL := ..
 DIRS := driver libclang c-index-test
 
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 ifeq ($(OS), $(filter $(OS), Cygwin MingW))
 DIRS := $(filter-out libclang c-index-test, $(DIRS))
 endif
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
diff --git a/tools/c-index-test/Makefile b/tools/c-index-test/Makefile
index 24fed16..dd39d25 100644
--- a/tools/c-index-test/Makefile
+++ b/tools/c-index-test/Makefile
@@ -6,7 +6,7 @@
 # License. See LICENSE.TXT for details.
 # 
 ##===----------------------------------------------------------------------===##
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 
 TOOLNAME = c-index-test
 CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
@@ -14,10 +14,10 @@
 # No plugins, optimize startup time.
 TOOL_NO_EXPORTS = 1
 
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_COMPONENTS := bitreader mc core
 USEDLIBS = clang.a clangIndex.a clangFrontend.a clangDriver.a clangSema.a \
 	   clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
 
-include $(LLVM_SRC_ROOT)/Makefile.rules
+include $(CLANG_LEVEL)/Makefile
diff --git a/tools/driver/Makefile b/tools/driver/Makefile
index ac98730..5125892 100644
--- a/tools/driver/Makefile
+++ b/tools/driver/Makefile
@@ -6,7 +6,7 @@
 # License. See LICENSE.TXT for details.
 #
 ##===----------------------------------------------------------------------===##
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 
 TOOLNAME = clang
 ifndef CLANG_IS_PRODUCTION
@@ -24,7 +24,7 @@
 # Include this here so we can get the configuration of the targets that have
 # been configured for construction. We have to do this early so we can set up
 # LINK_COMPONENTS before including Makefile.rules
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader bitwriter codegen \
                    ipo selectiondag
@@ -32,7 +32,7 @@
            clangChecker.a clangAnalysis.a clangRewrite.a  clangAST.a \
            clangParse.a clangLex.a clangBasic.a
 
-include $(LLVM_SRC_ROOT)/Makefile.rules
+include $(CLANG_LEVEL)/Makefile
 
 # Translate make variable to define when building a "production" clang.
 ifdef CLANG_IS_PRODUCTION
diff --git a/tools/libclang/Makefile b/tools/libclang/Makefile
index ff0fa33..4cfe126 100644
--- a/tools/libclang/Makefile
+++ b/tools/libclang/Makefile
@@ -7,7 +7,7 @@
 # 
 ##===----------------------------------------------------------------------===##
 
-LEVEL = ../../../..
+CLANG_LEVEL := ../..
 LIBRARYNAME = clang
 
 EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/libclang.exports
@@ -17,7 +17,7 @@
 # Include this here so we can get the configuration of the targets
 # that have been configured for construction. We have to do this 
 # early so we can set up LINK_COMPONENTS before including Makefile.rules
-include $(LEVEL)/Makefile.config
+include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_LIBS_IN_SHARED = 1
 SHARED_LIBRARY = 1
@@ -26,7 +26,7 @@
 USEDLIBS = clangFrontend.a clangDriver.a clangSema.a \
 	   clangAnalysis.a clangAST.a clangParse.a clangLex.a clangBasic.a
 
-include $(LEVEL)/Makefile.common
+include $(CLANG_LEVEL)/Makefile
 
 ##===----------------------------------------------------------------------===##
 # FIXME: This is copied from the 'lto' makefile.  Should we share this?