-PARALLEL_DIRS := llvm-as llvm-dis opt gccas llc llvm-link lli gccld llvm-stub \
- analyze llvm-extract llvm-nm llvm-prof llvm-ar llvm-ranlib \
- llvm-bcanalyzer llvmc llvm-ld llvm-db bugpoint llvm-config
+
+# Build clang if present.
+OPTIONAL_PARALLEL_DIRS := clang
+
+# Build LLDB if present. Note LLDB must be built last as it depends on the
+# wider LLVM infrastructure (including Clang).
+OPTIONAL_DIRS := lldb
+
+# NOTE: The tools are organized into five groups of four consisting of one
+# large and three small executables. This is done to minimize memory load
+# in parallel builds. Please retain this ordering.
+DIRS := llvm-config
+PARALLEL_DIRS := opt llvm-as llvm-dis \
+ llc llvm-ranlib llvm-ar llvm-nm \
+ llvm-ld llvm-prof llvm-link \
+ lli llvm-extract llvm-mc \
+ bugpoint llvm-bcanalyzer llvm-stub \
+ llvm-diff macho-dump llvm-objdump \
+ llvm-rtdyld llvm-dwarfdump
+
+# Let users override the set of tools to build from the command line.
+ifdef ONLY_TOOLS
+ OPTIONAL_PARALLEL_DIRS :=
+ OPTIONAL_DIRS := $(findstring lldb,$(ONLY_TOOLS))
+ PARALLEL_DIRS := $(filter-out lldb,$(ONLY_TOOLS))
+endif