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
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 *
23 os.putenv('PYTHONUNBUFFERED', '1')
25 #################################################################
26 # create the samba build environment
28 def SAMBA_BUILD_ENV(conf):
29 conf.env['BUILD_DIRECTORY'] = conf.blddir
30 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
31 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
32 # this allows all of the bin/shared and bin/python targets
33 # to be expressed in terms of build directory paths
34 for p in ['python','shared']:
35 link_target = os.path.join(conf.blddir, 'default/' + p)
36 if not os.path.lexists(link_target):
37 os.symlink('../' + p, link_target)
41 ################################################################
42 # add an init_function to the list for a subsystem
43 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
44 if init_function is None:
46 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
47 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
48 if not subsystem in cache:
50 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
51 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
54 #################################################################
55 # define a Samba library
56 def SAMBA_LIBRARY(bld, libname, source,
63 external_library=False,
74 SET_TARGET_TYPE(bld, libname, 'DISABLED')
77 # remember empty libraries, so we can strip the dependencies
78 if (source == '') or (source == []):
79 SET_TARGET_TYPE(bld, libname, 'EMPTY')
82 if bld.env.DISABLE_SHARED:
85 obj_target = libname + '.objlist'
87 # first create a target for building the object files for this library
88 # by separating in this way, we avoid recompiling the C files
89 # separately for the install library and the build library
90 bld.SAMBA_SUBSYSTEM(obj_target,
93 public_deps = public_deps,
95 public_headers = public_headers,
98 autoproto = autoproto,
99 depends_on = depends_on,
100 local_include = local_include)
102 if bld.env.DISABLE_SHARED:
105 if not SET_TARGET_TYPE(bld, libname, 'LIBRARY'):
108 # the library itself will depend on that object target
109 deps += ' ' + public_deps
111 deps.append(obj_target)
113 bld.SET_BUILD_GROUP(group)
115 features = 'cc cshlib symlink_lib',
118 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
119 depends_on = depends_on,
121 samba_includes = includes,
122 local_include = local_include,
125 ldflags = build_rpath(bld)
128 if install_path is None:
129 install_path = '${LIBDIR}'
130 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
132 # we don't need the double libraries if rpath is off
133 if (bld.env.RPATH_ON_INSTALL == False and
134 bld.env.RPATH_ON_BUILD == False):
135 install_target = libname
137 install_target = libname + '.inst'
139 if install and install_target != libname:
140 # create a separate install library, which may have
141 # different rpath settings
142 SET_TARGET_TYPE(bld, install_target, 'LIBRARY')
144 features = 'cc cshlib',
146 target = install_target,
147 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
148 depends_on = depends_on,
150 samba_includes = includes,
151 local_include = local_include,
153 install_as = libname,
155 ldflags = install_rpath(bld)
160 vnum_base = vnum.split('.')[0]
161 install_name = 'lib%s.so.%s' % (libname, vnum)
162 install_link = 'lib%s.so.%s' % (libname, vnum_base)
164 install_name = 'lib%s.so' % libname
167 bld.install_as(os.path.join(install_path, install_name),
168 'lib%s.inst.so' % libname)
170 bld.symlink_as(os.path.join(install_path, install_link), install_name)
172 if autoproto is not None:
173 bld.SAMBA_AUTOPROTO(autoproto, source)
175 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
178 #################################################################
179 # define a Samba binary
180 def SAMBA_BINARY(bld, binname, source,
199 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
202 features = 'cc cprogram'
204 features += ' pyembed'
206 bld.SET_BUILD_GROUP(group)
208 obj_target = binname + '.objlist'
210 # first create a target for building the object files for this binary
211 # by separating in this way, we avoid recompiling the C files
212 # separately for the install binary and the build binary
213 bld.SAMBA_SUBSYSTEM(obj_target,
219 autoproto = autoproto,
220 subsystem_name = subsystem_name,
221 needs_python = needs_python,
222 local_include = local_include)
224 # the library itself will depend on that object target
226 deps.append(obj_target)
229 features = features + ' symlink_bin',
232 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
234 samba_includes = includes,
235 local_include = local_include,
236 samba_modules = modules,
238 samba_subsystem= subsystem_name,
240 ldflags = build_rpath(bld)
243 if install_path is None:
244 install_path = '${BINDIR}'
245 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
247 # we don't need the double binaries if rpath is off
248 if (bld.env.RPATH_ON_INSTALL == False and
249 bld.env.RPATH_ON_BUILD == False):
250 install_target = binname
252 install_target = binname + '.inst'
254 if install and install_target != binname:
255 # we create a separate 'install' binary, which
256 # will have different rpath settings
257 SET_TARGET_TYPE(bld, install_target, 'BINARY')
261 target = install_target,
262 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
264 samba_includes = includes,
265 local_include = local_include,
266 samba_modules = modules,
268 samba_subsystem= subsystem_name,
270 ldflags = install_rpath(bld)
274 bld.install_as(os.path.join(install_path, binname),
278 # setup the subsystem_name as an alias for the real
279 # binary name, so it can be found when expanding
280 # subsystem dependencies
281 if subsystem_name is not None:
282 bld.TARGET_ALIAS(subsystem_name, binname)
284 if autoproto is not None:
285 bld.SAMBA_AUTOPROTO(autoproto, source)
286 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
289 #################################################################
290 # define a Samba module.
291 def SAMBA_MODULE(bld, modname, source,
297 autoproto_extra_source='',
300 internal_module=True,
304 # we add the init function regardless of whether the module
305 # is enabled or not, as we need to generate a null list if
307 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
309 if internal_module or bld.env.DISABLE_SHARED:
310 # treat internal modules as subsystems for now
311 SAMBA_SUBSYSTEM(bld, modname, source,
315 autoproto_extra_source=autoproto_extra_source,
317 local_include=local_include,
322 SET_TARGET_TYPE(bld, modname, 'DISABLED')
325 # remember empty modules, so we can strip the dependencies
326 if (source == '') or (source == []):
327 SET_TARGET_TYPE(bld, modname, 'EMPTY')
330 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
333 if subsystem is not None:
334 deps += ' ' + subsystem
336 bld.SET_BUILD_GROUP('main')
341 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
342 samba_includes = includes,
343 local_include = local_include,
344 samba_deps = TO_LIST(deps)
347 if autoproto is not None:
348 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
350 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
353 #################################################################
354 # define a Samba subsystem
355 def SAMBA_SUBSYSTEM(bld, modname, source,
363 init_function_sentinal=None,
364 heimdal_autoproto=None,
365 heimdal_autoproto_options=None,
366 heimdal_autoproto_private=None,
368 autoproto_extra_source='',
371 local_include_first=True,
377 SET_TARGET_TYPE(bld, modname, 'DISABLED')
380 # remember empty subsystems, so we can strip the dependencies
381 if (source == '') or (source == []):
382 SET_TARGET_TYPE(bld, modname, 'EMPTY')
385 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
388 deps += ' ' + public_deps
390 bld.SET_BUILD_GROUP(group)
400 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
401 depends_on = depends_on,
402 samba_deps = TO_LIST(deps),
403 samba_includes = includes,
404 local_include = local_include,
405 local_include_first = local_include_first,
406 samba_subsystem= subsystem_name
409 if cflags_end is not None:
410 t.samba_cflags.extend(TO_LIST(cflags_end))
412 if heimdal_autoproto is not None:
413 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source, options=heimdal_autoproto_options)
414 if heimdal_autoproto_private is not None:
415 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
416 if autoproto is not None:
417 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
420 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
423 def SAMBA_GENERATOR(bld, name, rule, source, target,
424 group='build_source', enabled=True):
425 '''A generic source generator target'''
427 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
433 bld.SET_BUILD_GROUP(group)
441 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
445 ###############################################################
446 # add a new set of build rules from a subdirectory
447 # the @runonce decorator ensures we don't end up
448 # with duplicate rules
449 def BUILD_SUBDIR(bld, dir):
450 path = os.path.normpath(bld.curdir + '/' + dir)
451 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
452 if path in cache: return
454 debug("build: Processing subdirectory %s" % dir)
457 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
460 ##########################################################
461 # add a new top level command to waf
462 def ADD_COMMAND(opt, name, function):
463 Utils.g_module.__dict__[name] = function
465 Options.Handler.ADD_COMMAND = ADD_COMMAND
467 ###########################################################
468 # setup build groups used to ensure that the different build
469 # phases happen consecutively
471 def SETUP_BUILD_GROUPS(bld):
472 bld.p_ln = bld.srcnode # we do want to see all targets!
473 bld.env['USING_BUILD_GROUPS'] = True
474 bld.add_group('setup')
475 bld.add_group('build_compiler_source')
476 bld.add_group('base_libraries')
477 bld.add_group('build_compilers')
478 bld.add_group('build_source')
479 bld.add_group('prototypes')
480 bld.add_group('main')
481 bld.add_group('binaries')
482 bld.add_group('final')
483 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
486 ###########################################################
487 # set the current build group
488 def SET_BUILD_GROUP(bld, group):
489 if not 'USING_BUILD_GROUPS' in bld.env:
492 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
495 def h_file(filename):
497 st = os.stat(filename)
498 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
500 m.update(str(st.st_mtime))
501 m.update(str(st.st_size))
506 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
507 Utils.h_file = h_file
510 ##############################
511 # handle the creation of links for libraries and binaries
512 # note that we use a relative symlink path to allow the whole tree
513 # to me moved/copied elsewhere without breaking the links
514 t = Task.simple_task_type('symlink_lib', 'ln -sf ${LINK_SOURCE} ${LINK_TARGET}',
515 color='PINK', ext_in='.bin')
518 @feature('symlink_lib')
520 def symlink_lib(self):
521 tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
523 # calculat the link target and put it in the environment
525 vnum = getattr(self, 'vnum', None)
527 soext = '.' + vnum.split('.')[0]
529 link_target = getattr(self, 'link_name', '')
530 if link_target == '':
531 link_target = '%s/lib%s.so%s' % (LIB_PATH, self.sname, soext)
534 link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
535 os.path.join(self.env.BUILD_DIRECTORY, link_target))
537 tsk.env.LINK_TARGET = link_target
538 tsk.env.LINK_SOURCE = link_source[3:]
539 debug('task_gen: LINK for %s is %s -> %s',
540 self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
543 t = Task.simple_task_type('symlink_bin', 'ln -sf ${SRC} ${BIN_TARGET}',
544 color='PINK', ext_in='.bin')
547 @feature('symlink_bin')
549 def symlink_bin(self):
550 if Options.is_install:
551 # we don't want to copy the install binary, as
552 # that has the install rpath, not the build rpath
553 # The rpath of the binaries in bin/default/foo/blah is different
554 # during the install phase, as distros insist on not using rpath in installed binaries
556 tsk = self.create_task('symlink_bin', self.link_task.outputs[0])
558 tsk.env.BIN_TARGET = self.target
559 debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
564 t = Task.simple_task_type('copy_script', 'ln -sf ${SRC[0].abspath(env)} ${LINK_TARGET}',
565 color='PINK', ext_in='.bin', shell=True)
568 @feature('copy_script')
569 @before('apply_link')
570 def copy_script(self):
571 tsk = self.create_task('copy_script', self.allnodes[0])
572 tsk.env.TARGET = self.target
574 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
575 '''used to copy scripts from the source tree into the build directory
576 for use by selftest'''
578 source = bld.path.ant_glob(pattern)
580 bld.SET_BUILD_GROUP('build_source')
581 for s in TO_LIST(source):
583 if installname != None:
585 target = os.path.join(installdir, iname)
586 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
588 t = bld(features='copy_script',
593 t.env.LINK_TARGET = target
595 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT