]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/python/python-config.py
Updates to how-to-make-a-release document after creating the 2.45 branch
[thirdparty/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 3
ec685c5e 4import getopt
c2cf30e7
TT
5import os
6import sys
be2057b9 7import sysconfig
ec685c5e 8
13123da8
SM
9valid_opts = ["prefix", "exec-prefix", "includes", "libs", "cflags", "ldflags", "help"]
10
ec685c5e
DE
11
12def exit_with_usage(code=1):
13123da8
SM
13 sys.stderr.write(
14 "Usage: %s [%s]\n" % (sys.argv[0], "|".join("--" + opt for opt in valid_opts))
15 )
ec685c5e
DE
16 sys.exit(code)
17
13123da8 18
ec685c5e 19try:
13123da8 20 opts, args = getopt.getopt(sys.argv[1:], "", valid_opts)
ec685c5e
DE
21except getopt.error:
22 exit_with_usage()
23
24if not opts:
25 exit_with_usage()
26
13123da8 27pyver = sysconfig.get_config_var("VERSION")
ec685c5e 28getvar = sysconfig.get_config_var
13123da8 29abiflags = getattr(sys, "abiflags", "")
ec685c5e 30
7e6e39e5
JB
31opt_flags = [flag for (flag, val) in opts]
32
13123da8 33if "--help" in opt_flags:
7e6e39e5
JB
34 exit_with_usage(code=0)
35
13123da8 36
9c4ea6c5
JB
37def to_unix_path(path):
38 """On Windows, returns the given path with all backslashes
39 converted into forward slashes. This is to help prevent problems
40 when using the paths returned by this script with cygwin tools.
41 In particular, cygwin bash treats backslashes as a special character.
42
43 On Unix systems, returns the path unchanged.
44 """
13123da8
SM
45 if os.name == "nt":
46 path = path.replace("\\", "/")
9c4ea6c5
JB
47 return path
48
13123da8 49
7e6e39e5 50for opt in opt_flags:
13123da8 51 if opt == "--prefix":
be2057b9 52 print(to_unix_path(os.path.normpath(sys.prefix)))
13123da8
SM
53
54 elif opt == "--exec-prefix":
be2057b9 55 print(to_unix_path(os.path.normpath(sys.exec_prefix)))
13123da8
SM
56
57 elif opt in ("--includes", "--cflags"):
58 flags = [
be2057b9
LS
59 "-I" + sysconfig.get_path("include"),
60 "-I" + sysconfig.get_path("platinclude"),
13123da8
SM
61 ]
62 if opt == "--cflags":
63 flags.extend(getvar("CFLAGS").split())
64 print(to_unix_path(" ".join(flags)))
65
66 elif opt in ("--libs", "--ldflags"):
67 libs = ["-lpython" + pyver + abiflags]
68 if getvar("LIBS") is not None:
69 libs.extend(getvar("LIBS").split())
70 if getvar("SYSLIBS") is not None:
71 libs.extend(getvar("SYSLIBS").split())
7e6e39e5
JB
72 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
73 # shared library in prefix/lib/.
13123da8
SM
74 if opt == "--ldflags":
75 if not getvar("Py_ENABLE_SHARED"):
76 if getvar("LIBPL") is not None:
77 libs.insert(0, "-L" + getvar("LIBPL"))
78 elif os.name == "nt":
be2057b9 79 libs.insert(0, "-L" + os.path.normpath(sys.prefix) + "/libs")
13123da8
SM
80 if getvar("LINKFORSHARED") is not None:
81 libs.extend(getvar("LINKFORSHARED").split())
82 print(to_unix_path(" ".join(libs)))