Skip to content

Instantly share code, notes, and snippets.

@43z3com
Last active August 29, 2015 14:02
Show Gist options
  • Save 43z3com/be6bdb5e9aaf4a6a6eb3 to your computer and use it in GitHub Desktop.
Save 43z3com/be6bdb5e9aaf4a6a6eb3 to your computer and use it in GitHub Desktop.
#!/bin/bash
: << '#__REM__'
ffmpegをAndroid用にビルドします。ダウンロード、toolchainsの作成、複数のアーキテクチャのビルドまでを自動で行います。デフォルトでは2.2.3をarmv5te、armv7-a、mips32r2、atomのアーキテクチャを作成します。
Build for Android and ffmpeg. Build a full auto of architecture and multiple creation of toolchains and downloads Create the following architecture, version 2.2.3 by default
armv5te, armv7-a, mips32r2, atom
#__REM__
TARGET_VERSION="2.2.3"
ARCHIVE_BASENAME="ffmpeg"
ARCHIVE_FILE="${ARCHIVE_BASENAME}-${TARGET_VERSION}.tar.bz2"
ARCHIVE_TYPE="tar.bz2"
DOWNLOAD_URL="http://www.ffmpeg.org/releases/${ARCHIVE_FILE}"
#android
#NDK_ROOT="/Workshop/Android-SDK/android-ndk-r8e"
DEPLOYMENT_TARGET="android"
# see ${NDK-ROOT}/platforms
ANDROID_PLATFORM=9
# see ${NDK-ROOT}/toolchains
ARCHS="[email protected] [email protected] [email protected] [email protected]"
NEON=1 #only armv7 or more
#VFP="vfpv3-d16" #only armv7 or more
VFP="vfpv4"
THUMB=0 #only armv7 or more
FILE_API_32=1
COCOS2DX=1
DEBUG=0
VERBOSE=1
########################################
if [ ! -n "${NDK_ROOT}" ]; then
echo "NDK_ROOT is not defined"
exit ;
fi
NDK="${NDK_ROOT}"
cd "`dirname \"$0\"`"
REPOROOT="$(pwd)"
OUTPUT_DIR="${REPOROOT}/dependencies-lib"
mkdir -p "${OUTPUT_DIR}"
BUILD_DIR="${REPOROOT}/build"
SRC_DIR="${BUILD_DIR}/src"
mkdir -p "${SRC_DIR}"
WORK_DIR="${BUILD_DIR}/work"
mkdir -p "${WORK_DIR}"
INTER_DIR="${BUILD_DIR}/built"
mkdir -p "${INTER_DIR}"
export TOOLCHAIN_BASE_DIR="${WORK_DIR}/toolchain"
########################################
#set -x
cd $SRC_DIR
set -e
if [ "${ARCHIVE_FILE}" == "" ]; then
ARCHIVE_FILE="src_archive.${ARCHIVE_TYPE}"
fi
if [ "`ls -F | grep /`" == "" ]; then
cat <<_EOT_
##############################################################################
####
#### Downloading ${ARCHIVE_BASENAME}-${TARGET_VERSION}.tar.gz
####
##############################################################################
_EOT_
#curl -O ${DOWNLOAD_URL}
wget "${DOWNLOAD_URL}" -O "${ARCHIVE_FILE}"
echo "Done." ; echo ""
cat <<_EOT_
##############################################################################
####
#### Using ${ARCHIVE_FILE}
####
##############################################################################
_EOT_
#tar jxf ${ARCHIVE_FILE} -C ${SRC_DIR}
#tar zxf ${ARCHIVE_FILE} -C ${SRC_DIR}
case "${ARCHIVE_TYPE}" in
"tar.gz" )
tar zxf ${ARCHIVE_FILE} -C ${SRC_DIR}
;;
"tar.bz2" )
tar jxf ${ARCHIVE_FILE} -C ${SRC_DIR}
;;
"tar.xz" )
tar Jxf ${ARCHIVE_FILE} -C ${SRC_DIR}
;;
".tar.lzma" )
tar xf --lzma ${ARCHIVE_FILE} -C ${SRC_DIR}
;;
esac
fi
ARCHIVE_OUT="`ls -F ${SRC_DIR} | grep /`"
cd "${SRC_DIR}/${ARCHIVE_OUT}"
export ORIGINALPATH="$PATH"
MACHINE=`uname -m | tr '[A-Z]' '[a-z]'`
SYSNAME=`uname -s | tr '[A-Z]' '[a-z]'`
BUILD="${MACHINE}-${SYSNAME}"
for ELEM in ${ARCHS}
do
OIFS="$IFS"; IFS='@'
set -- ${ELEM}; IFS="$OIFS"
ARCH="$1"
TOOLCHAIN="$2"
if [ ! -e "${TOOLCHAIN_BASE_DIR}/${ARCH}@${TOOLCHAIN}" ]; then
cat <<_EOT_
##############################################################################
####
#### Generate toolchain ${TOOLCHAIN}
####
##############################################################################
_EOT_
"${NDK}/build/tools/make-standalone-toolchain.sh" --platform="android-${ANDROID_PLATFORM}" --toolchain="${TOOLCHAIN}" --install-dir="${TOOLCHAIN_BASE_DIR}/${ARCH}@${TOOLCHAIN}" --system="${SYSNAME}-${MACHINE}"
echo ""
fi
TOOLCHAIN_DIR="${TOOLCHAIN_BASE_DIR}/${ARCH}@${TOOLCHAIN}"
PREFIX="${INTER_DIR}/${ARCHIVE_BASENAME}-${TARGET_VERSION}-android-${ANDROID_PLATFORM}-${ARCH}"
mkdir -p "${PREFIX}"
export PATH="$ORIGINALPATH"
cat <<_EOT_
##############################################################################
####
#### Configure ${ARCH}
####
##############################################################################
_EOT_
case "${ARCH}" in
"armv5te" )
export PATH="${TOOLCHAIN_DIR}/bin:${TOOLCHAIN_DIR}/arm-linux-androideabi/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/sbin"
HOST_CC="${TOOLCHAIN_DIR}/bin/arm-linux-androideabi-gcc"
HOST_CFLAGS="\
-D_GNU_SOURCE=1 \
-DANDROID \
-D__ARM_ARCH_5__ \
-D__ARM_ARCH_5T__ \
-D__ARM_ARCH_5E__ \
-D__ARM_ARCH_5TE__ \
-mfloat-abi=softfp \
"
HOST_LDFLAGS=""
HOST_SYSROOT="${TOOLCHAIN_DIR}/sysroot"
if [ ${DEBUG} -eq 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -O3 -DNDEBUG"
else
HOST_CFLAGS="${HOST_CFLAGS} -O0 -g -DDEBUG"
fi
if [ ${COCOS2DX} -ne 0 ]; then
FILE_API_32=1
if [ ${DEBUG} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -DCOCOS2D_DEBUG=2"
fi
fi
if [ ${FILE_API_32} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS -D_FILE_OFFSET_BITS=32 -DUSE_FILE32API"
fi
CONFIGURE_EXTEA="${CONFIGURE_EXTEA} --disable-neon"
CONFIGURE_EXTEA="${CONFIGURE_EXTEA} --disable-vfp"
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=${TOOLCHAIN_DIR}/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=${HOST_SYSROOT} \
--extra-cflags="${HOST_CFLAGS}" \
--extra-ldflags="${HOST_LDFLAGS}" \
${CONFIGURE_EXTEA}
;;
"armv7" | "armv7-a" )
export PATH="${TOOLCHAIN_DIR}/bin:${TOOLCHAIN_DIR}/arm-linux-androideabi/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/sbin"
HOST_CC="${TOOLCHAIN_DIR}/bin/arm-linux-androideabi-gcc"
HOST_CFLAGS="\
-D_GNU_SOURCE=1 \
-DANDROID \
-DAL_LIBTYPE_STATIC \
-DAL_ALEXT_PROTOTYPES \
-D__ARM_ARCH_7__ \
-D__ARM_ARCH_7A__ \
-D__TARGET_ARCH_7 \
"
HOST_LDFLAGS="-Wl,--fix-cortex-a8"
HOST_SYSROOT="${TOOLCHAIN_DIR}/sysroot"
if [ ${DEBUG} -eq 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -O3 -DNDEBUG"
else
HOST_CFLAGS="${HOST_CFLAGS} -O0 -g -DDEBUG"
fi
if [ ${COCOS2DX} -ne 0 ]; then
FILE_API_32=1
if [ ${DEBUG} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -DCOCOS2D_DEBUG=2"
fi
fi
if [ ${FILE_API_32} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS -D_FILE_OFFSET_BITS=32 -DUSE_FILE32API"
fi
if [ ${NEON} -eq 0 ]; then
CONFIGURE_EXTEA="${CONFIGURE_EXTEA} --disable-neon"
else
HOST_CFLAGS="${HOST_CFLAGS} -mfpu=neon -ffast-math"
fi
if [ "${VFP}" == "" ]; then
CONFIGURE_EXTEA="${CONFIGURE_EXTEA} --disable-vfp"
HOST_CFLAGS="${HOST_CFLAGS} -mfloat-abi=softfp"
else
HOST_CFLAGS="${HOST_CFLAGS} -mfpu=${VFP}"
fi
if [ ${THUMB} -ne 0 ]; then
CONFIGURE_EXTEA="${CONFIGURE_EXTEA} --enable-thumb"
fi
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=${TOOLCHAIN_DIR}/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--cpu=${ARCH} \
--enable-cross-compile \
--sysroot=${HOST_SYSROOT} \
--extra-cflags="${HOST_CFLAGS}" \
--extra-ldflags="${HOST_LDFLAGS}" \
${CONFIGURE_EXTEA}
;;
"mips32r2" )
export PATH="${TOOLCHAIN_DIR}/bin:${TOOLCHAIN_DIR}/mipsel-linux-android/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/sbin"
HOST_CC="${TOOLCHAIN_DIR}/bin/mipsel-linux-android-gcc"
HOST_CFLAGS="\
-D_GNU_SOURCE=1 \
-DANDROID \
"
HOST_LDFLAGS=""
HOST_SYSROOT="${TOOLCHAIN_DIR}/sysroot"
if [ ${DEBUG} -eq 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -O3 -DNDEBUG"
else
HOST_CFLAGS="${HOST_CFLAGS} -O0 -g -DDEBUG"
fi
if [ ${COCOS2DX} -ne 0 ]; then
FILE_API_32=1
if [ ${DEBUG} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -DCOCOS2D_DEBUG=2"
fi
fi
if [ ${FILE_API_32} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS -D_FILE_OFFSET_BITS=32 -DUSE_FILE32API"
fi
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=${TOOLCHAIN_DIR}/bin/mipsel-linux-android- \
--target-os=linux \
--arch=mips32 \
--cpu=${ARCH} \
--enable-cross-compile \
--sysroot=${HOST_SYSROOT} \
--extra-cflags="${HOST_CFLAGS}" \
--extra-ldflags="${HOST_LDFLAGS}" \
${CONFIGURE_EXTEA}
;;
"i386" | "i686" | "atom" )
export PATH="${TOOLCHAIN_DIR}/bin:${TOOLCHAIN_DIR}/i686-linux-android/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/opt/local/sbin"
HOST_CC="${TOOLCHAIN_DIR}/bin/i686-linux-android-gcc"
HOST_CFLAGS="\
-D_GNU_SOURCE=1 \
-DANDROID \
"
HOST_LDFLAGS=""
HOST_SYSROOT="${TOOLCHAIN_DIR}/sysroot"
if [ ${DEBUG} -eq 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -O3 -DNDEBUG"
else
HOST_CFLAGS="${HOST_CFLAGS} -O0 -g -DDEBUG"
fi
if [ ${COCOS2DX} -ne 0 ]; then
FILE_API_32=1
if [ ${DEBUG} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -DCOCOS2D_DEBUG=2"
fi
fi
if [ ${FILE_API_32} -ne 0 ]; then
HOST_CFLAGS="${HOST_CFLAGS} -U_LARGEFILE_SOURCE -U_FILE_OFFSET_BITS -D_FILE_OFFSET_BITS=32 -DUSE_FILE32API"
fi
#An error occurred in the assembler code
CONFIGURE_EXTEA="${CONFIGURE_EXTEA} --disable-asm"
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=${TOOLCHAIN_DIR}/bin/i686-linux-android- \
--target-os=linux \
--arch=x86 \
--cpu=${ARCH} \
--enable-cross-compile \
--sysroot=${HOST_SYSROOT} \
--extra-cflags="${HOST_CFLAGS}" \
--extra-ldflags="${HOST_LDFLAGS}" \
${CONFIGURE_EXTEA}
;;
* )
echo "ERROR: ${ARCH} is not supported"
exit
;;
esac
echo "Done." ; echo ""
cat <<_EOT_
##############################################################################
####
#### Make ${ARCH}
####
##############################################################################
_EOT_
make V=${VERBOSE} clean
make -j4 V=${VERBOSE}
make -j4 V=${VERBOSE} install
echo "Done." ; echo ""
cat <<_EOT_
##############################################################################
####
#### Build library ${ARCH}
####
##############################################################################
_EOT_
PREFIX="${INTER_DIR}/${ARCHIVE_BASENAME}-${TARGET_VERSION}-android-${ANDROID_PLATFORM}-${ARCH}"
PLATFORM_OUT_DIR="${OUTPUT_DIR}/${ARCHIVE_BASENAME}-${TARGET_VERSION}-android-${ANDROID_PLATFORM}-${ARCH}"
mkdir -p "${PLATFORM_OUT_DIR}"
cp -R "${PREFIX}/include" "${PLATFORM_OUT_DIR}"
cp -R "${PREFIX}/lib" "${PLATFORM_OUT_DIR}"
echo "Done." ; echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment