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")
59 def _check_python_headers(conf
, mandatory
):
60 conf
.check_python_headers(mandatory
=mandatory
)
62 if conf
.env
['PYTHON_VERSION'] > '3':
63 abi_pattern
= os
.path
.splitext(conf
.env
['pyext_PATTERN'])[0]
64 conf
.env
['PYTHON_SO_ABI_FLAG'] = abi_pattern
% ''
66 conf
.env
['PYTHON_SO_ABI_FLAG'] = ''
69 def SAMBA_PYTHON(bld
, name
,
76 init_function_sentinel
=None,
81 '''build a python extension for Samba'''
83 if bld
.env
['IS_EXTRA_PYTHON']:
84 name
= 'extra-' + name
86 # when we support static python modules we'll need to gather
87 # the list from all the SAMBA_PYTHON() targets
88 if init_function_sentinel
is not None:
89 cflags
+= '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
91 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
93 if realname
is not None:
94 link_name
= 'python_modules/%s' % realname
98 bld
.SAMBA_LIBRARY(name
,
101 public_deps
=public_deps
,
104 local_include
=local_include
,
109 target_type
='PYTHON',
110 install_path
='${PYTHONARCHDIR}',
111 allow_undefined_symbols
=True,
116 Build
.BuildContext
.SAMBA_PYTHON
= SAMBA_PYTHON
119 def pyembed_libname(bld
, name
, extrapython
=False):
120 return name
+ bld
.env
['PYTHON_SO_ABI_FLAG']
122 Build
.BuildContext
.pyembed_libname
= pyembed_libname
125 def gen_python_environments(bld
, extra_env_vars
=()):
126 """Generate all Python environments
128 To be used in a for loop. Normally, the loop body will be executed once.
130 When --extra-python is used, the body will additionaly be executed
131 with the extra-python environment active.
135 if bld
.env
['EXTRA_PYTHON']:
136 copied
= ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars
)
138 bld
.all_envs
['extrapython'][name
] = bld
.all_envs
['default'][name
]
139 default_env
= bld
.all_envs
['default']
140 bld
.all_envs
['default'] = bld
.all_envs
['extrapython']
142 bld
.all_envs
['default'] = default_env
144 Build
.BuildContext
.gen_python_environments
= gen_python_environments