Martin v. Löwis | c90b17e | 2006-04-15 08:13:05 +0000 | [diff] [blame] | 1 | #!@BINDIR@/python |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import getopt |
| 6 | from distutils import sysconfig |
| 7 | |
| 8 | valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', |
| 9 | 'ldflags', 'help'] |
| 10 | |
| 11 | def exit_with_usage(code=1): |
| 12 | print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0], |
| 13 | '|'.join('--'+opt for opt in valid_opts)) |
| 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': |
| 33 | print sysconfig.PREFIX |
| 34 | |
| 35 | elif opt == '--exec-prefix': |
| 36 | print sysconfig.EXEC_PREFIX |
| 37 | |
| 38 | elif opt in ('--includes', '--cflags'): |
| 39 | flags = ['-I'+dir for dir in getvar('INCLDIRSTOMAKE').split()] |
| 40 | if opt == '--cflags': |
| 41 | flags.extend(getvar('CFLAGS').split()) |
| 42 | print ' '.join(flags) |
| 43 | |
| 44 | elif opt in ('--libs', '--ldflags'): |
| 45 | libs = sysconfig.get_config_var('LIBS').split() |
| 46 | libs.append('-lpython'+pyver) |
| 47 | if opt == '--ldflags': |
| 48 | libs.insert(0, '-L' + getvar('LIBPL')) |
| 49 | print ' '.join(libs) |
| 50 | |