index all rss twitter github linkedin email

Álvaro Ramírez

30 April 2015 Building clang-format

Based on instructions from Building clang-format and friends on OSX Mountain Lion.

#!/bin/bash
  set -o nounset
  set -o errexit

  # Based on instructions from:
  # http://blog.hardcodes.de/articles/63/building-clang-format-and-friends-on-osx-mountain-lion

  readonly LLVM_DIR_PATH='/tmp/llvm'

  update_repo() {
    if [[ ! -d $1 ]]; then
      git clone $2
    else
      cd $1
      git pull
      cd ..
    fi
    cd ..
  }

  update_all_repos() {
    update_repo "llvm" "http://llvm.org/git/llvm.git"
    pushd "${LLVM_DIR_PATH}/llvm/tools"
    update_repo "clang" "http://llvm.org/git/clang.git"
    popd
    cd "../../${LLVM_DIR_PATH}/llvm/tools/clang/tools"
    update_repo "clang-tools-extra" "http://llvm.org/git/clang-tools-extra.git"
    cd "../../.."
  }

  build_clang() {
    mkdir -p clang
    mkdir -p build
    cd clang
    ../llvm/configure --enable-libcpp --enable-cxx11 --enable-debug-symbols=no --enable-optimized --prefix="${LLVM_DIR_PATH}/build"
    make install
  }

  mkdir -p $LLVM_DIR_PATH
  cd ${LLVM_DIR_PATH}
  update_all_repos
  build_clang

Bonus: use clang-format-configurator.