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 *
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)
42 ################################################################
43 # add an init_function to the list for a subsystem
44 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
45 if init_function is None:
47 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
48 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
49 if not subsystem in cache:
51 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
52 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
55 #################################################################
56 # define a Samba library
57 def SAMBA_LIBRARY(bld, libname, source,
65 external_library=False,
77 SET_TARGET_TYPE(bld, libname, 'DISABLED')
80 source = bld.EXPAND_VARIABLES(source, vars=vars)
82 # remember empty libraries, so we can strip the dependencies
83 if (source == '') or (source == []):
84 SET_TARGET_TYPE(bld, libname, 'EMPTY')
87 if bld.env.DISABLE_SHARED:
90 obj_target = libname + '.objlist'
92 # first create a target for building the object files for this library
93 # by separating in this way, we avoid recompiling the C files
94 # separately for the install library and the build library
95 bld.SAMBA_SUBSYSTEM(obj_target,
98 public_deps = public_deps,
100 public_headers = public_headers,
101 header_path = header_path,
104 autoproto = autoproto,
105 depends_on = depends_on,
106 local_include = local_include)
108 if bld.env.DISABLE_SHARED:
111 if not SET_TARGET_TYPE(bld, libname, 'LIBRARY'):
114 # the library itself will depend on that object target
115 deps += ' ' + public_deps
117 deps.append(obj_target)
119 bld.SET_BUILD_GROUP(group)
121 features = 'cc cshlib symlink_lib',
124 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
125 depends_on = depends_on,
127 samba_includes = includes,
128 local_include = local_include,
131 ldflags = build_rpath(bld)
134 if install_path is None:
135 install_path = '${LIBDIR}'
136 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
138 # we don't need the double libraries if rpath is off
139 if (bld.env.RPATH_ON_INSTALL == False and
140 bld.env.RPATH_ON_BUILD == False):
141 install_target = libname
143 install_target = libname + '.inst'
145 if install and install_target != libname:
146 # create a separate install library, which may have
147 # different rpath settings
148 SET_TARGET_TYPE(bld, install_target, 'LIBRARY')
150 features = 'cc cshlib',
152 target = install_target,
153 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
154 depends_on = depends_on,
156 samba_includes = includes,
157 local_include = local_include,
159 install_as = libname,
161 ldflags = install_rpath(bld)
166 vnum_base = vnum.split('.')[0]
167 install_name = 'lib%s.so.%s' % (libname, vnum)
168 install_link = 'lib%s.so.%s' % (libname, vnum_base)
170 install_name = 'lib%s.so' % libname
173 bld.install_as(os.path.join(install_path, install_name),
174 'lib%s.inst.so' % libname)
176 bld.symlink_as(os.path.join(install_path, install_link), install_name)
178 if autoproto is not None:
179 bld.SAMBA_AUTOPROTO(autoproto, source)
181 if public_headers is not None:
182 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
184 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
187 #################################################################
188 # define a Samba binary
189 def SAMBA_BINARY(bld, binname, source,
210 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
213 features = 'cc cprogram'
215 features += ' pyembed'
217 bld.SET_BUILD_GROUP(group)
219 obj_target = binname + '.objlist'
221 source = bld.EXPAND_VARIABLES(source, vars=vars)
223 # first create a target for building the object files for this binary
224 # by separating in this way, we avoid recompiling the C files
225 # separately for the install binary and the build binary
226 bld.SAMBA_SUBSYSTEM(obj_target,
232 autoproto = autoproto,
233 subsystem_name = subsystem_name,
234 needs_python = needs_python,
235 local_include = local_include)
237 # the library itself will depend on that object target
239 deps.append(obj_target)
242 features = features + ' symlink_bin',
245 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
247 samba_includes = includes,
248 local_include = local_include,
249 samba_modules = modules,
251 samba_subsystem= subsystem_name,
253 ldflags = build_rpath(bld)
256 if install_path is None:
257 install_path = '${BINDIR}'
258 install_path = SUBST_VARS_RECURSIVE(install_path, bld.env)
260 # we don't need the double binaries if rpath is off
261 if (bld.env.RPATH_ON_INSTALL == False and
262 bld.env.RPATH_ON_BUILD == False):
263 install_target = binname
265 install_target = binname + '.inst'
267 if install and install_target != binname:
268 # we create a separate 'install' binary, which
269 # will have different rpath settings
270 SET_TARGET_TYPE(bld, install_target, 'BINARY')
274 target = install_target,
275 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
277 samba_includes = includes,
278 local_include = local_include,
279 samba_modules = modules,
281 samba_subsystem= subsystem_name,
283 ldflags = install_rpath(bld)
287 bld.install_as(os.path.join(install_path, binname),
291 # setup the subsystem_name as an alias for the real
292 # binary name, so it can be found when expanding
293 # subsystem dependencies
294 if subsystem_name is not None:
295 bld.TARGET_ALIAS(subsystem_name, binname)
297 if autoproto is not None:
298 bld.SAMBA_AUTOPROTO(autoproto, source)
299 if public_headers is not None:
300 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
301 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
304 #################################################################
305 # define a Samba module.
306 def SAMBA_MODULE(bld, modname, source,
312 autoproto_extra_source='',
315 internal_module=True,
320 # we add the init function regardless of whether the module
321 # is enabled or not, as we need to generate a null list if
323 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
325 if internal_module or bld.env.DISABLE_SHARED:
326 # treat internal modules as subsystems for now
327 SAMBA_SUBSYSTEM(bld, modname, source,
331 autoproto_extra_source=autoproto_extra_source,
333 local_include=local_include,
338 SET_TARGET_TYPE(bld, modname, 'DISABLED')
341 source = bld.EXPAND_VARIABLES(source, vars=vars)
343 # remember empty modules, so we can strip the dependencies
344 if (source == '') or (source == []):
345 SET_TARGET_TYPE(bld, modname, 'EMPTY')
348 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
351 if subsystem is not None:
352 deps += ' ' + subsystem
354 bld.SET_BUILD_GROUP('main')
359 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
360 samba_includes = includes,
361 local_include = local_include,
362 samba_deps = TO_LIST(deps)
365 if autoproto is not None:
366 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
368 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
371 #################################################################
372 # define a Samba subsystem
373 def SAMBA_SUBSYSTEM(bld, modname, source,
382 init_function_sentinal=None,
383 heimdal_autoproto=None,
384 heimdal_autoproto_options=None,
385 heimdal_autoproto_private=None,
387 autoproto_extra_source='',
390 local_include_first=True,
397 SET_TARGET_TYPE(bld, modname, 'DISABLED')
400 # remember empty subsystems, so we can strip the dependencies
401 if (source == '') or (source == []):
402 SET_TARGET_TYPE(bld, modname, 'EMPTY')
405 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
408 source = bld.EXPAND_VARIABLES(source, vars=vars)
410 deps += ' ' + public_deps
412 bld.SET_BUILD_GROUP(group)
422 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
423 depends_on = depends_on,
424 samba_deps = TO_LIST(deps),
425 samba_includes = includes,
426 local_include = local_include,
427 local_include_first = local_include_first,
428 samba_subsystem= subsystem_name
431 if cflags_end is not None:
432 t.samba_cflags.extend(TO_LIST(cflags_end))
434 if heimdal_autoproto is not None:
435 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source, options=heimdal_autoproto_options)
436 if heimdal_autoproto_private is not None:
437 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
438 if autoproto is not None:
439 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
440 if public_headers is not None:
441 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
445 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
448 def SAMBA_GENERATOR(bld, name, rule, source, target,
449 group='build_source', enabled=True,
453 '''A generic source generator target'''
455 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
461 bld.SET_BUILD_GROUP(group)
464 source=bld.EXPAND_VARIABLES(source, vars=vars),
472 if public_headers is not None:
473 bld.PUBLIC_HEADERS(public_headers, header_path=header_path)
474 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
478 ###############################################################
479 # add a new set of build rules from a subdirectory
480 # the @runonce decorator ensures we don't end up
481 # with duplicate rules
482 def BUILD_SUBDIR(bld, dir):
483 path = os.path.normpath(bld.curdir + '/' + dir)
484 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
485 if path in cache: return
487 debug("build: Processing subdirectory %s" % dir)
490 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
493 ##########################################################
494 # add a new top level command to waf
495 def ADD_COMMAND(opt, name, function):
496 Utils.g_module.__dict__[name] = function
498 Options.Handler.ADD_COMMAND = ADD_COMMAND
500 ###########################################################
501 # setup build groups used to ensure that the different build
502 # phases happen consecutively
504 def SETUP_BUILD_GROUPS(bld):
505 bld.p_ln = bld.srcnode # we do want to see all targets!
506 bld.env['USING_BUILD_GROUPS'] = True
507 bld.add_group('setup')
508 bld.add_group('build_compiler_source')
509 bld.add_group('base_libraries')
510 bld.add_group('build_compilers')
511 bld.add_group('build_source')
512 bld.add_group('prototypes')
513 bld.add_group('main')
514 bld.add_group('binaries')
515 bld.add_group('final')
516 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
519 ###########################################################
520 # set the current build group
521 def SET_BUILD_GROUP(bld, group):
522 if not 'USING_BUILD_GROUPS' in bld.env:
525 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
528 def h_file(filename):
530 st = os.stat(filename)
531 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
533 m.update(str(st.st_mtime))
534 m.update(str(st.st_size))
539 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
540 Utils.h_file = h_file
543 ##############################
544 # handle the creation of links for libraries and binaries
545 # note that we use a relative symlink path to allow the whole tree
546 # to me moved/copied elsewhere without breaking the links
547 t = Task.simple_task_type('symlink_lib', 'rm -f ${LINK_TARGET} && ln -s ${LINK_SOURCE} ${LINK_TARGET}',
548 shell=True, color='PINK', ext_in='.bin')
551 @feature('symlink_lib')
553 def symlink_lib(self):
554 tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
556 # calculat the link target and put it in the environment
558 vnum = getattr(self, 'vnum', None)
560 soext = '.' + vnum.split('.')[0]
562 link_target = getattr(self, 'link_name', '')
563 if link_target == '':
564 link_target = '%s/lib%s.so%s' % (LIB_PATH, self.sname, soext)
567 link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
568 os.path.join(self.env.BUILD_DIRECTORY, link_target))
570 tsk.env.LINK_TARGET = link_target
571 tsk.env.LINK_SOURCE = link_source[3:]
572 debug('task_gen: LINK for %s is %s -> %s',
573 self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
576 t = Task.simple_task_type('symlink_bin', 'rm -f ${BIN_TARGET} && ln -s ${SRC} ${BIN_TARGET}',
577 shell=True, color='PINK', ext_in='.bin')
580 @feature('symlink_bin')
582 def symlink_bin(self):
583 if Options.is_install:
584 # we don't want to copy the install binary, as
585 # that has the install rpath, not the build rpath
586 # The rpath of the binaries in bin/default/foo/blah is different
587 # during the install phase, as distros insist on not using rpath in installed binaries
589 tsk = self.create_task('symlink_bin', self.link_task.outputs[0])
591 tsk.env.BIN_TARGET = self.target
592 debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
597 t = Task.simple_task_type('copy_script', 'rm -f ${LINK_TARGET} && ln -s ${SRC[0].abspath(env)} ${LINK_TARGET}',
598 shell=True, color='PINK', ext_in='.bin')
601 @feature('copy_script')
602 @before('apply_link')
603 def copy_script(self):
604 tsk = self.create_task('copy_script', self.allnodes[0])
605 tsk.env.TARGET = self.target
607 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
608 '''used to copy scripts from the source tree into the build directory
609 for use by selftest'''
611 source = bld.path.ant_glob(pattern)
613 bld.SET_BUILD_GROUP('build_source')
614 for s in TO_LIST(source):
616 if installname != None:
618 target = os.path.join(installdir, iname)
619 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
621 t = bld(features='copy_script',
626 t.env.LINK_TARGET = target
628 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT
631 def INSTALL_FILES(bld, destdir, files, chmod=0644, flat=False,
632 python_fixup=False, destname=None):
633 '''install a set of files'''
634 destdir = bld.EXPAND_VARIABLES(destdir)
636 bld.install_as(os.path.join(destdir,destname), files, chmod=chmod)
638 bld.install_files(destdir, files, chmod=chmod, relative_trick=not flat)
639 Build.BuildContext.INSTALL_FILES = INSTALL_FILES
642 def INSTALL_WILDCARD(bld, destdir, pattern, chmod=0644, flat=False,
644 '''install a set of files matching a wildcard pattern'''
645 files=bld.path.ant_glob(pattern)
646 INSTALL_FILES(bld, destdir, files, chmod=chmod, flat=flat)
647 Build.BuildContext.INSTALL_WILDCARD = INSTALL_WILDCARD
650 def PUBLIC_HEADERS(bld, public_headers, header_path=None):
651 '''install some headers
653 header_path may either be a string that is added to the INCLUDEDIR,
654 or it can be a dictionary of wildcard patterns which map to destination
655 directories relative to INCLUDEDIR
658 dest = '${INCLUDEDIR}'
659 if isinstance(header_path, str):
660 dest += '/' + header_path
661 for h in TO_LIST(public_headers):
663 if isinstance(header_path, list):
664 for (p1, dir) in header_path:
668 if fnmatch.fnmatch(h, p2):
670 hdest = os.path.join(hdest, dir)
673 if found_match: break
674 if h.find(':') != -1:
676 INSTALL_FILES(bld, hdest, hs[0], flat=True, destname=hs[1])
678 INSTALL_FILES(bld, hdest, h, flat=True)
679 Build.BuildContext.PUBLIC_HEADERS = PUBLIC_HEADERS