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