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,
75 SET_TARGET_TYPE(bld, libname, 'DISABLED')
78 source = bld.EXPAND_VARIABLES(source, vars=vars)
80 # remember empty libraries, so we can strip the dependencies
81 if (source == '') or (source == []):
82 SET_TARGET_TYPE(bld, libname, 'EMPTY')
85 if bld.env.DISABLE_SHARED:
88 obj_target = libname + '.objlist'
90 # first create a target for building the object files for this library
91 # by separating in this way, we avoid recompiling the C files
92 # separately for the install library and the build library
93 bld.SAMBA_SUBSYSTEM(obj_target,
96 public_deps = public_deps,
98 public_headers = public_headers,
101 autoproto = autoproto,
102 depends_on = depends_on,
103 local_include = local_include)
105 if bld.env.DISABLE_SHARED:
108 if not SET_TARGET_TYPE(bld, libname, 'LIBRARY'):
111 # the library itself will depend on that object target
112 deps += ' ' + public_deps
114 deps.append(obj_target)
116 bld.SET_BUILD_GROUP(group)
118 features = 'cc cshlib symlink_lib',
121 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
122 depends_on = depends_on,
124 samba_includes = includes,
125 local_include = local_include,
128 ldflags = build_rpath(bld)
131 if install_path is None:
132 install_path = '${LIBDIR}'
133 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
135 # we don't need the double libraries if rpath is off
136 if (bld.env.RPATH_ON_INSTALL == False and
137 bld.env.RPATH_ON_BUILD == False):
138 install_target = libname
140 install_target = libname + '.inst'
142 if install and install_target != libname:
143 # create a separate install library, which may have
144 # different rpath settings
145 SET_TARGET_TYPE(bld, install_target, 'LIBRARY')
147 features = 'cc cshlib',
149 target = install_target,
150 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
151 depends_on = depends_on,
153 samba_includes = includes,
154 local_include = local_include,
156 install_as = libname,
158 ldflags = install_rpath(bld)
163 vnum_base = vnum.split('.')[0]
164 install_name = 'lib%s.so.%s' % (libname, vnum)
165 install_link = 'lib%s.so.%s' % (libname, vnum_base)
167 install_name = 'lib%s.so' % libname
170 bld.install_as(os.path.join(install_path, install_name),
171 'lib%s.inst.so' % libname)
173 bld.symlink_as(os.path.join(install_path, install_link), install_name)
175 if autoproto is not None:
176 bld.SAMBA_AUTOPROTO(autoproto, source)
178 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
181 #################################################################
182 # define a Samba binary
183 def SAMBA_BINARY(bld, binname, source,
203 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
206 features = 'cc cprogram'
208 features += ' pyembed'
210 bld.SET_BUILD_GROUP(group)
212 obj_target = binname + '.objlist'
214 source = bld.EXPAND_VARIABLES(source, vars=vars)
216 # first create a target for building the object files for this binary
217 # by separating in this way, we avoid recompiling the C files
218 # separately for the install binary and the build binary
219 bld.SAMBA_SUBSYSTEM(obj_target,
225 autoproto = autoproto,
226 subsystem_name = subsystem_name,
227 needs_python = needs_python,
228 local_include = local_include)
230 # the library itself will depend on that object target
232 deps.append(obj_target)
235 features = features + ' symlink_bin',
238 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
240 samba_includes = includes,
241 local_include = local_include,
242 samba_modules = modules,
244 samba_subsystem= subsystem_name,
246 ldflags = build_rpath(bld)
249 if install_path is None:
250 install_path = '${BINDIR}'
251 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
253 # we don't need the double binaries if rpath is off
254 if (bld.env.RPATH_ON_INSTALL == False and
255 bld.env.RPATH_ON_BUILD == False):
256 install_target = binname
258 install_target = binname + '.inst'
260 if install and install_target != binname:
261 # we create a separate 'install' binary, which
262 # will have different rpath settings
263 SET_TARGET_TYPE(bld, install_target, 'BINARY')
267 target = install_target,
268 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
270 samba_includes = includes,
271 local_include = local_include,
272 samba_modules = modules,
274 samba_subsystem= subsystem_name,
276 ldflags = install_rpath(bld)
280 bld.install_as(os.path.join(install_path, binname),
284 # setup the subsystem_name as an alias for the real
285 # binary name, so it can be found when expanding
286 # subsystem dependencies
287 if subsystem_name is not None:
288 bld.TARGET_ALIAS(subsystem_name, binname)
290 if autoproto is not None:
291 bld.SAMBA_AUTOPROTO(autoproto, source)
292 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
295 #################################################################
296 # define a Samba module.
297 def SAMBA_MODULE(bld, modname, source,
303 autoproto_extra_source='',
306 internal_module=True,
311 # we add the init function regardless of whether the module
312 # is enabled or not, as we need to generate a null list if
314 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
316 if internal_module or bld.env.DISABLE_SHARED:
317 # treat internal modules as subsystems for now
318 SAMBA_SUBSYSTEM(bld, modname, source,
322 autoproto_extra_source=autoproto_extra_source,
324 local_include=local_include,
329 SET_TARGET_TYPE(bld, modname, 'DISABLED')
332 source = bld.EXPAND_VARIABLES(source, vars=vars)
334 # remember empty modules, so we can strip the dependencies
335 if (source == '') or (source == []):
336 SET_TARGET_TYPE(bld, modname, 'EMPTY')
339 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
342 if subsystem is not None:
343 deps += ' ' + subsystem
345 bld.SET_BUILD_GROUP('main')
350 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
351 samba_includes = includes,
352 local_include = local_include,
353 samba_deps = TO_LIST(deps)
356 if autoproto is not None:
357 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
359 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
362 #################################################################
363 # define a Samba subsystem
364 def SAMBA_SUBSYSTEM(bld, modname, source,
372 init_function_sentinal=None,
373 heimdal_autoproto=None,
374 heimdal_autoproto_options=None,
375 heimdal_autoproto_private=None,
377 autoproto_extra_source='',
380 local_include_first=True,
387 SET_TARGET_TYPE(bld, modname, 'DISABLED')
390 # remember empty subsystems, so we can strip the dependencies
391 if (source == '') or (source == []):
392 SET_TARGET_TYPE(bld, modname, 'EMPTY')
395 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
398 source = bld.EXPAND_VARIABLES(source, vars=vars)
400 deps += ' ' + public_deps
402 bld.SET_BUILD_GROUP(group)
412 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
413 depends_on = depends_on,
414 samba_deps = TO_LIST(deps),
415 samba_includes = includes,
416 local_include = local_include,
417 local_include_first = local_include_first,
418 samba_subsystem= subsystem_name
421 if cflags_end is not None:
422 t.samba_cflags.extend(TO_LIST(cflags_end))
424 if heimdal_autoproto is not None:
425 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source, options=heimdal_autoproto_options)
426 if heimdal_autoproto_private is not None:
427 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
428 if autoproto is not None:
429 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
432 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
435 def SAMBA_GENERATOR(bld, name, rule, source, target,
436 group='build_source', enabled=True,
438 '''A generic source generator target'''
440 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
446 bld.SET_BUILD_GROUP(group)
449 source=bld.EXPAND_VARIABLES(source, vars=vars),
456 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
460 ###############################################################
461 # add a new set of build rules from a subdirectory
462 # the @runonce decorator ensures we don't end up
463 # with duplicate rules
464 def BUILD_SUBDIR(bld, dir):
465 path = os.path.normpath(bld.curdir + '/' + dir)
466 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
467 if path in cache: return
469 debug("build: Processing subdirectory %s" % dir)
472 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
475 ##########################################################
476 # add a new top level command to waf
477 def ADD_COMMAND(opt, name, function):
478 Utils.g_module.__dict__[name] = function
480 Options.Handler.ADD_COMMAND = ADD_COMMAND
482 ###########################################################
483 # setup build groups used to ensure that the different build
484 # phases happen consecutively
486 def SETUP_BUILD_GROUPS(bld):
487 bld.p_ln = bld.srcnode # we do want to see all targets!
488 bld.env['USING_BUILD_GROUPS'] = True
489 bld.add_group('setup')
490 bld.add_group('build_compiler_source')
491 bld.add_group('base_libraries')
492 bld.add_group('build_compilers')
493 bld.add_group('build_source')
494 bld.add_group('prototypes')
495 bld.add_group('main')
496 bld.add_group('binaries')
497 bld.add_group('final')
498 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
501 ###########################################################
502 # set the current build group
503 def SET_BUILD_GROUP(bld, group):
504 if not 'USING_BUILD_GROUPS' in bld.env:
507 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
510 def h_file(filename):
512 st = os.stat(filename)
513 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
515 m.update(str(st.st_mtime))
516 m.update(str(st.st_size))
521 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
522 Utils.h_file = h_file
525 ##############################
526 # handle the creation of links for libraries and binaries
527 # note that we use a relative symlink path to allow the whole tree
528 # to me moved/copied elsewhere without breaking the links
529 t = Task.simple_task_type('symlink_lib', 'rm -f ${LINK_TARGET} && ln -s ${LINK_SOURCE} ${LINK_TARGET}',
530 shell=True, color='PINK', ext_in='.bin')
533 @feature('symlink_lib')
535 def symlink_lib(self):
536 tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
538 # calculat the link target and put it in the environment
540 vnum = getattr(self, 'vnum', None)
542 soext = '.' + vnum.split('.')[0]
544 link_target = getattr(self, 'link_name', '')
545 if link_target == '':
546 link_target = '%s/lib%s.so%s' % (LIB_PATH, self.sname, soext)
549 link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
550 os.path.join(self.env.BUILD_DIRECTORY, link_target))
552 tsk.env.LINK_TARGET = link_target
553 tsk.env.LINK_SOURCE = link_source[3:]
554 debug('task_gen: LINK for %s is %s -> %s',
555 self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
558 t = Task.simple_task_type('symlink_bin', 'rm -f ${BIN_TARGET} && ln -s ${SRC} ${BIN_TARGET}',
559 shell=True, color='PINK', ext_in='.bin')
562 @feature('symlink_bin')
564 def symlink_bin(self):
565 if Options.is_install:
566 # we don't want to copy the install binary, as
567 # that has the install rpath, not the build rpath
568 # The rpath of the binaries in bin/default/foo/blah is different
569 # during the install phase, as distros insist on not using rpath in installed binaries
571 tsk = self.create_task('symlink_bin', self.link_task.outputs[0])
573 tsk.env.BIN_TARGET = self.target
574 debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
579 t = Task.simple_task_type('copy_script', 'rm -f && ln -s ${SRC[0].abspath(env)} ${LINK_TARGET}',
580 shell=True, color='PINK', ext_in='.bin')
583 @feature('copy_script')
584 @before('apply_link')
585 def copy_script(self):
586 tsk = self.create_task('copy_script', self.allnodes[0])
587 tsk.env.TARGET = self.target
589 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
590 '''used to copy scripts from the source tree into the build directory
591 for use by selftest'''
593 source = bld.path.ant_glob(pattern)
595 bld.SET_BUILD_GROUP('build_source')
596 for s in TO_LIST(source):
598 if installname != None:
600 target = os.path.join(installdir, iname)
601 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
603 t = bld(features='copy_script',
608 t.env.LINK_TARGET = target
610 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT