blob: 1d4a81d8502dfc36f7db15eab6a7220381e1853a [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
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004import getopt
Collin Winter67091772010-04-06 21:30:42 +00005import os
6import sys
7import sysconfig
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00008
Georg Brandl7046e972007-09-01 07:27:37 +00009valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
Barry Warsaw8cf4eae2010-10-16 01:04:07 +000010 'ldflags', 'extension-suffix', 'help', 'abiflags']
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000011
12def exit_with_usage(code=1):
Georg Brandl7046e972007-09-01 07:27:37 +000013 print("Usage: {0} [{1}]".format(
14 sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000015 sys.exit(code)
16
17try:
18 opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
19except getopt.error:
20 exit_with_usage()
21
22if not opts:
23 exit_with_usage()
24
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000025pyver = sysconfig.get_config_var('VERSION')
26getvar = sysconfig.get_config_var
27
Collin Winterbf199072010-03-19 21:17:17 +000028opt_flags = [flag for (flag, val) in opts]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000029
Collin Winterbf199072010-03-19 21:17:17 +000030if '--help' in opt_flags:
31 exit_with_usage(code=0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000032
Collin Winterbf199072010-03-19 21:17:17 +000033for opt in opt_flags:
34 if opt == '--prefix':
Collin Winter67091772010-04-06 21:30:42 +000035 print(sysconfig.get_config_var('prefix'))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000036
Collin Winterbf199072010-03-19 21:17:17 +000037 elif opt == '--exec-prefix':
Collin Winter67091772010-04-06 21:30:42 +000038 print(sysconfig.get_config_var('exec_prefix'))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000039
Collin Winterbf199072010-03-19 21:17:17 +000040 elif opt in ('--includes', '--cflags'):
Collin Winter67091772010-04-06 21:30:42 +000041 flags = ['-I' + sysconfig.get_path('include'),
42 '-I' + sysconfig.get_path('platinclude')]
Collin Winterbf199072010-03-19 21:17:17 +000043 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()
Barry Warsawf040d7d2010-10-18 17:09:07 +000049 libs.append('-lpython' + pyver + sys.abiflags)
Collin Winterbf199072010-03-19 21:17:17 +000050 # 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))
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000057
Georg Brandlb084b482010-09-12 17:14:26 +000058 elif opt == '--extension-suffix':
Georg Brandlb2f98402010-09-12 20:58:19 +000059 print(sysconfig.get_config_var('SO'))
Barry Warsaw8cf4eae2010-10-16 01:04:07 +000060
61 elif opt == '--abiflags':
62 print(sys.abiflags)