buildtools: Expose the Python 3 ABI tag
[Samba.git] / buildtools / wafsamba / samba_python.py
blobb90655d9a2cb6a154776d13fc7dbb774276b85fe
1 # waf build tool for building IDL files with pidl
3 import Build
4 from samba_utils import *
5 from samba_autoconf import *
7 from Configure import conf
9 @conf
10 def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
11 # enable tool to build python extensions
12 conf.find_program('python', var='PYTHON', mandatory=mandatory)
13 conf.check_tool('python')
14 path_python = conf.find_program('python')
15 conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
16 conf.check_python_version(version)
18 @conf
19 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
20 if conf.env["python_headers_checked"] == []:
21 conf.check_python_headers(mandatory)
22 conf.env["python_headers_checked"] = "yes"
23 else:
24 conf.msg("python headers", "using cache")
26 if conf.env['PYTHON_VERSION'] > '3':
27 abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
28 conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
29 else:
30 conf.env['PYTHON_SO_ABI_FLAG'] = ''
33 def SAMBA_PYTHON(bld, name,
34 source='',
35 deps='',
36 public_deps='',
37 realname=None,
38 cflags='',
39 includes='',
40 init_function_sentinel=None,
41 local_include=True,
42 vars=None,
43 install=True,
44 enabled=True):
45 '''build a python extension for Samba'''
47 # when we support static python modules we'll need to gather
48 # the list from all the SAMBA_PYTHON() targets
49 if init_function_sentinel is not None:
50 cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
52 source = bld.EXPAND_VARIABLES(source, vars=vars)
54 if realname is not None:
55 link_name = 'python_modules/%s' % realname
56 else:
57 link_name = None
59 bld.SAMBA_LIBRARY(name,
60 source=source,
61 deps=deps,
62 public_deps=public_deps,
63 includes=includes,
64 cflags=cflags,
65 local_include=local_include,
66 vars=vars,
67 realname=realname,
68 link_name=link_name,
69 pyext=True,
70 target_type='PYTHON',
71 install_path='${PYTHONARCHDIR}',
72 allow_undefined_symbols=True,
73 allow_warnings=True,
74 install=install,
75 enabled=enabled)
77 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
80 def pyembed_libname(bld, name, extrapython=False):
81 return name + bld.env['PYTHON_SO_ABI_FLAG']
83 Build.BuildContext.pyembed_libname = pyembed_libname