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