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