[Android] [PATCH 1/2] Support compiling on Android-x86

Edward Wang edward.c.wang at compdigitec.com
Thu Jul 26 02:32:15 CEST 2012


This also softens the ground for the upcoming MIPS port too.

Signed-off-by: Rafaël Carré <funman at videolan.org>
---
 Makefile     |    4 ++--
 compile.sh   |   32 +++++++++++++++++++++++++++++---
 configure.sh |   34 ++++++++++++++++++++--------------
 3 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile
index 6022f8e..7f6e946 100644
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,7 @@ $(LIBVLCJNI_H):
 	printf "/* Autogenerated from the list of modules */\n $$DEFINITION\n $$BUILTINS\n" > $@
 
 $(PRIVATE_LIBDIR)/%.so: $(PRIVATE_LIBDIR)/%.c
-	$(GEN)arm-linux-androideabi-gcc $< -shared -o $@ --sysroot=$(ANDROID_NDK)/platforms/android-3/arch-arm
+	$(GEN)$(TARGET_TUPLE)-gcc $< -shared -o $@ --sysroot=$(ANDROID_NDK)/platforms/android-9/arch-$(PLATFORM_SHORT_ARCH)
 
 $(PRIVATE_LIBDIR)/%.c: $(PRIVATE_LIBDIR)/%.symbols
 	$(VERBOSE)rm -f $@
@@ -75,7 +75,7 @@ $(LIBVLCJNI): $(JNI_SOURCES) $(LIBVLCJNI_H) $(PRIVATE_LIBS)
 	@echo "=== Building libvlcjni with$${NO_NEON:+out} neon ==="
 	@echo
 	$(VERBOSE)if [ -z "$(VLC_SRC_DIR)" ] ; then VLC_SRC_DIR=./vlc; fi ; \
-	if [ -z "$(VLC_CONTRIB)" ] ; then VLC_CONTRIB="$$VLC_SRC_DIR/contrib/arm-linux-androideabi"; fi ; \
+	if [ -z "$(VLC_CONTRIB)" ] ; then VLC_CONTRIB="$$VLC_SRC_DIR/contrib/$(TARGET_TUPLE)"; fi ; \
 	vlc_modules="$(VLC_MODULES)" ; \
 	if [ `echo "$(VLC_BUILD_DIR)" | head -c 1` != "/" ] ; then \
 		vlc_modules="`echo $$vlc_modules|sed \"s|$(VLC_BUILD_DIR)|../$(VLC_BUILD_DIR)|g\"`" ; \
diff --git a/compile.sh b/compile.sh
index d03a9b9..cefd02f 100755
--- a/compile.sh
+++ b/compile.sh
@@ -31,9 +31,33 @@ if [ -z $REL ]; then
     exit 1
 fi
 
+# Set up ABI variables
+if [ ${ANDROID_ABI} = "x86" ] ; then
+    TARGET_TUPLE="i686-android-linux"
+    PATH_HOST="x86"
+    HAVE_X86=1
+    PLATFORM_SHORT_ARCH="x86"
+elif [ ${ANDROID_ABI} = "mips" ] ; then
+    TARGET_TUPLE="mipsel-linux-android"
+    PATH_HOST=$TARGET_TUPLE
+    HAVE_MIPS=1
+    PLATFORM_SHORT_ARCH="mips"
+else
+    TARGET_TUPLE="arm-linux-androideabi"
+    PATH_HOST=$TARGET_TUPLE
+    HAVE_ARM=1
+    PLATFORM_SHORT_ARCH="arm"
+fi
+export TARGET_TUPLE
+export PATH_HOST
+export HAVE_ARM
+export HAVE_X86
+export HAVE_MIPS
+export PLATFORM_SHORT_ARCH
+
 # Add the NDK toolchain to the PATH, needed both for contribs and for building
 # stub libraries
-export PATH=${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:${PATH}
+export PATH=${ANDROID_NDK}/toolchains/${PATH_HOST}-4.4.3/prebuilt/linux-x86/bin:${PATH}
 
 # 1/ libvlc, libvlccore and its plugins
 TESTED_HASH=57cace3
@@ -76,7 +100,7 @@ fi
 echo "Building the contribs"
 mkdir -p contrib/android
 cd contrib/android
-../bootstrap --host=arm-linux-androideabi --disable-disc --disable-sout --enable-small \
+../bootstrap --host=${TARGET_TUPLE} --disable-disc --disable-sout --enable-small \
     --disable-sdl \
     --disable-SDL_image \
     --disable-fontconfig \
@@ -115,6 +139,8 @@ elif [ ${ANDROID_ABI} = "armeabi" ] ; then
             EXTRA_CFLAGS="-mfpu=vfp -mcpu=arm1136jf-s -mfloat-abi=softfp"
         fi
     fi
+elif [ ${ANDROID_ABI} = "x86" ] ; then
+    EXTRA_CFLAGS="-march=pentium -ffunction-sections -funwind-tables -frtti -fno-exceptions"
 else
     echo "Unknown ABI. Die, die, die!"
     exit 2
@@ -146,7 +172,7 @@ echo "Configuring"
 ../../configure.sh $OPTS
 
 echo "Building"
-make
+make TARGET_TUPLE=$(TARGET_TUPLE) PLATFORM_SHORT_ARCH=$(PLATFORM_SHORT_ARCH)
 
 
 # 2/ VLC android UI and specific code
diff --git a/configure.sh b/configure.sh
index 788631b..2a5997a 100755
--- a/configure.sh
+++ b/configure.sh
@@ -12,26 +12,32 @@ ANDROID_API=android-9
 
 VLC_SOURCEDIR=..
 
-CFLAGS="-g -O2 -mlong-calls -fstrict-aliasing -funsafe-math-optimizations"
+CFLAGS="-g -O2 -fstrict-aliasing -funsafe-math-optimizations"
+if [ -n "$HAVE_ARM" ]; then
+    CFLAGS="${CFLAGS} -mlong-calls"
+fi
+
 LDFLAGS="-Wl,-Bdynamic,-dynamic-linker=/system/bin/linker -Wl,--no-undefined"
 
-if [ -z "$NO_NEON" ]; then
-    NO_NEON=0
-fi
+if [ -n "$HAVE_ARM" ]; then
+    if [ -z "$NO_NEON" ]; then
+        NO_NEON=0
+    fi
 
-if [ $NO_NEON -gt 0 ]; then
-    EXTRA_PARAMS=" --disable-neon"
-else
-    EXTRA_PARAMS=" --enable-neon"
-    LDFLAGS="$LDFLAGS -Wl,--fix-cortex-a8"
+    if [ $NO_NEON -gt 0 ]; then
+        EXTRA_PARAMS=" --disable-neon"
+    else
+        EXTRA_PARAMS=" --enable-neon"
+        LDFLAGS="$LDFLAGS -Wl,--fix-cortex-a8"
+    fi
 fi
 
 CPPFLAGS="-I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_ABI}/include"
 LDFLAGS="$LDFLAGS -L${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_ABI}"
 
-SYSROOT=$ANDROID_NDK/platforms/$ANDROID_API/arch-arm
-ANDROID_BIN=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86/bin/
-CROSS_COMPILE=${ANDROID_BIN}/arm-linux-androideabi-
+SYSROOT=$ANDROID_NDK/platforms/$ANDROID_API/arch-$PLATFORM_SHORT_ARCH
+ANDROID_BIN=$ANDROID_NDK/toolchains/${PATH_HOST}-4.4.3/prebuilt/linux-x86/bin/
+CROSS_COMPILE=${ANDROID_BIN}/${TARGET_TUPLE}-
 
 CPPFLAGS="$CPPFLAGS" \
 CFLAGS="$CFLAGS ${VLC_EXTRA_CFLAGS}" \
@@ -43,7 +49,7 @@ NM="${CROSS_COMPILE}nm" \
 STRIP="${CROSS_COMPILE}strip" \
 RANLIB="${CROSS_COMPILE}ranlib" \
 AR="${CROSS_COMPILE}ar" \
-sh $VLC_SOURCEDIR/configure --host=arm-linux-androideabi --build=x86_64-unknown-linux $EXTRA_PARAMS \
+sh $VLC_SOURCEDIR/configure --host=$TARGET_TUPLE --build=x86_64-unknown-linux $EXTRA_PARAMS \
                 --enable-live555 --enable-realrtsp \
                 --enable-avformat \
                 --enable-swscale \
-- 
1.7.5.4



More information about the Android mailing list