Upstream: https://opensource.apple.com/source/man/man-16/patches/PR11291804-xcode.diff

The header file "xcselect.h" referenced in the original patch is not available
in the OS X SDK. The local modification in this patch provide the necessary
declarations as implied by the context and put them right into this file.
--- src/manpath.c.orig	2005-08-20 16:26:06.000000000 -0700
+++ src/manpath.c	2012-10-17 13:05:56.000000000 -0700
@@ -26,6 +26,15 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef __APPLE__
+#include <stdbool.h>
+//#include <xcselect.h>
+typedef struct xcselect_manpaths xcselect_manpaths;
+xcselect_manpaths *xcselect_get_manpaths(char *sdkname);
+unsigned int xcselect_manpaths_get_num_paths(xcselect_manpaths *xcp);
+const char *xcselect_manpaths_get_path(xcselect_manpaths *xcp, unsigned i);
+void xcselect_manpaths_free(xcselect_manpaths *xcp);
+#endif /* __APPLE__ */
 
 /* not always in <string.h> */
 extern char *index(const char *, int);
@@ -372,6 +381,25 @@
      for (dlp = cfdirlist.nxt; dlp; dlp = dlp->nxt)
 	  if (dlp->mandatory)
 	       add_to_mandirlist (dlp->mandir, perrs);
+
+#ifdef __APPLE__
+	xcselect_manpaths *xcp;
+	const char *path;
+	unsigned i, count;
+
+	// TODO: pass something for sdkname
+	xcp = xcselect_get_manpaths(NULL);
+	if (xcp != NULL) {
+		count = xcselect_manpaths_get_num_paths(xcp);
+		for (i = 0; i < count; i++) {
+			path = xcselect_manpaths_get_path(xcp, i);
+			if (path != NULL) {
+				add_to_mandirlist((char *)path, perrs);
+			}
+		}
+		xcselect_manpaths_free(xcp);
+	}
+#endif /* __APPLE__ */
 }
 
 static void