diff -Naur ../vnc_unixsrc/Xvnc/config/cf/vnclibs.def Xvnc/config/cf/vnclibs.def
--- ../vnc_unixsrc/Xvnc/config/cf/vnclibs.def	2003-05-03 09:31:55.000000000 +0000
+++ Xvnc/config/cf/vnclibs.def	2007-05-15 02:18:22.000000000 +0000
@@ -11,7 +11,7 @@
 /* Avoid linking with different libjpeg in /usr/shlib under Tru64. */
 VNCSYSLIBS = /usr/local/lib/libjpeg.a /usr/local/lib/libz.a -lcrypt
 #else
-VNCSYSLIBS = -L/usr/local/lib -ljpeg -lz -lcrypt
+VNCSYSLIBS = -L@PREFIX@/lib -ljpeg -lz
 #endif
 
-VNCCPPFLAGS = -I$(TOP)/../include -I/usr/local/include
+VNCCPPFLAGS = -I$(TOP)/../include -I@PREFIX@/include
diff -Naur ../vnc_unixsrc/Xvnc/config/imake/imakemdep.h Xvnc/config/imake/imakemdep.h
--- ../vnc_unixsrc/Xvnc/config/imake/imakemdep.h	2003-02-19 16:39:54.000000000 +0000
+++ Xvnc/config/imake/imakemdep.h	2007-05-15 03:59:11.000000000 +0000
@@ -270,8 +270,12 @@
 #define DEFAULT_CPP "cpp"
 #endif
 #ifdef __MACH__
-#define DEFAULT_CPP "/usr/bin/cpp"
-#endif
+# ifdef __APPLE__
+# define DEFAULT_CPP "::CPPCMD::"
+# else
+# define DEFAULT_CPP "/usr/bin/cpp"
+# endif /* __APPLE__ */
+#endif /* __MACH__ */
 
 /*
  * Step 5:  cpp_argv
@@ -555,6 +559,9 @@
 	"-traditional",
 	"-Demxos2",
 #endif
+#if defined(__APPLE__)
+    "-D__APPLE__",
+#endif
 
 };
 
@@ -614,6 +621,12 @@
 # define DEFAULT_OS_MINOR_REV	"r %*d.%[0-9]"
 # define DEFAULT_OS_TEENY_REV	"r %*d.%*d.%[0-9]"
 # define DEFAULT_OS_NAME	"srm %[^\n]"
+#elif defined(__APPLE__)	
+/* uname -v returns "x.yz" or "x.y.z", e.g. "2.02" or "2.1.2". */
+# define DEFAULT_OS_MAJOR_REV	"r %[0-9]"
+# define DEFAULT_OS_MINOR_REV	"r %*d.%[0-9]"
+# define DEFAULT_OS_TEENY_REV	"r %*d.%*d.%[0-9]" /* this will just get 0 */
+# define DEFAULT_OS_NAME	"s %[^\n]"
 #elif defined(ISC)
 /* ISC all Versions ? */
 /* uname -r returns "x.y", e.g. "3.2" ,uname -v returns "x" e.g. "2" */
@@ -923,6 +936,33 @@
 #ifdef __EMX__
 	{"__EMX__", "1"},
 #endif
+#ifdef __APPLE__
+    {"__APPLE__", "1"},
+#endif
+#ifdef __MACH__
+    {"__MACH__", "1"},
+#endif
+#ifdef __ppc__
+    {"__ppc__", "1"},
+#endif
+#ifdef __ppc__
+    {"__ppc__", "1"},
+#endif
+#ifdef __ppc64__
+    {"__ppc64__", "1"},
+#endif
+#ifdef __i386__
+    {"__i386__", "1"},
+#endif
+#ifdef __x86_64__
+    {"__x86_64__", "1"},
+#endif
+#ifdef __BIG_ENDIAN__ 
+    {"__BIG_ENDIAN__", "1"},
+#endif
+#ifdef __LITTLE_ENDIAN__ 
+    {"__LITTLE_ENDIAN__", "1"},
+#endif
 	/* add any additional symbols before this line */
 	{NULL, NULL}
 };
diff -Naur ../vnc_unixsrc/Xvnc/lib/Xdmcp/Alloc.c Xvnc/lib/Xdmcp/Alloc.c
--- ../vnc_unixsrc/Xvnc/lib/Xdmcp/Alloc.c	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/lib/Xdmcp/Alloc.c	2007-05-15 06:13:59.000000000 +0000
@@ -31,7 +31,7 @@
 
 /* stubs for use when Xalloc, Xrealloc and Xfree are not defined */
 
-extern char	*malloc (), *realloc ();
+extern void	*malloc (), *realloc ();
 
 unsigned long *
 Xalloc (amount)
diff -Naur ../vnc_unixsrc/Xvnc/lib/font/Type1/objects.c Xvnc/lib/font/Type1/objects.c
--- ../vnc_unixsrc/Xvnc/lib/font/Type1/objects.c	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/lib/font/Type1/objects.c	2007-05-15 05:23:46.000000000 +0000
@@ -57,6 +57,14 @@
 #include  <ctype.h>
  
 /*
+The following is to include the function prototypes for printf and sprintf
+on Mac OS X and Darwin.
+*/
+#if defined(__APPLE__) || defined(__DARWIN__)
+# include <stdio.h>
+#endif
+
+/*
 override incorrect system functions; for example you might define
 a macro for "strcpy" that diverts it to "my_strcpy".
 */
diff -Naur ../vnc_unixsrc/Xvnc/lib/font/Type1/spaces.c Xvnc/lib/font/Type1/spaces.c
--- ../vnc_unixsrc/Xvnc/lib/font/Type1/spaces.c	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/lib/font/Type1/spaces.c	2007-05-15 05:57:29.000000000 +0000
@@ -37,6 +37,16 @@
  
 :h3.Include Files
 */
+
+/*
+The following is to include the function prototype for sprintf and strlen on
+Mac OS X and Darwin.
+*/
+#if defined(__APPLE__) || defined(__DARWIN__)
+# include <stdio.h>
+# include <string.h>
+#endif
+
 #include "objects.h"
 #include "spaces.h"
 #include "paths.h"
diff -Naur ../vnc_unixsrc/Xvnc/lib/font/Type1/t1malloc.c Xvnc/lib/font/Type1/t1malloc.c
--- ../vnc_unixsrc/Xvnc/lib/font/Type1/t1malloc.c	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/lib/font/Type1/t1malloc.c	2007-05-15 05:25:45.000000000 +0000
@@ -37,6 +37,14 @@
  
 */
 
+/*
+The following is to include the function prototype for printf on Mac OS X
+and Darwin.
+*/
+#if defined(__APPLE__) || defined(__DARWIN__)
+# include <stdio.h>
+#endif
+
 #include "objects.h"	/* get #define for abort() */
 
 static combine();
diff -Naur ../vnc_unixsrc/Xvnc/lib/font/Type1/t1stub.c Xvnc/lib/font/Type1/t1stub.c
--- ../vnc_unixsrc/Xvnc/lib/font/Type1/t1stub.c	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/lib/font/Type1/t1stub.c	2007-05-15 05:26:32.000000000 +0000
@@ -28,6 +28,14 @@
  * SOFTWARE.
  */
 
+/*
+The following is to include the function prototype for printf on Mac OS X
+and Darwin.
+*/
+#if defined(__APPLE__) || defined(__DARWIN__)
+# include <stdio.h>
+#endif
+
 #include "objects.h"	/* get #define for abort() */
  
 xiStub()
diff -Naur ../vnc_unixsrc/Xvnc/programs/Xserver/include/os.h Xvnc/programs/Xserver/include/os.h
--- ../vnc_unixsrc/Xvnc/programs/Xserver/include/os.h	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/programs/Xserver/include/os.h	2007-05-14 14:52:35.000000000 +0000
@@ -51,6 +51,9 @@
 
 #ifndef OS_H
 #define OS_H
+#ifdef __APPLE__
+#include <stdlib.h>
+#endif
 #include "misc.h"
 #define ALLOCATE_LOCAL_FALLBACK(_size) Xalloc((unsigned long)(_size))
 #define DEALLOCATE_LOCAL_FALLBACK(_ptr) Xfree((pointer)(_ptr))
diff -Naur ../vnc_unixsrc/Xvnc/programs/Xserver/include/servermd.h Xvnc/programs/Xserver/include/servermd.h
--- ../vnc_unixsrc/Xvnc/programs/Xserver/include/servermd.h	2006-12-23 12:07:55.000000000 +0000
+++ Xvnc/programs/Xserver/include/servermd.h	2007-05-15 02:05:38.000000000 +0000
@@ -132,6 +132,29 @@
 
 #endif /* vax */
 
+#if defined(__APPLE__) || defined(__DARWIN__)
+
+# if defined(__ppc__) || defined(__ppc64__)
+# define IMAGE_BYTE_ORDER        MSBFirst
+# define BITMAP_BIT_ORDER        MSBFirst /* __ppc__ || __ppc64__ */
+
+# elif defined(__i386__) || defined(__x86_64__)
+# define IMAGE_BYTE_ORDER        LSBFirst
+# define BITMAP_BIT_ORDER        LSBFirst
+# endif /* __i386__ || __x86_64__ */
+
+#define GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT   1
+
+#define LARGE_INSTRUCTION_CACHE
+#define FAST_CONSTANT_OFFSET_MODE
+#define PLENTIFUL_REGISTERS
+#define AVOID_MEMORY_READ
+
+#define FAST_MEMCPY
+
+#endif /* __APPLE__ || __DARWIN__ */
+
 #if (defined(Lynx) && defined(__powerpc__))
 
 /* For now this is for Xvfb only */
diff -Naur ../vnc_unixsrc/Xvnc/programs/Xserver/os/access.c Xvnc/programs/Xserver/os/access.c
--- ../vnc_unixsrc/Xvnc/programs/Xserver/os/access.c	2000-06-11 12:00:51.000000000 +0000
+++ Xvnc/programs/Xserver/os/access.c	2007-05-14 14:52:35.000000000 +0000
@@ -103,7 +103,7 @@
 #endif
 
 #if !defined(AMOEBA)
-#ifdef hpux
+#if defined(hpux) || defined(__DARWIN__)
 # include <sys/utsname.h>
 # ifdef HAS_IFREQ
 #  include <net/if.h>
@@ -480,7 +480,7 @@
 
 #else /* WINTCP */
 
-#if !defined(SIOCGIFCONF) || (defined (hpux) && ! defined (HAS_IFREQ))
+#if !defined(SIOCGIFCONF) || (defined (hpux) && ! defined (HAS_IFREQ)) || defined(__DARWIN__)
 void
 DefineSelf (fd)
     int fd;