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
5 from Configure import conf
8 # bring in the other samba modules
9 from samba_utils import *
10 from samba_autoconf import *
11 from samba_patterns import *
12 from samba_pidl import *
13 from samba_errtable import *
14 from samba_asn1 import *
15 from samba_autoproto import *
16 from samba_python import *
17 from samba_deps import *
23 #################################################################
24 # create the samba build environment
26 def SAMBA_BUILD_ENV(conf):
27 conf.env['BUILD_DIRECTORY'] = conf.blddir
28 mkdir_p(os.path.join(conf.blddir, LIB_PATH))
29 mkdir_p(os.path.join(conf.blddir, 'python/samba/dcerpc'))
30 # this allows all of the bin/shared and bin/python targets
31 # to be expressed in terms of build directory paths
32 os.symlink('../python', os.path.join(conf.blddir, 'default/python'))
33 os.symlink('../shared', os.path.join(conf.blddir, 'default/shared'))
36 ################################################################
37 # add an init_function to the list for a subsystem
38 def ADD_INIT_FUNCTION(bld, subsystem, target, init_function):
39 if init_function is None:
41 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
42 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
43 if not subsystem in cache:
45 cache[subsystem].append( { 'TARGET':target, 'INIT_FUNCTION':init_function } )
46 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
49 #################################################################
50 # define a Samba library
51 def SAMBA_LIBRARY(bld, libname, source,
58 external_library=False,
65 # remember empty libraries, so we can strip the dependencies
66 if (source == '') or (source == []):
67 SET_TARGET_TYPE(bld, libname, 'EMPTY')
70 if not SET_TARGET_TYPE(bld, libname, 'LIBRARY'):
73 deps += ' ' + public_deps
75 # this print below should show that we're runnig this code
76 bld.SET_BUILD_GROUP(group)
78 features = 'cc cshlib symlink_lib',
81 samba_cflags = CURRENT_CFLAGS(bld, libname, cflags),
82 depends_on = depends_on,
83 samba_deps = TO_LIST(deps),
84 samba_includes = includes,
85 local_include = local_include,
88 if autoproto is not None:
89 bld.SAMBA_AUTOPROTO(autoproto, source)
91 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
93 #################################################################
94 # define a Samba binary
95 def SAMBA_BINARY(bld, binname, source,
112 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
115 features = 'cc cprogram copy_bin'
117 features += ' pyembed'
119 bld.SET_BUILD_GROUP(group)
124 samba_cflags = CURRENT_CFLAGS(bld, binname, cflags),
125 samba_deps = TO_LIST(deps),
126 samba_includes = includes,
127 local_include = local_include,
128 samba_modules = modules,
130 samba_subsystem= subsystem_name
133 # setup the subsystem_name as an alias for the real
134 # binary name, so it can be found when expanding
135 # subsystem dependencies
136 if subsystem_name is not None:
137 bld.TARGET_ALIAS(subsystem_name, binname)
139 if autoproto is not None:
140 bld.SAMBA_AUTOPROTO(autoproto, source)
141 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
144 #################################################################
145 # define a Samba module.
146 def SAMBA_MODULE(bld, modname, source,
152 autoproto_extra_source='',
155 internal_module=True,
160 # treat internal modules as subsystems for now
161 SAMBA_SUBSYSTEM(bld, modname, source,
165 autoproto_extra_source=autoproto_extra_source,
167 local_include=local_include,
169 # even though we're treating it as a subsystem, we need to
170 # add it to the init_function list
171 # TODO: we should also create an implicit dependency
172 # between the subsystem target and this target
174 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
178 SET_TARGET_TYPE(bld, modname, 'DISABLED')
181 # remember empty modules, so we can strip the dependencies
182 if (source == '') or (source == []):
183 SET_TARGET_TYPE(bld, modname, 'EMPTY')
186 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
190 bld.ADD_INIT_FUNCTION(subsystem, modname, init_function)
192 if subsystem is not None:
193 deps += ' ' + subsystem
195 bld.SET_BUILD_GROUP('main')
200 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
201 samba_includes = includes,
202 local_include = local_include,
203 samba_deps = TO_LIST(deps)
206 if autoproto is not None:
207 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
209 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
212 #################################################################
213 # define a Samba subsystem
214 def SAMBA_SUBSYSTEM(bld, modname, source,
222 init_function_sentinal=None,
223 heimdal_autoproto=None,
224 heimdal_autoproto_options=None,
225 heimdal_autoproto_private=None,
227 autoproto_extra_source='',
230 local_include_first=True,
236 SET_TARGET_TYPE(bld, modname, 'DISABLED')
239 # remember empty subsystems, so we can strip the dependencies
240 if (source == '') or (source == []):
241 SET_TARGET_TYPE(bld, modname, 'EMPTY')
244 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
247 deps += ' ' + public_deps
249 bld.SET_BUILD_GROUP(group)
259 samba_cflags = CURRENT_CFLAGS(bld, modname, cflags),
260 depends_on = depends_on,
261 samba_deps = TO_LIST(deps),
262 samba_includes = includes,
263 local_include = local_include,
264 local_include_first = local_include_first,
265 samba_subsystem= subsystem_name
268 if heimdal_autoproto is not None:
269 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source, options=heimdal_autoproto_options)
270 if heimdal_autoproto_private is not None:
271 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
272 if autoproto is not None:
273 bld.SAMBA_AUTOPROTO(autoproto, source + ' ' + autoproto_extra_source)
276 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
279 def SAMBA_GENERATOR(bld, name, rule, source, target,
280 group='build_source'):
281 '''A generic source generator target'''
283 if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
286 bld.SET_BUILD_GROUP(group)
293 Build.BuildContext.SAMBA_GENERATOR = SAMBA_GENERATOR
297 ###############################################################
298 # add a new set of build rules from a subdirectory
299 # the @runonce decorator ensures we don't end up
300 # with duplicate rules
301 def BUILD_SUBDIR(bld, dir):
302 path = os.path.normpath(bld.curdir + '/' + dir)
303 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
304 if path in cache: return
306 debug("build: Processing subdirectory %s" % dir)
309 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
312 ##########################################################
313 # add a new top level command to waf
314 def ADD_COMMAND(opt, name, function):
315 Utils.g_module.__dict__[name] = function
317 Options.Handler.ADD_COMMAND = ADD_COMMAND
319 ###########################################################
320 # setup build groups used to ensure that the different build
321 # phases happen consecutively
323 def SETUP_BUILD_GROUPS(bld):
324 bld.p_ln = bld.srcnode # we do want to see all targets!
325 bld.env['USING_BUILD_GROUPS'] = True
326 bld.add_group('setup')
327 bld.add_group('base_libraries')
328 bld.add_group('build_compilers')
329 bld.add_group('build_source')
330 bld.add_group('prototypes')
331 bld.add_group('main')
332 bld.add_group('binaries')
333 bld.add_group('final')
334 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
337 ###########################################################
338 # set the current build group
339 def SET_BUILD_GROUP(bld, group):
340 if not 'USING_BUILD_GROUPS' in bld.env:
343 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP
346 def h_file(filename):
348 st = os.stat(filename)
349 if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
351 m.update(str(st.st_mtime))
352 m.update(str(st.st_size))
357 def ENABLE_TIMESTAMP_DEPENDENCIES(conf):
358 Utils.h_file = h_file
361 ##############################
362 # handle the creation of links for libraries and binaries
363 # note that we use a relative symlink path to allow the whole tree
364 # to me moved/copied elsewhere without breaking the links
365 t = Task.simple_task_type('symlink_lib', 'ln -sf ${LINK_SOURCE} ${LINK_TARGET}',
366 color='PINK', ext_in='.bin')
369 @feature('symlink_lib')
371 def symlink_lib(self):
372 tsk = self.create_task('symlink_lib', self.link_task.outputs[0])
374 # calculat the link target and put it in the environment
376 vnum = getattr(self, 'vnum', None)
378 soext = '.' + vnum.split('.')[0]
380 link_target = getattr(self, 'link_name', '')
381 if link_target == '':
382 link_target = '%s/lib%s.so%s' % (LIB_PATH, self.sname, soext)
385 link_source = os_path_relpath(self.link_task.outputs[0].abspath(self.env),
386 os.path.join(self.env.BUILD_DIRECTORY, link_target))
388 tsk.env.LINK_TARGET = link_target
389 tsk.env.LINK_SOURCE = link_source[3:]
390 debug('task_gen: LINK for %s is %s -> %s',
391 self.name, tsk.env.LINK_SOURCE, tsk.env.LINK_TARGET)
393 # for binaries we need to copy the executable to avoid the rpath changing
394 # in the local bin/ directory on install
395 t = Task.simple_task_type('copy_bin', 'rm -f ${BIN_TARGET} && cp ${SRC} ${BIN_TARGET}', color='PINK',
396 ext_in='.bin', shell=True)
402 if Options.is_install:
403 # we don't want to copy the install binary, as
404 # that has the install rpath, not the build rpath
405 # The rpath of the binaries in bin/default/foo/blah is different
406 # during the install phase, as distros insist on not using rpath in installed binaries
408 tsk = self.create_task('copy_bin', self.link_task.outputs[0])
410 tsk.env.BIN_TARGET = self.target
411 debug('task_gen: BIN_TARGET for %s is %s', self.name, tsk.env.BIN_TARGET)
416 t = Task.simple_task_type('copy_script', 'ln -sf ${SRC[0].abspath(env)} ${LINK_TARGET}',
417 color='PINK', ext_in='.bin', shell=True)
420 @feature('copy_script')
421 @before('apply_link')
422 def copy_script(self):
423 tsk = self.create_task('copy_script', self.allnodes[0])
424 tsk.env.TARGET = self.target
426 def SAMBA_SCRIPT(bld, name, pattern, installdir, installname=None):
427 '''used to copy scripts from the source tree into the build directory
428 for use by selftest'''
430 source = bld.path.ant_glob(pattern)
432 bld.SET_BUILD_GROUP('build_source')
433 for s in TO_LIST(source):
435 if installname != None:
437 target = os.path.join(installdir, iname)
438 tgtdir = os.path.dirname(os.path.join(bld.srcnode.abspath(bld.env), '..', target))
440 t = bld(features='copy_script',
444 t.env.LINK_TARGET = target
446 Build.BuildContext.SAMBA_SCRIPT = SAMBA_SCRIPT