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 # Do not create modules for disabled subsystems
417 if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
419 bld.SAMBA_SUBSYSTEM(modname, source,
423 autoproto_extra_source=autoproto_extra_source,
425 local_include=local_include,
426 global_include=global_include,
429 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
433 SET_TARGET_TYPE(bld, modname, 'DISABLED')
436 # Do not create modules for disabled subsystems
437 if subsystem and GET_TARGET_TYPE(bld, subsystem) == 'DISABLED':
440 obj_target = modname + '.objlist'
443 if subsystem is not None:
444 deps += ' ' + subsystem
445 while realname.startswith("lib"+subsystem+"_"):
446 realname = realname[len("lib"+subsystem+"_"):]
447 while realname.startswith(subsystem+"_"):
448 realname = realname[len(subsystem+"_"):]
450 realname = bld.make_libname(realname)
451 while realname.startswith("lib"):
452 realname = realname[len("lib"):]
454 build_link_name = "modules/%s/%s" % (subsystem, realname)
457 cflags += " -D%s=%s" % (init_function, module_init_name)
459 bld.SAMBA_LIBRARY(modname,
465 autoproto = autoproto,
466 local_include=local_include,
467 global_include=global_include,
469 link_name=build_link_name,
470 install_path="${MODULESDIR}/%s" % subsystem,
472 allow_undefined_symbols=allow_undefined_symbols
476 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
479 #################################################################
480 def SAMBA_SUBSYSTEM(bld, modname, source,
485 public_headers_install=True,
490 init_function_sentinel=None,
492 autoproto_extra_source='',
495 local_include_first=True,
500 use_global_deps=True,
506 '''define a Samba subsystem'''
509 SET_TARGET_TYPE(bld, modname, 'DISABLED')
512 # remember empty subsystems, so we can strip the dependencies
513 if ((source == '') or (source == [])) and deps == '' and public_deps == '':
514 SET_TARGET_TYPE(bld, modname, 'EMPTY')
517 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
520 source = bld.EXPAND_VARIABLES(source, vars=vars)
522 source = bld.SUBDIR(subdir, source)
523 source = unique_list(TO_LIST(source))
525 deps += ' ' + public_deps
527 bld.SET_BUILD_GROUP(group)
533 features += ' pyembed'
539 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags, hide_symbols=hide_symbols),
540 depends_on = depends_on,
541 samba_deps = TO_LIST(deps),
542 samba_includes = includes,
543 local_include = local_include,
544 local_include_first = local_include_first,
545 global_include = global_include,
546 samba_subsystem= subsystem_name,
547 samba_use_hostcc = use_hostcc,
548 samba_use_global_deps = use_global_deps,
551 if cflags_end is not None:
552 t.samba_cflags.extend(TO_LIST(cflags_end))
554 if autoproto is not None:
555 bld.SAMBA_AUTOPROTO(autoproto, source + TO_LIST(autoproto_extra_source))
556 if public_headers is not None:
557 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
558 public_headers_install=public_headers_install)
562 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
565 def SAMBA_GENERATOR(bld, name, rule, source='', target='',
566 group='generators', enabled=True,
568 public_headers_install=True,
572 '''A generic source generator target'''
574 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
580 bld.SET_BUILD_GROUP(group)
583 source=bld.EXPAND_VARIABLES(source, vars=vars),
585 shell=isinstance(rule, str),
589 samba_type='GENERATOR',
590 dep_vars = [rule] + (vars or []),
596 if public_headers is not None:
597 bld.PUBLIC_HEADERS(public_headers, header_path=header_path,
598 public_headers_install=public_headers_install)
600 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
605 def SETUP_BUILD_GROUPS(bld):
606 '''setup build groups used to ensure that the different build
607 phases happen consecutively'''
608 bld.p_ln = bld.srcnode # we do want to see all targets!
609 bld.env['USING_BUILD_GROUPS'] = True
610 bld.add_group('setup')
611 bld.add_group('build_compiler_source')
612 bld.add_group('vscripts')
613 bld.add_group('base_libraries')
614 bld.add_group('generators')
615 bld.add_group('compiler_prototypes')
616 bld.add_group('compiler_libraries')
617 bld.add_group('build_compilers')
618 bld.add_group('build_source')
619 bld.add_group('prototypes')
620 bld.add_group('headers')
621 bld.add_group('main')
622 bld.add_group('symbolcheck')
623 bld.add_group('libraries')
624 bld.add_group('binaries')
625 bld.add_group('syslibcheck')
626 bld.add_group('final')
627 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
630 def SET_BUILD_GROUP(bld, group):
631 '''set the current build group'''
632 if not 'USING_BUILD_GROUPS' in bld.env:
635 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
640 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
641 """use timestamps instead of file contents for deps
642 this currently doesn't work"""
643 def h_file(filename):
645 st = os.stat(filename)
646 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
648 m.update(str(st.st_mtime))
649 m.update(str(st.st_size))
652 Utils.h_file = h_file
655 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
656 '''used to copy scripts from the source tree into the build directory
657 for use by selftest'''
659 source = bld.path.ant_glob(pattern)
661 bld.SET_BUILD_GROUP('build_source')
662 for s in TO_LIST(source):
664 if installname != None:
666 target = os.path.join(installdir, iname)
667 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
669 link_src = os.path.normpath(os.path.join(bld.curdir, s))
670 link_dst = os.path.join(tgtdir, os.path.basename(iname))
671 if os.path.islink(link_dst) and os.readlink(link_dst) == link_src:
673 if os.path.exists(link_dst):
675 Logs.info("symlink: %s -> %s/%s" % (s, installdir, iname))
676 os.symlink(link_src, link_dst)
677 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
680 def copy_and_fix_python_path(task):
681 pattern='sys.path.insert(0, "bin/python")'
682 if task.env["PYTHONARCHDIR"] in sys.path and task.env["PYTHONDIR"] in sys.path:
684 elif task.env["PYTHONARCHDIR"] == task.env["PYTHONDIR"]:
685 replacement="""sys.path.insert(0, "%s")""" % task.env["PYTHONDIR"]
687 replacement="""sys.path.insert(0, "%s")
688 sys.path.insert(1, "%s")""" % (task.env["PYTHONARCHDIR"], task.env["PYTHONDIR"])
690 installed_location=task.outputs[0].bldpath(task.env)
691 source_file = open(task.inputs[0].srcpath(task.env))
692 installed_file = open(installed_location, 'w')
693 for line in source_file:
696 newline = line.replace(pattern, replacement)
697 installed_file.write(newline)
698 installed_file.close()
699 os.chmod(installed_location, 0755)
703 def install_file(bld, destdir, file, chmod=MODE_644, flat=False,
704 python_fixup=False, destname=None, base_name=None):
706 destdir = bld.EXPAND_VARIABLES(destdir)
710 destname = os.path.basename(destname)
711 dest = os.path.join(destdir, destname)
713 # fixup the python path it will use to find Samba modules
714 inst_file = file + '.inst'
715 bld.SAMBA_GENERATOR('python_%s' % destname,
716 rule=copy_and_fix_python_path,
719 bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONARCHDIR"])
720 bld.add_manual_dependency(bld.path.find_or_declare(inst_file), bld.env["PYTHONDIR"])
723 file = os.path.join(base_name, file)
724 bld.install_as(dest, file, chmod=chmod)
727 def INSTALL_FILES(bld, destdir, files, chmod=MODE_644, flat=False,
728 python_fixup=False, destname=None, base_name=None):
729 '''install a set of files'''
730 for f in TO_LIST(files):
731 install_file(bld, destdir, f, chmod=chmod, flat=flat,
732 python_fixup=python_fixup, destname=destname,
734 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
737 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=MODE_644, flat=False,
738 python_fixup=False, exclude=None, trim_path=None):
739 '''install a set of files matching a wildcard pattern'''
740 files=TO_LIST(bld.path.ant_glob(pattern))
744 files2.append(os_path_relpath(f, trim_path))
749 if fnmatch.fnmatch(f, exclude):
751 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat,
752 python_fixup=python_fixup, base_name=trim_path)
753 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
756 def INSTALL_DIRS(bld, destdir, dirs):
757 '''install a set of directories'''
758 destdir = bld.EXPAND_VARIABLES(destdir)
759 dirs = bld.EXPAND_VARIABLES(dirs)
760 for d in TO_LIST(dirs):
761 bld.install_dir(os.path.join(destdir, d))
762 Build.BuildContext.INSTALL_DIRS = INSTALL_DIRS
765 def MANPAGES(bld, manpages):
766 '''build and install manual pages'''
767 bld.env.MAN_XSL = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl'
768 for m in manpages.split():
770 bld.SAMBA_GENERATOR(m,
774 rule='${XSLTPROC} -o ${TGT} --nonet ${MAN_XSL} ${SRC}'
776 bld.INSTALL_FILES('${MANDIR}/man%s' % m[-1], m, flat=True)
777 Build.BuildContext.MANPAGES = MANPAGES
780 #############################################################
781 # give a nicer display when building different types of files
782 def progress_display(self, msg, fname):
783 col1 = Logs.colors(self.color)
784 col2 = Logs.colors.NORMAL
785 total = self.position[1]
787 fs = '[%%%dd/%%%dd] %s %%s%%s%%s\n' % (n, n, msg)
788 return fs % (self.position[0], self.position[1], col1, fname, col2)
790 def link_display(self):
791 if Options.options.progress_bar != 0:
792 return Task.Task.old_display(self)
793 fname = self.outputs[0].bldpath(self.env)
794 return progress_display(self, 'Linking', fname)
795 Task.TaskBase.classes['cc_link'].display = link_display
797 def samba_display(self):
798 if Options.options.progress_bar != 0:
799 return Task.Task.old_display(self)
801 targets = LOCAL_CACHE(self, 'TARGET_TYPE')
802 if self.name in targets:
803 target_type = targets[self.name]
804 type_map = { 'GENERATOR' : 'Generating',
805 'PROTOTYPE' : 'Generating'
807 if target_type in type_map:
808 return progress_display(self, type_map[target_type], self.name)
810 if len(self.inputs) == 0:
811 return Task.Task.old_display(self)
813 fname = self.inputs[0].bldpath(self.env)
814 if fname[0:3] == '../':
816 ext_loc = fname.rfind('.')
818 return Task.Task.old_display(self)
819 ext = fname[ext_loc:]
821 ext_map = { '.idl' : 'Compiling IDL',
822 '.et' : 'Compiling ERRTABLE',
823 '.asn1': 'Compiling ASN1',
826 return progress_display(self, ext_map[ext], fname)
827 return Task.Task.old_display(self)
829 Task.TaskBase.classes['Task'].old_display = Task.TaskBase.classes['Task'].display
830 Task.TaskBase.classes['Task'].display = samba_display
835 def apply_bundle_remove_dynamiclib_patch(self):
836 if self.env['MACBUNDLE'] or getattr(self,'mac_bundle',False):
837 if not getattr(self,'vnum',None):
839 self.env['LINKFLAGS'].remove('-dynamiclib')
840 self.env['LINKFLAGS'].remove('-single_module')