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
12 if conf
.env
.HAVE_PYTHON_H
:
13 conf
.check_python_version(version
)
18 if conf
.env
['EXTRA_PYTHON']:
19 conf
.all_envs
['extrapython'] = conf
.env
.copy()
20 conf
.setenv('extrapython')
21 conf
.env
['PYTHON'] = conf
.env
['EXTRA_PYTHON']
22 conf
.env
['IS_EXTRA_PYTHON'] = 'yes'
23 conf
.find_program('python', var
='PYTHON', mandatory
=True)
24 conf
.check_tool('python')
26 conf
.check_python_version((3, 3, 0))
28 Logs
.warn('extra-python needs to be Python 3.3 or later')
30 interpreters
.append(conf
.env
['PYTHON'])
31 conf
.setenv('default')
33 conf
.find_program('python', var
='PYTHON', mandatory
=mandatory
)
34 conf
.check_tool('python')
35 path_python
= conf
.find_program('python')
36 conf
.env
.PYTHON_SPECIFIED
= (conf
.env
.PYTHON
!= path_python
)
37 conf
.check_python_version(version
)
39 interpreters
.append(conf
.env
['PYTHON'])
40 conf
.env
.python_interpreters
= interpreters
44 def SAMBA_CHECK_PYTHON_HEADERS(conf
, mandatory
=True):
45 if conf
.env
["python_headers_checked"] == []:
46 if conf
.env
['EXTRA_PYTHON']:
47 conf
.setenv('extrapython')
48 _check_python_headers(conf
, mandatory
=True)
49 conf
.setenv('default')
51 _check_python_headers(conf
, mandatory
)
52 conf
.env
["python_headers_checked"] = "yes"
54 if conf
.env
['EXTRA_PYTHON']:
55 extraversion
= conf
.all_envs
['extrapython']['PYTHON_VERSION']
56 if extraversion
== conf
.env
['PYTHON_VERSION']:
57 raise Utils
.WafError("extrapython %s is same as main python %s" % (
58 extraversion
, conf
.env
['PYTHON_VERSION']))
60 conf
.msg("python headers", "using cache")
62 # we don't want PYTHONDIR in config.h, as otherwise changing
63 # --prefix causes a complete rebuild
64 del(conf
.env
.defines
['PYTHONDIR'])
65 del(conf
.env
.defines
['PYTHONARCHDIR'])
67 def _check_python_headers(conf
, mandatory
):
68 conf
.check_python_headers(mandatory
=mandatory
)
70 if conf
.env
['PYTHON_VERSION'] > '3':
71 abi_pattern
= os
.path
.splitext(conf
.env
['pyext_PATTERN'])[0]
72 conf
.env
['PYTHON_SO_ABI_FLAG'] = abi_pattern
% ''
74 conf
.env
['PYTHON_SO_ABI_FLAG'] = ''
77 def SAMBA_PYTHON(bld
, name
,
84 init_function_sentinel
=None,
89 '''build a python extension for Samba'''
91 if bld
.env
['IS_EXTRA_PYTHON']:
92 name
= 'extra-' + name
94 # when we support static python modules we'll need to gather
95 # the list from all the SAMBA_PYTHON() targets
96 if init_function_sentinel
is not None:
97 cflags
+= '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
99 source
= bld
.EXPAND_VARIABLES(source
, vars=vars)
101 if realname
is not None:
102 link_name
= 'python_modules/%s' % realname
106 bld
.SAMBA_LIBRARY(name
,
109 public_deps
=public_deps
,
112 local_include
=local_include
,
117 target_type
='PYTHON',
118 install_path
='${PYTHONARCHDIR}',
119 allow_undefined_symbols
=True,
123 Build
.BuildContext
.SAMBA_PYTHON
= SAMBA_PYTHON
126 def pyembed_libname(bld
, name
, extrapython
=False):
127 return name
+ bld
.env
['PYTHON_SO_ABI_FLAG']
129 Build
.BuildContext
.pyembed_libname
= pyembed_libname
132 def gen_python_environments(bld
, extra_env_vars
=()):
133 """Generate all Python environments
135 To be used in a for loop. Normally, the loop body will be executed once.
137 When --extra-python is used, the body will additionaly be executed
138 with the extra-python environment active.
142 if bld
.env
['EXTRA_PYTHON']:
143 copied
= ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars
)
145 bld
.all_envs
['extrapython'][name
] = bld
.all_envs
['default'][name
]
146 default_env
= bld
.all_envs
['default']
147 bld
.all_envs
['default'] = bld
.all_envs
['extrapython']
149 bld
.all_envs
['default'] = default_env
151 Build
.BuildContext
.gen_python_environments
= gen_python_environments