blob: 70f3f3c06e8f4cfaf8c519eed7ec931ab993a0f6 [file] [log] [blame]
Mike Frysinger682d0652012-07-30 11:38:25 -04001Change setup.py to respect the SYSROOT environment variable
2
3--- a/setup.py
4+++ b/setup.py
5@@ -337,9 +337,13 @@
6
7 def detect_modules(self):
8 global disable_ssl
9+
10+ # We must respect the user specified sysroot!
11+ sysroot = os.getenv('SYSROOT', '')
12+
13 # Ensure that /usr/local is always used
14- add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
15- add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
16+ add_dir_to_list(self.compiler.library_dirs, sysroot + '/usr/local/lib')
17+ add_dir_to_list(self.compiler.include_dirs, sysroot + '/usr/local/include')
18
19 # Add paths specified in the environment variables LDFLAGS and
20 # CPPFLAGS for header and library files.
21@@ -375,12 +381,18 @@
22 for directory in reversed(options.dirs):
23 add_dir_to_list(dir_list, directory)
24
25- if os.path.normpath(sys.prefix) != '/usr':
26+ if os.path.normpath(sys.prefix) != '/usr/local':
27 add_dir_to_list(self.compiler.library_dirs,
28 sysconfig.get_config_var("LIBDIR"))
29 add_dir_to_list(self.compiler.include_dirs,
30 sysconfig.get_config_var("INCLUDEDIR"))
31
32+ # We should always look into sysroot/usr/include and consider
33+ # also the lib dirs there for searching for files
34+ add_dir_to_list(self.compiler.include_dirs, sysroot + '/usr/include')
35+ add_dir_to_list(self.compiler.library_dirs, sysroot + '/@@GENTOO_LIBDIR@@')
36+ add_dir_to_list(self.compiler.library_dirs, sysroot + '/usr/@@GENTOO_LIBDIR@@')
37+
38 try:
39 have_unicode = unicode
40 except NameError:
41@@ -389,6 +403,9 @@
42 '/lib', '/usr/lib',
43 ]
44 inc_dirs = self.compiler.include_dirs + ['/usr/include']
45+ # Ignore previous settings.
46+ lib_dirs = self.compiler.library_dirs
47+ inc_dirs = self.compiler.include_dirs
48 exts = []
49 missing = []
50
51@@ -613,11 +624,11 @@
52 elif self.compiler.find_library_file(lib_dirs, 'curses'):
53 readline_libs.append('curses')
54 elif self.compiler.find_library_file(lib_dirs +
55- ['/usr/@@GENTOO_LIBDIR@@/termcap'],
56+ [sysroot + '/usr/@@GENTOO_LIBDIR@@/termcap'],
57 'termcap'):
58 readline_libs.append('termcap')
59 exts.append( Extension('readline', ['readline.c'],
60- library_dirs=['/usr/@@GENTOO_LIBDIR@@/termcap'],
61+ library_dirs=[sysroot + '/usr/@@GENTOO_LIBDIR@@/termcap'],
62 extra_link_args=readline_extra_link_args,
63 libraries=readline_libs) )
64 else:
65@@ -642,20 +653,20 @@
66 depends = ['socketmodule.h']) )
67 # Detect SSL support for the socket module (via _ssl)
68 search_for_ssl_incs_in = [
69- '/usr/local/ssl/include',
70- '/usr/contrib/ssl/include/'
71+ sysroot + '/usr/local/ssl/include',
72+ sysroot + '/usr/contrib/ssl/include/'
73 ]
74 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
75 search_for_ssl_incs_in
76 )
77 if ssl_incs is not None and not disable_ssl:
78 krb5_h = find_file('krb5.h', inc_dirs,
79- ['/usr/kerberos/include'])
80+ [sysroot + '/usr/kerberos/include'])
81 if krb5_h:
82 ssl_incs += krb5_h
83 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
84- ['/usr/local/ssl/lib',
85- '/usr/contrib/ssl/lib/'
86+ [sysroot + '/usr/local/ssl/lib',
87+ sysroot + '/usr/contrib/ssl/lib/'
88 ] )
89
90 if (ssl_incs is not None and
91@@ -773,6 +785,7 @@
92 db_inc_paths.append('/usr/local/include/db3%d' % x)
93 db_inc_paths.append('/pkg/db-3.%d/include' % x)
94 db_inc_paths.append('/opt/db-3.%d/include' % x)
95+ db_inc_paths = [sysroot + x for x in db_inc_paths]
96
97 # Add some common subdirectories for Sleepycat DB to the list,
98 # based on the standard include directories. This way DB3/4 gets
99@@ -921,5 +933,6 @@
100 '/usr/local/include/sqlite',
101 '/usr/local/include/sqlite3',
102 ]
103+ sqlite_inc_paths = [sysroot + x for x in sqlite_inc_paths]
104 MIN_SQLITE_VERSION_NUMBER = (3, 0, 8)
105 MIN_SQLITE_VERSION = ".".join([str(x)
106@@ -1021,7 +1033,7 @@
107 # we do not build this one. Otherwise this build will pick up
108 # the more recent berkeleydb's db.h file first in the include path
109 # when attempting to compile and it will fail.
110- f = "/usr/include/db.h"
111+ f = sysroot + "/usr/include/db.h"
112
113 if sys.platform == 'darwin':
114 if is_macosx_sdk_path(f):
115@@ -1236,7 +1248,7 @@
116 # More information on Expat can be found at www.libexpat.org.
117 #
118 # Use system expat
119- expatinc = '/usr/include'
120+ expatinc = sysroot + '/usr/include'
121 define_macros = []
122
123 exts.append(Extension('pyexpat',
124@@ -1546,7 +1558,7 @@
125 # For 8.4a2, the X11 headers are not included. Rather than include a
126 # complicated search, this is a hard-coded path. It could bail out
127 # if X11 libs are not found...
128- include_dirs.append('/usr/X11R6/include')
129+ include_dirs.append(sysroot + '/usr/X11R6/include')
130 frameworks = ['-framework', 'Tcl', '-framework', 'Tk']
131
132 # All existing framework builds of Tcl/Tk don't support 64-bit
133@@ -1579,6 +1591,9 @@
134 def detect_tkinter(self, inc_dirs, lib_dirs):
135 # The _tkinter module.
136
137+ # We must respect the user specified sysroot!
138+ sysroot = os.getenv('SYSROOT', '')
139+
140 # Rather than complicate the code below, detecting and building
141 # AquaTk is a separate method. Only one Tkinter will be built on
142 # Darwin - either AquaTk, if it is found, or X11 based Tk.
143@@ -1633,17 +1650,17 @@
144 if platform == 'sunos5':
145 include_dirs.append('/usr/openwin/include')
146 added_lib_dirs.append('/usr/openwin/lib')
147- elif os.path.exists('/usr/X11R6/include'):
148- include_dirs.append('/usr/X11R6/include')
149- added_lib_dirs.append('/usr/X11R6/lib64')
150- added_lib_dirs.append('/usr/X11R6/lib')
151- elif os.path.exists('/usr/X11R5/include'):
152- include_dirs.append('/usr/X11R5/include')
153- added_lib_dirs.append('/usr/X11R5/lib')
154+ elif os.path.exists(sysroot + '/usr/X11R6/include'):
155+ include_dirs.append(sysroot + '/usr/X11R6/include')
156+ added_lib_dirs.append(sysroot + '/usr/X11R6/lib64')
157+ added_lib_dirs.append(sysroot + '/usr/X11R6/lib')
158+ elif os.path.exists(sysroot + '/usr/X11R5/include'):
159+ include_dirs.append(sysroot + '/usr/X11R5/include')
160+ added_lib_dirs.append(sysroot + '/usr/X11R5/lib')
161 else:
162 # Assume default location for X11
163- include_dirs.append('/usr/X11/include')
164- added_lib_dirs.append('/usr/X11/lib')
165+ include_dirs.append(sysroot + '/usr/X11/include')
166+ added_lib_dirs.append(sysroot + '/usr/X11/lib')
167
168 # If Cygwin, then verify that X is installed before proceeding
169 if platform == 'cygwin':