1 # Program to fetch python compilation parameters.
2 # Copied from python-config of the 2.7 release.
9 valid_opts
= ["prefix", "exec-prefix", "includes", "libs", "cflags", "ldflags", "help"]
12 def exit_with_usage(code
=1):
14 "Usage: %s [%s]\n" % (sys
.argv
[0], "|".join("--" + opt
for opt
in valid_opts
))
20 opts
, args
= getopt
.getopt(sys
.argv
[1:], "", valid_opts
)
27 pyver
= sysconfig
.get_config_var("VERSION")
28 getvar
= sysconfig
.get_config_var
29 abiflags
= getattr(sys
, "abiflags", "")
31 opt_flags
= [flag
for (flag
, val
) in opts
]
33 if "--help" in opt_flags
:
34 exit_with_usage(code
=0)
37 def 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.
43 On Unix systems, returns the path unchanged.
46 path
= path
.replace("\\", "/")
52 print(to_unix_path(os
.path
.normpath(sys
.prefix
)))
54 elif opt
== "--exec-prefix":
55 print(to_unix_path(os
.path
.normpath(sys
.exec_prefix
)))
57 elif opt
in ("--includes", "--cflags"):
59 "-I" + sysconfig
.get_path("include"),
60 "-I" + sysconfig
.get_path("platinclude"),
63 flags
.extend(getvar("CFLAGS").split())
64 print(to_unix_path(" ".join(flags
)))
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())
72 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
73 # shared library in prefix/lib/.
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"))
79 libs
.insert(0, "-L" + os
.path
.normpath(sys
.prefix
) + "/libs")
80 if getvar("LINKFORSHARED") is not None:
81 libs
.extend(getvar("LINKFORSHARED").split())
82 print(to_unix_path(" ".join(libs
)))