1#!/bin/bash
2
3if [[ "$OUT" == "" ]]; then
4  echo "In order for this script to function, please choose an x86_64 target"
5  echo "using source build/envsetup.sh and lunch XXX\n"
6  exit 1
7fi
8
9x86_64_cc="${ANDROID_TOOLCHAIN}/x86_64-linux-android-gcc"
10x86_64_cpp="${ANDROID_TOOLCHAIN}/x86_64-linux-android-g++"
11
12includes=(
13  "-isystem ${ANDROID_BUILD_TOP}/bionic/libc/arch-x86_64/include"
14  "-isystem ${ANDROID_BUILD_TOP}/bionic/libc/include"
15  "-isystem ${ANDROID_BUILD_TOP}/bionic/libstdc++/include"
16  "-isystem ${ANDROID_BUILD_TOP}/bionic/libc/kernel/uapi"
17  "-isystem ${ANDROID_BUILD_TOP}/bionic/libc/kernel/uapi/asm-x86"
18  "-isystem ${ANDROID_BUILD_TOP}/bionic/libm/include"
19  "-isystem ${ANDROID_BUILD_TOP}/bionic/libm/include/amd64"
20)
21
22# Copy libm.so to libpthread.so to allow -lpthread to work.
23cp ${OUT}/obj/lib/libm.so ${OUT}/obj/lib/libpthread.so
24
25ldflags=(
26  "-nostdlib"
27  "-Bdynamic"
28  "-fPIE"
29  "-pie"
30  "-Wl,-dynamic-linker,/system/bin/linker64"
31  "-Wl,--gc-sections"
32  "-Wl,-z,nocopyreloc"
33  "-L${OUT}/obj/lib"
34  "-Wl,-rpath-link=${OUT}/obj/lib"
35  "${OUT}/obj/lib/crtbegin_dynamic.o"
36  "-Wl,--whole-archive"
37  "-Wl,--no-whole-archive"
38  "-lc"
39  "-lstdc++"
40  "-lgcc"
41  "-lm"
42  "-Wl,-z,noexecstack"
43  "-Wl,-z,relro"
44  "-Wl,-z,now"
45  "-Wl,--warn-shared-textrel"
46  "-Wl,--fatal-warnings"
47  "-Wl,--icf=safe"
48  "-Wl,--no-undefined"
49  "-ldl"
50)
51
52eval ./configure CC=\"${x86_64_cc} ${includes[@]}\" \
53                 CPP=\"${x86_64_cc} ${includes[@]} -E\" \
54                 CXX=\"${x86_64_cpp} ${includes[@]}\" \
55                 CXXCPP=\"${x86_64_cpp} ${includes[@]} -E\" \
56                 LDFLAGS=\"${ldflags[@]}\" \
57                 --host=x86_64-android-linux \
58                 --disable-valgrind \
59                 --with-jemalloc_prefix=je_ \
60
61