Home | History | Annotate | Download | only in gcmole
      1 #!/usr/bin/env bash
      2 
      3 # Copyright 2013 the V8 project authors. All rights reserved.
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions are
      6 # met:
      7 #
      8 #     * Redistributions of source code must retain the above copyright
      9 #       notice, this list of conditions and the following disclaimer.
     10 #     * Redistributions in binary form must reproduce the above
     11 #       copyright notice, this list of conditions and the following
     12 #       disclaimer in the documentation and/or other materials provided
     13 #       with the distribution.
     14 #     * Neither the name of Google Inc. nor the names of its
     15 #       contributors may be used to endorse or promote products derived
     16 #       from this software without specific prior written permission.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 # This script will build libgcmole.so. Building a recent clang needs a
     31 # recent GCC, so if you explicitly want to use GCC 4.8, use:
     32 #
     33 #    CC=gcc-4.8 CPP=cpp-4.8 CXX=g++-4.8 CXXFLAGS=-static-libstdc++ CXXCPP=cpp-4.8 ./bootstrap.sh
     34 
     35 CLANG_RELEASE=3.5
     36 
     37 THIS_DIR="$(dirname "${0}")"
     38 LLVM_DIR="${THIS_DIR}/../../third_party/llvm"
     39 CLANG_DIR="${LLVM_DIR}/tools/clang"
     40 
     41 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
     42 
     43 # Die if any command dies.
     44 set -e
     45 
     46 OS="$(uname -s)"
     47 
     48 # Xcode and clang don't get along when predictive compilation is enabled.
     49 # http://crbug.com/96315
     50 if [[ "${OS}" = "Darwin" ]] && xcodebuild -version | grep -q 'Xcode 3.2' ; then
     51   XCONF=com.apple.Xcode
     52   if [[ "${GYP_GENERATORS}" != "make" ]] && \
     53      [ "$(defaults read "${XCONF}" EnablePredictiveCompilation)" != "0" ]; then
     54     echo
     55     echo "          HEARKEN!"
     56     echo "You're using Xcode3 and you have 'Predictive Compilation' enabled."
     57     echo "This does not work well with clang (http://crbug.com/96315)."
     58     echo "Disable it in Preferences->Building (lower right), or run"
     59     echo "    defaults write ${XCONF} EnablePredictiveCompilation -boolean NO"
     60     echo "while Xcode is not running."
     61     echo
     62   fi
     63 
     64   SUB_VERSION=$(xcodebuild -version | sed -Ene 's/Xcode 3\.2\.([0-9]+)/\1/p')
     65   if [[ "${SUB_VERSION}" < 6 ]]; then
     66     echo
     67     echo "          YOUR LD IS BUGGY!"
     68     echo "Please upgrade Xcode to at least 3.2.6."
     69     echo
     70   fi
     71 fi
     72 
     73 echo Getting LLVM r"${CLANG_RELEASE}" in "${LLVM_DIR}"
     74 if ! svn co --force \
     75     "${LLVM_REPO_URL}/llvm/branches/release_${CLANG_RELEASE/./}" \
     76     "${LLVM_DIR}"; then
     77   echo Checkout failed, retrying
     78   rm -rf "${LLVM_DIR}"
     79   svn co --force \
     80       "${LLVM_REPO_URL}/llvm/branches/release_${CLANG_RELEASE/./}" \
     81       "${LLVM_DIR}"
     82 fi
     83 
     84 echo Getting clang r"${CLANG_RELEASE}" in "${CLANG_DIR}"
     85 svn co --force \
     86     "${LLVM_REPO_URL}/cfe/branches/release_${CLANG_RELEASE/./}" \
     87     "${CLANG_DIR}"
     88 
     89 # Echo all commands
     90 set -x
     91 
     92 NUM_JOBS=3
     93 if [[ "${OS}" = "Linux" ]]; then
     94   NUM_JOBS="$(grep -c "^processor" /proc/cpuinfo)"
     95 elif [ "${OS}" = "Darwin" ]; then
     96   NUM_JOBS="$(sysctl -n hw.ncpu)"
     97 fi
     98 
     99 # Build clang.
    100 cd "${LLVM_DIR}"
    101 if [[ ! -f ./config.status ]]; then
    102   ../llvm/configure \
    103       --enable-optimized \
    104       --disable-threads \
    105       --disable-pthreads \
    106       --without-llvmgcc \
    107       --without-llvmgxx
    108 fi
    109 
    110 MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}"
    111 STRIP_FLAGS=
    112 if [ "${OS}" = "Darwin" ]; then
    113   # See http://crbug.com/256342
    114   STRIP_FLAGS=-x
    115 fi
    116 strip ${STRIP_FLAGS} Release+Asserts/bin/clang
    117 cd -
    118 
    119 # Build libgcmole.so
    120 make -C "${THIS_DIR}" clean
    121 make -C "${THIS_DIR}" LLVM_SRC_ROOT="${LLVM_DIR}" libgcmole.so
    122 
    123 set +x
    124 
    125 echo
    126 echo You can now run gcmole using this command:
    127 echo
    128 echo CLANG_BIN=\"third_party/llvm/Release+Asserts/bin\" lua tools/gcmole/gcmole.lua
    129 echo
    130