+# Check what to run for -all.
+LIT_ALL_TESTSUITES := $(LIT_TESTSUITE)
+
+extra-lit-site-cfgs::
+.PHONY: extra-lit-site-cfgs
+
+ifneq ($(strip $(filter check-local-all,$(MAKECMDGOALS))),)
+ifndef TESTSUITE
+ifeq ($(shell test -d $(PROJ_SRC_DIR)/../tools/clang && echo OK), OK)
+LIT_ALL_TESTSUITES += $(PROJ_OBJ_DIR)/../tools/clang/test
+
+# Force creation of Clang's lit.site.cfg.
+clang-lit-site-cfg: FORCE
+ $(MAKE) -C $(PROJ_OBJ_DIR)/../tools/clang/test lit.site.cfg
+extra-lit-site-cfgs:: clang-lit-site-cfg
+endif
+endif
+endif
+
+IGNORE_TESTS :=
+
+ifndef RUNLLVM2CPP
+IGNORE_TESTS += llvm2cpp.exp
+endif
+
+ifdef IGNORE_TESTS
+RUNTESTFLAGS += --ignore "$(strip $(IGNORE_TESTS))"
+endif
+
+# ulimits like these are redundantly enforced by the buildbots, so
+# just removing them here won't work.
+# Both AuroraUX & Solaris do not have the -m flag for ulimit
+ifeq ($(HOST_OS),SunOS)
+ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ;
+else # !SunOS
+ifeq ($(HOST_OS),AuroraUX)
+ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ;
+else # !AuroraUX
+# Fedora 13 x86-64 python fails with -v 76800
+ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -m 512000 ; ulimit -v 1024000 ;
+endif # AuroraUX
+endif # SunOS
+
+ifneq ($(RUNTEST),)
+check-local-dg:: site.exp
+ ( $(ULIMIT) \
+ PATH="$(LLVMToolDir):$(LLVM_SRC_ROOT)/test/Scripts:$(LLVMGCCDIR)/bin:$(PATH)" \
+ $(RUNTEST) $(RUNTESTFLAGS) )
+else
+check-local-dg:: site.exp
+ @echo "*** dejagnu not found. Make sure 'runtest' is in your PATH, then reconfigure LLVM."
+endif
+
+check-local-lit:: lit.site.cfg Unit/lit.site.cfg
+ ( $(ULIMIT) \
+ $(LLVM_SRC_ROOT)/utils/lit/lit.py $(LIT_ARGS) $(LIT_TESTSUITE) )
+
+check-local-all:: lit.site.cfg Unit/lit.site.cfg extra-lit-site-cfgs
+ ( $(ULIMIT) \
+ $(LLVM_SRC_ROOT)/utils/lit/lit.py $(LIT_ARGS) $(LIT_ALL_TESTSUITES) )