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.
     31 
     32 CLANG_RELEASE=2.9
     33 
     34 THIS_DIR="$(dirname "${0}")"
     35 LLVM_DIR="${THIS_DIR}/../../third_party/llvm"
     36 CLANG_DIR="${LLVM_DIR}/tools/clang"
     37 
     38 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
     39 
     40 # Die if any command dies.
     41 set -e
     42 
     43 OS="$(uname -s)"
     44 
     45 # Xcode and clang don't get along when predictive compilation is enabled.
     46 # http://crbug.com/96315
     47 if [[ "${OS}" = "Darwin" ]] && xcodebuild -version | grep -q 'Xcode 3.2' ; then
     48   XCONF=com.apple.Xcode
     49   if [[ "${GYP_GENERATORS}" != "make" ]] && \
     50      [ "$(defaults read "${XCONF}" EnablePredictiveCompilation)" != "0" ]; then
     51     echo
     52     echo "          HEARKEN!"
     53     echo "You're using Xcode3 and you have 'Predictive Compilation' enabled."
     54     echo "This does not work well with clang (http://crbug.com/96315)."
     55     echo "Disable it in Preferences->Building (lower right), or run"
     56     echo "    defaults write ${XCONF} EnablePredictiveCompilation -boolean NO"
     57     echo "while Xcode is not running."
     58     echo
     59   fi
     60 
     61   SUB_VERSION=$(xcodebuild -version | sed -Ene 's/Xcode 3\.2\.([0-9]+)/\1/p')
     62   if [[ "${SUB_VERSION}" < 6 ]]; then
     63     echo
     64     echo "          YOUR LD IS BUGGY!"
     65     echo "Please upgrade Xcode to at least 3.2.6."
     66     echo
     67   fi
     68 fi
     69 
     70 echo Getting LLVM r"${CLANG_RELEASE}" in "${LLVM_DIR}"
     71 if ! svn co --force \
     72     "${LLVM_REPO_URL}/llvm/branches/release_${CLANG_RELEASE/./}" \
     73     "${LLVM_DIR}"; then
     74   echo Checkout failed, retrying
     75   rm -rf "${LLVM_DIR}"
     76   svn co --force \
     77       "${LLVM_REPO_URL}/llvm/branches/release_${CLANG_RELEASE/./}" \
     78       "${LLVM_DIR}"
     79 fi
     80 
     81 echo Getting clang r"${CLANG_RELEASE}" in "${CLANG_DIR}"
     82 svn co --force \
     83     "${LLVM_REPO_URL}/cfe/branches/release_${CLANG_RELEASE/./}" \
     84     "${CLANG_DIR}"
     85 
     86 # Echo all commands
     87 set -x
     88 
     89 NUM_JOBS=3
     90 if [[ "${OS}" = "Linux" ]]; then
     91   NUM_JOBS="$(grep -c "^processor" /proc/cpuinfo)"
     92 elif [ "${OS}" = "Darwin" ]; then
     93   NUM_JOBS="$(sysctl -n hw.ncpu)"
     94 fi
     95 
     96 # Build clang.
     97 cd "${LLVM_DIR}"
     98 if [[ ! -f ./config.status ]]; then
     99   ../llvm/configure \
    100       --enable-optimized \
    101       --disable-threads \
    102       --disable-pthreads \
    103       --without-llvmgcc \
    104       --without-llvmgxx
    105 fi
    106 
    107 MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}"
    108 STRIP_FLAGS=
    109 if [ "${OS}" = "Darwin" ]; then
    110   # See http://crbug.com/256342
    111   STRIP_FLAGS=-x
    112 fi
    113 strip ${STRIP_FLAGS} Release/bin/clang
    114 cd -
    115 
    116 # Build libgcmole.so
    117 make -C "${THIS_DIR}" clean
    118 make -C "${THIS_DIR}" LLVM_SRC_ROOT="${LLVM_DIR}" libgcmole.so
    119 
    120 set +x
    121 
    122 echo
    123 echo You can now run gcmole using this command:
    124 echo
    125 echo CLANG_BIN=\"third_party/llvm/Release/bin\" lua tools/gcmole/gcmole.lua
    126 echo
    127