2 # This file is part of NIT ( http://www.nitlanguage.org ).
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Fetch, configure and build libgc (the Boehm GC) for Android
18 # Will produce libgc.a which can be linked to Android NDK applications.
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.
23 # Alternatively, you may define a custom path to the NDK by setting
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"
34 ANDROID_NDK
=`dirname $ndk_build_path`
37 # Information on the currently targeted libgc and libatomic_ops source URL
38 # These may have to be updated according to server-side changes and newer
39 # versions of the Boehm GC.
40 libgc_url
=http
://www.hboehm.info
/gc
/gc_source
/gc
-7.4.0.
tar.gz
42 libatomic_ops_url
=http
://www.hboehm.info
/gc
/gc_source
/libatomic_ops
-7.4.0.
tar.gz
43 libatomic_ops_dir
=libatomic_ops
-7.4.0
45 # Absolute installation path
46 if expr match
"$0" "^/.*"; then
47 install="`dirname "$0"`"
49 install="`pwd`/`dirname "$0"`"
52 # Local source directory
53 mkdir
-p
"$install/src"
57 for url
in $libgc_url $libatomic_ops_url; do
58 echo "Downloading $url..."
59 curl
--progress
-bar
-o
`basename $url` $url ||
exit 1
62 if test -d
$libgc_dir; then
67 tar -xzf
`basename $libgc_url` ||
exit 1
68 tar -xzf
`basename $libatomic_ops_url` ||
exit 1
69 mv $libatomic_ops_dir $libgc_dir/libatomic_ops ||
exit 1
71 cd $libgc_dir ||
exit 1
74 tools_dirs
=( arm
-linux
-androideabi
-4.6 x86
-4.6 mipsel
-linux
-android
-4.6)
75 tools_prefixes
=(arm
-linux
-androideabi i686
-linux
-android mipsel
-linux
-android
)
76 hosts
=( arm
-linux
-androideabi x86
-linux
-android mips
-linux
-android
)
78 n_archs
=$
(( ${#archs[@]} - 1 ))
79 for i
in $
(eval echo "{0..$n_archs}"); do
81 tools_dir
=${tools_dirs[i]}
82 tools_prefix
=${tools_prefixes[i]}
85 # Get the first platform available (it shouldn't change much, but it may
86 # have to be adjusted)
87 for platform
in `echo $ANDROID_NDK/platforms/android-*/arch-$arch`; do
92 if test -z
"$sys_root"; then
93 echo "Error: could not an Android platform for $arch in the NDK, define ANDROID_NDK to the correct path."
97 # Configure for Android
98 path
="$ANDROID_NDK/toolchains/$tools_dir/prebuilt/linux-x86_64/bin/"
99 export CC
="$path/$tools_prefix-gcc --sysroot=$sys_root"
100 export CXX
="$path/$tools_prefix-g++ --sysroot=$sys_root"
101 export LD
="$path/$tools_prefix-ld"
102 export AR
="$path/$tools_prefix-ar"
103 export RANLIB
="$path/$tools_prefix-ranlib"
104 export STRIP
="$path/$tools_prefix-strip"
105 export CFLAGS
="-DIGNORE_DYNAMIC_LOADING -DPLATFORM_ANDROID -I libatomic_ops/src/"
106 export LIBS
="-lc -lgcc"
107 .
/configure
--host=$host --enable-static
--disable
-shared
--prefix
="$install/$arch/" ||
exit 1
109 # Compile and install locally
110 make install -j
4 ||
exit 1