blob: 727c4a8682270fc6a77ced0aeda0684b63bd00bd [file] [log] [blame]
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001#!@EXENAME@
Barry Warsawf040d7d2010-10-18 17:09:07 +00002# -*- python -*-
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003
doko@ubuntu.com0df35b02013-08-01 15:32:49 +02004# Keep this script in sync with python-config.sh.in
5
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00006import getopt
Collin Winter67091772010-04-06 21:30:42 +00007import os
8import sys
9import sysconfig
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000010
Georg Brandl7046e972007-09-01 07:27:37 +000011valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
Victor Stinner0a8e5722019-05-23 03:30:23 +020012 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir',
13 'embed']
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000014
15def exit_with_usage(code=1):
Georg Brandl7046e972007-09-01 07:27:37 +000016 print("Usage: {0} [{1}]".format(
17 sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000018 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
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000028pyver = sysconfig.get_config_var('VERSION')
29getvar = sysconfig.get_config_var
30
Collin Winterbf199072010-03-19 21:17:17 +000031opt_flags = [flag for (flag, val) in opts]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000032
Collin Winterbf199072010-03-19 21:17:17 +000033if '--help' in opt_flags:
34 exit_with_usage(code=0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000035
Collin Winterbf199072010-03-19 21:17:17 +000036for opt in opt_flags:
37 if opt == '--prefix':
Collin Winter67091772010-04-06 21:30:42 +000038 print(sysconfig.get_config_var('prefix'))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000039
Collin Winterbf199072010-03-19 21:17:17 +000040 elif opt == '--exec-prefix':
Collin Winter67091772010-04-06 21:30:42 +000041 print(sysconfig.get_config_var('exec_prefix'))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000042
Collin Winterbf199072010-03-19 21:17:17 +000043 elif opt in ('--includes', '--cflags'):
Collin Winter67091772010-04-06 21:30:42 +000044 flags = ['-I' + sysconfig.get_path('include'),
45 '-I' + sysconfig.get_path('platinclude')]
Collin Winterbf199072010-03-19 21:17:17 +000046 if opt == '--cflags':
47 flags.extend(getvar('CFLAGS').split())
48 print(' '.join(flags))
49
50 elif opt in ('--libs', '--ldflags'):
Victor Stinner0a8e5722019-05-23 03:30:23 +020051 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)
xdegaye254b3092019-04-29 09:27:40 +020058 libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split())
59
Collin Winterbf199072010-03-19 21:17:17 +000060 # 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'))
Collin Winterbf199072010-03-19 21:17:17 +000065 print(' '.join(libs))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000066
Georg Brandlb084b482010-09-12 17:14:26 +000067 elif opt == '--extension-suffix':
doko@ubuntu.comd5537d02013-03-21 13:21:49 -070068 print(sysconfig.get_config_var('EXT_SUFFIX'))
Barry Warsaw8cf4eae2010-10-16 01:04:07 +000069
70 elif opt == '--abiflags':
71 print(sys.abiflags)
Barry Warsaw9eeea482012-07-26 18:12:07 -040072
73 elif opt == '--configdir':
74 print(sysconfig.get_config_var('LIBPL'))