9 import sys
, os
, tempfile
10 sys
.path
.insert(0, srcdir
+"/buildtools/wafsamba")
11 import wafsamba
, Options
, samba_dist
, samba_git
, Scripting
, Utils
, samba_version
12 import Logs
, samba_utils
15 samba_dist
.DIST_DIRS('.')
16 samba_dist
.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
18 # install in /usr/local/samba by default
19 default_prefix
= Options
.default_prefix
= '/usr/local/samba'
21 # This callback optionally takes a list of paths as arguments:
22 # --with-system_mitkrb5 /path/to/krb5 /another/path
23 def system_mitkrb5_callback(option
, opt
, value
, parser
):
24 setattr(parser
.values
, option
.dest
, True)
26 for arg
in parser
.rargs
:
27 # stop on --foo like options
28 if arg
[:2] == "--" and len(arg
) > 2:
32 del parser
.rargs
[:len(value
)]
33 setattr(parser
.values
, option
.dest
, value
)
36 opt
.BUILTIN_DEFAULT('NONE')
37 opt
.PRIVATE_EXTENSION_DEFAULT('samba4')
38 opt
.RECURSE('lib/replace')
39 opt
.RECURSE('dynconfig')
40 opt
.RECURSE('lib/ldb')
41 opt
.RECURSE('selftest')
42 opt
.RECURSE('source4/lib/tls')
43 opt
.RECURSE('source4/dsdb/samdb/ldb_modules')
45 opt
.RECURSE('source3')
46 opt
.RECURSE('lib/util')
47 opt
.RECURSE('lib/crypto')
49 opt
.samba_add_onoff_option('pthreadpool', with_name
="enable", without_name
="disable", default
=True)
51 opt
.add_option('--with-system-mitkrb5',
52 help='build Samba with system MIT Kerberos. ' +
53 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
54 action
='callback', callback
=system_mitkrb5_callback
, dest
='with_system_mitkrb5', default
=False)
55 opt
.add_option('--with-system-mitkdc',
56 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
58 dest
='with_system_mitkdc',
61 opt
.add_option('--without-ad-dc',
62 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
63 action
='store_true', dest
='without_ad_dc', default
=False)
65 opt
.add_option('--with-ntvfs-fileserver',
66 help='enable the deprecated NTVFS file server from the original Samba4 branch (default if --enable-selftest specified). Conflicts with --with-system-mitkrb5 and --without-ad-dc',
67 action
='store_true', dest
='with_ntvfs_fileserver')
69 opt
.add_option('--without-ntvfs-fileserver',
70 help='disable the deprecated NTVFS file server from the original Samba4 branch',
71 action
='store_false', dest
='with_ntvfs_fileserver')
73 opt
.add_option('--with-pie',
74 help=("Build Position Independent Executables " +
75 "(default if supported by compiler)"),
76 action
="store_true", dest
='enable_pie')
77 opt
.add_option('--without-pie',
78 help=("Disable Position Independent Executable builds"),
79 action
="store_false", dest
='enable_pie')
81 opt
.add_option('--with-relro',
82 help=("Build with full RELocation Read-Only (RELRO)" +
83 "(default if supported by compiler)"),
84 action
="store_true", dest
='enable_relro')
85 opt
.add_option('--without-relro',
86 help=("Disable RELRO builds"),
87 action
="store_false", dest
='enable_relro')
89 gr
= opt
.option_group('developer options')
91 opt
.tool_options('python') # options for disabling pyc or pyo compilation
92 # enable options related to building python extensions
96 version
= samba_version
.load_version(env
=conf
.env
)
98 conf
.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
99 conf
.DEFINE('_SAMBA_BUILD_', version
.MAJOR
, add_to_cflags
=True)
100 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
102 if Options
.options
.developer
:
103 conf
.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
104 conf
.env
.DEVELOPER
= True
106 conf
.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
108 conf
.env
.replace_add_global_pthread
= True
109 conf
.RECURSE('lib/replace')
111 conf
.RECURSE('examples/fuse')
113 conf
.SAMBA_CHECK_PERL(mandatory
=True)
114 conf
.find_program('xsltproc', var
='XSLTPROC')
116 if conf
.env
.disable_python
:
117 if not (Options
.options
.without_ad_dc
):
118 raise Utils
.WafError('--disable-python requires --without-ad-dc')
120 conf
.SAMBA_CHECK_PYTHON(mandatory
=True, version
=(2, 6, 0))
121 conf
.SAMBA_CHECK_PYTHON_HEADERS(mandatory
=(not conf
.env
.disable_python
))
123 if sys
.platform
== 'darwin' and not conf
.env
['HAVE_ENVIRON_DECL']:
124 # Mac OSX needs to have this and it's also needed that the python is compiled with this
125 # otherwise you face errors about common symbols
126 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
127 conf
.ADD_CFLAGS('-fno-common')
128 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
129 conf
.env
.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
131 if sys
.platform
== 'darwin':
132 conf
.ADD_LDFLAGS('-framework CoreFoundation')
134 if int(conf
.env
['PYTHON_VERSION'][0]) >= 3:
135 raise Utils
.WafError('Python version 3.x is not supported by Samba yet')
137 conf
.RECURSE('dynconfig')
138 conf
.RECURSE('selftest')
140 if conf
.CHECK_FOR_THIRD_PARTY():
141 conf
.RECURSE('third_party')
143 if not conf
.CHECK_ZLIB():
144 raise Utils
.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
146 conf
.define('USING_SYSTEM_ZLIB',1)
148 if not conf
.CHECK_POPT():
149 raise Utils
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
151 conf
.define('USING_SYSTEM_POPT', 1)
153 if not conf
.CHECK_CMOCKA():
154 raise Utils
.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
156 conf
.define('USING_SYSTEM_CMOCKA', 1)
158 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
159 if not conf
.CHECK_SOCKET_WRAPPER():
160 raise Utils
.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
162 conf
.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
164 if not conf
.CHECK_NSS_WRAPPER():
165 raise Utils
.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
167 conf
.define('USING_SYSTEM_NSS_WRAPPER', 1)
169 if not conf
.CHECK_RESOLV_WRAPPER():
170 raise Utils
.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
172 conf
.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
174 if not conf
.CHECK_UID_WRAPPER():
175 raise Utils
.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
177 conf
.define('USING_SYSTEM_UID_WRAPPER', 1)
179 if not conf
.CHECK_PAM_WRAPPER():
180 raise Utils
.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
182 conf
.define('USING_SYSTEM_PAM_WRAPPER', 1)
184 conf
.RECURSE('lib/ldb')
186 if conf
.CHECK_LDFLAGS(['-Wl,--wrap=test']):
187 conf
.env
['HAVE_LDWRAP'] = True
188 conf
.define('HAVE_LDWRAP', 1)
190 if not (Options
.options
.without_ad_dc
):
191 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
193 if Options
.options
.with_system_mitkrb5
:
194 conf
.PROCESS_SEPARATE_RULE('system_mitkrb5')
195 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
196 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
198 # Only process heimdal_build for non-MIT KRB5 builds
199 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
200 # to the lowcased output of 'krb5-config --vendor'.
201 # If it is not set or the output is 'heimdal', we are dealing with
202 # system-provided or embedded Heimdal build
203 if conf
.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
204 conf
.RECURSE('source4/heimdal_build')
205 conf
.RECURSE('source4/lib/tls')
206 conf
.RECURSE('source4/dsdb/samdb/ldb_modules')
207 conf
.RECURSE('source4/ntvfs/sysdep')
208 conf
.RECURSE('lib/util')
209 conf
.RECURSE('lib/util/charset')
210 conf
.RECURSE('source4/auth')
211 conf
.RECURSE('nsswitch')
212 conf
.RECURSE('libcli/smbreadline')
213 conf
.RECURSE('lib/crypto')
215 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
216 if Options
.options
.with_ntvfs_fileserver
!= False:
217 if not (Options
.options
.without_ad_dc
):
218 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
219 if Options
.options
.with_ntvfs_fileserver
== False:
220 if not (Options
.options
.without_ad_dc
):
221 raise Utils
.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
222 conf
.RECURSE('testsuite/unittests')
224 if Options
.options
.with_ntvfs_fileserver
== True:
225 if Options
.options
.without_ad_dc
:
226 raise Utils
.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
227 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
229 if Options
.options
.with_pthreadpool
:
230 if conf
.CONFIG_SET('HAVE_PTHREAD'):
231 conf
.DEFINE('WITH_PTHREADPOOL', '1')
233 Logs
.warn("pthreadpool support cannot be enabled when pthread support was not found")
234 conf
.undefine('WITH_PTHREADPOOL')
236 conf
.RECURSE('source3')
237 conf
.RECURSE('lib/texpect')
238 conf
.RECURSE('python')
239 if conf
.env
.with_ctdb
:
241 conf
.RECURSE('lib/socket')
244 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
246 # gentoo always adds this. We want our normal build to be as
247 # strict as the strictest OS we support, so adding this here
248 # allows us to find problems on our development hosts faster.
249 # It also results in faster load time.
251 conf
.env
.asneeded_ldflags
= conf
.ADD_LDFLAGS('-Wl,--as-needed', testflags
=True)
253 if not conf
.CHECK_NEED_LC("-lc not needed"):
254 conf
.ADD_LDFLAGS('-lc', testflags
=False)
256 if not conf
.CHECK_CODE('#include "tests/summary.c"',
257 define
='SUMMARY_PASSES',
259 msg
='Checking configure summary'):
260 raise Utils
.WafError('configure summary failed')
262 if Options
.options
.enable_pie
!= False:
263 if Options
.options
.enable_pie
== True:
266 # not specified, only build PIEs if supported by compiler
268 if conf
.check_cc(cflags
='-fPIE', ldflags
='-pie', mandatory
=need_pie
,
269 msg
="Checking compiler for PIE support"):
270 conf
.env
['ENABLE_PIE'] = True
272 if Options
.options
.enable_relro
!= False:
273 if Options
.options
.enable_relro
== True:
276 # not specified, only build RELROs if supported by compiler
278 if conf
.check_cc(cflags
='', ldflags
='-Wl,-z,relro,-z,now', mandatory
=need_relro
,
279 msg
="Checking compiler for full RELRO support"):
280 conf
.env
['ENABLE_RELRO'] = True
282 conf
.SAMBA_CONFIG_H('include/config.h')
285 '''build TAGS file using etags'''
287 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
288 cmd
= 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root
, source_root
)
289 print("Running: %s" % cmd
)
290 status
= os
.system(cmd
)
291 if os
.WEXITSTATUS(status
):
292 raise Utils
.WafError('etags failed')
295 "build 'tags' file using ctags"
297 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
298 cmd
= 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root
, source_root
)
299 print("Running: %s" % cmd
)
300 status
= os
.system(cmd
)
301 if os
.WEXITSTATUS(status
):
302 raise Utils
.WafError('ctags failed')
305 # putting this here enabled build in the list
306 # of commands in --help
308 '''build all targets'''
309 samba_version
.load_version(env
=bld
.env
, is_install
=bld
.is_install
)
313 '''build python apidocs'''
314 bp
= os
.path
.abspath('bin/python')
316 modules
= ['talloc', 'tdb', 'ldb']
318 f
= os
.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp
, m
, m
), 'r')
320 mpaths
[m
] = f
.read().strip()
324 cmd
= ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
325 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
326 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n
for n
in modules
))
328 print("Running: %s" % cmd
)
329 status
= os
.system(cmd
)
330 if os
.WEXITSTATUS(status
):
331 raise Utils
.WafError('pydoctor failed')
335 '''run pep8 validator'''
336 cmd
='PYTHONPATH=bin/python pep8 -r bin/python/samba'
337 print("Running: %s" % cmd
)
338 status
= os
.system(cmd
)
339 if os
.WEXITSTATUS(status
):
340 raise Utils
.WafError('pep8 failed')
344 '''build wafsamba apidocs'''
345 from samba_utils
import recursive_dirlist
347 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern
='*.py')
349 cmd
='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
352 cmd
+= ' --add-module %s' % f
353 print("Running: %s" % cmd
)
354 status
= os
.system(cmd
)
355 if os
.WEXITSTATUS(status
):
356 raise Utils
.WafError('wafdocs failed')
360 '''makes a tarball for distribution'''
361 sambaversion
= samba_version
.load_version(env
=None)
363 os
.system("make -C ctdb manpages")
364 samba_dist
.DIST_FILES('ctdb/doc:ctdb/doc', extend
=True)
366 os
.system("DOC_VERSION='" + sambaversion
.STRING
+ "' " + srcdir
+ "/release-scripts/build-manpages-nogit")
367 samba_dist
.DIST_FILES('bin/docs:docs', extend
=True)
369 if sambaversion
.IS_SNAPSHOT
:
370 # write .distversion file and add to tar
371 if not os
.path
.isdir(blddir
):
373 distversionf
= tempfile
.NamedTemporaryFile(mode
='w', prefix
='.distversion',dir=blddir
)
374 for field
in sambaversion
.vcs_fields
:
375 distveroption
= field
+ '=' + str(sambaversion
.vcs_fields
[field
])
376 distversionf
.write(distveroption
+ '\n')
378 samba_dist
.DIST_FILES('%s:.distversion' % distversionf
.name
, extend
=True)
387 '''test that distribution tarball builds and installs'''
388 samba_version
.load_version(env
=None)
390 d
= Scripting
.distcheck
393 def wildcard_cmd(cmd
):
394 '''called on a unknown command'''
395 from samba_wildcard
import run_named_build_task
396 run_named_build_task(cmd
)
399 from samba_wildcard
import wildcard_main
401 wildcard_main(wildcard_cmd
)
402 Scripting
.main
= main
404 def reconfigure(ctx
):
405 '''reconfigure if config scripts have changed'''
407 samba_utils
.reconfigure(ctx
)
410 if os
.path
.isdir(os
.path
.join(srcdir
, ".git")):
411 # Check if there are submodules that are checked out but out of date.
412 for submodule
, status
in samba_git
.read_submodule_status(srcdir
):
413 if status
== "out-of-date":
414 raise Utils
.WafError("some submodules are out of date. Please run 'git submodule update'")