jpayne@68: #!/usr/bin/env python3.8 jpayne@68: # -*- python -*- jpayne@68: jpayne@68: # Keep this script in sync with python-config.sh.in jpayne@68: jpayne@68: import getopt jpayne@68: import os jpayne@68: import sys jpayne@68: import sysconfig jpayne@68: jpayne@68: valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', jpayne@68: 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir', jpayne@68: 'embed'] jpayne@68: jpayne@68: def exit_with_usage(code=1): jpayne@68: print("Usage: {0} [{1}]".format( jpayne@68: sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr) jpayne@68: sys.exit(code) jpayne@68: jpayne@68: try: jpayne@68: opts, args = getopt.getopt(sys.argv[1:], '', valid_opts) jpayne@68: except getopt.error: jpayne@68: exit_with_usage() jpayne@68: jpayne@68: if not opts: jpayne@68: exit_with_usage() jpayne@68: jpayne@68: pyver = sysconfig.get_config_var('VERSION') jpayne@68: getvar = sysconfig.get_config_var jpayne@68: jpayne@68: opt_flags = [flag for (flag, val) in opts] jpayne@68: jpayne@68: if '--help' in opt_flags: jpayne@68: exit_with_usage(code=0) jpayne@68: jpayne@68: for opt in opt_flags: jpayne@68: if opt == '--prefix': jpayne@68: print(sysconfig.get_config_var('prefix')) jpayne@68: jpayne@68: elif opt == '--exec-prefix': jpayne@68: print(sysconfig.get_config_var('exec_prefix')) jpayne@68: jpayne@68: elif opt in ('--includes', '--cflags'): jpayne@68: flags = ['-I' + sysconfig.get_path('include'), jpayne@68: '-I' + sysconfig.get_path('platinclude')] jpayne@68: if opt == '--cflags': jpayne@68: flags.extend(getvar('CFLAGS').split()) jpayne@68: print(' '.join(flags)) jpayne@68: jpayne@68: elif opt in ('--libs', '--ldflags'): jpayne@68: libs = [] jpayne@68: if '--embed' in opt_flags: jpayne@68: libs.append('-lpython' + pyver + sys.abiflags) jpayne@68: else: jpayne@68: libpython = getvar('LIBPYTHON') jpayne@68: if libpython: jpayne@68: libs.append(libpython) jpayne@68: libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split()) jpayne@68: jpayne@68: # add the prefix/lib/pythonX.Y/config dir, but only if there is no jpayne@68: # shared library in prefix/lib/. jpayne@68: if opt == '--ldflags': jpayne@68: if not getvar('Py_ENABLE_SHARED'): jpayne@68: libs.insert(0, '-L' + getvar('LIBPL')) jpayne@68: print(' '.join(libs)) jpayne@68: jpayne@68: elif opt == '--extension-suffix': jpayne@68: print(sysconfig.get_config_var('EXT_SUFFIX')) jpayne@68: jpayne@68: elif opt == '--abiflags': jpayne@68: print(sys.abiflags) jpayne@68: jpayne@68: elif opt == '--configdir': jpayne@68: print(sysconfig.get_config_var('LIBPL'))