#!/bin/bash
export VERSION=4.6
export NDK=/opt/google/android-ndk-r9b
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-$VERSION/prebuilt/linux-x86_64
export PLATFORM=$NDK/platforms/android-9/arch-arm
export FFMPEG_ROOT=../ffmpeg-1.2.4
export X264_ROOT=../x264 #上面的x264的源码目录
export PREFIX=../install
export ELIB="$PREFIX/lib"
export FAAC_ROOT=../faac-1.28
function build_x264
{
cd $X264_ROOT
pwd
./configure --enable-static \
--prefix=$PREFIX \
--enable-shared \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM
make
cp libx264.a $ELIB
cd -
}
function build_faac
{
cd $FAAC_ROOT
pwd
CFLAGS="-fpic -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID -Wa,--noexecstack -MMD -MP "
#FLAGS="--host=arm-androideabi-linux --enable-static --disable-shared --prefix=$HOME --enable-armv5e "
CROSS_COMPILE=$PREBUILT/bin/arm-linux-androideabi-
export CPPFLAGS="$CFLAGS"
export CFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export CXX="${CROSS_COMPILE}g++ --sysroot=${PLATFORM}"
export LDFLAGS="$LDFLAGS"
export CC="${CROSS_COMPILE}gcc --sysroot=${PLATFORM}"
export NM="${CROSS_COMPILE}nm"
export STRIP="${CROSS_COMPILE}strip"
export RANLIB="${CROSS_COMPILE}ranlib"
export AR="${CROSS_COMPILE}ar"
./configure --program-prefix=$PREFIX \
--host=arm-linux
make
cp ./libfaac/.libs/libfaac.a $ELIB
cd -
}
function build_one
{
$FFMPEG_ROOT/configure --target-os=linux \
--prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-nonfree \
--enable-version3 \
--enable-gpl \
--disable-doc \
--enable-avresample \
--enable-demuxer=rtsp \
--enable-muxer=rtsp \
--disable-ffplay \
--disable-ffserver \
--enable-ffmpeg \
--disable-ffprobe \
--enable-libx264 \
--enable-libfaac --enable-nonfree \
--enable-encoder=libx264 \
--enable-decoder=h264 \
--enable-protocol=rtp \
--enable-encoder=libfaac \
--enable-decoder=aac \
--enable-hwaccels \
--enable-zlib \
--disable-devices \
--disable-avdevice \
--extra-cflags="-I$X264_ROOT -I$FAAC_ROOT/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
--extra-ldflags="-L$ELIB"
make -j4
make install
}
mkdir -p $ELIB
build_faac
build_x264
build_one