waf: fetch and use some exit codes of called processes
[vlendec/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, Scripting, Utils, samba_version
12
13
14 samba_dist.DIST_DIRS('.')
15 samba_dist.DIST_BLACKLIST('.gitignore .bzrignore source4/selftest/provisions/alpha13 source4/selftest/provisions/release-4-0-0/ source4/selftest/provisions/release-4-1-0rc3/')
16
17 # install in /usr/local/samba by default
18 Options.default_prefix = '/usr/local/samba'
19
20 # This callback optionally takes a list of paths as arguments:
21 # --with-system_mitkrb5 /path/to/krb5 /another/path
22 def system_mitkrb5_callback(option, opt, value, parser):
23     setattr(parser.values, option.dest, True)
24     value = []
25     for arg in parser.rargs:
26         # stop on --foo like options
27         if arg[:2] == "--" and len(arg) > 2:
28             break
29         value.append(arg)
30     if len(value)>0:
31         del parser.rargs[:len(value)]
32         setattr(parser.values, option.dest, value)
33
34 def set_options(opt):
35     opt.BUILTIN_DEFAULT('NONE')
36     opt.PRIVATE_EXTENSION_DEFAULT('samba4')
37     opt.RECURSE('lib/replace')
38     opt.RECURSE('dynconfig')
39     opt.RECURSE('lib/ldb')
40     opt.RECURSE('lib/ntdb')
41     opt.RECURSE('selftest')
42     opt.RECURSE('source4/lib/tls')
43     opt.RECURSE('pidl')
44     opt.RECURSE('source3')
45     opt.RECURSE('lib/util')
46
47     opt.add_option('--with-system-mitkrb5',
48                    help='enable system MIT krb5 build (includes Samba 4 client and Samba 3 code base).'+
49                         'You may specify list of paths where Kerberos is installed (e.g. /usr/local /usr/kerberos) to search krb5-config',
50                    action='callback', callback=system_mitkrb5_callback, dest='with_system_mitkrb5', default=False)
51
52     opt.add_option('--without-ad-dc',
53                    help='disable AD DC functionality (enables Samba 4 client and Samba 3 code base).',
54                    action='store_true', dest='without_ad_dc', default=False)
55
56     opt.add_option('--with-pie',
57                   help=("Build Position Independent Executables " +
58                         "(default if supported by compiler)"),
59                   action="store_true", dest='enable_pie')
60     opt.add_option('--without-pie',
61                   help=("Disable Position Independent Executable builds"),
62                   action="store_false", dest='enable_pie')
63
64     opt.add_option('--with-relro',
65                   help=("Build with full RELocation Read-Only (RELRO)" +
66                         "(default if supported by compiler)"),
67                   action="store_true", dest='enable_relro')
68     opt.add_option('--without-relro',
69                   help=("Disable RELRO builds"),
70                   action="store_false", dest='enable_relro')
71
72     opt.add_option('--with-systemd',
73                    help=("Enable systemd integration"),
74                    action='store_true', dest='enable_systemd')
75
76     opt.add_option('--without-systemd',
77                    help=("Disable systemd integration"),
78                    action='store_false', dest='enable_systemd')
79
80     gr = opt.option_group('developer options')
81
82     opt.tool_options('python') # options for disabling pyc or pyo compilation
83     # enable options related to building python extensions
84
85
86 def configure(conf):
87     version = samba_version.load_version(env=conf.env)
88
89     conf.DEFINE('CONFIG_H_IS_FROM_SAMBA', 1)
90     conf.DEFINE('_SAMBA_BUILD_', version.MAJOR, add_to_cflags=True)
91     conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
92
93     if Options.options.developer:
94         conf.ADD_CFLAGS('-DDEVELOPER -DDEBUG_PASSWORD')
95         conf.env.DEVELOPER = True
96
97     conf.ADD_EXTRA_INCLUDES('#include/public #source4 #lib #source4/lib #source4/include #include #lib/replace')
98
99     conf.RECURSE('lib/replace')
100
101     conf.find_program('perl', var='PERL', mandatory=True)
102     conf.find_program('xsltproc', var='XSLTPROC')
103
104     conf.SAMBA_CHECK_PYTHON(mandatory=True, version=(2,5,0))
105     conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=True)
106
107     if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']:
108         # Mac OSX needs to have this and it's also needed that the python is compiled with this
109         # otherwise you face errors about common symbols
110         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -fno-common is needed"):
111             conf.ADD_CFLAGS('-fno-common')
112         if not conf.CHECK_SHLIB_W_PYTHON("Checking if -undefined dynamic_lookup is not need"):
113             conf.env.append_value('shlib_LINKFLAGS', ['-undefined', 'dynamic_lookup'])
114
115     if sys.platform == 'darwin':
116         conf.ADD_LDFLAGS('-framework CoreFoundation')
117
118     if int(conf.env['PYTHON_VERSION'][0]) >= 3:
119         raise Utils.WafError('Python version 3.x is not supported by Samba yet')
120
121     conf.RECURSE('dynconfig')
122     conf.RECURSE('lib/ldb')
123
124     if Options.options.with_system_mitkrb5:
125         conf.PROCESS_SEPARATE_RULE('system_mitkrb5')
126     if not (Options.options.without_ad_dc or Options.options.with_system_mitkrb5):
127         conf.DEFINE('AD_DC_BUILD_IS_ENABLED', 1)
128     # Only process heimdal_build for non-MIT KRB5 builds
129     # When MIT KRB5 checks are done as above, conf.env.KRB5_VENDOR will be set
130     # to the lowcased output of 'krb5-config --vendor'.
131     # If it is not set or the output is 'heimdal', we are dealing with
132     # system-provided or embedded Heimdal build
133     if conf.CONFIG_GET('KRB5_VENDOR') in (None, 'heimdal'):
134         conf.RECURSE('source4/heimdal_build')
135     conf.RECURSE('source4/lib/tls')
136     conf.RECURSE('source4/ntvfs/sysdep')
137     conf.RECURSE('lib/util')
138     conf.RECURSE('lib/ccan')
139     conf.RECURSE('lib/ntdb')
140     conf.RECURSE('lib/zlib')
141     conf.RECURSE('lib/util/charset')
142     conf.RECURSE('source4/auth')
143     conf.RECURSE('lib/nss_wrapper')
144     conf.RECURSE('nsswitch')
145     conf.RECURSE('lib/socket_wrapper')
146     conf.RECURSE('lib/uid_wrapper')
147     conf.RECURSE('lib/popt')
148     conf.RECURSE('lib/iniparser/src')
149     conf.RECURSE('lib/subunit/c')
150     conf.RECURSE('libcli/smbreadline')
151     conf.RECURSE('lib/crypto')
152     conf.RECURSE('pidl')
153     conf.RECURSE('selftest')
154     conf.RECURSE('source3')
155
156     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
157
158     # gentoo always adds this. We want our normal build to be as
159     # strict as the strictest OS we support, so adding this here
160     # allows us to find problems on our development hosts faster.
161     # It also results in faster load time.
162
163     if not sys.platform.startswith("openbsd"):
164         conf.env.asneeded_ldflags = conf.ADD_LDFLAGS('-Wl,--as-needed', testflags=True)
165
166     if not conf.CHECK_NEED_LC("-lc not needed"):
167         conf.ADD_LDFLAGS('-lc', testflags=False)
168
169     # we don't want PYTHONDIR in config.h, as otherwise changing
170     # --prefix causes a complete rebuild
171     del(conf.env.defines['PYTHONDIR'])
172     del(conf.env.defines['PYTHONARCHDIR'])
173
174     if not conf.CHECK_CODE('#include "tests/summary.c"',
175                            define='SUMMARY_PASSES',
176                            addmain=False,
177                            msg='Checking configure summary'):
178         raise Utils.WafError('configure summary failed')
179
180     if Options.options.enable_pie != False:
181         if Options.options.enable_pie == True:
182                 need_pie = True
183         else:
184                 # not specified, only build PIEs if supported by compiler
185                 need_pie = False
186         if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie,
187                          msg="Checking compiler for PIE support"):
188                 conf.env['ENABLE_PIE'] = True
189
190     if Options.options.enable_relro != False:
191         if Options.options.enable_relro == True:
192             need_relro = True
193         else:
194             # not specified, only build RELROs if supported by compiler
195             need_relro = False
196         if conf.check_cc(cflags='', ldflags='-Wl,-z,relro,-z,now', mandatory=need_relro,
197                          msg="Checking compiler for full RELRO support"):
198             conf.env['ENABLE_RELRO'] = True
199
200     if Options.options.enable_systemd != False:
201         conf.check_cfg(package='libsystemd-daemon', args='--cflags --libs',
202                        msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")
203         conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
204         conf.CHECK_LIB('systemd-daemon', shlib=True)
205
206     if conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H'):
207         conf.DEFINE('HAVE_SYSTEMD', '1')
208         conf.env['ENABLE_SYSTEMD'] = True
209     else:
210         conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
211         conf.undefine('HAVE_SYSTEMD')
212
213     conf.SAMBA_CONFIG_H('include/config.h')
214
215 def etags(ctx):
216     '''build TAGS file using etags'''
217     import Utils
218     source_root = os.path.dirname(Utils.g_module.root_path)
219     cmd = 'rm -f %s/TAGS && (find %s -name "*.[ch]" | egrep -v \.inst\. | xargs -n 100 etags -a)' % (source_root, source_root)
220     print("Running: %s" % cmd)
221     status = os.system(cmd)
222     if os.WEXITSTATUS(status):
223         raise Utils.WafError('etags failed')
224
225 def ctags(ctx):
226     "build 'tags' file using ctags"
227     import Utils
228     source_root = os.path.dirname(Utils.g_module.root_path)
229     cmd = 'ctags --python-kinds=-i $(find %s -name "*.[ch]" | grep -v "*_proto\.h" | egrep -v \.inst\.) $(find %s -name "*.py")' % (source_root, source_root)
230     print("Running: %s" % cmd)
231     status = os.system(cmd)
232     if os.WEXITSTATUS(status):
233         raise Utils.WafError('ctags failed')
234
235 # putting this here enabled build in the list
236 # of commands in --help
237 def build(bld):
238     '''build all targets'''
239     samba_version.load_version(env=bld.env, is_install=bld.is_install)
240     pass
241
242
243 def pydoctor(ctx):
244     '''build python apidocs'''
245     bp = os.path.abspath('bin/python')
246     mpaths = {}
247     for m in ['talloc', 'tdb', 'ldb', 'ntdb']:
248         f = os.popen("PYTHONPATH=%s python -c 'import %s; print %s.__file__'" % (bp, m, m), 'r')
249         try:
250             mpaths[m] = f.read().strip()
251         finally:
252             f.close()
253     cmd='PYTHONPATH=%s pydoctor --introspect-c-modules --project-name=Samba --project-url=http://www.samba.org --make-html --docformat=restructuredtext --add-package bin/python/samba --add-module %s --add-module %s --add-module %s' % (
254         bp, mpaths['tdb'], mpaths['ldb'], mpaths['talloc'], mpaths['ntdb'])
255     print("Running: %s" % cmd)
256     status = os.system(cmd)
257     if os.WEXITSTATUS(status):
258         raise Utils.WafError('pydoctor failed')
259
260
261 def pep8(ctx):
262     '''run pep8 validator'''
263     cmd='PYTHONPATH=bin/python pep8 -r bin/python/samba'
264     print("Running: %s" % cmd)
265     status = os.system(cmd)
266     if os.WEXITSTATUS(status):
267         raise Utils.WafError('pep8 failed')
268
269
270 def wafdocs(ctx):
271     '''build wafsamba apidocs'''
272     from samba_utils import recursive_dirlist
273     os.system('pwd')
274     list = recursive_dirlist('../buildtools/wafsamba', '.', pattern='*.py')
275
276     cmd='PYTHONPATH=bin/python pydoctor --project-name=wafsamba --project-url=http://www.samba.org --make-html --docformat=restructuredtext'
277     print(list)
278     for f in list:
279         cmd += ' --add-module %s' % f
280     print("Running: %s" % cmd)
281     status = os.system(cmd)
282     if os.WEXITSTATUS(status):
283         raise Utils.WafError('wafdocs failed')
284
285
286 def dist():
287     '''makes a tarball for distribution'''
288     sambaversion = samba_version.load_version(env=None)
289
290     os.system(srcdir + "/release-scripts/build-manpages-nogit")
291     samba_dist.DIST_FILES('bin/docs:docs', extend=True)
292
293     if sambaversion.IS_SNAPSHOT:
294         # write .distversion file and add to tar
295         if not os.path.isdir(blddir):
296             os.makedirs(blddir)
297         distversionf = tempfile.NamedTemporaryFile(mode='w', prefix='.distversion',dir=blddir)
298         for field in sambaversion.vcs_fields:
299             distveroption = field + '=' + str(sambaversion.vcs_fields[field])
300             distversionf.write(distveroption + '\n')
301         distversionf.flush()
302         samba_dist.DIST_FILES('%s:.distversion' % distversionf.name, extend=True)
303
304         samba_dist.dist()
305         distversionf.close()
306     else:
307         samba_dist.dist()
308
309
310 def distcheck():
311     '''test that distribution tarball builds and installs'''
312     samba_version.load_version(env=None)
313     import Scripting
314     d = Scripting.distcheck
315     d()
316
317 def wildcard_cmd(cmd):
318     '''called on a unknown command'''
319     from samba_wildcard import run_named_build_task
320     run_named_build_task(cmd)
321
322 def main():
323     from samba_wildcard import wildcard_main
324     wildcard_main(wildcard_cmd)
325 Scripting.main = main
326
327 def reconfigure(ctx):
328     '''reconfigure if config scripts have changed'''
329     import samba_utils
330     samba_utils.reconfigure(ctx)