+# 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
+