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