def parse_config_h(fp, g=None): """Parse a config.h-style file. A dictionary containing name/value pairs is returned. If an optional dictionary is passed in as the second argument, it is used instead of a new dictionary. """ return sysconfig.parse_config_h(fp, vars=g)
def init_inc_lib_dirs(self): if (not CROSS_COMPILING and os.path.normpath(sys.base_prefix) != '/usr' and not sysconfig.get_config_var('PYTHONFRAMEWORK')): # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework # (PYTHONFRAMEWORK is set) to avoid # linking problems when # building a framework with different architectures than # the one that is currently installed (issue #7473) add_dir_to_list(self.compiler.library_dirs, sysconfig.get_config_var("LIBDIR")) add_dir_to_list(self.compiler.include_dirs, sysconfig.get_config_var("INCLUDEDIR")) system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib'] system_include_dirs = ['/usr/include'] # lib_dirs and inc_dirs are used to search for files; # if a file is found in one of those directories, it can # be assumed that no additional -I,-L directives are needed. if not CROSS_COMPILING: self.lib_dirs = self.compiler.library_dirs + system_lib_dirs self.inc_dirs = self.compiler.include_dirs + system_include_dirs else: # Add the sysroot paths. 'sysroot' is a compiler option used to # set the logical path of the standard system headers and # libraries. self.lib_dirs = (self.compiler.library_dirs + sysroot_paths( ('LDFLAGS', 'CC'), system_lib_dirs)) self.inc_dirs = (self.compiler.include_dirs + sysroot_paths( ('CPPFLAGS', 'CFLAGS', 'CC'), system_include_dirs)) config_h = sysconfig.get_config_h_filename() with open(config_h) as file: self.config_h_vars = sysconfig.parse_config_h(file) # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']: self.lib_dirs += ['/usr/ccs/lib'] # HP-UX11iv3 keeps files in lib/hpux folders. if HOST_PLATFORM == 'hp-ux11': self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] if MACOS: # This should work on any unixy platform ;-) # If the user has bothered specifying additional -I and -L flags # in OPT and LDFLAGS we might as well use them here. # # NOTE: using shlex.split would technically be more correct, but # also gives a bootstrap problem. Let's hope nobody uses # directories with whitespace in the name to store libraries. cflags, ldflags = sysconfig.get_config_vars('CFLAGS', 'LDFLAGS') for item in cflags.split(): if item.startswith('-I'): self.inc_dirs.append(item[2:]) for item in ldflags.split(): if item.startswith('-L'): self.lib_dirs.append(item[2:])
def update_event(self, inp=-1): self.set_output_val( 0, sysconfig.parse_config_h(self.input(0), self.input(1)))
import sysconfig print('From sysconfig:') for k in 'Py_DEBUG', 'WITH_PYMALLOC', 'Py_UNICODE_SIZE': try: print(k + ': ' + repr(sysconfig.get_config_var(k))) except: print('Error getting %s' % k) print('From headers:') h_file = sysconfig.get_config_h_filename() conf_vars = sysconfig.parse_config_h(open(h_file)) for k in 'Py_DEBUG', 'WITH_PYMALLOC', 'Py_UNICODE_SIZE': try: print(k + ': ' + repr(conf_vars[k])) except: print('Error getting %s' % k)
def detect_modules(self): # On Debian /usr/local is always used, so we don't include it twice # only change this for cross builds for 3.3, issues on Mageia if cross_compiling: self.add_gcc_paths() self.add_multiarch_paths() # Add paths specified in the environment variables LDFLAGS and # CPPFLAGS for header and library files. # We must get the values from the Makefile and not the environment # directly since an inconsistently reproducible issue comes up where # the environment variable is not set even though the value were passed # into configure and stored in the Makefile (issue found on OS X 10.3). for env_var, arg_name, dir_list in ( ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), ('LDFLAGS', '-L', self.compiler.library_dirs), ('CPPFLAGS', '-I', self.compiler.include_dirs)): env_val = sysconfig.get_config_var(env_var) if env_val: # To prevent optparse from raising an exception about any # options in env_val that it doesn't know about we strip out # all double dashes and any dashes followed by a character # that is not for the option we are dealing with. # # Please note that order of the regex is important! We must # strip out double-dashes first so that we don't end up with # substituting "--Long" to "-Long" and thus lead to "ong" being # used for a library directory. env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], ' ', env_val) parser = optparse.OptionParser() # Make sure that allowing args interspersed with options is # allowed parser.allow_interspersed_args = True parser.error = lambda msg: None parser.add_option(arg_name, dest="dirs", action="append") options = parser.parse_args(env_val.split())[0] if options.dirs: for directory in reversed(options.dirs): add_dir_to_list(dir_list, directory) if os.path.normpath(sys.base_prefix) != '/usr' \ and not sysconfig.get_config_var('PYTHONFRAMEWORK'): # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework # (PYTHONFRAMEWORK is set) to avoid # linking problems when # building a framework with different architectures than # the one that is currently installed (issue #7473) add_dir_to_list(self.compiler.library_dirs, sysconfig.get_config_var("LIBDIR")) add_dir_to_list(self.compiler.include_dirs, sysconfig.get_config_var("INCLUDEDIR")) # lib_dirs and inc_dirs are used to search for files; # if a file is found in one of those directories, it can # be assumed that no additional -I,-L directives are needed. if not cross_compiling: lib_dirs = self.compiler.library_dirs + [ '/lib64', '/usr/lib64', '/lib', '/usr/lib', ] inc_dirs = self.compiler.include_dirs + ['/usr/include'] else: lib_dirs = self.compiler.library_dirs[:] inc_dirs = self.compiler.include_dirs[:] exts = [] missing = [] config_h = sysconfig.get_config_h_filename() with open(config_h) as file: config_h_vars = sysconfig.parse_config_h(file) srcdir = sysconfig.get_config_var('srcdir') # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) if host_platform in ['osf1', 'unixware7', 'openunix8']: lib_dirs += ['/usr/ccs/lib'] # HP-UX11iv3 keeps files in lib/hpux folders. if host_platform == 'hp-ux11': lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32'] if host_platform == 'darwin': # This should work on any unixy platform ;-) # If the user has bothered specifying additional -I and -L flags # in OPT and LDFLAGS we might as well use them here. # # NOTE: using shlex.split would technically be more correct, but # also gives a bootstrap problem. Let's hope nobody uses # directories with whitespace in the name to store libraries. cflags, ldflags = sysconfig.get_config_vars('CFLAGS', 'LDFLAGS') for item in cflags.split(): if item.startswith('-I'): inc_dirs.append(item[2:]) for item in ldflags.split(): if item.startswith('-L'): lib_dirs.append(item[2:]) # Check for MacOS X, which doesn't need libm.a at all math_libs = ['m'] if host_platform == 'darwin': math_libs = [] # XXX Omitted modules: gl, pure, dl, SGI-specific modules # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: if (True or 'gdbm' in dbm_order and self.compiler.find_library_file(lib_dirs, 'gdbm')): exts.append( Extension('_gdbm', ['Modules/_gdbmmodule.c'], libraries=['gdbm'])) else: missing.append('_gdbm') self.extensions.extend(exts) # Call the method for detecting whether _tkinter can be compiled self.detect_tkinter(inc_dirs, lib_dirs) if '_tkinter' not in [e.name for e in self.extensions]: missing.append('_tkinter') return missing
def detect_modules(self): # Ensure that /usr/local is always used # On Debian /usr/local is always used, so we don't include it twice #add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') #add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') # Add paths specified in the environment variables LDFLAGS and # CPPFLAGS for header and library files. # We must get the values from the Makefile and not the environment # directly since an inconsistently reproducible issue comes up where # the environment variable is not set even though the value were passed # into configure and stored in the Makefile (issue found on OS X 10.3). for env_var, arg_name, dir_list in ( ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), ('LDFLAGS', '-L', self.compiler.library_dirs), ('CPPFLAGS', '-I', self.compiler.include_dirs)): env_val = sysconfig.get_config_var(env_var) if env_val: # To prevent optparse from raising an exception about any # options in env_val that it doesn't know about we strip out # all double dashes and any dashes followed by a character # that is not for the option we are dealing with. # # Please note that order of the regex is important! We must # strip out double-dashes first so that we don't end up with # substituting "--Long" to "-Long" and thus lead to "ong" being # used for a library directory. env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], ' ', env_val) parser = optparse.OptionParser() # Make sure that allowing args interspersed with options is # allowed parser.allow_interspersed_args = True parser.error = lambda msg: None parser.add_option(arg_name, dest="dirs", action="append") options = parser.parse_args(env_val.split())[0] if options.dirs: for directory in reversed(options.dirs): add_dir_to_list(dir_list, directory) if os.path.normpath(sys.prefix) != '/usr': add_dir_to_list(self.compiler.library_dirs, sysconfig.get_config_var("LIBDIR")) add_dir_to_list(self.compiler.include_dirs, sysconfig.get_config_var("INCLUDEDIR")) try: have_unicode = unicode except NameError: have_unicode = 0 # lib_dirs and inc_dirs are used to search for files; # if a file is found in one of those directories, it can # be assumed that no additional -I,-L directives are needed. gnu_triplet = os.popen( 'dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null || dpkg-architecture -qDEB_HOST_GNU_TYPE' ).readline()[:-1] lib_dirs = self.compiler.library_dirs + [ os.path.join('/lib', gnu_triplet), os.path.join('/usr/lib', gnu_triplet), '/lib', '/usr/lib', ] inc_dirs = self.compiler.include_dirs + ['/usr/include'] inc_dirs.append(os.path.join('/usr/include', gnu_triplet)) exts = [] missing = [] config_h = sysconfig.get_config_h_filename() config_h_vars = sysconfig.parse_config_h(open(config_h)) platform = self.get_platform() srcdir = sysconfig.get_config_var('srcdir') # Check for AtheOS which has libraries in non-standard locations if platform == 'atheos': lib_dirs += ['/system/libs', '/atheos/autolnk/lib'] lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep) inc_dirs += ['/system/include', '/atheos/autolnk/include'] inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep) # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb) if platform in ['osf1', 'unixware7', 'openunix8']: lib_dirs += ['/usr/ccs/lib'] if platform == 'darwin': # This should work on any unixy platform ;-) # If the user has bothered specifying additional -I and -L flags # in OPT and LDFLAGS we might as well use them here. # NOTE: using shlex.split would technically be more correct, but # also gives a bootstrap problem. Let's hope nobody uses directories # with whitespace in the name to store libraries. cflags, ldflags = sysconfig.get_config_vars('CFLAGS', 'LDFLAGS') for item in cflags.split(): if item.startswith('-I'): inc_dirs.append(item[2:]) for item in ldflags.split(): if item.startswith('-L'): lib_dirs.append(item[2:]) # Check for MacOS X, which doesn't need libm.a at all math_libs = ['m'] if platform in ['darwin', 'beos']: math_libs = [] # XXX Omitted modules: gl, pure, dl, SGI-specific modules # # The following modules are all pretty straightforward, and compile # on pretty much any POSIXish platform. # dbm_order = ['gdbm'] # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: if ('gdbm' in dbm_order and self.compiler.find_library_file(lib_dirs, 'gdbm')): exts.append( Extension('gdbm', ['Modules/gdbmmodule.c'], libraries=['gdbm'])) else: missing.append('gdbm') self.extensions.extend(exts) # Call the method for detecting whether _tkinter can be compiled self.detect_tkinter(inc_dirs, lib_dirs) if '_tkinter' not in [e.name for e in self.extensions]: missing.append('_tkinter') return missing