1 # waf build tool for building IDL files with pidl
4 import Build, Logs, Utils, Configure
5 from Configure import conf
8 def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
9 # enable tool to build python extensions
10 if conf.env.HAVE_PYTHON_H:
11 conf.check_python_version(version)
16 if conf.env['EXTRA_PYTHON']:
17 conf.all_envs['extrapython'] = conf.env.copy()
18 conf.setenv('extrapython')
19 conf.env['PYTHON'] = conf.env['EXTRA_PYTHON']
20 conf.env['IS_EXTRA_PYTHON'] = 'yes'
21 conf.find_program('python', var='PYTHON', mandatory=True)
22 conf.check_tool('python')
24 conf.check_python_version((3, 3, 0))
26 Logs.warn('extra-python needs to be Python 3.3 or later')
28 interpreters.append(conf.env['PYTHON'])
29 conf.setenv('default')
31 conf.find_program('python', var='PYTHON', mandatory=mandatory)
32 conf.check_tool('python')
33 path_python = conf.find_program('python')
34 conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
35 conf.check_python_version(version)
37 interpreters.append(conf.env['PYTHON'])
38 conf.env.python_interpreters = interpreters
42 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
43 if conf.env["python_headers_checked"] == []:
44 if conf.env['EXTRA_PYTHON']:
45 conf.setenv('extrapython')
46 _check_python_headers(conf, mandatory=True)
47 conf.setenv('default')
49 _check_python_headers(conf, mandatory)
50 conf.env["python_headers_checked"] = "yes"
52 if conf.env['EXTRA_PYTHON']:
53 extraversion = conf.all_envs['extrapython']['PYTHON_VERSION']
54 if extraversion == conf.env['PYTHON_VERSION']:
55 raise Utils.WafError("extrapython %s is same as main python %s" % (
56 extraversion, conf.env['PYTHON_VERSION']))
58 conf.msg("python headers", "using cache")
60 # we don't want PYTHONDIR in config.h, as otherwise changing
61 # --prefix causes a complete rebuild
62 del(conf.env.defines['PYTHONDIR'])
63 del(conf.env.defines['PYTHONARCHDIR'])
65 def _check_python_headers(conf, mandatory):
67 Configure.ConfigurationError
68 conf.check_python_headers(mandatory=mandatory)
69 except Configure.ConfigurationError:
73 if conf.env['PYTHON_VERSION'] > '3':
74 abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
75 conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
77 conf.env['PYTHON_SO_ABI_FLAG'] = ''
80 def SAMBA_PYTHON(bld, name,
87 init_function_sentinel=None,
92 '''build a python extension for Samba'''
94 if bld.env['IS_EXTRA_PYTHON']:
95 name = 'extra-' + name
97 # when we support static python modules we'll need to gather
98 # the list from all the SAMBA_PYTHON() targets
99 if init_function_sentinel is not None:
100 cflags += '-DSTATIC_LIBPYTHON_MODULES=%s' % init_function_sentinel
102 source = bld.EXPAND_VARIABLES(source, vars=vars)
104 if realname is not None:
105 link_name = 'python_modules/%s' % realname
109 bld.SAMBA_LIBRARY(name,
112 public_deps=public_deps,
115 local_include=local_include,
120 target_type='PYTHON',
121 install_path='${PYTHONARCHDIR}',
122 allow_undefined_symbols=True,
126 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
129 def pyembed_libname(bld, name, extrapython=False):
130 return name + bld.env['PYTHON_SO_ABI_FLAG']
132 Build.BuildContext.pyembed_libname = pyembed_libname
135 def gen_python_environments(bld, extra_env_vars=()):
136 """Generate all Python environments
138 To be used in a for loop. Normally, the loop body will be executed once.
140 When --extra-python is used, the body will additionaly be executed
141 with the extra-python environment active.
145 if bld.env['EXTRA_PYTHON']:
146 copied = ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars)
148 bld.all_envs['extrapython'][name] = bld.all_envs['default'][name]
149 default_env = bld.all_envs['default']
150 bld.all_envs['default'] = bld.all_envs['extrapython']
152 bld.all_envs['default'] = default_env
154 Build.BuildContext.gen_python_environments = gen_python_environments