2010-05-27 03:36:22 +02:00
|
|
|
# Program to fetch python compilation parameters.
|
2010-07-09 00:12:44 +02:00
|
|
|
# Copied from python-config of the 2.7 release.
|
2010-05-27 03:36:22 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import getopt
|
|
|
|
from distutils import sysconfig
|
|
|
|
|
2010-07-09 00:12:44 +02:00
|
|
|
valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
|
2010-05-27 03:36:22 +02:00
|
|
|
'ldflags', 'help']
|
|
|
|
|
|
|
|
def exit_with_usage(code=1):
|
2012-12-12 17:47:30 +01:00
|
|
|
sys.stderr.write ("Usage: %s [%s]\n" % (sys.argv[0],
|
|
|
|
'|'.join('--'+opt for opt in valid_opts)))
|
2010-05-27 03:36:22 +02:00
|
|
|
sys.exit(code)
|
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
|
|
|
|
except getopt.error:
|
|
|
|
exit_with_usage()
|
|
|
|
|
|
|
|
if not opts:
|
|
|
|
exit_with_usage()
|
|
|
|
|
|
|
|
pyver = sysconfig.get_config_var('VERSION')
|
|
|
|
getvar = sysconfig.get_config_var
|
2012-12-12 17:47:30 +01:00
|
|
|
abiflags = getattr (sys, "abiflags", "")
|
2010-05-27 03:36:22 +02:00
|
|
|
|
2010-07-09 00:12:44 +02:00
|
|
|
opt_flags = [flag for (flag, val) in opts]
|
|
|
|
|
|
|
|
if '--help' in opt_flags:
|
|
|
|
exit_with_usage(code=0)
|
|
|
|
|
allow building GDB with Python support on MinGW
This makes several adjustements to the configure python-config.py
scripts to deal with the differences between a Unix install of Python
and a Windows install of Python (as downloaded from the Python website).
Differences:
- The Python executable is directly in the python prefix directory
as opposed to inside the bin/ subdirectory.
- The name of the python library is does not have a dot in the version
number: On Unix, we have libpython2.7, while on Windows, it's
libpython27. So the regexp extracting the python version from
the Python lib filename had to be adjusted slightly.
Also, the tests checking the name of the libpython had to be
adjusted to allow for that.
- There are no link options following the -lpython<version> switch
on Windows, but the regexp extracting the python version was
using it as a delimiter. It had to be removed.
- python-config.py does not work on Windows, mostly because
some sysconfig variables are missing. They are not necessary
so the script was adapted to skip them if not defined.
- The paths returned by python-config.py follow the Windows filename
convention in terms of the directory separator, and this is causing
trouble when the build environment is cygwin (while the compiler
and Python are MinGW). We could have fixed that in the configure
script, but it felt simpler to do so in python-config.py
gdb/ChangeLog:
* configure.ac: Add handling of Python distribution on Windows.
* python-config.py: If the LIBS, SYSLIBS, LIBPL and/or LINKFORSHARED
sysconfig variables are not defined, then do not use them.
On Windows, if LIBPL is not defined, then use prefix + '/libs'
instead. On Windows, return all paths using forward-slashes
rather than backslashes.
2011-01-31 05:42:08 +01:00
|
|
|
def to_unix_path(path):
|
|
|
|
"""On Windows, returns the given path with all backslashes
|
|
|
|
converted into forward slashes. This is to help prevent problems
|
|
|
|
when using the paths returned by this script with cygwin tools.
|
|
|
|
In particular, cygwin bash treats backslashes as a special character.
|
|
|
|
|
|
|
|
On Unix systems, returns the path unchanged.
|
|
|
|
"""
|
|
|
|
if os.name == 'nt':
|
|
|
|
path = path.replace('\\', '/')
|
|
|
|
return path
|
|
|
|
|
2010-07-09 00:12:44 +02:00
|
|
|
for opt in opt_flags:
|
|
|
|
if opt == '--prefix':
|
2012-12-12 17:47:30 +01:00
|
|
|
print (to_unix_path(sysconfig.PREFIX))
|
2010-07-09 00:12:44 +02:00
|
|
|
|
|
|
|
elif opt == '--exec-prefix':
|
2012-12-12 17:47:30 +01:00
|
|
|
print (to_unix_path(sysconfig.EXEC_PREFIX))
|
2010-07-09 00:12:44 +02:00
|
|
|
|
|
|
|
elif opt in ('--includes', '--cflags'):
|
|
|
|
flags = ['-I' + sysconfig.get_python_inc(),
|
|
|
|
'-I' + sysconfig.get_python_inc(plat_specific=True)]
|
|
|
|
if opt == '--cflags':
|
|
|
|
flags.extend(getvar('CFLAGS').split())
|
2012-12-12 17:47:30 +01:00
|
|
|
print (to_unix_path(' '.join(flags)))
|
2010-07-09 00:12:44 +02:00
|
|
|
|
|
|
|
elif opt in ('--libs', '--ldflags'):
|
allow building GDB with Python support on MinGW
This makes several adjustements to the configure python-config.py
scripts to deal with the differences between a Unix install of Python
and a Windows install of Python (as downloaded from the Python website).
Differences:
- The Python executable is directly in the python prefix directory
as opposed to inside the bin/ subdirectory.
- The name of the python library is does not have a dot in the version
number: On Unix, we have libpython2.7, while on Windows, it's
libpython27. So the regexp extracting the python version from
the Python lib filename had to be adjusted slightly.
Also, the tests checking the name of the libpython had to be
adjusted to allow for that.
- There are no link options following the -lpython<version> switch
on Windows, but the regexp extracting the python version was
using it as a delimiter. It had to be removed.
- python-config.py does not work on Windows, mostly because
some sysconfig variables are missing. They are not necessary
so the script was adapted to skip them if not defined.
- The paths returned by python-config.py follow the Windows filename
convention in terms of the directory separator, and this is causing
trouble when the build environment is cygwin (while the compiler
and Python are MinGW). We could have fixed that in the configure
script, but it felt simpler to do so in python-config.py
gdb/ChangeLog:
* configure.ac: Add handling of Python distribution on Windows.
* python-config.py: If the LIBS, SYSLIBS, LIBPL and/or LINKFORSHARED
sysconfig variables are not defined, then do not use them.
On Windows, if LIBPL is not defined, then use prefix + '/libs'
instead. On Windows, return all paths using forward-slashes
rather than backslashes.
2011-01-31 05:42:08 +01:00
|
|
|
libs = []
|
|
|
|
if getvar('LIBS') is not None:
|
|
|
|
libs.extend(getvar('LIBS').split())
|
|
|
|
if getvar('SYSLIBS') is not None:
|
|
|
|
libs.extend(getvar('SYSLIBS').split())
|
2012-12-12 17:47:30 +01:00
|
|
|
libs.append('-lpython'+pyver + abiflags)
|
2010-07-09 00:12:44 +02:00
|
|
|
# add the prefix/lib/pythonX.Y/config dir, but only if there is no
|
|
|
|
# shared library in prefix/lib/.
|
|
|
|
if opt == '--ldflags':
|
|
|
|
if not getvar('Py_ENABLE_SHARED'):
|
allow building GDB with Python support on MinGW
This makes several adjustements to the configure python-config.py
scripts to deal with the differences between a Unix install of Python
and a Windows install of Python (as downloaded from the Python website).
Differences:
- The Python executable is directly in the python prefix directory
as opposed to inside the bin/ subdirectory.
- The name of the python library is does not have a dot in the version
number: On Unix, we have libpython2.7, while on Windows, it's
libpython27. So the regexp extracting the python version from
the Python lib filename had to be adjusted slightly.
Also, the tests checking the name of the libpython had to be
adjusted to allow for that.
- There are no link options following the -lpython<version> switch
on Windows, but the regexp extracting the python version was
using it as a delimiter. It had to be removed.
- python-config.py does not work on Windows, mostly because
some sysconfig variables are missing. They are not necessary
so the script was adapted to skip them if not defined.
- The paths returned by python-config.py follow the Windows filename
convention in terms of the directory separator, and this is causing
trouble when the build environment is cygwin (while the compiler
and Python are MinGW). We could have fixed that in the configure
script, but it felt simpler to do so in python-config.py
gdb/ChangeLog:
* configure.ac: Add handling of Python distribution on Windows.
* python-config.py: If the LIBS, SYSLIBS, LIBPL and/or LINKFORSHARED
sysconfig variables are not defined, then do not use them.
On Windows, if LIBPL is not defined, then use prefix + '/libs'
instead. On Windows, return all paths using forward-slashes
rather than backslashes.
2011-01-31 05:42:08 +01:00
|
|
|
if getvar('LIBPL') is not None:
|
|
|
|
libs.insert(0, '-L' + getvar('LIBPL'))
|
|
|
|
elif os.name == 'nt':
|
|
|
|
libs.insert(0, '-L' + sysconfig.PREFIX + '/libs')
|
|
|
|
if getvar('LINKFORSHARED') is not None:
|
|
|
|
libs.extend(getvar('LINKFORSHARED').split())
|
2012-12-12 17:47:30 +01:00
|
|
|
print (to_unix_path(' '.join(libs)))
|
2010-05-27 03:36:22 +02:00
|
|
|
|