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, Logs, sys, Configure, Options, string, Task, Utils, optparse
5 from Configure import conf
7 from TaskGen import extension
9 # bring in the other samba modules
10 from samba_utils import *
11 # should be enabled from the above?
12 from samba_autoconf import *
13 from samba_patterns import *
14 from samba_pidl import *
15 from samba_asn1 import *
16 from samba_autoproto import *
21 #################################################################
22 # create the samba build environment
24 def SAMBA_BUILD_ENV(conf):
25 libpath="%s/%s" % (conf.blddir, LIB_PATH)
26 conf.env['BUILD_DIRECTORY'] = conf.blddir
27 if not os.path.exists(libpath):
30 ################################################################
31 # add an init_function to the list for a subsystem
32 def ADD_INIT_FUNCTION(bld, subsystem, init_function):
33 if init_function is None:
35 bld.ASSERT(subsystem is not None, "You must specify a subsystem for init_function '%s'" % init_function)
36 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
37 if not subsystem in cache:
39 cache[subsystem] += '%s,' % init_function
40 Build.BuildContext.ADD_INIT_FUNCTION = ADD_INIT_FUNCTION
42 ################################################################
43 # recursively build the dependency list for a target
44 def FULL_DEPENDENCIES(bld, cache, target, chain, path):
45 if not target in cache:
47 deps = cache[target].copy()
48 for t in cache[target]:
49 bld.ASSERT(t not in chain, "Circular dependency for %s: %s->%s" % (t, path, t));
52 dict_concat(deps, FULL_DEPENDENCIES(bld, cache, t, c2, "%s->%s" % (path, t)))
55 ############################################################
56 # check our build dependencies for circular dependencies
57 def CHECK_TARGET_DEPENDENCY(bld, target):
58 cache = LOCAL_CACHE(bld, 'LIB_DEPS')
59 return FULL_DEPENDENCIES(bld, cache, target, { target:True }, target)
61 ############################################################
62 # check that all dependencies have been declared
63 def CHECK_DEPENDENCIES(bld):
64 cache = LOCAL_CACHE(bld, 'LIB_DEPS')
65 target_cache = LOCAL_CACHE(bld, 'TARGET_TYPE')
66 debug('deps: Checking dependencies')
68 deps = CHECK_TARGET_DEPENDENCY(bld, t)
70 #if not d in target_cache:
71 # print "WARNING: Dependency '%s' of target '%s' not declared" % (d, t)
72 ASSERT(bld, d in target_cache,
73 "Dependency '%s' of target '%s' not declared" % (d, t))
74 debug("deps: Dependencies checked for %u targets" % len(target_cache))
75 Build.BuildContext.CHECK_DEPENDENCIES = CHECK_DEPENDENCIES
78 ############################################################
79 # pre-declare a target as being of a particular type
80 def PREDECLARE(bld, target, type):
81 cache = LOCAL_CACHE(bld, 'PREDECLARED_TARGET')
82 target_cache = LOCAL_CACHE(bld, 'TARGET_TYPE')
83 ASSERT(bld, not target in target_cache, "Target '%s' is already declared" % target)
84 ASSERT(bld, not target in cache, "Target '%s' already predeclared" % target)
86 Build.BuildContext.PREDECLARE = PREDECLARE
90 ################################################################
91 # add to the dependency list. Return a new dependency list with
92 # any circular dependencies removed
93 # returns a tuple containing (systemdeps, localdeps, add_objects)
94 def ADD_DEPENDENCIES(bld, name, deps):
95 debug('deps: Calculating dependencies for %s' % name)
96 lib_deps = LOCAL_CACHE(bld, 'LIB_DEPS')
97 if not name in lib_deps:
102 lib_deps[name][d] = True;
104 CHECK_TARGET_DEPENDENCY(bld, name)
106 except AssertionError:
107 sys.stderr.write("Removing dependency %s from target %s\n" % (d, name))
108 del(lib_deps[name][d])
110 target_cache = LOCAL_CACHE(bld, 'TARGET_TYPE')
112 # extract out the system dependencies
116 cache = LOCAL_CACHE(bld, 'EMPTY_TARGETS')
117 predeclare = LOCAL_CACHE(bld, 'PREDECLARED_TARGET')
120 # strip out any dependencies on empty libraries
122 debug("deps: Removing empty dependency '%s' from '%s'" % (d, name))
126 if d in target_cache:
127 type = target_cache[d]
128 elif d in predeclare:
132 LOCAL_CACHE_SET(bld, 'ASSUMED_TARGET', d, type)
136 elif type == 'LIBRARY':
138 elif type == 'SUBSYSTEM':
139 add_objects.append(d)
141 elif type == 'MODULE':
142 add_objects.append(d)
144 elif type == 'PYTHON':
148 elif type == 'BINARY':
151 ASSERT(bld, False, "Unknown target type '%s' for dependency %s" % (
154 # for some types we have to build the list recursively
155 if recurse and (d in lib_deps):
156 rec_deps = ' '.join(lib_deps[d].keys())
157 (rec_sysdeps, rec_localdeps, rec_add_objects) = ADD_DEPENDENCIES(bld, d, rec_deps)
158 sysdeps.extend(to_list(rec_sysdeps))
159 localdeps.extend(to_list(rec_localdeps))
160 add_objects.extend(to_list(rec_add_objects))
162 debug('deps: Dependencies for %s: sysdeps: %u localdeps: %u add_objects=%u' % (
163 name, len(sysdeps), len(localdeps), len(add_objects)))
164 return (' '.join(sysdeps), ' '.join(localdeps), ' '.join(add_objects))
167 #################################################################
168 # return a include list for a set of library dependencies
169 def SAMBA_LIBRARY_INCLUDE_LIST(bld, deps):
170 ret = bld.curdir + ' '
171 cache = LOCAL_CACHE(bld, 'INCLUDE_LIST')
172 for l in to_list(deps):
174 ret = ret + cache[l] + ' '
175 if 'EXTRA_INCLUDES' in bld.env:
176 ret += ' ' + ' '.join(bld.env['EXTRA_INCLUDES'])
178 Build.BuildContext.SAMBA_LIBRARY_INCLUDE_LIST = SAMBA_LIBRARY_INCLUDE_LIST
180 #################################################################
181 # define a Samba library
182 def SAMBA_LIBRARY(bld, libname, source,
194 if not SET_TARGET_TYPE(bld, libname, 'LIBRARY'):
197 # remember empty libraries, so we can strip the dependencies
198 if (source == '') or (source == []):
199 LOCAL_CACHE_SET(bld, 'EMPTY_TARGETS', libname, True)
202 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, libname, deps)
204 ilist = includes + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
205 ilist = bld.NORMPATH(ilist)
207 # this print below should show that we're runnig this code
208 bld.SET_BUILD_GROUP(group) # <- here
210 features = 'cc cshlib',
213 uselib_local = localdeps,
215 add_objects = add_objects,
216 ccflags = CURRENT_CFLAGS(bld, cflags),
217 includes=ilist + ' . #',
218 depends_on=depends_on,
221 # I have to set it each time? I expect it to be still
222 # set from the few lines above
224 # put a link to the library in bin/shared
227 soext = '.' + vnum.split('.')[0]
230 source = 'lib%s.so' % libname,
231 rule = 'ln -sf ../${SRC}%s %s/lib%s.so%s' % (soext, LIB_PATH, libname, soext),
232 # rule = 'ln -sf ../%s.so%s %s/lib%s.so%s' % (libname, soext, LIB_PATH, libname, soext),
236 name = 'fff' + libname,
239 LOCAL_CACHE_SET(bld, 'INCLUDE_LIST', libname, ilist)
241 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
243 #################################################################
244 # define a Samba binary
245 def SAMBA_BINARY(bld, binname, source,
258 ilist = includes + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
259 ilist = bld.NORMPATH(ilist)
261 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
264 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, binname, deps)
266 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
267 if modules is not None:
268 for m in to_list(modules):
269 bld.ASSERT(m in cache,
270 "No init_function defined for module '%s' in binary '%s'" % (m, binname))
271 cflags += ' -DSTATIC_%s_MODULES="%s"' % (m, cache[m])
273 bld.SET_BUILD_GROUP(group)
275 features = 'cc cprogram',
278 uselib_local = localdeps,
280 includes = ilist + ' . #',
281 ccflags = CURRENT_CFLAGS(bld, cflags),
282 add_objects = add_objects,
285 if not Options.is_install:
288 rule = 'rm -f %s && cp ${SRC} .' % (binname),
293 name = binname + ".copy",
296 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
299 #################################################################
300 # define a Samba python module
301 def SAMBA_PYTHON(bld, name, source,
306 if not SET_TARGET_TYPE(bld, name, 'PYTHON'):
309 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, name, deps)
312 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
314 #################################################################
315 # define a Samba ET target
316 def SAMBA_ERRTABLE(bld, name, source,
319 # print "Skipping ERRTABLE rule for %s with source=%s" % (name, source)
321 if not SET_TARGET_TYPE(bld, name, 'ET'):
323 bld.SET_BUILD_GROUP('build_source')
328 includes = '# #source4/heimdal_build #source4 #lib/replace'
330 Build.BuildContext.SAMBA_ERRTABLE = SAMBA_ERRTABLE
332 #################################################################
333 # define a Samba module.
334 def SAMBA_MODULE(bld, modname, source,
344 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
347 # remember empty modules, so we can strip the dependencies
348 if (source == '') or (source == []):
349 LOCAL_CACHE_SET(bld, 'EMPTY_TARGETS', modname, True)
352 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, modname, deps)
354 ilist = includes + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
355 ilist = bld.NORMPATH(ilist)
356 bld.SET_BUILD_GROUP('main')
361 ccflags = CURRENT_CFLAGS(bld, cflags),
362 includes=ilist + ' . #')
363 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
366 #################################################################
367 # define a Samba subsystem
368 def SAMBA_SUBSYSTEM(bld, modname, source,
376 init_function_sentinal=None,
377 heimdal_autoproto=None,
378 heimdal_autoproto_private=None,
382 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
385 # if the caller specifies a config_option, then we create a blank
386 # subsystem if that configuration option was found at configure time
387 if (config_option is not None) and bld.CONFIG_SET(config_option):
390 # remember empty subsystems, so we can strip the dependencies
391 if (source == '') or (source == []):
392 LOCAL_CACHE_SET(bld, 'EMPTY_TARGETS', modname, True)
395 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, modname, deps)
397 ilist = includes + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
398 ilist = bld.NORMPATH(ilist)
399 bld.SET_BUILD_GROUP(group)
404 ccflags = CURRENT_CFLAGS(bld, cflags),
405 includes=ilist + ' . #',
406 depends_on=depends_on)
407 LOCAL_CACHE_SET(bld, 'INCLUDE_LIST', modname, ilist)
409 if heimdal_autoproto is not None:
410 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source)
411 if heimdal_autoproto_private is not None:
412 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
413 if autoproto is not None:
414 bld.SAMBA_AUTOPROTO(autoproto, source)
417 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
420 ###############################################################
421 # add a new set of build rules from a subdirectory
422 # the @runonce decorator ensures we don't end up
423 # with duplicate rules
424 def BUILD_SUBDIR(bld, dir):
425 path = os.path.normpath(bld.curdir + '/' + dir)
426 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
427 if path in cache: return
429 debug("build: Processing subdirectory %s" % dir)
432 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
435 ##########################################################
436 # add a new top level command to waf
437 def ADD_COMMAND(opt, name, function):
438 Utils.g_module.__dict__[name] = function
440 Options.Handler.ADD_COMMAND = ADD_COMMAND
442 ###########################################################
443 # setup build groups used to ensure that the different build
444 # phases happen consecutively
446 def SETUP_BUILD_GROUPS(bld):
447 bld.p_ln = bld.srcnode # we do want to see all targets!
448 bld.env['USING_BUILD_GROUPS'] = True
449 bld.add_group('setup')
450 bld.add_group('base_libraries')
451 bld.add_group('build_compilers')
452 bld.add_group('build_source')
453 bld.add_group('prototypes')
454 bld.add_group('main')
455 bld.add_group('final')
456 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
459 ###########################################################
460 # set the current build group
461 def SET_BUILD_GROUP(bld, group):
462 if not 'USING_BUILD_GROUPS' in bld.env:
465 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP