Add support for building LLVM

Add a llvm.py subcommand for building LLVM in a given build directory.
The build directory must have already been configured with CMake. The
build command that is run will be either a 'ninja' command or a 'make'
command, depending on whether the build directory contains a
'build.ninja' or a 'Makefile'. If it contains neither of those, an error
is generated.

I initially wanted to put the implementation for this in the
LLVMBuildConfig, but it doesn't really need anything from there. For now
I left it as a free-standing function. It doesn't have any knowledge of
LLVM whatsoever, so an argument could be made for moving it into the
"utils" package rather than the "llvm" package. In the future, we may
want to remove the LLVMBuildConfig class and see if there's a better way
to organize the code for configuring and building.

One disadvantage with using python here is that we lose the nice
progress bars that we could see when running 'ninja check' from the bash
scripts. I'm not sure how to fix that, suggestions welcome.

Change-Id: I48cf464a6412238a26eb5bcfb4723946983c86f2
diff --git a/helpers/llvm-build b/helpers/llvm-build
index 64c15ea..773c16a 100755
--- a/helpers/llvm-build
+++ b/helpers/llvm-build
@@ -1,10 +1,6 @@
 #!/usr/bin/env bash
 
-# This script helps you build LLVM. It can update the repositories first,
-# run the check-all after and even install it in your system. Since the
-# LLVM tree changes constantly, it's recommended that you run this script
-# with update+check at least once a week, and most importantly, before you
-# begin a big change, to make sure the repos are current and stable.
+# This script helps you build LLVM.
 
 . llvm-common
 
@@ -24,10 +20,6 @@
 targets=
 prog=`basename $0`
 syntax="Syntax: $prog [-jN] [targets]"
-update=false
-check=false
-master=false
-inst=false
 minimal_targets="--cmake-def LLVM_TARGETS_TO_BUILD='ARM;X86;AArch64'"
 link_jobs=
 
@@ -37,10 +29,8 @@
 fi
 
 ## Choose between make and ninja
-make=make
 generator="Unix Makefiles"
 if which ninja > /dev/null 2>&1; then
-  make=ninja
   generator="Ninja"
 fi
 
@@ -54,7 +44,7 @@
 # Building on ARM?
 if grep -q "ARM.* Processor" /proc/cpuinfo; then
   targets=$minimal_targets
-  if [ "$make" = "ninja" ]; then
+  if [ "$generator" = "Ninja" ]; then
     link=$(free -g | awk '/Mem/ {print $2}')
     if [ "$link" -gt "$CPUS" ]; then
       link=$CPUS
@@ -95,11 +85,12 @@
 ## Build
 if [ "$1" == "" ]; then
   echo " + Building LLVM"
-  safe_run $make $PARALLEL
+  safe_run python3 $llvmtool build --build-dir $build_dir --build-flag=$PARALLEL
 else
   for target in "$@"; do
     echo " + Running $target"
-    safe_run $make $PARALLEL $target
+    safe_run python3 $llvmtool build --build-dir $build_dir \
+                                     --build-flag=$PARALLEL --build-flag $target
   done
 fi