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, Options, Task, Utils, cc, TaskGen, fnmatch
5 from Configure import conf
7 from samba_utils import SUBST_VARS_RECURSIVE
9 # bring in the other samba modules
10 from samba_optimisation import *
11 from samba_utils import *
12 from samba_autoconf import *
13 from samba_patterns import *
14 from samba_pidl import *
15 from samba_errtable import *
16 from samba_asn1 import *
17 from samba_autoproto import *
18 from samba_python import *
19 from samba_deps import *
20 import samba_conftests
24 os.putenv('PYTHONUNBUFFERED', '1')
26 #################################################################
27 # create the samba build environment
29 def SAMBA_BUILD_ENV(conf):
30 conf.env['BUILD_DIRECTORY'] = conf.blddir
31 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
32 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
33 # this allows all of the bin/shared and bin/python targets
34 # to be expressed in terms of build directory paths
35 for p in ['python','shared']:
36 link_target = os.path.join(conf.blddir, 'default/' + p)
37 if not os.path.lexists(link_target):
38 os.symlink('../' + p, link_target)
40 # get perl to put the blib files in the build directory
41 blib_bld = os.path.join(conf.blddir, 'default/pidl/blib')
42 blib_src = os.path.join(conf.srcdir, 'pidl/blib')
43 mkdir_p(blib_bld + '/man1')
44 mkdir_p(blib_bld + '/man3')
45 if not os.path.lexists(blib_src):
46 os.symlink(blib_bld, blib_src)
50 ################################################################
51 # add an init_function to the list for a subsystem
52 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
53 if init_function is None:
55 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
56 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
57 if not subsystem in cache:
59 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
60 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
63 #################################################################
64 # define a Samba library
65 def SAMBA_LIBRARY(bld, libname, source,
73 external_library=False,
85 SET_TARGET_TYPE(bld, libname, 'DISABLED')
88 source = bld.EXPAND_VARIABLES(source, vars=vars)
90 # remember empty libraries, so we can strip the dependencies
91 if (source == '') or (source == []):
92 SET_TARGET_TYPE(bld, libname, 'EMPTY')
95 if bld.env.DISABLE_SHARED:
98 obj_target = libname + '.objlist'
100 # first create a target for building the object files for this library
101 # by separating in this way, we avoid recompiling the C files
102 # separately for the install library and the build library
103 bld.SAMBA_SUBSYSTEM(obj_target,
106 public_deps = public_deps,
108 public_headers = public_headers,
109 header_path = header_path,
112 autoproto = autoproto,
113 depends_on = depends_on,
114 local_include = local_include)
116 if bld.env.DISABLE_SHARED:
119 if not SET_TARGET_TYPE(bld, libname, 'LIBRARY'):
122 # the library itself will depend on that object target
123 deps += ' ' + public_deps
125 deps.append(obj_target)
127 bld.SET_BUILD_GROUP(group)
129 features = 'cc cshlib symlink_lib',
132 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
133 depends_on = depends_on,
135 samba_includes = includes,
136 local_include = local_include,
139 ldflags = build_rpath(bld)
142 if install_path is None:
143 install_path = '${LIBDIR}'
144 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
146 # we don't need the double libraries if rpath is off
147 if (bld.env.RPATH_ON_INSTALL == False and
148 bld.env.RPATH_ON_BUILD == False):
149 install_target = libname
151 install_target = libname + '.inst'
153 if install and install_target != libname:
154 # create a separate install library, which may have
155 # different rpath settings
156 SET_TARGET_TYPE(bld, install_target, 'LIBRARY')
158 features = 'cc cshlib',
160 target = install_target,
161 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
162 depends_on = depends_on,
164 samba_includes = includes,
165 local_include = local_include,
167 install_as = libname,
169 ldflags = install_rpath(bld)
174 vnum_base = vnum.split('.')[0]
175 install_name = 'lib%s.so.%s' % (libname, vnum)
176 install_link = 'lib%s.so.%s' % (libname, vnum_base)
178 install_name = 'lib%s.so' % libname
181 bld.install_as(os.path.join(install_path, install_name),
182 'lib%s.inst.so' % libname)
184 bld.symlink_as(os.path.join(install_path, install_link), install_name)
186 if autoproto is not None:
187 bld.SAMBA_AUTOPROTO(autoproto, source)
189 if public_headers is not None:
190 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
192 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
195 #################################################################
196 # define a Samba binary
197 def SAMBA_BINARY(bld, binname, source,
218 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
221 features = 'cc cprogram'
223 features += ' pyembed'
225 bld.SET_BUILD_GROUP(group)
227 obj_target = binname + '.objlist'
229 source = bld.EXPAND_VARIABLES(source, vars=vars)
231 # first create a target for building the object files for this binary
232 # by separating in this way, we avoid recompiling the C files
233 # separately for the install binary and the build binary
234 bld.SAMBA_SUBSYSTEM(obj_target,
240 autoproto = autoproto,
241 subsystem_name = subsystem_name,
242 needs_python = needs_python,
243 local_include = local_include)
245 # the library itself will depend on that object target
247 deps.append(obj_target)
250 features = features + ' symlink_bin',
253 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
255 samba_includes = includes,
256 local_include = local_include,
257 samba_modules = modules,
259 samba_subsystem= subsystem_name,
261 ldflags = build_rpath(bld)
264 if install_path is None:
265 install_path = '${BINDIR}'
266 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
268 # we don't need the double binaries if rpath is off
269 if (bld.env.RPATH_ON_INSTALL == False and
270 bld.env.RPATH_ON_BUILD == False):
271 install_target = binname
273 install_target = binname + '.inst'
275 if install and install_target != binname:
276 # we create a separate 'install' binary, which
277 # will have different rpath settings
278 SET_TARGET_TYPE(bld, install_target, 'BINARY')
282 target = install_target,
283 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
285 samba_includes = includes,
286 local_include = local_include,
287 samba_modules = modules,
289 samba_subsystem= subsystem_name,
291 ldflags = install_rpath(bld)
295 bld.install_as(os.path.join(install_path, binname),
299 # setup the subsystem_name as an alias for the real
300 # binary name, so it can be found when expanding
301 # subsystem dependencies
302 if subsystem_name is not None:
303 bld.TARGET_ALIAS(subsystem_name, binname)
305 if autoproto is not None:
306 bld.SAMBA_AUTOPROTO(autoproto, source)
307 if public_headers is not None:
308 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
309 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
312 #################################################################
313 # define a Samba module.
314 def SAMBA_MODULE(bld, modname, source,
320 autoproto_extra_source='',
323 internal_module=True,
328 # we add the init function regardless of whether the module
329 # is enabled or not, as we need to generate a null list if
331 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
333 if internal_module or bld.env.DISABLE_SHARED:
334 # treat internal modules as subsystems for now
335 SAMBA_SUBSYSTEM(bld, modname, source,
339 autoproto_extra_source=autoproto_extra_source,
341 local_include=local_include,
346 SET_TARGET_TYPE(bld, modname, 'DISABLED')
349 source = bld.EXPAND_VARIABLES(source, vars=vars)
351 # remember empty modules, so we can strip the dependencies
352 if (source == '') or (source == []):
353 SET_TARGET_TYPE(bld, modname, 'EMPTY')
356 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
359 if subsystem is not None:
360 deps += ' ' + subsystem
362 bld.SET_BUILD_GROUP('main')
367 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
368 samba_includes = includes,
369 local_include = local_include,
370 samba_deps = TO_LIST(deps)
373 if autoproto is not None:
374 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
376 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
379 #################################################################
380 # define a Samba subsystem
381 def SAMBA_SUBSYSTEM(bld, modname, source,
390 init_function_sentinal=None,
391 heimdal_autoproto=None,
392 heimdal_autoproto_options=None,
393 heimdal_autoproto_private=None,
395 autoproto_extra_source='',
398 local_include_first=True,
405 SET_TARGET_TYPE(bld, modname, 'DISABLED')
408 # remember empty subsystems, so we can strip the dependencies
409 if (source == '') or (source == []):
410 SET_TARGET_TYPE(bld, modname, 'EMPTY')
413 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
416 source = bld.EXPAND_VARIABLES(source, vars=vars)
418 deps += ' ' + public_deps
420 bld.SET_BUILD_GROUP(group)
430 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
431 depends_on = depends_on,
432 samba_deps = TO_LIST(deps),
433 samba_includes = includes,
434 local_include = local_include,
435 local_include_first = local_include_first,
436 samba_subsystem= subsystem_name
439 if cflags_end is not None:
440 t.samba_cflags.extend(TO_LIST(cflags_end))
442 if heimdal_autoproto is not None:
443 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source, options=heimdal_autoproto_options)
444 if heimdal_autoproto_private is not None:
445 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
446 if autoproto is not None:
447 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
448 if public_headers is not None:
449 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
453 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
456 def SAMBA_GENERATOR(bld, name, rule, source, target,
457 group='build_source', enabled=True,
461 '''A generic source generator target'''
463 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
469 bld.SET_BUILD_GROUP(group)
472 source=bld.EXPAND_VARIABLES(source, vars=vars),
480 if public_headers is not None:
481 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
483 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
487 ###############################################################
488 # add a new set of build rules from a subdirectory
489 # the @runonce decorator ensures we don't end up
490 # with duplicate rules
491 def BUILD_SUBDIR(bld, dir):
492 path = os.path.normpath(bld.curdir + '/' + dir)
493 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
494 if path in cache: return
496 debug("build: Processing subdirectory %s" % dir)
499 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
502 ##########################################################
503 # add a new top level command to waf
504 def ADD_COMMAND(opt, name, function):
505 Utils.g_module.__dict__[name] = function
507 Options.Handler.ADD_COMMAND = ADD_COMMAND
509 ###########################################################
510 # setup build groups used to ensure that the different build
511 # phases happen consecutively
513 def SETUP_BUILD_GROUPS(bld):
514 bld.p_ln = bld.srcnode # we do want to see all targets!
515 bld.env['USING_BUILD_GROUPS'] = True
516 bld.add_group('setup')
517 bld.add_group('build_compiler_source')
518 bld.add_group('base_libraries')
519 bld.add_group('build_compilers')
520 bld.add_group('build_source')
521 bld.add_group('prototypes')
522 bld.add_group('main')
523 bld.add_group('binaries')
524 bld.add_group('final')
525 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
528 ###########################################################
529 # set the current build group
530 def SET_BUILD_GROUP(bld, group):
531 if not 'USING_BUILD_GROUPS' in bld.env:
534 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
537 def h_file(filename):
539 st = os.stat(filename)
540 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
542 m.update(str(st.st_mtime))
543 m.update(str(st.st_size))
548 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
549 Utils.h_file = h_file
552 ##############################
553 # handle the creation of links for libraries and binaries
554 # note that we use a relative symlink path to allow the whole tree
555 # to me moved/copied elsewhere without breaking the links
556 t = Task.simple_task_type('symlink_lib', 'rm -f ${LINK_TARGET} && ln -s ${LINK_SOURCE} ${LINK_TARGET}',
557 shell=True, color='PINK', ext_in='.bin')
560 @feature('symlink_lib')
562 def symlink_lib(self):
563 tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
565 # calculat the link target and put it in the environment
567 vnum = getattr(self, 'vnum', None)
569 soext = '.' + vnum.split('.')[0]
571 link_target = getattr(self, 'link_name', '')
572 if link_target == '':
573 link_target = '%s/lib%s.so%s' % (LIB_PATH, self.sname, soext)
576 link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
577 os.path.join(self.env.BUILD_DIRECTORY, link_target))
579 tsk.env.LINK_TARGET = link_target
580 tsk.env.LINK_SOURCE = link_source[3:]
581 debug('task_gen: LINK for %s is %s -> %s',
582 self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
585 t = Task.simple_task_type('symlink_bin', 'rm -f ${BIN_TARGET} && ln -s ${SRC} ${BIN_TARGET}',
586 shell=True, color='PINK', ext_in='.bin')
589 @feature('symlink_bin')
591 def symlink_bin(self):
592 if Options.is_install:
593 # we don't want to copy the install binary, as
594 # that has the install rpath, not the build rpath
595 # The rpath of the binaries in bin/default/foo/blah is different
596 # during the install phase, as distros insist on not using rpath in installed binaries
598 tsk = self.create_task('symlink_bin', self.link_task.outputs[0])
600 tsk.env.BIN_TARGET = self.target
601 debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
606 t = Task.simple_task_type('copy_script', 'rm -f ${LINK_TARGET} && ln -s ${SRC[0].abspath(env)} ${LINK_TARGET}',
607 shell=True, color='PINK', ext_in='.bin')
610 @feature('copy_script')
611 @before('apply_link')
612 def copy_script(self):
613 tsk = self.create_task('copy_script', self.allnodes[0])
614 tsk.env.TARGET = self.target
616 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
617 '''used to copy scripts from the source tree into the build directory
618 for use by selftest'''
620 source = bld.path.ant_glob(pattern)
622 bld.SET_BUILD_GROUP('build_source')
623 for s in TO_LIST(source):
625 if installname != None:
627 target = os.path.join(installdir, iname)
628 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
630 t = bld(features='copy_script',
635 t.env.LINK_TARGET = target
637 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
640 def INSTALL_FILES(bld, destdir, files, chmod=0644, flat=False,
641 python_fixup=False, destname=None):
642 '''install a set of files'''
643 destdir = bld.EXPAND_VARIABLES(destdir)
645 bld.install_as(os.path.join(destdir,destname), files, chmod=chmod)
647 bld.install_files(destdir, files, chmod=chmod, relative_trick=not flat)
648 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
651 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=0644, flat=False,
652 python_fixup=False, exclude=None):
653 '''install a set of files matching a wildcard pattern'''
654 files=TO_LIST(bld.path.ant_glob(pattern))
657 if fnmatch.fnmatch(f, exclude):
659 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat, python_fixup=python_fixup)
660 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
663 def PUBLIC_HEADERS(bld, public_headers, header_path=None):
664 '''install some headers
666 header_path may either be a string that is added to the INCLUDEDIR,
667 or it can be a dictionary of wildcard patterns which map to destination
668 directories relative to INCLUDEDIR
670 dest = '${INCLUDEDIR}'
671 if isinstance(header_path, str):
672 dest += '/' + header_path
673 for h in TO_LIST(public_headers):
675 if isinstance(header_path, list):
676 for (p1, dir) in header_path:
680 if fnmatch.fnmatch(h, p2):
682 hdest = os.path.join(hdest, dir)
685 if found_match: break
686 if h.find(':') != -1:
688 INSTALL_FILES(bld, hdest, hs[0], flat=True, destname=hs[1])
690 INSTALL_FILES(bld, hdest, h, flat=True)
691 Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS