-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
376 lines (309 loc) · 13.4 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
require 'zip'
require 'digest/md5'
GIT_ROOT = `git rev-parse --show-toplevel`.strip
VERSION = 'v1.2.2'
LIBWEBP = "libwebp"
desc "default"
task :default do
sh 'rake -T'
end
## ================================================================================
desc "prepare library_windows"
task :prepare_library_windows do
build_dir = 'build/windows'
FileUtils.mkdir_p(build_dir) unless File.directory?(build_dir)
Dir.chdir(build_dir) do
sh 'git clone https://github.com/webmproject/libwebp.git'
Dir.chdir('libwebp') do
sh "git checkout #{VERSION}"
end
end
end
desc "update library_windows_x64"
task :update_library_windows_x64 do
# Windows + R
# %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
build_dir = 'build/windows'
lib_dir = "#{GIT_ROOT}/lib/windows"
Dir.chdir(build_dir) do
Dir.chdir('libwebp') do
puts "============== x64"
sh "git clean -xdf"
arch_lib_dir = "#{lib_dir}/x64"
FileUtils.mkdir_p(arch_lib_dir) unless File.directory?(arch_lib_dir)
sh 'nmake /f Makefile.vc CFG=release-dynamic RTLIBCFG=dynamic OBJDIR=output ARCH=x64'
cp 'output/release-dynamic/x64/bin/libwebp.dll', arch_lib_dir
cp 'output/release-dynamic/x64/bin/libwebpdecoder.dll', arch_lib_dir
cp 'output/release-dynamic/x64/bin/libwebpdemux.dll', arch_lib_dir
end
end
end
desc "update library_windows_x86"
task :update_library_windows_x86 do
# Windows + R
# %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
build_dir = 'build/windows'
lib_dir = "#{GIT_ROOT}/lib/windows"
Dir.chdir(build_dir) do
Dir.chdir('libwebp') do
puts "============== x86"
sh "git clean -xdf"
arch_lib_dir = "#{lib_dir}/x86"
FileUtils.mkdir_p(arch_lib_dir) unless File.directory?(arch_lib_dir)
sh 'nmake /f Makefile.vc CFG=release-dynamic RTLIBCFG=dynamic OBJDIR=output ARCH=x86'
cp 'output/release-dynamic/x86/bin/libwebp.dll', arch_lib_dir
cp 'output/release-dynamic/x86/bin/libwebpdecoder.dll', arch_lib_dir
cp 'output/release-dynamic/x86/bin/libwebpdemux.dll', arch_lib_dir
end
end
end
desc "update library_windows_arm64"
task :update_library_windows_arm64 do
# Windows + R
# %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
build_dir = 'build/windows'
lib_dir = "#{GIT_ROOT}/lib/windows"
Dir.chdir(build_dir) do
Dir.chdir('libwebp') do
puts "============== ARM"
sh "git clean -xdf"
arch_lib_dir = "#{lib_dir}/ARM"
FileUtils.mkdir_p(arch_lib_dir) unless File.directory?(arch_lib_dir)
data = File.read("Makefile.vc")
filtered_data = data.gsub("OUT_LIBS = $(LIBWEBPDECODER) $(LIBWEBP)", "OUT_LIBS = $(LIBWEBPDECODER) $(LIBWEBP) $(LIBWEBPDEMUX)")
File.open("Makefile.vc", "w") do |f|
f.write(filtered_data)
end
sh 'nmake /f Makefile.vc CFG=release-dynamic RTLIBCFG=dynamic OBJDIR=output ARCH=ARM'
cp 'output/release-dynamic/ARM/bin/libwebp.dll', arch_lib_dir
cp 'output/release-dynamic/ARM/bin/libwebpdecoder.dll', arch_lib_dir
cp 'output/release-dynamic/ARM/bin/libwebpdemux.dll', arch_lib_dir
end
end
end
## ================================================================================
desc "update library_linux"
task :update_library_linux do
build_dir = 'build/linux'
lib_dir = "#{GIT_ROOT}/lib/linux_64"
FileUtils.mkdir_p(build_dir) unless File.directory?(build_dir)
FileUtils.mkdir_p(lib_dir) unless File.directory?(lib_dir)
Dir.chdir(build_dir) do
sh 'git clone https://github.com/webmproject/libwebp.git'
Dir.chdir('libwebp') do
sh "git checkout #{VERSION}"
sh './autogen.sh'
sh "./configure --prefix=`pwd`/.lib --enable-everything --disable-static"
sh 'make && make install'
cp_r '.lib/lib', lib_dir
end
end
end
desc "update library_android"
task :update_library_android do
# android-ndk: https://developer.android.com/ndk/downloads
ANDROID_MK = 'Android.mk'
build_dir = 'build/android'
lib_armeabi_v7a_dir = "#{GIT_ROOT}/lib/android/armeabi-v7a"
lib_x86_dir = "#{GIT_ROOT}/lib/android/x86"
lib_x86_64_dir = "#{GIT_ROOT}/lib/android/x86_64"
lib_arm64_v8a_dir = "#{GIT_ROOT}/lib/android/arm64-v8a"
FileUtils.mkdir_p(build_dir) unless File.directory?(build_dir)
FileUtils.mkdir_p(lib_x86_dir) unless File.directory?(lib_x86_dir)
FileUtils.mkdir_p(lib_armeabi_v7a_dir) unless File.directory?(lib_armeabi_v7a_dir)
FileUtils.mkdir_p(lib_arm64_v8a_dir) unless File.directory?(lib_arm64_v8a_dir)
FileUtils.mkdir_p(lib_x86_64_dir) unless File.directory?(lib_x86_64_dir)
Dir.chdir(build_dir) do
puts '==== Clone webp'
sh 'git clone https://github.com/webmproject/libwebp.git'
Dir.chdir('libwebp') do
puts '==== checkout'
sh "git checkout #{VERSION}"
# to enable build shared library
File.open(ANDROID_MK, "r") do |orig|
# File.unlink(ANDROID_MK)
o = orig.read()
File.open(ANDROID_MK, "w") do |new|
new.puts 'ENABLE_SHARED := 1'
new.write(o)
end
end
puts '==== NDK build'
# NDK_BUILD_FPATH = "#{Dir.home}/android-ndk-r20/ndk-build"
sh "ndk-build NDK_PROJECT_PATH=#{Dir.pwd} APP_BUILD_SCRIPT=#{Dir.pwd}/#{ANDROID_MK}"
['libwebp.so', 'libwebpdecoder.so', 'libwebpdemux.so', 'libwebpmux.so'].each do |so|
cp_r "libs/armeabi-v7a/#{so}", lib_armeabi_v7a_dir
cp_r "libs/arm64-v8a/#{so}", lib_arm64_v8a_dir
cp_r "libs/x86/#{so}", lib_x86_dir
cp_r "libs/x86_64/#{so}", lib_x86_64_dir
end
end
end
end
## ================================================================================
desc "update library_macos"
task :update_library_macos do
BUILD_DIR = "#{Dir.pwd}/build/macos"
LIB_DIR = "#{GIT_ROOT}/lib/macos_64"
FileUtils.mkdir_p(BUILD_DIR) unless File.directory?(BUILD_DIR)
FileUtils.mkdir_p(LIB_DIR) unless File.directory?(LIB_DIR)
DEVELOPER=`xcode-select -print-path`.strip
TOOLCHAIN_BIN="#{DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin"
ENV["CC"] ="#{TOOLCHAIN_BIN}/clang"
ENV["AR"] ="#{TOOLCHAIN_BIN}/ar"
ENV["RANLIB"] ="#{TOOLCHAIN_BIN}/ranlib"
ENV["STRIP"] ="#{TOOLCHAIN_BIN}/strip"
ENV["LIBTOOL"] ="#{TOOLCHAIN_BIN}/libtool"
ENV["NM"] ="#{TOOLCHAIN_BIN}/nm"
ENV["LD"] ="#{TOOLCHAIN_BIN}/ld"
OUT_LIB_PATHS_webp = ''
OUT_LIB_PATHS_webpdecoder = ''
OUT_LIB_PATHS_webpdemux = ''
OUT_LIB_PATHS_webpmux = ''
HOST="aarch64-apple-darwin"
ISYSROOT=`xcrun --sdk macosx --show-sdk-path`
Dir.chdir(BUILD_DIR) do
sh 'git clone https://github.com/webmproject/libwebp.git'
Dir.chdir('libwebp') do
sh "git checkout #{VERSION}"
for ARCH in ['x86_64', 'arm64']
BUILD_ARCH_DIR="#{BUILD_DIR}/#{ARCH}"
LIB_ARCH_DIR="#{LIB_DIR}/#{ARCH}"
sh "mkdir -p #{BUILD_ARCH_DIR}"
sh "mkdir -p #{LIB_ARCH_DIR}"
TARGET="#{ARCH}-apple-macos"
CFLAGS = ""\
" -arch #{ARCH}" \
" -target #{TARGET}" \
" -isysroot #{ISYSROOT}" \
" -mmacos-version-min=13.0" \
" -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" \
" -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
sh './autogen.sh'
sh "./configure --prefix=#{BUILD_ARCH_DIR} --enable-everything --disable-static --host=#{HOST} CFLAGS='#{CFLAGS}'"
sh 'make && make install'
path_libwebp = `realpath #{BUILD_ARCH_DIR}/lib/libwebp.dylib`.strip
path_libwebpdecoder = `realpath #{BUILD_ARCH_DIR}/lib/libwebpdecoder.dylib`.strip
path_libwebpdemux = `realpath #{BUILD_ARCH_DIR}/lib/libwebpdemux.dylib`.strip
path_libwebpmux = `realpath #{BUILD_ARCH_DIR}/lib/libwebpmux.dylib`.strip
sh "cp -r #{path_libwebp} #{BUILD_ARCH_DIR}/webp.bundle"
sh "cp -r #{path_libwebpdecoder} #{BUILD_ARCH_DIR}/webpdecoder.bundle"
sh "cp -r #{path_libwebpdemux} #{BUILD_ARCH_DIR}/webpdemux.bundle"
sh "cp -r #{path_libwebpmux} #{BUILD_ARCH_DIR}/webpmux.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webp.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webpdecoder.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webpdemux.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webpmux.bundle"
sh "install_name_tool -id @loader_path/webp.bundle #{BUILD_ARCH_DIR}/webp.bundle"
sh "install_name_tool -id @loader_path/wewebpdecoderbp.bundle #{BUILD_ARCH_DIR}/webpdecoder.bundle"
sh "install_name_tool -id @loader_path/webpdemux.bundle #{BUILD_ARCH_DIR}/webpdemux.bundle"
sh "install_name_tool -id @loader_path/webpmux.bundle #{BUILD_ARCH_DIR}/webpmux.bundle"
sh "install_name_tool -change #{path_libwebp} @loader_path/webp.bundle #{BUILD_ARCH_DIR}/webpdemux.bundle"
sh "install_name_tool -change #{path_libwebp} @loader_path/webp.bundle #{BUILD_ARCH_DIR}/webpmux.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webp.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webpdecoder.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webpdemux.bundle"
sh "otool -L #{BUILD_ARCH_DIR}/webpmux.bundle"
OUT_LIB_PATHS_webp += " #{BUILD_ARCH_DIR}/webp.bundle"
OUT_LIB_PATHS_webpdecoder += " #{BUILD_ARCH_DIR}/webpdecoder.bundle"
OUT_LIB_PATHS_webpdemux += " #{BUILD_ARCH_DIR}/webpdemux.bundle"
OUT_LIB_PATHS_webpmux += " #{BUILD_ARCH_DIR}/webpmux.bundle"
sh 'make clean'
end
end
end
sh "lipo -create #{OUT_LIB_PATHS_webp} -output #{LIB_DIR}/webp.bundle"
sh "lipo -create #{OUT_LIB_PATHS_webpdecoder} -output #{LIB_DIR}/webpdecoder.bundle"
sh "lipo -create #{OUT_LIB_PATHS_webpdemux} -output #{LIB_DIR}/webpdemux.bundle"
sh "lipo -create #{OUT_LIB_PATHS_webpmux} -output #{LIB_DIR}/webpmux.bundle"
sh "lipo -info #{LIB_DIR}/webp.bundle"
sh "lipo -info #{LIB_DIR}/webpdecoder.bundle"
sh "lipo -info #{LIB_DIR}/webpdemux.bundle"
sh "lipo -info #{LIB_DIR}/webpmux.bundle"
end
desc "update library_ios"
task :update_library_ios do
build_dir = 'build/ios'
lib_dir = "#{GIT_ROOT}/lib/ios"
lib_simulator_dir = "#{GIT_ROOT}/lib/ios-simulator"
sdk_version = `xcodebuild -showsdks | grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'`.strip # same as 'iosbuild.sh'
FileUtils.mkdir_p(build_dir) unless File.directory?(build_dir)
FileUtils.mkdir_p(lib_dir) unless File.directory?(lib_dir)
FileUtils.mkdir_p(lib_simulator_dir) unless File.directory?(lib_simulator_dir)
Dir.chdir(build_dir) do
sh 'git clone https://github.com/webmproject/libwebp.git'
Dir.chdir('libwebp') do
sh "git checkout #{VERSION}"
sh "./iosbuild.sh"
# universal static library
# ['libwebp.a', 'libwebpdecoder.a', 'libwebpdemux.a'].each do |a|
# sh "lipo -create -output #{a} iosbuild/iPhoneOS-#{sdk_version}-aarch64/lib/#{a} iosbuild/iPhoneOS-#{sdk_version}-armv7/lib/#{a}"
# cp_r a, lib_dir
# end
# x64 only
['libwebp.a', 'libwebpdecoder.a', 'libwebpdemux.a'].each do |a|
cp_r "iosbuild/iPhoneOS-#{sdk_version}-aarch64/lib/#{a}", lib_dir
end
# simulator static library
['libwebp.a', 'libwebpdecoder.a', 'libwebpdemux.a'].each do |a|
# sh "lipo -create -output #{a} iosbuild/iPhoneSimulator-#{sdk_version}-x86_64/lib/#{a} iosbuild/iPhoneSimulator-#{sdk_version}-i386/lib/#{a}"
cp_r "iosbuild/iPhoneSimulator-#{sdk_version}-x86_64/lib/#{a}", lib_simulator_dir
end
end
end
end
## ================================================================================
desc "print lib md5"
task :print_lib_md5 do
Dir.glob("lib/**/*").each do |path|
next if File.directory?(path)
md5 = Digest::MD5.hexdigest(IO.read(path))
puts "#{md5} : #{path}"
end
end
## ================================================================================
class ZipFileGenerator
# Usage:
# directory_to_zip = "/tmp/input"
# output_file = "/tmp/out.zip"
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
# zf.write()
# Initialize with the directory to zip and the location of the output archive.
def initialize(input_dir, output_file)
@input_dir = input_dir
@output_file = output_file
end
# Zip the input directory.
def write
entries = Dir.entries(@input_dir) - %w[. ..]
::Zip::File.open(@output_file, create: true) do |zipfile|
write_entries entries, '', zipfile
end
end
private
# A helper method to make the recursion work.
def write_entries(entries, path, zipfile)
entries.each do |e|
zipfile_path = path == '' ? e : File.join(path, e)
disk_file_path = File.join(@input_dir, zipfile_path)
if File.directory? disk_file_path
recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
else
put_into_archive(disk_file_path, zipfile, zipfile_path)
end
end
end
def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
zipfile.mkdir zipfile_path
subdir = Dir.entries(disk_file_path) - %w[. ..]
write_entries subdir, zipfile_path, zipfile
end
def put_into_archive(disk_file_path, zipfile, zipfile_path)
zipfile.add(zipfile_path, disk_file_path)
end
end
desc "zip library"
task :zip_library do
zf = ZipFileGenerator.new('lib', 'lib.zip')
zf.write()
end