+LEVEL := .
+
+# Top-Level LLVM Build Stages:
+# 1. Build lib/System and lib/Support, which are used by utils (tblgen).
+# 2. Build utils, which is used by VMCore.
+# 3. Build VMCore, which builds the Intrinsics.inc file used by libs.
+# 4. Build libs, which are needed by llvm-config.
+# 5. Build llvm-config, which determines inter-lib dependencies for tools.
+# 6. Build tools, runtime, docs.
+#
+# When cross-compiling, there are some things (tablegen) that need to
+# be build for the build system first.
+
+# If "RC_ProjectName" exists in the environment, and its value is
+# "llvmCore", then this is an "Apple-style" build; search for
+# "Apple-style" in the comments for more info. Anything else is a
+# normal build.
+ifneq ($(findstring llvmCore, $(RC_ProjectName)),llvmCore) # Normal build (not "Apple-style").
+
+ifeq ($(BUILD_DIRS_ONLY),1)
+ DIRS := lib/System lib/Support utils
+ OPTIONAL_DIRS :=
+else
+ DIRS := lib/System lib/Support utils lib/VMCore lib tools/llvm-config \
+ tools runtime docs unittests
+ OPTIONAL_DIRS := projects bindings
+endif
+
+ifeq ($(BUILD_EXAMPLES),1)
+ OPTIONAL_DIRS += examples
+endif
+
+EXTRA_DIST := test unittests llvm.spec include win32 Xcode
+
+include $(LEVEL)/Makefile.config
+
+# llvm-gcc4 doesn't need runtime libs. llvm-gcc4 is the only supported one.
+# FIXME: Remove runtime entirely once we have an understanding of where
+# libprofile etc should go.
+#ifeq ($(LLVMGCC_MAJVERS),4)
+# DIRS := $(filter-out runtime, $(DIRS))
+#endif
+
+ifeq ($(MAKECMDGOALS),libs-only)
+ DIRS := $(filter-out tools runtime docs, $(DIRS))
+ OPTIONAL_DIRS :=
+endif
+
+ifeq ($(MAKECMDGOALS),install-libs)
+ DIRS := $(filter-out tools runtime docs, $(DIRS))
+ OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
+endif
+
+ifeq ($(MAKECMDGOALS),tools-only)
+ DIRS := $(filter-out runtime docs, $(DIRS))
+ OPTIONAL_DIRS :=
+endif
+
+ifeq ($(MAKECMDGOALS),install-clang)
+ DIRS := tools/clang/tools/driver tools/clang/lib/Headers tools/clang/docs
+ OPTIONAL_DIRS :=
+ NO_INSTALL = 1
+endif
+
+ifeq ($(MAKECMDGOALS),clang-only)
+ DIRS := $(filter-out tools runtime docs unittests, $(DIRS)) tools/clang
+ OPTIONAL_DIRS :=
+endif
+
+ifeq ($(MAKECMDGOALS),unittests)
+ DIRS := $(filter-out tools runtime docs, $(DIRS)) utils unittests
+ OPTIONAL_DIRS :=
+endif