GDB (API)
/home/stan/gdb/src/gdb/python/python-config.py
Go to the documentation of this file.
00001 # Program to fetch python compilation parameters.
00002 # Copied from python-config of the 2.7 release.
00003 
00004 import sys
00005 import os
00006 import getopt
00007 from distutils import sysconfig
00008 
00009 valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
00010               'ldflags', 'help']
00011 
00012 def exit_with_usage(code=1):
00013     sys.stderr.write ("Usage: %s [%s]\n" % (sys.argv[0],
00014                                           '|'.join('--'+opt for opt in valid_opts)))
00015     sys.exit(code)
00016 
00017 try:
00018     opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
00019 except getopt.error:
00020     exit_with_usage()
00021 
00022 if not opts:
00023     exit_with_usage()
00024 
00025 pyver = sysconfig.get_config_var('VERSION')
00026 getvar = sysconfig.get_config_var
00027 abiflags = getattr (sys, "abiflags", "")
00028 
00029 opt_flags = [flag for (flag, val) in opts]
00030 
00031 if '--help' in opt_flags:
00032     exit_with_usage(code=0)
00033 
00034 def to_unix_path(path):
00035     """On Windows, returns the given path with all backslashes
00036     converted into forward slashes.  This is to help prevent problems
00037     when using the paths returned by this script with cygwin tools.
00038     In particular, cygwin bash treats backslashes as a special character.
00039 
00040     On Unix systems, returns the path unchanged.
00041     """
00042     if os.name == 'nt':
00043         path = path.replace('\\', '/')
00044     return path
00045 
00046 for opt in opt_flags:
00047     if opt == '--prefix':
00048         print (to_unix_path(sysconfig.PREFIX))
00049 
00050     elif opt == '--exec-prefix':
00051         print (to_unix_path(sysconfig.EXEC_PREFIX))
00052 
00053     elif opt in ('--includes', '--cflags'):
00054         flags = ['-I' + sysconfig.get_python_inc(),
00055                  '-I' + sysconfig.get_python_inc(plat_specific=True)]
00056         if opt == '--cflags':
00057             flags.extend(getvar('CFLAGS').split())
00058         print (to_unix_path(' '.join(flags)))
00059 
00060     elif opt in ('--libs', '--ldflags'):
00061         libs = []
00062         if getvar('LIBS') is not None:
00063             libs.extend(getvar('LIBS').split())
00064         if getvar('SYSLIBS') is not None:
00065             libs.extend(getvar('SYSLIBS').split())
00066         libs.append('-lpython'+pyver + abiflags)
00067         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
00068         # shared library in prefix/lib/.
00069         if opt == '--ldflags':
00070             if not getvar('Py_ENABLE_SHARED'):
00071                 if getvar('LIBPL') is not None:
00072                     libs.insert(0, '-L' + getvar('LIBPL'))
00073                 elif os.name == 'nt':
00074                     libs.insert(0, '-L' + sysconfig.PREFIX + '/libs')
00075             if getvar('LINKFORSHARED') is not None:
00076                 libs.extend(getvar('LINKFORSHARED').split())
00077         print (to_unix_path(' '.join(libs)))
00078 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines