python-config.py 2.2 KB

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