forked from kolyvan/kxsmb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
237 lines (186 loc) · 6.25 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
#
# 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='11.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_VERSION}"
SAMBA_SOURCE_PATH="#{SAMBA_FOLDER}/source3"
EXT_INCLUDE_PATH='tmp/include'
# configure arguments
CF_FLAGS='-pipe -Wno-trigraphs -fpascal-strings -Os -g'
IOS_CF_FLAGS='-ftree-vectorize'
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}"
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',
]
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',
]
ARM64_SMB_ARGS = [
'--host=arm-apple-darwin',
]
# libs
SMB_LIBS = [
'libsmbclient',
'libtalloc',
'libtevent',
'libtdb',
'libwbclient',
'bin/smbclient',
]
# 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 'arm64'
args = mkArgs(IOS_SDK_PATH, IOS_SMB_ARGS, ARM64_SMB_ARGS, ARM64_CF_FLAGS, ARM64_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 arm64 libs"
task :build_smb_arm64 do
checkExtInclude
buildArch('arm64')
end
desc "clean"
task :clean do
cleanDir("#{SAMBA_SOURCE_PATH}/bin/arm64")
system_or_exit "cd #{SAMBA_SOURCE_PATH}; make clean"
end
desc "retrieve samba 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_all => [:retrieve_samba, :build_smb_arm64]
task :default => [:build_all]