churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

Blame 00289-fix-nis-compilation.patch

6ff303e
diff --git a/setup.py b/setup.py
6ff303e
index 3eb6ad1..3437e48 100644
6ff303e
--- a/setup.py
6ff303e
+++ b/setup.py
6ff303e
@@ -1331,20 +1331,14 @@ class PyBuildExt(build_ext):
6ff303e
             exts.append( Extension('termios', ['termios.c']) )
6ff303e
             # Jeremy Hylton's rlimit interface
6ff303e
             exts.append( Extension('resource', ['resource.c']) )
6ff303e
+        else:
6ff303e
+            missing.extend(['resource', 'termios'])
6ff303e
 
6ff303e
-            # Sun yellow pages. Some systems have the functions in libc.
6ff303e
-            if (host_platform not in ['cygwin', 'qnx6'] and
6ff303e
-                find_file('rpcsvc/yp_prot.h', inc_dirs, []) is not None):
6ff303e
-                if (self.compiler.find_library_file(lib_dirs, 'nsl')):
6ff303e
-                    libs = ['nsl']
6ff303e
-                else:
6ff303e
-                    libs = []
6ff303e
-                exts.append( Extension('nis', ['nismodule.c'],
6ff303e
-                                       libraries = libs) )
6ff303e
-            else:
6ff303e
-                missing.append('nis')
6ff303e
+        nis = self._detect_nis(inc_dirs, lib_dirs)
6ff303e
+        if nis is not None:
6ff303e
+            exts.append(nis)
6ff303e
         else:
6ff303e
-            missing.extend(['nis', 'resource', 'termios'])
6ff303e
+            missing.append('nis')
6ff303e
 
6ff303e
         # Curses support, requiring the System V version of curses, often
6ff303e
         # provided by the ncurses library.
6ff303e
@@ -2179,6 +2173,51 @@ class PyBuildExt(build_ext):
6ff303e
         )
6ff303e
         return ext
6ff303e
 
6ff303e
+    def _detect_nis(self, inc_dirs, lib_dirs):
6ff303e
+        if host_platform in {'win32', 'cygwin', 'qnx6'}:
6ff303e
+            return None
6ff303e
+
6ff303e
+        libs = []
6ff303e
+        library_dirs = []
6ff303e
+        includes_dirs = []
6ff303e
+
6ff303e
+        # Latest glibc has moved Sun RPC headers into tircp and nsl sub
6ff303e
+        # directories. rpc code has been moved to libtirpc.
6ff303e
+        rpcsvc_inc = find_file(
6ff303e
+            'rpcsvc/yp_prot.h', inc_dirs,
6ff303e
+            ['/usr/local/include/nsl', '/usr/include/nsl']
6ff303e
+        )
6ff303e
+        rpc_inc = find_file(
6ff303e
+            'rpc/rpc.h', inc_dirs,
6ff303e
+            ['/usr/local/include/tirpc', '/usr/include/tirpc']
6ff303e
+        )
6ff303e
+        if rpcsvc_inc is None or rpc_inc is None:
6ff303e
+            # not found
6ff303e
+            return None
6ff303e
+        includes_dirs.extend(rpcsvc_inc)
6ff303e
+        includes_dirs.extend(rpc_inc)
6ff303e
+
6ff303e
+        if self.compiler.find_library_file(lib_dirs, 'nsl'):
6ff303e
+            libs.append('nsl')
6ff303e
+        else:
6ff303e
+            # libnsl-devel: check for libnsl in nsl/ subdirectory
6ff303e
+            nsl_dirs = [os.path.join(lib_dir, 'nsl') for lib_dir in lib_dirs]
6ff303e
+            libnsl = self.compiler.find_library_file(nsl_dirs, 'nsl')
6ff303e
+            if libnsl is not None:
6ff303e
+                library_dirs.append(os.path.dirname(libnsl))
6ff303e
+                libs.append('nsl')
6ff303e
+
6ff303e
+        if self.compiler.find_library_file(lib_dirs, 'tirpc'):
6ff303e
+            libs.append('tirpc')
6ff303e
+
6ff303e
+        return Extension(
6ff303e
+            'nis', ['nismodule.c'],
6ff303e
+            libraries=libs,
6ff303e
+            library_dirs=library_dirs,
6ff303e
+            include_dirs=includes_dirs
6ff303e
+        )
6ff303e
+
6ff303e
+
6ff303e
 class PyBuildInstall(install):
6ff303e
     # Suppress the warning about installation into the lib_dynload
6ff303e
     # directory, which is not in sys.path when running Python during