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