]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/config/python.py
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / boost / libs / python / config / python.py
1 #
2 # Copyright (c) 2016 Stefan Seefeld
3 # All rights reserved.
4 #
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or copy at
7 # http://www.boost.org/LICENSE_1_0.txt)
8
9 from . import ui
10
11 def add_options(vars):
12
13 ui.add_option('--python', help='the python executable')
14
15
16 def check(context):
17
18 python_source_file = r"""
19 // If defined, enforces linking againg PythonXXd.lib, which
20 // is usually not included in Python environments.
21 #undef _DEBUG
22 #include "Python.h"
23 int main()
24 {
25 Py_Initialize();
26 Py_Finalize();
27 return 0;
28 }
29 """
30
31 import platform
32 import subprocess
33 import re, os
34
35 def check_python(cmd):
36 return subprocess.check_output([python, '-c', cmd]).strip()
37
38 def check_sysconfig(cmd):
39 r = check_python('import distutils.sysconfig as c; print(c.%s)'%cmd)
40 return r if r != 'None' else ''
41
42 context.Message('Checking for Python...')
43 python = context.env.GetOption('python') or 'python'
44 context.env['PYTHON'] = python
45 incpath = check_sysconfig('get_python_inc()')
46 context.env.AppendUnique(CPPPATH=[incpath])
47 if platform.system() == 'Windows':
48 version = check_python('import sys; print("%d%d"%sys.version_info[0:2])')
49 prefix = check_python('import sys; print(sys.prefix)')
50 libfile = os.path.join(prefix, 'libs', 'python%s.lib'%version)
51 libpath = os.path.join(prefix, 'libs')
52 lib = 'python%s'%version
53 context.env.AppendUnique(LIBS=[lib])
54 else:
55 libpath = check_sysconfig('get_config_var("LIBDIR")')
56 libfile = check_sysconfig('get_config_var("LIBRARY")')
57 match = re.search('(python.*)\.(a|so|dylib)', libfile)
58 lib = None
59 if match:
60 lib = match.group(1)
61 context.env.AppendUnique(PYTHONLIBS=[lib])
62 if match.group(2) == 'a':
63 flags = check_sysconfig('get_config_var("LINKFORSHARED")')
64 if flags is not None:
65 context.env.AppendUnique(LINKFLAGS=flags.split())
66 context.env.AppendUnique(LIBPATH=[libpath])
67 oldlibs = context.AppendLIBS([lib])
68 flags = check_sysconfig('get_config_var("MODLIBS")')
69 flags += ' ' + check_sysconfig('get_config_var("SHLIBS")')
70 flags = [f[2:] for f in flags.strip().split() if f.startswith('-l')]
71 if flags:
72 context.AppendLIBS([flags])
73 result = context.TryLink(python_source_file,'.cpp')
74 if not result and context.env['PLATFORM'] == 'darwin':
75 # Sometimes we need some extra stuff on Mac OS
76 frameworkDir = libpath # search up the libDir tree for the proper home for frameworks
77 while frameworkDir and frameworkDir != "/":
78 frameworkDir, d2 = os.path.split(frameworkDir)
79 if d2 == "Python.framework":
80 if not "Python" in os.listdir(os.path.join(frameworkDir, d2)):
81 context.Result(0)
82 print((
83 "Expected to find Python in framework directory %s, but it isn't there"
84 % frameworkDir))
85 return False
86 break
87 context.env.AppendUnique(LINKFLAGS="-F%s" % frameworkDir)
88 result = context.TryLink(python_source_file,'.cpp')
89 if not result:
90 context.Result(0)
91 print("Cannot link program with Python.")
92 return False
93 if context.env['PLATFORM'] == 'darwin':
94 context.env['LDMODULESUFFIX'] = '.so'
95 context.Result(1)
96 context.SetLIBS(oldlibs)
97 context.env.AppendUnique(PYTHONLIBS=[lib] + flags)
98 return True