转一段 Xcode6 下编译x264的脚本

下载最新x264源码 ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
下载gas-preprocessor https://github.com/libav/gas-preprocessor 并copy到 /usr/local/bin/gas-preprocessor.pl

#!/bin/sh

CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli"

ARCHS="arm64 armv7s x86_64 i386 armv7"

# directories
SOURCE="x264"
FAT="x264-iOS"

SCRATCH="scratch-x264"
# must be an absolute path
THIN=`pwd`/"thin-x264"

# the one included in x264 does not work; specify full path to working one
GAS_PREPROCESSOR=/usr/local/bin/gas-preprocessor.pl

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"
		    CPU=
		    if [ "$ARCH" = "x86_64" ]
		    then
		    	SIMULATOR="-mios-simulator-version-min=7.0"
		    	HOST=
		    else
		    	SIMULATOR="-mios-simulator-version-min=5.0"
			HOST="--host=i386-apple-darwin"
		    fi
		else
		    PLATFORM="iPhoneOS"
		    if [ $ARCH = "armv7s" ]
		    then
		    	CPU="--cpu=swift"
		    else
		    	CPU=
		    fi
		    SIMULATOR=
		    if [ $ARCH = "arm64" ]
		    then
		        HOST="--host=aarch64-apple-darwin"
		    else
		        HOST="--host=arm-apple-darwin"
		    fi
		fi

		XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
		CC="xcrun -sdk $XCRUN_SDK clang -Wno-error=unused-command-line-argument-hard-error-in-future -arch $ARCH"
		CFLAGS="-arch $ARCH $SIMULATOR"
		CXXFLAGS="$CFLAGS"
		LDFLAGS="$CFLAGS"

		CC=$CC $CWD/$SOURCE/configure 
		    $CONFIGURE_FLAGS 
		    $HOST 
		    $CPU 
		    --extra-cflags="$CFLAGS" 
		    --extra-ldflags="$LDFLAGS" 
		    --prefix="$THIN/$ARCH"

		mkdir extras
		ln -s $GAS_PREPROCESSOR extras

		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

To build everything:
./build-x264.sh

To build for arm64:
./build-x264.sh arm64

To build fat library for armv7 and x86_64 (64-bit simulator):
./build-x264.sh armv7 x86_64

To build fat library from separately built thin libraries:
./build-x264.sh lipo

源址 https://github.com/kewlbear/x264-ios

原创文章,转载请注明: 转载自贝壳博客

本文链接地址: 转一段 Xcode6 下编译x264的脚本

3 评论

  1. 奇怪了,为什么在我的mac os x 10.10.5 , xcode 7.1.1
    编译的时候生成的libx264.a没有导出函数呢。
    当我只编译arm64版本的时候生成的libx264.a是有导出符号的呢?

    1. 脚本默认是编译多个架构到一个 .a 里
      你可以通过 lipo -info libx264.a 可以看到它包含了arm64 armv7s x86_64 i386 armv7 这几个架构

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据