blob: f9d35b2be523e21908d4ccff5d8b26387b1cba0a [file] [log] [blame]
Yi Kong878f9942023-12-13 12:55:04 +09001#!/tmpfs/src/git/out/python3/install/bin/python3.10
2# -*- python -*-
3
4# Keep this script in sync with python-config.sh.in
5
6import getopt
7import os
8import sys
9import sysconfig
10
11valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
12 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir',
13 'embed']
14
15def exit_with_usage(code=1):
16 print("Usage: {0} [{1}]".format(
17 sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
18 sys.exit(code)
19
20try:
21 opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
22except getopt.error:
23 exit_with_usage()
24
25if not opts:
26 exit_with_usage()
27
28getvar = sysconfig.get_config_var
29pyver = getvar('VERSION')
30
31opt_flags = [flag for (flag, val) in opts]
32
33if '--help' in opt_flags:
34 exit_with_usage(code=0)
35
36for opt in opt_flags:
37 if opt == '--prefix':
38 print(getvar('prefix'))
39
40 elif opt == '--exec-prefix':
41 print(getvar('exec_prefix'))
42
43 elif opt in ('--includes', '--cflags'):
44 flags = ['-I' + sysconfig.get_path('include'),
45 '-I' + sysconfig.get_path('platinclude')]
46 if opt == '--cflags':
47 flags.extend(getvar('CFLAGS').split())
48 print(' '.join(flags))
49
50 elif opt in ('--libs', '--ldflags'):
51 libs = []
52 if '--embed' in opt_flags:
53 libs.append('-lpython' + pyver + sys.abiflags)
54 else:
55 libpython = getvar('LIBPYTHON')
56 if libpython:
57 libs.append(libpython)
58 libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split())
59
60 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
61 # shared library in prefix/lib/.
62 if opt == '--ldflags':
63 if not getvar('Py_ENABLE_SHARED'):
64 libs.insert(0, '-L' + getvar('LIBPL'))
65 print(' '.join(libs))
66
67 elif opt == '--extension-suffix':
68 print(getvar('EXT_SUFFIX'))
69
70 elif opt == '--abiflags':
71 print(sys.abiflags)
72
73 elif opt == '--configdir':
74 print(getvar('LIBPL'))