libcli/smb/smb_direct.c define...
[metze/samba/wip.git] / wscript
1 #!/usr/bin/env python
2
3 srcdir = '.'
4 blddir = 'bin'
5
6 APPNAME='samba'
7 VERSION=None
8
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
13 import shutil
14
15 samba_dist.DIST_DIRS('.')
16 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions')
17
18 # install in /usr/local/samba by default
19 default_prefix = Options.default_prefix = '/usr/local/samba'
20
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)
25     value = []
26     for arg in parser.rargs:
27         # stop on --foo like options
28         if arg[:2] == "--" and len(arg) > 2:
29             break
30         value.append(arg)
31     if len(value)>0:
32         del parser.rargs[:len(value)]
33         setattr(parser.values, option.dest, value)
34
35 def set_options(opt):
36     opt.BUILTIN_DEFAULT('NONE')
37     opt.PRIVATE_EXTENSION_DEFAULT('samba4')
38     opt.RECURSE('auth')
39     opt.RECURSE('lib/replace')
40     opt.RECURSE('dynconfig')
41     opt.RECURSE('packaging')
42     opt.RECURSE('lib/ldb')
43     opt.RECURSE('selftest')
44     opt.RECURSE('source4/lib/tls')
45     opt.RECURSE('source4/dsdb/samdb/ldb_modules')
46     opt.RECURSE('libcli/smb')
47     opt.RECURSE('pidl')
48     opt.RECURSE('source3')
49     opt.RECURSE('lib/util')
50     opt.RECURSE('lib/crypto')
51     opt.RECURSE('ctdb')
52
53
54     opt.samba_add_onoff_option('pthreadpool', with_name="enable", without_name="disable", default=True)
55
56     opt.add_option('--with-system-mitkrb5',
57                    help='build Samba with system MIT Kerberos. ' +
58                         'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
59                    action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
60     opt.add_option('--with-system-mitkdc',
61                    help=('Specify the path to the krb5kdc binary from MIT Kerberos'),
62                    type="string",
63                    dest='with_system_mitkdc',
64                    default=None)
65
66     opt.add_option('--without-ad-dc',
67                    help='disable AD DC functionality (enables only Samba FS (File Server, Winbind, NMBD) and client utilities.',
68                    action='store_true', dest='without_ad_dc', default=False)
69
70     opt.add_option('--with-ntvfs-fileserver',
71                    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',
72                    action='store_true', dest='with_ntvfs_fileserver')
73
74     opt.add_option('--without-ntvfs-fileserver',
75                    help='disable the deprecated NTVFS file server from the original Samba4 branch',
76                    action='store_false', dest='with_ntvfs_fileserver')
77
78     opt.add_option('--with-pie',
79                   help=("Build Position Independent Executables " +
80                         "(default if supported by compiler)"),
81                   action="store_true", dest='enable_pie')
82     opt.add_option('--without-pie',
83                   help=("Disable Position Independent Executable builds"),
84                   action="store_false", dest='enable_pie')
85
86     opt.add_option('--with-relro',
87                   help=("Build with full RELocation Read-Only (RELRO)" +
88                         "(default if supported by compiler)"),
89                   action="store_true", dest='enable_relro')
90     opt.add_option('--without-relro',
91                   help=("Disable RELRO builds"),
92                   action="store_false", dest='enable_relro')
93
94     gr = opt.option_group('developer options')
95
96     opt.tool_options('python') # options for disabling pyc or pyo compilation
97     # enable options related to building python extensions
98
99
100 def configure(conf):
101     version = samba_version.load_version(env=conf.env)
102
103     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
104     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
105     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
106
107     if Options.options.developer:
108         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
109         conf.env.DEVELOPER = True
110         # if we are in a git tree without a pre-commit hook, install a
111         # simple default.
112         pre_commit_hook = os.path.join(srcdir, '.git/hooks/pre-commit')
113         if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
114             not os.path.exists(pre_commit_hook)):
115             shutil.copy(os.path.join(srcdir, 'script/git-hooks/pre-commit-hook'),
116                         pre_commit_hook)
117
118     conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
119
120     conf.env.replace_add_global_pthread = True
121     conf.RECURSE('lib/replace')
122
123     conf.RECURSE('examples/fuse')
124
125     conf.SAMBA_CHECK_PERL(mandatory=True)
126     conf.find_program('xsltproc', var='XSLTPROC')
127
128     if conf.env.disable_python:
129         if not (Options.options.without_ad_dc):
130             raise Utils.WafError('--disable-python requires --without-ad-dc')
131
132     conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2, 6, 0))
133     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=(not conf.env.disable_python))
134
135     if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
136         # Mac OSX needs to have this and it's also needed that the python is compiled with this
137         # otherwise you face errors about common symbols
138         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
139             conf.ADD_CFLAGS('-fno-common')
140         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
141             conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
142
143     if sys.platform == 'darwin':
144         conf.ADD_LDFLAGS('-framework CoreFoundation')
145
146     if int(conf.env['PYTHON_VERSION'][0]) >= 3:
147         raise Utils.WafError('Python version 3.x is not supported by Samba yet')
148
149     conf.RECURSE('dynconfig')
150     conf.RECURSE('selftest')
151
152     if conf.CHECK_FOR_THIRD_PARTY():
153         conf.RECURSE('third_party')
154     else:
155         if not conf.CHECK_ZLIB():
156             raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
157         else:
158             conf.define('USING_SYSTEM_ZLIB',1)
159
160         if not conf.CHECK_POPT():
161             raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
162         else:
163             conf.define('USING_SYSTEM_POPT', 1)
164
165         if not conf.CHECK_CMOCKA():
166             raise Utils.WafError('cmocka development packages has not been found.\nIf third_party is installed, check that it is in the proper place.')
167         else:
168             conf.define('USING_SYSTEM_CMOCKA', 1)
169
170         if conf.CONFIG_GET('ENABLE_SELFTEST'):
171             if not conf.CHECK_SOCKET_WRAPPER():
172                 raise Utils.WafError('socket_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
173             else:
174                 conf.define('USING_SYSTEM_SOCKET_WRAPPER', 1)
175
176             if not conf.CHECK_NSS_WRAPPER():
177                 raise Utils.WafError('nss_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
178             else:
179                 conf.define('USING_SYSTEM_NSS_WRAPPER', 1)
180
181             if not conf.CHECK_RESOLV_WRAPPER():
182                 raise Utils.WafError('resolv_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
183             else:
184                 conf.define('USING_SYSTEM_RESOLV_WRAPPER', 1)
185
186             if not conf.CHECK_UID_WRAPPER():
187                 raise Utils.WafError('uid_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
188             else:
189                 conf.define('USING_SYSTEM_UID_WRAPPER', 1)
190
191             if not conf.CHECK_PAM_WRAPPER():
192                 raise Utils.WafError('pam_wrapper package has not been found.\nIf third_party is installed, check that it is in the proper place.')
193             else:
194                 conf.define('USING_SYSTEM_PAM_WRAPPER', 1)
195
196     conf.RECURSE('lib/ldb')
197
198     if conf.CHECK_LDFLAGS(['-Wl,--wrap=test']):
199         conf.env['HAVE_LDWRAP'] = True
200         conf.define('HAVE_LDWRAP', 1)
201
202     if not (Options.options.without_ad_dc):
203         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
204
205     if Options.options.with_system_mitkrb5:
206         conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
207     if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
208         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
209
210     # Only process heimdal_build for non-MIT KRB5 builds
211     # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
212     # to the lowcased output of 'krb5-config --vendor'.
213     # If it is not set or the output is 'heimdal', we are dealing with
214     # system-provided or embedded Heimdal build
215     if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
216         conf.RECURSE('source4/heimdal_build')
217     conf.RECURSE('auth')
218     conf.RECURSE('source4/lib/tls')
219     conf.RECURSE('source4/dsdb/samdb/ldb_modules')
220     conf.RECURSE('source4/ntvfs/sysdep')
221     conf.RECURSE('lib/util')
222     conf.RECURSE('lib/util/charset')
223     conf.RECURSE('source4/auth')
224     conf.RECURSE('nsswitch')
225     conf.RECURSE('libcli/smbreadline')
226     conf.RECURSE('lib/crypto')
227     conf.RECURSE('libcli/smb')
228     conf.RECURSE('pidl')
229     if conf.CONFIG_GET('ENABLE_SELFTEST'):
230         if Options.options.with_ntvfs_fileserver != False:
231             if not (Options.options.without_ad_dc):
232                 conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
233         if Options.options.with_ntvfs_fileserver == False:
234             if not (Options.options.without_ad_dc):
235                 raise Utils.WafError('--without-ntvfs-fileserver conflicts with --enable-selftest while building the AD DC')
236         conf.RECURSE('testsuite/unittests')
237
238     if Options.options.with_ntvfs_fileserver == True:
239         if Options.options.without_ad_dc:
240             raise Utils.WafError('--with-ntvfs-fileserver conflicts with --without-ad-dc')
241         conf.DEFINE('WITH_NTVFS_FILESERVER', 1)
242
243     if Options.options.with_pthreadpool:
244         if conf.CONFIG_SET('HAVE_PTHREAD'):
245             conf.DEFINE('WITH_PTHREADPOOL', '1')
246         else:
247             Logs.warn("pthreadpool support cannot be enabled when pthread support was not found")
248             conf.undefine('WITH_PTHREADPOOL')
249
250     conf.RECURSE('source3')
251     conf.RECURSE('lib/texpect')
252     conf.RECURSE('python')
253     if conf.env.with_ctdb:
254         conf.RECURSE('ctdb')
255     conf.RECURSE('lib/socket')
256     conf.RECURSE('auth')
257     conf.RECURSE('packaging')
258
259     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
260
261     # gentoo always adds this. We want our normal build to be as
262     # strict as the strictest OS we support, so adding this here
263     # allows us to find problems on our development hosts faster.
264     # It also results in faster load time.
265
266     conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
267
268     if not conf.CHECK_NEED_LC("-lc not needed"):
269         conf.ADD_LDFLAGS('-lc', testflags=False)
270
271     if not conf.CHECK_CODE('#include "tests/summary.c"',
272                            define='SUMMARY_PASSES',
273                            addmain=False,
274                            msg='Checking configure summary'):
275         raise Utils.WafError('configure summary failed')
276
277     if Options.options.enable_pie != False:
278         if Options.options.enable_pie == True:
279                 need_pie = True
280         else:
281                 # not specified, only build PIEs if supported by compiler
282                 need_pie = False
283         if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
284                          msg="Checking compiler for PIE support"):
285             conf.env['ENABLE_PIE'] = True
286
287     if Options.options.enable_relro != False:
288         if Options.options.enable_relro == True:
289             need_relro = True
290         else:
291             # not specified, only build RELROs if supported by compiler
292             need_relro = False
293         if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
294                          msg="Checking compiler for full RELRO support"):
295             conf.env['ENABLE_RELRO'] = True
296
297     conf.SAMBA_CONFIG_H('include/config.h')
298
299 def etags(ctx):
300     '''build TAGS file using etags'''
301     import Utils
302     source_root = os.path.dirname(Utils.g_module.root_path)
303     cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
304     print("Running: %s" % cmd)
305     status = os.system(cmd)
306     if os.WEXITSTATUS(status):
307         raise Utils.WafError('etags failed')
308
309 def ctags(ctx):
310     "build 'tags' file using ctags"
311     import Utils
312     source_root = os.path.dirname(Utils.g_module.root_path)
313     cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
314     print("Running: %s" % cmd)
315     status = os.system(cmd)
316     if os.WEXITSTATUS(status):
317         raise Utils.WafError('ctags failed')
318
319
320 # putting this here enabled build in the list
321 # of commands in --help
322 def build(bld):
323     '''build all targets'''
324     samba_version.load_version(env=bld.env, is_install=bld.is_install)
325
326
327 def pydoctor(ctx):
328     '''build python apidocs'''
329     bp = os.path.abspath('bin/python')
330     mpaths = {}
331     modules = ['talloc', 'tdb', 'ldb']
332     for m in modules:
333         f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
334         try:
335             mpaths[m] = f.read().strip()
336         finally:
337             f.close()
338     mpaths['main'] = bp
339     cmd = ('PYTHONPATH=%(main)s pydoctor --introspect-c-modules --project-name=Samba '
340            '--project-url=http://www.samba.org --make-html --docformat=restructuredtext '
341            '--add-package bin/python/samba ' + ''.join('--add-module %s ' % n for n in modules))
342     cmd = cmd % mpaths
343     print("Running: %s" % cmd)
344     status = os.system(cmd)
345     if os.WEXITSTATUS(status):
346         raise Utils.WafError('pydoctor failed')
347
348
349 def pep8(ctx):
350     '''run pep8 validator'''
351     cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
352     print("Running: %s" % cmd)
353     status = os.system(cmd)
354     if os.WEXITSTATUS(status):
355         raise Utils.WafError('pep8 failed')
356
357
358 def wafdocs(ctx):
359     '''build wafsamba apidocs'''
360     from samba_utils import recursive_dirlist
361     os.system('pwd')
362     list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
363
364     cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
365     print(list)
366     for f in list:
367         cmd += ' --add-module %s' % f
368     print("Running: %s" % cmd)
369     status = os.system(cmd)
370     if os.WEXITSTATUS(status):
371         raise Utils.WafError('wafdocs failed')
372
373
374 def dist():
375     '''makes a tarball for distribution'''
376     sambaversion = samba_version.load_version(env=None)
377
378     os.system("make -C ctdb manpages")
379     samba_dist.DIST_FILES('ctdb/doc:ctdb/doc', extend=True)
380
381     os.system("DOC_VERSION='" + sambaversion.STRING + "' " + srcdir + "/release-scripts/build-manpages-nogit")
382     samba_dist.DIST_FILES('bin/docs:docs', extend=True)
383
384     if sambaversion.IS_SNAPSHOT:
385         # write .distversion file and add to tar
386         if not os.path.isdir(blddir):
387             os.makedirs(blddir)
388         distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
389         for field in sambaversion.vcs_fields:
390             distveroption = field + '=' + str(sambaversion.vcs_fields[field])
391             distversionf.write(distveroption + '\n')
392         distversionf.flush()
393         samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
394
395         samba_dist.dist()
396         distversionf.close()
397     else:
398         samba_dist.dist()
399
400
401 def distcheck():
402     '''test that distribution tarball builds and installs'''
403     samba_version.load_version(env=None)
404     import Scripting
405     d = Scripting.distcheck
406     d()
407
408 def wildcard_cmd(cmd):
409     '''called on a unknown command'''
410     from samba_wildcard import run_named_build_task
411     run_named_build_task(cmd)
412
413 def main():
414     from samba_wildcard import wildcard_main
415
416     wildcard_main(wildcard_cmd)
417 Scripting.main = main
418
419 def reconfigure(ctx):
420     '''reconfigure if config scripts have changed'''
421     import samba_utils
422     samba_utils.reconfigure(ctx)
423
424
425 if os.path.isdir(os.path.join(srcdir, ".git")):
426     # Check if there are submodules that are checked out but out of date.
427     for submodule, status in samba_git.read_submodule_status(srcdir):
428         if status == "out-of-date":
429             raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'")