Home | History | Annotate | Download | only in build
      1 #!/bin/bash
      2 CLANG_PACKAGE=clang
      3 GNSHA1_URL="https://chromium.googlesource.com/chromium/buildtools/\
      4 +/master/linux64/gn.sha1?format=TEXT"
      5 
      6 # Check if clang is already installed on current system
      7 clang_path=`which clang`
      8 if [ -f "$clang_path" ]; then
      9   # if clang binary is avalable, check its version
     10   clang_version=$($clang_path --version | grep clang | sed "s/.*version\s*\([0-9]*\.[0-9]*\).*/\1/")
     11   IFS="." read -ra clang_version_array <<< "$clang_version"
     12   clang_version_major=${clang_version_array[0]}
     13   clang_version_minor=${clang_version_array[1]}
     14   # if the version is greater than 3.5 then do not install clang here
     15   if [ $clang_version_major -ge 3 ] && [ $clang_version_minor -ge 5 ]; then
     16     echo "Detected clang $clang_version"
     17     CLANG_PACKAGE=""
     18   fi
     19 fi
     20 
     21 if [ ! -z "$CLANG_PACKAGE" ]; then
     22   # Try to find clang from a known list
     23   for clang_version in 3.9 3.8 3.7 3.6 3.5
     24   do
     25     clang_path=`which clang-$clang_version`
     26     if [ -f "$clang_path" ]; then
     27       echo "Detected clang-$clang_version"
     28       CLANG_PACKAGE=""
     29       break
     30     fi
     31   done
     32 fi
     33 
     34 if [ ! -z "$CLANG_PACKAGE" ]; then
     35   echo "clang not found on current system, installing"
     36   if [ -f /etc/lsb-release ]; then
     37 	  # Ubuntu
     38 	  ubuntu_version=$(lsb_release --release --short)
     39 	  IFS="." read -ra ubuntu_version_array <<< "$ubuntu_version"
     40 	  ubuntu_version_major=${ubuntu_version_array[0]}
     41 	  ubuntu_version_minor=${ubuntu_version_array[1]}
     42 	  if [ $ubuntu_version_major -lt 15 ]; then
     43 	    echo "Choose clang-3.8 for Ubuntu 14 and below"
     44 	    CLANG_PACKAGE=clang-3.8
     45 	  fi
     46   fi
     47 fi
     48 
     49 sudo apt-get -y install $CLANG_PACKAGE libevent-dev libc++-dev libc++abi-dev \
     50                         ninja-build
     51 gn_path=`which gn`
     52 if [ -z $gn_path ]; then
     53   gnsha1=$(curl $GNSHA1_URL | base64 -d)
     54   wget -O gn http://storage.googleapis.com/chromium-gn/$gnsha1
     55   chmod a+x ./gn
     56   sudo mv ./gn /usr/bin/
     57 fi
     58