Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1 | #!@EXENAME@ |
Barry Warsaw | f040d7d | 2010-10-18 17:09:07 +0000 | [diff] [blame] | 2 | # -*- python -*- |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3 | |
doko@ubuntu.com | 0df35b0 | 2013-08-01 15:32:49 +0200 | [diff] [blame] | 4 | # Keep this script in sync with python-config.sh.in |
| 5 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 6 | import getopt |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 7 | import os |
| 8 | import sys |
| 9 | import sysconfig |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 10 | |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 11 | valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', |
Victor Stinner | 0a8e572 | 2019-05-23 03:30:23 +0200 | [diff] [blame] | 12 | 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir', |
| 13 | 'embed'] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 14 | |
| 15 | def exit_with_usage(code=1): |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 16 | print("Usage: {0} [{1}]".format( |
| 17 | sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 18 | sys.exit(code) |
| 19 | |
| 20 | try: |
| 21 | opts, args = getopt.getopt(sys.argv[1:], '', valid_opts) |
| 22 | except getopt.error: |
| 23 | exit_with_usage() |
| 24 | |
| 25 | if not opts: |
| 26 | exit_with_usage() |
| 27 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 28 | pyver = sysconfig.get_config_var('VERSION') |
| 29 | getvar = sysconfig.get_config_var |
| 30 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 31 | opt_flags = [flag for (flag, val) in opts] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 32 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 33 | if '--help' in opt_flags: |
| 34 | exit_with_usage(code=0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 35 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 36 | for opt in opt_flags: |
| 37 | if opt == '--prefix': |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 38 | print(sysconfig.get_config_var('prefix')) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 39 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 40 | elif opt == '--exec-prefix': |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 41 | print(sysconfig.get_config_var('exec_prefix')) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 42 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 43 | elif opt in ('--includes', '--cflags'): |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 44 | flags = ['-I' + sysconfig.get_path('include'), |
| 45 | '-I' + sysconfig.get_path('platinclude')] |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 46 | if opt == '--cflags': |
| 47 | flags.extend(getvar('CFLAGS').split()) |
| 48 | print(' '.join(flags)) |
| 49 | |
| 50 | elif opt in ('--libs', '--ldflags'): |
Victor Stinner | 0a8e572 | 2019-05-23 03:30:23 +0200 | [diff] [blame] | 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) |
xdegaye | 254b309 | 2019-04-29 09:27:40 +0200 | [diff] [blame] | 58 | libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split()) |
| 59 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 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')) |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 65 | print(' '.join(libs)) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 66 | |
Georg Brandl | b084b48 | 2010-09-12 17:14:26 +0000 | [diff] [blame] | 67 | elif opt == '--extension-suffix': |
doko@ubuntu.com | d5537d0 | 2013-03-21 13:21:49 -0700 | [diff] [blame] | 68 | print(sysconfig.get_config_var('EXT_SUFFIX')) |
Barry Warsaw | 8cf4eae | 2010-10-16 01:04:07 +0000 | [diff] [blame] | 69 | |
| 70 | elif opt == '--abiflags': |
| 71 | print(sys.abiflags) |
Barry Warsaw | 9eeea48 | 2012-07-26 18:12:07 -0400 | [diff] [blame] | 72 | |
| 73 | elif opt == '--configdir': |
| 74 | print(sysconfig.get_config_var('LIBPL')) |