require "pathname"require "fileutils"def system_or_exit(cmd, stdout = nil)puts "Executing #{cmd}"cmd += " >#{stdout}" if stdoutsystem(cmd) or raise "******** Build failed ********"end## build ffmpegXCODE_PATH='/Applications/Xcode.app/Contents/Developer/Platforms'GCC_PATH='/Developer/usr/bin/gcc'LIB_PATH='/usr/lib/system'PLATOFRM_PATH_SIM ='/iPhoneSimulator.platform'PLATOFRM_PATH_IOS ='/iPhoneOS.platform'#SDK_PATH_SIM ='/Developer/SDKs/iPhoneSimulator5.1.sdk'SDK_PATH_SIM ='/Developer/SDKs/iPhoneSimulator6.0.sdk'SDK_PATH_IOS='/Developer/SDKs/iPhoneOS6.0.sdk'FFMPEG_BUILD_ARGS_SIM = ['--assert-level=2','--disable-mmx','--arch=i386','--cpu=i386',"--extra-ldflags='-arch i386'","--extra-cflags='-arch i386'",]FFMPEG_BUILD_ARGS_ARMV7 = ['--arch=arm','--cpu=cortex-a8','--enable-pic',"--extra-cflags='-arch armv7'","--extra-ldflags='-arch armv7'","--extra-cflags='-mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad'",'--enable-neon','--disable-debug','--enable-optimizations','--disable-armv5te','--disable-armv6','--disable-armv6t2','--disable-armvfp',]FFMPEG_BUILD_ARGS_ARMV7S = ['--arch=arm','--cpu=cortex-a8','--enable-pic',"--extra-cflags='-arch armv7s'","--extra-ldflags='-arch armv7s'","--extra-cflags='-mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad'",'--enable-neon','--disable-debug','--enable-optimizations','--disable-armv5te','--disable-armv6','--disable-armv6t2','--disable-armvfp',]FFMPEG_BUILD_ARGS = [#'--disable-asm','--disable-ffmpeg','--disable-ffplay','--disable-ffserver','--disable-ffprobe','--disable-doc','--disable-bzlib','--target-os=darwin','--enable-cross-compile',#'--enable-nonfree','--enable-gpl','--enable-version3',]FFMPEG_LIBS = ['libavcodec',#'libavdevice','libavformat','libavutil','libswscale','libswresample',]def mkArgs(platformPath, sdkPath, platformArgs)cc = '--cc=' + XCODE_PATH + platformPath + GCC_PATHas = "--as='" + 'gas-preprocessor.pl ' + XCODE_PATH + platformPath + GCC_PATH + "'"sysroot = '--sysroot=' + XCODE_PATH + platformPath + sdkPathextra = '--extra-ldflags=-L' + XCODE_PATH + platformPath + sdkPath + LIB_PATHargs = FFMPEG_BUILD_ARGS + platformArgsargs << ccargs << asargs << sysrootargs << extraargs.join(' ')enddef moveLibs(dest)FFMPEG_LIBS.each do |x|FileUtils.move Pathname.new("ffmpeg/#{x}/#{x}.a"), destendenddef ensureDir(path)dest = Pathname.new pathif dest.exist?FileUtils.rm Dir.glob("#{path}/*.a")elsedest.mkdirenddestenddef buildArch(arch)case archwhen 'i386'args = mkArgs(PLATOFRM_PATH_SIM, SDK_PATH_SIM, FFMPEG_BUILD_ARGS_SIM)when 'armv7'args = mkArgs(PLATOFRM_PATH_IOS, SDK_PATH_IOS, FFMPEG_BUILD_ARGS_ARMV7)when 'armv7s'args = mkArgs(PLATOFRM_PATH_IOS, SDK_PATH_IOS, FFMPEG_BUILD_ARGS_ARMV7S)elseraise "Build failed: unknown arch: #{arch}"enddest = ensureDir('ffmpeg/' + arch)system_or_exit "cd ffmpeg; ./configure #{args}"system_or_exit "cd ffmpeg; make"moveLibs(dest)system_or_exit "cd ffmpeg; make clean"enddef mkLipoArgs(lib)"-create -arch armv7 armv7/#{lib}.a -arch armv7 armv7s/#{lib}.a -arch i386 i386/#{lib}.a -output universal/#{lib}.a"enddesc "check gas-preprocessor.pl"task :check_gas_preprocessor dofound = falseENV['PATH'].split(':').each do |x|p = Pathname.new(x) + 'gas-preprocessor.pl'if p.exist? && p.writable?found = truebreak;endendunless foundraise "Build failed: first install gas-preprocessor.pl.\nSee http://stackoverflow.com/questions/5056600/how-to-install-gas-preprocessor for more info."endenddesc "Clean ffmpeg"task :clean_ffmpeg dosystem_or_exit "cd ffmpeg; make clean"enddesc "Build ffmpeg i386 libs"task :build_ffmpeg_i386 dobuildArch('i386')enddesc "Build ffmpeg armv7 libs"task :build_ffmpeg_armv7 dobuildArch('armv7')enddesc "Build ffmpeg armv7s libs"task :build_ffmpeg_armv7s dobuildArch('armv7s')enddesc "Build ffmpeg universal libs"task :build_ffmpeg_universal doensureDir('ffmpeg/universal')FFMPEG_LIBS.each do |x|args = mkLipoArgs(x)system_or_exit "cd ffmpeg; lipo #{args}"enddest = ensureDir('libs')FFMPEG_LIBS.each do |x|FileUtils.move Pathname.new("ffmpeg/universal/#{x}.a"), destendend## build libkxmoviedef cleanMovieLib(config)buildDir = Pathname.new 'tmp/build'system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration #{config} -sdk iphoneos6.0 clean SYMROOT=#{buildDir}"system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration #{config} -sdk iphonesimulator6.0 clean SYMROOT=#{buildDir}"enddesc "Clean libkxmovie-debug"task :clean_movie_debug docleanMovieLib 'Debug'enddesc "Clean libkxmovie-release"task :clean_movie_release docleanMovieLib 'Release'enddesc "Build libkxmovie-debug"task :build_movie_debug dobuildDir = Pathname.new 'tmp/build'system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphoneos6.0 build SYMROOT=#{buildDir} -arch armv7s"FileUtils.move Pathname.new('tmp/build/Debug-iphoneos/libkxmovie.a'), Pathname.new('tmp/build/Debug-iphoneos/libkxmovie_armv7s.a')system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphoneos6.0 build SYMROOT=#{buildDir} -arch armv7"system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphonesimulator6.0 build SYMROOT=#{buildDir}"system_or_exit "lipo -create -arch armv7 tmp/build/Debug-iphoneos/libkxmovie.a -arch armv7 tmp/build/Debug-iphoneos/libkxmovie_armv7s.a -arch i386 tmp/build/Debug-iphonesimulator/libkxmovie.a -output tmp/build/libkxmovie.a"enddesc "Build libkxmovie-release"task :build_movie_release dobuildDir = Pathname.new 'tmp/build'system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Release -sdk iphoneos6.0 build SYMROOT=#{buildDir} -arch armv7s"FileUtils.move Pathname.new('tmp/build/Release-iphoneos/libkxmovie.a'), Pathname.new('tmp/build/Release-iphoneos/libkxmovie_armv7s.a')system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Release -sdk iphoneos6.0 build SYMROOT=#{buildDir} -arch armv7"system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphonesimulator6.0 build SYMROOT=#{buildDir}"system_or_exit "lipo -create -arch armv7 tmp/build/Release-iphoneos/libkxmovie.a -arch armv7 tmp/build/Release-iphoneos/libkxmovie_armv7s.a -arch i386 tmp/build/Debug-iphonesimulator/libkxmovie.a -output tmp/build/libkxmovie.a"#FileUtils.copy Pathname.new('tmp/build/Release-iphoneos/libkxmovie.a'), buildDirenddesc "Copy to output folder"task :copy_movie dodest = ensureDir 'output'FileUtils.move Pathname.new('tmp/build/libkxmovie.a'), destFileUtils.copy Pathname.new('libs/libavcodec.a'), destFileUtils.copy Pathname.new('libs/libavformat.a'), destFileUtils.copy Pathname.new('libs/libavutil.a'), destFileUtils.copy Pathname.new('libs/libswscale.a'), destFileUtils.copy Pathname.new('libs/libswresample.a'), destFileUtils.copy Pathname.new('kxmovie/KxMovieViewController.h'), destFileUtils.copy Pathname.new('kxmovie/KxAudioManager.h'), destFileUtils.copy Pathname.new('kxmovie/KxMovieDecoder.h'), destFileUtils.copy_entry Pathname.new('kxmovie/kxmovie.bundle'), dest + 'kxmovie.bundle'end##task :clean => [:clean_movie_debug, :clean_movie_release, :clean_ffmpeg]task :build_ffmpeg => [:check_gas_preprocessor, :build_ffmpeg_i386, :build_ffmpeg_armv7, :build_ffmpeg_armv7s, :build_ffmpeg_universal]#task :build_movie => [:build_movie_debug, :copy_movie]task :build_movie => [:build_movie_release, :copy_movie]task :build_all => [:build_ffmpeg, :build_movie]task :default => [:build_all]
2013年2月27日星期三
rake示例
订阅:
博文 (Atom)