diff -uprN grx249.orig/configure grx249.macosx/configure
--- grx249.orig/configure	2012-07-10 19:30:52 +0000
+++ grx249.macosx/configure	2012-11-22 16:35:52 +0000
@@ -48,7 +48,7 @@ target=$default_target
 default_fontpath='${datadir}/grx/fonts'
 fontpath=""
 
-default_x11base=/usr/X11R6
+default_x11base=/usr/X11
 x11base="$default_x11base"
 
 default_x11lib='$(X11BASE)/lib'
@@ -73,8 +73,10 @@ USE_DIRECT_MOUSE_DRIVER=n
 USE_SVGALIB_DRIVER=y
 USE_FRAMEBUFFER_DRIVER=y
 SET_SUIDROOT=y
-USE_INOUTP_FRAMEDRIVERS=y
+USE_INOUTP_FRAMEDRIVERS=n
 BUILD_X86_64=n
+FAT_I386=n
+FAT_X86_64=n
 lsocket=""
 subst_EP=""
 
@@ -165,6 +167,8 @@ for ac_option do
       suidroot)        SET_SUIDROOT=y;;
       io-framedrivers) USE_INOUTP_FRAMEDRIVERS=y;;
       lsocket)         lsocket=" -lsocket";;
+      fat-i386)        FAT_I386=y;;
+      fat-x86_64)      FAT_X86_64=y;;
     esac;;
   -disable-* | --disable-* | -di-* | --di-*)
     case "`echo "$ac_option" | sed -e 's/^-*disable-//;s/^-*di-//'`" in
@@ -185,6 +189,8 @@ for ac_option do
       suidroot)        SET_SUIDROOT=n;;
       io-framedrivers) USE_INOUTP_FRAMEDRIVERS=n;;
       lsocket)         lsocket="";;
+      fat-i386)        FAT_I386=n;;
+      fat-x86_64)      FAT_X86_64=n;;
     esac;;
   -with-* | --with-*)
     case "`echo "$ac_option" | sed -e 's/^-*with-//'`" in
@@ -193,9 +199,9 @@ for ac_option do
       x11-base=*)  x11base="$ac_optarg";;
       x11-base)    echo "$0: \`--with-x11-base' requires an argument" >&2; exit 1;;
       x11-lib=*)   x11lib="$ac_optarg";;
-      x11-base)    echo "$0: \`--with-x11-lib' requires an argument" >&2; exit 1;;
-      unitspath=*)  unitspath="$ac_optarg";;
-      unitspath)    echo "$0: \`--with-unitspath' requires an argument" >&2; exit 1;;
+      x11-lib)     echo "$0: \`--with-x11-lib' requires an argument" >&2; exit 1;;
+      unitspath=*) unitspath="$ac_optarg";;
+      unitspath)   echo "$0: \`--with-unitspath' requires an argument" >&2; exit 1;;
     esac;;
   -without-* | --without-*)
     case "`echo "$ac_option" | sed -e 's/^-*without-//'`" in
@@ -219,9 +225,9 @@ Options: [defaults in brackets after des
   --includedir=DIR          C header files [PREFIX/include]
   --infodir=DIR             info documentation [PREFIX/info]
   --target=TARGET           configure for TARGET [$default_target]
-                            possible values: djgpp,x11,console,w32,sdlx,sdlw
+                            possible values djgpp,x11,console,w32,sdlx,sdlw,osx
                             or GCC-style ("i386-mingw32") for cross-compiling
-  --enable-x86_64           build for x86_64 architecture [no]
+  --enable-x86_64           in linux build for x86_64 architecture [no]
   --enable-jpeg             include JPEG support [no]
   --enable-png              include PNG support [no]
   --enable-zlib             use zlib [no]
@@ -247,8 +253,11 @@ The following options apply to the Linux
   --enable-framebuffer      use framebuffer driver [yes]
   --enable-suidroot         create suid root executables (required with svgalib
                             1.4.x) [yes]
-  --enable-io-framedrivers  use frame drivers that require suid root
-                            executables under newer versions of svgalib [yes]
+  --enable-io-framedrivers  add frame drivers that use inport/outport 
+                            instructions [no]
+The following options apply to Mac OS X build of "fat binaries" only
+  --enable-fat-i386         [no]
+  --enable-fat-x86_64       [no]
 Some options can be abbreviated, e.g. \`--p' for \`--prefix',
 \`--en-FOO' for \`--enable-FOO' and \`--di-FOO' for \`--disable-FOO'.
 NOTE: This script is completely OPTIONAL. If you don't know what to do with it,
@@ -270,6 +279,8 @@ case "`echo "$target" | tr A-Z a-z`" in
   *w32 | *mingw*) cfgsection=GRXVW32; target_makefile=makefile.w32;;
   sdlx)           cfgsection=GRXVX11; target_makefile=makefile.sdl; subst_EP="/^EP=/s/=.*/=x/";;
   sdlw)           cfgsection=GRXVW32; target_makefile=makefile.sdl; subst_EP="/^EP=/s/=.*/=/";;
+  osx)            cfgsection=GRXVOSX; target_makefile=makefile.osx;;
+  *darwin*)       cfgsection=GRXVOSX; target_makefile=makefile.osx;;
   *)              echo "$0: invalid target" >&2; exit 1;;
 esac
 
@@ -297,7 +308,8 @@ if [ -r Makefile ]; then
      cmp Makefile makefile.dj2 > /dev/null 2>&1 ||
      cmp Makefile makefile.w32 > /dev/null 2>&1 ||
      cmp Makefile makefile.x11 > /dev/null 2>&1 ||
-     cmp Makefile makefile.sdl > /dev/null 2>&1; then
+     cmp Makefile makefile.sdl > /dev/null 2>&1 ||
+     cmp Makefile makefile.osx > /dev/null 2>&1; then
     rm -f Makefile
   else
     echo "$0: Makefile exists already. Not overwriting!" >&2
@@ -319,7 +331,7 @@ cfgfile="makedefs.grx"
 cfgorigfile="makedefs.orig"
 if [ ! -r "$cfgfile" ]; then
   echo "$0: $cfgfile not found" >&2
-  exit 1											    
+  exit 1
 fi
 
 if [ ! -r "$cfgorigfile" ]; then
@@ -356,6 +368,8 @@ if sed -e "/^BUILD_X86_64=/s/=.*/=$BUILD
            /^USE_FRAMEBUFFER_DRIVER=/s/=.*/=$USE_FRAMEBUFFER_DRIVER/;
            /^SET_SUIDROOT=/s/=.*/=$SET_SUIDROOT/;
            /^USE_INOUTP_FRAMEDRIVERS=/s/=.*/=$USE_INOUTP_FRAMEDRIVERS/;
+           /^FAT_I386=/s/=.*/=$FAT_I386/;
+           /^FAT_X86_64=/s/=.*/=$FAT_X86_64/;
            /^exec_prefix=/s|=.*|=$exec_prefix|;
            /^bindir=/s|=.*|=$bindir|;
            /^libdir=/s|=.*|=$libdir|;
diff -uprN grx249.orig/include/grx20.h grx249.macosx/include/grx20.h
--- grx249.orig/include/grx20.h	2012-07-08 14:40:56 +0000
+++ grx249.macosx/include/grx20.h	2012-11-22 13:52:24 +0000
@@ -64,10 +64,10 @@
 #define GRX_VERSION     GRX_VERSION_GCC_386_DJGPP
 #endif
 #if defined(__XWIN__)
-#if defined(__linux__) && defined(__i386__)
+#if (defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) ) && defined(__i386__)
 #define GRX_VERSION     GRX_VERSION_GCC_386_X11
 #endif
-#if defined(__linux__) && defined(__x86_64__)
+#if (defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) ) && defined(__x86_64__)
 #define GRX_VERSION     GRX_VERSION_GCC_X86_64_X11
 #endif
 #else
@@ -77,7 +77,7 @@
 #if defined(__linux__) && defined(__x86_64__)
 #define GRX_VERSION     GRX_VERSION_GCC_X86_64_LINUX
 #endif
-#endif
+#endif	/* __XWIN__ */
 #ifdef  __WIN32__
 #define GRX_VERSION     GRX_VERSION_GCC_386_WIN32
 #endif
@@ -109,7 +109,7 @@
 #endif /* _MSC_VER */
 
 #ifndef GRX_VERSION
-#if defined(unix) || defined(__unix) || defined(__unix__) || defined(_AIX)
+#if defined(unix) || defined(__unix) || defined(__unix__) || defined(_AIX) || (defined(__APPLE__) && defined(__MACH__))
 #define GRX_VERSION     GRX_VERSION_GENERIC_X11
 #endif
 #endif
diff -uprN grx249.orig/lib/macosx/dummy grx249.macosx/lib/macosx/dummy
--- grx249.orig/lib/macosx/dummy	1970-01-01 00:00:00 +0000
+++ grx249.macosx/lib/macosx/dummy	1998-01-08 02:32:44 +0000
@@ -0,0 +1 @@
+-- empty --
diff -uprN grx249.orig/makedefs.grx grx249.macosx/makedefs.grx
--- grx249.orig/makedefs.grx	2012-07-10 20:21:50 +0000
+++ grx249.macosx/makedefs.grx	2012-11-22 16:29:00 +0000
@@ -46,6 +46,10 @@ HAVE_UNIX_TOOLS=n
 # Specify in linux if you want to build the library for x86_64
 BUILD_X86_64=n
 
+# Specify in Mac OS X if you want to build "fat binaries" which include
+FAT_I386=n
+FAT_X86_64=n
+
 # For SDL driver the executable prefix EP is used to discriminate 
 # between linux X11 and mingw32. Set
 #EP=x         ... For linux X11.
@@ -65,6 +69,7 @@ STRIP  = $(CROSS_PLATFORM)strip
 SYSTEM_TAG_PREFIX     = systag
 LINUX_i386_CONSOLE    = $(SYSTEM_TAG_PREFIX).000
 LINUX_i386_X11        = $(SYSTEM_TAG_PREFIX).002
+MACOSX_GCC_X11        = $(SYSTEM_TAG_PREFIX).003
 DOS_DJGPP_V2          = $(SYSTEM_TAG_PREFIX).004
 WIN32_GCC_i386_STATIC = $(SYSTEM_TAG_PREFIX).006
 ANY_GCC_SDL_STATIC    = $(SYSTEM_TAG_PREFIX).008
@@ -171,7 +176,7 @@ endif
 ifdef GRXVX11
 
 # The X11 base dir on your system
-X11BASE=/usr/X11R6
+X11BASE=/usr/X11
 
 # Add directories with X11 include files here
 X11INCS=-I$(X11BASE)/include
@@ -197,6 +202,50 @@ SET_XSUIDROOT=n
 
 endif
 
+### MAC OS X X11 SPECIFIC ###################################################
+
+ifdef GRXVOSX
+
+# Put libgrx20X.a, libgrx20X.dylib in lib/macosx
+GRX_LIB_SUBDIR=macosx
+
+# Set here the default destination dirs for install and uninstall targets
+prefix=/usr/local
+
+# Set the default GRX font path
+#GRX_DEFAULT_FONT_PATH=${datadir}/grx/fonts
+
+# The X11 base dir on your system
+X11BASE=/usr/X11
+
+# Add directories with X11 include files here
+X11INCS=-I$(X11BASE)/include
+
+# put X11 required libraries and directories here
+# note: some systems need -lsocket added
+X11LIB=$(X11BASE)/lib
+X11LIBS=-L$(X11LIB) -lX11
+
+# the apple linker ld has no option -s
+ifndef   DEBUG
+LDOPT =
+endif
+
+# for smart linking
+LDOPT += -dead_strip
+
+# check for "fat binaries" build
+ifeq ($(FAT_I386),y)
+CCOPT += -arch i386
+LDOPT += -arch i386
+endif
+ifeq ($(FAT_X86_64),y)
+CCOPT += -arch x86_64
+LDOPT += -arch x86_64
+endif
+
+endif
+
 ### DOS DJGPPv2 SPECIFIC #################################################
 
 ifdef GRXVDJ2
diff -uprN grx249.orig/makefile.osx grx249.macosx/makefile.osx
--- grx249.orig/makefile.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/makefile.osx	2012-11-16 18:26:34 +0000
@@ -0,0 +1,69 @@
+#
+# GRX makefile for MAC OS X /X11 version (GNU-make)
+#
+.PHONY : libs test bgitest clean cleanall install uninstall \
+	 install-bin uninstall-bin install-fonts uninstall-fonts \
+	 install-info uninstall-info
+
+GRXVOSX=y
+
+include makedefs.grx
+
+all: libs test bgitest
+
+libs:
+	$(MAKE) -C src -f makefile.osx
+
+test: libs
+	$(MAKE) -C test   -f makefile.osx
+ifeq ($(INCLUDE_GPC_SUPPORT),y)
+	$(MAKE) -C pascal -f makefile.osx
+endif
+
+bgitest: libs
+ifeq ($(INCLUDE_BGI_SUPPORT),y)
+	$(MAKE) -C test/bgi   -f makefile.osx
+ifeq ($(INCLUDE_GPC_SUPPORT),y)
+	$(MAKE) -C pascal/bgi -f makefile.osx
+endif
+endif
+
+clean:
+	$(MAKE) -C test       -f makefile.osx clean
+ifeq ($(INCLUDE_BGI_SUPPORT),y)
+	$(MAKE) -C test/bgi   -f makefile.osx clean
+endif
+	$(MAKE) -C src        -f makefile.osx clean
+ifeq ($(INCLUDE_GPC_SUPPORT),y)
+	$(MAKE) -C pascal     -f makefile.osx clean
+ifeq ($(INCLUDE_BGI_SUPPORT),y)
+	$(MAKE) -C pascal/bgi -f makefile.osx clean
+endif
+endif
+
+cleanall: clean
+	$(MAKE) -C src -f makefile.osx cleanall
+
+install:
+	$(MAKE) -C src -f makefile.osx install
+
+uninstall:
+	$(MAKE) -C src -f makefile.osx uninstall
+
+install-info:
+	$(MAKE) -C src -f makefile.osx install-info
+
+uninstall-info:
+	$(MAKE) -C src -f makefile.osx uninstall-info
+
+install-bin:
+	$(MAKE) -C src -f makefile.osx install-bin
+
+uninstall-bin:
+	$(MAKE) -C src -f makefile.osx uninstall-bin
+
+install-fonts:
+	$(MAKE) -C src -f makefile.osx install-fonts
+
+uninstall-fonts:
+	$(MAKE) -C src -f makefile.osx uninstall-fonts
diff -uprN grx249.orig/pascal/bgi/graph.pas grx249.macosx/pascal/bgi/graph.pas
--- grx249.orig/pascal/bgi/graph.pas	2012-07-07 14:20:54 +0000
+++ grx249.macosx/pascal/bgi/graph.pas	2012-11-16 19:02:16 +0000
@@ -488,7 +488,7 @@ function KeyPressed: Boolean; asmname 'k
 function ReadKey: Char; asmname 'getch';
 {$endif}
 
-{flush the graphics: useful only in X windows when switching 
+{flush the graphics: useful only in X windows when switching
  between graphics and console windows open simultaneously}
 procedure GrFlush; asmname 'GrFlush';
 
diff -uprN grx249.orig/pascal/bgi/makefile.lnx grx249.macosx/pascal/bgi/makefile.lnx
--- grx249.orig/pascal/bgi/makefile.lnx	2007-08-27 01:59:50 +0000
+++ grx249.macosx/pascal/bgi/makefile.lnx	2012-11-14 14:06:30 +0000
@@ -2,7 +2,6 @@
 # GRX test programs makefile for LINUX/console.
 # Uses GNU make.
 #
-.SUFFIXES: .exe
 .PHONY: clean
 
 GRXVLNX=y
@@ -42,7 +41,7 @@ PROGS= 			\
 all: $(PROGS)
 
 $(PROGS): % : %.pas $(GRXLIB) graph.pas
-	$(COMPILER) $(CCOPT) -o $* $*.pas $(LIBS)
+	$(COMPILER) $(CCOPT) -o $* $*.pas $(LDOPT) $(LIBS)
 	chmod $(EXECBITS) $@
 
 clean:
diff -uprN grx249.orig/pascal/bgi/makefile.osx grx249.macosx/pascal/bgi/makefile.osx
--- grx249.orig/pascal/bgi/makefile.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/pascal/bgi/makefile.osx	2012-11-14 14:05:56 +0000
@@ -0,0 +1,56 @@
+#
+# GRX test programs makefile for MAC OS X /X11.
+# Uses GNU make.
+#
+.PHONY: clean
+
+GRXVOSX=y
+
+include ../../makedefs.grx
+
+# The following line is useful only in this makefile to force recompilation
+GRXLIB = ../../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+# In normal use  the library libgrx20X.a or libgrx20X.dylib is linked in through 
+# {$L grx20X} contained in the unit graph.pas called by "uses graph".
+# The same is valid for other ADDON libraries.
+# If the library is NOT installed give its path
+# (default when first compiling/testing the library)
+GRXLIBPATH = -L../../lib/$(GRX_LIB_SUBDIR)
+# When it is installed in a standard system location
+# (normal use) this is no more necessary
+
+ifeq ($(SET_XSUIDROOT),y)
+EXECBITS = 4755
+else
+EXECBITS = 0755
+endif
+
+ADDON_LIBS=
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+  ADDON_LIBS += -lXxf86dga -lXext    #NOT included in graph.pas
+endif
+
+LIBS= $(GRXLIBPATH) $(ADDON_LIBS)
+
+# Compiler and options on your system  
+COMPILER = $(PC) --automake
+
+PROGS= 			\
+	xallmodes	\
+	xmodelist	\
+	xcolors		\
+	xdemo		\
+	xsmall		\
+	xpalette
+
+all: $(PROGS)
+
+$(PROGS): x% : %.pas $(GRXLIB) graph.pas
+	$(COMPILER) $(CCOPT) -o $@ $*.pas $(LDOPT) $(LIBS)
+	chmod $(EXECBITS) $@
+
+clean:
+	rm -f *.o *.gpi *.gpm $(PROGS)
+
+
diff -uprN grx249.orig/pascal/bgi/makefile.x11 grx249.macosx/pascal/bgi/makefile.x11
--- grx249.orig/pascal/bgi/makefile.x11	2007-08-27 02:00:34 +0000
+++ grx249.macosx/pascal/bgi/makefile.x11	2012-11-14 14:07:05 +0000
@@ -2,7 +2,6 @@
 # GRX test programs makefile for LINUX/X11.
 # Uses GNU make.
 #
-.SUFFIXES: .exe
 .PHONY: clean
 
 GRXVX11=y
@@ -48,7 +47,7 @@ PROGS= 			\
 all: $(PROGS)
 
 $(PROGS): x% : %.pas $(GRXLIB) graph.pas
-	$(COMPILER) $(CCOPT) -o $@ $*.pas $(LIBS)
+	$(COMPILER) $(CCOPT) -o $@ $*.pas $(LDOPT) $(LIBS)
 	chmod $(EXECBITS) $@
 
 clean:
diff -uprN grx249.orig/pascal/makefile.lnx grx249.macosx/pascal/makefile.lnx
--- grx249.orig/pascal/makefile.lnx	2007-08-27 01:57:08 +0000
+++ grx249.macosx/pascal/makefile.lnx	2012-11-14 14:07:56 +0000
@@ -2,7 +2,6 @@
 # GRX test programs makefile for LINUX/console.
 # Uses GNU make.
 #
-.SUFFIXES: .exe
 .PHONY: clean
 
 GRXVLNX=y
@@ -46,7 +45,7 @@ PROGS= 			\
 all: $(PROGS)
 
 $(PROGS): % : %.pas $(GRXLIB) grx.pas
-	$(COMPILER) $(CCOPT) -o $* $*.pas $(LIBS)
+	$(COMPILER) $(CCOPT) -o $* $*.pas $(LDOPT) $(LIBS)
 	chmod $(EXECBITS) $@
 
 clean:
diff -uprN grx249.orig/pascal/makefile.osx grx249.macosx/pascal/makefile.osx
--- grx249.orig/pascal/makefile.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/pascal/makefile.osx	2012-11-16 18:52:07 +0000
@@ -0,0 +1,60 @@
+#
+# GRX test programs makefile for MAC OS X /X11. Uses GNU make.
+# Uses GNU make.
+#
+.PHONY: clean
+
+GRXVOSX=y
+
+include ../makedefs.grx
+
+# The following line is useful only in this makefile to force recompilation
+GRXLIB = ../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+# In normal use  the library libgrx20X.a or libgrx20X.dylib is linked in through 
+# {$L grx20X} contained in the unit grx.pas called by "uses grx".
+# The same is valid for other ADDON libraries.
+# If the library is NOT installed give its path
+# (default when first compiling/testing the library)
+GRXLIBPATH = -L../lib/$(GRX_LIB_SUBDIR)
+# When it is installed in a standard system location
+# (normal use) this is no more necessary
+
+ifeq ($(SET_XSUIDROOT),y)
+EXECBITS = 4755
+else
+EXECBITS = 0755
+endif
+
+ADDON_LIBS = -L${prefix}/lib
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+  ADDON_LIBS += -lXxf86dga -lXext      #NOT included in grx.pas
+endif
+
+LIBS= $(GRXLIBPATH) $(ADDON_LIBS)
+
+# Compiler and options on your system  
+COMPILER = $(PC) --automake
+
+
+PROGS= 			\
+	xblt_test 	\
+	xmodetest 	\
+	xkeytest	\
+	xtxt_test 	\
+	xvir_test	\
+	xpolytest	\
+	xjpgtest	\
+	xcolortst	\
+	ximgview
+
+all: $(PROGS)
+
+$(PROGS): x% : %.pas $(GRXLIB) grx.pas
+	$(COMPILER) $(CCOPT) -o $@ $*.pas $(LDOPT) $(LIBS)
+	chmod $(EXECBITS) $@
+
+clean:
+	rm -f *.o *.gpi *.gpm $(PROGS)
+
+
diff -uprN grx249.orig/pascal/makefile.w32 grx249.macosx/pascal/makefile.w32
--- grx249.orig/pascal/makefile.w32	2007-08-27 01:58:12 +0000
+++ grx249.macosx/pascal/makefile.w32	2012-11-14 13:33:44 +0000
@@ -42,10 +42,10 @@ PROGS_C=		\
 all: $(PROGS) $(PROGS_C)
 
 $(PROGS): %.exe : %.pas $(GRXLIB) grx.pas
-	$(COMPILER) $(CCOPT) -o $*.exe $*.pas $(LIBS)
+	$(COMPILER) $(CCOPT) -o $*.exe $*.pas $(LDOPT) $(LIBS)
 
 $(PROGS_C): %.exe : %.pas $(GRXLIB) grx.pas
-	$(COMPILER) $(CCOPT) -o $*.exe $*.pas $(LIBS) -mconsole
+	$(COMPILER) $(CCOPT) -o $*.exe $*.pas $(LDOPT) $(LIBS) -mconsole
 
 clean:
 ifeq ($(HAVE_UNIX_TOOLS),y)
diff -uprN grx249.orig/pascal/makefile.x11 grx249.macosx/pascal/makefile.x11
--- grx249.orig/pascal/makefile.x11	2007-08-27 01:57:40 +0000
+++ grx249.macosx/pascal/makefile.x11	2012-11-14 14:07:32 +0000
@@ -2,7 +2,6 @@
 # GRX test programs makefile for LINUX/X11. Uses GNU make.
 # Uses GNU make.
 #
-.SUFFIXES: .exe
 .PHONY: clean
 
 GRXVX11=y
@@ -52,7 +51,7 @@ PROGS= 			\
 all: $(PROGS)
 
 $(PROGS): x% : %.pas $(GRXLIB) grx.pas
-	$(COMPILER) $(CCOPT) -o $@ $*.pas $(LIBS)
+	$(COMPILER) $(CCOPT) -o $@ $*.pas $(LDOPT) $(LIBS)
 	chmod $(EXECBITS) $@
 
 clean:
diff -uprN grx249.orig/src/bgi/bccgrx00.h grx249.macosx/src/bgi/bccgrx00.h
--- grx249.orig/src/bgi/bccgrx00.h	2007-01-09 16:35:46 +0000
+++ grx249.macosx/src/bgi/bccgrx00.h	2012-10-28 16:25:43 +0000
@@ -26,7 +26,13 @@
 #define __BCCGRX00_H
 
 #include <stddef.h>
+
+#if defined(__APPLE__) && defined(__MACH__)
+#include <stdlib.h>
+#else
 #include <malloc.h>
+#endif
+
 #include <string.h>
 
 #include "../include/grx20.h"
diff -uprN grx249.orig/src/bgi/text1.c grx249.macosx/src/bgi/text1.c
--- grx249.orig/src/bgi/text1.c	2001-12-23 04:15:42 +0000
+++ grx249.macosx/src/bgi/text1.c	2012-11-01 09:42:44 +0000
@@ -69,7 +69,7 @@ int __gr_text_installfont( int start, in
   char *temp = alloca(strlen(name)+1+4);
   char *temp1;
 
-#ifdef __linux__
+#if ((defined __linux__) || (defined(__APPLE__) && defined(__MACH__)) )
 #  define CHG_CHAR '\\'
 #  define NEW_CHAR '/'
 #else
diff -uprN grx249.orig/src/depend.osx grx249.macosx/src/depend.osx
--- grx249.orig/src/depend.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/src/depend.osx	2012-10-31 08:25:24 +0000
@@ -0,0 +1,5 @@
+# This is just a dummy file
+# If you really work on GRX and need a working
+# rebuild, create a real dependencies file by
+# make -f makefile.osx dep
+
diff -uprN grx249.orig/src/fonts/fdv_raw.c grx249.macosx/src/fonts/fdv_raw.c
--- grx249.orig/src/fonts/fdv_raw.c	2006-10-12 13:17:10 +0000
+++ grx249.macosx/src/fonts/fdv_raw.c	2012-11-22 16:17:51 +0000
@@ -50,7 +50,7 @@ static void swap_header(void) {
     _GR_swap32u(&fhdr.version);
     _GR_swap32u(&fhdr.offset);
     _GR_swap32u(&fhdr.flags);
-    _GR_swap32u(&fhdr.length);
+    _GR_swap32u(&fhdr.numchars);
     _GR_swap32u(&fhdr.charsize);
     _GR_swap32u(&fhdr.height);
     _GR_swap32u(&fhdr.width);
diff -uprN grx249.orig/src/gformats/png2ctx.c grx249.macosx/src/gformats/png2ctx.c
--- grx249.orig/src/gformats/png2ctx.c	2001-06-22 00:10:24 +0000
+++ grx249.macosx/src/gformats/png2ctx.c	2012-11-21 10:10:49 +0000
@@ -124,7 +124,7 @@ static int readpng( FILE *f, GrContext *
 
   /* is it a PNG file? */
   if( fread( buf,1,8,f ) != 8 ) return -1;
-  if( ! png_check_sig( buf,8 ) ) return -1;
+  if(png_sig_cmp( buf,0,8 ) ) return -1;
 
   png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
   if( !png_ptr ){
@@ -267,7 +267,7 @@ static int querypng( FILE *f, int *w, in
 
   /* is it a PNG file? */
   if( fread( buf,1,8,f ) != 8 ) return -1;
-  if( ! png_check_sig( buf,8 ) ) return -1;
+  if(png_sig_cmp( buf,0,8 ) ) return -1;
 
   png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
   if( !png_ptr ) return -1;
diff -uprN grx249.orig/src/makefile.dj2 grx249.macosx/src/makefile.dj2
--- grx249.orig/src/makefile.dj2	2012-07-07 14:33:22 +0000
+++ grx249.macosx/src/makefile.dj2	2012-11-11 19:03:31 +0000
@@ -2,7 +2,7 @@
 # GRX Library Makefile for DJGPP v2. Needs GNU Make.
 # Make sure your shell is command.com !
 #
-.PHONY : clean cleanall install uninstall \
+.PHONY : clean cleanall install uninstall dep \
 	 install-bin uninstall-bin install-fonts uninstall-fonts \
 	 install-info uninstall-info
 
diff -uprN grx249.orig/src/makefile.lnx grx249.macosx/src/makefile.lnx
--- grx249.orig/src/makefile.lnx	2012-07-07 14:33:22 +0000
+++ grx249.macosx/src/makefile.lnx	2012-11-11 19:02:48 +0000
@@ -1,7 +1,7 @@
 #
 # GRX Library Makefile for LINUX/console. Uses GNU Make.
 #
-.PHONY : libst libsh clean cleanall install uninstall setsuid \
+.PHONY : libst libsh clean cleanall install uninstall setsuid dep \
 	 install-bin uninstall-bin install-fonts uninstall-fonts \
 	 install-info uninstall-info
 
diff -uprN grx249.orig/src/makefile.osx grx249.macosx/src/makefile.osx
--- grx249.orig/src/makefile.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/src/makefile.osx	2012-11-22 13:50:50 +0000
@@ -0,0 +1,287 @@
+#
+# Library Makefile for MAC OS X/X11. Uses GNU Make.
+#
+# set up for GCC 
+#
+.PHONY : libst libsh clean cleanall install uninstall setsuid dep \
+	 install-bin uninstall-bin install-fonts uninstall-fonts \
+	 install-info uninstall-info
+         
+GRXVOSX=y
+
+include ../makedefs.grx
+
+INCDIR= -I. -I./include -I../include $(X11INCS) -I${prefix}/include
+
+ifdef GRX_DEFAULT_FONT_PATH
+CCOPT += -DGRX_DEFAULT_FONT_PATH=\"$(GRX_DEFAULT_FONT_PATH)\"
+endif
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+CCOPT += -DXF86DGA_DRIVER
+endif
+
+ifeq ($(USE_XF86DGA_FRAMEBUFFER),y)
+CCOPT += -DXF86DGA_FRAMEBUFFER
+endif
+
+ifeq ($(SET_XSUIDROOT),y)
+EXECBITS = 4755
+else
+EXECBITS = 0755
+endif
+
+ADDON_LIBS = -L${prefix}/lib
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+  ADDON_LIBS += -lXxf86dga -lXext
+endif
+
+GRX20ST   = ../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+
+GRX20SH = ../lib/$(GRX_LIB_SUBDIR)/libgrx20X
+GRX20SHli = $(GRX20SH)-$(word 1,$(subst ., ,$(GRX_VERSION))).dylib
+GRX20SHna = $(GRX20SH)-$(GRX_VERSION).dylib
+SHCCOPT = -fPIC -D__SHARED__
+
+OX=.o
+OP=
+
+include ./stdobjs.mak
+
+STD_O= $(STD_1) $(STD_2)  $(STD_3)  $(STD_4) \
+       $(STD_5) $(STD_6)  $(STD_7)  $(STD_8) \
+       $(STD_9) $(STD_10) $(STD_11) $(STD_12)\
+
+BGI_O= $(BGI_1) $(BGI_2)  $(BGI_3)  $(BGI_4) \
+       $(BGI_5) $(BGI_6)
+
+ADDON_O=
+
+ifdef DEBUG
+ ADDON_O += $(DBG_1)
+endif
+
+ifeq ($(HAVE_LIBTIFF),y)
+  ADDON_O += $(TIF_1)
+  ADDON_LIBS += -ltiff
+endif
+
+ifeq ($(HAVE_LIBJPEG),y)
+  ADDON_O += $(JPG_1)
+  ADDON_LIBS += -ljpeg
+else
+  ADDON_O += $(NOJPG_1)
+endif
+
+ifeq ($(HAVE_LIBPNG),y)
+  ADDON_O += $(PNG_1)
+  ADDON_LIBS += -lpng
+else
+  ADDON_O += $(NOPNG_1)
+endif
+
+ifeq ($(NEED_ZLIB),y)
+  ADDON_LIBS += -lz
+endif
+
+ifeq ($(INCLUDE_PRINTING_CODE),y)
+  ADDON_O += $(PRN_1)
+  INCDIR += -I../addons/print
+ifeq ($(INCLUDE_BGI_SUPPORT),y)
+  BGI_O += $(PRNBGI_1)
+endif
+endif
+
+ifeq ($(INCLUDE_BMP_CODE),y)
+  ADDON_O += $(BMP_1)
+  INCDIR  += -I../addons/bmp
+endif
+
+O=      $(STD_O)            \
+	$(ADDON_O)          \
+	fdrivers/fd_xwin.o  \
+	fdrivers/ram24.o    \
+	fdrivers/ram32l.o   \
+	fdrivers/ram32h.o   \
+	fonts/fdv_xwin.o    \
+	mouse/xwininp.o     \
+	mouse/xwinkeys.o    \
+	misc/x11misc.o      \
+	vdrivers/vd_xwin.o
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+O+=	fdrivers/lfb16.o    \
+	fdrivers/lfb24.o    \
+	fdrivers/lfb32h.o   \
+	fdrivers/lfb32l.o   \
+	fdrivers/lfb8.o     \
+	fdrivers/lfbbltrv.o \
+	fdrivers/lfbbltvr.o \
+	fdrivers/lfbbltvv.o \
+	vdrivers/vd_xfdga.o
+endif
+
+ifeq ($(INCLUDE_BGI_SUPPORT),y)
+  O += $(BGI_O)
+endif
+
+LO = $(subst $(OX),.lo,$(O))
+
+UTILP = ../bin/bin2c \
+	../bin/fnt2c
+
+UTILPX= ../bin/xmodetest
+
+all: libst libsh $(UTILP) $(UTILPX)
+
+libst: $(GRX20ST)
+
+$(GRX20ST): $(MACOSX_GCC_X11) $(O)
+	-rm -f $(GRX20ST)
+	$(AR) -r $(GRX20ST) $(O)
+	$(RANLIB) $(GRX20ST)
+
+ifeq ($(INCLUDE_SHARED_SUPPORT),y)
+libsh: $(GRX20SHna)
+else
+libsh:
+endif
+
+$(GRX20SHna): $(MACOSX_GCC_X11) $(LO)
+	-rm -f $(GRX20SHna)
+	$(CC) $(LDOPT) -dynamiclib -install_name $(libdir)/$(notdir $(GRX20SHna)) -headerpad_max_install_names -o $(GRX20SHna) $(LO) $(ADDON_LIBS) $(X11LIBS)
+ifndef DEBUG
+	$(STRIP) -r -x -u $(GRX20SHna)
+endif
+	ln -sf $(notdir $(GRX20SHna)) $(GRX20SHli)
+
+$(UTILP): ../bin/% : utilprog/%.o $(GRX20ST)
+	$(CC) $(LDOPT) -o $@ utilprog/$*.o $(GRX20ST) $(X11LIBS)
+	$(STRIP) $@
+
+$(UTILPX): ../bin/x% : utilprog/%.o $(GRX20ST)
+	$(CC) $(LDOPT) -o $@ utilprog/$*.o $(GRX20ST) $(ADDON_LIBS) $(X11LIBS)
+	$(STRIP) $@
+	chmod $(EXECBITS) $@
+
+$(O): $(MACOSX_GCC_X11)
+
+$(LO): $(MACOSX_GCC_X11)
+
+$(MACOSX_GCC_X11):
+	-if [ ! -r $(MACOSX_GCC_X11) ]; then \
+	rm -f $(SYSTEM_TAG_PREFIX).* $(O) $(LO) utilprog/*.o; fi
+	touch $(MACOSX_GCC_X11)
+
+clean:
+	rm -f $(O) $(LO) $(MACOSX_GCC_X11)
+	rm -f utilprog/*.o
+
+cleanall: clean
+ifeq ($(INCLUDE_SHARED_SUPPORT),y)
+	rm -f $(GRX20SHna) $(GRX20SHli)
+endif
+	rm -f $(GRX20ST)
+	rm -f $(UTILP) $(UTILPX)
+
+install: libst libsh
+	install -m 0755 -d $(DESTDIR)$(libdir)
+	install -m 0755 -d $(DESTDIR)$(includedir)
+	install -m 0644 $(GRX20ST) $(DESTDIR)$(libdir)
+ifeq ($(INCLUDE_SHARED_SUPPORT),y)
+	install -m 0755 $(GRX20SHna) $(DESTDIR)$(libdir)
+	ln -sf $(notdir $(GRX20SHna)) $(DESTDIR)$(libdir)/$(notdir $(GRX20SHli))
+	ln -sf $(notdir $(GRX20SHli)) $(DESTDIR)$(libdir)/$(notdir $(GRX20SH).dylib)
+endif
+	install -m 0644 ../include/grx20.h $(DESTDIR)$(includedir)
+	install -m 0644 ../include/grxkeys.h $(DESTDIR)$(includedir)
+	install -m 0644 ../include/libbcc.h $(DESTDIR)$(includedir)
+ifeq ($(INCLUDE_PRINTING_CODE),y)
+	install -m 0644 ../addons/print/grxprint.h $(DESTDIR)$(includedir)
+endif
+ifeq ($(INCLUDE_GPC_SUPPORT),y)
+	install -m 0755 -d $(DESTDIR)$(unitsdir)
+	install -m 0644 ../pascal/grx.pas $(DESTDIR)$(unitsdir)
+	install -m 0644 ../pascal/bgi/graph.pas $(DESTDIR)$(unitsdir)
+endif
+
+uninstall:
+	rm -f $(DESTDIR)$(libdir)/$(notdir $(GRX20ST))
+ifeq ($(INCLUDE_SHARED_SUPPORT),y)
+	rm -f $(DESTDIR)$(libdir)/$(notdir $(GRX20SH).dylib)
+	rm -f $(DESTDIR)$(libdir)/$(notdir $(GRX20SHli))
+	rm -f $(DESTDIR)$(libdir)/$(notdir $(GRX20SHna))
+endif
+	rm -f $(DESTDIR)$(includedir)/grx20.h
+	rm -f $(DESTDIR)$(includedir)/grxkeys.h
+	rm -f $(DESTDIR)$(includedir)/libbcc.h
+ifeq ($(INCLUDE_PRINTING_CODE),y)
+	rm -f $(DESTDIR)$(includedir)/grxprint.h
+endif
+ifeq ($(INCLUDE_GPC_SUPPORT),y)
+	rm -f $(DESTDIR)$(unitsdir)/grx.pas
+	rm -f $(DESTDIR)$(unitsdir)/graph.pas
+endif
+
+setsuid: $(UTILPX)
+ifeq ($(SET_XSUIDROOT),y)
+	chown root ../bin/modetest
+	chmod $(EXECBITS) ../bin/modetest
+else
+	@echo "Nothing to do, SET_XSUIDROOT is not set to 'y' in makedefs.grx"
+endif
+
+install-info:
+	install -m 0755 -d $(DESTDIR)$(infodir)
+	install -m 0644 ../doc/grx*um.inf $(DESTDIR)$(infodir)/grx.info
+	for info_dir_file in $(DESTDIR)$(infodir)/dir /etc/info-dir; do \
+	  if [ -w $$info_dir_file ]; then \
+	    install-info --dir-file=$$info_dir_file $(DESTDIR)$(infodir)/grx.info; \
+	  fi; \
+	done
+
+uninstall-info:
+	for info_dir_file in $(DESTDIR)$(infodir)/dir /etc/info-dir; do \
+	  if [ -w $$info_dir_file ]; then \
+	    install-info --dir-file=$$info_dir_file -r grx; \
+	  fi; \
+	done
+	rm -f $(DESTDIR)$(infodir)/grx.info
+
+install-bin: $(UTILP) $(UTILPX)
+	install -m 0755 -d $(DESTDIR)$(bindir)
+	install -m 0755 ../bin/bin2c $(DESTDIR)$(bindir)
+	install -m 0755 ../bin/fnt2c $(DESTDIR)$(bindir)
+	install -m $(EXECBITS) ../bin/xmodetest $(DESTDIR)$(bindir)
+
+uninstall-bin:
+	rm -f $(DESTDIR)$(bindir)/bin2c
+	rm -f $(DESTDIR)$(bindir)/fnt2c
+	rm -f $(DESTDIR)$(bindir)/xmodetest
+
+ifdef GRX_DEFAULT_FONT_PATH
+install-fonts:
+	install -m 0755 -d $(DESTDIR)$(GRX_DEFAULT_FONT_PATH)
+	install -m 0644 ../fonts/* $(DESTDIR)$(GRX_DEFAULT_FONT_PATH)
+uninstall-fonts:
+	rm -f $(DESTDIR)$(GRX_DEFAULT_FONT_PATH)/*
+endif
+
+dep:
+	$(CC) -MM $(CCOPT) $(INCDIR) $(O:.o=.c) \
+	| sed 's#^.*: \(.*\)\.c#\1.o: \1.c#g' >depend.osx
+
+$(O): %.o : %.c
+	$(CC) -c $(CCOPT) -D__XWIN__ $(INCDIR) $*.c -o $*.o
+
+$(LO): %.lo : %.c
+	$(CC) -c $(CCOPT) $(SHCCOPT) -D__XWIN__ $(INCDIR) $*.c -o $*.lo
+
+.c.s:
+	$(CC) -S $(CCOPT) -D__XWIN__ $(INCDIR) $*.c -o $*.s
+
+.c.o:
+	$(CC) -c $(CCOPT) -D__XWIN__ $(INCDIR) $*.c -o $*.o
+
+include depend.osx
diff -uprN grx249.orig/src/makefile.sdl grx249.macosx/src/makefile.sdl
--- grx249.orig/src/makefile.sdl	2012-07-07 14:33:22 +0000
+++ grx249.macosx/src/makefile.sdl	2012-11-11 19:04:02 +0000
@@ -1,7 +1,7 @@
 #
 # GRX Library Makefile for SDL
 #
-.PHONY : clean cleanall install uninstall \
+.PHONY : clean cleanall install uninstall dep \
 	 install-bin uninstall-bin install-fonts uninstall-fonts
          
 GRXVSDL=y
diff -uprN grx249.orig/src/makefile.w32 grx249.macosx/src/makefile.w32
--- grx249.orig/src/makefile.w32	2012-07-07 14:33:22 +0000
+++ grx249.macosx/src/makefile.w32	2012-11-11 19:05:31 +0000
@@ -2,7 +2,7 @@
 # GRX Library Makefile for Mingw
 # Make sure your shell is command.com !
 #
-.PHONY : clean cleanall install uninstall \
+.PHONY : clean cleanall install uninstall dep \
 	 install-bin uninstall-bin install-fonts uninstall-fonts
          
 GRXVW32=y
diff -uprN grx249.orig/src/makefile.x11 grx249.macosx/src/makefile.x11
--- grx249.orig/src/makefile.x11	2012-07-07 14:33:22 +0000
+++ grx249.macosx/src/makefile.x11	2012-11-11 19:07:41 +0000
@@ -3,7 +3,7 @@
 #
 # set up for GCC / Linux
 #
-.PHONY : libst libsh clean cleanall install uninstall setsuid \
+.PHONY : libst libsh clean cleanall install uninstall setsuid dep \
 	 install-bin uninstall-bin install-fonts uninstall-fonts \
 	 install-info uninstall-info
          
diff -uprN grx249.orig/src/mouse/input.h grx249.macosx/src/mouse/input.h
--- grx249.orig/src/mouse/input.h	2012-07-07 14:29:18 +0000
+++ grx249.macosx/src/mouse/input.h	2012-10-28 16:19:08 +0000
@@ -136,7 +136,7 @@
 #define MS_PER_TICK  (1000L / CLOCKS_PER_SEC)
 #endif
 
-#if !defined(real_time) && defined(unix)
+#if !defined(real_time) && (defined(unix) || (defined(__APPLE__) && defined(__MACH__)))
 #include <unistd.h>
 #include <sys/times.h>
 #define real_time(tv) do {                                                  \
diff -uprN grx249.orig/src/utilprog/bin2c.c grx249.macosx/src/utilprog/bin2c.c
--- grx249.orig/src/utilprog/bin2c.c	2002-06-16 02:06:02 +0000
+++ grx249.macosx/src/utilprog/bin2c.c	2012-10-28 16:28:20 +0000
@@ -26,7 +26,10 @@
 #include <stdio.h>
 #include <string.h>
 #include <time.h>
+
+#if !(defined(__APPLE__) && defined(__MACH__))
 #include <malloc.h>
+#endif
 
 #define TRUE (1==1)
 #define FALSE (!TRUE)
diff -uprN grx249.orig/src/vdrivers/vd_xwin.c grx249.macosx/src/vdrivers/vd_xwin.c
--- grx249.orig/src/vdrivers/vd_xwin.c	2012-07-07 14:34:06 +0000
+++ grx249.macosx/src/vdrivers/vd_xwin.c	2012-10-28 16:45:18 +0000
@@ -70,7 +70,7 @@ char *_XGrClassNames[6] = {
 static void setbank(int bk);
 static void setrwbanks(int rb,int wb);
 static void loadcolor(int c,int r,int g,int b);
-static int setmode(GrVideoMode *mp,int noclear);
+static int mysetmode(GrVideoMode *mp,int noclear);
 
 GrVideoModeExt grtextext = {
   GR_frameText,                       /* frame driver */
@@ -79,7 +79,7 @@ GrVideoModeExt grtextext = {
   { 0, 0, 0 },                        /* color precisions */
   { 0, 0, 0 },                        /* color component bit positions */
   0,                                  /* mode flag bits */
-  setmode,                            /* mode set */
+  mysetmode,                            /* mode set */
   NULL,                               /* virtual size set */
   NULL,                               /* virtual scroll */
   NULL,                               /* bank set function */
@@ -94,7 +94,7 @@ static GrVideoModeExt grxwinext = {
   { 0, 0, 0 },                        /* color precisions */
   { 0, 0, 0 },                        /* color component bit positions */
   0,                                  /* mode flag bits */
-  setmode,                            /* mode set */
+  mysetmode,                            /* mode set */
   NULL,                               /* virtual size set */
   NULL,                               /* virtual scroll */
   setbank,                            /* bank set function */
@@ -178,7 +178,7 @@ static void loadcolor(int c,int r,int g,
   GRX_LEAVE();
 }
 
-static int setmode(GrVideoMode *mp,int noclear)
+static int mysetmode(GrVideoMode *mp,int noclear)
 {
   char name[100], *window_name, *icon_name;
   int res;
diff -uprN grx249.orig/test/bgi/makefile.dj2 grx249.macosx/test/bgi/makefile.dj2
--- grx249.orig/test/bgi/makefile.dj2	2007-04-06 17:29:34 +0000
+++ grx249.macosx/test/bgi/makefile.dj2	2012-11-11 18:54:13 +0000
@@ -3,7 +3,7 @@
 # Uses GNU make.
 #
 .SUFFIXES: .exe
-.PHONY: clean install uninstall
+.PHONY: clean
 
 GRXVDJ2=y
 
@@ -17,11 +17,15 @@ ADDON_LIBS=-lpc
 #ifeq ($(HAVE_LIBTIFF),y)
 #  ADDON_LIBS += -ltiff
 #endif
-#
+
 #ifeq ($(HAVE_LIBJPEG),y)
 #  ADDON_LIBS += -ljpeg
 #endif
-#
+
+#ifeq ($(HAVE_LIBPNG),y)
+#  ADDON_LIBS += -lpng
+#endif
+
 #ifeq ($(NEED_ZLIB),y)
 #  ADDON_LIBS += -lz
 #endif
diff -uprN grx249.orig/test/bgi/makefile.lnx grx249.macosx/test/bgi/makefile.lnx
--- grx249.orig/test/bgi/makefile.lnx	2007-04-06 17:29:34 +0000
+++ grx249.macosx/test/bgi/makefile.lnx	2012-11-11 16:52:28 +0000
@@ -11,10 +11,12 @@ INCDIR=  -I../../include
 
 CCOPT += -pipe
 
+GRXLIB = ../../lib/$(GRX_LIB_SUBDIR)/libgrx20.a
+
 # Enable this line for static linked test progs (default)
-GRX20 = ../../lib/$(GRX_LIB_SUBDIR)/libgrx20.a
+LIBS = $(GRXLIB)
 # or this if you've already installed the shared libs
-#GRX20 = -L../../lib/$(GRX_LIB_SUBDIR) -lgrx20
+#LIBS = -lgrx20
 
 ifeq ($(USE_SVGALIB_DRIVER),y)
   ADDON_LIBS= -lvga
@@ -23,11 +25,15 @@ endif
 #ifeq ($(HAVE_LIBTIFF),y)
 #  ADDON_LIBS += -ltiff
 #endif
-#
+
 #ifeq ($(HAVE_LIBJPEG),y)
 #  ADDON_LIBS += -ljpeg
 #endif
-#
+
+#ifeq ($(HAVE_LIBPNG),y)
+#  ADDON_LIBS += -lpng
+#endif
+
 #ifeq ($(NEED_ZLIB),y)
 #  ADDON_LIBS += -lz
 #endif
@@ -38,7 +44,7 @@ else
 EXECBITS = 0755
 endif
 
-LIBS= $(GRX20) $(ADDON_LIBS) -lm
+LIBS += $(ADDON_LIBS) -lm
 
 PROGS=              \
 	bgilink     \
@@ -54,7 +60,7 @@ PROGS=              \
 
 all:    $(PROGS)
 
-$(PROGS): % : %.o $(GRX20)
+$(PROGS): % : %.o $(GRXLIB)
 
 clean:
 	rm -f *.o $(PROGS)
diff -uprN grx249.orig/test/bgi/makefile.osx grx249.macosx/test/bgi/makefile.osx
--- grx249.orig/test/bgi/makefile.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/test/bgi/makefile.osx	2012-11-14 14:04:08 +0000
@@ -0,0 +1,87 @@
+#
+# GRX test programs makefile for MAC OS X /X11. Uses GNU make.
+#
+.PHONY : clean setsuid
+
+GRXVOSX=y
+
+include ../../makedefs.grx
+
+INCDIR=  -I../../include
+
+GRXLIB = ../../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+
+# Enable this line for static linked test progs (default)
+LIBS = $(GRXLIB)
+# or this if you've already installed the shared libs
+#LIBS = -lgrx20X
+
+ifeq ($(SET_XSUIDROOT),y)
+EXECBITS = 4755
+else
+EXECBITS = 0755
+endif
+
+ADDON_LIBS=
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+  ADDON_LIBS += -lXxf86dga -lXext
+endif
+
+#ifeq ($(HAVE_LIBTIFF),y)
+#  ADDON_LIBS += -ltiff
+#endif
+
+#ifeq ($(HAVE_LIBJPEG),y)
+#  ADDON_LIBS += -ljpeg
+#endif
+
+#ifeq ($(HAVE_LIBPNG),y)
+#  ADDON_LIBS += -lpng
+#endif
+
+#ifeq ($(NEED_ZLIB),y)
+#  ADDON_LIBS += -lz
+#endif
+
+LIBS += $(ADDON_LIBS) $(X11LIBS) -lm
+
+PROGS=               \
+	xbgilink     \
+	xbccbgi      \
+	xcolortst    \
+	xfontplay    \
+	xsmall       \
+	xtellipse    \
+	xtfill       \
+	xtmodes      \
+	xtpoly       \
+	xttext
+
+all: $(PROGS)
+
+$(PROGS): x%: %.o $(GRXLIB)
+	$(CC) $(LDOPT) -o $@ $*.o $(LIBS)
+	chmod $(EXECBITS) $@
+
+$(PROGS:x%=%.o): %.o : %.c
+	$(CC) -c $(CCOPT) -D__XWIN__ $(INCDIR) $*.c -o $*.o
+
+setsuid: $(PROGS)
+ifeq ($(SET_XSUIDROOT),y)
+	chown root $(PROGS)
+	chmod $(EXECBITS) $(PROGS)
+else
+	@echo "Nothing to do, SET_XSUIDROOT is not set to 'y' in makedefs.grx"
+endif
+
+.c.s:
+	$(CC) -S $(CCOPT) $(INCDIR) $*.c
+
+clean:
+	rm -f *.o $(PROGS)
+
+depend.new:
+	$(CC) -MM $(CCOPT) $(INCDIR) $(PROGS:x%=%.c) > depend.new
+
+#include depend.gnu
diff -uprN grx249.orig/test/bgi/makefile.sdl grx249.macosx/test/bgi/makefile.sdl
--- grx249.orig/test/bgi/makefile.sdl	2007-04-06 17:29:34 +0000
+++ grx249.macosx/test/bgi/makefile.sdl	2012-11-14 14:09:17 +0000
@@ -1,6 +1,7 @@
 #
 # GRX test programs makefile for SDL. Uses GNU make.
 #
+.SUFFIXES: .exe
 .PHONY : clean
 
 GRXVSDL=y
diff -uprN grx249.orig/test/bgi/makefile.w32 grx249.macosx/test/bgi/makefile.w32
--- grx249.orig/test/bgi/makefile.w32	2007-04-06 17:29:34 +0000
+++ grx249.macosx/test/bgi/makefile.w32	2012-11-11 18:53:20 +0000
@@ -3,7 +3,7 @@
 # Uses GNU make.
 #
 .SUFFIXES: .exe
-.PHONY: clean install uninstall
+.PHONY: clean
 
 GRXVW32=y
 
@@ -20,6 +20,10 @@ GRX20 = ../../lib/$(GRX_LIB_SUBDIR)/libg
 #  ADDON_LIBS += -ljpeg
 #endif
 
+#ifeq ($(HAVE_LIBPNG),y)
+#  ADDON_LIBS += -lpng
+#endif
+
 #ifeq ($(NEED_ZLIB),y)
 #  ADDON_LIBS += -lz
 #endif
diff -uprN grx249.orig/test/bgi/makefile.x11 grx249.macosx/test/bgi/makefile.x11
--- grx249.orig/test/bgi/makefile.x11	2012-07-07 14:17:58 +0000
+++ grx249.macosx/test/bgi/makefile.x11	2012-11-11 16:51:23 +0000
@@ -9,10 +9,12 @@ include ../../makedefs.grx
 
 INCDIR=  -I../../include
 
+GRXLIB = ../../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+
 # Enable this line for static linked test progs (default)
-GRX20X = ../../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+LIBS = $(GRXLIB)
 # or this if you've already installed the shared libs
-#GRX20X = -L./../lib/$(GRX_LIB_SUBDIR) -lgrx20X
+#LIBS = -lgrx20X
 
 ifeq ($(SET_XSUIDROOT),y)
 EXECBITS = 4755
@@ -29,16 +31,20 @@ endif
 #ifeq ($(HAVE_LIBTIFF),y)
 #  ADDON_LIBS += -ltiff
 #endif
-#
+
 #ifeq ($(HAVE_LIBJPEG),y)
 #  ADDON_LIBS += -ljpeg
 #endif
-#
+
+#ifeq ($(HAVE_LIBPNG),y)
+#  ADDON_LIBS += -lpng
+#endif
+
 #ifeq ($(NEED_ZLIB),y)
 #  ADDON_LIBS += -lz
 #endif
 
-LIBS= $(GRX20X) $(ADDON_LIBS) $(X11LIBS) -lm
+LIBS += $(ADDON_LIBS) $(X11LIBS) -lm
 
 PROGS=               \
 	xbgilink     \
@@ -54,7 +60,7 @@ PROGS=               \
 
 all: $(PROGS)
 
-$(PROGS): x%: %.o $(GRX20X)
+$(PROGS): x%: %.o $(GRXLIB)
 	$(CC) $(LDOPT) -o $@ $*.o $(LIBS)
 	chmod $(EXECBITS) $@
 
diff -uprN grx249.orig/test/life.c grx249.macosx/test/life.c
--- grx249.orig/test/life.c	2001-03-11 00:44:30 +0000
+++ grx249.macosx/test/life.c	2012-10-28 16:29:15 +0000
@@ -20,7 +20,12 @@
 #include "test.h"
 #include "rand.h"
 
+#if defined(__APPLE__) && defined(__MACH__)
+#include <stdlib.h>
+#else
 #include <malloc.h>
+#endif
+
 #include <string.h>
 #include <time.h>
 
diff -uprN grx249.orig/test/makefile.dj2 grx249.macosx/test/makefile.dj2
--- grx249.orig/test/makefile.dj2	2005-01-17 19:44:24 +0000
+++ grx249.macosx/test/makefile.dj2	2012-11-01 10:45:08 +0000
@@ -3,7 +3,7 @@
 # Uses GNU make.
 #
 .SUFFIXES: .exe
-.PHONY: clean install uninstall
+.PHONY: clean
 
 GRXVDJ2=y
 
diff -uprN grx249.orig/test/makefile.lnx grx249.macosx/test/makefile.lnx
--- grx249.orig/test/makefile.lnx	2002-08-09 02:33:58 +0000
+++ grx249.macosx/test/makefile.lnx	2012-11-11 16:20:41 +0000
@@ -11,10 +11,12 @@ INCDIR=  -I../include
 
 CCOPT += -pipe
 
+GRXLIB = ../lib/$(GRX_LIB_SUBDIR)/libgrx20.a
+
 # Enable this line for static linked test progs (default)
-GRX20 = ../lib/$(GRX_LIB_SUBDIR)/libgrx20.a
+LIBS = $(GRXLIB)
 # or this if you've already installed the shared libs
-#GRX20 = -L../lib/$(GRX_LIB_SUBDIR) -lgrx20
+#LIBS = -lgrx20
 
 ifeq ($(SET_SUIDROOT),y)
 EXECBITS = 4755
@@ -44,7 +46,7 @@ ifeq ($(NEED_ZLIB),y)
   ADDON_LIBS += -lz
 endif
 
-LIBS= $(GRX20) $(ADDON_LIBS) -lm
+LIBS += $(ADDON_LIBS) -lm
 
 PROGS=	arctest     \
 	bb1test     \
@@ -76,11 +78,11 @@ PROGS=	arctest     \
 
 all:    $(PROGS) demogrx
 
-demogrx: demogrx.o gfaz.o $(GRX20)
+demogrx: demogrx.o gfaz.o $(GRXLIB)
 	$(CC) $(LDOPT) -o demogrx demogrx.o gfaz.o $(LIBS)
 	chmod $(EXECBITS) demogrx
 
-$(PROGS): % : %.o $(GRX20)
+$(PROGS): % : %.o $(GRXLIB)
 
 clean:
 	rm -f *.o $(PROGS) demogrx
diff -uprN grx249.orig/test/makefile.osx grx249.macosx/test/makefile.osx
--- grx249.orig/test/makefile.osx	1970-01-01 00:00:00 +0000
+++ grx249.macosx/test/makefile.osx	2012-11-16 18:48:12 +0000
@@ -0,0 +1,110 @@
+#
+# GRX test programs makefile for MAC OS X/X11. Uses GNU make.
+#
+.PHONY : clean setsuid
+
+GRXVOSX=y
+
+include ../makedefs.grx
+
+INCDIR=  -I../include -I${prefix}/include
+
+GRXLIB = ../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+
+# Enable this line for static linked test progs (default)
+LIBS = $(GRXLIB)
+# or this if you've already installed the shared libs
+#LIBS = -lgrx20X
+
+ifeq ($(SET_XSUIDROOT),y)
+EXECBITS = 4755
+else
+EXECBITS = 0755
+endif
+
+ADDON_LIBS= -L${prefix}/lib
+
+ifeq ($(USE_XF86DGA_DRIVER),y)
+  ADDON_LIBS += -lXxf86dga -lXext
+endif
+
+ifeq ($(HAVE_LIBTIFF),y)
+  ADDON_LIBS += -ltiff
+endif
+
+ifeq ($(HAVE_LIBJPEG),y)
+  ADDON_LIBS += -ljpeg
+endif
+
+ifeq ($(HAVE_LIBPNG),y)
+  ADDON_LIBS += -lpng
+endif
+
+ifeq ($(NEED_ZLIB),y)
+  ADDON_LIBS += -lz
+endif
+
+LIBS += $(ADDON_LIBS) $(X11LIBS) -lm
+
+PROGS=  xarctest     \
+	xbb1test     \
+	xblittest    \
+	xcirctest    \
+	xcliptest    \
+	xcolorops    \
+	xcurstest    \
+	xfontdemo    \
+	xfonttest    \
+	ximgtest     \
+	xjpgtest     \
+	xkeys        \
+	xlife        \
+	xlinetest    \
+	xmemtest     \
+	xmousetst    \
+	xpcirctst    \
+	xpnmtest     \
+	xpngtest     \
+	xpolytest    \
+	xrgbtest     \
+	xsbctest     \
+	xscroltst    \
+	xspeedtst    \
+	xtextpatt    \
+	xwinclip     \
+	xwintest
+
+all: $(PROGS) xdemogrx
+
+xdemogrx: demogrx.o gfaz.o $(GRXLIB)
+	$(CC) $(LDOPT) -o xdemogrx demogrx.o gfaz.o $(LIBS)
+	chmod $(EXECBITS) xdemogrx
+
+$(PROGS): x%: %.o $(GRXLIB)
+	$(CC) $(LDOPT) -o $@ $*.o $(LIBS)
+	chmod $(EXECBITS) $@
+
+$(PROGS:x%=%.o): %.o : %.c
+	$(CC) -c $(CCOPT) -D__XWIN__ $(INCDIR) $*.c -o $*.o
+
+.c.o:
+	$(CC) -c $(CCOPT) -D__XWIN__ $(INCDIR) $*.c
+
+.c.s:
+	$(CC) -S $(CCOPT) $(INCDIR) $*.c
+
+clean:
+	rm -f *.o $(PROGS) xdemogrx
+
+setsuid: $(PROGS) xdemogrx
+ifeq ($(SET_XSUIDROOT),y)
+	chown root $(PROGS) xdemogrx
+	chmod $(EXECBITS) $(PROGS) xdemogrx
+else
+	@echo "Nothing to do, SET_XSUIDROOT is not set to 'y' in makedefs.grx"
+endif
+
+depend.new:
+	$(CC) -MM $(CCOPT) $(INCDIR) $(PROGS:x%=%.c) > depend.new
+
+include depend.gnu
diff -uprN grx249.orig/test/makefile.sdl grx249.macosx/test/makefile.sdl
--- grx249.orig/test/makefile.sdl	2007-04-15 17:16:42 +0000
+++ grx249.macosx/test/makefile.sdl	2012-11-14 14:10:20 +0000
@@ -1,6 +1,7 @@
 #
 # GRX test programs makefile for SDL. Uses GNU make.
 #
+.SUFFIXES: .exe
 .PHONY : clean
 
 GRXVSDL=y
diff -uprN grx249.orig/test/makefile.w32 grx249.macosx/test/makefile.w32
--- grx249.orig/test/makefile.w32	2012-07-07 14:19:08 +0000
+++ grx249.macosx/test/makefile.w32	2012-11-11 18:56:00 +0000
@@ -3,7 +3,7 @@
 # Uses GNU make.
 #
 .SUFFIXES: .exe
-.PHONY: clean install uninstall
+.PHONY: clean
 
 GRXVW32=y
 
diff -uprN grx249.orig/test/makefile.x11 grx249.macosx/test/makefile.x11
--- grx249.orig/test/makefile.x11	2012-07-07 14:17:58 +0000
+++ grx249.macosx/test/makefile.x11	2012-11-11 16:21:56 +0000
@@ -9,10 +9,12 @@ include ../makedefs.grx
 
 INCDIR=  -I../include
 
+GRXLIB = ../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+
 # Enable this line for static linked test progs (default)
-GRX20X = ../lib/$(GRX_LIB_SUBDIR)/libgrx20X.a
+LIBS = $(GRXLIB)
 # or this if you've already installed the shared libs
-#GRX20X = -L../lib/$(GRX_LIB_SUBDIR) -lgrx20X
+#LIBS = -lgrx20X
 
 ifeq ($(SET_XSUIDROOT),y)
 EXECBITS = 4755
@@ -42,7 +44,7 @@ ifeq ($(NEED_ZLIB),y)
   ADDON_LIBS += -lz
 endif
 
-LIBS= $(GRX20X) $(ADDON_LIBS) $(X11LIBS) -lm
+LIBS += $(ADDON_LIBS) $(X11LIBS) -lm
 
 PROGS=  xarctest     \
 	xbb1test     \
@@ -74,11 +76,11 @@ PROGS=  xarctest     \
 
 all: $(PROGS) xdemogrx
 
-xdemogrx: demogrx.o gfaz.o $(GRX20X)
+xdemogrx: demogrx.o gfaz.o $(GRXLIB)
 	$(CC) $(LDOPT) -o xdemogrx demogrx.o gfaz.o $(LIBS)
 	chmod $(EXECBITS) xdemogrx
 
-$(PROGS): x%: %.o $(GRX20X)
+$(PROGS): x%: %.o $(GRXLIB)
 	$(CC) $(LDOPT) -o $@ $*.o $(LIBS)
 	chmod $(EXECBITS) $@
 
diff -uprN grx249.orig/test/speedtst.c grx249.macosx/test/speedtst.c
--- grx249.orig/test/speedtst.c	2012-07-07 14:21:56 +0000
+++ grx249.macosx/test/speedtst.c	2012-11-04 23:06:14 +0000
@@ -25,12 +25,18 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <assert.h>
+
 #ifdef __WATCOMC__
 /*#include <wcdefs.h>*/
 #include <conio.h>
 #else
+#if defined(__APPLE__) && defined(__MACH__)
+#include <limits.h>
+#else
 #include <values.h>
 #endif
+#endif
+
 #include <math.h>
 #include "rand.h"
 
