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 # The source package should be downloaded and compiled only once.
27 # If the working directory is cleared, the cached version will be lost.
28 # On test servers, which clear the working directory frequently,
29 # it may be a good idea to use a local version of the source packages.
30 # To do so, download the following two packages and put them in your HOME directory.
31 # * http://www.hboehm.info/gc/gc_source/gc-7.4.0.tar.gz
32 # * http://www.hboehm.info/gc/gc_source/libatomic_ops-7.4.0.tar.gz
34 # If ANDROID_NDK is not set, get it from the path to `ndk-build`
35 if test -z
"$ANDROID_NDK"; then
36 ndk_build_path
=`which ndk-build`
37 if test $?
-ne
0; then
38 echo "Error: ndk-build from the Android NDK must be in your PATH"
42 ANDROID_NDK
=`dirname $ndk_build_path`
45 # Information on the currently targeted libgc and libatomic_ops source URL
46 # These may have to be updated according to server-side changes and newer
47 # versions of the Boehm GC.
48 libgc_url
=http
://www.hboehm.info
/gc
/gc_source
/gc
-7.4.0.
tar.gz
49 libgc_local
=~
/gc
-7.4.0.
tar.gz
51 libatomic_ops_url
=http
://www.hboehm.info
/gc
/gc_source
/libatomic_ops
-7.4.0.
tar.gz
52 libatomic_ops_local
=~
/libatomic_ops
-7.4.0.
tar.gz
53 libatomic_ops_dir
=libatomic_ops
-7.4.0
55 # Absolute installation path
56 if expr match
"$0" "^/.*"; then
57 install="`dirname "$0"`"
59 install="`pwd`/`dirname "$0"`"
62 # Local source directory
63 mkdir
-p
"$install/src"
66 # Download libs, trying to use a local version if possible
68 if test -f
$libgc_local; then
74 if test -f
$libatomic_ops_local; then
75 cp $libatomic_ops_local .
77 urls
="$urls $libatomic_ops_url"
81 echo "Downloading $url..."
82 curl
--progress
-bar
-o
`basename $url` $url ||
exit 1
85 if test -d
$libgc_dir; then
90 tar -xzf
`basename $libgc_url` ||
exit 1
91 tar -xzf
`basename $libatomic_ops_url` ||
exit 1
92 mv $libatomic_ops_dir $libgc_dir/libatomic_ops ||
exit 1
94 cd $libgc_dir ||
exit 1
97 tools_dirs
=( arm
-linux
-androideabi
-4.9 x86
-4.9 mipsel
-linux
-android
-4.9)
98 tools_prefixes
=(arm
-linux
-androideabi i686
-linux
-android mipsel
-linux
-android
)
99 hosts
=( arm
-linux
-androideabi x86
-linux
-android mips
-linux
-android
)
101 n_archs
=$
(( ${#archs[@]} - 1 ))
102 for i
in $
(eval echo "{0..$n_archs}"); do
104 tools_dir
=${tools_dirs[i]}
105 tools_prefix
=${tools_prefixes[i]}
108 # Get the first platform available (it shouldn't change much, but it may
109 # have to be adjusted)
110 for platform
in `echo $ANDROID_NDK/platforms/android-*/arch-$arch`; do
115 if test -z
"$sys_root"; then
116 echo "Error: could not an Android platform for $arch in the NDK, define ANDROID_NDK to the correct path."
120 # Configure for Android
121 path
="$ANDROID_NDK/toolchains/$tools_dir/prebuilt/linux-x86_64/bin/"
122 export CC
="$path/$tools_prefix-gcc --sysroot=$sys_root"
123 export CXX
="$path/$tools_prefix-g++ --sysroot=$sys_root"
124 export LD
="$path/$tools_prefix-ld"
125 export AR
="$path/$tools_prefix-ar"
126 export RANLIB
="$path/$tools_prefix-ranlib"
127 export STRIP
="$path/$tools_prefix-strip"
128 export CFLAGS
="-DIGNORE_DYNAMIC_LOADING -DPLATFORM_ANDROID -I libatomic_ops/src/"
129 export LIBS
="-lc -lgcc"
130 .
/configure
--host=$host --enable-static
--disable
-shared
--prefix
="$install/$arch/" ||
exit 1
132 # Compile and install locally
133 make install -j
4 ||
exit 1