iOS開發之Lame編譯
阿新 • • 發佈:2021-06-17
前言
為了保證音訊格式在多端通用,需要將音訊轉化為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
版本包含真機和模擬器