2010-03-17 14:07:11 +03:00
# waf build tool for building IDL files with pidl
2018-11-29 18:12:10 +03:00
import os , sys
2018-01-31 12:48:43 +03:00
from waflib import Build , Logs , Utils , Configure , Errors
from waflib . Configure import conf
2013-04-08 09:57:45 +04:00
@conf
2020-03-04 03:51:23 +03:00
def SAMBA_CHECK_PYTHON ( conf , version = ( 3 , 6 , 0 ) ) :
2019-02-15 07:45:27 +03:00
2013-04-08 09:57:45 +04:00
# enable tool to build python extensions
2015-06-08 20:02:03 +03:00
if conf . env . HAVE_PYTHON_H :
conf . check_python_version ( version )
return
2015-03-10 20:19:14 +03:00
interpreters = [ ]
2019-02-15 06:13:48 +03:00
conf . find_program ( ' python3 ' , var = ' PYTHON ' ,
mandatory = not conf . env . disable_python )
2018-01-31 12:48:43 +03:00
conf . load ( ' python ' )
2018-12-13 20:03:13 +03:00
path_python = conf . find_program ( ' python3 ' )
2018-12-12 23:30:32 +03:00
2013-04-08 09:57:45 +04:00
conf . env . PYTHON_SPECIFIED = ( conf . env . PYTHON != path_python )
2013-04-08 11:25:27 +04:00
conf . check_python_version ( version )
2013-04-08 09:57:45 +04:00
2015-03-10 20:19:14 +03:00
interpreters . append ( conf . env [ ' PYTHON ' ] )
conf . env . python_interpreters = interpreters
2015-01-15 16:22:22 +03:00
2010-12-10 01:42:32 +03:00
@conf
2019-02-15 06:13:48 +03:00
def SAMBA_CHECK_PYTHON_HEADERS ( conf ) :
2017-01-27 21:28:01 +03:00
if conf . env . disable_python :
conf . msg ( " python headers " , " Check disabled due to --disable-python " )
# we don't want PYTHONDIR in config.h, as otherwise changing
# --prefix causes a complete rebuild
2016-03-26 15:18:07 +03:00
conf . env . DEFINES = [ x for x in conf . env . DEFINES
if not x . startswith ( ' PYTHONDIR= ' )
and not x . startswith ( ' PYTHONARCHDIR= ' ) ]
2017-01-27 21:28:01 +03:00
return
2010-12-10 01:42:32 +03:00
if conf . env [ " python_headers_checked " ] == [ ] :
2019-02-15 06:13:48 +03:00
_check_python_headers ( conf )
2010-12-10 01:42:32 +03:00
conf . env [ " python_headers_checked " ] = " yes "
2015-01-15 16:22:22 +03:00
2010-12-10 01:42:32 +03:00
else :
conf . msg ( " python headers " , " using cache " )
2015-06-19 00:45:11 +03:00
# we don't want PYTHONDIR in config.h, as otherwise changing
# --prefix causes a complete rebuild
2016-03-26 15:18:07 +03:00
conf . env . DEFINES = [ x for x in conf . env . DEFINES
if not x . startswith ( ' PYTHONDIR= ' )
and not x . startswith ( ' PYTHONARCHDIR= ' ) ]
2015-01-15 16:22:22 +03:00
2019-02-15 06:13:48 +03:00
def _check_python_headers ( conf ) :
conf . check_python_headers ( )
2015-01-15 16:22:22 +03:00
2020-09-11 02:05:58 +03:00
abi_pattern = os . path . splitext ( conf . env [ ' pyext_PATTERN ' ] ) [ 0 ]
conf . env [ ' PYTHON_SO_ABI_FLAG ' ] = abi_pattern % ' '
2017-03-06 09:25:13 +03:00
conf . env [ ' PYTHON_LIBNAME_SO_ABI_FLAG ' ] = (
conf . env [ ' PYTHON_SO_ABI_FLAG ' ] . replace ( ' _ ' , ' - ' ) )
2015-05-06 13:45:42 +03:00
2017-03-28 16:28:21 +03:00
for lib in conf . env [ ' LINKFLAGS_PYEMBED ' ] :
if lib . startswith ( ' -L ' ) :
conf . env . append_unique ( ' LIBPATH_PYEMBED ' , lib [ 2 : ] ) # strip '-L'
conf . env [ ' LINKFLAGS_PYEMBED ' ] . remove ( lib )
2016-03-26 15:18:07 +03:00
# same as in waf 1.5, keep only '-fno-strict-aliasing'
# and ignore defines such as NDEBUG _FORTIFY_SOURCE=2
conf . env . DEFINES_PYEXT = [ ]
conf . env . CFLAGS_PYEXT = [ ' -fno-strict-aliasing ' ]
2017-03-28 16:28:21 +03:00
return
2010-03-17 14:07:11 +03:00
2017-01-27 21:28:01 +03:00
def PYTHON_BUILD_IS_ENABLED ( self ) :
return self . CONFIG_SET ( ' HAVE_PYTHON_H ' )
Build . BuildContext . PYTHON_BUILD_IS_ENABLED = PYTHON_BUILD_IS_ENABLED
2010-03-17 14:07:11 +03:00
def SAMBA_PYTHON ( bld , name ,
source = ' ' ,
deps = ' ' ,
public_deps = ' ' ,
realname = None ,
cflags = ' ' ,
2017-11-19 14:32:16 +03:00
cflags_end = None ,
2010-03-17 14:07:11 +03:00
includes = ' ' ,
2012-04-09 16:33:37 +04:00
init_function_sentinel = None ,
2010-03-17 14:07:11 +03:00
local_include = True ,
2010-03-25 01:23:10 +03:00
vars = None ,
2015-03-06 13:55:49 +03:00
install = True ,
2010-03-17 14:07:11 +03:00
enabled = True ) :
''' build a python extension for Samba '''
2017-01-27 21:28:01 +03:00
# force-disable when we can't build python modules, so
# every single call doesn't need to pass this in.
if not bld . PYTHON_BUILD_IS_ENABLED ( ) :
enabled = False
2019-12-07 03:37:10 +03:00
# Save time, no need to build python bindings when fuzzing
if bld . env . enable_fuzzing :
enabled = False
2010-03-17 12:12:16 +03:00
# when we support static python modules we'll need to gather
# the list from all the SAMBA_PYTHON() targets
2012-04-09 16:33:37 +04:00
if init_function_sentinel is not None :
2016-01-06 02:28:44 +03:00
cflags + = ' -DSTATIC_LIBPYTHON_MODULES= %s ' % init_function_sentinel
2010-03-17 12:12:16 +03:00
2016-01-06 01:57:39 +03:00
# From https://docs.python.org/2/c-api/arg.html:
# Starting with Python 2.5 the type of the length argument to
# PyArg_ParseTuple(), PyArg_ParseTupleAndKeywords() and PyArg_Parse()
# can be controlled by defining the macro PY_SSIZE_T_CLEAN before
# including Python.h. If the macro is defined, length is a Py_ssize_t
# rather than an int.
# Because <Python.h> if often included before includes.h/config.h
# This must be in the -D compiler options
cflags + = ' -DPY_SSIZE_T_CLEAN=1 '
2010-03-25 01:23:10 +03:00
source = bld . EXPAND_VARIABLES ( source , vars = vars )
2011-11-13 20:50:52 +04:00
if realname is not None :
2018-07-03 11:09:12 +03:00
link_name = ' python/ %s ' % realname
2011-11-13 20:50:52 +04:00
else :
link_name = None
2010-03-17 14:07:11 +03:00
2010-03-29 08:19:13 +04:00
bld . SAMBA_LIBRARY ( name ,
source = source ,
deps = deps ,
public_deps = public_deps ,
includes = includes ,
cflags = cflags ,
2017-11-19 14:32:16 +03:00
cflags_end = cflags_end ,
2010-03-29 08:19:13 +04:00
local_include = local_include ,
vars = vars ,
2011-11-13 20:50:52 +04:00
realname = realname ,
2010-03-29 08:19:13 +04:00
link_name = link_name ,
2011-11-12 08:20:10 +04:00
pyext = True ,
2010-03-29 08:19:13 +04:00
target_type = ' PYTHON ' ,
2011-01-14 09:20:01 +03:00
install_path = ' $ {PYTHONARCHDIR} ' ,
2011-11-13 20:50:52 +04:00
allow_undefined_symbols = True ,
2015-03-06 13:55:49 +03:00
install = install ,
2010-03-29 08:19:13 +04:00
enabled = enabled )
2010-03-27 06:50:43 +03:00
2010-03-17 14:07:11 +03:00
Build . BuildContext . SAMBA_PYTHON = SAMBA_PYTHON
2015-05-06 13:45:42 +03:00
2019-02-15 06:28:38 +03:00
def pyembed_libname ( bld , name ) :
2017-01-27 21:28:01 +03:00
if bld . env [ ' PYTHON_SO_ABI_FLAG ' ] :
return name + bld . env [ ' PYTHON_SO_ABI_FLAG ' ]
else :
return name
2015-05-06 13:45:42 +03:00
Build . BuildContext . pyembed_libname = pyembed_libname
2015-05-06 18:50:57 +03:00