]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/config/python.py
2 # Copyright (c) 2016 Stefan Seefeld
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)
11 def add_options(vars):
13 ui
.add_option('--python', help='the python executable')
18 python_source_file
= r
"""
19 // If defined, enforces linking againg PythonXXd.lib, which
20 // is usually not included in Python environments.
35 def check_python(cmd
):
36 return subprocess
.check_output([python
, '-c', cmd
]).strip()
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 ''
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
])
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
)
61 context
.env
.AppendUnique(PYTHONLIBS
=[lib
])
62 if match
.group(2) == 'a':
63 flags
= check_sysconfig('get_config_var("LINKFORSHARED")')
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')]
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
)):
83 "Expected to find Python in framework directory %s, but it isn't there"
87 context
.env
.AppendUnique(LINKFLAGS
="-F%s" % frameworkDir
)
88 result
= context
.TryLink(python_source_file
,'.cpp')
91 print("Cannot link program with Python.")
93 if context
.env
['PLATFORM'] == 'darwin':
94 context
.env
['LDMODULESUFFIX'] = '.so'
96 context
.SetLIBS(oldlibs
)
97 context
.env
.AppendUnique(PYTHONLIBS
=[lib
] + flags
)