|
| 1 | +#!/bin/bash |
| 2 | +#------------------------------------------------------------------------------------------------------- |
| 3 | +# Copyright (C) Microsoft. All rights reserved. |
| 4 | +# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
| 5 | +#------------------------------------------------------------------------------------------------------- |
| 6 | + |
| 7 | +LLVM_VERSION="3.9.1" |
| 8 | + |
| 9 | +CC_URL="git://sourceware.org/git/binutils-gdb.git\nhttp://llvm.org/releases/${LLVM_VERSION}/\n" |
| 10 | +echo -e "\n----------------------------------------------------------------" |
| 11 | +echo -e "\nThis script will download LLVM/CLANG and LLVM Gold Bintools from\n${CC_URL}\n" |
| 12 | +echo "These software are licensed to you by its publisher(s), not Microsoft." |
| 13 | +echo "Microsoft is not responsible for the software." |
| 14 | +echo "Your installation and use of the software is subject to the publisher’s terms available here:" |
| 15 | +echo -e "http://llvm.org/docs/DeveloperPolicy.html#license\nhttp://llvm.org/docs/GoldPlugin.html#licensing\n" |
| 16 | +echo -e "----------------------------------------------------------------\n" |
| 17 | +echo "If you don't agree, press Ctrl+C to terminate" |
| 18 | +read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)" |
| 19 | + |
| 20 | +echo -e "\nThis will take some time... [and free memory 2GB+]\n" |
| 21 | + |
| 22 | +ROOT=${PWD}/cc-toolchain/ |
| 23 | +GOLD_PLUGIN="" |
| 24 | + |
| 25 | +if [ ! -d ./cc-toolchain/src/llvm/projects/compiler-rt ]; then |
| 26 | + rm -rf cc-toolchain |
| 27 | + mkdir cc-toolchain |
| 28 | + cd cc-toolchain |
| 29 | + mkdir src |
| 30 | + mkdir bin |
| 31 | + cd src |
| 32 | + |
| 33 | + apt-get -v >/dev/null 2>&1 |
| 34 | + if [ $? == 0 ]; then # debian |
| 35 | + sudo apt-get install -y apt-file texinfo texi2html csh gawk automake libtool libtool-bin bison flex libncurses5-dev |
| 36 | + if [ $? != 0 ]; then |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + else |
| 40 | + yum -v >/dev/null 2>&1 |
| 41 | + if [ $? == 0 ]; then # redhat |
| 42 | + yum install -y texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel |
| 43 | + else |
| 44 | + echo "This script requires (texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel)" |
| 45 | + echo "Automated installation of these requirements is supported with apt-get and yum only." |
| 46 | + echo "" |
| 47 | + echo "If you don't have these packages are installed, press Ctrl+C to terminate" |
| 48 | + read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)" |
| 49 | + fi |
| 50 | + fi |
| 51 | + |
| 52 | + mkdir lto_utils |
| 53 | + cd lto_utils |
| 54 | + echo "Downloading LLVM Gold Plugin" |
| 55 | + git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils >/dev/null 2>&1 |
| 56 | + mkdir binutils_compile; cd binutils_compile |
| 57 | + ../binutils/configure --enable-gold --enable-plugins --disable-werror --prefix="${ROOT}/build" |
| 58 | + make -j2 |
| 59 | + make install |
| 60 | + if [ $? != 0 ]; then |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + |
| 64 | + echo -e "\n\n\n\n" |
| 65 | + cd "${ROOT}/src/" |
| 66 | + |
| 67 | + echo "Downloading LLVM ${LLVM_VERSION}" |
| 68 | + wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1 |
| 69 | + tar -xf "llvm-${LLVM_VERSION}.src.tar.xz" |
| 70 | + if [ $? == 0 ]; then |
| 71 | + rm "llvm-${LLVM_VERSION}.src.tar.xz" |
| 72 | + mv "llvm-${LLVM_VERSION}.src" llvm |
| 73 | + else |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + |
| 77 | + cd llvm/tools/ |
| 78 | + echo "Downloading Clang ${LLVM_VERSION}" |
| 79 | + wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/cfe-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1 |
| 80 | + tar -xf "cfe-${LLVM_VERSION}.src.tar.xz" |
| 81 | + if [ $? == 0 ]; then |
| 82 | + mv "cfe-${LLVM_VERSION}.src" clang |
| 83 | + rm "cfe-${LLVM_VERSION}.src.tar.xz" |
| 84 | + else |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | + |
| 88 | + mkdir -p ../projects/ |
| 89 | + cd ../projects/ |
| 90 | + echo "Downloading Compiler-RT ${LLVM_VERSION}" |
| 91 | + wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/compiler-rt-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1 |
| 92 | + tar -xf "compiler-rt-${LLVM_VERSION}.src.tar.xz" |
| 93 | + if [ $? == 0 ]; then |
| 94 | + mv "compiler-rt-${LLVM_VERSION}.src" compiler-rt |
| 95 | + rm "compiler-rt-${LLVM_VERSION}.src.tar.xz" |
| 96 | + else |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +fi |
| 100 | + |
| 101 | +GOLD_PLUGIN=-DLLVM_BINUTILS_INCDIR="${ROOT}/src/lto_utils/binutils/include" |
| 102 | + |
| 103 | +mkdir -p "${ROOT}/build" |
| 104 | +cd "${ROOT}/src/llvm" |
| 105 | +mkdir -p build_ |
| 106 | +cd build_ |
| 107 | + |
| 108 | +cmake ../ -DCMAKE_INSTALL_PREFIX="${ROOT}/build" -DCMAKE_BUILD_TYPE=Release ${GOLD_PLUGIN} |
| 109 | + |
| 110 | +if [ $? != 0 ]; then |
| 111 | + cd .. |
| 112 | + rm -rf build_ |
| 113 | + mkdir build_ |
| 114 | + exit 1 |
| 115 | +fi |
| 116 | + |
| 117 | +make -j4 install |
| 118 | + |
| 119 | +if [ $? == 0 ]; then |
| 120 | + echo -e "Done!\n./build.sh args are given below;\n\n" |
| 121 | + echo "--cxx=${ROOT}/build/bin/clang++ --cc=${ROOT}/build/bin/clang" |
| 122 | +fi |
0 commit comments