Add back commits r219835 and a fixed version of r219829.
[oota-llvm.git] / bindings / go / build.sh
1 #!/bin/sh -xe
2
3 llvm_components="\
4 all-targets \
5 analysis \
6 asmparser \
7 asmprinter \
8 bitreader \
9 bitwriter \
10 codegen \
11 core \
12 debuginfo \
13 executionengine \
14 instrumentation \
15 interpreter \
16 ipo \
17 irreader \
18 linker \
19 mc \
20 mcjit \
21 objcarcopts \
22 option \
23 profiledata \
24 scalaropts \
25 support \
26 target \
27 "
28
29 if [ "$1" == "--print-components" ] ; then
30   echo $llvm_components
31   exit 0
32 fi
33
34 gollvmdir=$(dirname "$0")/llvm
35
36 workdir=$gollvmdir/workdir
37 llvmdir=$gollvmdir/../../..
38 llvm_builddir=$workdir/llvm_build
39
40 mkdir -p $llvm_builddir
41
42 cmake_flags="../../../../.. $@"
43 llvm_config="$llvm_builddir/bin/llvm-config"
44
45 if test -n "`which ninja`" ; then
46   # If Ninja is available, we can speed up the build by building only the
47   # required subset of LLVM.
48   (cd $llvm_builddir && cmake -G Ninja $cmake_flags)
49   ninja -C $llvm_builddir llvm-config
50   llvm_buildtargets="$($llvm_config --libs $llvm_components | sed -e 's/-l//g')"
51   ninja -C $llvm_builddir $llvm_buildtargets FileCheck
52 else
53   (cd $llvm_builddir && cmake $cmake_flags)
54   make -C $llvm_builddir -j4
55 fi
56
57 llvm_version="$($llvm_config --version)"
58 llvm_cflags="$($llvm_config --cppflags)"
59 llvm_ldflags="$($llvm_config --ldflags) $($llvm_config --libs $llvm_components) $($llvm_config --system-libs)"
60 if [ $(uname) != "Darwin" ]; then
61   # OS X doesn't like -rpath with cgo. See:
62   # https://code.google.com/p/go/issues/detail?id=7293
63   llvm_ldflags="-Wl,-rpath,$($llvm_config --libdir) $llvm_ldflags"
64 fi
65 sed -e "s#@LLVM_CFLAGS@#$llvm_cflags#g; s#@LLVM_LDFLAGS@#$llvm_ldflags#g" $gollvmdir/llvm_config.go.in > \
66   $gollvmdir/llvm_config.go
67 printf "package llvm\n\nconst Version = \"%s\"\n" "$llvm_version" > $gollvmdir/version.go