Search
lxdream.org :: lxdream/m4/android.m4
lxdream 0.9.1
released Jun 29
Download Now
filename m4/android.m4
changeset 1255:d63f73cc586f
prev1245:01e0020adf88
author nkeynes
date Sun Mar 04 20:56:40 2012 +1000 (7 years ago)
permissions -rw-r--r--
last change Add support for armv7-a abi and make it the default - it's a good bit faster
file annotate diff log raw
nkeynes@1239
     1
# LX_ANDROID_BUILD
nkeynes@1239
     2
# Defines --with-android, --with-android-ndk, and --with-android-version
nkeynes@1239
     3
# If specified, checks for a working install, and sets build parameters
nkeynes@1239
     4
# appropriately for an Android host. 
nkeynes@1239
     5
AC_DEFUN([LX_ANDROID_BUILD], [
nkeynes@1239
     6
   AC_REQUIRE([AC_CANONICAL_HOST])
nkeynes@1239
     7
   AC_ARG_WITH( android, AS_HELP_STRING( [--with-android=SDK], [Specify the location of the Android SDK] ) )
nkeynes@1239
     8
   AC_ARG_WITH( android-ndk, AS_HELP_STRING( [--with-android-ndk=NDK], [Specify the location of the Android NDK] ) )
nkeynes@1245
     9
   AC_ARG_WITH( android-version, AS_HELP_STRING( [--with-android-version], [Specify target Android SDK version]), [], [with_android_version="android-11"] )
nkeynes@1245
    10
   AC_ARG_WITH( android-ndk-version, AS_HELP_STRING( [--with-android-version], [Specify target Android NDK version]), [], [with_ndk_version="android-9"] )
nkeynes@1255
    11
   AC_ARG_WITH( android-abi, AS_HELP_STRING( [--with-android-abi], [Specify target Android ABI]), [], [ANDROID_ABI="armeabi-v7a"] )
nkeynes@1239
    12
nkeynes@1239
    13
   if test "x$with_android" != "x"; then
nkeynes@1239
    14
      if test "$with_android" = "yes"; then
nkeynes@1239
    15
         AC_MSG_ERROR( [--with-android option must be given with the path to the Android SDK] )
nkeynes@1239
    16
      fi
nkeynes@1239
    17
      if test "x$with_android_ndk" = "x" -o "x$with_android_ndk" = "xyes"; then
nkeynes@1239
    18
         AC_MSG_ERROR( [--with-android-ndk=/path/to/ndk option must be used with --with-android] )
nkeynes@1239
    19
      fi
nkeynes@1239
    20
nkeynes@1239
    21
      ANDROID_SDK_HOME="$with_android"
nkeynes@1239
    22
      ANDROID_NDK_HOME="$with_android_ndk"
nkeynes@1239
    23
      ANDROID_SDK_VERSION="$with_android_version"
nkeynes@1245
    24
      ANDROID_NDK_VERSION="$with_ndk_version"
nkeynes@1239
    25
      
nkeynes@1239
    26
      AC_CHECK_FILE( [$ANDROID_SDK_HOME/tools/ant/pre_setup.xml], [], [ AC_MSG_ERROR([Android SDK not found in $ANDROID_SDK_HOME]) ])
nkeynes@1239
    27
      AC_CHECK_FILE( [$ANDROID_SDK_HOME/platforms/$ANDROID_SDK_VERSION/sdk.properties], [], [ AC_MSG_ERROR([Android platform version $ANDROID_SDK_VERSION not found in $ANDROID_SDK_HOME]) ])
nkeynes@1239
    28
      AC_CHECK_FILE( [$ANDROID_NDK_HOME/toolchains], [], [ AC_MSG_ERROR([Android NDK not found in $ANDROID_NDK_HOME]) ])
nkeynes@1239
    29
nkeynes@1255
    30
      dnl common flags
nkeynes@1255
    31
      TARGETFLAGS="-ffunction-sections -funwind-tables -fomit-frame-pointer -DANDROID -Wa,--noexecstack"
nkeynes@1255
    32
      
nkeynes@1255
    33
      case $ANDROID_ABI in
nkeynes@1255
    34
         armeabi | armeabi-v7a) 
nkeynes@1239
    35
            host_alias="arm-linux-androideabi"
nkeynes@1239
    36
            host_cpu="arm"
nkeynes@1239
    37
            host_vendor="unknown";
nkeynes@1239
    38
            host_os="linux-androideabi"
nkeynes@1239
    39
            ANDROID_NDK_BIN=`echo $ANDROID_NDK_HOME/toolchains/arm-*/prebuilt/*/bin`
nkeynes@1239
    40
            ANDROID_GDBSERVER=`echo $ANDROID_NDK_HOME/toolchains/arm-*/prebuilt/gdbserver`
nkeynes@1245
    41
            ANDROID_SYSROOT="$ANDROID_NDK_HOME/platforms/$ANDROID_NDK_VERSION/arch-arm"
nkeynes@1255
    42
            dnl Common ARM flags
nkeynes@1255
    43
            TARGETFLAGS="$TARGETFLAGS -fstack-protector -finline-limit=64 -fno-strict-aliasing -Wno-psabi -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__"
nkeynes@1255
    44
            if test "x$with_abi" = "armeabi"; then
nkeynes@1255
    45
                TARGETFLAGS="$TARGETFLAGS -march=armv5te -mtune=xscale -msoft-float"
nkeynes@1255
    46
            else
nkeynes@1255
    47
                TARGETFLAGS="$TARGETFLAGS -march=armv7-a -mtune=cortex-a8 -mfloat-abi=softfp -mfpu=vfp"
nkeynes@1255
    48
            fi
nkeynes@1239
    49
            ;;
nkeynes@1255
    50
         x86)
nkeynes@1239
    51
            host_alias="i686-android-linux"
nkeynes@1239
    52
            host_cpu="i686"
nkeynes@1239
    53
            host_vendor="android"
nkeynes@1239
    54
            host_os="linux"
nkeynes@1239
    55
            ANDROID_NDK_BIN=`echo $ANDROID_NDK_HOME/toolchains/x86-*/prebuilt/*/bin`
nkeynes@1239
    56
            ANDROID_GDBSERVER=`echo $ANDROID_NDK_HOME/toolchains/x86-*/prebuilt/gdbserver`
nkeynes@1245
    57
            ANDROID_SYSROOT="$ANDROID_NDK_HOME/platforms/$ANDROID_NDK_VERSION/arch-x86"
nkeynes@1255
    58
            TARGETFLAGS="$TARGETFLAGS -finline-limit=300 -fno-rtti -funswitch-loops -fstrict-aliasing"
nkeynes@1239
    59
            ;;
nkeynes@1239
    60
         *)
nkeynes@1255
    61
            AC_MSG_ERROR([Unsupported android ABI $ANDROID_ABI])
nkeynes@1239
    62
      	    ;;
nkeynes@1239
    63
      esac
nkeynes@1239
    64
   
nkeynes@1239
    65
      AC_PATH_PROG( ANT, [ant] )
nkeynes@1239
    66
      
nkeynes@1239
    67
      CC="$ANDROID_NDK_BIN/${host_alias}-gcc"
nkeynes@1239
    68
      CXX="$ANDROID_NDK_BIN/${host_alias}-g++"
nkeynes@1239
    69
      CPP="$ANDROID_NDK_BIN/${host_alias}-cpp"
nkeynes@1239
    70
      LD="$ANDROID_NDK_BIN/${host_alias}-ld"
nkeynes@1239
    71
      AR="$ANDROID_NDK_BIN/${host_alias}-ar"
nkeynes@1239
    72
      RANLIB="$ANDROID_NDK_BIN/${host_alias}-ranlib"
nkeynes@1239
    73
      STRIP="$ANDROID_NDK_BIN/${host_alias}-strip"
nkeynes@1239
    74
      OBJDUMP="$ANDROID_NDK_BIN/${host_alias}-objdump"
nkeynes@1239
    75
      CPPFLAGS="-fPIC --sysroot=$ANDROID_SYSROOT -I$ANDROID_SYSROOT/usr/include $TARGETFLAGS $CPPFLAGS"
nkeynes@1239
    76
      LDFLAGS="-nostdlib -Wl,--no-undefined -L${ANDROID_SYSROOT}/usr/lib -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib -Wl,-allow-shlib-undefined -Wl,-z,noexecstack $LDFLAGS"
nkeynes@1245
    77
      LIBS="$LIBS -liconv -landroid -llog -lgcc -lc -lm"
nkeynes@1239
    78
      
nkeynes@1255
    79
      AC_SUBST(ANDROID_ABI)
nkeynes@1239
    80
      AC_SUBST(ANDROID_SDK_HOME)
nkeynes@1239
    81
      AC_SUBST(ANDROID_NDK_HOME)
nkeynes@1239
    82
      AC_SUBST(ANDROID_SDK_VERSION)
nkeynes@1245
    83
      AC_SUBST(ANDROID_NDK_VERSION)
nkeynes@1239
    84
      AC_SUBST(ANDROID_GDBSERVER)
nkeynes@1239
    85
      
nkeynes@1239
    86
      ANDROID_BUILD=yes
nkeynes@1239
    87
      cross_compiling=yes
nkeynes@1239
    88
   fi
nkeynes@1239
    89
   
nkeynes@1239
    90
   AM_CONDITIONAL(GUI_ANDROID, [test "$ANDROID_BUILD" = "yes"])
nkeynes@1239
    91
        
nkeynes@1239
    92
])
.