blob: 47ea669bd52aa22a8fdfe673f3b4134bda6d4264 [file] [log] [blame]
Thomas Wouters0e3f5912006-08-11 14:57:12 +00001#!@EXENAME@
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002
3import sys
4import os
5import getopt
6from distutils import sysconfig
7
Georg Brandl7046e972007-09-01 07:27:37 +00008valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00009 'ldflags', 'help']
10
11def exit_with_usage(code=1):
Georg Brandl7046e972007-09-01 07:27:37 +000012 print("Usage: {0} [{1}]".format(
13 sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000014 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
24opt = opts[0][0]
25
26pyver = sysconfig.get_config_var('VERSION')
27getvar = sysconfig.get_config_var
28
29if opt == '--help':
30 exit_with_usage(0)
31
32elif opt == '--prefix':
Georg Brandl7046e972007-09-01 07:27:37 +000033 print(sysconfig.PREFIX)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000034
35elif opt == '--exec-prefix':
Georg Brandl7046e972007-09-01 07:27:37 +000036 print(sysconfig.EXEC_PREFIX)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000037
38elif opt in ('--includes', '--cflags'):
Thomas Wouters0e3f5912006-08-11 14:57:12 +000039 flags = ['-I' + sysconfig.get_python_inc(),
40 '-I' + sysconfig.get_python_inc(plat_specific=True)]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000041 if opt == '--cflags':
42 flags.extend(getvar('CFLAGS').split())
Georg Brandl7046e972007-09-01 07:27:37 +000043 print(' '.join(flags))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000044
45elif opt in ('--libs', '--ldflags'):
Thomas Wouters0e3f5912006-08-11 14:57:12 +000046 libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000047 libs.append('-lpython'+pyver)
Guido van Rossumd8faa362007-04-27 19:54:29 +000048 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
49 # shared library in prefix/lib/.
50 if opt == '--ldflags' and not getvar('Py_ENABLE_SHARED'):
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000051 libs.insert(0, '-L' + getvar('LIBPL'))
Georg Brandl7046e972007-09-01 07:27:37 +000052 print(' '.join(libs))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000053