includes='',
init_function_sentinal=None,
local_include=True,
+ vars=None,
enabled=True):
'''build a python extension for Samba'''
if init_function_sentinal is not None:
cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinal
+ source = bld.EXPAND_VARIABLES(source, vars=vars)
+
if realname is None:
# a SAMBA_PYTHON target without a realname is just a
# subsystem with needs_python=True
limit -= 1
return string
+@conf
+def EXPAND_VARIABLES(ctx, varstr, vars=None):
+ '''expand variables from a user supplied dictionary
+
+ This is most useful when you pass vars=locals() to expand
+ all your local variables in strings
+ '''
+
+ if isinstance(varstr, list):
+ ret = []
+ for s in varstr:
+ ret.append(EXPAND_VARIABLES(ctx, s, vars=vars))
+ return ret
+
+ import Environment
+ env = Environment.Environment()
+ ret = varstr
+ # substitute on user supplied dict if avaiilable
+ if vars is not None:
+ for v in vars.keys():
+ env[v] = vars[v]
+ ret = SUBST_VARS_RECURSIVE(ret, env)
+
+ # if anything left, subst on the environment as well
+ if ret.find('${'):
+ ret = SUBST_VARS_RECURSIVE(ret, ctx.env)
+ # make sure there is nothing left. Also check for the common
+ # typo of $( instead of ${
+ if ret.find('${') != -1 or ret.find('$(') != -1:
+ print('Failed to substitute all variables in varstr=%s' % ret)
+ raise
+ return ret
+Build.BuildContext.EXPAND_VARIABLES = EXPAND_VARIABLES
+
def RUN_COMMAND(cmd,
env=None,
group='main',
depends_on='',
local_include=True,
+ vars=None,
install_path=None,
install=True,
enabled=True):
SET_TARGET_TYPE(bld, libname, 'DISABLED')
return
+ source = bld.EXPAND_VARIABLES(source, vars=vars)
+
# remember empty libraries, so we can strip the dependencies
if (source == '') or (source == []):
SET_TARGET_TYPE(bld, libname, 'EMPTY')
local_include=True,
subsystem_name=None,
needs_python=False,
+ vars=None,
install=True,
install_path=None):
obj_target = binname + '.objlist'
+ source = bld.EXPAND_VARIABLES(source, vars=vars)
+
# first create a target for building the object files for this binary
# by separating in this way, we avoid recompiling the C files
# separately for the install binary and the build binary
cflags='',
internal_module=True,
local_include=True,
+ vars=None,
enabled=True):
# we add the init function regardless of whether the module
SET_TARGET_TYPE(bld, modname, 'DISABLED')
return
+ source = bld.EXPAND_VARIABLES(source, vars=vars)
+
# remember empty modules, so we can strip the dependencies
if (source == '') or (source == []):
SET_TARGET_TYPE(bld, modname, 'EMPTY')
local_include_first=True,
subsystem_name=None,
enabled=True,
+ vars=None,
needs_python=False):
if not enabled:
if not SET_TARGET_TYPE(bld, modname, 'SUBSYSTEM'):
return
+ source = bld.EXPAND_VARIABLES(source, vars=vars)
+
deps += ' ' + public_deps
bld.SET_BUILD_GROUP(group)
def SAMBA_GENERATOR(bld, name, rule, source, target,
- group='build_source', enabled=True):
+ group='build_source', enabled=True,
+ vars=None):
'''A generic source generator target'''
if not SET_TARGET_TYPE(bld, name, 'GENERATOR'):
bld.SET_BUILD_GROUP(group)
bld(
rule=rule,
- source=source,
+ source=bld.EXPAND_VARIABLES(source, vars=vars),
target=target,
shell=True,
on_results=True,