android-configure.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash -e
  2. # Copyright (C) 2013-2016 Erik de Castro Lopo <[email protected]>
  3. #
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Neither the author nor the names of any contributors may be used
  13. # to endorse or promote products derived from this software without
  14. # specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  18. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  25. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # Android NDK version number; eg r10, r10b etc
  28. ANDROID_NDK_VER=${ANDROID_NDK_VER:-r10}
  29. # Android NDK gcc version; eg 4.8, 4.9 etc.
  30. ANDROID_GCC_VER=${ANDROID_GCC_VER:-4.9}
  31. # Android API version; eg 14 (Android 4.0), 21 (Android 5.0) etc.
  32. ANDROID_API_VER=${ANDROID_API_VER:-14}
  33. ANDROID_TARGET=${ANDROID_TARGET:-arm-linux-androideabi}
  34. if test -z ${ANDROID_TOOLCHAIN_HOME} ; then
  35. echo "Environment variable ANDROID_TOOLCHAIN_HOME not defined."
  36. echo "This should point to the directory containing the Android NDK."
  37. exit 1
  38. fi
  39. #-------------------------------------------------------------------------------
  40. # No more user config beyond here.
  41. BUILD_MACHINE=$(uname -s | tr 'A-Z' 'a-z')-$(uname -m)
  42. function die_with {
  43. echo $1
  44. exit 1
  45. }
  46. export CROSS_COMPILE=${ANDROID_TARGET}
  47. # Don't forget to adjust this to your NDK path
  48. export ANDROID_NDK=${ANDROID_TOOLCHAIN_HOME}/android-ndk-${ANDROID_NDK_VER}
  49. test -d ${ANDROID_NDK} || die_with "Error : ANDROID_NDK '$ANDROID_NDK' does not exist."
  50. export ANDROID_PREFIX=${ANDROID_NDK}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VER}/prebuilt/${BUILD_MACHINE}
  51. test -d ${ANDROID_PREFIX} || die_with "Error : ANDROID_PREFIX '$ANDROID_PREFIX' does not exist."
  52. export SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API_VER}/arch-arm
  53. test -d ${SYSROOT} || die_with "Error : SYSROOT '$SYSROOT' does not exist."
  54. export CROSS_PREFIX=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}
  55. test -f ${CROSS_PREFIX}-gcc || die_with "Error : CROSS_PREFIX compiler '${CROSS_PREFIX}-gcc' does not exist."
  56. # Non-exhaustive lists of compiler + binutils
  57. # Depending on what you compile, you might need more binutils than that
  58. export CPP=${CROSS_PREFIX}-cpp
  59. export AR=${CROSS_PREFIX}-ar
  60. export AS=${CROSS_PREFIX}-as
  61. export NM=${CROSS_PREFIX}-nm
  62. export CC=${CROSS_PREFIX}-gcc
  63. export CXX=${CROSS_PREFIX}-g++
  64. export LD=${CROSS_PREFIX}-ld
  65. export RANLIB=${CROSS_PREFIX}-ranlib
  66. # Don't mix up .pc files from your host and build target
  67. export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
  68. # Set up the needed FLAGS.
  69. export CFLAGS="${CFLAGS} -gstabs --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"
  70. export CXXFLAGS="${CXXFLAGS} -gstabs -fno-exceptions --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VER}/include/ -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VER}/libs/armeabi/include"
  71. export CPPFLAGS="${CFLAGS}"
  72. export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"
  73. # Create a symlink to the gdbclient.
  74. test -h gdbclient || ln -s ${ANDROID_PREFIX}/bin/arm-linux-androideabi-gdb gdbclient
  75. ./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} "$@"