Build Opus Codec for iOS

项目中需要使用Opus Codec for iOS, 在github 上找了一个不错的脚本,  对其稍作修改, 编译非常顺利。 如下为脚本代码。 

[plain] view plain copy
  1. #!/bin/bash  
  2.   
  3. VERSION="1.1.2"   #Opus Version  
  4. SDKVERSION="9.2"  
  5. MINIOSVERSION="7.0"  
  6.   
  7. # by default, we won't build for debugging purposes  
  8. if [ "${DEBUG}" == "true" ]; then  
  9.     echo "Compiling for debugging ..."  
  10.     OPT_CFLAGS="-O0 -fno-inline -g"  
  11.     OPT_LDFLAGS=""  
  12.     OPT_CONFIG_ARGS="--enable-assertions --disable-asm"  
  13. else  
  14.     OPT_CFLAGS="-Ofast -flto -g"  
  15.     OPT_LDFLAGS="-flto"  
  16.     OPT_CONFIG_ARGS=""  
  17. fi  
  18.   
  19. ARCHS="i386 x86_64 armv7 armv7s arm64"  
  20. DEVELOPER=`xcode-select -print-path`  
  21. cd "`dirname \"$0\"`"  
  22. REPOROOT=$(pwd)  
  23.   
  24. OUTPUTDIR="${REPOROOT}/out"  
  25. mkdir -p ${OUTPUTDIR}/include  
  26. mkdir -p ${OUTPUTDIR}/lib  
  27. BUILDDIR="${REPOROOT}/build"  
  28.   
  29. echo $REPOROOT  
  30. echo $OUTPUTDIR  
  31. echo $BUILDDIR  
  32.   
  33. SRCDIR=$REPOROOT  
  34. INTERDIR="${BUILDDIR}/built"  
  35. mkdir -p $INTERDIR  
  36.   
  37. set +e  
  38. CCACHE=`which ccache`  
  39. if [ $? == "0" ]; then  
  40.     echo "Building with ccache: $CCACHE"  
  41.     CCACHE="${CCACHE} "  
  42. else  
  43.     echo "Building without ccache"  
  44.     CCACHE=""  
  45. fi  
  46.   
  47. set -e  
  48. export ORIGINALPATH=$PATH  
  49. for ARCH in ${ARCHS}  
  50. do  
  51.     if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; then  
  52.         PLATFORM="iPhoneSimulator"  
  53.         EXTRA_CFLAGS="-arch ${ARCH}"  
  54.         EXTRA_CONFIG=""  
  55.     else  
  56.         PLATFORM="iPhoneOS"  
  57.         EXTRA_CFLAGS="-arch ${ARCH}"  
  58.         EXTRA_CONFIG="--host=arm-apple-darwin"  
  59.     fi  
  60.     mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"  
  61.     ./configure --enable-float-approx --disable-shared --enable-static --with-pic --disable-extra-programs --disable-doc ${EXTRA_CONFIG} \  
  62.     --prefix="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" \  
  63.     LDFLAGS="$LDFLAGS ${OPT_LDFLAGS} -fPIE -miphoneos-version-min=${MINIOSVERSION} -L${OUTPUTDIR}/lib" \  
  64.     CFLAGS="$CFLAGS ${EXTRA_CFLAGS} ${OPT_CFLAGS} -fPIE -miphoneos-version-min=${MINIOSVERSION} -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \  
  65.     # Build the application and install it to the fake SDK intermediary dir  
  66.     # we have set up. Make sure to clean up afterward because we will re-use  
  67.     # this source tree to cross-compile other targets.  
  68.     make -j4  
  69.     make install  
  70.     make clean  
  71. done  
  72.   
  73. ########################################  
  74. echo "Build library..."  
  75. # These are the libs that comprise libopus.  
  76. OUTPUT_LIBS="libopus.a"  
  77. for OUTPUT_LIB in ${OUTPUT_LIBS}; do  
  78.     INPUT_LIBS=""  
  79.     for ARCH in ${ARCHS}; do  
  80.         if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ];  
  81.         then  
  82.             PLATFORM="iPhoneSimulator"  
  83.         else  
  84.             PLATFORM="iPhoneOS"  
  85.         fi  
  86.         INPUT_ARCH_LIB="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/lib/${OUTPUT_LIB}"  
  87.         if [ -e $INPUT_ARCH_LIB ]; then  
  88.             INPUT_LIBS="${INPUT_LIBS} ${INPUT_ARCH_LIB}"  
  89.         fi  
  90.     done  
  91.     # Combine the three architectures into a universal library.  
  92.     if [ -n "$INPUT_LIBS"  ]; then  
  93.         lipo -create $INPUT_LIBS \  
  94.         -output "${OUTPUTDIR}/lib/${OUTPUT_LIB}"  
  95.     else  
  96.         echo "$OUTPUT_LIB does not exist, skipping (are the dependencies installed?)"  
  97.     fi  
  98. done  
  99. for ARCH in ${ARCHS}; do  
  100.     if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ];  
  101.     then  
  102.         PLATFORM="iPhoneSimulator"  
  103.     else  
  104.         PLATFORM="iPhoneOS"  
  105.     fi  
  106.     cp -R ${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include/* ${OUTPUTDIR}/include/  
  107.     if [ $? == "0" ]; then  
  108.         # We only need to copy the headers over once. (So break out of forloop  
  109.         # once we get first success.)  
  110.         break  
  111.     fi  
  112. done  
  113. ####################  
  114. echo "Building done."  
  115. echo "Cleaning up..."  
  116. rm -fr ${INTERDIR}  
  117.   
  118. echo "Done."  

Reference:  

     很棒的Opus iOS编译脚本,上面的代码大多从次复制。    https://github.com/chrisballinger/Opus-iOS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值