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 Build, os, sys, Options, Task, Utils, cc, TaskGen, fnmatch, re, shutil, Logs, Constants
5 from Configure import conf
7 from samba_utils import SUBST_VARS_RECURSIVE
8 TaskGen.task_gen.apply_verif = Utils.nada
10 # bring in the other samba modules
11 from samba_optimisation import *
12 from samba_utils import *
13 from samba_version import *
14 from samba_autoconf import *
15 from samba_patterns import *
16 from samba_pidl import *
17 from samba_autoproto import *
18 from samba_python import *
19 from samba_deps import *
20 from samba_bundled import *
22 import samba_conftests
35 # some systems have broken threading in python
36 if os.environ.get('WAF_NOTHREADS') == '1':
41 os.environ['PYTHONUNBUFFERED'] = '1'
44 if Constants.HEXVERSION < 0x105019:
46 Please use the version of waf that comes with Samba, not
47 a system installed version. See http://wiki.samba.org/index.php/Waf
50 Alternatively, please run ./configure and make as usual. That will
51 call the right version of waf.''')
56 def SAMBA_BUILD_ENV(conf):
57 '''create the samba build environment'''
58 conf.env.BUILD_DIRECTORY = conf.blddir
59 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
60 mkdir_p(os.path.join(conf.blddir, LIB_PATH, "private"))
61 mkdir_p(os.path.join(conf.blddir, "modules"))
62 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
63 # this allows all of the bin/shared and bin/python targets
64 # to be expressed in terms of build directory paths
65 mkdir_p(os.path.join(conf.blddir, 'default'))
66 for p in ['python','shared', 'modules']:
67 link_target = os.path.join(conf.blddir, 'default/' + p)
68 if not os.path.lexists(link_target):
69 os.symlink('../' + p, link_target)
71 # get perl to put the blib files in the build directory
72 blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
73 blib_src = os.path.join(conf.srcdir, 'pidl/blib')
74 mkdir_p(blib_bld + '/man1')
75 mkdir_p(blib_bld + '/man3')
76 if os.path.islink(blib_src):
78 elif os.path.exists(blib_src):
79 shutil.rmtree(blib_src)
82 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
83 '''add an init_function to the list for a subsystem'''
84 if init_function is None:
86 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
87 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
88 if not subsystem in cache:
90 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
91 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
95 #################################################################
96 def SAMBA_LIBRARY(bld, libname, source,
101 public_headers_install=True,
108 external_library=False,
111 autoproto_extra_source='',
122 target_type='LIBRARY',
123 bundled_extension=True,
129 private_library=False,
130 grouping_library=False,
131 allow_undefined_symbols=False,
133 '''define a Samba library'''
135 if LIB_MUST_BE_PRIVATE(bld, libname):
139 SET_TARGET_TYPE(bld, libname, 'DISABLED')
142 source = bld.EXPAND_VARIABLES(source, vars=vars)
144 source = bld.SUBDIR(subdir, source)
146 # remember empty libraries, so we can strip the dependencies
147 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
148 SET_TARGET_TYPE(bld, libname, 'EMPTY')
151 if BUILTIN_LIBRARY(bld, libname):
154 obj_target = libname + '.objlist'
156 if group == 'libraries':
157 subsystem_group = 'main'
159 subsystem_group = group
161 # first create a target for building the object files for this library
162 # by separating in this way, we avoid recompiling the C files
163 # separately for the install library and the build library
164 bld.SAMBA_SUBSYSTEM(obj_target,
167 public_deps = public_deps,
169 public_headers = public_headers,
170 public_headers_install = public_headers_install,
171 header_path = header_path,
173 group = subsystem_group,
174 autoproto = autoproto,
175 autoproto_extra_source=autoproto_extra_source,
176 depends_on = depends_on,
177 hide_symbols = hide_symbols,
180 local_include = local_include,
181 global_include = global_include)
183 if BUILTIN_LIBRARY(bld, libname):
186 if not SET_TARGET_TYPE(bld, libname, target_type):
189 # the library itself will depend on that object target
190 deps += ' ' + public_deps
192 deps.append(obj_target)
194 realname = bld.map_shlib_extension(realname, python=(target_type=='PYTHON'))
195 link_name = bld.map_shlib_extension(link_name, python=(target_type=='PYTHON'))
197 # we don't want any public libraries without version numbers
198 if (not private_library and target_type != 'PYTHON' and not realname):
199 if vnum is None and soname is None:
200 raise Utils.WafError("public library '%s' must have a vnum" %
203 raise Utils.WafError("public library '%s' must have pkg-config file" %
205 if public_headers is None:
206 raise Utils.WafError("public library '%s' must have header files" %
209 if target_type == 'PYTHON' or realname or not private_library:
210 bundled_name = libname.replace('_', '-')
212 bundled_name = PRIVATE_NAME(bld, libname, bundled_extension,
215 ldflags = TO_LIST(ldflags)
217 features = 'cc cshlib symlink_lib install_lib'
221 features += ' pyembed'
224 features += ' abi_check'
227 if bld.env.HAVE_LD_VERSION_SCRIPT:
229 version = "%s_%s" % (Utils.g_module.APPNAME, Utils.g_module.VERSION)
231 version = "%s_%s" % (libname, vnum)
235 vscript = "%s.vscript" % libname
236 bld.ABI_VSCRIPT(libname, abi_directory, version, vscript,
238 fullname = apply_pattern(bundled_name, bld.env.shlib_PATTERN)
239 fullpath = bld.path.find_or_declare(fullname)
240 vscriptpath = bld.path.find_or_declare(vscript)
242 raise Utils.WafError("unable to find fullpath for %s" % fullname)
244 raise Utils.WafError("unable to find vscript path for %s" % vscript)
245 bld.add_manual_dependency(fullpath, vscriptpath)
246 if Options.is_install:
247 # also make the .inst file depend on the vscript
248 instname = apply_pattern(bundled_name + '.inst', bld.env.shlib_PATTERN)
249 bld.add_manual_dependency(bld.path.find_or_declare(instname), bld.path.find_or_declare(vscript))
250 vscript = os.path.join(bld.path.abspath(bld.env), vscript)
252 bld.SET_BUILD_GROUP(group)
256 target = bundled_name,
257 depends_on = depends_on,
258 samba_ldflags = ldflags,
260 samba_includes = includes,
261 version_script = vscript,
262 local_include = local_include,
263 global_include = global_include,
267 samba_inst_path = install_path,
269 samba_realname = realname,
270 samba_install = install,
271 abi_directory = "%s/%s" % (bld.path.abspath(), abi_directory),
272 abi_match = abi_match,
273 private_library = private_library,
274 grouping_library=grouping_library,
275 allow_undefined_symbols=allow_undefined_symbols
278 if realname and not link_name:
279 link_name = 'shared/%s' % realname
282 t.link_name = link_name
284 if pc_files is not None and not private_library:
285 bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
287 if (manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and
288 bld.env['XSLTPROC_MANPAGES']):
289 bld.MANPAGES(manpages)
292 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
295 #################################################################
296 def SAMBA_BINARY(bld, binname, source,
306 use_global_deps=True,
319 '''define a Samba binary'''
322 SET_TARGET_TYPE(bld, binname, 'DISABLED')
325 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
328 features = 'cc cprogram symlink_bin install_bin'
330 features += ' pyembed'
332 obj_target = binname + '.objlist'
334 source = bld.EXPAND_VARIABLES(source, vars=vars)
336 source = bld.SUBDIR(subdir, source)
337 source = unique_list(TO_LIST(source))
339 if group == 'binaries':
340 subsystem_group = 'main'
342 subsystem_group = group
344 # first create a target for building the object files for this binary
345 # by separating in this way, we avoid recompiling the C files
346 # separately for the install binary and the build binary
347 bld.SAMBA_SUBSYSTEM(obj_target,
352 group = subsystem_group,
353 autoproto = autoproto,
354 subsystem_name = subsystem_name,
355 local_include = local_include,
356 global_include = global_include,
357 use_hostcc = use_hostcc,
359 use_global_deps= use_global_deps)
361 bld.SET_BUILD_GROUP(group)
363 # the binary itself will depend on that object target
365 deps.append(obj_target)
372 samba_includes = includes,
373 local_include = local_include,
374 global_include = global_include,
375 samba_modules = modules,
377 samba_subsystem= subsystem_name,
379 samba_inst_path= install_path,
380 samba_install = install,
381 samba_ldflags = TO_LIST(ldflags)
384 if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
385 bld.MANPAGES(manpages)
387 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
390 #################################################################
391 def SAMBA_MODULE(bld, modname, source,
396 module_init_name='samba_init_module',
398 autoproto_extra_source='',
400 internal_module=True,
407 allow_undefined_symbols=False
409 '''define a Samba module.'''
411 source = bld.EXPAND_VARIABLES(source, vars=vars)
413 source = bld.SUBDIR(subdir, source)
415 if internal_module or BUILTIN_LIBRARY(bld, modname):
416 bld.SAMBA_SUBSYSTEM(modname, source,
420 autoproto_extra_source=autoproto_extra_source,
422 local_include=local_include,
423 global_include=global_include,
426 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
430 SET_TARGET_TYPE(bld, modname, 'DISABLED')
433 obj_target = modname + '.objlist'
436 if subsystem is not None:
437 deps += ' ' + subsystem
438 while realname.startswith("lib"+subsystem+"_"):
439 realname = realname[len("lib"+subsystem+"_"):]
440 while realname.startswith(subsystem+"_"):
441 realname = realname[len(subsystem+"_"):]
443 realname = bld.make_libname(realname)
444 while realname.startswith("lib"):
445 realname = realname[len("lib"):]
447 build_link_name = "modules/%s/%s" % (subsystem, realname)
450 cflags += " -D%s=%s" % (init_function, module_init_name)
452 bld.SAMBA_LIBRARY(modname,
458 autoproto = autoproto,
459 local_include=local_include,
460 global_include=global_include,
462 link_name=build_link_name,
463 install_path="${MODULESDIR}/%s" % subsystem,
465 allow_undefined_symbols=allow_undefined_symbols
469 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
472 #################################################################
473 def SAMBA_SUBSYSTEM(bld, modname, source,
478 public_headers_install=True,
483 init_function_sentinel=None,
485 autoproto_extra_source='',
488 local_include_first=True,
493 use_global_deps=True,
499 '''define a Samba subsystem'''
502 SET_TARGET_TYPE(bld, modname, 'DISABLED')
505 # remember empty subsystems, so we can strip the dependencies
506 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
507 SET_TARGET_TYPE(bld, modname, 'EMPTY')
510 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
513 source = bld.EXPAND_VARIABLES(source, vars=vars)
515 source = bld.SUBDIR(subdir, source)
516 source = unique_list(TO_LIST(source))
518 deps += ' ' + public_deps
520 bld.SET_BUILD_GROUP(group)
526 features += ' pyembed'
532 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
533 depends_on = depends_on,
534 samba_deps = TO_LIST(deps),
535 samba_includes = includes,
536 local_include = local_include,
537 local_include_first = local_include_first,
538 global_include = global_include,
539 samba_subsystem= subsystem_name,
540 samba_use_hostcc = use_hostcc,
541 samba_use_global_deps = use_global_deps,
544 if cflags_end is not None:
545 t.samba_cflags.extend(TO_LIST(cflags_end))
547 if autoproto is not None:
548 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
549 if public_headers is not None:
550 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
551 public_headers_install=public_headers_install)
555 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
558 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
559 group='generators', enabled=True,
561 public_headers_install=True,
565 '''A generic source generator target'''
567 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
573 bld.SET_BUILD_GROUP(group)
576 source=bld.EXPAND_VARIABLES(source, vars=vars),
578 shell=isinstance(rule, str),
582 samba_type='GENERATOR',
583 dep_vars = [rule] + (vars or []),
589 if public_headers is not None:
590 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
591 public_headers_install=public_headers_install)
593 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
598 def SETUP_BUILD_GROUPS(bld):
599 '''setup build groups used to ensure that the different build
600 phases happen consecutively'''
601 bld.p_ln = bld.srcnode # we do want to see all targets!
602 bld.env['USING_BUILD_GROUPS'] = True
603 bld.add_group('setup')
604 bld.add_group('build_compiler_source')
605 bld.add_group('vscripts')
606 bld.add_group('base_libraries')
607 bld.add_group('generators')
608 bld.add_group('compiler_prototypes')
609 bld.add_group('compiler_libraries')
610 bld.add_group('build_compilers')
611 bld.add_group('build_source')
612 bld.add_group('prototypes')
613 bld.add_group('headers')
614 bld.add_group('main')
615 bld.add_group('symbolcheck')
616 bld.add_group('libraries')
617 bld.add_group('binaries')
618 bld.add_group('syslibcheck')
619 bld.add_group('final')
620 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
623 def SET_BUILD_GROUP(bld, group):
624 '''set the current build group'''
625 if not 'USING_BUILD_GROUPS' in bld.env:
628 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
633 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
634 """use timestamps instead of file contents for deps
635 this currently doesn't work"""
636 def h_file(filename):
638 st = os.stat(filename)
639 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
641 m.update(str(st.st_mtime))
642 m.update(str(st.st_size))
645 Utils.h_file = h_file
648 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
649 '''used to copy scripts from the source tree into the build directory
650 for use by selftest'''
652 source = bld.path.ant_glob(pattern)
654 bld.SET_BUILD_GROUP('build_source')
655 for s in TO_LIST(source):
657 if installname != None:
659 target = os.path.join(installdir, iname)
660 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
662 link_src = os.path.normpath(os.path.join(bld.curdir, s))
663 link_dst = os.path.join(tgtdir, os.path.basename(iname))
664 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
666 if os.path.exists(link_dst):
668 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
669 os.symlink(link_src, link_dst)
670 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
673 def copy_and_fix_python_path(task):
674 pattern='sys.path.insert(0, "bin/python")'
675 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
677 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
678 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
680 replacement="""sys.path.insert(0, "%s")
681 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
683 installed_location=task.outputs[0].bldpath(task.env)
684 source_file = open(task.inputs[0].srcpath(task.env))
685 installed_file = open(installed_location, 'w')
686 for line in source_file:
689 newline = line.replace(pattern, replacement)
690 installed_file.write(newline)
691 installed_file.close()
692 os.chmod(installed_location, 0755)
696 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
697 python_fixup=False, destname=None, base_name=None):
699 destdir = bld.EXPAND_VARIABLES(destdir)
703 destname = os.path.basename(destname)
704 dest = os.path.join(destdir, destname)
706 # fixup the python path it will use to find Samba modules
707 inst_file = file + '.inst'
708 bld.SAMBA_GENERATOR('python_%s' % destname,
709 rule=copy_and_fix_python_path,
712 bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONARCHDIR"])
713 bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONDIR"])
716 file = os.path.join(base_name, file)
717 bld.install_as(dest, file, chmod=chmod)
720 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
721 python_fixup=False, destname=None, base_name=None):
722 '''install a set of files'''
723 for f in TO_LIST(files):
724 install_file(bld, destdir, f, chmod=chmod, flat=flat,
725 python_fixup=python_fixup, destname=destname,
727 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
730 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
731 python_fixup=False, exclude=None, trim_path=None):
732 '''install a set of files matching a wildcard pattern'''
733 files=TO_LIST(bld.path.ant_glob(pattern))
737 files2.append(os_path_relpath(f, trim_path))
742 if fnmatch.fnmatch(f, exclude):
744 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
745 python_fixup=python_fixup, base_name=trim_path)
746 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
749 def INSTALL_DIRS(bld, destdir, dirs):
750 '''install a set of directories'''
751 destdir = bld.EXPAND_VARIABLES(destdir)
752 dirs = bld.EXPAND_VARIABLES(dirs)
753 for d in TO_LIST(dirs):
754 bld.install_dir(os.path.join(destdir, d))
755 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
758 def MANPAGES(bld, manpages):
759 '''build and install manual pages'''
760 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
761 for m in manpages.split():
763 bld.SAMBA_GENERATOR(m,
767 rule='${XSLTPROC} -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
769 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
770 Build.BuildContext.MANPAGES = MANPAGES
773 #############################################################
774 # give a nicer display when building different types of files
775 def progress_display(self, msg, fname):
776 col1 = Logs.colors(self.color)
777 col2 = Logs.colors.NORMAL
778 total = self.position[1]
780 fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
781 return fs % (self.position[0], self.position[1], col1, fname, col2)
783 def link_display(self):
784 if Options.options.progress_bar != 0:
785 return Task.Task.old_display(self)
786 fname = self.outputs[0].bldpath(self.env)
787 return progress_display(self, 'Linking', fname)
788 Task.TaskBase.classes['cc_link'].display = link_display
790 def samba_display(self):
791 if Options.options.progress_bar != 0:
792 return Task.Task.old_display(self)
794 targets = LOCAL_CACHE(self, 'TARGET_TYPE')
795 if self.name in targets:
796 target_type = targets[self.name]
797 type_map = { 'GENERATOR' : 'Generating',
798 'PROTOTYPE' : 'Generating'
800 if target_type in type_map:
801 return progress_display(self, type_map[target_type], self.name)
803 if len(self.inputs) == 0:
804 return Task.Task.old_display(self)
806 fname = self.inputs[0].bldpath(self.env)
807 if fname[0:3] == '../':
809 ext_loc = fname.rfind('.')
811 return Task.Task.old_display(self)
812 ext = fname[ext_loc:]
814 ext_map = { '.idl' : 'Compiling IDL',
815 '.et' : 'Compiling ERRTABLE',
816 '.asn1': 'Compiling ASN1',
819 return progress_display(self, ext_map[ext], fname)
820 return Task.Task.old_display(self)
822 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
823 Task.TaskBase.classes['Task'].display = samba_display
828 def apply_bundle_remove_dynamiclib_patch(self):
829 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
830 if not getattr(self,'vnum',None):
832 self.env['LINKFLAGS'].remove('-dynamiclib')
833 self.env['LINKFLAGS'].remove('-single_module')