• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 as well as a corresponding recent
31# version of Clang and LLVM. The Clang will be built with the locally
32# installed compiler and statically link against the local libstdc++ so
33# that the resulting binary is easier transferable between different
34# environments.
35
36LLVM_RELEASE=9.0.1
37
38BUILD_TYPE="Release"
39# BUILD_TYPE="Debug"
40THIS_DIR="$(readlink -f "$(dirname "${0}")")"
41LLVM_PROJECT_DIR="${THIS_DIR}/bootstrap/llvm"
42BUILD_DIR="${THIS_DIR}/bootstrap/build"
43
44# Die if any command dies.
45set -e
46
47OS="$(uname -s)"
48
49# Xcode and clang don't get along when predictive compilation is enabled.
50# http://crbug.com/96315
51if [[ "${OS}" = "Darwin" ]] && xcodebuild -version | grep -q 'Xcode 3.2' ; then
52  XCONF=com.apple.Xcode
53  if [[ "${GYP_GENERATORS}" != "make" ]] && \
54     [ "$(defaults read "${XCONF}" EnablePredictiveCompilation)" != "0" ]; then
55    echo
56    echo "          HEARKEN!"
57    echo "You're using Xcode3 and you have 'Predictive Compilation' enabled."
58    echo "This does not work well with clang (http://crbug.com/96315)."
59    echo "Disable it in Preferences->Building (lower right), or run"
60    echo "    defaults write ${XCONF} EnablePredictiveCompilation -boolean NO"
61    echo "while Xcode is not running."
62    echo
63  fi
64
65  SUB_VERSION=$(xcodebuild -version | sed -Ene 's/Xcode 3\.2\.([0-9]+)/\1/p')
66  if [[ "${SUB_VERSION}" < 6 ]]; then
67    echo
68    echo "          YOUR LD IS BUGGY!"
69    echo "Please upgrade Xcode to at least 3.2.6."
70    echo
71  fi
72fi
73
74echo Getting LLVM release "${LLVM_RELEASE}" in "${LLVM_PROJECT_DIR}"
75if ! [ -d "${LLVM_PROJECT_DIR}" ] || ! git -C "${LLVM_PROJECT_DIR}" remote get-url origin | grep -q -F "https://github.com/llvm/llvm-project.git" ; then
76  rm -rf "${LLVM_PROJECT_DIR}"
77  git clone --depth=1 --branch "llvmorg-${LLVM_RELEASE}" "https://github.com/llvm/llvm-project.git" "${LLVM_PROJECT_DIR}"
78else
79  git -C "${LLVM_PROJECT_DIR}" fetch --depth=1 origin "llvmorg-${LLVM_RELEASE}"
80  git -C "${LLVM_PROJECT_DIR}" checkout FETCH_HEAD
81fi
82
83# Echo all commands
84set -x
85
86NUM_JOBS=3
87if [[ "${OS}" = "Linux" ]]; then
88  if [[ -e "/proc/cpuinfo" ]]; then
89    NUM_JOBS="$(grep -c "^processor" /proc/cpuinfo)"
90  else
91    # Hack when running in chroot
92    NUM_JOBS="32"
93  fi
94elif [ "${OS}" = "Darwin" ]; then
95  NUM_JOBS="$(sysctl -n hw.ncpu)"
96fi
97
98# Build clang.
99if [ ! -e "${BUILD_DIR}" ]; then
100  mkdir "${BUILD_DIR}"
101fi
102cd "${BUILD_DIR}"
103cmake -GNinja -DCMAKE_CXX_FLAGS="-static-libstdc++" -DLLVM_ENABLE_TERMINFO=OFF \
104    -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DLLVM_ENABLE_PROJECTS=clang \
105    -DLLVM_ENABLE_Z3_SOLVER=OFF "${LLVM_PROJECT_DIR}/llvm"
106MACOSX_DEPLOYMENT_TARGET=10.5 ninja -j"${NUM_JOBS}" clang
107
108if [[ "${BUILD_TYPE}" = "Release" ]]; then
109  # Strip the clang binary.
110  STRIP_FLAGS=
111  if [ "${OS}" = "Darwin" ]; then
112    # See http://crbug.com/256342
113    STRIP_FLAGS=-x
114  fi
115  strip ${STRIP_FLAGS} bin/clang
116fi
117cd -
118
119# Build libgcmole.so
120make -C "${THIS_DIR}" clean
121make -C "${THIS_DIR}" LLVM_SRC_ROOT="${LLVM_PROJECT_DIR}/llvm" \
122    CLANG_SRC_ROOT="${LLVM_PROJECT_DIR}/clang" \
123    BUILD_ROOT="${BUILD_DIR}" $BUILD_TYPE
124
125set +x
126
127echo '#########################################################################'
128echo 'Congratulations you compiled clang and libgcmole.so'
129echo
130echo '# You can now run gcmole:'
131echo 'tools/gcmole/gcmole.py \'
132echo '   --clang-bin-dir="tools/gcmole/bootstrap/build/bin" \'
133echo '   --clang-plugins-dir="tools/gcmole" \'
134echo '   --v8-target-cpu=$CPU'
135echo
136