Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 1 | #!@EXENAME@ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import getopt |
| 6 | from distutils import sysconfig |
| 7 | |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 8 | valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 9 | 'ldflags', 'help'] |
| 10 | |
| 11 | def exit_with_usage(code=1): |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 12 | print("Usage: {0} [{1}]".format( |
| 13 | 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] | 14 | sys.exit(code) |
| 15 | |
| 16 | try: |
| 17 | opts, args = getopt.getopt(sys.argv[1:], '', valid_opts) |
| 18 | except getopt.error: |
| 19 | exit_with_usage() |
| 20 | |
| 21 | if not opts: |
| 22 | exit_with_usage() |
| 23 | |
| 24 | opt = opts[0][0] |
| 25 | |
| 26 | pyver = sysconfig.get_config_var('VERSION') |
| 27 | getvar = sysconfig.get_config_var |
| 28 | |
| 29 | if opt == '--help': |
| 30 | exit_with_usage(0) |
| 31 | |
| 32 | elif opt == '--prefix': |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 33 | print(sysconfig.PREFIX) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 34 | |
| 35 | elif opt == '--exec-prefix': |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 36 | print(sysconfig.EXEC_PREFIX) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 37 | |
| 38 | elif opt in ('--includes', '--cflags'): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 39 | flags = ['-I' + sysconfig.get_python_inc(), |
| 40 | '-I' + sysconfig.get_python_inc(plat_specific=True)] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 41 | if opt == '--cflags': |
| 42 | flags.extend(getvar('CFLAGS').split()) |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 43 | print(' '.join(flags)) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 44 | |
| 45 | elif opt in ('--libs', '--ldflags'): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 46 | libs = getvar('LIBS').split() + getvar('SYSLIBS').split() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 47 | libs.append('-lpython'+pyver) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 48 | # 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 Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 51 | libs.insert(0, '-L' + getvar('LIBPL')) |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 52 | print(' '.join(libs)) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 53 | |