blob: 8947f113f928ca3744aec3af1f596cc6730764cf [file] [log] [blame]
#!/bin/bash
ROOT_PATH=`pwd`/`dirname "$0"`
LIB_PATH=ffmpeg_build
SDKROOT_TVOS_DEVICE=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk
SDKROOT_TVOS_SIMULATOR=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk
mkdir -p $ROOT_PATH/$LIB_PATH/{arm64-tvos,x86_64-tvos}
PATH=$PATH:$ROOT_PATH
COMMON_PARAMS="--disable-doc --disable-ffplay --disable-ffserver \
--disable-encoders --disable-decoders --disable-hwaccels --disable-iconv \
--disable-muxers --disable-demuxers --disable-parsers --disable-bsfs \
--disable-protocols --disable-indevs --disable-outdevs --disable-devices \
--disable-filters --disable-network --disable-zlib --disable-bzlib \
--enable-small --disable-swscale-alpha --disable-runtime-cpudetect \
--enable-decoder=h264 \
--enable-demuxer=h264 \
--enable-parser=h264 \
--enable-protocol=file \
--enable-pic"
# build arm64/tvos device
cd $ROOT_PATH/$LIB_PATH/arm64-tvos
../../ffmpeg/configure --enable-cross-compile --arch=arm64 --target-os=darwin \
--cc=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
--sysroot=$SDKROOT_TVOS_DEVICE \
--extra-cflags='-arch arm64 -mtvos-version-min=9.0 -fembed-bitcode' \
--extra-ldflags="-arch arm64 -isysroot $SDKROOT_TVOS_DEVICE -mtvos-version-min=9.0" \
$COMMON_PARAMS
make V=1
# build x86/simulator
# (note: not with assembly)
cd $ROOT_PATH/$LIB_PATH/x86_64-tvos
../../ffmpeg/configure --enable-cross-compile --arch=x86_64 --target-os=darwin \
--cc=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
--sysroot=$SDKROOT_TVOS_SIMULATOR \
--extra-cflags='-arch x86_64 -mtvos-simulator-version-min=9.0' \
--extra-ldflags="-arch x86_64 -isysroot $SDKROOT_TVOS_SIMULATOR -mtvos-simulator-version-min=9.0" \
--disable-asm \
$COMMON_PARAMS
make V=1
# make fat library for each CPU
cd $ROOT_PATH/$LIB_PATH
for l in `echo -ne "libavcodec\nlibavdevice\nlibavformat\nlibavutil\nlibswscale"`; do
lipo -create "arm64-tvos/$l/$l.a" "x86_64-tvos/$l/$l.a" -output "$l-tvos.a";
done
# copy header files to build directory
for l in `echo -ne "libavcodec\nlibavdevice\nlibavformat\nlibavutil\nlibswscale"`; do
mkdir -p $ROOT_PATH/$LIB_PATH/include/$l
cp $ROOT_PATH/ffmpeg/$l/*.h $ROOT_PATH/$LIB_PATH/include/$l
done
# make universal avconfig.h file
AVCONFIG_H=$ROOT_PATH/$LIB_PATH/include/libavutil/avconfig.h
echo "#if defined __arm64__" > $AVCONFIG_H
cat arm64-tvos/libavutil/avconfig.h >> $AVCONFIG_H
echo "#elif defined __x86_64__" >> $AVCONFIG_H
cat x86_64-tvos/libavutil/avconfig.h >> $AVCONFIG_H
echo "#else" >> $AVCONFIG_H
echo "#error ffmpeg not compiled for target architecture" >> $AVCONFIG_H
echo "#endif" >> $AVCONFIG_H