Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / pnacl / unsupported / llc-builder.sh
1 #!/bin/bash
2 # Copyright (c) 2012 The Native Client 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 set -o nounset
6 set -o errexit
7
8 # Script for building just llc and reducing its memory footprint
9
10 readonly CC=gcc
11 readonly CXX=g++
12
13 readonly MAKE_OPTS="-j12 VERBOSE=1"
14
15 enable-32bit() {
16     readonly CFLAGS=-m32
17     readonly CXXFLAGS=-m32
18     readonly LDFLAGS=-m32
19 }
20
21 readonly PNACL_ROOT="$(pwd)/pnacl"
22 readonly TC_BUILD="${PNACL_ROOT}/build"
23 readonly TC_BUILD_LLVM="${TC_BUILD}/llc"
24
25 readonly TC_SRC="${PNACL_ROOT}/src"
26 readonly TC_SRC_UPSTREAM="${TC_SRC}/upstream"
27 readonly TC_SRC_LLVM="${TC_SRC_UPSTREAM}/llvm"
28
29 readonly LLVM_EXTRA_OPTIONS="--enable-optimized"
30
31 readonly CROSS_TARGET_ARM=arm-none-linux-gnueabi
32
33
34 llvm-unlink-clang() {
35   if [ -d "${TC_SRC_LLVM}" ]; then
36     rm -f "${TC_SRC_LLVM}"/tools/clang
37   fi
38 }
39
40
41 llc-configure() {
42   local srcdir="${TC_SRC_LLVM}"
43   local objdir="${TC_BUILD_LLVM}"
44
45   rm -rf "${objdir}"
46   mkdir -p "${objdir}"
47   pushd "${objdir}"
48
49   # Some components like ARMDisassembler may time out when built with -O3.
50   # If we ever start using MSVC, we may also need to tone down the opt level
51   # (see the settings in the CMake file for those components).
52   local llvm_extra_opts=${LLVM_EXTRA_OPTIONS}
53
54   llvm-unlink-clang
55   # The --with-binutils-include is to allow llvm to build the gold plugin
56   env -i PATH=/usr/bin/:/bin \
57              MAKE_OPTS=${MAKE_OPTS} \
58              CC="${CC}" \
59              CXX="${CXX}" \
60              CFLAGS="${CFLAGS}" \
61              CXXFLAGS="${CXXFLAGS}" \
62              LDFLAGS="${LDFLAGS}" \
63              ${srcdir}/configure \
64              --disable-jit \
65              --enable-static \
66              --enable-targets=x86,x86_64,arm \
67              --target=${CROSS_TARGET_ARM} \
68              ${llvm_extra_opts}
69   popd
70 }
71
72
73 llc-make() {
74   local srcdir="${TC_SRC_LLVM}"
75   local objdir="${TC_BUILD_LLVM}"
76
77   pushd "${objdir}"
78
79   llvm-unlink-clang
80
81   env -i PATH=/usr/bin/:/bin \
82            MAKE_OPTS="${MAKE_OPTS}" \
83            NACL_SANDBOX=0 \
84            NACL_SB_JIT=0 \
85            CC="${CC}" \
86            CXX="${CXX}" \
87            CFLAGS="${CFLAGS}" \
88            CXXFLAGS="${CXXFLAGS}" \
89            LDFLAGS="${LDFLAGS}" \
90            make ${MAKE_OPTS} tools-only
91   popd
92 }
93
94
95 llc-install() {
96   # This just works on linux and assumes release builds...
97   # TODO(pnacl-team): Make this path configurable.
98   cp ${TC_BUILD_LLVM}/Release+Asserts/bin/llc \
99     toolchain/linux_x86/pnacl_newlib/host_x86_32/bin/llc
100 }
101
102
103 llc-run-x8632() {
104   local pexe=$1
105   ${TC_BUILD_LLVM}/Release+Asserts/bin/llc \
106       -mcpu=pentium4 \
107       -mtriple=i686-none-nacl-gnu \
108       -filetype=obj \
109       -streaming-bitcode \
110       -tail-merge-threshold=50 \
111       ${pexe} \
112       -o ${pexe}.o \
113       -metadata-text ${pexe}.meta
114 }
115
116 # to use tc malloc, get it from here and configure it like so:
117 # https://code.google.com/p/gperftools/
118 # CXXFLAGS=-m32   LDFLAGS=-m32 CFLAGS=-m32   ./configure
119 llc-run-x8632-heapprofile() {
120    export LD_PRELOAD="${TCMALLOC_SO}"
121    export HEAPPROFILE="$1.heapprofile"
122    llc-run-x8632 "$@"
123 }
124
125 enable-32bit
126
127 "$@"