Commit | Line | Data |
---|---|---|
ec685c5e | 1 | # Program to fetch python compilation parameters. |
7e6e39e5 | 2 | # Copied from python-config of the 2.7 release. |
ec685c5e DE |
3 | |
4 | import sys | |
5 | import os | |
6 | import getopt | |
7 | from distutils import sysconfig | |
8 | ||
7e6e39e5 | 9 | valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', |
ec685c5e DE |
10 | 'ldflags', 'help'] |
11 | ||
12 | def exit_with_usage(code=1): | |
7e6e39e5 | 13 | print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0], |
ec685c5e DE |
14 | '|'.join('--'+opt for opt in valid_opts)) |
15 | sys.exit(code) | |
16 | ||
17 | try: | |
18 | opts, args = getopt.getopt(sys.argv[1:], '', valid_opts) | |
19 | except getopt.error: | |
20 | exit_with_usage() | |
21 | ||
22 | if not opts: | |
23 | exit_with_usage() | |
24 | ||
ec685c5e DE |
25 | pyver = sysconfig.get_config_var('VERSION') |
26 | getvar = sysconfig.get_config_var | |
27 | ||
7e6e39e5 JB |
28 | opt_flags = [flag for (flag, val) in opts] |
29 | ||
30 | if '--help' in opt_flags: | |
31 | exit_with_usage(code=0) | |
32 | ||
33 | for opt in opt_flags: | |
34 | if opt == '--prefix': | |
35 | print sysconfig.PREFIX | |
36 | ||
37 | elif opt == '--exec-prefix': | |
38 | print sysconfig.EXEC_PREFIX | |
39 | ||
40 | elif opt in ('--includes', '--cflags'): | |
41 | flags = ['-I' + sysconfig.get_python_inc(), | |
42 | '-I' + sysconfig.get_python_inc(plat_specific=True)] | |
43 | if opt == '--cflags': | |
44 | flags.extend(getvar('CFLAGS').split()) | |
45 | print ' '.join(flags) | |
46 | ||
47 | elif opt in ('--libs', '--ldflags'): | |
48 | libs = getvar('LIBS').split() + getvar('SYSLIBS').split() | |
49 | libs.append('-lpython'+pyver) | |
50 | # add the prefix/lib/pythonX.Y/config dir, but only if there is no | |
51 | # shared library in prefix/lib/. | |
52 | if opt == '--ldflags': | |
53 | if not getvar('Py_ENABLE_SHARED'): | |
54 | libs.insert(0, '-L' + getvar('LIBPL')) | |
55 | libs.extend(getvar('LINKFORSHARED').split()) | |
56 | print ' '.join(libs) | |
ec685c5e | 57 |