1#!/bin/bash
2# This script is used to run configure and generate all of the necessary
3# files when updating to a new version of jemalloc.
4# The NDK argument must be a NDK at r20 or newer so that it does not
5# require installing the standalone tools.
6
7ndk=${1}
8if [[ "$ndk" == "" ]]; then
9  echo "Requires two arguments."
10  echo "usage: conf.sh NDK ARCH"
11  exit 1
12fi
13
14arch=${2}
15if [[ "$arch" == "" ]]; then
16  echo "Requires two arguments."
17  echo "usage: conf.sh NDK ARCH"
18  exit 1
19fi
20
21if [[ ! -d ${ndk} ]]; then
22  echo "NDK directory ${ndk} does not exist."
23  exit 1
24fi
25toolchain=${ndk}/toolchains/llvm/prebuilt/linux-x86_64
26if [[ ! -d ${toolchain} ]]; then
27  echo "NDK ${ndk} cannot find toolchain directory."
28  echo "  ${toolchain}"
29  exit 1
30fi
31
32# The latest version of clang to use for compilation.
33latest_api=29
34
35case "$arch" in
36  "arm")
37    prefix="arm-linux-androideabi"
38    clang_prefix="armv7a-linux-androideabi"
39    target="arm-android-linux"
40    ;;
41  "arm64")
42    prefix="aarch64-linux-android"
43    target="aarch64-android-linux"
44    ;;
45  "x86")
46    target="x86-android-linux"
47    export CPPFLAGS="-m32"
48    ;&
49  "x86_64")
50    prefix="x86_64-linux-android"
51    if [[ "$target" == "" ]]; then
52      target="x86_64-android-linux"
53    fi
54    ;;
55  *)
56    echo "Unknown arch $arch"
57    exit 1
58    ;;
59esac
60
61if [[ "${clang_prefix}" == "" ]]; then
62  clang_prefix="${prefix}"
63fi
64
65tools=("AR" "ar"
66       "AS" "as"
67       "LD" "ld"
68       "RANLIB" "ranlib"
69       "STRIP" "strip")
70
71for ((i = 0; i < ${#tools[@]}; i = i + 2)); do
72  binary=${toolchain}/bin/${prefix}-${tools[$((i + 1))]}
73  if [[ ! -e ${binary} ]]; then
74    echo "${binary} does not exist."
75    exit 1
76  fi
77  export ${tools[$i]}=${binary}
78done
79
80clang=("CC" "clang"
81       "CXX" "clang++")
82
83for ((i = 0; i < ${#clang[@]}; i = i + 2)); do
84  binary=${toolchain}/bin/${clang_prefix}${latest_api}-${clang[$((i + 1))]}
85  if [[ ! -e ${binary} ]]; then
86    echo "${binary} does not exist."
87    exit 1
88  fi
89  export ${clang[$i]}=${binary}
90done
91
92export CPP="${CC} -E"
93
94./autogen.sh --with-jemalloc_prefix=je_ --host=${target}
95