gdb/
[deliverable/binutils-gdb.git] / gdb / python / python-config.py
CommitLineData
ec685c5e 1# Program to fetch python compilation parameters.
7e6e39e5 2# Copied from python-config of the 2.7 release.
ec685c5e
DE
3
4import sys
5import os
6import getopt
7from distutils import sysconfig
8
7e6e39e5 9valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
ec685c5e
DE
10 'ldflags', 'help']
11
12def exit_with_usage(code=1):
7e6e39e5 13 print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
ec685c5e
DE
14 '|'.join('--'+opt for opt in valid_opts))
15 sys.exit(code)
16
17try:
18 opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
19except getopt.error:
20 exit_with_usage()
21
22if not opts:
23 exit_with_usage()
24
ec685c5e
DE
25pyver = sysconfig.get_config_var('VERSION')
26getvar = sysconfig.get_config_var
27
7e6e39e5
JB
28opt_flags = [flag for (flag, val) in opts]
29
30if '--help' in opt_flags:
31 exit_with_usage(code=0)
32
9c4ea6c5
JB
33def to_unix_path(path):
34 """On Windows, returns the given path with all backslashes
35 converted into forward slashes. This is to help prevent problems
36 when using the paths returned by this script with cygwin tools.
37 In particular, cygwin bash treats backslashes as a special character.
38
39 On Unix systems, returns the path unchanged.
40 """
41 if os.name == 'nt':
42 path = path.replace('\\', '/')
43 return path
44
7e6e39e5
JB
45for opt in opt_flags:
46 if opt == '--prefix':
9c4ea6c5 47 print to_unix_path(sysconfig.PREFIX)
7e6e39e5
JB
48
49 elif opt == '--exec-prefix':
9c4ea6c5 50 print to_unix_path(sysconfig.EXEC_PREFIX)
7e6e39e5
JB
51
52 elif opt in ('--includes', '--cflags'):
53 flags = ['-I' + sysconfig.get_python_inc(),
54 '-I' + sysconfig.get_python_inc(plat_specific=True)]
55 if opt == '--cflags':
56 flags.extend(getvar('CFLAGS').split())
9c4ea6c5 57 print to_unix_path(' '.join(flags))
7e6e39e5
JB
58
59 elif opt in ('--libs', '--ldflags'):
9c4ea6c5
JB
60 libs = []
61 if getvar('LIBS') is not None:
62 libs.extend(getvar('LIBS').split())
63 if getvar('SYSLIBS') is not None:
64 libs.extend(getvar('SYSLIBS').split())
7e6e39e5
JB
65 libs.append('-lpython'+pyver)
66 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
67 # shared library in prefix/lib/.
68 if opt == '--ldflags':
69 if not getvar('Py_ENABLE_SHARED'):
9c4ea6c5
JB
70 if getvar('LIBPL') is not None:
71 libs.insert(0, '-L' + getvar('LIBPL'))
72 elif os.name == 'nt':
73 libs.insert(0, '-L' + sysconfig.PREFIX + '/libs')
74 if getvar('LINKFORSHARED') is not None:
75 libs.extend(getvar('LINKFORSHARED').split())
76 print to_unix_path(' '.join(libs))
ec685c5e 77
This page took 0.410551 seconds and 4 git commands to generate.