• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# This script will check out llvm and clang, and then package the results up
7# to a tgz file.
8
9gcc_toolchain=
10
11# Parse command line options.
12while [[ $# > 0 ]]; do
13  case $1 in
14    --gcc-toolchain)
15      shift
16      if [[ $# == 0 ]]; then
17        echo "--gcc-toolchain requires an argument."
18        exit 1
19      fi
20      if [[ -x "$1/bin/gcc" ]]; then
21        gcc_toolchain=$1
22      else
23        echo "Invalid --gcc-toolchain: '$1'."
24        echo "'$1/bin/gcc' does not appear to be valid."
25        exit 1
26      fi
27      ;;
28
29    --help)
30      echo "usage: $0 [--gcc-toolchain <prefix>]"
31      echo
32      echo "--gcc-toolchain: Set the prefix for which GCC version should"
33      echo "    be used for building. For example, to use gcc in"
34      echo "    /opt/foo/bin/gcc, use '--gcc-toolchain '/opt/foo"
35      echo
36      exit 1
37      ;;
38    *)
39      echo "Unknown argument: '$1'."
40      echo "Use --help for help."
41      exit 1
42      ;;
43  esac
44  shift
45done
46
47
48THIS_DIR="$(dirname "${0}")"
49LLVM_DIR="${THIS_DIR}/../../../third_party/llvm"
50LLVM_BOOTSTRAP_DIR="${THIS_DIR}/../../../third_party/llvm-bootstrap"
51LLVM_BOOTSTRAP_INSTALL_DIR="${LLVM_DIR}/../llvm-bootstrap-install"
52LLVM_BUILD_DIR="${THIS_DIR}/../../../third_party/llvm-build"
53LLVM_BIN_DIR="${LLVM_BUILD_DIR}/Release+Asserts/bin"
54LLVM_LIB_DIR="${LLVM_BUILD_DIR}/Release+Asserts/lib"
55
56echo "Diff in llvm:" | tee buildlog.txt
57svn stat "${LLVM_DIR}" 2>&1 | tee -a buildlog.txt
58svn diff "${LLVM_DIR}" 2>&1 | tee -a buildlog.txt
59echo "Diff in llvm/tools/clang:" | tee -a buildlog.txt
60svn stat "${LLVM_DIR}/tools/clang" 2>&1 | tee -a buildlog.txt
61svn diff "${LLVM_DIR}/tools/clang" 2>&1 | tee -a buildlog.txt
62echo "Diff in llvm/projects/compiler-rt:" | tee -a buildlog.txt
63svn stat "${LLVM_DIR}/projects/compiler-rt" 2>&1 | tee -a buildlog.txt
64svn diff "${LLVM_DIR}/projects/compiler-rt" 2>&1 | tee -a buildlog.txt
65
66echo "Starting build" | tee -a buildlog.txt
67
68set -exu
69
70# Do a clobber build.
71rm -rf "${LLVM_BOOTSTRAP_DIR}"
72rm -rf "${LLVM_BOOTSTRAP_INSTALL_DIR}"
73rm -rf "${LLVM_BUILD_DIR}"
74extra_flags=
75if [[ -n "${gcc_toolchain}" ]]; then
76  extra_flags="--gcc-toolchain ${gcc_toolchain}"
77fi
78"${THIS_DIR}"/update.sh --bootstrap --force-local-build --run-tests \
79    ${extra_flags} 2>&1 | tee -a buildlog.txt
80
81R=$("${LLVM_BIN_DIR}/clang" --version | \
82     sed -ne 's/clang version .*(trunk \([0-9]*\))/\1/p')
83
84PDIR=clang-$R
85rm -rf $PDIR
86mkdir $PDIR
87mkdir $PDIR/bin
88mkdir $PDIR/lib
89
90if [ "$(uname -s)" = "Darwin" ]; then
91  SO_EXT="dylib"
92else
93  SO_EXT="so"
94fi
95
96# Copy buildlog over.
97cp buildlog.txt $PDIR/
98
99# Copy clang into pdir, symlink clang++ to it.
100cp "${LLVM_BIN_DIR}/clang" $PDIR/bin/
101(cd $PDIR/bin && ln -sf clang clang++)
102cp "${LLVM_BIN_DIR}/llvm-symbolizer" $PDIR/bin/
103if [ "$(uname -s)" = "Darwin" ]; then
104  cp "${LLVM_BIN_DIR}/libc++.1.${SO_EXT}" $PDIR/bin/
105  (cd $PDIR/bin && ln -sf libc++.1.dylib libc++.dylib)
106fi
107
108# Copy libc++ headers.
109if [ "$(uname -s)" = "Darwin" ]; then
110  mkdir $PDIR/include
111  cp -R "${LLVM_BOOTSTRAP_INSTALL_DIR}/include/c++" $PDIR/include
112fi
113
114# Copy plugins. Some of the dylibs are pretty big, so copy only the ones we
115# care about.
116cp "${LLVM_LIB_DIR}/libFindBadConstructs.${SO_EXT}" $PDIR/lib
117
118BLINKGCPLUGIN_LIBNAME=\
119$(grep LIBRARYNAME "$THIS_DIR"/../blink_gc_plugin/Makefile \
120    | cut -d ' ' -f 3)
121cp "${LLVM_LIB_DIR}/lib${BLINKGCPLUGIN_LIBNAME}.${SO_EXT}" $PDIR/lib
122
123if [[ -n "${gcc_toolchain}" ]]; then
124  # Copy the stdlibc++.so.6 we linked Clang against so it can run.
125  cp "${LLVM_LIB_DIR}/libstdc++.so.6" $PDIR/lib
126fi
127
128# Copy built-in headers (lib/clang/3.x.y/include).
129# libcompiler-rt puts all kinds of libraries there too, but we want only some.
130if [ "$(uname -s)" = "Darwin" ]; then
131  # Keep only the OSX (ASan and profile) and iossim (ASan) runtime libraries:
132  # Release+Asserts/lib/clang/*/lib/darwin/libclang_rt.{asan,profile}_*
133  find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/darwin*' \
134       ! -name '*asan_osx*' ! -name '*asan_iossim*' ! -name '*profile_osx*' | \
135      xargs rm
136  # Fix LC_ID_DYLIB for the ASan dynamic libraries to be relative to
137  # @executable_path.
138  # TODO(glider): this is transitional. We'll need to fix the dylib name
139  # either in our build system, or in Clang. See also http://crbug.com/344836.
140  ASAN_DYLIB_NAMES="libclang_rt.asan_osx_dynamic.dylib
141    libclang_rt.asan_iossim_dynamic.dylib"
142  for ASAN_DYLIB_NAME in $ASAN_DYLIB_NAMES
143  do
144    ASAN_DYLIB=$(find "${LLVM_LIB_DIR}/clang" \
145                      -type f -path "*${ASAN_DYLIB_NAME}")
146    install_name_tool -id @executable_path/${ASAN_DYLIB_NAME} "${ASAN_DYLIB}"
147  done
148else
149  # Keep only
150  # Release+Asserts/lib/clang/*/lib/linux/libclang_rt.{[atm]san,san,ubsan,profile}-*.a
151  # , but not dfsan.
152  find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/linux*' \
153       ! -name '*[atm]san*' ! -name '*ubsan*' ! -name '*libclang_rt.san*' \
154       ! -name '*profile*' | xargs rm
155  # Strip the debug info from the runtime libraries.
156  find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/linux*' | xargs strip -g
157fi
158
159cp -R "${LLVM_LIB_DIR}/clang" $PDIR/lib
160
161tar zcf $PDIR.tgz -C $PDIR bin lib buildlog.txt
162
163if [ "$(uname -s)" = "Darwin" ]; then
164  PLATFORM=Mac
165else
166  PLATFORM=Linux_x64
167fi
168
169echo To upload, run:
170echo gsutil cp -a public-read $PDIR.tgz \
171     gs://chromium-browser-clang/$PLATFORM/$PDIR.tgz
172