PageRenderTime 45ms CodeModel.GetById 41ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/Misc/python-config.in

http://unladen-swallow.googlecode.com/
Autoconf | 61 lines | 44 code | 14 blank | 3 comment | 14 complexity | d32df196539fb4a7ef2e9989fc85b5df MD5 | raw file
 1#!@EXENAME@
 2
 3import sys
 4import os
 5import getopt
 6from distutils import sysconfig
 7
 8valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', 'cxxflags', 
 9              'ldflags', 'help']
10
11def exit_with_usage(code=1):
12    print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
13                                            '|'.join('--'+opt for opt in valid_opts))
14    sys.exit(code)
15
16try:
17    opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
18except getopt.error:
19    exit_with_usage()
20
21if not opts:
22    exit_with_usage()
23
24pyver = sysconfig.get_config_var('VERSION')
25getvar = sysconfig.get_config_var
26
27opt_flags = [flag for (flag, val) in opts]
28
29if '--help' in opt_flags:
30    exit_with_usage(code=0)
31
32for opt in opt_flags:
33    if opt == '--prefix':
34        print sysconfig.PREFIX
35
36    elif opt == '--exec-prefix':
37        print sysconfig.EXEC_PREFIX
38
39    elif opt in ('--includes', '--cflags'):
40        flags = ['-I' + sysconfig.get_python_inc(),
41                 '-I' + sysconfig.get_python_inc(plat_specific=True)]
42        if opt == '--cflags':
43            flags.extend(getvar('CFLAGS').split())
44            flags.extend(getvar('LLVM_CXXFLAGS').split())
45        print ' '.join(flags)
46
47    elif opt == '--cxxflags':
48        print ' '.join(getvar('LLVM_CXXFLAGS').split())
49
50    elif opt in ('--libs', '--ldflags'):
51        libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
52        libs.append('-lpython'+pyver)
53        # add the prefix/lib/pythonX.Y/config dir, but only if there is no
54        # shared library in prefix/lib/.
55        if opt == '--ldflags':
56            if not getvar('Py_ENABLE_SHARED'):
57                libs.insert(0, '-L' + getvar('LIBPL'))
58            libs.extend(getvar('LLVM_LDFLAGS').split())
59            libs.extend(getvar('LINKFORSHARED').split())
60        print ' '.join(libs)
61