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 = bld.SUBDIR(bld.curdir, 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 print "Setting build group for library %s to %s" % (libname, group), bld.path
209 bld.SET_BUILD_GROUP(group) # <- here
211 features = 'cc cshlib',
214 uselib_local = localdeps,
216 add_objects = add_objects,
217 ccflags = CURRENT_CFLAGS(bld, cflags),
218 includes=ilist + ' . #',
219 depends_on=depends_on,
222 # I have to set it each time? I expect it to be still
223 # set from the few lines above
225 # put a link to the library in bin/shared
228 soext = '.' + vnum.split('.')[0]
231 source = 'lib%s.so' % libname,
232 rule = 'ln -sf ../${SRC}%s %s/lib%s.so%s' % (soext, LIB_PATH, libname, soext),
233 # rule = 'ln -sf ../%s.so%s %s/lib%s.so%s' % (libname, soext, LIB_PATH, libname, soext),
237 name = 'fff' + libname,
240 LOCAL_CACHE_SET(bld, 'INCLUDE_LIST', libname, ilist)
242 Build.BuildContext.SAMBA_LIBRARY = SAMBA_LIBRARY
244 #################################################################
245 # define a Samba binary
246 def SAMBA_BINARY(bld, binname, source,
259 ilist = includes + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
260 ilist = bld.NORMPATH(ilist)
262 if not SET_TARGET_TYPE(bld, binname, 'BINARY'):
265 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, binname, deps)
267 cache = LOCAL_CACHE(bld, 'INIT_FUNCTIONS')
268 if modules is not None:
269 for m in to_list(modules):
270 bld.ASSERT(m in cache,
271 "No init_function defined for module '%s' in binary '%s'" % (m, binname))
272 cflags += ' -DSTATIC_%s_MODULES="%s"' % (m, cache[m])
274 bld.SET_BUILD_GROUP(group)
276 features = 'cc cprogram',
279 uselib_local = localdeps,
281 includes = ilist + ' . #',
282 ccflags = CURRENT_CFLAGS(bld, cflags),
283 add_objects = add_objects,
286 if not Options.is_install:
289 rule = 'rm -f %s && cp ${SRC} .' % (binname),
294 name = binname + ".copy",
297 Build.BuildContext.SAMBA_BINARY = SAMBA_BINARY
300 #################################################################
301 # define a Samba python module
302 def SAMBA_PYTHON(bld, name, source,
307 if not SET_TARGET_TYPE(bld, name, 'PYTHON'):
310 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, name, deps)
313 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
315 #################################################################
316 # define a Samba ET target
317 def SAMBA_ERRTABLE(bld, name, source,
320 # print "Skipping ERRTABLE rule for %s with source=%s" % (name, source)
322 if not SET_TARGET_TYPE(bld, name, 'ET'):
324 bld.SET_BUILD_GROUP('build_source')
329 includes = '# #source4/heimdal_build #source4 #lib/replace'
331 Build.BuildContext.SAMBA_ERRTABLE = SAMBA_ERRTABLE
333 #################################################################
334 # define a Samba module.
335 def SAMBA_MODULE(bld, modname, source,
345 if not SET_TARGET_TYPE(bld, modname, 'MODULE'):
348 # remember empty modules, so we can strip the dependencies
349 if (source == '') or (source == []):
350 LOCAL_CACHE_SET(bld, 'EMPTY_TARGETS', modname, True)
353 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, modname, deps)
355 ilist = bld.SUBDIR(bld.curdir, includes) + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
356 ilist = bld.NORMPATH(ilist)
357 bld.SET_BUILD_GROUP('main')
362 ccflags = CURRENT_CFLAGS(bld, cflags),
363 includes=ilist + ' . #')
364 Build.BuildContext.SAMBA_MODULE = SAMBA_MODULE
367 #################################################################
368 # define a Samba subsystem
369 def SAMBA_SUBSYSTEM(bld, modname, source,
377 init_function_sentinal=None,
378 heimdal_autoproto=None,
379 heimdal_autoproto_private=None,
383 if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
386 # if the caller specifies a config_option, then we create a blank
387 # subsystem if that configuration option was found at configure time
388 if (config_option is not None) and bld.CONFIG_SET(config_option):
391 # remember empty subsystems, so we can strip the dependencies
392 if (source == '') or (source == []):
393 LOCAL_CACHE_SET(bld, 'EMPTY_TARGETS', modname, True)
396 (sysdeps, localdeps, add_objects) = ADD_DEPENDENCIES(bld, modname, deps)
398 ilist = bld.SUBDIR(bld.curdir, includes) + ' ' + bld.SAMBA_LIBRARY_INCLUDE_LIST(deps)
399 ilist = bld.NORMPATH(ilist)
400 bld.SET_BUILD_GROUP(group)
405 ccflags = CURRENT_CFLAGS(bld, cflags),
406 includes=ilist + ' . #',
407 depends_on=depends_on)
408 LOCAL_CACHE_SET(bld, 'INCLUDE_LIST', modname, ilist)
410 if heimdal_autoproto is not None:
411 bld.HEIMDAL_AUTOPROTO(heimdal_autoproto, source)
412 if heimdal_autoproto_private is not None:
413 bld.HEIMDAL_AUTOPROTO_PRIVATE(heimdal_autoproto_private, source)
414 if autoproto is not None:
415 bld.SAMBA_AUTOPROTO(autoproto, source)
418 Build.BuildContext.SAMBA_SUBSYSTEM = SAMBA_SUBSYSTEM
421 ###############################################################
422 # add a new set of build rules from a subdirectory
423 # the @runonce decorator ensures we don't end up
424 # with duplicate rules
425 def BUILD_SUBDIR(bld, dir):
426 path = os.path.normpath(bld.curdir + '/' + dir)
427 cache = LOCAL_CACHE(bld, 'SUBDIR_LIST')
428 if path in cache: return
430 debug("build: Processing subdirectory %s" % dir)
433 Build.BuildContext.BUILD_SUBDIR = BUILD_SUBDIR
436 ##########################################################
437 # add a new top level command to waf
438 def ADD_COMMAND(opt, name, function):
439 Utils.g_module.__dict__[name] = function
441 Options.Handler.ADD_COMMAND = ADD_COMMAND
443 ###########################################################
444 # setup build groups used to ensure that the different build
445 # phases happen consecutively
447 def SETUP_BUILD_GROUPS(bld):
448 bld.p_ln = bld.srcnode # we do want to see all targets!
449 bld.env['USING_BUILD_GROUPS'] = True
450 bld.add_group('setup')
451 bld.add_group('base_libraries')
452 bld.add_group('build_compilers')
453 bld.add_group('build_source')
454 bld.add_group('prototypes')
455 bld.add_group('main')
456 bld.add_group('final')
457 Build.BuildContext.SETUP_BUILD_GROUPS = SETUP_BUILD_GROUPS
460 ###########################################################
461 # set the current build group
462 def SET_BUILD_GROUP(bld, group):
463 if not 'USING_BUILD_GROUPS' in bld.env:
466 Build.BuildContext.SET_BUILD_GROUP = SET_BUILD_GROUP