install_deps.sh 1.8 KB

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