6 from distutils import sysconfig
8 valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
11 def exit_with_usage(code=1):
12 print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
13 '|'.join('--'+opt for opt in valid_opts))
17 opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
24 pyver = sysconfig.get_config_var('VERSION')
25 getvar = sysconfig.get_config_var
27 opt_flags = [flag for (flag, val) in opts]
29 if '--help' in opt_flags:
30 exit_with_usage(code=0)
34 print sysconfig.PREFIX
36 elif opt == '--exec-prefix':
37 print sysconfig.EXEC_PREFIX
39 elif opt in ('--includes', '--cflags'):
40 flags = ['-I' + sysconfig.get_python_inc(),
41 '-I' + sysconfig.get_python_inc(plat_specific=True)]
43 flags.extend(getvar('CFLAGS').split())
46 elif opt in ('--libs', '--ldflags'):
47 libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
48 libs.append('-lpython'+pyver)
49 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
50 # shared library in prefix/lib/.
51 if opt == '--ldflags':
52 if not getvar('Py_ENABLE_SHARED'):
53 libs.insert(0, '-L' + getvar('LIBPL'))
54 libs.extend(getvar('LINKFORSHARED').split())