8e20ca0ec6bf6f885ea4f93755584ed52c302360
[nit.git] / share / libgc / android-setup-libgc.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Fetch, configure and build libgc (the Boehm GC) for Android
17 #
18 # Will produce libgc.a which can be linked to Android NDK applications.
19 #
20 # The `ndk-build` tool from the Android NDK must be in PATH before
21 # invoking this tool. It will be used to guess the path to the NDK.
22 #
23 # Alternatively, you may define a custom path to the NDK by setting
24 # `ANDROID_NDK`.
25
26 # If ANDROID_NDK is not set, get it from the path to `ndk-build`
27 if test -z "$ANDROID_NDK"; then
28 ndk_build_path=`which ndk-build`
29 if test $? -ne 0; then
30 echo "Error: ndk-build from the Android NDK must be in your PATH"
31 exit 1
32 fi
33
34 ANDROID_NDK=`dirname $ndk_build_path`
35 fi
36
37 # Get the first platform available (it shouldn't change much, but it may
38 # have to be adjusted)
39 for platform in `echo $ANDROID_NDK/platforms/android-*/arch-arm`; do
40 SYS_ROOT=$platform
41 break
42 done
43
44 if test -z "$SYS_ROOT"; then
45 echo "Error: could not an Android platform in the NDK, define ANDROID_NDK to the correct path."
46 exit 1
47 fi
48
49 # Information on the currently targeted libgc and libatomic_ops source URL
50 # These may have to be updated according to server-side changes and newer
51 # versions of the Boehm GC.
52 libgc_url=http://www.hboehm.info/gc/gc_source/gc-7.4.0.tar.gz
53 libgc_dir=gc-7.4.0
54 libatomic_ops_url=http://www.hboehm.info/gc/gc_source/libatomic_ops-7.4.0.tar.gz
55 libatomic_ops_dir=libatomic_ops-7.4.0
56
57 # Absolute installation path
58 if expr match "$0" "^/.*"; then
59 install="`dirname "$0"`"
60 else
61 install="`pwd`/`dirname "$0"`"
62 fi
63
64 # Local source directory
65 mkdir -p "$install/src"
66 cd "$install/src"
67
68 # Download libs
69 for url in $libgc_url $libatomic_ops_url; do
70 echo "Downloading $url..."
71 curl --progress-bar -o `basename $url` $url || exit 1
72 done
73
74 if test -d $libgc_dir; then
75 rm -r $libgc_dir
76 fi
77
78 # Extract
79 tar -xzf `basename $libgc_url` || exit 1
80 tar -xzf `basename $libatomic_ops_url` || exit 1
81 mv $libatomic_ops_dir $libgc_dir/libatomic_ops || exit 1
82
83 cd $libgc_dir || exit 1
84
85 # Configure for Android
86 path="$ANDROID_NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/"
87 export CC="$path/arm-linux-androideabi-gcc --sysroot=$SYS_ROOT"
88 export CXX="$path/arm-linux-androideabi-g++ --sysroot=$SYS_ROOT"
89 export LD="$path/arm-linux-androideabi-ld"
90 export AR="$path/arm-linux-androideabi-ar"
91 export RANLIB="$path/arm-linux-androideabi-ranlib"
92 export STRIP="$path/arm-linux-androideabi-strip"
93 export CFLAGS="-DIGNORE_DYNAMIC_LOADING -DPLATFORM_ANDROID -I libatomic_ops/src/"
94 export LIBS="-lc -lgcc"
95 ./configure --host=arm-linux-androideabi --enable-static --disable-shared --prefix="$install" || exit 1
96
97 # Compile and install locally
98 make install -j 4 || exit 1