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 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4 | import getopt |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 5 | import os |
| 6 | import sys |
| 7 | import sysconfig |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 8 | |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 9 | valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', |
Barry Warsaw | 8cf4eae | 2010-10-16 01:04:07 +0000 | [diff] [blame] | 10 | 'ldflags', 'extension-suffix', 'help', 'abiflags'] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 11 | |
| 12 | def exit_with_usage(code=1): |
Georg Brandl | 7046e97 | 2007-09-01 07:27:37 +0000 | [diff] [blame] | 13 | print("Usage: {0} [{1}]".format( |
| 14 | 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] | 15 | sys.exit(code) |
| 16 | |
| 17 | try: |
| 18 | opts, args = getopt.getopt(sys.argv[1:], '', valid_opts) |
| 19 | except getopt.error: |
| 20 | exit_with_usage() |
| 21 | |
| 22 | if not opts: |
| 23 | exit_with_usage() |
| 24 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 25 | pyver = sysconfig.get_config_var('VERSION') |
| 26 | getvar = sysconfig.get_config_var |
| 27 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 28 | opt_flags = [flag for (flag, val) in opts] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 29 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 30 | if '--help' in opt_flags: |
| 31 | exit_with_usage(code=0) |
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 | for opt in opt_flags: |
| 34 | if opt == '--prefix': |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 35 | print(sysconfig.get_config_var('prefix')) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 36 | |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 37 | elif opt == '--exec-prefix': |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 38 | print(sysconfig.get_config_var('exec_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 in ('--includes', '--cflags'): |
Collin Winter | 6709177 | 2010-04-06 21:30:42 +0000 | [diff] [blame] | 41 | flags = ['-I' + sysconfig.get_path('include'), |
| 42 | '-I' + sysconfig.get_path('platinclude')] |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 43 | 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 Warsaw | f040d7d | 2010-10-18 17:09:07 +0000 | [diff] [blame] | 49 | libs.append('-lpython' + pyver + sys.abiflags) |
Collin Winter | bf19907 | 2010-03-19 21:17:17 +0000 | [diff] [blame] | 50 | # 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 Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 57 | |
Georg Brandl | b084b48 | 2010-09-12 17:14:26 +0000 | [diff] [blame] | 58 | elif opt == '--extension-suffix': |
Georg Brandl | b2f9840 | 2010-09-12 20:58:19 +0000 | [diff] [blame] | 59 | print(sysconfig.get_config_var('SO')) |
Barry Warsaw | 8cf4eae | 2010-10-16 01:04:07 +0000 | [diff] [blame] | 60 | |
| 61 | elif opt == '--abiflags': |
| 62 | print(sys.abiflags) |