forked from kolyvan/kxmovie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
302 lines (248 loc) · 9.05 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
require "pathname"
require "fileutils"
def system_or_exit(cmd, stdout = nil)
puts "Executing #{cmd}"
cmd += " >#{stdout}" if stdout
system(cmd) or raise "******** Build failed ********"
end
## build ffmpeg
SDK_VERSION='7.1'
XCODE_PATH='/Applications/Xcode.app/Contents/Developer/Platforms'
GCC_PATH='/Applications/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang'
LIB_PATH='/usr/lib/system'
GASPREP_DEST_PATH='/usr/local/bin'
PLATOFRM_PATH_SIM ='/iPhoneSimulator.platform'
PLATOFRM_PATH_IOS ='/iPhoneOS.platform'
SDK_PATH_SIM="/Developer/SDKs/iPhoneSimulator#{SDK_VERSION}.sdk"
SDK_PATH_IOS="/Developer/SDKs/iPhoneOS#{SDK_VERSION}.sdk"
FFMPEG_BUILD_ARGS_SIM = [
'--assert-level=2',
'--disable-mmx',
'--arch=i386',
'--cpu=i386',
"--extra-ldflags='-arch i386 -miphoneos-version-min=6.0'",
"--extra-cflags='-arch i386 -miphoneos-version-min=6.0'",
'--disable-asm',
]
FFMPEG_BUILD_ARGS_ARMV7 = [
'--arch=arm',
'--cpu=cortex-a8',
'--enable-pic',
"--extra-cflags='-arch armv7 -miphoneos-version-min=6.0'",
"--extra-ldflags='-arch armv7 -miphoneos-version-min=6.0'",
"--extra-cflags='-mfpu=neon -mfloat-abi=softfp'",
'--enable-neon',
# '--disable-neon',
'--enable-optimizations',
'--disable-debug',
'--disable-armv5te',
'--disable-armv6',
'--disable-armv6t2',
'--enable-small',
]
FFMPEG_BUILD_ARGS_ARMV7S = [
'--arch=arm',
'--cpu=cortex-a9',
'--enable-pic',
"--extra-cflags='-arch armv7s -miphoneos-version-min=6.0'",
"--extra-ldflags='-arch armv7s -miphoneos-version-min=6.0'",
"--extra-cflags='-mfpu=neon -mfloat-abi=softfp'",
'--enable-neon',
# '--disable-neon',
'--enable-optimizations',
'--disable-debug',
'--disable-armv5te',
'--disable-armv6',
'--disable-armv6t2',
'--enable-small',
]
FFMPEG_BUILD_ARGS_ARM64 = [
'--arch=arm64',
# '--cpu=cortex-a9',
'--enable-pic',
"--extra-cflags='-arch arm64 -miphoneos-version-min=6.0'",
"--extra-ldflags='-arch arm64 -miphoneos-version-min=6.0'",
"--extra-cflags='-mfpu=neon -mfloat-abi=softfp'",
'--enable-neon',
# '--disable-neon',
'--enable-optimizations',
'--disable-debug',
'--disable-armv5te',
'--disable-armv6',
'--disable-armv6t2',
'--enable-small',
]
FFMPEG_BUILD_ARGS = [
'--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',
'libavformat',
'libavutil',
'libswscale',
'libswresample',
]
def mkArgs(platformPath, sdkPath, platformArgs)
cc = '--cc=' + GCC_PATH
as = ""
sysroot = '--sysroot=' + XCODE_PATH + platformPath + sdkPath
# extra = '--extra-ldflags=-L' + XCODE_PATH + platformPath + sdkPath + LIB_PATH
extra = ""
args = FFMPEG_BUILD_ARGS + platformArgs
args << cc
args << as
args << sysroot
args << extra
args.join(' ')
end
def moveLibs(dest)
FFMPEG_LIBS.each do |x|
FileUtils.move Pathname.new("FFmpeg/#{x}/#{x}.a"), dest
end
end
def ensureDir(path)
dest = Pathname.new path
if dest.exist?
FileUtils.rm Dir.glob("#{path}/*.a")
else
dest.mkpath
end
dest
end
def buildArch(arch)
case arch
when '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)
when 'arm64'
args = mkArgs(PLATOFRM_PATH_IOS, SDK_PATH_IOS, FFMPEG_BUILD_ARGS_ARM64)
else
raise "Build failed: unknown arch: #{arch}"
end
dest = ensureDir('FFmpeg/' + arch)
system_or_exit "cd FFmpeg; ./configure #{args}"
system_or_exit "cd FFmpeg; make"
moveLibs(dest)
system_or_exit "cd FFmpeg; [ -f -.d ] && rm -- -.d; make clean"
end
def mkLipoArgs(lib)
"-create -arch armv7 armv7/#{lib}.a -arch armv7 armv7s/#{lib}.a -arch arm64 arm64/#{lib}.a -arch i386 i386/#{lib}.a -output universal/#{lib}.a"
end
desc "check gas-preprocessor.pl"
task :check_gas_preprocessor do
found = false
ENV['PATH'].split(':').each do |x|
p = Pathname.new(x) + 'gas-preprocessor.pl'
if p.exist? && p.writable?
found = true
break;
end
end
unless found
# See http://stackoverflow.com/questions/5056600/how-to-install-gas-preprocessor for more info.
puts "Installing the gas-preprocessor to #{GASPREP_DEST_PATH}"
FileUtils.move Pathname.new("gas-preprocessor/gas-preprocessor.pl"), Pathname.new(GASPREP_DEST_PATH)
system_or_exit "chmod +x #{GASPREP_DEST_PATH}/gas-preprocessor.pl"
# raise "Build failed: first install gas-preprocessor.pl.\nSee http://stackoverflow.com/questions/5056600/how-to-install-gas-preprocessor for more info."
end
end
desc "Clean ffmpeg"
task :clean_ffmpeg do
system_or_exit "cd FFmpeg; [ -f -.d ] && rm -- -.d; make clean"
end
desc "Build ffmpeg i386 libs"
task :build_ffmpeg_i386 do
buildArch('i386')
end
desc "Build ffmpeg armv7 libs"
task :build_ffmpeg_armv7 do
buildArch('armv7')
end
desc "Build ffmpeg armv7s libs"
task :build_ffmpeg_armv7s do
buildArch('armv7s')
end
desc "Build ffmpeg arm64 libs"
task :build_ffmpeg_arm64 do
buildArch('arm64')
end
desc "Build ffmpeg universal libs"
task :build_ffmpeg_universal do
ensureDir('FFmpeg/universal')
FFMPEG_LIBS.each do |x|
args = mkLipoArgs(x)
system_or_exit "cd FFmpeg; xcrun -sdk iphoneos lipo #{args}"
end
dest = ensureDir('libs/FFmpeg/')
FFMPEG_LIBS.each do |x|
FileUtils.move Pathname.new("FFmpeg/universal/#{x}.a"), dest
end
end
## build libkxmovie
def cleanMovieLib(config)
buildDir = Pathname.new 'tmp/build'
system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration #{config} -sdk iphoneos#{SDK_VERSION} clean SYMROOT=#{buildDir}"
system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration #{config} -sdk iphonesimulator#{SDK_VERSION} clean SYMROOT=#{buildDir}"
end
desc "Clean libkxmovie-debug"
task :clean_movie_debug do
cleanMovieLib 'Debug'
end
desc "Clean libkxmovie-release"
task :clean_movie_release do
cleanMovieLib 'Release'
end
desc "Build libkxmovie-debug"
task :build_movie_debug do
buildDir = Pathname.new 'tmp/build'
system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphoneos#{SDK_VERSION} 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 iphoneos#{SDK_VERSION} build SYMROOT=#{buildDir} -arch armv7"
system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphonesimulator#{SDK_VERSION} 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"
end
desc "Build libkxmovie-release"
task :build_movie_release do
buildDir = Pathname.new 'tmp/build'
system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Release -sdk iphoneos#{SDK_VERSION} 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 iphoneos#{SDK_VERSION} build SYMROOT=#{buildDir} -arch armv7"
system_or_exit "xcodebuild -project kxmovie.xcodeproj -target kxmovie -configuration Debug -sdk iphonesimulator#{SDK_VERSION} 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'), buildDir
end
desc "Copy to output folder"
task :copy_movie do
dest = ensureDir 'output'
FileUtils.move Pathname.new('tmp/build/libkxmovie.a'), dest
FileUtils.copy Pathname.new('libs/FFmpeg/libavcodec.a'), dest
FileUtils.copy Pathname.new('libs/FFmpeg/libavformat.a'), dest
FileUtils.copy Pathname.new('libs/FFmpeg/libavutil.a'), dest
FileUtils.copy Pathname.new('libs/FFmpeg/libswscale.a'), dest
FileUtils.copy Pathname.new('libs/FFmpeg/libswresample.a'), dest
FileUtils.copy Pathname.new('kxmovie/KxMovieViewController.h'), dest
FileUtils.copy Pathname.new('kxmovie/KxAudioManager.h'), dest
FileUtils.copy Pathname.new('kxmovie/KxMovieDecoder.h'), dest
FileUtils.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_armv7, :build_ffmpeg_armv7s, :build_ffmpeg_arm64, :build_ffmpeg_i386, :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]
task :default => [:build_ffmpeg]