2015-11-23 13:44:26 +03:00
#!/usr/bin/env python
import os
2020-08-18 02:59:09 +03:00
from waflib import Options, Errors
2015-11-23 13:44:26 +03:00
2020-08-17 08:14:25 +03:00
# work out what python external libraries we need to be successful
selftest_pkgs = {
2020-08-18 02:59:09 +03:00
'cryptography': 'python3-cryptography',
2021-01-05 11:33:30 +03:00
'pyasn1': 'python3-pyasn1'
2020-08-18 02:59:09 +03:00
}
ad_dc_pkgs = {
'markdown': 'python3-markdown',
'dns': 'python3-dnspython (python3-dns on some systems)'
2020-08-17 08:14:25 +03:00
}
2021-07-21 10:17:31 +03:00
def find_third_party_module(conf, module, package, required=True):
2020-08-17 08:14:25 +03:00
conf.COMPOUND_START("Checking for system installation of Python module %s" % module)
try:
__import__(module)
except ImportError:
conf.COMPOUND_END(False)
2021-07-21 10:17:31 +03:00
if not required:
return False
2020-08-17 08:14:25 +03:00
raise Errors.WafError("""\
Unable to find Python module '%s'. Please install the system package: %s'.
""" % (module, package))
else:
# Installed on the system
conf.COMPOUND_END("system")
2021-07-21 10:17:31 +03:00
return True
2020-08-17 08:14:25 +03:00
2015-11-23 13:44:26 +03:00
def configure(conf):
2019-01-23 12:55:58 +03:00
if conf.env.disable_python:
return
2018-02-02 17:34:32 +03:00
kerberos_py = conf.srcnode.abspath() + "/python/samba/provision/kerberos_implementation.py"
2015-11-23 13:44:26 +03:00
f = open(kerberos_py, 'w')
try:
header = """#
# Copyright (c) 2016 Andreas Schneider <asn@samba.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
f.write(header)
data = """kdb_modules_dir = "{0}"
"""
if conf.env.HEIMDAL_KRB5_CONFIG:
2022-05-05 12:21:28 +03:00
f.write(data.format(""))
2015-11-23 13:44:26 +03:00
else:
modulesdir = "%s/krb5/plugins/kdb" % conf.env.LIBDIR
2017-05-03 10:19:38 +03:00
f.write(data.format(modulesdir))
2015-11-23 13:44:26 +03:00
finally:
f.close()
2015-11-23 17:08:54 +03:00
2020-08-17 08:14:25 +03:00
if conf.CONFIG_GET('ENABLE_SELFTEST'):
for module, package in selftest_pkgs.items():
find_third_party_module(conf, module, package)
2021-07-21 10:17:31 +03:00
# Prefer dateutil.parser which is much more widely used.
if not find_third_party_module(conf,
'dateutil.parser',
'python3-dateutilis',
required=False):
if not find_third_party_module(conf,
'iso8601',
'python3-iso8601',
required=False):
raise Errors.WafError("Could not find Python package "
"'python3-dateutils' nor "
"'python3-iso8601'. Please install "
"one of the packages.")
2020-08-18 02:59:09 +03:00
if not Options.options.without_ad_dc:
for module, package in ad_dc_pkgs.items():
find_third_party_module(conf, module, package)
2020-08-17 08:14:25 +03:00
2015-11-23 17:08:54 +03:00
def build(bld):
2018-04-06 18:35:49 +03:00
2015-11-23 17:08:54 +03:00
2019-02-15 06:37:48 +03:00
pytalloc_util = bld.pyembed_libname('pytalloc-util')
pyparam_util = bld.pyembed_libname('pyparam_util')
libpython = bld.pyembed_libname('LIBPYTHON')
pyrpc_util = bld.pyembed_libname('pyrpc_util')
samba_python = bld.pyembed_libname('samba_python')
bld.SAMBA_LIBRARY(samba_python,
2018-04-06 18:35:49 +03:00
source=[],
deps='%s %s %s' % (libpython, pytalloc_util, pyrpc_util),
grouping_library=True,
private_library=True,
pyembed=True,
enabled=bld.PYTHON_BUILD_IS_ENABLED())
2019-02-15 06:37:48 +03:00
bld.SAMBA_PYTHON('python_glue',
source='pyglue.c',
deps='''
2015-11-23 17:08:54 +03:00
%s
samba-util
netif
2021-05-25 12:12:44 +03:00
ndr
2023-07-21 04:29:22 +03:00
cmdline
2023-12-12 08:31:34 +03:00
gkdi
2015-11-23 17:08:54 +03:00
%s
''' % (pyparam_util, pytalloc_util),
2019-02-15 06:37:48 +03:00
realname='samba/_glue.so')
2015-11-23 17:08:54 +03:00
2019-02-15 06:37:48 +03:00
bld.SAMBA_SUBSYSTEM(libpython,
source='modules.c',
public_deps='',
init_function_sentinel='{NULL,NULL}',
deps='talloc',
pyext=True,
enabled=bld.PYTHON_BUILD_IS_ENABLED())
2017-04-20 16:11:58 +03:00
2015-11-23 17:08:54 +03:00
if bld.PYTHON_BUILD_IS_ENABLED():
2019-02-15 06:37:48 +03:00
# install out various python scripts for use by make test
bld.SAMBA_SCRIPT('samba_python_files',
pattern='samba/**/*.py',
installdir='python')
2021-07-21 10:17:31 +03:00
2019-02-15 06:37:48 +03:00
bld.INSTALL_WILDCARD('${PYTHONARCHDIR}', 'samba/**/*.py', flat=False)