iOS开发之Lame编译
作者:互联网
前言
为了保证音频格式在多端通用,需要将音频转化为MP3
格式,本文讲解了如何使用Shell
脚本来编译lame
库。
编译脚本
#!/bin/sh
CONFIGURE_FLAGS="--disable-shared --disable-frontend"
ARCHS="arm64 armv7s armv7 x86_64 i386"
MIN_VERSION="10.0"
# directories
SOURCE="lame"
FAT="fat-lame"
SCRATCH="scratch-lame"
# must be an absolute path
THIN=`pwd`/"thin-lame"
COMPILE="y"
LIPO="y"
if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi
if [ "$COMPILE" ]
then
CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
if [ "$ARCH" = "x86_64" ]
then
SIMULATOR="-mios-simulator-version-min=7.0"
HOST=x86_64-apple-darwin
else
SIMULATOR="-mios-simulator-version-min=5.0"
HOST=i386-apple-darwin
fi
else
PLATFORM="iPhoneOS"
SIMULATOR=
HOST=arm-apple-darwin
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang -arch $ARCH -miphoneos-version-min=${MIN_VERSION}"
#AS="$CWD/$SOURCE/extras/gas-preprocessor.pl $CC"
CFLAGS="-arch $ARCH $SIMULATOR"
if ! xcodebuild -version | grep "Xcode [1-6]\."
then
CFLAGS="$CFLAGS -fembed-bitcode"
fi
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
CC=$CC $CWD/$SOURCE/configure \
$CONFIGURE_FLAGS \
--host=$HOST \
--prefix="$THIN/$ARCH" \
CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"
make -j3 install
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB
done
cd $CWD
cp -rf $THIN/$1/include $FAT
fi
使用步骤
- 下载lame
- 解压后将
lame
和脚本放到同一文件夹下 - 修改
lame
文件夹名称,去除版本号 - 打开终端,切换到文件夹路径
- 执行
shell
脚本
注意事项
- 文件夹路径不要包含中文
fat
版本包含真机和模拟器
标签:lame,CC,Lame,iOS,编译,CFLAGS,fi,ARCH,CWD 来源: https://www.cnblogs.com/JmoVxia/p/14893335.html