1diff -ur misc/Python-2.7.18/setup.py misc/build/Python-2.7.18/setup.py
2--- misc/Python-2.7.18/setup.py	2016-06-25 16:49:32.000000000 -0500
3+++ misc/build/Python-2.7.18/setup.py	2016-09-02 17:09:20.687419000 -0500
4@@ -126,39 +126,41 @@
5         # system, but with only header files and libraries.
6         sysroot = macosx_sdk_root()
7
8-    # Check the standard locations
9-    for dir in std_dirs:
10+    # Check the standard directories
11+    for dir in paths:
12         f = os.path.join(dir, filename)
13
14         if host_platform == 'darwin' and is_macosx_sdk_path(dir):
15             f = os.path.join(sysroot, dir[1:], filename)
16
17-        if os.path.exists(f): return []
18+        if os.path.exists(f):
19+	    return [dir]
20
21-    # Check the additional directories
22-    for dir in paths:
23+    # Check the standard locations
24+    for dir in std_dirs:
25         f = os.path.join(dir, filename)
26
27         if host_platform == 'darwin' and is_macosx_sdk_path(dir):
28             f = os.path.join(sysroot, dir[1:], filename)
29
30         if os.path.exists(f):
31-            return [dir]
32+            return []
33
34     # Not found anywhere
35     return None
36
37 def find_library_file(compiler, libname, std_dirs, paths):
38-    result = compiler.find_library_file(std_dirs + paths, libname)
39+    result = compiler.find_library_file(paths+std_dirs, libname)
40     if result is None:
41         return None
42
43     if host_platform == 'darwin':
44         sysroot = macosx_sdk_root()
45
46-    # Check whether the found file is in one of the standard directories
47     dirname = os.path.dirname(result)
48-    for p in std_dirs:
49+    # Otherwise, it must have been in one of the additional directories,
50+    # so we have to figure out which one.
51+    for p in paths:
52         # Ensure path doesn't end with path separator
53         p = p.rstrip(os.sep)
54
55@@ -180,23 +180,22 @@
56             # vs
57             #   /usr/lib/libedit.dylib
58             if os.path.join(sysroot, p[1:]) == dirname:
59-                return [ ]
60+                return [ p ]
61
62         if p == dirname:
63-            return [ ]
64+            return [ p ]
65
66-    # Otherwise, it must have been in one of the additional directories,
67-    # so we have to figure out which one.
68-    for p in paths:
69+    # Check whether the found file is in one of the standard directories
70+    for p in std_dirs:
71         # Ensure path doesn't end with path separator
72         p = p.rstrip(os.sep)
73
74         if host_platform == 'darwin' and is_macosx_sdk_path(p):
75             if os.path.join(sysroot, p[1:]) == dirname:
76-                return [ p ]
77+                return [ ]
78
79         if p == dirname:
80-            return [p]
81+            return [ ]
82     else:
83         assert False, "Internal error: Path not found in std_dirs or paths"
84
85@@ -891,6 +892,7 @@
86             exts.append( Extension('_ssl', ['_ssl.c'],
87                                    include_dirs = ssl_incs,
88                                    library_dirs = ssl_libs,
89+                                   extra_link_args = ['-Wl,--exclude-libs,ALL'],
90                                    libraries = ['ssl', 'crypto'],
91                                    depends = ['socketmodule.h']), )
92         else:
93@@ -930,6 +931,7 @@
94                 exts.append( Extension('_hashlib', ['_hashopenssl.c'],
95                                        include_dirs = ssl_incs,
96                                        library_dirs = ssl_libs,
97+                                       extra_link_args = ['-Wl,--exclude-libs,ALL'],
98                                        libraries = ['ssl', 'crypto']) )
99             else:
100                 print ("warning: openssl 0x%08x is too old for _hashlib" %
101