only build the nis module when the headers are found #7589
diff --git a/Misc/NEWS b/Misc/NEWS
index 46c8765..cbf28a4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@
 Build
 -----
 
+- Issue #7589: Only build the nis module when the correct header files are
+  found.
+
 - Switch to OpenSSL 0.9.8l on Windows.
 
 - Issue #7541: when using ``python-config`` with a framework install the compiler might
diff --git a/setup.py b/setup.py
index f25b829..d2334e7 100644
--- a/setup.py
+++ b/setup.py
@@ -1088,7 +1088,7 @@
                 missing.append('resource')
 
             # Sun yellow pages. Some systems have the functions in libc.
-            if platform not in ['cygwin', 'atheos', 'qnx6']:
+            if platform not in ['cygwin', 'atheos', 'qnx6'] and find_file('rpcsvc/yp_prot.h', inc_dirs, []) is not None:
                 if (self.compiler_obj.find_library_file(lib_dirs, 'nsl')):
                     libs = ['nsl']
                 else: