smbdotconf: add client ldap sasl wrapping = {starttls,ldaps}
[samba.git] / buildtools / wafsamba / samba_python.py
blob12a94c8079d6474bd49f5e654fce889a8d1f7dcb
1 # waf build tool for building IDL files with pidl
3 import os, sys
4 from waflib import Build, Logs, Utils, Configure, Errors
5 from waflib.Configure import conf
7 @conf
8 def SAMBA_CHECK_PYTHON(conf, version=(3,6,0)):
10 # enable tool to build python extensions
11 if conf.env.HAVE_PYTHON_H:
12 conf.check_python_version(version)
13 return
15 interpreters = []
17 conf.find_program('python3', var='PYTHON',
18 mandatory=not conf.env.disable_python)
19 conf.load('python')
20 path_python = conf.find_program('python3')
22 conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
23 conf.check_python_version(version)
25 interpreters.append(conf.env['PYTHON'])
26 conf.env.python_interpreters = interpreters
29 @conf
30 def SAMBA_CHECK_PYTHON_HEADERS(conf):
31 if conf.env.disable_python:
33 conf.msg("python headers", "Check disabled due to --disable-python")
34 # we don't want PYTHONDIR in config.h, as otherwise changing
35 # --prefix causes a complete rebuild
36 conf.env.DEFINES = [x for x in conf.env.DEFINES
37 if not x.startswith('PYTHONDIR=')
38 and not x.startswith('PYTHONARCHDIR=')]
40 return
42 if conf.env["python_headers_checked"] == []:
43 _check_python_headers(conf)
44 conf.env["python_headers_checked"] = "yes"
46 else:
47 conf.msg("python headers", "using cache")
49 # we don't want PYTHONDIR in config.h, as otherwise changing
50 # --prefix causes a complete rebuild
51 conf.env.DEFINES = [x for x in conf.env.DEFINES
52 if not x.startswith('PYTHONDIR=')
53 and not x.startswith('PYTHONARCHDIR=')]
55 def _check_python_headers(conf):
56 conf.check_python_headers()
58 abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
59 conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
60 conf.env['PYTHON_LIBNAME_SO_ABI_FLAG'] = (
61 conf.env['PYTHON_SO_ABI_FLAG'].replace('_', '-'))
63 for lib in conf.env['LINKFLAGS_PYEMBED']:
64 if lib.startswith('-L'):
65 conf.env.append_unique('LIBPATH_PYEMBED', lib[2:]) # strip '-L'
66 conf.env['LINKFLAGS_PYEMBED'].remove(lib)
68 # same as in waf 1.5, keep only '-fno-strict-aliasing'
69 # and ignore defines such as NDEBUG _FORTIFY_SOURCE=2
70 conf.env.DEFINES_PYEXT = []
71 conf.env.CFLAGS_PYEXT = ['-fno-strict-aliasing']
73 return
75 def PYTHON_BUILD_IS_ENABLED(self):
76 return self.CONFIG_SET('HAVE_PYTHON_H')
78 Build.BuildContext.PYTHON_BUILD_IS_ENABLED = PYTHON_BUILD_IS_ENABLED
81 def SAMBA_PYTHON(bld, name,
82 source='',
83 deps='',
84 public_deps='',
85 realname=None,
86 cflags='',
87 cflags_end=None,
88 includes='',
89 init_function_sentinel=None,
90 local_include=True,
91 vars=None,
92 install=True,
93 enabled=True):
94 '''build a python extension for Samba'''
96 # force-disable when we can't build python modules, so
97 # every single call doesn't need to pass this in.
98 if not bld.PYTHON_BUILD_IS_ENABLED():
99 enabled = False
101 # Save time, no need to build python bindings when fuzzing
102 if bld.env.enable_fuzzing:
103 enabled = False
105 # when we support static python modules we'll need to gather
106 # the list from all the SAMBA_PYTHON() targets
107 if init_function_sentinel is not None:
108 cflags += ' -DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
110 # From https://docs.python.org/2/c-api/arg.html:
111 # Starting with Python 2.5 the type of the length argument to
112 # PyArg_ParseTuple(), PyArg_ParseTupleAndKeywords() and PyArg_Parse()
113 # can be controlled by defining the macro PY_SSIZE_T_CLEAN before
114 # including Python.h. If the macro is defined, length is a Py_ssize_t
115 # rather than an int.
117 # Because <Python.h> if often included before includes.h/config.h
118 # This must be in the -D compiler options
119 cflags += ' -DPY_SSIZE_T_CLEAN=1'
121 source = bld.EXPAND_VARIABLES(source, vars=vars)
123 if realname is not None:
124 link_name = 'python/%s' % realname
125 else:
126 link_name = None
128 bld.SAMBA_LIBRARY(name,
129 source=source,
130 deps=deps,
131 public_deps=public_deps,
132 includes=includes,
133 cflags=cflags,
134 cflags_end=cflags_end,
135 local_include=local_include,
136 vars=vars,
137 realname=realname,
138 link_name=link_name,
139 pyext=True,
140 target_type='PYTHON',
141 install_path='${PYTHONARCHDIR}',
142 allow_undefined_symbols=True,
143 install=install,
144 enabled=enabled)
146 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
149 def pyembed_libname(bld, name):
150 if bld.env['PYTHON_SO_ABI_FLAG']:
151 return name + bld.env['PYTHON_SO_ABI_FLAG']
152 else:
153 return name
155 Build.BuildContext.pyembed_libname = pyembed_libname