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 *
26 import samba_conftests
39 os.environ['PYTHONUNBUFFERED'] = '1'
41 if Context.HEXVERSION not in (0x2001800,):
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
47 Alternatively, please run ./configure and make as usual. That will
48 call the right version of waf.''')
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):
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:
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 not subsystem in cache:
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('')
95 #################################################################
96 def SAMBA_LIBRARY(bld, libname, source,
101 public_headers_install=True,
102 private_headers=None,
110 external_library=False,
112 keep_underscore=False,
114 autoproto_extra_source='',
125 target_type='LIBRARY',
130 orig_vscript_map=None,
133 private_library=False,
134 grouping_library=False,
135 require_builtin_deps=False,
136 provide_builtin_linking=False,
138 allow_undefined_symbols=False,
139 allow_warnings=False,
141 '''define a Samba library'''
144 # - LIBRARY: this can be use 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" %
164 if orig_vscript_map and not private_library:
165 raise Errors.WafError("public library '%s' must not have orig_vscript_map" %
168 if orig_vscript_map and abi_directory:
169 raise Errors.WafError("private library '%s' with orig_vscript_map must not have abi_directory" %
171 if orig_vscript_map and abi_match:
172 raise Errors.WafError("private library '%s' with orig_vscript_map must not have abi_match" %
175 if LIB_MUST_BE_PRIVATE(bld, libname) and target_type not in ['PLUGIN']:
176 private_library = True
179 SET_TARGET_TYPE(bld, libname, 'DISABLED')
182 source = bld.EXPAND_VARIABLES(source, vars=vars)
184 source = bld.SUBDIR(subdir, source)
186 # remember empty libraries, so we can strip the dependencies
187 if ((source == '') or (source == [])):
188 if deps == '' and public_deps == '':
189 SET_TARGET_TYPE(bld, libname, 'EMPTY')
191 empty_c = libname + '.empty.c'
192 bld.SAMBA_GENERATOR('%s_empty_c' % libname,
193 rule=generate_empty_file,
197 samba_deps = deps + ' ' + public_deps
198 samba_deps = TO_LIST(samba_deps)
200 if BUILTIN_LIBRARY(bld, libname):
201 builtin_target = libname + '.builtin.objlist'
202 builtin_cflags_end = '-D_PUBLIC_=_PRIVATE_'
203 empty_target = libname
206 if provide_builtin_linking:
207 builtin_target = libname + '.builtin.objlist'
208 builtin_cflags_end = '-D_PUBLIC_=_PRIVATE_'
210 builtin_target = None
212 obj_target = libname + '.objlist'
213 if require_builtin_deps:
214 # hide the builtin deps from the callers
215 samba_deps = TO_LIST('')
216 dep_target = obj_target
218 if group == 'libraries':
219 subsystem_group = 'main'
221 subsystem_group = group
223 # first create a target for building the object files for this library
224 # by separating in this way, we avoid recompiling the C files
225 # separately for the install library and the build library
227 __t = __SAMBA_SUBSYSTEM_BUILTIN(bld, builtin_target, source,
229 public_deps=public_deps,
231 header_path=header_path,
232 builtin_cflags=builtin_cflags,
233 builtin_cflags_end=builtin_cflags_end,
235 depends_on=depends_on,
236 local_include=local_include,
237 global_include=global_include,
238 allow_warnings=allow_warnings)
239 builtin_subsystem = __t
241 builtin_subsystem = None
243 bld.SAMBA_SUBSYSTEM(obj_target,
246 public_deps = public_deps,
248 public_headers = public_headers,
249 public_headers_install = public_headers_install,
250 private_headers= private_headers,
251 header_path = header_path,
253 cflags_end = cflags_end,
254 group = subsystem_group,
255 autoproto = autoproto,
256 autoproto_extra_source=autoproto_extra_source,
257 depends_on = depends_on,
258 hide_symbols = hide_symbols,
259 allow_warnings = allow_warnings,
262 local_include = local_include,
263 __require_builtin_deps=require_builtin_deps,
264 global_include = global_include)
266 et = bld.SAMBA_SUBSYSTEM(empty_target,
269 __require_builtin_deps=True)
270 et.samba_builtin_subsystem = builtin_subsystem
272 if BUILTIN_LIBRARY(bld, libname):
275 if not SET_TARGET_TYPE(bld, libname, target_type):
278 # the library itself will depend on that object target
279 samba_deps.append(dep_target)
281 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
282 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
284 # we don't want any public libraries without version numbers
285 if (not private_library and target_type != 'PYTHON' and not realname):
286 if vnum is None and soname is None:
287 raise Errors.WafError("public library '%s' must have a vnum" %
290 raise Errors.WafError("public library '%s' must have pkg-config file" %
292 if public_headers is None:
293 raise Errors.WafError("public library '%s' must have header files" %
298 if bundled_name is not None:
300 elif target_type == 'PYTHON' or realname or not private_library:
302 bundled_name = libname
304 bundled_name = libname.replace('_', '-')
306 assert (private_library == True and realname is None)
307 bundled_name = PRIVATE_NAME(bld, libname.replace('_', '-'))
310 ldflags = TO_LIST(ldflags)
311 if bld.env['ENABLE_RELRO'] is True:
312 ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
314 features = 'c cshlib symlink_lib install_lib'
318 features += ' pyembed'
321 features += ' abi_check'
323 if pyembed and bld.env['PYTHON_SO_ABI_FLAG']:
324 # For ABI checking, we don't care about the Python version.
325 # Remove the Python ABI tag (e.g. ".cpython-35m")
326 abi_flag = bld.env['PYTHON_SO_ABI_FLAG']
328 version_libname = libname.replace(abi_flag, replacement)
330 version_libname = libname
333 if bld.env.HAVE_LD_VERSION_SCRIPT:
335 version = bld.env.PRIVATE_VERSION
337 version = "%s_%s" % (libname, vnum)
341 vscript = "%s.vscript" % libname
343 bld.VSCRIPT_MAP_PRIVATE(version_libname, orig_vscript_map, version, vscript)
345 bld.ABI_VSCRIPT(version_libname, abi_directory, version, vscript,
346 abi_match, private_library)
347 fullname = apply_pattern(bundled_name, bld.env.cshlib_PATTERN)
348 fullpath = bld.path.find_or_declare(fullname)
349 vscriptpath = bld.path.find_or_declare(vscript)
351 raise Errors.WafError("unable to find fullpath for %s" % fullname)
353 raise Errors.WafError("unable to find vscript path for %s" % vscript)
354 bld.add_manual_dependency(fullpath, vscriptpath)
356 # also make the .inst file depend on the vscript
357 instname = apply_pattern(bundled_name + '.inst', bld.env.cshlib_PATTERN)
358 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
359 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
361 bld.SET_BUILD_GROUP(group)
365 target = bundled_name,
366 depends_on = depends_on,
367 samba_ldflags = ldflags,
368 samba_deps = samba_deps,
369 samba_includes = includes,
370 version_script = vscript,
371 version_libname = version_libname,
372 local_include = local_include,
373 global_include = global_include,
377 samba_inst_path = install_path,
379 samba_realname = realname,
380 samba_install = install,
381 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
382 abi_match = abi_match,
384 private_library = private_library,
385 grouping_library=grouping_library,
386 allow_undefined_symbols=allow_undefined_symbols,
387 samba_require_builtin_deps=False,
388 samba_builtin_subsystem=builtin_subsystem,
391 if realname and not link_name:
392 link_name = 'shared/%s' % realname
395 if 'waflib.extras.compat15' in sys.modules:
396 link_name = 'default/' + link_name
397 t.link_name = link_name
399 if pc_files is not None and not private_library:
401 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum, extra_name=bld.env['PYTHON_SO_ABI_FLAG'])
403 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
405 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
406 bld.env['XSLTPROC_MANPAGES']):
407 bld.MANPAGES(manpages, install)
410 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
413 #################################################################
414 def SAMBA_BINARY(bld, binname, source,
418 private_headers=None,
426 use_global_deps=True,
433 allow_warnings=False,
442 '''define a Samba binary'''
446 if not bld.CONFIG_GET('ENABLE_SELFTEST'):
450 SET_TARGET_TYPE(bld, binname, 'DISABLED')
453 # Fuzzing builds do not build normal binaries
454 # however we must build asn1compile etc
456 if not use_hostcc and bld.env.enable_fuzzing != fuzzer:
457 SET_TARGET_TYPE(bld, binname, 'DISABLED')
463 ldflags = bld.env['FUZZ_TARGET_LDFLAGS']
465 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
468 features = 'c cprogram symlink_bin install_bin'
470 features += ' pyembed'
472 obj_target = binname + '.objlist'
474 source = bld.EXPAND_VARIABLES(source, vars=vars)
476 source = bld.SUBDIR(subdir, source)
477 source = unique_list(TO_LIST(source))
479 if group == 'binaries':
480 subsystem_group = 'main'
481 elif group == 'build_compilers':
482 subsystem_group = 'compiler_libraries'
484 subsystem_group = group
486 # only specify PIE flags for binaries
487 pie_cflags = TO_LIST(cflags)
488 pie_ldflags = TO_LIST(ldflags)
489 if bld.env['ENABLE_PIE'] is True:
490 pie_cflags.extend(TO_LIST('-fPIE'))
491 pie_ldflags.extend(TO_LIST('-pie'))
492 if bld.env['ENABLE_RELRO'] is True:
493 pie_ldflags.extend(TO_LIST('-Wl,-z,relro,-z,now'))
495 # first create a target for building the object files for this binary
496 # by separating in this way, we avoid recompiling the C files
497 # separately for the install binary and the build binary
498 bld.SAMBA_SUBSYSTEM(obj_target,
503 cflags_end = cflags_end,
504 group = subsystem_group,
505 autoproto = autoproto,
506 subsystem_name = subsystem_name,
507 local_include = local_include,
508 global_include = global_include,
509 use_hostcc = use_hostcc,
511 allow_warnings = allow_warnings,
512 use_global_deps= use_global_deps)
514 bld.SET_BUILD_GROUP(group)
516 # the binary itself will depend on that object target
518 deps.append(obj_target)
525 samba_includes = includes,
526 local_include = local_include,
527 global_include = global_include,
528 samba_modules = modules,
530 samba_subsystem= subsystem_name,
532 samba_inst_path= install_path,
533 samba_install = install,
534 samba_ldflags = pie_ldflags
537 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
538 bld.MANPAGES(manpages, install)
540 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
543 #################################################################
544 def SAMBA_MODULE(bld, modname, source,
549 module_init_name='samba_init_module',
551 autoproto_extra_source='',
554 internal_module=True,
562 allow_undefined_symbols=False,
563 allow_warnings=False,
566 '''define a Samba module.'''
568 bld.ASSERT(subsystem, "You must specify a subsystem for SAMBA_MODULE(%s)" % modname)
570 source = bld.EXPAND_VARIABLES(source, vars=vars)
572 source = bld.SUBDIR(subdir, source)
574 if internal_module or BUILTIN_LIBRARY(bld, modname):
575 # Do not create modules for disabled subsystems
576 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
578 bld.SAMBA_SUBSYSTEM(modname, source,
582 autoproto_extra_source=autoproto_extra_source,
584 cflags_end=cflags_end,
585 local_include=local_include,
586 global_include=global_include,
587 allow_warnings=allow_warnings,
590 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
594 SET_TARGET_TYPE(bld, modname, 'DISABLED')
597 # Do not create modules for disabled subsystems
598 if GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
602 deps += ' ' + subsystem
603 while realname.startswith("lib"+subsystem+"_"):
604 realname = realname[len("lib"+subsystem+"_"):]
605 while realname.startswith(subsystem+"_"):
606 realname = realname[len(subsystem+"_"):]
608 build_name = "%s_module_%s" % (subsystem, realname)
610 realname = bld.make_libname(realname)
611 while realname.startswith("lib"):
612 realname = realname[len("lib"):]
614 build_link_name = "modules/%s/%s" % (subsystem, realname)
617 cflags += " -D%s=%s" % (init_function, module_init_name)
619 bld.SAMBA_LIBRARY(modname,
624 cflags_end=cflags_end,
626 autoproto = autoproto,
627 local_include=local_include,
628 global_include=global_include,
630 bundled_name=build_name,
631 link_name=build_link_name,
632 install_path="${MODULESDIR}/%s" % subsystem,
635 allow_undefined_symbols=allow_undefined_symbols,
636 allow_warnings=allow_warnings,
637 private_library=True,
642 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
644 #################################################################
645 def SAMBA_PLUGIN(bld, pluginname, source,
657 keep_underscore=False,
659 autoproto_extra_source='',
663 require_builtin_deps=True,
664 allow_undefined_symbols=False,
666 '''define an external plugin.'''
668 bld.ASSERT(realname, "You must specify a realname for SAMBA_PLUGIN(%s)" % pluginname)
670 source = bld.EXPAND_VARIABLES(source, vars=vars)
672 source = bld.SUBDIR(subdir, source)
674 build_name = "_plugin_%s" % (pluginname)
675 build_link_name = "plugins/%s" % (realname)
677 bld.SAMBA_LIBRARY(pluginname,
679 bundled_name=build_name,
680 link_name=build_link_name,
681 target_type='PLUGIN',
690 autoproto_extra_source=autoproto_extra_source,
691 local_include=local_include,
692 global_include=global_include,
695 install_path=install_path,
698 require_builtin_deps=require_builtin_deps,
699 builtin_cflags=cflags,
702 public_headers_install=False,
704 allow_undefined_symbols=allow_undefined_symbols,
705 allow_warnings=False,
707 Build.BuildContext.SAMBA_PLUGIN = SAMBA_PLUGIN
709 def __SAMBA_SUBSYSTEM_BUILTIN(bld, builtin_target, source,
714 public_headers_install=True,
715 private_headers=None,
718 builtin_cflags_end=None,
721 autoproto_extra_source='',
725 allow_warnings=False):
727 bld.ASSERT(builtin_target.endswith('.builtin.objlist'),
728 "builtin_target[%s] does not end with '.builtin.objlist'" %
730 return bld.SAMBA_SUBSYSTEM(builtin_target, source,
732 public_deps=public_deps,
734 public_headers=public_headers,
735 public_headers_install=public_headers_install,
736 private_headers=private_headers,
737 header_path=header_path,
738 cflags=builtin_cflags,
739 cflags_end=builtin_cflags_end,
742 target_type='BUILTIN',
744 autoproto_extra_source=autoproto_extra_source,
745 depends_on=depends_on,
746 local_include=local_include,
747 global_include=global_include,
748 allow_warnings=allow_warnings,
749 __require_builtin_deps=True)
751 #################################################################
752 def SAMBA_SUBSYSTEM(bld, modname, source,
758 public_headers_install=True,
759 private_headers=None,
764 target_type='SUBSYSTEM',
765 init_function_sentinel=None,
767 autoproto_extra_source='',
770 local_include_first=True,
775 use_global_deps=True,
779 __require_builtin_deps=False,
780 provide_builtin_linking=False,
782 allow_warnings=False,
785 '''define a Samba subsystem'''
788 # - SUBSYSTEM: a normal subsystem from SAMBA_SUBSYSTEM()
789 # - BUILTIN: a hidden subsystem from __SAMBA_SUBSYSTEM_BUILTIN()
790 if target_type not in ['SUBSYSTEM', 'BUILTIN']:
791 raise Errors.WafError("target_type[%s] not supported in SAMBA_SUBSYSTEM('%s')" %
792 (target_type, modname))
795 SET_TARGET_TYPE(bld, modname, 'DISABLED')
798 # remember empty subsystems, so we can strip the dependencies
799 if ((source == '') or (source == [])):
800 if not __force_empty and deps == '' and public_deps == '':
801 SET_TARGET_TYPE(bld, modname, 'EMPTY')
803 empty_c = modname + '.empty.c'
804 bld.SAMBA_GENERATOR('%s_empty_c' % modname,
805 rule=generate_empty_file,
809 if not SET_TARGET_TYPE(bld, modname, target_type):
812 source = bld.EXPAND_VARIABLES(source, vars=vars)
814 source = bld.SUBDIR(subdir, source)
815 source = unique_list(TO_LIST(source))
817 deps += ' ' + public_deps
819 bld.SET_BUILD_GROUP(group)
825 features += ' pyembed'
831 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags,
832 allow_warnings=allow_warnings,
833 use_hostcc=use_hostcc,
834 hide_symbols=hide_symbols),
835 depends_on = depends_on,
836 samba_deps = TO_LIST(deps),
837 samba_includes = includes,
838 local_include = local_include,
839 local_include_first = local_include_first,
840 global_include = global_include,
841 samba_subsystem= subsystem_name,
842 samba_use_hostcc = use_hostcc,
843 samba_use_global_deps = use_global_deps,
844 samba_require_builtin_deps = __require_builtin_deps,
845 samba_builtin_subsystem = None,
848 if cflags_end is not None:
849 t.samba_cflags.extend(TO_LIST(cflags_end))
851 if autoproto is not None:
852 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
853 if public_headers is not None:
854 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
855 public_headers_install=public_headers_install)
857 if provide_builtin_linking:
860 raise Errors.WafError("subsystem[%s] provide_builtin_linking=True " +
861 "not allowed with use_hostcc=True" %
865 raise Errors.WafError("subsystem[%s] provide_builtin_linking=True " +
866 "not allowed with pyext=True nor pyembed=True" %
869 if __require_builtin_deps:
870 raise Errors.WafError("subsystem[%s] provide_builtin_linking=True " +
871 "not allowed with __require_builtin_deps=True" %
874 builtin_target = modname + '.builtin.objlist'
875 tbuiltin = __SAMBA_SUBSYSTEM_BUILTIN(bld, builtin_target, source,
877 public_deps=public_deps,
879 header_path=header_path,
880 builtin_cflags=builtin_cflags,
881 builtin_cflags_end='-D_PUBLIC_=_PRIVATE_',
883 depends_on=depends_on,
884 local_include=local_include,
885 global_include=global_include,
886 allow_warnings=allow_warnings)
887 t.samba_builtin_subsystem = tbuiltin
892 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
895 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
896 group='generators', enabled=True,
898 public_headers_install=True,
899 private_headers=None,
904 '''A generic source generator target'''
906 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
912 dep_vars = TO_LIST(dep_vars)
913 dep_vars.append('ruledeps')
914 dep_vars.append('SAMBA_GENERATOR_VARS')
916 bld.SET_BUILD_GROUP(group)
919 source=bld.EXPAND_VARIABLES(source, vars=vars),
921 shell=isinstance(rule, str),
925 samba_type='GENERATOR',
931 t.env.SAMBA_GENERATOR_VARS = vars
936 if public_headers is not None:
937 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
938 public_headers_install=public_headers_install)
940 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
945 def SETUP_BUILD_GROUPS(bld):
946 '''setup build groups used to ensure that the different build
947 phases happen consecutively'''
948 bld.p_ln = bld.srcnode # we do want to see all targets!
949 bld.env['USING_BUILD_GROUPS'] = True
950 bld.add_group('setup')
951 bld.add_group('generators')
952 bld.add_group('hostcc_base_build_source')
953 bld.add_group('hostcc_base_build_main')
954 bld.add_group('hostcc_build_source')
955 bld.add_group('hostcc_build_main')
956 bld.add_group('vscripts')
957 bld.add_group('base_libraries')
958 bld.add_group('build_source')
959 bld.add_group('prototypes')
960 bld.add_group('headers')
961 bld.add_group('main')
962 bld.add_group('symbolcheck')
963 bld.add_group('syslibcheck')
964 bld.add_group('final')
965 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
968 def SET_BUILD_GROUP(bld, group):
969 '''set the current build group'''
970 if not 'USING_BUILD_GROUPS' in bld.env:
973 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
977 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
978 '''used to copy scripts from the source tree into the build directory
979 for use by selftest'''
981 source = bld.path.ant_glob(pattern, flat=True)
983 bld.SET_BUILD_GROUP('build_source')
984 for s in TO_LIST(source):
986 if installname is not None:
988 target = os.path.join(installdir, iname)
989 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
991 link_src = os.path.normpath(os.path.join(bld.path.abspath(), s))
992 link_dst = os.path.join(tgtdir, os.path.basename(iname))
993 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
995 if os.path.islink(link_dst):
997 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
998 symlink(link_src, link_dst)
999 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
1002 def copy_and_fix_python_path(task):
1003 pattern='sys.path.insert(0, "bin/python")'
1004 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
1006 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
1007 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
1009 replacement="""sys.path.insert(0, "%s")
1010 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
1012 if task.env["PYTHON"][0].startswith("/"):
1013 replacement_shebang = "#!%s\n" % task.env["PYTHON"][0]
1015 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PYTHON"][0]
1017 installed_location=task.outputs[0].bldpath(task.env)
1018 source_file = open(task.inputs[0].srcpath(task.env))
1019 installed_file = open(installed_location, 'w')
1021 for line in source_file:
1025 newline = replacement_shebang
1026 elif pattern in line:
1027 newline = line.replace(pattern, replacement)
1028 installed_file.write(newline)
1030 installed_file.close()
1031 os.chmod(installed_location, 0o755)
1034 def copy_and_fix_perl_path(task):
1035 pattern='use lib "$RealBin/lib";'
1038 if not task.env["PERL_LIB_INSTALL_DIR"] in task.env["PERL_INC"]:
1039 replacement = 'use lib "%s";' % task.env["PERL_LIB_INSTALL_DIR"]
1041 if task.env["PERL"][0] == "/":
1042 replacement_shebang = "#!%s\n" % task.env["PERL"]
1044 replacement_shebang = "#!/usr/bin/env %s\n" % task.env["PERL"]
1046 installed_location=task.outputs[0].bldpath(task.env)
1047 source_file = open(task.inputs[0].srcpath(task.env))
1048 installed_file = open(installed_location, 'w')
1050 for line in source_file:
1052 if lineno == 0 and task.env["PERL_SPECIFIED"] == True and line[:2] == "#!":
1053 newline = replacement_shebang
1054 elif pattern in line:
1055 newline = line.replace(pattern, replacement)
1056 installed_file.write(newline)
1058 installed_file.close()
1059 os.chmod(installed_location, 0o755)
1063 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
1064 python_fixup=False, perl_fixup=False,
1065 destname=None, base_name=None):
1066 '''install a file'''
1067 if not isinstance(file, str):
1068 file = file.abspath()
1069 destdir = bld.EXPAND_VARIABLES(destdir)
1073 destname = os.path.basename(destname)
1074 dest = os.path.join(destdir, destname)
1076 # fix the path python will use to find Samba modules
1077 inst_file = file + '.inst'
1078 bld.SAMBA_GENERATOR('python_%s' % destname,
1079 rule=copy_and_fix_python_path,
1080 dep_vars=["PYTHON","PYTHON_SPECIFIED","PYTHONDIR","PYTHONARCHDIR"],
1085 # fix the path perl will use to find Samba modules
1086 inst_file = file + '.inst'
1087 bld.SAMBA_GENERATOR('perl_%s' % destname,
1088 rule=copy_and_fix_perl_path,
1089 dep_vars=["PERL","PERL_SPECIFIED","PERL_LIB_INSTALL_DIR"],
1094 file = os.path.join(base_name, file)
1095 bld.install_as(dest, file, chmod=chmod)
1098 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
1099 python_fixup=False, perl_fixup=False,
1100 destname=None, base_name=None):
1101 '''install a set of files'''
1102 for f in TO_LIST(files):
1103 install_file(bld, destdir, f, chmod=chmod, flat=flat,
1104 python_fixup=python_fixup, perl_fixup=perl_fixup,
1105 destname=destname, base_name=base_name)
1106 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
1109 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
1110 python_fixup=False, exclude=None, trim_path=None):
1111 '''install a set of files matching a wildcard pattern'''
1112 files=TO_LIST(bld.path.ant_glob(pattern, flat=True))
1116 files2.append(os.path.relpath(f, trim_path))
1121 if fnmatch.fnmatch(f, exclude):
1123 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
1124 python_fixup=python_fixup, base_name=trim_path)
1125 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
1127 def INSTALL_DIR(bld, path, chmod=0o755, env=None):
1128 """Install a directory if it doesn't exist, always set permissions."""
1133 destpath = bld.EXPAND_VARIABLES(path)
1134 if Options.options.destdir:
1135 destpath = os.path.join(Options.options.destdir, destpath.lstrip(os.sep))
1137 if bld.is_install > 0:
1138 if not os.path.isdir(destpath):
1140 Logs.info('* create %s', destpath)
1141 os.makedirs(destpath)
1142 os.chmod(destpath, chmod)
1143 except OSError as e:
1144 if not os.path.isdir(destpath):
1145 raise Errors.WafError("Cannot create the folder '%s' (error: %s)" % (path, e))
1146 Build.BuildContext.INSTALL_DIR = INSTALL_DIR
1148 def INSTALL_DIRS(bld, destdir, dirs, chmod=0o755, env=None):
1149 '''install a set of directories'''
1150 destdir = bld.EXPAND_VARIABLES(destdir)
1151 dirs = bld.EXPAND_VARIABLES(dirs)
1152 for d in TO_LIST(dirs):
1153 INSTALL_DIR(bld, os.path.join(destdir, d), chmod, env)
1154 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
1157 def MANPAGES(bld, manpages, install):
1158 '''build and install manual pages'''
1159 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
1160 for m in manpages.split():
1162 bld.SAMBA_GENERATOR(m,
1166 rule='${XSLTPROC} --xinclude -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
1169 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
1170 Build.BuildContext.MANPAGES = MANPAGES
1172 def SAMBAMANPAGES(bld, manpages, extra_source=None):
1173 '''build and install manual pages'''
1174 bld.env.SAMBA_EXPAND_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/expand-sambadoc.xsl'
1175 bld.env.SAMBA_MAN_XSL = bld.srcnode.abspath() + '/docs-xml/xslt/man.xsl'
1176 bld.env.SAMBA_CATALOG = bld.bldnode.abspath() + '/docs-xml/build/catalog.xml'
1177 bld.env.SAMBA_CATALOGS = 'file:///etc/xml/catalog file:///usr/local/share/xml/catalog file://' + bld.env.SAMBA_CATALOG
1179 for m in manpages.split():
1180 source = [m + '.xml']
1181 if extra_source is not None:
1182 source = [source, extra_source]
1183 # ${SRC[1]}, ${SRC[2]} and ${SRC[3]} are not referenced in the
1184 # SAMBA_GENERATOR but trigger the dependency calculation so
1185 # ensures that manpages are rebuilt when these change.
1186 source += ['build/DTD/samba.build.pathconfig', 'build/DTD/samba.entities', 'build/DTD/samba.build.version']
1187 bld.SAMBA_GENERATOR(m,
1191 dep_vars=['SAMBA_MAN_XSL', 'SAMBA_EXPAND_XSL', 'SAMBA_CATALOG'],
1192 rule='''XML_CATALOG_FILES="${SAMBA_CATALOGS}"
1193 export XML_CATALOG_FILES
1194 ${XSLTPROC} --xinclude --stringparam noreference 0 -o ${TGT}.xml --nonet ${SAMBA_EXPAND_XSL} ${SRC[0].abspath(env)}
1195 ${XSLTPROC} --nonet -o ${TGT} ${SAMBA_MAN_XSL} ${TGT}.xml'''
1197 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
1198 Build.BuildContext.SAMBAMANPAGES = SAMBAMANPAGES
1200 @after('apply_link')
1202 def apply_bundle_remove_dynamiclib_patch(self):
1203 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
1204 if not getattr(self,'vnum',None):
1206 self.env['LINKFLAGS'].remove('-dynamiclib')
1207 self.env['LINKFLAGS'].remove('-single_module')