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['EXTRA_PYTHON']:
13 conf.all_envs['extrapython'] = conf.env.copy()
14 conf.setenv('extrapython')
15 conf.env['PYTHON'] = conf.env['EXTRA_PYTHON']
16 conf.env['IS_EXTRA_PYTHON'] = 'yes'
17 conf.find_program('python', var='PYTHON', mandatory=True)
18 conf.check_tool('python')
20 conf.check_python_version((3, 3, 0))
22 warn('extra-python needs to be Python 3.3 or later')
24 conf.setenv('default')
26 conf.find_program('python', var='PYTHON', mandatory=mandatory)
27 conf.check_tool('python')
28 path_python = conf.find_program('python')
29 conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
30 conf.check_python_version(version)
34 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
35 if conf.env["python_headers_checked"] == []:
36 if conf.env['EXTRA_PYTHON']:
37 conf.setenv('extrapython')
38 _check_python_headers(conf, mandatory=True)
39 conf.setenv('default')
41 _check_python_headers(conf, mandatory)
42 conf.env["python_headers_checked"] = "yes"
44 if conf.env['EXTRA_PYTHON']:
45 extraversion = conf.all_envs['extrapython']['PYTHON_VERSION']
46 if extraversion == conf.env['PYTHON_VERSION']:
47 raise Utils.WafError("extrapython %s is same as main python %s" % (
48 extraversion, conf.env['PYTHON_VERSION']))
50 conf.msg("python headers", "using cache")
53 def _check_python_headers(conf, mandatory):
54 conf.check_python_headers(mandatory=mandatory)
56 if conf.env['PYTHON_VERSION'] > '3':
57 abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
58 conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
60 conf.env['PYTHON_SO_ABI_FLAG'] = ''
63 def SAMBA_PYTHON(bld, name,
70 init_function_sentinel=None,
75 '''build a python extension for Samba'''
77 # when we support static python modules we'll need to gather
78 # the list from all the SAMBA_PYTHON() targets
79 if init_function_sentinel is not None:
80 cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
82 source = bld.EXPAND_VARIABLES(source, vars=vars)
84 if realname is not None:
85 link_name = 'python_modules/%s' % realname
89 bld.SAMBA_LIBRARY(name,
92 public_deps=public_deps,
95 local_include=local_include,
100 target_type='PYTHON',
101 install_path='${PYTHONARCHDIR}',
102 allow_undefined_symbols=True,
107 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
110 def pyembed_libname(bld, name, extrapython=False):
111 return name + bld.env['PYTHON_SO_ABI_FLAG']
113 Build.BuildContext.pyembed_libname = pyembed_libname