@@ -60,6 +60,31 @@ def add_dir_to_list(dirlist, dir):
60
60
return
61
61
dirlist .insert (0 , dir )
62
62
63
+ def sysroot_paths (make_vars , subdirs ):
64
+ """Get the paths of sysroot sub-directories.
65
+
66
+ * make_vars: a sequence of names of variables of the Makefile where
67
+ sysroot may be set.
68
+ * subdirs: a sequence of names of subdirectories used as the location for
69
+ headers or libraries.
70
+ """
71
+
72
+ dirs = []
73
+ for var_name in make_vars :
74
+ var = sysconfig .get_config_var (var_name )
75
+ if var is not None :
76
+ m = re .search (r'--sysroot=([^"]\S*|"[^"]+")' , var )
77
+ if m is not None :
78
+ sysroot = m .group (1 ).strip ('"' )
79
+ for subdir in subdirs :
80
+ if os .path .isabs (subdir ):
81
+ subdir = subdir [1 :]
82
+ path = os .path .join (sysroot , subdir )
83
+ if os .path .isdir (path ):
84
+ dirs .append (path )
85
+ break
86
+ return dirs
87
+
63
88
def macosx_sdk_root ():
64
89
"""
65
90
Return the directory of the current OSX SDK,
@@ -544,18 +569,23 @@ def detect_modules(self):
544
569
add_dir_to_list (self .compiler .include_dirs ,
545
570
sysconfig .get_config_var ("INCLUDEDIR" ))
546
571
572
+ system_lib_dirs = ['/lib64' , '/usr/lib64' , '/lib' , '/usr/lib' ]
573
+ system_include_dirs = ['/usr/include' ]
547
574
# lib_dirs and inc_dirs are used to search for files;
548
575
# if a file is found in one of those directories, it can
549
576
# be assumed that no additional -I,-L directives are needed.
550
577
if not cross_compiling :
551
- lib_dirs = self .compiler .library_dirs + [
552
- '/lib64' , '/usr/lib64' ,
553
- '/lib' , '/usr/lib' ,
554
- ]
555
- inc_dirs = self .compiler .include_dirs + ['/usr/include' ]
578
+ lib_dirs = self .compiler .library_dirs + system_lib_dirs
579
+ inc_dirs = self .compiler .include_dirs + system_include_dirs
556
580
else :
557
- lib_dirs = self .compiler .library_dirs [:]
558
- inc_dirs = self .compiler .include_dirs [:]
581
+ # Add the sysroot paths. 'sysroot' is a compiler option used to
582
+ # set the logical path of the standard system headers and
583
+ # libraries.
584
+ lib_dirs = (self .compiler .library_dirs +
585
+ sysroot_paths (('LDFLAGS' , 'CC' ), system_lib_dirs ))
586
+ inc_dirs = (self .compiler .include_dirs +
587
+ sysroot_paths (('CPPFLAGS' , 'CFLAGS' , 'CC' ),
588
+ system_include_dirs ))
559
589
exts = []
560
590
missing = []
561
591
0 commit comments