python-config.in 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!@EXENAME@
  2. import sys
  3. import os
  4. import getopt
  5. import re
  6. from distutils import sysconfig
  7. valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
  8. 'ldflags', 'help']
  9. def exit_with_usage(code=1):
  10. print >>sys.stderr, "Usage: %s [%s]" % (sys.argv[0],
  11. '|'.join('--'+opt for opt in valid_opts))
  12. sys.exit(code)
  13. try:
  14. opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
  15. except getopt.error:
  16. exit_with_usage()
  17. if not opts:
  18. exit_with_usage()
  19. pyver = sysconfig.get_config_var('VERSION')
  20. getvar = sysconfig.get_config_var
  21. opt_flags = [flag for (flag, val) in opts]
  22. if '--help' in opt_flags:
  23. exit_with_usage(code=0)
  24. for opt in opt_flags:
  25. if opt == '--prefix':
  26. print sysconfig.PREFIX
  27. elif opt == '--exec-prefix':
  28. print sysconfig.EXEC_PREFIX
  29. elif opt in ('--includes', '--cflags'):
  30. flags = ['-I' + re.sub('host_', 'target_', sysconfig.get_python_inc()),
  31. '-I' + re.sub('host_', 'target_', sysconfig.get_python_inc(plat_specific=True))]
  32. if opt == '--cflags':
  33. flags.extend(getvar('CFLAGS').split())
  34. print ' '.join(flags)
  35. elif opt in ('--libs', '--ldflags'):
  36. libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
  37. libs.append('-lpython'+pyver)
  38. # add the prefix/lib/pythonX.Y/config dir, but only if there is no
  39. # shared library in prefix/lib/.
  40. if opt == '--ldflags':
  41. if not getvar('Py_ENABLE_SHARED'):
  42. libs.insert(0, '-L' + getvar('LIBPL'))
  43. libs.extend(getvar('LINKFORSHARED').split())
  44. print ' '.join(libs)