+ifeq ($(BUILD_EXAMPLES),1)
+ OPTIONAL_DIRS += examples
+endif
+
+EXTRA_DIST := test unittests llvm.spec include win32 Xcode
+
+include $(LEVEL)/Makefile.config
+
+ifneq ($(ENABLE_SHARED),1)
+ DIRS := $(filter-out tools/llvm-shlib, $(DIRS))
+endif
+
+ifneq ($(ENABLE_DOCS),1)
+ DIRS := $(filter-out docs, $(DIRS))
+endif
+
+ifeq ($(MAKECMDGOALS),libs-only)
+ DIRS := $(filter-out tools docs, $(DIRS))
+ OPTIONAL_DIRS :=
+endif
+
+ifeq ($(MAKECMDGOALS),install-libs)
+ DIRS := $(filter-out tools docs, $(DIRS))
+ OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
+endif
+
+ifeq ($(MAKECMDGOALS),tools-only)
+ DIRS := $(filter-out docs, $(DIRS))
+ OPTIONAL_DIRS :=
+endif
+
+ifeq ($(MAKECMDGOALS),install-clang)
+ DIRS := tools/clang/tools/driver tools/clang/lib/Headers \
+ tools/clang/tools/libclang \
+ tools/clang/tools/c-index-test \
+ tools/clang/include/clang-c \
+ tools/clang/runtime tools/clang/docs \
+ tools/lto
+ OPTIONAL_DIRS :=
+ NO_INSTALL = 1
+endif
+
+ifeq ($(MAKECMDGOALS),clang-only)
+ DIRS := $(filter-out tools docs unittests, $(DIRS)) \
+ tools/clang tools/lto
+ OPTIONAL_DIRS :=
+endif
+
+ifeq ($(MAKECMDGOALS),unittests)
+ DIRS := $(filter-out tools docs, $(DIRS)) utils unittests
+ OPTIONAL_DIRS :=
+endif
+
+# Use NO_INSTALL define of the Makefile of each directory for deciding
+# if the directory is installed or not
+ifeq ($(MAKECMDGOALS),install)
+ OPTIONAL_DIRS := $(filter bindings, $(OPTIONAL_DIRS))
+endif
+
+# Don't build unittests when ONLY_TOOLS is set.
+ifneq ($(ONLY_TOOLS),)
+ DIRS := $(filter-out unittests, $(DIRS))
+endif
+
+# If we're cross-compiling, build the build-hosted tools first
+ifeq ($(LLVM_CROSS_COMPILING),1)
+all:: cross-compile-build-tools
+
+clean::
+ $(Verb) rm -rf BuildTools
+
+cross-compile-build-tools:
+ $(Verb) if [ ! -f BuildTools/Makefile ]; then \
+ $(MKDIR) BuildTools; \
+ cd BuildTools ; \
+ unset CFLAGS ; \
+ unset CXXFLAGS ; \
+ AR=$(BUILD_AR) ; \
+ AS=$(BUILD_AS) ; \
+ LD=$(BUILD_LD) ; \
+ CC=$(BUILD_CC) ; \
+ CXX=$(BUILD_CXX) ; \
+ unset SDKROOT ; \
+ unset UNIVERSAL_SDK_PATH ; \
+ configure_opts= ; \
+ if test "$(ENABLE_LIBCPP)" -ne 0 ; then \
+ configure_opts="$$configure_opts --enable-libcpp"; \
+ fi; \
+ $(PROJ_SRC_DIR)/configure --build=$(BUILD_TRIPLE) \
+ --host=$(BUILD_TRIPLE) --target=$(BUILD_TRIPLE) \
+ --disable-polly $$configure_opts; \
+ cd .. ; \
+ fi; \
+ ($(MAKE) -C BuildTools \
+ BUILD_DIRS_ONLY=1 \
+ UNIVERSAL= \
+ UNIVERSAL_SDK_PATH= \
+ SDKROOT= \
+ TARGET_NATIVE_ARCH="$(TARGET_NATIVE_ARCH)" \
+ TARGETS_TO_BUILD="$(TARGETS_TO_BUILD)" \
+ TARGET_LIBS="$(LIBS)" \
+ ENABLE_OPTIMIZED=$(ENABLE_OPTIMIZED) \
+ ENABLE_PROFILING=$(ENABLE_PROFILING) \
+ ENABLE_COVERAGE=$(ENABLE_COVERAGE) \
+ DISABLE_ASSERTIONS=$(DISABLE_ASSERTIONS) \
+ ENABLE_EXPENSIVE_CHECKS=$(ENABLE_EXPENSIVE_CHECKS) \
+ ENABLE_LIBCPP=$(ENABLE_LIBCPP) \
+ CFLAGS= \
+ CXXFLAGS= \
+ ) || exit 1;
+endif
+
+# Include the main makefile machinery.