You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.3 KiB

  1. #!/home/yigido/projects/Food_Cloud/venv/bin/python
  2. import sys
  3. import getopt
  4. import sysconfig
  5. valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags',
  6. 'ldflags', 'help']
  7. if sys.version_info >= (3, 2):
  8. valid_opts.insert(-1, 'extension-suffix')
  9. valid_opts.append('abiflags')
  10. if sys.version_info >= (3, 3):
  11. valid_opts.append('configdir')
  12. def exit_with_usage(code=1):
  13. sys.stderr.write("Usage: {0} [{1}]\n".format(
  14. sys.argv[0], '|'.join('--'+opt for opt in valid_opts)))
  15. sys.exit(code)
  16. try:
  17. opts, args = getopt.getopt(sys.argv[1:], '', valid_opts)
  18. except getopt.error:
  19. exit_with_usage()
  20. if not opts:
  21. exit_with_usage()
  22. pyver = sysconfig.get_config_var('VERSION')
  23. getvar = sysconfig.get_config_var
  24. opt_flags = [flag for (flag, val) in opts]
  25. if '--help' in opt_flags:
  26. exit_with_usage(code=0)
  27. for opt in opt_flags:
  28. if opt == '--prefix':
  29. print(sysconfig.get_config_var('prefix'))
  30. elif opt == '--exec-prefix':
  31. print(sysconfig.get_config_var('exec_prefix'))
  32. elif opt in ('--includes', '--cflags'):
  33. flags = ['-I' + sysconfig.get_path('include'),
  34. '-I' + sysconfig.get_path('platinclude')]
  35. if opt == '--cflags':
  36. flags.extend(getvar('CFLAGS').split())
  37. print(' '.join(flags))
  38. elif opt in ('--libs', '--ldflags'):
  39. abiflags = getattr(sys, 'abiflags', '')
  40. libs = ['-lpython' + pyver + abiflags]
  41. libs += getvar('LIBS').split()
  42. libs += getvar('SYSLIBS').split()
  43. # add the prefix/lib/pythonX.Y/config dir, but only if there is no
  44. # shared library in prefix/lib/.
  45. if opt == '--ldflags':
  46. if not getvar('Py_ENABLE_SHARED'):
  47. libs.insert(0, '-L' + getvar('LIBPL'))
  48. if not getvar('PYTHONFRAMEWORK'):
  49. libs.extend(getvar('LINKFORSHARED').split())
  50. print(' '.join(libs))
  51. elif opt == '--extension-suffix':
  52. ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
  53. if ext_suffix is None:
  54. ext_suffix = sysconfig.get_config_var('SO')
  55. print(ext_suffix)
  56. elif opt == '--abiflags':
  57. if not getattr(sys, 'abiflags', None):
  58. exit_with_usage()
  59. print(sys.abiflags)
  60. elif opt == '--configdir':
  61. print(sysconfig.get_config_var('LIBPL'))