forked from kolyvan/kxsmb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
350 lines (276 loc) · 9.47 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
#
# Rakefile
# kxsmb project
# https://github.com/kolyvan/kxsmb/
#
# Created by Kolyvan on 29.03.13.
#
#
# Copyright (c) 2013 Konstantin Bukreev All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
require "pathname"
require "fileutils"
# utils
def system_or_exit(cmd, stdout = nil)
puts "Executing #{cmd}"
cmd += " >#{stdout}" if stdout
system(cmd) or raise "******** Build failed ********"
end
def copyIfNotExists(file, from, to)
dest = Pathname.new(to)
dest.mkdir unless dest.exist?
unless (dest + file).exist?
source = Pathname.new(from) + file
FileUtils.copy source, dest
p "copy #{source} -> #{dest}"
end
end
def cleanOrMkDir(path)
dest = Pathname.new path
if dest.exist?
FileUtils.rm Dir.glob("#{path}/*.a")
else
dest.mkdir
end
end
def cleanDir(path)
dest = Pathname.new path
if dest.exist?
FileUtils.rm Dir.glob("#{path}/*.a")
end
end
# versions
IOS_MIN_VERSION='8.0'
SAMBA_VERSION='4.0.26'
# samba source
SAMBA_BASE_URL="http://ftp.samba.org/pub/samba/stable/"
#pathes
XCODE_PATH=%x{ /usr/bin/xcode-select --print-path }.delete("\n")
SIM_SDK_PATH=XCODE_PATH + "/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
IOS_SDK_PATH=XCODE_PATH + "/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
#SAMBA_PATH="samba-#{SAMBA_VERSION}/source3"
SAMBA_FOLDER="samba"
SAMBA_SOURCE_PATH="#{SAMBA_FOLDER}/source3"
EXT_INCLUDE_PATH='tmp/include'
# configure arguments
CF_FLAGS='-pipe -Wno-trigraphs -fpascal-strings -Os -fembed-bitcode -g'
IOS_CF_FLAGS='-ftree-vectorize'
IOS_LD_FLAGS=''
ARM7_CF_FLAGS="-arch armv7 -mcpu=cortex-a8 -mfpu=neon #{IOS_CF_FLAGS} #{CF_FLAGS}"
ARM7_LD_FLAGS="-arch armv7 #{IOS_LD_FLAGS}"
ARM7s_CF_FLAGS="-arch armv7s -mcpu=cortex-a8 -mfpu=neon #{IOS_CF_FLAGS} #{CF_FLAGS}"
ARM7s_LD_FLAGS="-arch armv7s #{IOS_LD_FLAGS}"
ARM64_CF_FLAGS="-arch arm64 -Wno-error=implicit-function-declaration #{IOS_CF_FLAGS} #{CF_FLAGS}"
ARM64_LD_FLAGS="-arch arm64 #{IOS_LD_FLAGS}"
I386_CF_FLAGS="-arch i386 #{CF_FLAGS}"
I386_LD_FLAGS='-arch i386'
X86_64_CF_FLAGS="-arch x86_64 -Wno-error=implicit-function-declaration #{CF_FLAGS}"
X86_64_LD_FLAGS='-arch x86_64'
SMB_ARGS = [
'--prefix=/private',
'--disable-shared',
'--enable-static',
'--without-readline',
'--with-libsmbclient',
'--without-libnetapi',
'--without-libsmbsharemodes',
'--without-cluster-support',
'--without-ldap',
'--disable-swat',
'--disable-cups',
'--disable-iprint',
'libreplace_cv_HAVE_C99_VSNPRINTF=yes',
'samba_cv_CC_NEGATIVE_ENUM_VALUES=yes',
]
SIM_SMB_ARGS = [
'--enable-debug',
'samba_cv_HAVE_FCNTL_LOCK=yes'
]
IOS_SMB_ARGS = [
'ac_cv_header_libunwind_h=no',
'ac_cv_header_execinfo_h=no',
'ac_cv_header_rpcsvc_ypclnt_h=no',
'ac_cv_file__proc_sys_kernel_core_pattern=no',
'ac_cv_func_fdatasync=no',
'libreplace_cv_HAVE_GETADDRINFO=no',
'samba_cv_SYSCONF_SC_NPROCESSORS_ONLN=no',
'samba_cv_big_endian=no',
'samba_cv_little_endian=yes',
]
ARM7_SMB_ARGS = [
'--host=arm-apple-darwin',
]
ARM7s_SMB_ARGS = [
'--host=arm-apple-darwin',
]
ARM64_SMB_ARGS = [
'--host=arm-apple-darwin',
]
I386_SMB_ARGS = [
'--host=i686-apple-darwin',
]
X86_64_SMB_ARGS = [
'--host=x86_64-apple-darwin',
]
# libs
SMB_LIBS = [
'libsmbclient',
'libtalloc',
'libtevent',
'libtdb',
'libwbclient',
]
# functions
def mkArgs(sdkPath, platformArgs, procArgs, cfFlags, ldFlags)
extInclude = Pathname.new(EXT_INCLUDE_PATH).realpath
args = SMB_ARGS + platformArgs + procArgs
ENV['AR']="xcrun ar"
ENV['CC']="xcrun clang"
ENV['CPP']="xcrun clang -E"
ENV['LD']="xcrun ld"
ENV['CFLAGS']="-std=gnu99 -no-cpp-precomp -miphoneos-version-min=#{IOS_MIN_VERSION} -isysroot #{sdkPath} -I#{sdkPath}/usr/include #{cfFlags}"
ENV['CPPFLAGS']="-std=gnu99 -no-cpp-precomp -miphoneos-version-min=#{IOS_MIN_VERSION} -isysroot #{sdkPath} -I#{sdkPath}/usr/include #{cfFlags} -I#{extInclude}"
ENV['LDFLAGS']="-miphoneos-version-min=#{IOS_MIN_VERSION} -isysroot #{sdkPath} -L#{sdkPath}/usr/lib #{ldFlags}"
args.join(' ')
end
def buildArch(arch)
case arch
when 'i386'
args = mkArgs(SIM_SDK_PATH, SIM_SMB_ARGS, I386_SMB_ARGS, I386_CF_FLAGS, I386_LD_FLAGS)
when 'armv7'
args = mkArgs(IOS_SDK_PATH, IOS_SMB_ARGS, ARM7_SMB_ARGS, ARM7_CF_FLAGS, ARM7_LD_FLAGS)
when 'armv7s'
args = mkArgs(IOS_SDK_PATH, IOS_SMB_ARGS, ARM7s_SMB_ARGS, ARM7s_CF_FLAGS, ARM7s_LD_FLAGS)
when 'arm64'
args = mkArgs(IOS_SDK_PATH, IOS_SMB_ARGS, ARM64_SMB_ARGS, ARM64_CF_FLAGS, ARM64_LD_FLAGS)
when 'x86_64'
args = mkArgs(SIM_SDK_PATH, SIM_SMB_ARGS, X86_64_SMB_ARGS, X86_64_CF_FLAGS, X86_64_LD_FLAGS)
else
raise "Build failed: unknown arch: #{arch}"
end
p args
system_or_exit "cd #{SAMBA_SOURCE_PATH}; ./autogen.sh"
system_or_exit "cd #{SAMBA_SOURCE_PATH}; ./configure #{args}"
SMB_LIBS.each do |x|
system_or_exit "cd #{SAMBA_SOURCE_PATH}; make #{x}"
end
dest = Pathname.new("#{SAMBA_SOURCE_PATH}/bin/#{arch}")
cleanOrMkDir(dest)
SMB_LIBS.each do |x|
FileUtils.move Pathname.new("#{SAMBA_SOURCE_PATH}/bin/#{x}.a"), dest
end
system_or_exit "cd #{SAMBA_SOURCE_PATH}; make clean"
end
def checkExtInclude
extInclude = Pathname.new(EXT_INCLUDE_PATH)
extInclude.mkpath unless extInclude.exist?
copyIfNotExists('crt_externs.h', "#{SIM_SDK_PATH}/usr/include/", extInclude.realpath)
end
# tasks
desc "Build smb armv7 libs"
task :build_smb_armv7 do
checkExtInclude
buildArch('armv7')
end
desc "Build smb armv7s libs"
task :build_smb_armv7s do
checkExtInclude
buildArch('armv7s')
end
desc "Build smb arm64 libs"
task :build_smb_arm64 do
checkExtInclude
buildArch('arm64')
end
desc "Build smb i386 libs"
task :build_smb_i386 do
buildArch('i386')
end
desc "Build smb x86_64 libs"
task :build_smb_x86_64 do
buildArch('x86_64')
end
desc "Build smb universal libs (full)"
task :build_smb_universal_full do
dest = Pathname.new("#{SAMBA_SOURCE_PATH}/bin/universal")
dest.mkdir unless dest.exist?
SMB_LIBS.each do |x|
args = "-create -arch armv7 #{SAMBA_SOURCE_PATH}/bin/armv7/#{x}.a -arch armv7s #{SAMBA_SOURCE_PATH}/bin/armv7s/#{x}.a -arch arm64 #{SAMBA_SOURCE_PATH}/bin/arm64/#{x}.a -arch i386 #{SAMBA_SOURCE_PATH}/bin/i386/#{x}.a -arch x86_64 #{SAMBA_SOURCE_PATH}/bin/x86_64/#{x}.a -output #{dest}/#{x}.a"
system_or_exit "xcrun lipo #{args}"
end
end
desc "Build smb universal libs"
task :build_smb_universal do
dest = Pathname.new("#{SAMBA_SOURCE_PATH}/bin/universal")
dest.mkdir unless dest.exist?
SMB_LIBS.each do |x|
args = "-create -arch armv7 #{SAMBA_SOURCE_PATH}/bin/armv7/#{x}.a -arch arm64 #{SAMBA_SOURCE_PATH}/bin/arm64/#{x}.a -arch i386 #{SAMBA_SOURCE_PATH}/bin/i386/#{x}.a -arch x86_64 #{SAMBA_SOURCE_PATH}/bin/x86_64/#{x}.a -output #{dest}/#{x}.a"
system_or_exit "xcrun lipo #{args}"
end
end
desc "Copy smb headers"
task :copy_headers do
copyIfNotExists('libsmbclient.h', "#{SAMBA_SOURCE_PATH}/include/", 'libs')
copyIfNotExists('talloc.h', "#{SAMBA_FOLDER}/lib/talloc/", 'libs')
copyIfNotExists('talloc_stack.h', "#{SAMBA_FOLDER}/lib/util/", 'libs')
end
desc "Copy smb libs"
task :copy_libs do
dest = Pathname.new('libs')
dest.mkdir unless dest.exist?
from = Pathname.new("#{SAMBA_SOURCE_PATH}/bin/universal")
SMB_LIBS.each do |x|
source = from + "#{x}.a"
FileUtils.move source, dest
p "copy #{source} -> #{dest}"
end
end
desc "Clean"
task :clean do
cleanDir("#{SAMBA_SOURCE_PATH}/bin/armv7")
cleanDir("#{SAMBA_SOURCE_PATH}/bin/armv7s")
cleanDir("#{SAMBA_SOURCE_PATH}/bin/arm64")
cleanDir("#{SAMBA_SOURCE_PATH}/bin/i386")
cleanDir("#{SAMBA_SOURCE_PATH}/bin/x86_64")
cleanDir("#{SAMBA_SOURCE_PATH}/bin/universal")
system_or_exit "cd #{SAMBA_SOURCE_PATH}; make clean"
end
desc "Retrieve samble archive"
task :retrieve_samba do
p = Pathname.new "#{SAMBA_SOURCE_PATH}"
unless p.exist?
name = "samba-#{SAMBA_VERSION}"
file = "#{name}.tar.gz"
url = "#{SAMBA_BASE_URL}#{file}"
p "retrieving samba from #{url}"
system_or_exit "/usr/bin/curl -L --output #{file} #{url}"
p "extracting samba from archive"
system_or_exit "tar -zxf #{file}"
Pathname.new(file).delete
Pathname.new(name).rename SAMBA_FOLDER
end
end
task :build_full => [:retrieve_samba, :build_smb_armv7, :build_smb_armv7s, :build_smb_arm64, :build_smb_i386, :build_smb_x86_64, :build_smb_universal_full, :copy_libs, :copy_headers]
task :build_all => [:retrieve_samba, :build_smb_armv7, :build_smb_arm64, :build_smb_i386, :build_smb_x86_64, :build_smb_universal, :copy_libs, :copy_headers]
task :default => [:build_all]