ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[samba4-gss.git] / buildtools / wafsamba / wafsamba.py
blob250da072c508987d1e23c50fa2eab8a46b49f5bd
1 # a waf tool to add autoconf-like macros to the configure section
2 # and for SAMBA_ macros for building libraries, binaries etc
4 import os, sys, re, shutil, fnmatch
5 from waflib import Build, Options, Task, Utils, TaskGen, Logs, Context, Errors
6 from waflib.Configure import conf
7 from waflib.Logs import debug
8 from samba_utils import SUBST_VARS_RECURSIVE
9 TaskGen.task_gen.apply_verif = Utils.nada
11 # bring in the other samba modules
12 from samba_utils import *
13 from samba_utils import symlink
14 from samba_version import *
15 from samba_autoconf import *
16 from samba_patterns import *
17 from samba_pidl import *
18 from samba_autoproto import *
19 from samba_python import *
20 from samba_perl import *
21 from samba_deps import *
22 from samba_bundled import *
23 from samba_third_party import *
24 import samba_cross
25 import samba_install
26 import samba_conftests
27 import samba_abi
28 import samba_headers
29 import generic_cc
30 import samba_dist
31 import samba_wildcard
32 import symbols
33 import pkgconfig
34 import configure_file
35 import samba_waf18
36 import samba_bundled
38 LIB_PATH="shared"
40 os.environ['PYTHONUNBUFFERED'] = '1'
42 if Context.HEXVERSION not in (0x2001a00,):
43 Logs.error('''
44 Please use the version of waf that comes with Samba, not
45 a system installed version. See http://wiki.samba.org/index.php/Waf
46 for details.
48 Alternatively, please run ./configure and make as usual. That will
49 call the right version of waf.''')
50 sys.exit(1)
52 @conf
53 def SAMBA_BUILD_ENV(conf):
54 '''create the samba build environment'''
55 conf.env.BUILD_DIRECTORY = conf.bldnode.abspath()
56 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, LIB_PATH))
57 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, LIB_PATH, "private"))
58 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, "modules"))
59 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, "plugins"))
60 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, 'python/samba/dcerpc'))
61 # this allows all of the bin/shared and bin/python targets
62 # to be expressed in terms of build directory paths
63 mkdir_p(os.path.join(conf.env.BUILD_DIRECTORY, 'default'))
64 for (source, target) in [('shared', 'shared'), ('modules', 'modules'), ('plugins', 'plugins'), ('python', 'python')]:
65 link_target = os.path.join(conf.env.BUILD_DIRECTORY, 'default/' + target)
66 if not os.path.lexists(link_target):
67 symlink('../' + source, link_target)
69 # get perl to put the blib files in the build directory
70 blib_bld = os.path.join(conf.env.BUILD_DIRECTORY, 'default/pidl/blib')
71 blib_src = os.path.join(conf.srcnode.abspath(), 'pidl/blib')
72 mkdir_p(blib_bld + '/man1')
73 mkdir_p(blib_bld + '/man3')
74 if os.path.islink(blib_src):
75 os.unlink(blib_src)
76 elif os.path.exists(blib_src):
77 shutil.rmtree(blib_src)
80 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
81 '''add an init_function to the list for a subsystem'''
82 if init_function is None:
83 return
84 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
85 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
86 if subsystem not in cache:
87 cache[subsystem] = []
88 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
89 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
92 def generate_empty_file(task):
93 task.outputs[0].write('')
94 return 0
96 #################################################################
97 def SAMBA_LIBRARY(bld, libname, source,
98 deps='',
99 public_deps='',
100 includes='',
101 public_headers=None,
102 public_headers_install=True,
103 private_headers=None,
104 header_path=None,
105 pc_files=None,
106 vnum=None,
107 soname=None,
108 cflags='',
109 cflags_end=None,
110 ldflags='',
111 external_library=False,
112 realname=None,
113 autoproto=None,
114 autoproto_extra_source='',
115 group='main',
116 depends_on='',
117 local_include=True,
118 global_include=True,
119 vars=None,
120 subdir=None,
121 install_path=None,
122 install=True,
123 pyembed=False,
124 pyext=False,
125 target_type='LIBRARY',
126 bundled_name=None,
127 link_name=None,
128 abi_directory=None,
129 abi_match=None,
130 orig_vscript_map=None,
131 hide_symbols=False,
132 manpages=None,
133 private_library=False,
134 grouping_library=False,
135 require_builtin_deps=False,
136 provide_builtin_linking=False,
137 builtin_cflags='',
138 force_unversioned=False,
139 allow_undefined_symbols=False,
140 allow_warnings=False,
141 enabled=True):
142 '''define a Samba library'''
144 # We support:
145 # - LIBRARY: this can be used to link via -llibname
146 # - MODULE: this is module from SAMBA_MODULE()
147 # - PLUGIN: this is plugin for external consumers to be
148 # loaded via dlopen()
149 # - PYTHON: a python C binding library
151 if target_type not in ['LIBRARY', 'MODULE', 'PLUGIN', 'PYTHON']:
152 raise Errors.WafError("target_type[%s] not supported in SAMBA_LIBRARY('%s')" %
153 (target_type, libname))
155 if require_builtin_deps:
156 # For now we only support require_builtin_deps only for libraries, plugins
157 if target_type not in ['LIBRARY', 'PLUGIN']:
158 raise Errors.WafError("target_type[%s] not supported SAMBA_LIBRARY('%s', require_builtin_deps=True)" %
159 (target_type, libname))
161 if private_library and public_headers:
162 raise Errors.WafError("private library '%s' must not have public header files" %
163 libname)
165 if orig_vscript_map and not private_library:
166 raise Errors.WafError("public library '%s' must not have orig_vscript_map" %
167 libname)
169 if orig_vscript_map and abi_directory:
170 raise Errors.WafError("private library '%s' with orig_vscript_map must not have abi_directory" %
171 libname)
172 if orig_vscript_map and abi_match:
173 raise Errors.WafError("private library '%s' with orig_vscript_map must not have abi_match" %
174 libname)
176 if force_unversioned and private_library:
177 raise Errors.WafError("private library '%s': can't have force_unversioned=True" %
178 libname)
180 if force_unversioned and realname is None:
181 raise Errors.WafError("library '%s': force_unversioned=True needs realname too" %
182 libname)
184 if LIB_MUST_BE_PRIVATE(bld, libname) and target_type not in ['PLUGIN']:
185 private_library = True
186 public_headers_install = False
188 if force_unversioned:
189 private_library = False
191 if not enabled:
192 SET_TARGET_TYPE(bld, libname, 'DISABLED')
193 return
195 source = bld.EXPAND_VARIABLES(source, vars=vars)
196 if subdir:
197 source = bld.SUBDIR(subdir, source)
199 # remember empty libraries, so we can strip the dependencies
200 if ((source == '') or (source == [])):
201 if deps == '' and public_deps == '':
202 SET_TARGET_TYPE(bld, libname, 'EMPTY')
203 return
204 empty_c = libname + '.empty.c'
205 bld.SAMBA_GENERATOR('%s_empty_c' % libname,
206 rule=generate_empty_file,
207 target=empty_c)
208 source=empty_c
210 samba_deps = deps + ' ' + public_deps
211 samba_deps = TO_LIST(samba_deps)
213 if BUILTIN_LIBRARY(bld, libname):
214 builtin_target = libname + '.builtin.objlist'
215 builtin_cflags_end = '-D_PUBLIC_=_PRIVATE_'
216 empty_target = libname
217 obj_target = None
218 else:
219 if provide_builtin_linking:
220 builtin_target = libname + '.builtin.objlist'
221 builtin_cflags_end = '-D_PUBLIC_=_PRIVATE_'
222 else:
223 builtin_target = None
224 empty_target = None
225 obj_target = libname + '.objlist'
226 if require_builtin_deps:
227 # hide the builtin deps from the callers
228 samba_deps = TO_LIST('')
229 dep_target = obj_target
231 if group == 'libraries':
232 subsystem_group = 'main'
233 else:
234 subsystem_group = group
236 # first create a target for building the object files for this library
237 # by separating in this way, we avoid recompiling the C files
238 # separately for the install library and the build library
239 if builtin_target:
240 __t = __SAMBA_SUBSYSTEM_BUILTIN(bld, builtin_target, source,
241 deps=deps,
242 public_deps=public_deps,
243 includes=includes,
244 header_path=header_path,
245 builtin_cflags=builtin_cflags,
246 builtin_cflags_end=builtin_cflags_end,
247 group=group,
248 depends_on=depends_on,
249 local_include=local_include,
250 global_include=global_include,
251 allow_warnings=allow_warnings)
252 builtin_subsystem = __t
253 else:
254 builtin_subsystem = None
255 if obj_target:
256 bld.SAMBA_SUBSYSTEM(obj_target,
257 source = source,
258 deps = deps,
259 public_deps = public_deps,
260 includes = includes,
261 public_headers = public_headers,
262 public_headers_install = public_headers_install,
263 private_headers= private_headers,
264 header_path = header_path,
265 cflags = cflags,
266 cflags_end = cflags_end,
267 group = subsystem_group,
268 autoproto = autoproto,
269 autoproto_extra_source=autoproto_extra_source,
270 depends_on = depends_on,
271 hide_symbols = hide_symbols,
272 allow_warnings = allow_warnings,
273 pyembed = pyembed,
274 pyext = pyext,
275 local_include = local_include,
276 __require_builtin_deps=require_builtin_deps,
277 global_include = global_include)
278 else:
279 et = bld.SAMBA_SUBSYSTEM(empty_target,
280 source=[],
281 __force_empty=True,
282 __require_builtin_deps=True)
283 et.samba_builtin_subsystem = builtin_subsystem
285 if BUILTIN_LIBRARY(bld, libname):
286 return
288 if not SET_TARGET_TYPE(bld, libname, target_type):
289 return
291 # the library itself will depend on that object target
292 samba_deps.append(dep_target)
294 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
295 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
297 # we don't want any public libraries without version numbers
298 if (not private_library and target_type != 'PYTHON' and not realname):
299 if vnum is None and soname is None:
300 raise Errors.WafError("public library '%s' must have a vnum" %
301 libname)
302 if pc_files is None:
303 raise Errors.WafError("public library '%s' must have pkg-config file" %
304 libname)
305 if public_headers is None:
306 raise Errors.WafError("public library '%s' must have header files" %
307 libname)
309 abi_vnum = vnum
311 if bundled_name is not None:
312 pass
313 elif target_type == 'PYTHON' or realname or not private_library:
314 bundled_name = libname.replace('_', '-')
315 else:
316 assert (private_library is True and realname is None)
317 bundled_name = PRIVATE_NAME(bld, libname.replace('_', '-'))
318 vnum = None
320 ldflags = TO_LIST(ldflags)
321 if bld.env['ENABLE_RELRO'] is True:
322 ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
324 features = 'c cshlib symlink_lib install_lib'
325 if pyext:
326 features += ' pyext'
327 if pyembed:
328 features += ' pyembed'
330 if abi_directory:
331 features += ' abi_check'
333 if pyembed and bld.env['PYTHON_SO_ABI_FLAG']:
334 # For ABI checking, we don't care about the Python version.
335 # Remove the Python ABI tag (e.g. ".cpython-35m")
336 abi_flag = bld.env['PYTHON_SO_ABI_FLAG']
337 replacement = ''
338 version_libname = libname.replace(abi_flag, replacement)
339 else:
340 version_libname = libname
342 vscript = None
343 if bld.env.HAVE_LD_VERSION_SCRIPT:
344 if force_unversioned:
345 version = None
346 elif private_library:
347 version = bld.env.PRIVATE_VERSION
348 elif vnum:
349 version = "%s_%s" % (libname, vnum)
350 else:
351 version = None
352 if version:
353 vscript = "%s.vscript" % libname
354 if orig_vscript_map:
355 bld.VSCRIPT_MAP_PRIVATE(version_libname, orig_vscript_map, version, vscript)
356 else:
357 bld.ABI_VSCRIPT(version_libname, abi_directory, version, vscript,
358 abi_match, private_library)
359 fullname = apply_pattern(bundled_name, bld.env.cshlib_PATTERN)
360 fullpath = bld.path.find_or_declare(fullname)
361 vscriptpath = bld.path.find_or_declare(vscript)
362 if not fullpath:
363 raise Errors.WafError("unable to find fullpath for %s" % fullname)
364 if not vscriptpath:
365 raise Errors.WafError("unable to find vscript path for %s" % vscript)
366 bld.add_manual_dependency(fullpath, vscriptpath)
367 if bld.is_install:
368 # also make the .inst file depend on the vscript
369 instname = apply_pattern(bundled_name + '.inst', bld.env.cshlib_PATTERN)
370 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
371 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
373 bld.SET_BUILD_GROUP(group)
374 t = bld(
375 features = features,
376 source = [],
377 target = bundled_name,
378 depends_on = depends_on,
379 samba_ldflags = ldflags,
380 samba_deps = samba_deps,
381 samba_includes = includes,
382 version_script = vscript,
383 version_libname = version_libname,
384 local_include = local_include,
385 global_include = global_include,
386 vnum = vnum,
387 soname = soname,
388 install_path = None,
389 samba_inst_path = install_path,
390 name = libname,
391 samba_realname = realname,
392 samba_install = install,
393 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
394 abi_match = abi_match,
395 abi_vnum = abi_vnum,
396 private_library = private_library,
397 grouping_library=grouping_library,
398 allow_undefined_symbols=allow_undefined_symbols,
399 samba_require_builtin_deps=False,
400 samba_builtin_subsystem=builtin_subsystem,
403 if realname and not link_name:
404 link_name = 'shared/%s' % realname
406 if link_name:
407 if 'waflib.extras.compat15' in sys.modules:
408 link_name = 'default/' + link_name
409 t.link_name = link_name
411 if pc_files is not None and not private_library:
412 if pyembed:
413 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum, extra_name=bld.env['PYTHON_SO_ABI_FLAG'])
414 else:
415 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
417 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
418 bld.env['XSLTPROC_MANPAGES']):
419 bld.MANPAGES(manpages, install)
422 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
425 #################################################################
426 def SAMBA_BINARY(bld, binname, source,
427 deps='',
428 includes='',
429 public_headers=None,
430 private_headers=None,
431 header_path=None,
432 modules=None,
433 ldflags=None,
434 cflags='',
435 cflags_end=None,
436 autoproto=None,
437 use_hostcc=False,
438 use_global_deps=True,
439 compiler=None,
440 group='main',
441 manpages=None,
442 local_include=True,
443 global_include=True,
444 subsystem_name=None,
445 allow_warnings=False,
446 pyembed=False,
447 vars=None,
448 subdir=None,
449 install=True,
450 install_path=None,
451 enabled=True,
452 fuzzer=False,
453 for_selftest=False):
454 '''define a Samba binary'''
456 if for_selftest:
457 install=False
458 if not bld.CONFIG_GET('ENABLE_SELFTEST'):
459 enabled=False
461 if not enabled:
462 SET_TARGET_TYPE(bld, binname, 'DISABLED')
463 return
465 # Fuzzing builds do not build normal binaries
466 # however we must build asn1compile etc
468 if not use_hostcc and bld.env.enable_fuzzing != fuzzer:
469 SET_TARGET_TYPE(bld, binname, 'DISABLED')
470 return
472 if fuzzer:
473 install = False
474 if ldflags is None:
475 ldflags = bld.env['FUZZ_TARGET_LDFLAGS']
477 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
478 return
480 features = 'c cprogram symlink_bin install_bin'
481 if pyembed:
482 features += ' pyembed'
484 obj_target = binname + '.objlist'
486 source = bld.EXPAND_VARIABLES(source, vars=vars)
487 if subdir:
488 source = bld.SUBDIR(subdir, source)
489 source = unique_list(TO_LIST(source))
491 if group == 'binaries':
492 subsystem_group = 'main'
493 elif group == 'build_compilers':
494 subsystem_group = 'compiler_libraries'
495 else:
496 subsystem_group = group
498 # only specify PIE flags for binaries
499 pie_cflags = TO_LIST(cflags)
500 pie_ldflags = TO_LIST(ldflags)
501 if bld.env['ENABLE_PIE'] is True:
502 pie_cflags.extend(TO_LIST('-fPIE'))
503 pie_ldflags.extend(TO_LIST('-pie'))
504 if bld.env['ENABLE_RELRO'] is True:
505 pie_ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
507 # first create a target for building the object files for this binary
508 # by separating in this way, we avoid recompiling the C files
509 # separately for the install binary and the build binary
510 bld.SAMBA_SUBSYSTEM(obj_target,
511 source = source,
512 deps = deps,
513 includes = includes,
514 cflags = pie_cflags,
515 cflags_end = cflags_end,
516 group = subsystem_group,
517 autoproto = autoproto,
518 subsystem_name = subsystem_name,
519 local_include = local_include,
520 global_include = global_include,
521 use_hostcc = use_hostcc,
522 pyext = pyembed,
523 allow_warnings = allow_warnings,
524 use_global_deps= use_global_deps)
526 bld.SET_BUILD_GROUP(group)
528 # the binary itself will depend on that object target
529 deps = TO_LIST(deps)
530 deps.append(obj_target)
532 t = bld(
533 features = features,
534 source = [],
535 target = binname,
536 samba_deps = deps,
537 samba_includes = includes,
538 local_include = local_include,
539 global_include = global_include,
540 samba_modules = modules,
541 top = True,
542 samba_subsystem= subsystem_name,
543 install_path = None,
544 samba_inst_path= install_path,
545 samba_install = install,
546 samba_ldflags = pie_ldflags
549 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
550 bld.MANPAGES(manpages, install)
552 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
555 #################################################################
556 def SAMBA_MODULE(bld, modname, source,
557 deps='',
558 includes='',
559 subsystem=None,
560 init_function=None,
561 module_init_name='samba_init_module',
562 autoproto=None,
563 autoproto_extra_source='',
564 cflags='',
565 cflags_end=None,
566 internal_module=True,
567 local_include=True,
568 global_include=True,
569 vars=None,
570 subdir=None,
571 enabled=True,
572 pyembed=False,
573 manpages=None,
574 allow_undefined_symbols=False,
575 allow_warnings=False,
576 install=True):
577 '''define a Samba module.'''
579 bld.ASSERT(subsystem, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname)
581 source = bld.EXPAND_VARIABLES(source, vars=vars)
582 if subdir:
583 source = bld.SUBDIR(subdir, source)
585 if internal_module or BUILTIN_LIBRARY(bld, modname):
586 # Do not create modules for disabled subsystems
587 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
588 return
589 bld.SAMBA_SUBSYSTEM(modname, source,
590 deps=deps,
591 includes=includes,
592 autoproto=autoproto,
593 autoproto_extra_source=autoproto_extra_source,
594 cflags=cflags,
595 cflags_end=cflags_end,
596 local_include=local_include,
597 global_include=global_include,
598 allow_warnings=allow_warnings,
599 enabled=enabled)
601 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
602 return
604 if not enabled:
605 SET_TARGET_TYPE(bld, modname, 'DISABLED')
606 return
608 # Do not create modules for disabled subsystems
609 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
610 return
612 realname = modname
613 deps += ' ' + subsystem
614 while realname.startswith("lib"+subsystem+"_"):
615 realname = realname[len("lib"+subsystem+"_"):]
616 while realname.startswith(subsystem+"_"):
617 realname = realname[len(subsystem+"_"):]
619 build_name = "%s_module_%s" % (subsystem, realname)
621 realname = bld.make_libname(realname)
622 while realname.startswith("lib"):
623 realname = realname[len("lib"):]
625 build_link_name = "modules/%s/%s" % (subsystem, realname)
627 if f'{subsystem}_modules_install_dir' in bld.env:
628 install_path = bld.env[f'{subsystem}_modules_install_dir']
629 else:
630 install_path = "${MODULESDIR}/%s" % subsystem
632 if init_function:
633 cflags += " -D%s=%s" % (init_function, module_init_name)
635 bld.SAMBA_LIBRARY(modname,
636 source,
637 deps=deps,
638 includes=includes,
639 cflags=cflags,
640 cflags_end=cflags_end,
641 realname = realname,
642 autoproto = autoproto,
643 local_include=local_include,
644 global_include=global_include,
645 vars=vars,
646 bundled_name=build_name,
647 link_name=build_link_name,
648 install_path=install_path,
649 pyembed=pyembed,
650 manpages=manpages,
651 allow_undefined_symbols=allow_undefined_symbols,
652 allow_warnings=allow_warnings,
653 private_library=True,
654 install=install
658 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
660 #################################################################
661 def SAMBA_PLUGIN(bld, pluginname, source,
662 deps='',
663 includes='',
664 vnum=None,
665 soname=None,
666 cflags='',
667 ldflags='',
668 local_include=True,
669 global_include=True,
670 vars=None,
671 subdir=None,
672 realname=None,
673 autoproto=None,
674 autoproto_extra_source='',
675 install_path=None,
676 install=True,
677 manpages=None,
678 require_builtin_deps=True,
679 allow_undefined_symbols=False,
680 enabled=True):
681 '''define an external plugin.'''
683 bld.ASSERT(realname, "You must specify a realname for SAMBA_PLUGIN(%s)" % pluginname)
685 source = bld.EXPAND_VARIABLES(source, vars=vars)
686 if subdir:
687 source = bld.SUBDIR(subdir, source)
689 build_name = "_plugin_%s" % (pluginname)
690 build_link_name = "plugins/%s" % (realname)
692 bld.SAMBA_LIBRARY(pluginname,
693 source,
694 bundled_name=build_name,
695 link_name=build_link_name,
696 target_type='PLUGIN',
697 deps=deps,
698 includes=includes,
699 vnum=vnum,
700 soname=soname,
701 cflags=cflags,
702 ldflags=ldflags,
703 realname=realname,
704 autoproto=autoproto,
705 autoproto_extra_source=autoproto_extra_source,
706 local_include=local_include,
707 global_include=global_include,
708 vars=vars,
709 group='main',
710 install_path=install_path,
711 install=install,
712 manpages=manpages,
713 require_builtin_deps=require_builtin_deps,
714 builtin_cflags=cflags,
715 hide_symbols=True,
716 public_headers=[],
717 public_headers_install=False,
718 pc_files=[],
719 allow_undefined_symbols=allow_undefined_symbols,
720 allow_warnings=False,
721 enabled=enabled)
722 Build.BuildContext.SAMBA_PLUGIN = SAMBA_PLUGIN
724 def __SAMBA_SUBSYSTEM_BUILTIN(bld, builtin_target, source,
725 deps='',
726 public_deps='',
727 includes='',
728 public_headers=None,
729 public_headers_install=True,
730 private_headers=None,
731 header_path=None,
732 builtin_cflags='',
733 builtin_cflags_end=None,
734 group='main',
735 autoproto=None,
736 autoproto_extra_source='',
737 depends_on='',
738 local_include=True,
739 global_include=True,
740 allow_warnings=False):
742 bld.ASSERT(builtin_target.endswith('.builtin.objlist'),
743 "builtin_target[%s] does not end with '.builtin.objlist'" %
744 (builtin_target))
745 return bld.SAMBA_SUBSYSTEM(builtin_target, source,
746 deps=deps,
747 public_deps=public_deps,
748 includes=includes,
749 public_headers=public_headers,
750 public_headers_install=public_headers_install,
751 private_headers=private_headers,
752 header_path=header_path,
753 cflags=builtin_cflags,
754 cflags_end=builtin_cflags_end,
755 hide_symbols=True,
756 group=group,
757 target_type='BUILTIN',
758 autoproto=autoproto,
759 autoproto_extra_source=autoproto_extra_source,
760 depends_on=depends_on,
761 local_include=local_include,
762 global_include=global_include,
763 allow_warnings=allow_warnings,
764 __require_builtin_deps=True)
766 #################################################################
767 def SAMBA_SUBSYSTEM(bld, modname, source,
768 deps='',
769 public_deps='',
770 __force_empty=False,
771 includes='',
772 public_headers=None,
773 public_headers_install=True,
774 private_headers=None,
775 header_path=None,
776 cflags='',
777 cflags_end=None,
778 group='main',
779 target_type='SUBSYSTEM',
780 init_function_sentinel=None,
781 autoproto=None,
782 autoproto_extra_source='',
783 depends_on='',
784 local_include=True,
785 local_include_first=True,
786 global_include=True,
787 subsystem_name=None,
788 enabled=True,
789 use_hostcc=False,
790 use_global_deps=True,
791 vars=None,
792 subdir=None,
793 hide_symbols=False,
794 __require_builtin_deps=False,
795 provide_builtin_linking=False,
796 builtin_cflags='',
797 allow_warnings=False,
798 pyext=False,
799 pyembed=False):
800 '''define a Samba subsystem'''
802 # We support:
803 # - SUBSYSTEM: a normal subsystem from SAMBA_SUBSYSTEM()
804 # - BUILTIN: a hidden subsystem from __SAMBA_SUBSYSTEM_BUILTIN()
805 if target_type not in ['SUBSYSTEM', 'BUILTIN']:
806 raise Errors.WafError("target_type[%s] not supported in SAMBA_SUBSYSTEM('%s')" %
807 (target_type, modname))
809 if not enabled:
810 SET_TARGET_TYPE(bld, modname, 'DISABLED')
811 return
813 # remember empty subsystems, so we can strip the dependencies
814 if ((source == '') or (source == [])):
815 if not __force_empty and deps == '' and public_deps == '':
816 SET_TARGET_TYPE(bld, modname, 'EMPTY')
817 return
818 empty_c = modname + '.empty.c'
819 bld.SAMBA_GENERATOR('%s_empty_c' % modname,
820 rule=generate_empty_file,
821 target=empty_c)
822 source=empty_c
824 if not SET_TARGET_TYPE(bld, modname, target_type):
825 return
827 source = bld.EXPAND_VARIABLES(source, vars=vars)
828 if subdir:
829 source = bld.SUBDIR(subdir, source)
830 source = unique_list(TO_LIST(source))
832 deps += ' ' + public_deps
834 bld.SET_BUILD_GROUP(group)
836 features = 'c'
837 if pyext:
838 features += ' pyext'
839 if pyembed:
840 features += ' pyembed'
842 t = bld(
843 features = features,
844 source = source,
845 target = modname,
846 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags,
847 allow_warnings=allow_warnings,
848 use_hostcc=use_hostcc,
849 hide_symbols=hide_symbols),
850 depends_on = depends_on,
851 samba_deps = TO_LIST(deps),
852 samba_includes = includes,
853 local_include = local_include,
854 local_include_first = local_include_first,
855 global_include = global_include,
856 samba_subsystem= subsystem_name,
857 samba_use_hostcc = use_hostcc,
858 samba_use_global_deps = use_global_deps,
859 samba_require_builtin_deps = __require_builtin_deps,
860 samba_builtin_subsystem = None,
863 if cflags_end is not None:
864 t.samba_cflags.extend(TO_LIST(cflags_end))
866 if autoproto is not None:
867 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
868 if public_headers is not None:
869 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
870 public_headers_install=public_headers_install)
872 if provide_builtin_linking:
874 if use_hostcc:
875 raise Errors.WafError("subsystem[%s] provide_builtin_linking=True " +
876 "not allowed with use_hostcc=True" %
877 modname)
879 if pyext or pyembed:
880 raise Errors.WafError("subsystem[%s] provide_builtin_linking=True " +
881 "not allowed with pyext=True nor pyembed=True" %
882 modname)
884 if __require_builtin_deps:
885 raise Errors.WafError("subsystem[%s] provide_builtin_linking=True " +
886 "not allowed with __require_builtin_deps=True" %
887 modname)
889 builtin_target = modname + '.builtin.objlist'
890 tbuiltin = __SAMBA_SUBSYSTEM_BUILTIN(bld, builtin_target, source,
891 deps=deps,
892 public_deps=public_deps,
893 includes=includes,
894 header_path=header_path,
895 builtin_cflags=builtin_cflags,
896 builtin_cflags_end='-D_PUBLIC_=_PRIVATE_',
897 group=group,
898 depends_on=depends_on,
899 local_include=local_include,
900 global_include=global_include,
901 allow_warnings=allow_warnings)
902 t.samba_builtin_subsystem = tbuiltin
904 return t
907 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
910 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
911 group='generators', enabled=True,
912 public_headers=None,
913 public_headers_install=True,
914 private_headers=None,
915 header_path=None,
916 vars=None,
917 dep_vars=None,
918 always=False):
919 '''A generic source generator target'''
921 if dep_vars is None:
922 dep_vars = []
923 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
924 return
926 if not enabled:
927 return
929 dep_vars = TO_LIST(dep_vars)
930 dep_vars.append('ruledeps')
931 dep_vars.append('SAMBA_GENERATOR_VARS')
933 shell=isinstance(rule, str)
935 # This ensures that if the command (executed in the shell) fails
936 # (returns non-zero), the build fails
937 if shell:
938 rule = "set -e; " + rule
940 bld.SET_BUILD_GROUP(group)
941 t = bld(
942 rule=rule,
943 source=bld.EXPAND_VARIABLES(source, vars=vars),
944 shell=shell,
945 target=target,
946 update_outputs=True,
947 before='c',
948 ext_out='.c',
949 samba_type='GENERATOR',
950 dep_vars = dep_vars,
951 name=name)
953 if vars is None:
954 vars = {}
955 t.env.SAMBA_GENERATOR_VARS = vars
957 if always:
958 t.always = True
960 if public_headers is not None:
961 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
962 public_headers_install=public_headers_install)
963 return t
964 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
968 @Utils.run_once
969 def SETUP_BUILD_GROUPS(bld):
970 '''setup build groups used to ensure that the different build
971 phases happen consecutively'''
972 bld.p_ln = bld.srcnode # we do want to see all targets!
973 bld.env['USING_BUILD_GROUPS'] = True
974 bld.add_group('setup')
975 bld.add_group('generators')
976 bld.add_group('hostcc_base_build_source')
977 bld.add_group('hostcc_base_build_main')
978 bld.add_group('hostcc_build_source')
979 bld.add_group('hostcc_build_main')
980 bld.add_group('vscripts')
981 bld.add_group('base_libraries')
982 bld.add_group('build_source')
983 bld.add_group('prototypes')
984 bld.add_group('headers')
985 bld.add_group('main')
986 bld.add_group('symbolcheck')
987 bld.add_group('syslibcheck')
988 bld.add_group('final')
989 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
992 def SET_BUILD_GROUP(bld, group):
993 '''set the current build group'''
994 if not 'USING_BUILD_GROUPS' in bld.env:
995 return
996 bld.set_group(group)
997 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
1001 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
1002 '''used to copy scripts from the source tree into the build directory
1003 for use by selftest'''
1005 source = bld.path.ant_glob(pattern, flat=True)
1007 bld.SET_BUILD_GROUP('build_source')
1008 for s in TO_LIST(source):
1009 iname = s
1010 if installname is not None:
1011 iname = installname
1012 target = os.path.join(installdir, iname)
1013 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
1014 mkdir_p(tgtdir)
1015 link_src = os.path.normpath(os.path.join(bld.path.abspath(), s))
1016 link_dst = os.path.join(tgtdir, os.path.basename(iname))
1017 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
1018 continue
1019 if os.path.islink(link_dst):
1020 os.unlink(link_dst)
1021 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
1022 symlink(link_src, link_dst)
1023 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
1026 def copy_and_fix_python_path(task):
1027 pattern='sys.path.insert(0, "bin/python")'
1028 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
1029 replacement = ""
1030 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
1031 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
1032 else:
1033 replacement="""sys.path.insert(0, "%s")
1034 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
1036 if task.env["PYTHON"][0].startswith("/"):
1037 replacement_shebang = "#!%s\n" % task.env["PYTHON"][0]
1038 else:
1039 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"][0]
1041 installed_location=task.outputs[0].bldpath(task.env)
1042 source_file = open(task.inputs[0].srcpath(task.env))
1043 installed_file = open(installed_location, 'w')
1044 lineno = 0
1045 for line in source_file:
1046 newline = line
1047 if (lineno == 0 and
1048 line[:2] == "#!"):
1049 newline = replacement_shebang
1050 elif pattern in line:
1051 newline = line.replace(pattern, replacement)
1052 installed_file.write(newline)
1053 lineno = lineno + 1
1054 installed_file.close()
1055 os.chmod(installed_location, 0o755)
1056 return 0
1058 def copy_and_fix_perl_path(task):
1059 pattern='use lib "$RealBin/lib";'
1061 replacement = ""
1062 if not task.env["PERL_LIB_INSTALL_DIR"] in task.env["PERL_INC"]:
1063 replacement = 'use lib "%s";' % task.env["PERL_LIB_INSTALL_DIR"]
1065 if task.env["PERL"][0] == "/":
1066 replacement_shebang = "#!%s\n" % task.env["PERL"]
1067 else:
1068 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PERL"]
1070 installed_location=task.outputs[0].bldpath(task.env)
1071 source_file = open(task.inputs[0].srcpath(task.env))
1072 installed_file = open(installed_location, 'w')
1073 lineno = 0
1074 for line in source_file:
1075 newline = line
1076 if lineno == 0 and task.env["PERL_SPECIFIED"] is True and line[:2] == "#!":
1077 newline = replacement_shebang
1078 elif pattern in line:
1079 newline = line.replace(pattern, replacement)
1080 installed_file.write(newline)
1081 lineno = lineno + 1
1082 installed_file.close()
1083 os.chmod(installed_location, 0o755)
1084 return 0
1087 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
1088 python_fixup=False, perl_fixup=False,
1089 destname=None, base_name=None):
1090 '''install a file'''
1091 if not isinstance(file, str):
1092 file = file.abspath()
1093 destdir = bld.EXPAND_VARIABLES(destdir)
1094 if not destname:
1095 destname = file
1096 if flat:
1097 destname = os.path.basename(destname)
1098 dest = os.path.join(destdir, destname)
1099 if python_fixup:
1100 # fix the path python will use to find Samba modules
1101 inst_file = file + '.inst'
1102 bld.SAMBA_GENERATOR('python_%s' % destname,
1103 rule=copy_and_fix_python_path,
1104 dep_vars=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
1105 source=file,
1106 target=inst_file)
1107 file = inst_file
1108 if perl_fixup:
1109 # fix the path perl will use to find Samba modules
1110 inst_file = file + '.inst'
1111 bld.SAMBA_GENERATOR('perl_%s' % destname,
1112 rule=copy_and_fix_perl_path,
1113 dep_vars=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
1114 source=file,
1115 target=inst_file)
1116 file = inst_file
1117 if base_name:
1118 file = os.path.join(base_name, file)
1119 bld.install_as(dest, file, chmod=chmod)
1122 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
1123 python_fixup=False, perl_fixup=False,
1124 destname=None, base_name=None):
1125 '''install a set of files'''
1126 for f in TO_LIST(files):
1127 install_file(bld, destdir, f, chmod=chmod, flat=flat,
1128 python_fixup=python_fixup, perl_fixup=perl_fixup,
1129 destname=destname, base_name=base_name)
1130 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
1133 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
1134 python_fixup=False, exclude=None, trim_path=None):
1135 '''install a set of files matching a wildcard pattern'''
1136 files=TO_LIST(bld.path.ant_glob(pattern, flat=True))
1137 if trim_path:
1138 files2 = []
1139 for f in files:
1140 files2.append(os.path.relpath(f, trim_path))
1141 files = files2
1143 if exclude:
1144 for f in files[:]:
1145 if fnmatch.fnmatch(f, exclude):
1146 files.remove(f)
1147 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
1148 python_fixup=python_fixup, base_name=trim_path)
1149 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
1151 def INSTALL_DIR(bld, path, chmod=0o755):
1152 """Install a directory if it doesn't exist, always set permissions."""
1154 if not path:
1155 return []
1157 destpath = bld.EXPAND_VARIABLES(path)
1158 if Options.options.destdir:
1159 destpath = os.path.join(Options.options.destdir, destpath.lstrip(os.sep))
1161 if bld.is_install > 0:
1162 if not os.path.isdir(destpath):
1163 try:
1164 Logs.info('* create %s', destpath)
1165 os.makedirs(destpath)
1166 os.chmod(destpath, chmod)
1167 except OSError as e:
1168 if not os.path.isdir(destpath):
1169 raise Errors.WafError("Cannot create the folder '%s' (error: %s)" % (path, e))
1170 Build.BuildContext.INSTALL_DIR = INSTALL_DIR
1172 def INSTALL_DIRS(bld, destdir, dirs, chmod=0o755):
1173 '''install a set of directories'''
1174 destdir = bld.EXPAND_VARIABLES(destdir)
1175 dirs = bld.EXPAND_VARIABLES(dirs)
1176 for d in TO_LIST(dirs):
1177 INSTALL_DIR(bld, os.path.join(destdir, d), chmod)
1178 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
1181 def MANPAGES(bld, manpages, install):
1182 '''build and install manual pages'''
1183 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
1184 for m in manpages.split():
1185 source = m + '.xml'
1186 bld.SAMBA_GENERATOR(m,
1187 source=source,
1188 target=m,
1189 group='final',
1190 rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
1192 if install:
1193 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
1194 Build.BuildContext.MANPAGES = MANPAGES
1196 def SAMBAMANPAGES(bld, manpages, extra_source=None):
1197 '''build and install manual pages'''
1198 bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
1199 bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
1200 bld.env.SAMBA_CATALOG = bld.bldnode.abspath() + '/docs-xml/build/catalog.xml'
1201 bld.env.SAMBA_CATALOGS = os.getenv('XML_CATALOG_FILES', 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog') + ' file://' + bld.env.SAMBA_CATALOG
1203 for m in manpages.split():
1204 source = [m + '.xml']
1205 if extra_source is not None:
1206 source = [source, extra_source]
1207 # ${SRC[1]}, ${SRC[2]} and ${SRC[3]} are not referenced in the
1208 # SAMBA_GENERATOR but trigger the dependency calculation so
1209 # ensures that manpages are rebuilt when these change.
1210 source += ['build/DTD/samba.build.pathconfig', 'build/DTD/samba.entities', 'build/DTD/samba.build.version']
1211 bld.SAMBA_GENERATOR(m,
1212 source=source,
1213 target=m,
1214 group='final',
1215 dep_vars=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
1216 rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
1217 export XML_CATALOG_FILES
1218 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
1219 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
1221 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
1222 Build.BuildContext.SAMBAMANPAGES = SAMBAMANPAGES
1224 @after('apply_link')
1225 @feature('cshlib')
1226 def apply_bundle_remove_dynamiclib_patch(self):
1227 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
1228 if not getattr(self,'vnum',None):
1229 try:
1230 self.env['LINKFLAGS'].remove('-dynamiclib')
1231 self.env['LINKFLAGS'].remove('-single_module')
1232 except ValueError:
1233 pass