From 9f6a47087b28fc230e804da404798acb9641cb4e Mon Sep 17 00:00:00 2001
From: dscho <dscho>
Date: Sat, 8 Feb 2003 14:26:39 +0000
Subject: autoconf'ed everything

---
 Makefile             | 738 ++++++++++++++++++++++++++++++++++++++++++++++-----
 Makefile.am          |  21 ++
 TODO                 |   9 +-
 bootstrap.sh         |   5 +
 configure.ac         |  88 ++++++
 contrib/Makefile     | 354 ++++++++++++++++++++++--
 contrib/Makefile.am  |  10 +
 examples/Makefile    | 395 ++++++++++++++++++++++++---
 examples/Makefile.am |   6 +
 examples/example.c   |  10 +-
 include/rfb.h        |  33 ++-
 include/rfbproto.h   |   6 +-
 main.c               |   8 +-
 rfbserver.c          |  32 ++-
 sockets.c            |   2 +-
 tight.c              |   5 +
 zlib.c               |   4 +-
 zrle.cc              | 180 -------------
 zrle.cxx             | 180 +++++++++++++
 19 files changed, 1752 insertions(+), 334 deletions(-)
 create mode 100644 Makefile.am
 create mode 100644 bootstrap.sh
 create mode 100644 configure.ac
 create mode 100644 contrib/Makefile.am
 create mode 100644 examples/Makefile.am
 delete mode 100644 zrle.cc
 create mode 100644 zrle.cxx

diff --git a/Makefile b/Makefile
index 1f403f5..80869cf 100644
--- a/Makefile
+++ b/Makefile
@@ -1,92 +1,704 @@
-INCLUDES=-I. -Iinclude
-VNCSERVERLIB=-L. -lvncserver -L/usr/local/lib -lz -ljpeg
+# Makefile.in generated by automake 1.6.3 from Makefile.am.
+# Makefile.  Generated from Makefile.in by configure.
 
-#CXX=
-CXX=g++
-CC=gcc
-LINK=gcc
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
 
-# for IRIX
-#EXTRALIBS=-L/usr/lib32
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
 
-# for Solaris
-#EXTRALIBS=-lsocket -lnsl -L/usr/X/lib
 
-# for FreeBSD
-#EXTRAINCLUDES=-I/usr/X11R6/include
+SHELL = /bin/sh
 
-# Uncomment these two lines to enable use of PThreads
-#PTHREADLIB = -lpthread
+srcdir = .
+top_srcdir = .
 
-# Comment the following line to disable the use of 3 Bytes/Pixel.
-# The code for 3 Bytes/Pixel is not very efficient!
+prefix = /usr/local
+exec_prefix = ${prefix}
 
-OPTFLAGS=-g -Wall -pedantic
-#OPTFLAGS=-O2 -Wall
-RANLIB=ranlib
+bindir = ${exec_prefix}/bin
+sbindir = ${exec_prefix}/sbin
+libexecdir = ${exec_prefix}/libexec
+datadir = ${prefix}/share
+sysconfdir = ${prefix}/etc
+sharedstatedir = ${prefix}/com
+localstatedir = ${prefix}/var
+libdir = ${exec_prefix}/lib
+infodir = ${prefix}/info
+mandir = ${prefix}/man
+includedir = ${prefix}/include
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/libvncserver
+pkglibdir = $(libdir)/libvncserver
+pkgincludedir = $(includedir)/libvncserver
+top_builddir = .
 
-# for Mac OS X
-OSX_LIBS = -framework ApplicationServices -framework Carbon -framework IOKit
+ACLOCAL = ${SHELL} /my/libvncserver/missing --run aclocal-1.6
+AUTOCONF = ${SHELL} /my/libvncserver/missing --run autoconf
+AUTOMAKE = ${SHELL} /my/libvncserver/missing --run automake-1.6
+AUTOHEADER = ${SHELL} /my/libvncserver/missing --run autoheader
 
-ifdef CXX
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = /usr/bin/install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_SCRIPT = ${INSTALL}
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = s,x,x,
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
 
-ZRLE_SRCS=zrle.cc rdr/FdInStream.cxx rdr/FdOutStream.cxx rdr/InStream.cxx \
-	rdr/NullOutStream.cxx rdr/ZlibInStream.cxx rdr/ZlibOutStream.cxx
-ZRLE_OBJS=zrle.o rdr/FdInStream.o rdr/FdOutStream.o rdr/InStream.o \
-	rdr/NullOutStream.o rdr/ZlibInStream.o rdr/ZlibOutStream.o
-ZRLE_DEF=-DHAVE_ZRLE
-LINK=$(CXX)
+EXEEXT = 
+OBJEXT = o
+PATH_SEPARATOR = :
+AMTAR = ${SHELL} /my/libvncserver/missing --run tar
+AWK = gawk
+CC = gcc
+CCLD = g++
+CXX = g++
+DEPDIR = .deps
+INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
+PACKAGE = libvncserver
+RANLIB = ranlib
+STRIP = 
+VERSION = 0.5
+X_CFLAGS =  -I/usr/X11R6/include
+X_EXTRA_LIBS = 
+X_LIBS =  -L/usr/X11R6/lib  -lX11  -lXext -lXtst
+X_PRE_LIBS =  -lSM -lICE
+am__include = include
+am__quote = 
+install_sh = /my/libvncserver/install-sh
+SUBDIRS = . examples contrib
+DIST_SUBDIRS = examples contrib
+
+include_HEADERS = include/rfb.h include/rfbconfig.h include/rfbproto.h \
+	include/keysym.h
 
-%.o: %.cxx
-	$(CXX) $(CXXFLAGS) -c -o $@ $<
 
-endif
+ZRLE_SRCS = zrle.cxx rdr/FdInStream.cxx rdr/FdOutStream.cxx rdr/InStream.cxx \
+	rdr/NullOutStream.cxx rdr/ZlibInStream.cxx rdr/ZlibOutStream.cxx
 
-CFLAGS=$(OPTFLAGS) $(INCLUDES) $(EXTRAINCLUDES)
-CXXFLAGS=$(OPTFLAGS) $(INCLUDES) $(EXTRAINCLUDES)
-LIBS=$(LDFLAGS) $(VNCSERVERLIB) $(PTHREADLIB) $(EXTRALIBS)
 
-SOURCES=main.c rfbserver.c sraRegion.c auth.c sockets.c \
+LIB_SOURCES = main.c rfbserver.c sraRegion.c auth.c sockets.c \
 	stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
 	zlib.c tight.c httpd.c cursor.c font.c \
-	draw.c selbox.c d3des.c vncauth.c cargs.c $(ZRLE_SRCS)
-OBJS=main.o rfbserver.o sraRegion.o auth.o sockets.o \
-	stats.o corre.o hextile.o rre.o translate.o cutpaste.o \
-	zlib.o tight.o httpd.o cursor.o font.o \
-	draw.o selbox.o d3des.o vncauth.o cargs.o $(ZRLE_OBJS)
-INSTALLHEADER=rfb.h rfbproto.h sraRegion.h keysym.h
+	draw.c selbox.c d3des.c vncauth.c cargs.c
+
+
+libvncserver_a_SOURCES = $(LIB_SOURCES) $(ZRLE_SRCS)
+#libvncserver_a_SOURCES = $(LIB_SOURCES)
+
+lib_LIBRARIES = libvncserver.a
+subdir = .
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/include/rfbconfig.h
+CONFIG_CLEAN_FILES = libvncserver.spec
+LIBRARIES = $(lib_LIBRARIES)
+
+libvncserver_a_AR = $(AR) cru
+libvncserver_a_LIBADD =
+am__objects_1 = main.$(OBJEXT) rfbserver.$(OBJEXT) sraRegion.$(OBJEXT) \
+	auth.$(OBJEXT) sockets.$(OBJEXT) stats.$(OBJEXT) \
+	corre.$(OBJEXT) hextile.$(OBJEXT) rre.$(OBJEXT) \
+	translate.$(OBJEXT) cutpaste.$(OBJEXT) zlib.$(OBJEXT) \
+	tight.$(OBJEXT) httpd.$(OBJEXT) cursor.$(OBJEXT) font.$(OBJEXT) \
+	draw.$(OBJEXT) selbox.$(OBJEXT) d3des.$(OBJEXT) \
+	vncauth.$(OBJEXT) cargs.$(OBJEXT)
+am__objects_2 = zrle.$(OBJEXT) FdInStream.$(OBJEXT) \
+	FdOutStream.$(OBJEXT) InStream.$(OBJEXT) \
+	NullOutStream.$(OBJEXT) ZlibInStream.$(OBJEXT) \
+	ZlibOutStream.$(OBJEXT)
+am_libvncserver_a_OBJECTS = $(am__objects_1) \
+	$(am__objects_2)
+#am_libvncserver_a_OBJECTS = $(am__objects_1)
+libvncserver_a_OBJECTS = $(am_libvncserver_a_OBJECTS)
+
+DEFS = -DHAVE_CONFIG_H
+DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/include
+CPPFLAGS = 
+LDFLAGS = 
+LIBS = -L.. -lvncserver -lz -lpthread -ljpeg 
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+DEP_FILES = ./$(DEPDIR)/FdInStream.Po \
+	./$(DEPDIR)/FdOutStream.Po ./$(DEPDIR)/InStream.Po \
+	./$(DEPDIR)/NullOutStream.Po \
+	./$(DEPDIR)/ZlibInStream.Po \
+	./$(DEPDIR)/ZlibOutStream.Po ./$(DEPDIR)/auth.Po \
+	./$(DEPDIR)/cargs.Po ./$(DEPDIR)/corre.Po \
+	./$(DEPDIR)/cursor.Po ./$(DEPDIR)/cutpaste.Po \
+	./$(DEPDIR)/d3des.Po ./$(DEPDIR)/draw.Po \
+	./$(DEPDIR)/font.Po ./$(DEPDIR)/hextile.Po \
+	./$(DEPDIR)/httpd.Po ./$(DEPDIR)/main.Po \
+	./$(DEPDIR)/rfbserver.Po ./$(DEPDIR)/rre.Po \
+	./$(DEPDIR)/selbox.Po ./$(DEPDIR)/sockets.Po \
+	./$(DEPDIR)/sraRegion.Po ./$(DEPDIR)/stats.Po \
+	./$(DEPDIR)/tight.Po ./$(DEPDIR)/translate.Po \
+	./$(DEPDIR)/vncauth.Po ./$(DEPDIR)/zlib.Po \
+	./$(DEPDIR)/zrle.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+CFLAGS = -g -O2
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+CXXLD = $(CXX)
+CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+	-o $@
+CXXFLAGS = -g -O2
+DIST_SOURCES = $(libvncserver_a_SOURCES)
+HEADERS = $(include_HEADERS)
+
+
+RECURSIVE_TARGETS = info-recursive dvi-recursive install-info-recursive \
+	uninstall-info-recursive all-recursive install-data-recursive \
+	install-exec-recursive installdirs-recursive install-recursive \
+	uninstall-recursive check-recursive installcheck-recursive
+DIST_COMMON = README $(include_HEADERS) ./include/rfbconfig.h.in \
+	AUTHORS COPYING ChangeLog INSTALL Makefile.am Makefile.in NEWS \
+	TODO aclocal.m4 configure configure.ac depcomp install-sh \
+	libvncserver.spec.in missing mkinstalldirs
+SOURCES = $(libvncserver_a_SOURCES)
+
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .cxx .o .obj
+
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno
+$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
+	cd $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu  Makefile
+Makefile:  $(srcdir)/Makefile.in  $(top_builddir)/config.status
+	cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)
+
+$(top_builddir)/config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	$(SHELL) ./config.status --recheck
+$(srcdir)/configure:  $(srcdir)/configure.ac $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
+	cd $(srcdir) && $(AUTOCONF)
+
+$(ACLOCAL_M4):  configure.ac 
+	cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+
+include/rfbconfig.h: include/stamp-h1
+	@if test ! -f $@; then \
+	  rm -f include/stamp-h1; \
+	  $(MAKE) include/stamp-h1; \
+	else :; fi
+
+include/stamp-h1: $(srcdir)/./include/rfbconfig.h.in $(top_builddir)/config.status
+	@rm -f include/stamp-h1
+	cd $(top_builddir) && $(SHELL) ./config.status include/rfbconfig.h
+
+$(srcdir)/./include/rfbconfig.h.in:  $(top_srcdir)/configure.ac $(ACLOCAL_M4) 
+	cd $(top_srcdir) && $(AUTOHEADER)
+	touch $(srcdir)/./include/rfbconfig.h.in
 
-all: libvncserver.a all_examples
+distclean-hdr:
+	-rm -f include/rfbconfig.h include/stamp-h1
+libvncserver.spec: $(top_builddir)/config.status libvncserver.spec.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
 
-all_examples:
-	cd examples && make
+AR = ar
+libLIBRARIES_INSTALL = $(INSTALL_DATA)
+install-libLIBRARIES: $(lib_LIBRARIES)
+	@$(NORMAL_INSTALL)
+	$(mkinstalldirs) $(DESTDIR)$(libdir)
+	@list='$(lib_LIBRARIES)'; for p in $$list; do \
+	  if test -f $$p; then \
+	    f="`echo $$p | sed -e 's|^.*/||'`"; \
+	    echo " $(libLIBRARIES_INSTALL) $$p $(DESTDIR)$(libdir)/$$f"; \
+	    $(libLIBRARIES_INSTALL) $$p $(DESTDIR)$(libdir)/$$f; \
+	  else :; fi; \
+	done
+	@$(POST_INSTALL)
+	@list='$(lib_LIBRARIES)'; for p in $$list; do \
+	  if test -f $$p; then \
+	    p="`echo $$p | sed -e 's|^.*/||'`"; \
+	    echo " $(RANLIB) $(DESTDIR)$(libdir)/$$p"; \
+	    $(RANLIB) $(DESTDIR)$(libdir)/$$p; \
+	  else :; fi; \
+	done
 
-all_contrib:
-	cd contrib && make
+uninstall-libLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(lib_LIBRARIES)'; for p in $$list; do \
+	  p="`echo $$p | sed -e 's|^.*/||'`"; \
+	  echo " rm -f $(DESTDIR)$(libdir)/$$p"; \
+	  rm -f $(DESTDIR)$(libdir)/$$p; \
+	done
 
-install_OSX: OSXvnc-server
-	cp OSXvnc-server storepasswd ../OSXvnc/build/OSXvnc.app/Contents/MacOS
+clean-libLIBRARIES:
+	-test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
+FdInStream.$(OBJEXT): rdr/FdInStream.cxx
+FdOutStream.$(OBJEXT): rdr/FdOutStream.cxx
+InStream.$(OBJEXT): rdr/InStream.cxx
+NullOutStream.$(OBJEXT): rdr/NullOutStream.cxx
+ZlibInStream.$(OBJEXT): rdr/ZlibInStream.cxx
+ZlibOutStream.$(OBJEXT): rdr/ZlibOutStream.cxx
+libvncserver.a: $(libvncserver_a_OBJECTS) $(libvncserver_a_DEPENDENCIES) 
+	-rm -f libvncserver.a
+	$(libvncserver_a_AR) libvncserver.a $(libvncserver_a_OBJECTS) $(libvncserver_a_LIBADD)
+	$(RANLIB) libvncserver.a
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT) core *.core
+
+distclean-compile:
+	-rm -f *.tab.c
+
+include ./$(DEPDIR)/FdInStream.Po
+include ./$(DEPDIR)/FdOutStream.Po
+include ./$(DEPDIR)/InStream.Po
+include ./$(DEPDIR)/NullOutStream.Po
+include ./$(DEPDIR)/ZlibInStream.Po
+include ./$(DEPDIR)/ZlibOutStream.Po
+include ./$(DEPDIR)/auth.Po
+include ./$(DEPDIR)/cargs.Po
+include ./$(DEPDIR)/corre.Po
+include ./$(DEPDIR)/cursor.Po
+include ./$(DEPDIR)/cutpaste.Po
+include ./$(DEPDIR)/d3des.Po
+include ./$(DEPDIR)/draw.Po
+include ./$(DEPDIR)/font.Po
+include ./$(DEPDIR)/hextile.Po
+include ./$(DEPDIR)/httpd.Po
+include ./$(DEPDIR)/main.Po
+include ./$(DEPDIR)/rfbserver.Po
+include ./$(DEPDIR)/rre.Po
+include ./$(DEPDIR)/selbox.Po
+include ./$(DEPDIR)/sockets.Po
+include ./$(DEPDIR)/sraRegion.Po
+include ./$(DEPDIR)/stats.Po
+include ./$(DEPDIR)/tight.Po
+include ./$(DEPDIR)/translate.Po
+include ./$(DEPDIR)/vncauth.Po
+include ./$(DEPDIR)/zlib.Po
+include ./$(DEPDIR)/zrle.Po
+
+distclean-depend:
+	-rm -rf ./$(DEPDIR)
 
 .c.o:
-	$(CC) $(CFLAGS) -c $<
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CCDEPMODE) $(depcomp) \
+	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+
+.c.obj:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CCDEPMODE) $(depcomp) \
+	$(COMPILE) -c `cygpath -w $<`
+CCDEPMODE = depmode=gcc3
+
+.cxx.o:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXXCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
+
+.cxx.obj:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXXCOMPILE) -c -o $@ `cygpath -w $<`
+
+FdInStream.o: rdr/FdInStream.cxx
+	source='rdr/FdInStream.cxx' object='FdInStream.o' libtool=no \
+	depfile='$(DEPDIR)/FdInStream.Po' tmpdepfile='$(DEPDIR)/FdInStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o FdInStream.o `test -f 'rdr/FdInStream.cxx' || echo '$(srcdir)/'`rdr/FdInStream.cxx
+
+FdInStream.obj: rdr/FdInStream.cxx
+	source='rdr/FdInStream.cxx' object='FdInStream.obj' libtool=no \
+	depfile='$(DEPDIR)/FdInStream.Po' tmpdepfile='$(DEPDIR)/FdInStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o FdInStream.obj `cygpath -w rdr/FdInStream.cxx`
+
+FdOutStream.o: rdr/FdOutStream.cxx
+	source='rdr/FdOutStream.cxx' object='FdOutStream.o' libtool=no \
+	depfile='$(DEPDIR)/FdOutStream.Po' tmpdepfile='$(DEPDIR)/FdOutStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o FdOutStream.o `test -f 'rdr/FdOutStream.cxx' || echo '$(srcdir)/'`rdr/FdOutStream.cxx
+
+FdOutStream.obj: rdr/FdOutStream.cxx
+	source='rdr/FdOutStream.cxx' object='FdOutStream.obj' libtool=no \
+	depfile='$(DEPDIR)/FdOutStream.Po' tmpdepfile='$(DEPDIR)/FdOutStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o FdOutStream.obj `cygpath -w rdr/FdOutStream.cxx`
+
+InStream.o: rdr/InStream.cxx
+	source='rdr/InStream.cxx' object='InStream.o' libtool=no \
+	depfile='$(DEPDIR)/InStream.Po' tmpdepfile='$(DEPDIR)/InStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o InStream.o `test -f 'rdr/InStream.cxx' || echo '$(srcdir)/'`rdr/InStream.cxx
+
+InStream.obj: rdr/InStream.cxx
+	source='rdr/InStream.cxx' object='InStream.obj' libtool=no \
+	depfile='$(DEPDIR)/InStream.Po' tmpdepfile='$(DEPDIR)/InStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o InStream.obj `cygpath -w rdr/InStream.cxx`
+
+NullOutStream.o: rdr/NullOutStream.cxx
+	source='rdr/NullOutStream.cxx' object='NullOutStream.o' libtool=no \
+	depfile='$(DEPDIR)/NullOutStream.Po' tmpdepfile='$(DEPDIR)/NullOutStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o NullOutStream.o `test -f 'rdr/NullOutStream.cxx' || echo '$(srcdir)/'`rdr/NullOutStream.cxx
+
+NullOutStream.obj: rdr/NullOutStream.cxx
+	source='rdr/NullOutStream.cxx' object='NullOutStream.obj' libtool=no \
+	depfile='$(DEPDIR)/NullOutStream.Po' tmpdepfile='$(DEPDIR)/NullOutStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o NullOutStream.obj `cygpath -w rdr/NullOutStream.cxx`
+
+ZlibInStream.o: rdr/ZlibInStream.cxx
+	source='rdr/ZlibInStream.cxx' object='ZlibInStream.o' libtool=no \
+	depfile='$(DEPDIR)/ZlibInStream.Po' tmpdepfile='$(DEPDIR)/ZlibInStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ZlibInStream.o `test -f 'rdr/ZlibInStream.cxx' || echo '$(srcdir)/'`rdr/ZlibInStream.cxx
+
+ZlibInStream.obj: rdr/ZlibInStream.cxx
+	source='rdr/ZlibInStream.cxx' object='ZlibInStream.obj' libtool=no \
+	depfile='$(DEPDIR)/ZlibInStream.Po' tmpdepfile='$(DEPDIR)/ZlibInStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ZlibInStream.obj `cygpath -w rdr/ZlibInStream.cxx`
+
+ZlibOutStream.o: rdr/ZlibOutStream.cxx
+	source='rdr/ZlibOutStream.cxx' object='ZlibOutStream.o' libtool=no \
+	depfile='$(DEPDIR)/ZlibOutStream.Po' tmpdepfile='$(DEPDIR)/ZlibOutStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ZlibOutStream.o `test -f 'rdr/ZlibOutStream.cxx' || echo '$(srcdir)/'`rdr/ZlibOutStream.cxx
+
+ZlibOutStream.obj: rdr/ZlibOutStream.cxx
+	source='rdr/ZlibOutStream.cxx' object='ZlibOutStream.obj' libtool=no \
+	depfile='$(DEPDIR)/ZlibOutStream.Po' tmpdepfile='$(DEPDIR)/ZlibOutStream.TPo' \
+	$(CXXDEPMODE) $(depcomp) \
+	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o ZlibOutStream.obj `cygpath -w rdr/ZlibOutStream.cxx`
+CXXDEPMODE = depmode=gcc3
+uninstall-info-am:
+includeHEADERS_INSTALL = $(INSTALL_HEADER)
+install-includeHEADERS: $(include_HEADERS)
+	@$(NORMAL_INSTALL)
+	$(mkinstalldirs) $(DESTDIR)$(includedir)
+	@list='$(include_HEADERS)'; for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  f="`echo $$p | sed -e 's|^.*/||'`"; \
+	  echo " $(includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(includedir)/$$f"; \
+	  $(includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(includedir)/$$f; \
+	done
+
+uninstall-includeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(include_HEADERS)'; for p in $$list; do \
+	  f="`echo $$p | sed -e 's|^.*/||'`"; \
+	  echo " rm -f $(DESTDIR)$(includedir)/$$f"; \
+	  rm -f $(DESTDIR)$(includedir)/$$f; \
+	done
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@set fnord $$MAKEFLAGS; amf=$$2; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+mostlyclean-recursive clean-recursive distclean-recursive \
+maintainer-clean-recursive:
+	@set fnord $$MAKEFLAGS; amf=$$2; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+
+ETAGS = etags
+ETAGSFLAGS =
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	mkid -fID $$unique
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(ETAGS_ARGS)$$tags$$unique" \
+	  || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	     $$tags $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && cd $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = .
+distdir = $(PACKAGE)-$(VERSION)
+
+am__remove_distdir = \
+  { test ! -d $(distdir) \
+    || { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
+         && rm -fr $(distdir); }; }
+
+GZIP_ENV = --best
+distcleancheck_listfiles = find . -type f -print
+
+distdir: $(DISTFILES)
+	$(am__remove_distdir)
+	mkdir $(distdir)
+	$(mkinstalldirs) $(distdir)/. $(distdir)/./include $(distdir)/include
+	@list='$(DISTFILES)'; for file in $$list; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+	    dir="/$$dir"; \
+	    $(mkinstalldirs) "$(distdir)$$dir"; \
+	  else \
+	    dir=''; \
+	  fi; \
+	  if test -d $$d/$$file; then \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+	    fi; \
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || cp -p $$d/$$file $(distdir)/$$file \
+	    || exit 1; \
+	  fi; \
+	done
+	list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d $(distdir)/$$subdir \
+	    || mkdir $(distdir)/$$subdir \
+	    || exit 1; \
+	    (cd $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$(top_distdir)" \
+	        distdir=../$(distdir)/$$subdir \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+	-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
+	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
+	|| chmod -R a+r $(distdir)
+dist-gzip: distdir
+	$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+dist dist-all: distdir
+	$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+	$(am__remove_distdir)
+	GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf -
+	chmod -R a-w $(distdir); chmod a+w $(distdir)
+	mkdir $(distdir)/=build
+	mkdir $(distdir)/=inst
+	chmod a-w $(distdir)
+	dc_install_base=`$(am__cd) $(distdir)/=inst && pwd` \
+	  && cd $(distdir)/=build \
+	  && ../configure --srcdir=.. --prefix=$$dc_install_base \
+	    $(DISTCHECK_CONFIGURE_FLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) check \
+	  && $(MAKE) $(AM_MAKEFLAGS) install \
+	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+	  && (test `find $$dc_install_base -type f -print | wc -l` -le 1 \
+	      || { echo "ERROR: files left after uninstall:" ; \
+	           find $$dc_install_base -type f -print ; \
+	           exit 1; } >&2 ) \
+	  && $(MAKE) $(AM_MAKEFLAGS) dist-gzip \
+	  && rm -f $(distdir).tar.gz \
+	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck
+	$(am__remove_distdir)
+	@echo "$(distdir).tar.gz is ready for distribution" | \
+	  sed 'h;s/./=/g;p;x;p;x'
+distcleancheck: distclean
+	if test '$(srcdir)' = . ; then \
+	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+	  exit 1 ; \
+	fi
+	test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+	  || { echo "ERROR: files left after distclean:" ; \
+	       $(distcleancheck_listfiles) ; \
+	       exit 1; } >&2
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+installdirs: installdirs-recursive
+installdirs-am:
+	$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
+
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-rm -f Makefile $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libLIBRARIES mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+distclean-am: clean-am distclean-compile distclean-depend \
+	distclean-generic distclean-hdr distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-includeHEADERS
+
+install-exec-am: install-libLIBRARIES
+
+install-info: install-info-recursive
+
+install-man:
+
+installcheck-am:
 
-$(OBJS): Makefile include/rfb.h
+maintainer-clean: maintainer-clean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -rf autom4te.cache
+maintainer-clean-am: distclean-am maintainer-clean-generic
 
-libvncserver.a: $(OBJS)
-	$(AR) cru $@ $(OBJS)
-	$(RANLIB) $@
+mostlyclean: mostlyclean-recursive
 
-translate.o: translate.c tableinit24.c tableinitcmtemplate.c tableinittctemplate.c tabletrans24template.c tabletranstemplate.c
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
 
-clean:
-	rm -f $(OBJS) *~ core "#"* *.bak *.orig
-	cd examples && make clean
-	cd contrib && make clean
+uninstall-am: uninstall-includeHEADERS uninstall-info-am \
+	uninstall-libLIBRARIES
 
-realclean: clean
-	rm -f OSXvnc-server storepasswd example pnmshow libvncserver.a
+uninstall-info: uninstall-info-recursive
 
-depend:
-	$(CC) -M $(INCLUDES) $(SOURCES) >.depend
+.PHONY: $(RECURSIVE_TARGETS) GTAGS all all-am check check-am clean \
+	clean-generic clean-libLIBRARIES clean-recursive dist dist-all \
+	dist-gzip distcheck distclean distclean-compile \
+	distclean-depend distclean-generic distclean-hdr \
+	distclean-recursive distclean-tags distcleancheck distdir dvi \
+	dvi-am dvi-recursive info info-am info-recursive install \
+	install-am install-data install-data-am install-data-recursive \
+	install-exec install-exec-am install-exec-recursive \
+	install-includeHEADERS install-info install-info-am \
+	install-info-recursive install-libLIBRARIES install-man \
+	install-recursive install-strip installcheck installcheck-am \
+	installdirs installdirs-am installdirs-recursive \
+	maintainer-clean maintainer-clean-generic \
+	maintainer-clean-recursive mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-recursive tags tags-recursive \
+	uninstall uninstall-am uninstall-includeHEADERS \
+	uninstall-info-am uninstall-info-recursive \
+	uninstall-libLIBRARIES uninstall-recursive
 
-#include .depend
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..9a52747
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,21 @@
+SUBDIRS=. examples contrib
+DIST_SUBDIRS=examples contrib
+
+include_HEADERS=include/rfb.h include/rfbconfig.h include/rfbproto.h \
+	include/keysym.h
+
+ZRLE_SRCS=zrle.cxx rdr/FdInStream.cxx rdr/FdOutStream.cxx rdr/InStream.cxx \
+	rdr/NullOutStream.cxx rdr/ZlibInStream.cxx rdr/ZlibOutStream.cxx
+
+LIB_SOURCES = main.c rfbserver.c sraRegion.c auth.c sockets.c \
+	stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
+	zlib.c tight.c httpd.c cursor.c font.c \
+	draw.c selbox.c d3des.c vncauth.c cargs.c
+
+if HAVE_CXX
+libvncserver_a_SOURCES=$(LIB_SOURCES) $(ZRLE_SRCS)
+else
+libvncserver_a_SOURCES=$(LIB_SOURCES)
+endif
+
+lib_LIBRARIES=libvncserver.a
diff --git a/TODO b/TODO
index 70dae90..e84b197 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,7 @@
 immediate:
 ----------
 
-x11vnc: clipboard, cursor, updates interruptible by input (doesn't work yet)
+x11vnc: clipboard, cursor
 extra_bytes in rfbDrawCharWithClip.
 tested mouse buttons make copy rect, but text is not marked as mod.
 cursor drawing: set optional grain to mark bigger rectangles as drawn (else
@@ -18,16 +18,15 @@ later:
 authentification schemes (secure vnc)
 	IO function ptr exists; now explain how to tunnel and implement a
 	client address restriction scheme.
-autoconf? at least Sun Solaris and Windows compilation
-	(maybe Michael makes a small autconf)
 using Hermes library for fast colour translations.
 CORBA
-internal HTTP tunnelling feature (needs a special GET target and a few
-	changes to java applet).
 
 done:
 -----
 
+.autoconf
+.internal HTTP tunnelling feature (needs a special GET target and a few
+.	changes to java applet).
 .x11vnc: sometimes XTest fails (but doesn't with x0rfbserver)
 .DeferUpdateTime (timing problems!)
 .empty cursor sending doesn't work.
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100644
index 0000000..5e1caa5
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+aclocal && automake && autoconf && ./configure && make
+
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..822e5ef
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,88 @@
+# Process this file with autoconf to produce a configure script.
+AC_INIT(LibVNCServer, 0.5, http://sourceforge.net/projects/libvncserver)
+AM_INIT_AUTOMAKE
+AM_CONFIG_HEADER([include/rfbconfig.h])
+
+# Checks for programs.
+AC_PROG_CC
+CCLD=$CC
+AC_PROG_MAKE_SET
+AC_PROG_RANLIB
+
+# Options
+AH_TEMPLATE(BACKCHANNEL, [Enable BackChannel communication])
+AC_ARG_WITH(backchannel,
+	[  --without-backchannel		disable backchannel method],
+	,AC_DEFINE(BACKCHANNEL))
+AH_TEMPLATE(ALLOW24BPP, [Enable 24 bit per pixel in native framebuffer])
+AC_ARG_WITH(24bpp,
+	[ --without-24bpp			disable 24 bpp framebuffers],
+	,AC_DEFINE(ALLOW24BPP))
+
+# Checks for X libraries
+HAVE_X="false"
+AC_PATH_XTRA
+if test "$X_CFLAGS" != "-DX_DISPLAY_MISSING"; then
+	AC_CHECK_LIB(Xtst, XTestFakeKeyEvent, HAVE_XTEST="true",
+		HAVE_XTEST="false",
+		$X_LIBS $X_PRELIBS -lX11 -lXext $X_EXTRA_LIBS)
+	if test $HAVE_XTEST = "true"; then
+		X_LIBS="$X_LIBS $X_PRELIBS -lX11 $X_EXTRA_LIBS -lXext -lXtst"
+		HAVE_X="true"
+	fi
+fi
+AC_SUBST(X_LIBS)
+AM_CONDITIONAL(HAVE_X, test $HAVE_X != "false")
+
+# Checks for libraries.
+AC_CHECK_HEADERS(jpeglib.h pthread.h zlib.h)
+if test ! -z "$HAVE_JPEGLIB.H"; then
+	AC_CHECK_LIB(jpeg, jpeg_CreateCompress)
+fi
+AM_CONDITIONAL(HAVE_LIBPTHREAD, test ! -z "$HAVE_PTHREAD.H")
+if test ! -z "$HAVE_PTHREAD.H"; then
+	AC_CHECK_LIB(pthread, pthread_mutex_lock)
+fi
+if test ! -z "$HAVE_ZLIB.H"; then
+	AC_CHECK_LIB(z, deflate)
+	# check for c++, but don't fail if not found
+	AC_CHECK_PROGS(CXX,[g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],none)
+	AH_TEMPLATE(HAVE_ZRLE, [Use zrle compression; needs a c++ compiler])
+	if test x$CXX != xnone; then
+		AC_DEFINE(HAVE_ZRLE)
+		AC_PROG_CXX
+		CCLD=$CXX
+	fi
+else
+	CXX=none
+fi
+AM_CONDITIONAL(HAVE_CXX, test x$CXX != xnone)
+AC_SUBST(CCLD)
+
+VNCLIBS="-L.. -lvncserver"
+
+LIBS="$VNCLIBS $LIBS"
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h sys/timeb.h syslog.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_C_INLINE
+AC_TYPE_SIZE_T
+AC_HEADER_TIME
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_FUNC_MEMCMP
+AC_FUNC_STAT
+AC_FUNC_STRFTIME
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS([ftime gethostbyname gethostname gettimeofday inet_ntoa memmove memset mkfifo select socket strchr strcspn strdup strerror strstr])
+
+AC_CONFIG_FILES([Makefile
+                 contrib/Makefile
+                 examples/Makefile
+		 libvncserver.spec])
+AC_OUTPUT
diff --git a/contrib/Makefile b/contrib/Makefile
index 8faa4b7..2cdc143 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -1,30 +1,340 @@
-CFLAGS=-I. -I../include
-VNCSERVERLIB=-L.. -lvncserver -L/usr/local/lib -lz -ljpeg -lpthread
-LDFLAGS=$(VNCSERVERLIB)
-ifdef CXX
-LINK=$(CXX)
-else
-LINK=$(CC)
-endif
+# Makefile.in generated by automake 1.6.3 from Makefile.am.
+# contrib/Makefile.  Generated from Makefile.in by configure.
 
-# for x11vnc
-#XLIBS =  -L/usr/X11R6/lib -lXtst -lXext -lX11
-XLIBS =  -L/usr/X11R6/lib -L/usr/lib32 -lXtst -lXext -lX11
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
 
-OBJS=*.o
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
 
-all: x11vnc zippy
 
-x11vnc.o: x11vnc.c ../include/rfb.h ../examples/1instance.c Makefile
-	$(CC) $(CFLAGS) -I. -c -o x11vnc.o x11vnc.c
+SHELL = /bin/sh
 
-x11vnc: x11vnc.o ../libvncserver.a
-	$(LINK) -g -o x11vnc x11vnc.o $(LDFLAGS) $(XLIBS)
+srcdir = .
+top_srcdir = ..
 
-# Example from Justin
-zippy: zippy.o ../libvncserver.a
-	$(LINK) -o zippy zippy.o $(LDFLAGS)
+prefix = /usr/local
+exec_prefix = ${prefix}
 
-clean:
-	rm -f $(OBJS) *~ core "#"* *.bak *.orig
+bindir = ${exec_prefix}/bin
+sbindir = ${exec_prefix}/sbin
+libexecdir = ${exec_prefix}/libexec
+datadir = ${prefix}/share
+sysconfdir = ${prefix}/etc
+sharedstatedir = ${prefix}/com
+localstatedir = ${prefix}/var
+libdir = ${exec_prefix}/lib
+infodir = ${prefix}/info
+mandir = ${prefix}/man
+includedir = ${prefix}/include
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/libvncserver
+pkglibdir = $(libdir)/libvncserver
+pkgincludedir = $(includedir)/libvncserver
+top_builddir = ..
 
+ACLOCAL = ${SHELL} /my/libvncserver/missing --run aclocal-1.6
+AUTOCONF = ${SHELL} /my/libvncserver/missing --run autoconf
+AUTOMAKE = ${SHELL} /my/libvncserver/missing --run automake-1.6
+AUTOHEADER = ${SHELL} /my/libvncserver/missing --run autoheader
+
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = /usr/bin/install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_SCRIPT = ${INSTALL}
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = s,x,x,
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+
+EXEEXT = 
+OBJEXT = o
+PATH_SEPARATOR = :
+AMTAR = ${SHELL} /my/libvncserver/missing --run tar
+AWK = gawk
+CC = gcc
+CCLD = g++
+CXX = g++
+DEPDIR = .deps
+INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
+PACKAGE = libvncserver
+RANLIB = ranlib
+STRIP = 
+VERSION = 0.5
+X_CFLAGS =  -I/usr/X11R6/include
+X_EXTRA_LIBS = 
+X_LIBS =  -L/usr/X11R6/lib  -lX11  -lXext -lXtst
+X_PRE_LIBS =  -lSM -lICE
+am__include = include
+am__quote = 
+install_sh = /my/libvncserver/install-sh
+noinst_PROGRAMS = zippy
+
+bin_PROGRAMS = x11vnc
+x11vnc_SOURCES = x11vnc.c
+x11vnc_CFLAGSADD =  -I/usr/X11R6/include
+x11vnc_LDADD =  -L/usr/X11R6/lib  -lX11  -lXext -lXtst
+
+zippy_SOURCES = zippy.c
+subdir = contrib
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/include/rfbconfig.h
+CONFIG_CLEAN_FILES =
+bin_PROGRAMS = x11vnc$(EXEEXT)
+#bin_PROGRAMS =
+noinst_PROGRAMS = zippy$(EXEEXT)
+PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
+
+am_x11vnc_OBJECTS = x11vnc.$(OBJEXT)
+x11vnc_OBJECTS = $(am_x11vnc_OBJECTS)
+x11vnc_DEPENDENCIES =
+#x11vnc_DEPENDENCIES =
+x11vnc_LDFLAGS =
+am_zippy_OBJECTS = zippy.$(OBJEXT)
+zippy_OBJECTS = $(am_zippy_OBJECTS)
+zippy_LDADD = $(LDADD)
+zippy_DEPENDENCIES =
+zippy_LDFLAGS =
+
+DEFS = -DHAVE_CONFIG_H
+DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/include
+CPPFLAGS = 
+LDFLAGS = 
+LIBS = -L.. -lvncserver -lz -lpthread -ljpeg 
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+DEP_FILES = ./$(DEPDIR)/x11vnc.Po ./$(DEPDIR)/zippy.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+CFLAGS = -g -O2
+DIST_SOURCES = $(x11vnc_SOURCES) $(zippy_SOURCES)
+DIST_COMMON = Makefile.am Makefile.in
+SOURCES = $(x11vnc_SOURCES) $(zippy_SOURCES)
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .o .obj
+$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
+	cd $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu  contrib/Makefile
+Makefile:  $(srcdir)/Makefile.in  $(top_builddir)/config.status
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
+binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
+install-binPROGRAMS: $(bin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	$(mkinstalldirs) $(DESTDIR)$(bindir)
+	@list='$(bin_PROGRAMS)'; for p in $$list; do \
+	  p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+	  if test -f $$p \
+	  ; then \
+	    f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
+	   echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \
+	   $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f; \
+	  else :; fi; \
+	done
+
+uninstall-binPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(bin_PROGRAMS)'; for p in $$list; do \
+	  f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
+	  echo " rm -f $(DESTDIR)$(bindir)/$$f"; \
+	  rm -f $(DESTDIR)$(bindir)/$$f; \
+	done
+
+clean-binPROGRAMS:
+	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+
+clean-noinstPROGRAMS:
+	-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
+x11vnc$(EXEEXT): $(x11vnc_OBJECTS) $(x11vnc_DEPENDENCIES) 
+	@rm -f x11vnc$(EXEEXT)
+	$(LINK) $(x11vnc_LDFLAGS) $(x11vnc_OBJECTS) $(x11vnc_LDADD) $(LIBS)
+zippy$(EXEEXT): $(zippy_OBJECTS) $(zippy_DEPENDENCIES) 
+	@rm -f zippy$(EXEEXT)
+	$(LINK) $(zippy_LDFLAGS) $(zippy_OBJECTS) $(zippy_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT) core *.core
+
+distclean-compile:
+	-rm -f *.tab.c
+
+include ./$(DEPDIR)/x11vnc.Po
+include ./$(DEPDIR)/zippy.Po
+
+distclean-depend:
+	-rm -rf ./$(DEPDIR)
+
+.c.o:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CCDEPMODE) $(depcomp) \
+	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+
+.c.obj:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CCDEPMODE) $(depcomp) \
+	$(COMPILE) -c `cygpath -w $<`
+CCDEPMODE = depmode=gcc3
+uninstall-info-am:
+
+ETAGS = etags
+ETAGSFLAGS =
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	mkid -fID $$unique
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(ETAGS_ARGS)$$tags$$unique" \
+	  || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	     $$tags $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && cd $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+	@list='$(DISTFILES)'; for file in $$list; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+	    dir="/$$dir"; \
+	    $(mkinstalldirs) "$(distdir)$$dir"; \
+	  else \
+	    dir=''; \
+	  fi; \
+	  if test -d $$d/$$file; then \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+	    fi; \
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || cp -p $$d/$$file $(distdir)/$$file \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+
+installdirs:
+	$(mkinstalldirs) $(DESTDIR)$(bindir)
+
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-rm -f Makefile $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-noinstPROGRAMS \
+	mostlyclean-am
+
+distclean: distclean-am
+
+distclean-am: clean-am distclean-compile distclean-depend \
+	distclean-generic distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+uninstall-am: uninstall-binPROGRAMS uninstall-info-am
+
+.PHONY: GTAGS all all-am check check-am clean clean-binPROGRAMS \
+	clean-generic clean-noinstPROGRAMS distclean distclean-compile \
+	distclean-depend distclean-generic distclean-tags distdir dvi \
+	dvi-am info info-am install install-am install-binPROGRAMS \
+	install-data install-data-am install-exec install-exec-am \
+	install-info install-info-am install-man install-strip \
+	installcheck installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic tags uninstall uninstall-am \
+	uninstall-binPROGRAMS uninstall-info-am
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
new file mode 100644
index 0000000..de73c82
--- /dev/null
+++ b/contrib/Makefile.am
@@ -0,0 +1,10 @@
+noinst_PROGRAMS=zippy
+
+if HAVE_X
+bin_PROGRAMS=x11vnc
+x11vnc_SOURCES=x11vnc.c
+x11vnc_CFLAGSADD=@X_CFLAGS@
+x11vnc_LDADD=@X_LIBS@
+endif
+
+zippy_SOURCES=zippy.c
diff --git a/examples/Makefile b/examples/Makefile
index c2de7ae..0c7ac44 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,50 +1,375 @@
-CFLAGS=-I. -I../include
-VNCSERVERLIB=-L.. -lvncserver -L/usr/local/lib -lz -ljpeg -lpthread
-LDFLAGS=$(VNCSERVERLIB)
-ifdef CXX
-LINK=$(CXX)
-else
-LINK=$(CC)
-endif
+# Makefile.in generated by automake 1.6.3 from Makefile.am.
+# examples/Makefile.  Generated from Makefile.in by configure.
 
-all: example pnmshow sratest blooptest pnmshow24 fontsel vncev storepasswd
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
 
-example: example.o ../libvncserver.a
-	$(LINK) -o example example.o $(LDFLAGS)
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
 
-pnmshow: pnmshow.o ../libvncserver.a
-	$(LINK) -o pnmshow pnmshow.o $(LDFLAGS)
 
-mac.o: mac.c 1instance.c
+SHELL = /bin/sh
 
-OSXvnc-server: mac.o ../libvncserver.a
-	$(LINK) -o OSXvnc-server mac.o $(LDFLAGS) $(OSX_LIBS)
+srcdir = .
+top_srcdir = ..
 
-storepasswd: storepasswd.o
-	$(LINK) -o storepasswd storepasswd.o $(LDFLAGS)
+prefix = /usr/local
+exec_prefix = ${prefix}
 
-sratest: sratest.o
-	$(LINK) -o sratest sratest.o
+bindir = ${exec_prefix}/bin
+sbindir = ${exec_prefix}/sbin
+libexecdir = ${exec_prefix}/libexec
+datadir = ${prefix}/share
+sysconfdir = ${prefix}/etc
+sharedstatedir = ${prefix}/com
+localstatedir = ${prefix}/var
+libdir = ${exec_prefix}/lib
+infodir = ${prefix}/info
+mandir = ${prefix}/man
+includedir = ${prefix}/include
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/libvncserver
+pkglibdir = $(libdir)/libvncserver
+pkgincludedir = $(includedir)/libvncserver
+top_builddir = ..
 
-sratest.o: ../sraRegion.c
-	$(CC) $(CFLAGS) -DSRA_TEST -c -o sratest.o ../sraRegion.c
+ACLOCAL = ${SHELL} /my/libvncserver/missing --run aclocal-1.6
+AUTOCONF = ${SHELL} /my/libvncserver/missing --run autoconf
+AUTOMAKE = ${SHELL} /my/libvncserver/missing --run automake-1.6
+AUTOHEADER = ${SHELL} /my/libvncserver/missing --run autoheader
 
-blooptest: blooptest.o ../libvncserver.a
-	$(LINK) -o blooptest blooptest.o $(LDFLAGS)
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = /usr/bin/install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_SCRIPT = ${INSTALL}
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = s,x,x,
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
 
-blooptest.o: example.c
-	$(CC) $(CFLAGS) -DBACKGROUND_LOOP_TEST -c -o blooptest.o example.c
+EXEEXT = 
+OBJEXT = o
+PATH_SEPARATOR = :
+AMTAR = ${SHELL} /my/libvncserver/missing --run tar
+AWK = gawk
+CC = gcc
+CCLD = g++
+CXX = g++
+DEPDIR = .deps
+INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
+PACKAGE = libvncserver
+RANLIB = ranlib
+STRIP = 
+VERSION = 0.5
+X_CFLAGS =  -I/usr/X11R6/include
+X_EXTRA_LIBS = 
+X_LIBS =  -L/usr/X11R6/lib  -lX11  -lXext -lXtst
+X_PRE_LIBS =  -lSM -lICE
+am__include = include
+am__quote = 
+install_sh = /my/libvncserver/install-sh
+BACKGROUND_TEST = blooptest
 
-pnmshow24: pnmshow24.o ../libvncserver.a
-	$(LINK) -o pnmshow24 pnmshow24.o $(LDFLAGS)
+noinst_PROGRAMS = example pnmshow sratest pnmshow24 fontsel \
+	vncev storepasswd $(BACKGROUND_TEST)
 
-fontsel: fontsel.o ../libvncserver.a
-	$(LINK) -o fontsel fontsel.o $(LDFLAGS)
+subdir = examples
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/include/rfbconfig.h
+CONFIG_CLEAN_FILES =
+noinst_PROGRAMS = example$(EXEEXT) \
+	pnmshow$(EXEEXT) sratest$(EXEEXT) \
+	pnmshow24$(EXEEXT) fontsel$(EXEEXT) \
+	vncev$(EXEEXT) storepasswd$(EXEEXT) \
+	blooptest$(EXEEXT)
+#noinst_PROGRAMS = example$(EXEEXT) \
+#	pnmshow$(EXEEXT) sratest$(EXEEXT) \
+#	pnmshow24$(EXEEXT) fontsel$(EXEEXT) \
+#	vncev$(EXEEXT) storepasswd$(EXEEXT)
+PROGRAMS = $(noinst_PROGRAMS)
 
-vncev: vncev.o ../libvncserver.a
-	$(LINK) -o vncev vncev.o $(LDFLAGS)
+blooptest_SOURCES = blooptest.c
+blooptest_OBJECTS = blooptest.$(OBJEXT)
+blooptest_LDADD = $(LDADD)
+blooptest_DEPENDENCIES =
+blooptest_LDFLAGS =
+example_SOURCES = example.c
+example_OBJECTS = example.$(OBJEXT)
+example_LDADD = $(LDADD)
+example_DEPENDENCIES =
+example_LDFLAGS =
+fontsel_SOURCES = fontsel.c
+fontsel_OBJECTS = fontsel.$(OBJEXT)
+fontsel_LDADD = $(LDADD)
+fontsel_DEPENDENCIES =
+fontsel_LDFLAGS =
+pnmshow_SOURCES = pnmshow.c
+pnmshow_OBJECTS = pnmshow.$(OBJEXT)
+pnmshow_LDADD = $(LDADD)
+pnmshow_DEPENDENCIES =
+pnmshow_LDFLAGS =
+pnmshow24_SOURCES = pnmshow24.c
+pnmshow24_OBJECTS = pnmshow24.$(OBJEXT)
+pnmshow24_LDADD = $(LDADD)
+pnmshow24_DEPENDENCIES =
+pnmshow24_LDFLAGS =
+sratest_SOURCES = sratest.c
+sratest_OBJECTS = sratest.$(OBJEXT)
+sratest_LDADD = $(LDADD)
+sratest_DEPENDENCIES =
+sratest_LDFLAGS =
+storepasswd_SOURCES = storepasswd.c
+storepasswd_OBJECTS = storepasswd.$(OBJEXT)
+storepasswd_LDADD = $(LDADD)
+storepasswd_DEPENDENCIES =
+storepasswd_LDFLAGS =
+vncev_SOURCES = vncev.c
+vncev_OBJECTS = vncev.$(OBJEXT)
+vncev_LDADD = $(LDADD)
+vncev_DEPENDENCIES =
+vncev_LDFLAGS =
 
-pnmshow24.o pnmshow.o example.o mac.o blooptest.o: Makefile ../include/rfb.h
+DEFS = -DHAVE_CONFIG_H
+DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/include
+CPPFLAGS = 
+LDFLAGS = 
+LIBS = -L.. -lvncserver -lz -lpthread -ljpeg 
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+DEP_FILES = ./$(DEPDIR)/blooptest.Po ./$(DEPDIR)/example.Po \
+	./$(DEPDIR)/fontsel.Po ./$(DEPDIR)/pnmshow.Po \
+	./$(DEPDIR)/pnmshow24.Po ./$(DEPDIR)/sratest.Po \
+	./$(DEPDIR)/storepasswd.Po ./$(DEPDIR)/vncev.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+CFLAGS = -g -O2
+DIST_SOURCES = blooptest.c example.c fontsel.c pnmshow.c pnmshow24.c \
+	sratest.c storepasswd.c vncev.c
+DIST_COMMON = Makefile.am Makefile.in
+SOURCES = blooptest.c example.c fontsel.c pnmshow.c pnmshow24.c sratest.c storepasswd.c vncev.c
 
-clean:
-	rm -f $(OBJS) *~ core "#"* *.bak *.orig
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .o .obj
+$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
+	cd $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu  examples/Makefile
+Makefile:  $(srcdir)/Makefile.in  $(top_builddir)/config.status
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
+
+clean-noinstPROGRAMS:
+	-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
+blooptest$(EXEEXT): $(blooptest_OBJECTS) $(blooptest_DEPENDENCIES) 
+	@rm -f blooptest$(EXEEXT)
+	$(LINK) $(blooptest_LDFLAGS) $(blooptest_OBJECTS) $(blooptest_LDADD) $(LIBS)
+example$(EXEEXT): $(example_OBJECTS) $(example_DEPENDENCIES) 
+	@rm -f example$(EXEEXT)
+	$(LINK) $(example_LDFLAGS) $(example_OBJECTS) $(example_LDADD) $(LIBS)
+fontsel$(EXEEXT): $(fontsel_OBJECTS) $(fontsel_DEPENDENCIES) 
+	@rm -f fontsel$(EXEEXT)
+	$(LINK) $(fontsel_LDFLAGS) $(fontsel_OBJECTS) $(fontsel_LDADD) $(LIBS)
+pnmshow$(EXEEXT): $(pnmshow_OBJECTS) $(pnmshow_DEPENDENCIES) 
+	@rm -f pnmshow$(EXEEXT)
+	$(LINK) $(pnmshow_LDFLAGS) $(pnmshow_OBJECTS) $(pnmshow_LDADD) $(LIBS)
+pnmshow24$(EXEEXT): $(pnmshow24_OBJECTS) $(pnmshow24_DEPENDENCIES) 
+	@rm -f pnmshow24$(EXEEXT)
+	$(LINK) $(pnmshow24_LDFLAGS) $(pnmshow24_OBJECTS) $(pnmshow24_LDADD) $(LIBS)
+sratest$(EXEEXT): $(sratest_OBJECTS) $(sratest_DEPENDENCIES) 
+	@rm -f sratest$(EXEEXT)
+	$(LINK) $(sratest_LDFLAGS) $(sratest_OBJECTS) $(sratest_LDADD) $(LIBS)
+storepasswd$(EXEEXT): $(storepasswd_OBJECTS) $(storepasswd_DEPENDENCIES) 
+	@rm -f storepasswd$(EXEEXT)
+	$(LINK) $(storepasswd_LDFLAGS) $(storepasswd_OBJECTS) $(storepasswd_LDADD) $(LIBS)
+vncev$(EXEEXT): $(vncev_OBJECTS) $(vncev_DEPENDENCIES) 
+	@rm -f vncev$(EXEEXT)
+	$(LINK) $(vncev_LDFLAGS) $(vncev_OBJECTS) $(vncev_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT) core *.core
+
+distclean-compile:
+	-rm -f *.tab.c
+
+include ./$(DEPDIR)/blooptest.Po
+include ./$(DEPDIR)/example.Po
+include ./$(DEPDIR)/fontsel.Po
+include ./$(DEPDIR)/pnmshow.Po
+include ./$(DEPDIR)/pnmshow24.Po
+include ./$(DEPDIR)/sratest.Po
+include ./$(DEPDIR)/storepasswd.Po
+include ./$(DEPDIR)/vncev.Po
+
+distclean-depend:
+	-rm -rf ./$(DEPDIR)
+
+.c.o:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CCDEPMODE) $(depcomp) \
+	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+
+.c.obj:
+	source='$<' object='$@' libtool=no \
+	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
+	$(CCDEPMODE) $(depcomp) \
+	$(COMPILE) -c `cygpath -w $<`
+CCDEPMODE = depmode=gcc3
+uninstall-info-am:
+
+ETAGS = etags
+ETAGSFLAGS =
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	mkid -fID $$unique
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(ETAGS_ARGS)$$tags$$unique" \
+	  || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	     $$tags $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && cd $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+	@list='$(DISTFILES)'; for file in $$list; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+	    dir="/$$dir"; \
+	    $(mkinstalldirs) "$(distdir)$$dir"; \
+	  else \
+	    dir=''; \
+	  fi; \
+	  if test -d $$d/$$file; then \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+	    fi; \
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || cp -p $$d/$$file $(distdir)/$$file \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+
+installdirs:
+
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-rm -f Makefile $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstPROGRAMS mostlyclean-am
+
+distclean: distclean-am
+
+distclean-am: clean-am distclean-compile distclean-depend \
+	distclean-generic distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+uninstall-am: uninstall-info-am
+
+.PHONY: GTAGS all all-am check check-am clean clean-generic \
+	clean-noinstPROGRAMS distclean distclean-compile \
+	distclean-depend distclean-generic distclean-tags distdir dvi \
+	dvi-am info info-am install install-am install-data \
+	install-data-am install-exec install-exec-am install-info \
+	install-info-am install-man install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic tags uninstall uninstall-am \
+	uninstall-info-am
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..16dff2a
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,6 @@
+if HAVE_LIBPTHREAD
+BACKGROUND_TEST=blooptest
+endif
+
+noinst_PROGRAMS=example pnmshow sratest pnmshow24 fontsel \
+	vncev storepasswd $(BACKGROUND_TEST)
diff --git a/examples/example.c b/examples/example.c
index 62295c3..e82ccea 100644
--- a/examples/example.c
+++ b/examples/example.c
@@ -297,7 +297,7 @@ int main(int argc,char** argv)
   /* initialize the server */
   rfbInitServer(rfbScreen);
 
-#define USE_OWN_LOOP
+#ifndef BACKGROUND_LOOP_TEST
 #ifdef USE_OWN_LOOP
   {
     int i;
@@ -307,12 +307,12 @@ int main(int argc,char** argv)
     }
   }
 #else
-
-#ifndef BACKGROUND_LOOP_TEST
   /* this is the blocking event loop, i.e. it never returns */
   /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */
   rfbRunEventLoop(rfbScreen,40000,FALSE);
-#elif !defined(HAVE_PTHREADS)
+#endif /* OWN LOOP */
+#else
+#if !defined(HAVE_LIBPTHREAD)
 #error "I need pthreads for that."
 #endif
 
@@ -320,7 +320,7 @@ int main(int argc,char** argv)
   rfbRunEventLoop(rfbScreen,-1,TRUE);
   /* now we could do some cool things like rendering in idle time */
   while(1) sleep(5); /* render(); */
-#endif
+#endif /* BACKGROUND_LOOP */
 
   rfbFreeCursor(rfbScreen->cursor);
   free(rfbScreen->frameBuffer);
diff --git a/include/rfb.h b/include/rfb.h
index 965ac71..fcaa995 100644
--- a/include/rfb.h
+++ b/include/rfb.h
@@ -35,14 +35,14 @@ extern "C"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <zlib.h>
+#include "rfbconfig.h"
 #include "keysym.h"
 
+#ifdef HAVE_LIBZ
+#include <zlib.h>
+#endif
+
 /* TODO: this stuff has to go into autoconf */
-#define HAVE_PTHREADS
-#define ALLOW24BPP
-#define HAVE_ZRLE
-#define BACKCHANNEL
 typedef unsigned char CARD8;
 typedef unsigned short CARD16;
 typedef unsigned int CARD32;
@@ -120,7 +120,7 @@ typedef int socklen_t;
 #define                INADDR_NONE     ((in_addr_t) 0xffffffff)
 #endif
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 #include <pthread.h>
 #if 0 /* debugging */
 #define LOCK(mutex) fprintf(stderr,"%s:%d LOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex))
@@ -163,11 +163,11 @@ typedef int socklen_t;
 
 /* end of stuff for autoconf */
 
-/* if you use pthreads, but don't define HAVE_PTHREADS, the structs
+/* if you use pthreads, but don't define HAVE_LIBPTHREAD, the structs
    get all mixed up. So this gives a linker error reminding you to compile
    the library and your application (at least the parts including rfb.h)
    with the same support for pthreads. */
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 #ifdef HAVE_ZRLE
 #define rfbInitServer rfbInitServerWithPthreadsAndZRLE
 #else
@@ -345,7 +345,7 @@ typedef struct _rfbScreenInfo
     /* displayHook is called just before a frame buffer update */
     DisplayHookPtr displayHook;
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
     MUTEX(cursorMutex);
     Bool backgroundLoop;
 #endif
@@ -404,7 +404,7 @@ typedef struct _rfbClientRec {
     SOCKET sock;
     char *host;
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
     pthread_t client_thread;
 #endif
                                 /* Possible client states: */
@@ -501,19 +501,23 @@ typedef struct _rfbClientRec {
     int rfbKeyEventsRcvd;
     int rfbPointerEventsRcvd;
 
+#ifdef HAVE_LIBZ
     /* zlib encoding -- necessary compression state info per client */
 
     struct z_stream_s compStream;
     Bool compStreamInited;
     CARD32 zlibCompressLevel;
 
+#ifdef HAVE_LIBJPEG
     /* tight encoding -- preserve zlib streams' state for each client */
-
+  //#ifdef HAVE_LIBJPEG
     z_stream zsStruct[4];
     Bool zsActive[4];
     int zsLevel[4];
     int tightCompressLevel;
     int tightQualityLevel;
+#endif
+#endif
 
     Bool enableLastRectEncoding;   /* client supports LastRect encoding */
     Bool enableCursorShapeUpdates; /* client supports cursor shape updates */
@@ -532,7 +536,7 @@ typedef struct _rfbClientRec {
     struct _rfbClientRec *prev;
     struct _rfbClientRec *next;
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
     /* whenever a client is referenced, the refCount has to be incremented
        and afterwards decremented, so that the client is not cleaned up
        while being referenced.
@@ -683,6 +687,7 @@ extern Bool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
                                        int h);
 
 
+#ifdef HAVE_LIBZ
 /* zlib.c */
 
 /* Minimum zlib rectangle size in bytes.  Anything smaller will
@@ -700,7 +705,7 @@ extern Bool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
 extern Bool rfbSendRectEncodingZlib(rfbClientPtr cl, int x, int y, int w,
 				    int h);
 
-
+#ifdef HAVE_LIBJPEG
 /* tight.c */
 
 #define TIGHT_DEFAULT_COMPRESSION  6
@@ -709,6 +714,8 @@ extern Bool rfbTightDisableGradient;
 
 extern int rfbNumCodedRectsTight(rfbClientPtr cl, int x,int y,int w,int h);
 extern Bool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
+#endif
+#endif
 
 
 /* cursor.c */
diff --git a/include/rfbproto.h b/include/rfbproto.h
index 0fb19b3..bdb9670 100644
--- a/include/rfbproto.h
+++ b/include/rfbproto.h
@@ -296,9 +296,11 @@ typedef struct {
 #define rfbEncodingRRE 2
 #define rfbEncodingCoRRE 4
 #define rfbEncodingHextile 5
+#ifdef HAVE_LIBZ
 #define rfbEncodingZlib 6
 #define rfbEncodingTight 7
 #define rfbEncodingZlibHex 8
+#endif
 #ifdef BACKCHANNEL
 #define rfbEncodingBackChannel 15
 #endif
@@ -488,7 +490,7 @@ typedef struct {
 #define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
 #define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
 
-
+#ifdef HAVE_LIBZ
 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  * zlib - zlib compressed Encoding.  We have an rfbZlibHeader structure
  * giving the number of bytes following.  Finally the data follows is
@@ -637,6 +639,8 @@ typedef struct {
 #define rfbTightFilterPalette          0x01
 #define rfbTightFilterGradient         0x02
 
+#endif
+
 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  * XCursor encoding. This is a special encoding used to transmit X-style
  * cursor shapes from server to clients. Note that for this encoding,
diff --git a/main.c b/main.c
index eeeb163..dddd961 100644
--- a/main.c
+++ b/main.c
@@ -32,7 +32,7 @@
 #include "rfb.h"
 #include "sraRegion.h"
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 MUTEX(logMutex);
 #endif
 
@@ -130,7 +130,7 @@ void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,in
 #if 0
        /* TODO: is this needed? Or does it mess up deferring? */
        /* while(!sraRgnEmpty(cl->copyRegion)) */ {
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 	 if(!cl->screen->backgroundLoop)
 #endif
 	   {
@@ -231,7 +231,7 @@ void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y
    sraRgnDestroy(region);
 }
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 static void *
 clientOutput(void *data)
 {
@@ -796,7 +796,7 @@ rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec)
 void rfbRunEventLoop(rfbScreenInfoPtr rfbScreen, long usec, Bool runInBackground)
 {
   if(runInBackground) {
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
        pthread_t listener_thread;
 
        rfbScreen->backgroundLoop = TRUE;
diff --git a/rfbserver.c b/rfbserver.c
index ec725e9..09be38e 100644
--- a/rfbserver.c
+++ b/rfbserver.c
@@ -59,7 +59,7 @@ static void rfbProcessClientProtocolVersion(rfbClientPtr cl);
 static void rfbProcessClientNormalMessage(rfbClientPtr cl);
 static void rfbProcessClientInitMessage(rfbClientPtr cl);
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 void rfbIncrClientRef(rfbClientPtr cl)
 {
   LOCK(cl->refCountMutex);
@@ -80,7 +80,7 @@ void rfbIncrClientRef(rfbClientPtr cl) {}
 void rfbDecrClientRef(rfbClientPtr cl) {}
 #endif
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
 MUTEX(rfbClientListMutex);
 #endif
 
@@ -124,7 +124,7 @@ rfbClientIteratorNext(rfbClientIteratorPtr i)
     IF_PTHREADS(rfbDecrClientRef(cl));
   }
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
     while(i->next && i->next->sock<0)
       i->next = i->next->next;
     if(i->next)
@@ -289,10 +289,12 @@ rfbNewTCPOrUDPClient(rfbScreen,sock,isUDP)
       rfbScreen->rfbClientHead = cl;
       UNLOCK(rfbClientListMutex);
 
+#ifdef HAVE_LIBJPEG
       cl->tightCompressLevel = TIGHT_DEFAULT_COMPRESSION;
       cl->tightQualityLevel = -1;
       for (i = 0; i < 4; i++)
         cl->zsActive[i] = FALSE;
+#endif
 
       cl->enableCursorShapeUpdates = FALSE;
       cl->enableCursorPosUpdates = FALSE;
@@ -300,6 +302,7 @@ rfbNewTCPOrUDPClient(rfbScreen,sock,isUDP)
       cl->enableLastRectEncoding = FALSE;
       cl->useNewFBSize = FALSE;
 
+#ifdef HAVE_LIBZ
       cl->compStreamInited = FALSE;
       cl->compStream.total_in = 0;
       cl->compStream.total_out = 0;
@@ -308,6 +311,7 @@ rfbNewTCPOrUDPClient(rfbScreen,sock,isUDP)
       cl->compStream.opaque = Z_NULL;
 
       cl->zlibCompressLevel = 5;
+#endif
 
       sprintf(pv,rfbProtocolVersionFormat,rfbProtocolMajorVersion,
 	      rfbProtocolMinorVersion);
@@ -381,7 +385,7 @@ rfbClientConnectionGone(cl)
     FreeZrleData(cl);
 #endif
 
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
     LOCK(cl->refCountMutex);
     if(cl->refCount) {
       UNLOCK(cl->refCountMutex);
@@ -399,15 +403,19 @@ rfbClientConnectionGone(cl)
     rfbLog("Client %s gone\n",cl->host);
     free(cl->host);
 
+#ifdef HAVE_LIBZ
     /* Release the compression state structures if any. */
     if ( cl->compStreamInited ) {
 	deflateEnd( &(cl->compStream) );
     }
 
+#ifdef HAVE_LIBJPEG
     for (i = 0; i < 4; i++) {
 	if (cl->zsActive[i])
 	    deflateEnd(&cl->zsStruct[i]);
     }
+#endif
+#endif
 
     if (pointerClient == cl)
         pointerClient = NULL;
@@ -745,6 +753,7 @@ rfbProcessClientNormalMessage(cl)
                            cl->host);
                 }
                 break;
+#ifdef HAVE_LIBZ
 	    case rfbEncodingZlib:
 		if (cl->preferredEncoding == -1) {
 		    cl->preferredEncoding = enc;
@@ -752,6 +761,7 @@ rfbProcessClientNormalMessage(cl)
 			   cl->host);
 		}
               break;
+#ifdef HAVE_LIBJPEG
 	    case rfbEncodingTight:
 		if (cl->preferredEncoding == -1) {
 		    cl->preferredEncoding = enc;
@@ -759,6 +769,8 @@ rfbProcessClientNormalMessage(cl)
 			   cl->host);
 		}
 		break;
+#endif
+#endif
 	    case rfbEncodingXCursor:
 		if(!cl->screen->dontConvertRichCursorToXCursor) {
 		    rfbLog("Enabling X-style cursor updates for client %s\n",
@@ -815,9 +827,11 @@ rfbProcessClientNormalMessage(cl)
                break;
 #endif
             default:
+#ifdef HAVE_LIBZ
 		if ( enc >= (CARD32)rfbEncodingCompressLevel0 &&
 		     enc <= (CARD32)rfbEncodingCompressLevel9 ) {
 		    cl->zlibCompressLevel = enc & 0x0F;
+#ifdef HAVE_LIBJPEG
 		    cl->tightCompressLevel = enc & 0x0F;
 		    rfbLog("Using compression level %d for client %s\n",
 			   cl->tightCompressLevel, cl->host);
@@ -826,7 +840,9 @@ rfbProcessClientNormalMessage(cl)
 		    cl->tightQualityLevel = enc & 0x0F;
 		    rfbLog("Using image quality level %d for client %s\n",
 			   cl->tightQualityLevel, cl->host);
+#endif
 		} else
+#endif
 		 rfbLog("rfbProcessClientNormalMessage: ignoring unknown "
                        "encoding type %d\n", (int)enc);
             }
@@ -1127,6 +1143,7 @@ rfbSendFramebufferUpdate(cl, givenUpdateRegion)
             nUpdateRegionRects += (((w-1) / cl->correMaxWidth + 1)
                                      * ((h-1) / cl->correMaxHeight + 1));
         }
+#ifdef HAVE_LIBZ
     } else if (cl->preferredEncoding == rfbEncodingZlib) {
 	nUpdateRegionRects = 0;
 
@@ -1137,6 +1154,7 @@ rfbSendFramebufferUpdate(cl, givenUpdateRegion)
             int h = rect.y2 - y;
 	    nUpdateRegionRects += (((h-1) / (ZLIB_MAX_SIZE( w ) / w)) + 1);
 	}
+#ifdef HAVE_LIBJPEG
     } else if (cl->preferredEncoding == rfbEncodingTight) {
 	nUpdateRegionRects = 0;
 
@@ -1152,6 +1170,8 @@ rfbSendFramebufferUpdate(cl, givenUpdateRegion)
 	    }
 	    nUpdateRegionRects += n;
 	}
+#endif
+#endif
     } else {
         nUpdateRegionRects = sraRgnCountRects(updateRegion);
     }
@@ -1226,18 +1246,22 @@ rfbSendFramebufferUpdate(cl, givenUpdateRegion)
                 return FALSE;
             }
             break;
+#ifdef HAVE_LIBZ
 	case rfbEncodingZlib:
 	    if (!rfbSendRectEncodingZlib(cl, x, y, w, h)) {
 	        sraRgnDestroy(updateRegion);
 		return FALSE;
 	    }
 	    break;
+#ifdef HAVE_LIBJPEG
 	case rfbEncodingTight:
 	    if (!rfbSendRectEncodingTight(cl, x, y, w, h)) {
 	        sraRgnDestroy(updateRegion);
 		return FALSE;
 	    }
 	    break;
+#endif
+#endif
 #ifdef HAVE_ZRLE
        case rfbEncodingZRLE:
            if (!rfbSendRectEncodingZRLE(cl, x, y, w, h)) {
diff --git a/sockets.c b/sockets.c
index e27ddc6..0c560f2 100644
--- a/sockets.c
+++ b/sockets.c
@@ -309,7 +309,7 @@ rfbCloseClient(cl)
      rfbClientPtr cl;
 {
     LOCK(cl->updateMutex);
-#ifdef HAVE_PTHREADS
+#ifdef HAVE_LIBPTHREAD
     if (cl->sock != -1)
 #endif
       {
diff --git a/tight.c b/tight.c
index ec4b43c..6f4997f 100644
--- a/tight.c
+++ b/tight.c
@@ -27,6 +27,9 @@
 /*#include <stdio.h>*/
 #include "rfb.h"
 
+#ifdef HAVE_LIBZ
+#ifdef HAVE_LIBJPEG
+
 #ifdef WIN32
 #define XMD_H
 #undef FAR
@@ -1798,3 +1801,5 @@ JpegSetDstManager(j_compress_ptr cinfo)
     cinfo->dest = &jpegDstManager;
 }
 
+#endif /* LIBJPEG */
+#endif /* LIBZ */
diff --git a/zlib.c b/zlib.c
index 1eac366..d0aaa8b 100644
--- a/zlib.c
+++ b/zlib.c
@@ -33,6 +33,8 @@
 #include <stdio.h>
 #include "rfb.h"
 
+#ifdef HAVE_LIBZ
+
 /*
  * zlibBeforeBuf contains pixel data in the client's format.
  * zlibAfterBuf contains the zlib (deflated) encoding version.
@@ -301,4 +303,4 @@ rfbSendRectEncodingZlib(cl, x, y, w, h)
 
 }
 
-
+#endif
diff --git a/zrle.cc b/zrle.cc
deleted file mode 100644
index 7839677..0000000
--- a/zrle.cc
+++ /dev/null
@@ -1,180 +0,0 @@
-//
-// Copyright (C) 2002 RealVNC Ltd.  All Rights Reserved.
-//
-// This is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This software is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this software; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
-// USA.
-//
-
-//
-// zrle.cc
-//
-// Routines to implement Zlib Run-length Encoding (ZRLE).
-//
-
-#include <stdio.h>
-extern "C" {
-#include "rfb.h"
-}
-#include <rdr/MemOutStream.h>
-#include <rdr/ZlibOutStream.h>
-
-
-#define GET_IMAGE_INTO_BUF(tx,ty,tw,th,buf)                                \
-  char *fbptr = (cl->screen->frameBuffer                                   \
-		 + (cl->screen->paddedWidthInBytes * ty)                   \
-                 + (tx * (cl->screen->bitsPerPixel / 8)));                 \
-                                                                           \
-  (*cl->translateFn)(cl->translateLookupTable, &cl->screen->rfbServerFormat,\
-                     &cl->format, fbptr, (char*)buf,                       \
-                     cl->screen->paddedWidthInBytes, tw, th);
-
-#define EXTRA_ARGS , rfbClientPtr cl
-
-#define BPP 8
-#include <zrleEncode.h>
-#undef BPP
-#define BPP 16
-#include <zrleEncode.h>
-#undef BPP
-#define BPP 32
-#include <zrleEncode.h>
-#define CPIXEL 24A
-#include <zrleEncode.h>
-#undef CPIXEL
-#define CPIXEL 24B
-#include <zrleEncode.h>
-#undef CPIXEL
-#undef BPP
-
-
-/*
- * zrleBeforeBuf contains pixel data in the client's format.  It must be at
- * least one pixel bigger than the largest tile of pixel data, since the
- * ZRLE encoding algorithm writes to the position one past the end of the pixel
- * data.
- */
-
-static char zrleBeforeBuf[rfbZRLETileWidth * rfbZRLETileHeight * 4 + 4];
-
-static rdr::MemOutStream mos;
-
-
-/*
- * rfbSendRectEncodingZRLE - send a given rectangle using ZRLE encoding.
- */
-
-
-Bool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w, int h)
-{
-  if (!cl->zrleData) cl->zrleData = new rdr::ZlibOutStream;
-  rdr::ZlibOutStream* zos = (rdr::ZlibOutStream*)cl->zrleData;
-  mos.clear();
-
-  switch (cl->format.bitsPerPixel) {
-
-  case 8:
-    zrleEncode8( x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
-    break;
-
-  case 16:
-    zrleEncode16(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
-    break;
-
-  case 32:
-    bool fitsInLS3Bytes
-      = ((cl->format.redMax   << cl->format.redShift)   < (1<<24) &&
-         (cl->format.greenMax << cl->format.greenShift) < (1<<24) &&
-         (cl->format.blueMax  << cl->format.blueShift)  < (1<<24));
-
-    bool fitsInMS3Bytes = (cl->format.redShift   > 7  &&
-                           cl->format.greenShift > 7  &&
-                           cl->format.blueShift  > 7);
-
-    if ((fitsInLS3Bytes && !cl->format.bigEndian) ||
-        (fitsInMS3Bytes && cl->format.bigEndian))
-    {
-      zrleEncode24A(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
-    }
-    else if ((fitsInLS3Bytes && cl->format.bigEndian) ||
-             (fitsInMS3Bytes && !cl->format.bigEndian))
-    {
-      zrleEncode24B(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
-    }
-    else
-    {
-      zrleEncode32(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
-    }
-    break;
-  }
-
-  cl->rfbRectanglesSent[rfbEncodingZRLE]++;
-  cl->rfbBytesSent[rfbEncodingZRLE] += (sz_rfbFramebufferUpdateRectHeader
-                                        + sz_rfbZRLEHeader + mos.length());
-
-  if (cl->ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbZRLEHeader
-      > UPDATE_BUF_SIZE)
-    {
-      if (!rfbSendUpdateBuf(cl))
-        return FALSE;
-    }
-
-  rfbFramebufferUpdateRectHeader rect;
-  rect.r.x = Swap16IfLE(x);
-  rect.r.y = Swap16IfLE(y);
-  rect.r.w = Swap16IfLE(w);
-  rect.r.h = Swap16IfLE(h);
-  rect.encoding = Swap32IfLE(rfbEncodingZRLE);
-
-  memcpy(cl->updateBuf+cl->ublen, (char *)&rect,
-         sz_rfbFramebufferUpdateRectHeader);
-  cl->ublen += sz_rfbFramebufferUpdateRectHeader;
-
-  rfbZRLEHeader hdr;
-
-  hdr.length = Swap32IfLE(mos.length());
-
-  memcpy(cl->updateBuf+cl->ublen, (char *)&hdr, sz_rfbZRLEHeader);
-  cl->ublen += sz_rfbZRLEHeader;
-
-  // copy into updateBuf and send from there.  Maybe should send directly?
-
-  for (int i = 0; i < mos.length();) {
-
-    int bytesToCopy = UPDATE_BUF_SIZE - cl->ublen;
-
-    if (i + bytesToCopy > mos.length()) {
-      bytesToCopy = mos.length() - i;
-    }
-
-    memcpy(cl->updateBuf+cl->ublen, (CARD8*)mos.data() + i, bytesToCopy);
-
-    cl->ublen += bytesToCopy;
-    i += bytesToCopy;
-
-    if (cl->ublen == UPDATE_BUF_SIZE) {
-      if (!rfbSendUpdateBuf(cl))
-        return FALSE;
-    }
-  }
-
-  return TRUE;
-}
-
-
-void FreeZrleData(rfbClientPtr cl)
-{
-  delete (rdr::ZlibOutStream*)cl->zrleData;
-}
-
diff --git a/zrle.cxx b/zrle.cxx
new file mode 100644
index 0000000..7839677
--- /dev/null
+++ b/zrle.cxx
@@ -0,0 +1,180 @@
+//
+// Copyright (C) 2002 RealVNC Ltd.  All Rights Reserved.
+//
+// This is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this software; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+// USA.
+//
+
+//
+// zrle.cc
+//
+// Routines to implement Zlib Run-length Encoding (ZRLE).
+//
+
+#include <stdio.h>
+extern "C" {
+#include "rfb.h"
+}
+#include <rdr/MemOutStream.h>
+#include <rdr/ZlibOutStream.h>
+
+
+#define GET_IMAGE_INTO_BUF(tx,ty,tw,th,buf)                                \
+  char *fbptr = (cl->screen->frameBuffer                                   \
+		 + (cl->screen->paddedWidthInBytes * ty)                   \
+                 + (tx * (cl->screen->bitsPerPixel / 8)));                 \
+                                                                           \
+  (*cl->translateFn)(cl->translateLookupTable, &cl->screen->rfbServerFormat,\
+                     &cl->format, fbptr, (char*)buf,                       \
+                     cl->screen->paddedWidthInBytes, tw, th);
+
+#define EXTRA_ARGS , rfbClientPtr cl
+
+#define BPP 8
+#include <zrleEncode.h>
+#undef BPP
+#define BPP 16
+#include <zrleEncode.h>
+#undef BPP
+#define BPP 32
+#include <zrleEncode.h>
+#define CPIXEL 24A
+#include <zrleEncode.h>
+#undef CPIXEL
+#define CPIXEL 24B
+#include <zrleEncode.h>
+#undef CPIXEL
+#undef BPP
+
+
+/*
+ * zrleBeforeBuf contains pixel data in the client's format.  It must be at
+ * least one pixel bigger than the largest tile of pixel data, since the
+ * ZRLE encoding algorithm writes to the position one past the end of the pixel
+ * data.
+ */
+
+static char zrleBeforeBuf[rfbZRLETileWidth * rfbZRLETileHeight * 4 + 4];
+
+static rdr::MemOutStream mos;
+
+
+/*
+ * rfbSendRectEncodingZRLE - send a given rectangle using ZRLE encoding.
+ */
+
+
+Bool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w, int h)
+{
+  if (!cl->zrleData) cl->zrleData = new rdr::ZlibOutStream;
+  rdr::ZlibOutStream* zos = (rdr::ZlibOutStream*)cl->zrleData;
+  mos.clear();
+
+  switch (cl->format.bitsPerPixel) {
+
+  case 8:
+    zrleEncode8( x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    break;
+
+  case 16:
+    zrleEncode16(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    break;
+
+  case 32:
+    bool fitsInLS3Bytes
+      = ((cl->format.redMax   << cl->format.redShift)   < (1<<24) &&
+         (cl->format.greenMax << cl->format.greenShift) < (1<<24) &&
+         (cl->format.blueMax  << cl->format.blueShift)  < (1<<24));
+
+    bool fitsInMS3Bytes = (cl->format.redShift   > 7  &&
+                           cl->format.greenShift > 7  &&
+                           cl->format.blueShift  > 7);
+
+    if ((fitsInLS3Bytes && !cl->format.bigEndian) ||
+        (fitsInMS3Bytes && cl->format.bigEndian))
+    {
+      zrleEncode24A(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    }
+    else if ((fitsInLS3Bytes && cl->format.bigEndian) ||
+             (fitsInMS3Bytes && !cl->format.bigEndian))
+    {
+      zrleEncode24B(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    }
+    else
+    {
+      zrleEncode32(x, y, w, h, &mos, zos, zrleBeforeBuf, cl);
+    }
+    break;
+  }
+
+  cl->rfbRectanglesSent[rfbEncodingZRLE]++;
+  cl->rfbBytesSent[rfbEncodingZRLE] += (sz_rfbFramebufferUpdateRectHeader
+                                        + sz_rfbZRLEHeader + mos.length());
+
+  if (cl->ublen + sz_rfbFramebufferUpdateRectHeader + sz_rfbZRLEHeader
+      > UPDATE_BUF_SIZE)
+    {
+      if (!rfbSendUpdateBuf(cl))
+        return FALSE;
+    }
+
+  rfbFramebufferUpdateRectHeader rect;
+  rect.r.x = Swap16IfLE(x);
+  rect.r.y = Swap16IfLE(y);
+  rect.r.w = Swap16IfLE(w);
+  rect.r.h = Swap16IfLE(h);
+  rect.encoding = Swap32IfLE(rfbEncodingZRLE);
+
+  memcpy(cl->updateBuf+cl->ublen, (char *)&rect,
+         sz_rfbFramebufferUpdateRectHeader);
+  cl->ublen += sz_rfbFramebufferUpdateRectHeader;
+
+  rfbZRLEHeader hdr;
+
+  hdr.length = Swap32IfLE(mos.length());
+
+  memcpy(cl->updateBuf+cl->ublen, (char *)&hdr, sz_rfbZRLEHeader);
+  cl->ublen += sz_rfbZRLEHeader;
+
+  // copy into updateBuf and send from there.  Maybe should send directly?
+
+  for (int i = 0; i < mos.length();) {
+
+    int bytesToCopy = UPDATE_BUF_SIZE - cl->ublen;
+
+    if (i + bytesToCopy > mos.length()) {
+      bytesToCopy = mos.length() - i;
+    }
+
+    memcpy(cl->updateBuf+cl->ublen, (CARD8*)mos.data() + i, bytesToCopy);
+
+    cl->ublen += bytesToCopy;
+    i += bytesToCopy;
+
+    if (cl->ublen == UPDATE_BUF_SIZE) {
+      if (!rfbSendUpdateBuf(cl))
+        return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+
+void FreeZrleData(rfbClientPtr cl)
+{
+  delete (rdr::ZlibOutStream*)cl->zrleData;
+}
+
-- 
cgit v1.2.3

