1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 from distutils
import sysconfig
10 from distutils
.command
import build_ext
11 from distutils
.dist
import Distribution
12 from distutils
.extension
import Extension
15 """Command line utility to retrieve compilation options for python modules'
17 parser
= argparse
.ArgumentParser(
18 description
='Retrieves compilation options for python modules.')
19 parser
.add_argument('--gn',
20 help='Returns all values in a format suitable for gn',
22 parser
.add_argument('--libraries', help='Returns libraries',
24 parser
.add_argument('--includes', help='Returns includes',
26 parser
.add_argument('--library_dirs', help='Returns library_dirs',
28 opts
= parser
.parse_args()
30 ext
= Extension('Dummy', [])
31 b
= build_ext
.build_ext(Distribution())
32 b
.initialize_options()
36 libraries
= b
.get_libraries(ext
)
37 if sys
.platform
in ['darwin', 'linux2']:
38 # In case of darwin and linux prefix all libraries (if there is any)
39 # so it can be used as a compiler argument.
40 libraries
= ['-l%s' % library
for library
in libraries
]
41 if sys
.platform
== 'darwin':
42 libraries
.append('-lpython%s' % sys
.version
[:3])
43 result
.extend(libraries
)
45 result
= result
+ b
.include_dirs
47 if sys
.platform
== 'darwin':
48 result
.append('%s/lib' % sysconfig
.get_config_vars('prefix')[0])
54 print ''.join(['"%s"' % x
for x
in result
])
56 if __name__
== '__main__':