diff -uraN gs-orig/src/devs.mak gs-x11module/src/devs.mak
--- gs-orig/src/devs.mak	2004-09-28 02:58:01.000000000 +0200
+++ gs-x11module/src/devs.mak	2004-12-16 23:04:37.892390760 +0100
@@ -405,7 +405,7 @@
 	$(ADDMOD) $(DD)lvga256 -lib vga vgagl
 
 $(GLOBJ)gdevl256.$(OBJ) : $(GLSRC)gdevl256.c $(GDEV) $(memory__h)
-	$(GLCC) $(GLO_)gdevl256.$(OBJ) $(C_) $(GLSRC)gdevl256.c
+	$(GLCCSHARED) $(GLO_)gdevl256.$(OBJ) $(C_) $(GLSRC)gdevl256.c
 
 vgalib_=$(GLOBJ)gdevvglb.$(OBJ) $(GLOBJ)gdevpccm.$(OBJ)
 $(DD)vgalib.dev : $(DEVS_MAK) $(vgalib_)
@@ -413,7 +413,18 @@
 	$(ADDMOD) $(DD)vgalib -lib vga
 
 $(GLOBJ)gdevvglb.$(OBJ) : $(GLSRC)gdevvglb.c $(GDEV) $(gdevpccm_h) $(gsparam_h)
-	$(GLCC) $(GLO_)gdevvglb.$(OBJ) $(C_) $(GLSRC)gdevvglb.c
+	$(GLCCSHARED) $(GLO_)gdevvglb.$(OBJ) $(C_) $(GLSRC)gdevvglb.c
+
+### Shared library object supporting vgalib.
+### NON PORTABLE, ONLY UNIX WITH GCC SUPPORT
+
+$(GLOBJ)lvga256.so: $(lvga256_)
+	$(CCLD) -shared -Wl,'-solvga256.so' $(lvga256_) -lvga -lvgagl
+	mv lvga256.so $(GLOBJ)lvga256.so
+
+$(GLOBJ)vgalib.so: $(vgalib_)
+	$(CCLD) -shared -Wl,'-sovgalib.so' $(vgalib_) -lvga -lvgagl
+	mv vgalib.so $(GLOBJ)vgalib.so
 
 ### -------------------------- The X11 device -------------------------- ###
 
@@ -443,14 +454,14 @@
 $(GLOBJ)gdevx.$(OBJ) : $(GLSRC)gdevx.c $(GDEVX) $(math__h) $(memory__h)\
  $(gscoord_h) $(gsdevice_h) $(gsiparm2_h) $(gsmatrix_h) $(gsparam_h)\
  $(gxdevmem_h) $(gxgetbit_h) $(gxiparam_h) $(gxpath_h)
-	$(GLCC) $(XINCLUDE) $(GLO_)gdevx.$(OBJ) $(C_) $(GLSRC)gdevx.c
+	$(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevx.$(OBJ) $(C_) $(GLSRC)gdevx.c
 
 $(GLOBJ)gdevxcmp.$(OBJ) : $(GLSRC)gdevxcmp.c $(GDEVX) $(math__h)
 	$(GLCC) $(XINCLUDE) $(GLO_)gdevxcmp.$(OBJ) $(C_) $(GLSRC)gdevxcmp.c
 
 $(GLOBJ)gdevxini.$(OBJ) : $(GLSRC)gdevxini.c $(GDEVX) $(memory__h)\
  $(gserrors_h) $(gsparamx_h) $(gxdevmem_h) $(gdevbbox_h)
-	$(GLCC) $(XINCLUDE) $(GLO_)gdevxini.$(OBJ) $(C_) $(GLSRC)gdevxini.c
+	$(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxini.$(OBJ) $(C_) $(GLSRC)gdevxini.c
 
 # We have to compile gdevxres without warnings, because there is a
 # const/non-const cast required by the X headers that we can't work around.
@@ -460,7 +471,7 @@
 
 $(GLOBJ)gdevxxf.$(OBJ) : $(GLSRC)gdevxxf.c $(GDEVX) $(math__h) $(memory__h)\
  $(gsstruct_h) $(gsutil_h) $(gxxfont_h)
-	$(GLCC) $(XINCLUDE) $(GLO_)gdevxxf.$(OBJ) $(C_) $(GLSRC)gdevxxf.c
+	$(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxxf.$(OBJ) $(C_) $(GLSRC)gdevxxf.c
 
 # Alternate X11-based devices to help debug other drivers.
 # x11alpha pretends to have 4 bits of alpha channel.
@@ -510,7 +521,14 @@
 
 $(GLOBJ)gdevxalt.$(OBJ) : $(GLSRC)gdevxalt.c $(GDEVX) $(math__h) $(memory__h)\
  $(gsdevice_h) $(gsparam_h) $(gsstruct_h)
-	$(GLCC) $(XINCLUDE) $(GLO_)gdevxalt.$(OBJ) $(C_) $(GLSRC)gdevxalt.c
+	$(GLCCSHARED) $(XINCLUDE) $(GLO_)gdevxalt.$(OBJ) $(C_) $(GLSRC)gdevxalt.c
+
+### Shared library object supporting X11.
+### NON PORTABLE, ONLY UNIX WITH GCC SUPPORT
+
+$(GLOBJ)X11.so: $(x11alt_) $(x11_)
+	$(CCLD) -shared -Wl,'-soX11.so' $(x11alt_) $(x11_) -L/usr/X11R6/lib -lXt -lSM -lICE -lXext -lX11 $(XLIBDIRS)
+	mv X11.so $(GLOBJ)X11.so
 
 ###### --------------- Memory-buffered printer devices --------------- ######
 
diff -uraN gs-orig/src/gconf.c gs-x11module/src/gconf.c
--- gs-orig/src/gconf.c	2002-08-22 09:12:28.000000000 +0200
+++ gs-x11module/src/gconf.c	2004-12-16 23:10:50.940678800 +0100
@@ -92,7 +92,8 @@
 /* Set up the device table. */
 #define device_(dev) (const gx_device *)&dev,
 #define device2_(dev) &dev,
-private const gx_device *const gx_device_list[] = {
+private gx_device *gx_device_list[1024] = {
+  /* as shared library are adding drivers here, so removed constness */
 #include "gconf.h"
 	 0
 };
@@ -173,9 +174,29 @@
 gs_lib_device_list(const gx_device * const **plist,
 		   gs_memory_struct_type_t ** pst)
 {
+    int i;
+
     if (plist != 0)
 	*plist = gx_device_list;
     if (pst != 0)
 	*pst = NULL;
-    return countof(gx_device_list) - 1;
+
+    for (i = 0; i < countof(gx_device_list) - 1; ++i)
+      if (!gx_device_list[i])
+	break;
+    return i;
+}
+
+#ifdef GS_DEVS_SHARED
+void
+gs_lib_register_device(const gx_device *dev)
+{
+  int i;
+
+  for (i = 0; i < countof(gx_device_list) - 1; ++i)
+    if (!gx_device_list[i]) {
+      gx_device_list[i] = dev;
+      return;
+    }
 }
+#endif
diff -uraN gs-orig/src/gdevl256.c gs-x11module/src/gdevl256.c
--- gs-orig/src/gdevl256.c	2002-02-21 23:24:51.000000000 +0100
+++ gs-x11module/src/gdevl256.c	2004-12-16 23:14:58.345067616 +0100
@@ -305,3 +305,12 @@
     gl_line(x0, y0, x1, y1, color);
     return 0;
 }
+
+#ifdef GS_DEVS_SHARED
+extern void gs_lib_register_device(const gx_device *dev);
+void
+gs_shared_init(void)
+{
+  gs_lib_register_device(&gs_lvga256_device);
+}
+#endif
diff -uraN gs-orig/src/gdevvglb.c gs-x11module/src/gdevvglb.c
--- gs-orig/src/gdevvglb.c	2002-02-21 23:24:52.000000000 +0100
+++ gs-x11module/src/gdevvglb.c	2004-12-16 23:16:49.306198960 +0100
@@ -371,3 +371,12 @@
     }
     return 0;
 }
+
+#ifdef GS_DEVS_SHARED
+extern void gs_lib_register_device(const gx_device *dev);
+void
+gs_shared_init(void)
+{
+  gs_lib_register_device(&gs_vgalib_device);
+}
+#endif
diff -uraN gs-orig/src/gdevxalt.c gs-x11module/src/gdevxalt.c
--- gs-orig/src/gdevxalt.c	2002-09-07 22:02:54.000000000 +0200
+++ gs-x11module/src/gdevxalt.c	2004-12-16 23:47:23.669333376 +0100
@@ -28,6 +28,7 @@
 #include "gdevx.h"
 
 extern const gx_device_X gs_x11_device;
+extern const gx_device_X gs_x11alpha_device;
 
 /*
  * Define a forwarding device with a cache for the first 16 colors,
@@ -844,3 +845,20 @@
     rgb[2] = ((color >> 11) & 0x3ff) * gx_max_color_value / 0x3ff;
     return -1;
 }
+
+#ifdef GS_DEVS_SHARED
+extern void gs_lib_register_device(const gx_device *dev);
+void
+gs_shared_init(void)
+{
+  gs_lib_register_device(&gs_x11_device);
+  gs_lib_register_device(&gs_x11alpha_device);
+  gs_lib_register_device(&gs_x11cmyk_device);
+  gs_lib_register_device(&gs_x11cmyk2_device);
+  gs_lib_register_device(&gs_x11cmyk4_device);
+  gs_lib_register_device(&gs_x11cmyk8_device);
+  gs_lib_register_device(&gs_x11gray2_device);
+  gs_lib_register_device(&gs_x11gray4_device);
+  gs_lib_register_device(&gs_x11mono_device);
+}
+#endif
diff -uraN gs-orig/src/gp_unix.c gs-x11module/src/gp_unix.c
--- gs-orig/src/gp_unix.c	2003-12-12 23:08:02.000000000 +0100
+++ gs-x11module/src/gp_unix.c	2004-12-16 23:25:46.128589552 +0100
@@ -39,11 +39,56 @@
 
 #endif
 
+#ifdef GS_DEVS_SHARED
+#ifndef GS_DEVS_SHARED_DIR
+#  define GS_DEVS_SHARED_DIR "/usr/lib/ghostscript/8.16"
+#endif
+/*
+ * use shared library for drivers, always load them when starting, this
+ * avoid too many modifications, and since it is supported only under linux
+ * and applied as a patch (preferable).
+ */
+#include <sys/types.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <string.h>
+
+void
+gp_init(void)
+{
+  DIR*           dir = NULL;
+  struct dirent* dirent;
+  char           buff[1024];
+  char*          pbuff;
+  void*          handle;
+  void           (*gs_shared_init)(void);
+
+  strncpy(buff, GS_DEVS_SHARED_DIR, sizeof(buff) - 2);
+  pbuff = buff + strlen(buff);
+  *pbuff++ = '/'; *pbuff = '\0';
+
+  dir = opendir(GS_DEVS_SHARED_DIR);
+  if (dir == 0) return;
+
+  while ((dirent = readdir(dir)) != 0) {
+    strncpy(pbuff, dirent->d_name, sizeof(buff) - (pbuff - buff) - 1);
+    if ((handle = dlopen(buff, RTLD_NOW)) != 0) {
+      if ((gs_shared_init = dlsym(handle, "gs_shared_init")) != 0) {
+	(*gs_shared_init)();
+      } else {
+      }
+    }
+  }
+
+  closedir(dir);
+}
+#else
 /* Do platform-dependent initialization. */
 void
 gp_init(void)
 {
 }
+#endif
 
 /* Do platform-dependent cleanup. */
 void
diff -uraN gs-orig/src/gs.mak gs-x11module/src/gs.mak
--- gs-orig/src/gs.mak	2003-04-16 15:38:19.000000000 +0200
+++ gs-x11module/src/gs.mak	2004-12-16 23:31:27.835642184 +0100
@@ -246,7 +246,8 @@
 gconfig_h=$(GLGENDIR)$(D)gconfxx.h
 gconfigf_h=$(GLGENDIR)$(D)gconfxc.h
 
-all default : $(GS_XE)
+all default : $(GS_XE) $(GS_SHARED_OBJS)
+	$(RM) _temp_*
 	$(NO_OP)
 
 # the distclean and maintainer-clean targets (if any)
@@ -259,6 +260,7 @@
 clean : mostlyclean
 	$(RM_) $(GSGEN)arch.h
 	$(RM_) $(GS_XE)
+	$(RM_) $(GS_SHARED_OBJS)
 
 #****** FOLLOWING IS WRONG, NEEDS TO BE PER-SUBSYSTEM ******
 mostlyclean : config-clean
diff -uraN gs-orig/src/lib.mak gs-x11module/src/lib.mak
--- gs-orig/src/lib.mak	2004-09-28 02:58:01.000000000 +0200
+++ gs-x11module/src/lib.mak	2004-12-16 23:32:59.061773704 +0100
@@ -34,6 +34,7 @@
 GLZCC=$(CC_) $(I_)$(GLI_) $(II)$(ZI_)$(_I) $(ZCF_) $(GLF_)
 GLJBIG2CC=$(CC_) $(I_)$(GLI_) $(II)$(JB2I_)$(_I) $(JB2CF_) $(GLF_)
 GLCCLEAF=$(CC_LEAF) $(I_)$(GLI_)$(_I) $(GLF_)
+GLCCSHARED=$(CC_SHARED) $(I_)$(GLI_)$(_I) $(GLF_)
 # All top-level makefiles define GLD.
 #GLD=$(GLGEN)
 
diff -uraN gs-orig/src/Makefile.in gs-x11module/src/Makefile.in
--- gs-orig/src/Makefile.in	2004-09-08 08:30:15.000000000 +0200
+++ gs-x11module/src/Makefile.in	2004-12-16 20:49:08.285278896 +0100
@@ -62,6 +62,7 @@
 datadir = @datadir@
 gsdir = $(datadir)/ghostscript
 gsdatadir = $(gsdir)/$(GS_DOT_VERSION)
+gssharedir = $(prefix)/lib/ghostscript/$(GS_DOT_VERSION)
 
 docdir=$(gsdatadir)/doc
 exdir=$(gsdatadir)/examples
@@ -217,7 +218,7 @@
 # We don't include -ansi, because this gets in the way of the platform-
 #   specific stuff that <math.h> typically needs; nevertheless, we expect
 #   gcc to accept ANSI-style function prototypes and function definitions.
-XCFLAGS=
+XCFLAGS=-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\"$(gssharedir)\"
 
 # defines from autoconf; note that we don't use these at present.
 ACDEFS=@DEFS@
@@ -242,7 +243,7 @@
 # Solaris may need -lnsl -lsocket -lposix4.
 # (Libraries required by individual drivers are handled automatically.)
 
-EXTRALIBS=
+EXTRALIBS=-rdynamic -ldl
 
 # Define the standard libraries to search at the end of linking.
 # Most platforms require -lpthread for the POSIX threads library;
@@ -353,7 +354,8 @@
 # devs.mak and contrib.mak for the list of available devices.
 
 #DEVICE_DEVS=$(DISPLAY_DEV) $(DD)x11.dev $(DD)x11alpha.dev $(DD)x11cmyk.dev $(DD)x11gray2.dev $(DD)x11gray4.dev $(DD)x11mono.dev
-DEVICE_DEVS=$(DISPLAY_DEV) @X11DEVS@
+#DEVICE_DEVS=$(DISPLAY_DEV) @X11DEVS@
+DEVICE_DEVS=
 
 DEVICE_DEVS1=$(DD)bmpmono.dev $(DD)bmpgray.dev $(DD)bmpsep1.dev $(DD)bmpsep8.dev $(DD)bmp16.dev $(DD)bmp256.dev $(DD)bmp16m.dev $(DD)bmp32b.dev
 DEVICE_DEVS2=
@@ -379,6 +381,9 @@
 DEVICE_DEVS20=$(DD)cljet5.dev $(DD)cljet5c.dev
 DEVICE_DEVS21=$(DD)spotcmyk.dev $(DD)devicen.dev $(DD)xcf.dev $(DD)psdcmyk.dev $(DD)psdrgb.dev
 
+# Shared library target to build.
+GS_SHARED_OBJS=$(GLOBJDIR)/X11.so
+
 # ---------------------------- End of options --------------------------- #
 
 # Define the name of the partial makefile that specifies options --
@@ -402,6 +407,7 @@
 # These are the specific warnings we have to turn off to compile those
 # specific few files that need this.  We may turn off others in the future.
 CC_NO_WARN=$(CC_)
+CC_SHARED=$(CC_) -fPIC -shared
 
 # ---------------- End of platform-specific section ---------------- #
 
diff -uraN gs-orig/src/unix-gcc.mak gs-x11module/src/unix-gcc.mak
--- gs-orig/src/unix-gcc.mak	2003-12-24 04:31:30.000000000 +0100
+++ gs-x11module/src/unix-gcc.mak	2004-12-16 23:38:44.821210280 +0100
@@ -234,7 +234,7 @@
 # We don't include -ansi, because this gets in the way of the platform-
 #   specific stuff that <math.h> typically needs; nevertheless, we expect
 #   gcc to accept ANSI-style function prototypes and function definitions.
-XCFLAGS=
+XCFLAGS=-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\"$(gssharedir)\"
 
 CFLAGS=$(CFLAGS_STANDARD) $(GCFLAGS) $(XCFLAGS)
 
@@ -256,7 +256,7 @@
 # Solaris may need -lnsl -lsocket -lposix4.
 # (Libraries required by individual drivers are handled automatically.)
 
-EXTRALIBS=
+EXTRALIBS=-rdynamic -ldl
 
 # Define the standard libraries to search at the end of linking.
 # Most platforms require -lpthread for the POSIX threads library;
@@ -413,6 +413,10 @@
 DEVICE_DEVS20=$(DD)cljet5.dev $(DD)cljet5c.dev
 DEVICE_DEVS21=$(DD)spotcmyk.dev $(DD)devicen.dev $(DD)xcf.dev $(DD)bmpsep1.dev $(DD)bmpsep8.dev $(DD)bmp16m.dev $(DD)bmp32b.dev $(DD)psdcmyk.dev $(DD)psdrgb.dev
 
+# Shared library target to build.
+GS_SHARED_OBJS=$(GLOBJDIR)/X11.so $(GLOBJDIR)/lvga256.so $(GLOBJDIR)/vgalib.so
+#GS_SHARED_OBJS=$(GLOBJDIR)/X11.so
+
 # ---------------------------- End of options --------------------------- #
 
 # Define the name of the partial makefile that specifies options --
@@ -438,6 +442,7 @@
 # These are the specific warnings we have to turn off to compile those
 # specific few files that need this.  We may turn off others in the future.
 CC_NO_WARN=$(CC_) -Wno-cast-qual -Wno-traditional
+CC_SHARED=$(CC_) -fPIC -shared
 
 # ---------------- End of platform-specific section ---------------- #
 
diff -uraN gs-orig/src/unixinst.mak gs-x11module/src/unixinst.mak
--- gs-orig/src/unixinst.mak	2003-12-12 23:08:05.000000000 +0100
+++ gs-x11module/src/unixinst.mak	2004-12-16 23:40:49.235296464 +0100
@@ -18,7 +18,7 @@
 # containing the `install' targets.
 # This is the very last part of the makefile for these configurations.
 
-install: install-exec install-scripts install-data
+install: install-exec install-scripts install-data install-shared
 
 # The sh -c in the rules below is required because Ultrix's implementation
 # of sh -e terminates execution of a command if any error occurs, even if
@@ -164,3 +164,9 @@
 ridt91.eps ;\
 	do $(INSTALL_DATA) $(PSEXDIR)/$$f $(exdir) ;\
 	done
+
+install-shared: $(GS_SHARED_OBJS)
+	-mkdir -p $(gssharedir)
+	$(SH) -c 'for obj in $(GS_SHARED_OBJS); do \
+	    $(INSTALL_PROGRAM) $$obj $(gssharedir)/; done'
+
