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