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('packaging')
41 opt
.RECURSE('lib/ldb')
42 opt
.RECURSE('selftest')
43 opt
.RECURSE('source4/lib/tls')
44 opt
.RECURSE('source4/dsdb/samdb/ldb_modules')
46 opt
.RECURSE('source3')
47 opt
.RECURSE('lib/util')
48 opt
.RECURSE('lib/crypto')
52 opt
.samba_add_onoff_option('pthreadpool', with_name
="enable", without_name
="disable", default
=True)
54 opt
.add_option('--with-system-mitkrb5',
55 help='build Samba with system MIT Kerberos. ' +
56 'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
57 action
='callback', callback
=system_mitkrb5_callback
, dest
='with_system_mitkrb5', default
=False)
58 opt
.add_option('--with-system-mitkdc',
59 help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
61 dest
='with_system_mitkdc',
64 opt
.add_option('--without-ad-dc',
65 help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
66 action
='store_true', dest
='without_ad_dc', default
=False)
68 opt
.add_option('--with-ntvfs-fileserver',
69 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',
70 action
='store_true', dest
='with_ntvfs_fileserver')
72 opt
.add_option('--without-ntvfs-fileserver',
73 help='disable the deprecated NTVFS file server from the original Samba4 branch',
74 action
='store_false', dest
='with_ntvfs_fileserver')
76 opt
.add_option('--with-pie',
77 help=("Build Position Independent Executables " +
78 "(default if supported by compiler)"),
79 action
="store_true", dest
='enable_pie')
80 opt
.add_option('--without-pie',
81 help=("Disable Position Independent Executable builds"),
82 action
="store_false", dest
='enable_pie')
84 opt
.add_option('--with-relro',
85 help=("Build with full RELocation Read-Only (RELRO)" +
86 "(default if supported by compiler)"),
87 action
="store_true", dest
='enable_relro')
88 opt
.add_option('--without-relro',
89 help=("Disable RELRO builds"),
90 action
="store_false", dest
='enable_relro')
92 gr
= opt
.option_group('developer options')
94 opt
.tool_options('python') # options for disabling pyc or pyo compilation
95 # enable options related to building python extensions
99 version
= samba_version
.load_version(env
=conf
.env
)
101 conf
.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
102 conf
.DEFINE('_SAMBA_BUILD_', version
.MAJOR
, add_to_cflags
=True)
103 conf
.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags
=True)
105 if Options
.options
.developer
:
106 conf
.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
107 conf
.env
.DEVELOPER
= True
109 conf
.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
111 conf
.env
.replace_add_global_pthread
= True
112 conf
.RECURSE('lib/replace')
114 conf
.RECURSE('examples/fuse')
116 conf
.SAMBA_CHECK_PERL(mandatory
=True)
117 conf
.find_program('xsltproc', var
='XSLTPROC')
119 if conf
.env
.disable_python
:
120 if not (Options
.options
.without_ad_dc
):
121 raise Utils
.WafError('--disable-python requires --without-ad-dc')
123 conf
.SAMBA_CHECK_PYTHON(mandatory
=True, version
=(2, 6, 0))
124 conf
.SAMBA_CHECK_PYTHON_HEADERS(mandatory
=(not conf
.env
.disable_python
))
126 if sys
.platform
== 'darwin' and not conf
.env
['HAVE_ENVIRON_DECL']:
127 # Mac OSX needs to have this and it's also needed that the python is compiled with this
128 # otherwise you face errors about common symbols
129 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
130 conf
.ADD_CFLAGS('-fno-common')
131 if not conf
.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
132 conf
.env
.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
134 if sys
.platform
== 'darwin':
135 conf
.ADD_LDFLAGS('-framework CoreFoundation')
137 if int(conf
.env
['PYTHON_VERSION'][0]) >= 3:
138 raise Utils
.WafError('Python version 3.x is not supported by Samba yet')
140 conf
.RECURSE('dynconfig')
141 conf
.RECURSE('selftest')
143 if conf
.CHECK_FOR_THIRD_PARTY():
144 conf
.RECURSE('third_party')
146 if not conf
.CHECK_ZLIB():
147 raise Utils
.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
149 conf
.define('USING_SYSTEM_ZLIB',1)
151 if not conf
.CHECK_POPT():
152 raise Utils
.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
154 conf
.define('USING_SYSTEM_POPT', 1)
156 if not conf
.CHECK_CMOCKA():
157 raise Utils
.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
159 conf
.define('USING_SYSTEM_CMOCKA', 1)
161 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
162 if not conf
.CHECK_SOCKET_WRAPPER():
163 raise Utils
.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
165 conf
.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
167 if not conf
.CHECK_NSS_WRAPPER():
168 raise Utils
.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
170 conf
.define('USING_SYSTEM_NSS_WRAPPER', 1)
172 if not conf
.CHECK_RESOLV_WRAPPER():
173 raise Utils
.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
175 conf
.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
177 if not conf
.CHECK_UID_WRAPPER():
178 raise Utils
.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
180 conf
.define('USING_SYSTEM_UID_WRAPPER', 1)
182 if not conf
.CHECK_PAM_WRAPPER():
183 raise Utils
.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
185 conf
.define('USING_SYSTEM_PAM_WRAPPER', 1)
187 conf
.RECURSE('lib/ldb')
189 if conf
.CHECK_LDFLAGS(['-Wl,--wrap=test']):
190 conf
.env
['HAVE_LDWRAP'] = True
191 conf
.define('HAVE_LDWRAP', 1)
193 if not (Options
.options
.without_ad_dc
):
194 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
196 if Options
.options
.with_system_mitkrb5
:
197 conf
.PROCESS_SEPARATE_RULE('system_mitkrb5')
198 if not (Options
.options
.without_ad_dc
or Options
.options
.with_system_mitkrb5
):
199 conf
.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
201 # Only process heimdal_build for non-MIT KRB5 builds
202 # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
203 # to the lowcased output of 'krb5-config --vendor'.
204 # If it is not set or the output is 'heimdal', we are dealing with
205 # system-provided or embedded Heimdal build
206 if conf
.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
207 conf
.RECURSE('source4/heimdal_build')
208 conf
.RECURSE('source4/lib/tls')
209 conf
.RECURSE('source4/dsdb/samdb/ldb_modules')
210 conf
.RECURSE('source4/ntvfs/sysdep')
211 conf
.RECURSE('lib/util')
212 conf
.RECURSE('lib/util/charset')
213 conf
.RECURSE('source4/auth')
214 conf
.RECURSE('nsswitch')
215 conf
.RECURSE('libcli/smbreadline')
216 conf
.RECURSE('lib/crypto')
218 if conf
.CONFIG_GET('ENABLE_SELFTEST'):
219 if Options
.options
.with_ntvfs_fileserver
!= False:
220 if not (Options
.options
.without_ad_dc
):
221 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
222 if Options
.options
.with_ntvfs_fileserver
== False:
223 if not (Options
.options
.without_ad_dc
):
224 raise Utils
.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
225 conf
.RECURSE('testsuite/unittests')
227 if Options
.options
.with_ntvfs_fileserver
== True:
228 if Options
.options
.without_ad_dc
:
229 raise Utils
.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
230 conf
.DEFINE('WITH_NTVFS_FILESERVER', 1)
232 if Options
.options
.with_pthreadpool
:
233 if conf
.CONFIG_SET('HAVE_PTHREAD'):
234 conf
.DEFINE('WITH_PTHREADPOOL', '1')
236 Logs
.warn("pthreadpool support cannot be enabled when pthread support was not found")
237 conf
.undefine('WITH_PTHREADPOOL')
239 conf
.RECURSE('source3')
240 conf
.RECURSE('lib/texpect')
241 conf
.RECURSE('python')
242 if conf
.env
.with_ctdb
:
244 conf
.RECURSE('lib/socket')
246 conf
.RECURSE('packaging')
248 conf
.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
250 # gentoo always adds this. We want our normal build to be as
251 # strict as the strictest OS we support, so adding this here
252 # allows us to find problems on our development hosts faster.
253 # It also results in faster load time.
255 conf
.env
.asneeded_ldflags
= conf
.ADD_LDFLAGS('-Wl,--as-needed', testflags
=True)
257 if not conf
.CHECK_NEED_LC("-lc not needed"):
258 conf
.ADD_LDFLAGS('-lc', testflags
=False)
260 if not conf
.CHECK_CODE('#include "tests/summary.c"',
261 define
='SUMMARY_PASSES',
263 msg
='Checking configure summary'):
264 raise Utils
.WafError('configure summary failed')
266 if Options
.options
.enable_pie
!= False:
267 if Options
.options
.enable_pie
== True:
270 # not specified, only build PIEs if supported by compiler
272 if conf
.check_cc(cflags
='-fPIE', ldflags
='-pie', mandatory
=need_pie
,
273 msg
="Checking compiler for PIE support"):
274 conf
.env
['ENABLE_PIE'] = True
276 if Options
.options
.enable_relro
!= False:
277 if Options
.options
.enable_relro
== True:
280 # not specified, only build RELROs if supported by compiler
282 if conf
.check_cc(cflags
='', ldflags
='-Wl,-z,relro,-z,now', mandatory
=need_relro
,
283 msg
="Checking compiler for full RELRO support"):
284 conf
.env
['ENABLE_RELRO'] = True
286 conf
.SAMBA_CONFIG_H('include/config.h')
289 '''build TAGS file using etags'''
291 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
292 cmd
= 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root
, source_root
)
293 print("Running: %s" % cmd
)
294 status
= os
.system(cmd
)
295 if os
.WEXITSTATUS(status
):
296 raise Utils
.WafError('etags failed')
299 "build 'tags' file using ctags"
301 source_root
= os
.path
.dirname(Utils
.g_module
.root_path
)
302 cmd
= 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root
, source_root
)
303 print("Running: %s" % cmd
)
304 status
= os
.system(cmd
)
305 if os
.WEXITSTATUS(status
):
306 raise Utils
.WafError('ctags failed')
309 # putting this here enabled build in the list
310 # of commands in --help
312 '''build all targets'''
313 samba_version
.load_version(env
=bld
.env
, is_install
=bld
.is_install
)
317 '''build python apidocs'''
318 bp
= os
.path
.abspath('bin/python')
320 modules
= ['talloc', 'tdb', 'ldb']
322 f
= os
.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp
, m
, m
), 'r')
324 mpaths
[m
] = f
.read().strip()
328 cmd
= ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
329 '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
330 '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n
for n
in modules
))
332 print("Running: %s" % cmd
)
333 status
= os
.system(cmd
)
334 if os
.WEXITSTATUS(status
):
335 raise Utils
.WafError('pydoctor failed')
339 '''run pep8 validator'''
340 cmd
='PYTHONPATH=bin/python pep8 -r bin/python/samba'
341 print("Running: %s" % cmd
)
342 status
= os
.system(cmd
)
343 if os
.WEXITSTATUS(status
):
344 raise Utils
.WafError('pep8 failed')
348 '''build wafsamba apidocs'''
349 from samba_utils
import recursive_dirlist
351 list = recursive_dirlist('../buildtools/wafsamba', '.', pattern
='*.py')
353 cmd
='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
356 cmd
+= ' --add-module %s' % f
357 print("Running: %s" % cmd
)
358 status
= os
.system(cmd
)
359 if os
.WEXITSTATUS(status
):
360 raise Utils
.WafError('wafdocs failed')
364 '''makes a tarball for distribution'''
365 sambaversion
= samba_version
.load_version(env
=None)
367 os
.system("make -C ctdb manpages")
368 samba_dist
.DIST_FILES('ctdb/doc:ctdb/doc', extend
=True)
370 os
.system("DOC_VERSION='" + sambaversion
.STRING
+ "' " + srcdir
+ "/release-scripts/build-manpages-nogit")
371 samba_dist
.DIST_FILES('bin/docs:docs', extend
=True)
373 if sambaversion
.IS_SNAPSHOT
:
374 # write .distversion file and add to tar
375 if not os
.path
.isdir(blddir
):
377 distversionf
= tempfile
.NamedTemporaryFile(mode
='w', prefix
='.distversion',dir=blddir
)
378 for field
in sambaversion
.vcs_fields
:
379 distveroption
= field
+ '=' + str(sambaversion
.vcs_fields
[field
])
380 distversionf
.write(distveroption
+ '\n')
382 samba_dist
.DIST_FILES('%s:.distversion' % distversionf
.name
, extend
=True)
391 '''test that distribution tarball builds and installs'''
392 samba_version
.load_version(env
=None)
394 d
= Scripting
.distcheck
397 def wildcard_cmd(cmd
):
398 '''called on a unknown command'''
399 from samba_wildcard
import run_named_build_task
400 run_named_build_task(cmd
)
403 from samba_wildcard
import wildcard_main
405 wildcard_main(wildcard_cmd
)
406 Scripting
.main
= main
408 def reconfigure(ctx
):
409 '''reconfigure if config scripts have changed'''
411 samba_utils
.reconfigure(ctx
)
414 if os
.path
.isdir(os
.path
.join(srcdir
, ".git")):
415 # Check if there are submodules that are checked out but out of date.
416 for submodule
, status
in samba_git
.read_submodule_status(srcdir
):
417 if status
== "out-of-date":
418 raise Utils
.WafError("some submodules are out of date. Please run 'git submodule update'")