PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/python-config.py

http://scim-python.googlecode.com/
Python | 53 lines | 48 code | 4 blank | 1 comment | 2 complexity | 19734968b701cdcfd916ae28ccb5989a MD5 | raw file
  1. #!/usr/bin/python2.5
  2. import sys
  3. import os
  4. import getopt
  5. from distutils import sysconfig
  6. valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
  7. 'ldflags', 'help']
  8. def exit_with_usage(code=1):
  9. print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
  10. '|'.join('--'+opt for opt in valid_opts))
  11. sys.exit(code)
  12. try:
  13. opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
  14. except getopt.error:
  15. exit_with_usage()
  16. if not opts:
  17. exit_with_usage()
  18. opt = opts[0][0]
  19. pyver = sysconfig.get_config_var('VERSION')
  20. getvar = sysconfig.get_config_var
  21. if opt == '--help':
  22. exit_with_usage(0)
  23. elif opt == '--prefix':
  24. print sysconfig.PREFIX
  25. elif opt == '--exec-prefix':
  26. print sysconfig.EXEC_PREFIX
  27. elif opt in ('--includes', '--cflags'):
  28. flags = ['-I' + sysconfig.get_python_inc(),
  29. '-I' + sysconfig.get_python_inc(plat_specific=True)]
  30. if opt == '--cflags':
  31. flags.extend(getvar('CFLAGS').split())
  32. print ' '.join(flags)
  33. elif opt in ('--libs', '--ldflags'):
  34. libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
  35. libs.append('-lpython'+pyver)
  36. # add the prefix/lib/pythonX.Y/config dir, but only if there is no
  37. # shared library in prefix/lib/.
  38. if opt == '--ldflags' and not getvar('Py_ENABLE_SHARED'):
  39. libs.insert(0, '-L' + getvar('LIBPL'))
  40. print ' '.join(libs)