1 # waf build tool for building IDL files with pidl
4 from samba_utils
import *
5 from samba_autoconf
import *
7 from Configure
import conf
10 def SAMBA_CHECK_PYTHON(conf
, mandatory
=True, version
=(2,4,2)):
11 # enable tool to build python extensions
14 if conf
.env
['EXTRA_PYTHON']:
15 conf
.all_envs
['extrapython'] = conf
.env
.copy()
16 conf
.setenv('extrapython')
17 conf
.env
['PYTHON'] = conf
.env
['EXTRA_PYTHON']
18 conf
.env
['IS_EXTRA_PYTHON'] = 'yes'
19 conf
.find_program('python', var
='PYTHON', mandatory
=True)
20 conf
.check_tool('python')
22 conf
.check_python_version((3, 3, 0))
24 warn('extra-python needs to be Python 3.3 or later')
26 interpreters
.append(conf
.env
['PYTHON'])
27 conf
.setenv('default')
29 conf
.find_program('python', var
='PYTHON', mandatory
=mandatory
)
30 conf
.check_tool('python')
31 path_python
= conf
.find_program('python')
32 conf
.env
.PYTHON_SPECIFIED
= (conf
.env
.PYTHON
!= path_python
)
33 conf
.check_python_version(version
)
35 interpreters
.append(conf
.env
['PYTHON'])
36 conf
.env
.python_interpreters
= interpreters
40 def SAMBA_CHECK_PYTHON_HEADERS(conf
, mandatory
=True):
41 if conf
.env
["python_headers_checked"] == []:
42 if conf
.env
['EXTRA_PYTHON']:
43 conf
.setenv('extrapython')
44 _check_python_headers(conf
, mandatory
=True)
45 conf
.setenv('default')
47 _check_python_headers(conf
, mandatory
)
48 conf
.env
["python_headers_checked"] = "yes"
50 if conf
.env
['EXTRA_PYTHON']:
51 extraversion
= conf
.all_envs
['extrapython']['PYTHON_VERSION']
52 if extraversion
== conf
.env
['PYTHON_VERSION']:
53 raise Utils
.WafError("extrapython %s is same as main python %s" % (
54 extraversion
, conf
.env
['PYTHON_VERSION']))
56 conf
.msg("python headers", "using cache")
58 # we don't want PYTHONDIR in config.h, as otherwise changing
59 # --prefix causes a complete rebuild
60 del(conf
.env
.defines
['PYTHONDIR'])
61 del(conf
.env
.defines
['PYTHONARCHDIR'])
63 def _check_python_headers(conf
, mandatory
):
64 conf
.check_python_headers(mandatory
=mandatory
)
66 if conf
.env
['PYTHON_VERSION'] > '3':
67 abi_pattern
= os
.path
.splitext(conf
.env
['pyext_PATTERN'])[0]
68 conf
.env
['PYTHON_SO_ABI_FLAG'] = abi_pattern
% ''
70 conf
.env
['PYTHON_SO_ABI_FLAG'] = ''
73 def SAMBA_PYTHON(bld
, name
,
80 init_function_sentinel
=None,
85 '''build a python extension for Samba'''
87 if bld
.env
['IS_EXTRA_PYTHON']:
88 name
= 'extra-' + name
90 # when we support static python modules we'll need to gather
91 # the list from all the SAMBA_PYTHON() targets
92 if init_function_sentinel
is not None:
93 cflags
+= '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
95 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
97 if realname
is not None:
98 link_name
= 'python_modules/%s' % realname
102 bld
.SAMBA_LIBRARY(name
,
105 public_deps
=public_deps
,
108 local_include
=local_include
,
113 target_type
='PYTHON',
114 install_path
='${PYTHONARCHDIR}',
115 allow_undefined_symbols
=True,
119 Build
.BuildContext
.SAMBA_PYTHON
= SAMBA_PYTHON
122 def pyembed_libname(bld
, name
, extrapython
=False):
123 return name
+ bld
.env
['PYTHON_SO_ABI_FLAG']
125 Build
.BuildContext
.pyembed_libname
= pyembed_libname
128 def gen_python_environments(bld
, extra_env_vars
=()):
129 """Generate all Python environments
131 To be used in a for loop. Normally, the loop body will be executed once.
133 When --extra-python is used, the body will additionaly be executed
134 with the extra-python environment active.
138 if bld
.env
['EXTRA_PYTHON']:
139 copied
= ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars
)
141 bld
.all_envs
['extrapython'][name
] = bld
.all_envs
['default'][name
]
142 default_env
= bld
.all_envs
['default']
143 bld
.all_envs
['default'] = bld
.all_envs
['extrapython']
145 bld
.all_envs
['default'] = default_env
147 Build
.BuildContext
.gen_python_environments
= gen_python_environments