build: support variable expansion in source= arguments to build rules
[nivanova/samba-autobuild/.git] / buildtools / wafsamba / samba_python.py
1 # waf build tool for building IDL files with pidl
2
3 import Build
4 from samba_utils import *
5 from samba_autoconf import *
6
7
8 def SAMBA_PYTHON(bld, name,
9                  source='',
10                  deps='',
11                  public_deps='',
12                  realname=None,
13                  cflags='',
14                  includes='',
15                  init_function_sentinal=None,
16                  local_include=True,
17                  vars=None,
18                  enabled=True):
19     '''build a python extension for Samba'''
20
21     # when we support static python modules we'll need to gather
22     # the list from all the SAMBA_PYTHON() targets
23     if init_function_sentinal is not None:
24         cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinal
25
26     source = bld.EXPAND_VARIABLES(source, vars=vars)
27
28     if realname is None:
29         # a SAMBA_PYTHON target without a realname is just a
30         # subsystem with needs_python=True
31         return bld.SAMBA_SUBSYSTEM(name,
32                                    source=source,
33                                    deps=deps,
34                                    public_deps=public_deps,
35                                    cflags=cflags,
36                                    includes=includes,
37                                    init_function_sentinal=init_function_sentinal,
38                                    local_include=local_include,
39                                    needs_python=True,
40                                    enabled=enabled)
41
42     if not enabled:
43         SET_TARGET_TYPE(bld, name, 'DISABLED')
44         return
45
46     if not SET_TARGET_TYPE(bld, name, 'PYTHON'):
47         return
48
49     deps += ' ' + public_deps
50
51     if realname is None:
52         realname = '%s.so' % name
53     link_name = 'python/%s' % realname
54
55     t = bld(
56         features       = 'cc cshlib pyext symlink_lib',
57         source         = source,
58         target         = name,
59         samba_cflags   = CURRENT_CFLAGS(bld, name, cflags),
60         samba_includes = includes,
61         local_include  = local_include,
62         samba_deps     = TO_LIST(deps),
63         link_name      = link_name,
64         name           = name
65         )
66 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON