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)
443 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
447 ###############################################################
448 # add a new set of build rules from a subdirectory
449 # the @runonce decorator ensures we don't end up
450 # with duplicate rules
451 def BUILD_SUBDIR(bld, dir):
452 path = os.path.normpath(bld.curdir + '/' + dir)
453 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
454 if path in cache: return
456 debug("build: Processing subdirectory %s" % dir)
459 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
462 ##########################################################
463 # add a new top level command to waf
464 def ADD_COMMAND(opt, name, function):
465 Utils.g_module.__dict__[name] = function
467 Options.Handler.ADD_COMMAND = ADD_COMMAND
469 ###########################################################
470 # setup build groups used to ensure that the different build
471 # phases happen consecutively
473 def SETUP_BUILD_GROUPS(bld):
474 bld.p_ln = bld.srcnode # we do want to see all targets!
475 bld.env['USING_BUILD_GROUPS'] = True
476 bld.add_group('setup')
477 bld.add_group('build_compiler_source')
478 bld.add_group('base_libraries')
479 bld.add_group('build_compilers')
480 bld.add_group('build_source')
481 bld.add_group('prototypes')
482 bld.add_group('main')
483 bld.add_group('binaries')
484 bld.add_group('final')
485 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
488 ###########################################################
489 # set the current build group
490 def SET_BUILD_GROUP(bld, group):
491 if not 'USING_BUILD_GROUPS' in bld.env:
494 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
497 def h_file(filename):
499 st = os.stat(filename)
500 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
502 m.update(str(st.st_mtime))
503 m.update(str(st.st_size))
508 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
509 Utils.h_file = h_file
512 ##############################
513 # handle the creation of links for libraries and binaries
514 # note that we use a relative symlink path to allow the whole tree
515 # to me moved/copied elsewhere without breaking the links
516 t = Task.simple_task_type('symlink_lib', 'ln -sf ${LINK_SOURCE} ${LINK_TARGET}',
517 color='PINK', ext_in='.bin')
520 @feature('symlink_lib')
522 def symlink_lib(self):
523 tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
525 # calculat the link target and put it in the environment
527 vnum = getattr(self, 'vnum', None)
529 soext = '.' + vnum.split('.')[0]
531 link_target = getattr(self, 'link_name', '')
532 if link_target == '':
533 link_target = '%s/lib%s.so%s' % (LIB_PATH, self.sname, soext)
536 link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
537 os.path.join(self.env.BUILD_DIRECTORY, link_target))
539 tsk.env.LINK_TARGET = link_target
540 tsk.env.LINK_SOURCE = link_source[3:]
541 debug('task_gen: LINK for %s is %s -> %s',
542 self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
545 t = Task.simple_task_type('symlink_bin', 'ln -sf ${SRC} ${BIN_TARGET}',
546 color='PINK', ext_in='.bin')
549 @feature('symlink_bin')
551 def symlink_bin(self):
552 if Options.is_install:
553 # we don't want to copy the install binary, as
554 # that has the install rpath, not the build rpath
555 # The rpath of the binaries in bin/default/foo/blah is different
556 # during the install phase, as distros insist on not using rpath in installed binaries
558 tsk = self.create_task('symlink_bin', self.link_task.outputs[0])
560 tsk.env.BIN_TARGET = self.target
561 debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
566 t = Task.simple_task_type('copy_script', 'ln -sf ${SRC[0].abspath(env)} ${LINK_TARGET}',
567 color='PINK', ext_in='.bin', shell=True)
570 @feature('copy_script')
571 @before('apply_link')
572 def copy_script(self):
573 tsk = self.create_task('copy_script', self.allnodes[0])
574 tsk.env.TARGET = self.target
576 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
577 '''used to copy scripts from the source tree into the build directory
578 for use by selftest'''
580 source = bld.path.ant_glob(pattern)
582 bld.SET_BUILD_GROUP('build_source')
583 for s in TO_LIST(source):
585 if installname != None:
587 target = os.path.join(installdir, iname)
588 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
590 t = bld(features='copy_script',
595 t.env.LINK_TARGET = target
597 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT