diff -Nurd -x'*~' EMBOSS-6.3.1.orig/Makefile.am EMBOSS-6.3.1/Makefile.am
--- EMBOSS-6.3.1.orig/Makefile.am	2010-01-11 08:15:41.000000000 -0500
+++ EMBOSS-6.3.1/Makefile.am	2010-08-04 12:15:15.000000000 -0400
@@ -5,7 +5,10 @@
 
 AUTOMAKE_OPTIONS = gnits
 
-SUBDIRS = plplot ajax nucleus emboss test doc jemboss
+if !ESYSTEMLIBS
+EXTRA_DIRS = plplot
+endif
+SUBDIRS = $(EXTRA_DIRS) ajax nucleus emboss test doc jemboss
 
 # AJAX_FIXED_ROOT = \"`pwd`/emboss/acd\"
 
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/Makefile.am EMBOSS-6.3.1/ajax/Makefile.am
--- EMBOSS-6.3.1.orig/ajax/Makefile.am	2010-06-16 06:26:45.000000000 -0400
+++ EMBOSS-6.3.1/ajax/Makefile.am	2010-08-04 19:07:47.000000000 -0400
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 if !ESYSTEMLIBS
-EXTRA_DIRS = expat zlib
+EXTRA_DIRS = pcre expat zlib
 endif
 
-SUBDIRS = pcre $(EXTRA_DIRS) core graphics ensembl ajaxdb acd
+SUBDIRS = $(EXTRA_DIRS) core graphics ensembl ajaxdb acd
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/acd/Makefile.am EMBOSS-6.3.1/ajax/acd/Makefile.am
--- EMBOSS-6.3.1.orig/ajax/acd/Makefile.am	2010-06-16 07:36:00.000000000 -0400
+++ EMBOSS-6.3.1/ajax/acd/Makefile.am	2010-08-06 04:31:47.000000000 -0400
@@ -13,10 +13,13 @@
 endif
 
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre
+else
+EXTRA_INCLUDES = $(PLPLOT_CFLAGS)
 endif
 
-INCLUDES = -I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre \
+INCLUDES =  \
 $(EXTRA_INCLUDES) \
 -I$(top_srcdir)/ajax/core \
 -I$(top_srcdir)/ajax/graphics \
@@ -38,3 +41,4 @@
 endif
 
 libacd_la_LDFLAGS = $(LINKFLAGS)
+libacd_la_LIBADD = ../core/libajax.la ../graphics/libajaxg.la ../ajaxdb/libajaxdb.la
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/ajaxdb/Makefile.am EMBOSS-6.3.1/ajax/ajaxdb/Makefile.am
--- EMBOSS-6.3.1.orig/ajax/ajaxdb/Makefile.am	2010-06-16 07:36:00.000000000 -0400
+++ EMBOSS-6.3.1/ajax/ajaxdb/Makefile.am	2010-08-06 04:19:18.000000000 -0400
@@ -13,11 +13,12 @@
 endif
 
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre
 endif
 
 
-INCLUDES = -I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre \
+INCLUDES = \
 $(EXTRA_INCLUDES) \
 -I$(top_srcdir)/ajax/core -I$(top_srcdir)/ajax/ensembl
 
@@ -37,3 +38,4 @@
 endif
 
 libajaxdb_la_LDFLAGS = $(LINKFLAGS)
+libajaxdb_la_LIBADD = ../core/libajax.la ../ensembl/libensembl.la
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/core/Makefile.am EMBOSS-6.3.1/ajax/core/Makefile.am
--- EMBOSS-6.3.1.orig/ajax/core/Makefile.am	2010-06-16 07:36:00.000000000 -0400
+++ EMBOSS-6.3.1/ajax/core/Makefile.am	2010-08-06 08:16:54.000000000 -0400
@@ -12,13 +12,18 @@
 endif
 
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre 
+else
+EXTRA_LIBS = -lexpat -lpcre
 endif
 
+EXTRA_DIST = ajax-pcre-config.h.in
+DISTCLEAN = ajax-pcre-config.h
 
 INCLUDES = -DAJAX_FIXED_ROOT=$(AJAX_FIXED_ROOT) \
 -DAJAX_SYSTEM="$(AJAX_SYSTEM)" -DPREFIX=\"$(prefix)\" \
--I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre $(EXTRA_INCLUDES)
+$(EXTRA_INCLUDES) $(POSTGRESQL_CFLAGS) $(MYSQL_CFLAGS)
 
 AJAXSRC = ajalign.c ajarr.c ajassert.c \
 ajbase.c ajcall.c ajcod.c \
@@ -44,7 +49,7 @@
 ajmath.h ajmatrices.h ajmem.h ajmess.h \
 ajnam.h ajnexus.h ajobo.h \
 ajpat.h ajpdb.h ajpdbio.h ajphylo.h \
-ajrange.h ajreg.h ajreport.h ajresource.h \
+ajrange.h ajreg.h ajax-pcre-config.h ajreport.h ajresource.h \
 ajseq.h ajseqabi.h ajseqbam.h ajseqdata.h ajseqread.h ajseqtype.h ajseqwrite.h \
 ajsort.h ajsql.h ajstr.h ajsys.h \
 ajtable.h ajtax.h ajtime.h ajtranslate.h ajtree.h ajutil.h ajvector.h
@@ -61,3 +66,4 @@
 endif
 
 libajax_la_LDFLAGS = $(LINKFLAGS)
+libajax_la_LIBADD = $(EXTRA_LIBS) $(POSTGRESQL_LDFLAGS) $(MYSQL_LDFLAGS)
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/core/ajax-pcre-config.h.in EMBOSS-6.3.1/ajax/core/ajax-pcre-config.h.in
--- EMBOSS-6.3.1.orig/ajax/core/ajax-pcre-config.h.in	1969-12-31 19:00:00.000000000 -0500
+++ EMBOSS-6.3.1/ajax/core/ajax-pcre-config.h.in	2010-08-04 20:21:16.000000000 -0400
@@ -0,0 +1 @@
+@DEFINE_USE_SYSTEM_PCRE@ AJAX_USE_SYSTEM_PCRE
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/core/ajreg.h EMBOSS-6.3.1/ajax/core/ajreg.h
--- EMBOSS-6.3.1.orig/ajax/core/ajreg.h	2010-04-14 03:44:20.000000000 -0400
+++ EMBOSS-6.3.1/ajax/core/ajreg.h	2010-08-04 20:29:22.000000000 -0400
@@ -16,9 +16,14 @@
 #define ajreg_h
 
 #include "ajax.h"
+#include "ajax-pcre-config.h"
+#ifndef AJAX_USE_SYSTEM_PCRE
 #include "pcre_config.h"
 #include "pcre_internal.h"
 #include "pcreposix.h"
+#else
+#include <pcre.h>
+#endif
 
 #define AJREG_OVECSIZE 30
 
@@ -41,7 +46,11 @@
 ******************************************************************************/
 
 typedef struct AjSRegexp {
+#ifndef AJAX_USE_SYSTEM_PCRE
     real_pcre *pcre;
+#else
+    pcre *pcre;
+#endif
     pcre_extra *extra;
     int *ovector;
     const char* orig;
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/ensembl/Makefile.am EMBOSS-6.3.1/ajax/ensembl/Makefile.am
--- EMBOSS-6.3.1.orig/ajax/ensembl/Makefile.am	2010-06-16 07:36:00.000000000 -0400
+++ EMBOSS-6.3.1/ajax/ensembl/Makefile.am	2010-08-06 04:16:49.000000000 -0400
@@ -10,12 +10,13 @@
 endif
 
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre 
 endif
 
 
-INCLUDES = -I$(top_srcdir)/plplot $(EXTRA_INCLUDES) \
--I$(top_srcdir)/ajax/pcre -I$(top_srcdir)/ajax/core
+INCLUDES = $(EXTRA_INCLUDES) \
+-I$(top_srcdir)/ajax/core
 
 ENSEMBLSRC = ensanalysis.c ensassembly.c ensassemblyexception.c \
 ensassemblymapper.c ensattribute.c ensbaseadaptor.c enscache.c \
@@ -56,3 +57,4 @@
 endif
 
 libensembl_la_LDFLAGS = $(LINKFLAGS)
+libensembl_la_LIBADD = ../core/libajax.la
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/graphics/Makefile.am EMBOSS-6.3.1/ajax/graphics/Makefile.am
--- EMBOSS-6.3.1.orig/ajax/graphics/Makefile.am	2010-06-16 07:36:00.000000000 -0400
+++ EMBOSS-6.3.1/ajax/graphics/Makefile.am	2010-08-06 04:09:10.000000000 -0400
@@ -10,11 +10,15 @@
 endif
 
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre
+else
+EXTRA_INCLUDES = $(PLPLOT_CFLAGS) -DUSE_PLXSFNAM_SHIM
+EXTRA_LIBS = $(PLPLOT_LIBS)
 endif
 
 
-INCLUDES = -I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre \
+INCLUDES = \
 $(EXTRA_INCLUDES) -I$(top_srcdir)/ajax/core
 
 AJAXGSRC = ajgraph.c ajhist.c
@@ -32,3 +36,4 @@
 endif
 
 libajaxg_la_LDFLAGS = $(LINKFLAGS)
+libajaxg_la_LIBADD = ../core/libajax.la $(EXTRA_LIBS)
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/ajax/graphics/ajgraph.c EMBOSS-6.3.1/ajax/graphics/ajgraph.c
--- EMBOSS-6.3.1.orig/ajax/graphics/ajgraph.c	2010-07-19 07:40:00.000000000 -0400
+++ EMBOSS-6.3.1/ajax/graphics/ajgraph.c	2010-08-06 04:11:20.000000000 -0400
@@ -1054,8 +1054,18 @@
 {
     if(!thys->ready)
     {
+#ifdef USE_PLXSFNAM_SHIM
+        char *fullname;
+#endif
         ajDebug("=g= plxsfnam ('%S', '%s')\n", txt, ext);
+#ifdef USE_PLXSFNAM_SHIM
+        fullname = asprintf(fullname,"%s%s", ajStrGetPtr(txt), ext);
+        ajDebug("=g= plsfnam ('%S') instead\n", fullname);
+        plsfnam(fullname);
+        free(fullname);
+#else
         plxsfnam(ajStrGetPtr(txt), ext);
+#endif
         ajStrAssignS(&graphBasename, txt);
         ajStrAssignC(&graphExtension, ext);
         if(ajStrGetCharFirst(graphExtension) == '.')
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/configure.in EMBOSS-6.3.1/configure.in
--- EMBOSS-6.3.1.orig/configure.in	2010-07-19 07:45:34.000000000 -0400
+++ EMBOSS-6.3.1/configure.in	2010-08-06 07:20:07.000000000 -0400
@@ -235,15 +235,6 @@
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 
-dnl Intel MacOSX 10.6 puts X11 in a non-standard place
-if test "${with_x}" != "no" ; then
-if test "`uname -a | grep Darwin`"; then
-OSXX=`sw_vers -productVersion | sed 's/\(10\.[[0-9]]*\).*/\1/'`
-if test ${OSXX} '>' '10.4'; then
-CFLAGS="$CFLAGS -I/usr/X11/include -L/usr/X11/lib"
-fi
-fi
-fi
 
 # Checks for header files.
 #as# AC_PATH_X
@@ -292,9 +283,6 @@
 #as# 		select socket sqrt strchr strcspn strdup strerror strpbrk \
 #as# 		strrchr strspn strstr strtol])
 
-if test "${with_x}" != "no" ; then
-LF_EMBOSS_PATH_XLIB
-fi
 
 dnl Library checks
 AC_CHECK_LIB(c, socket, LIBS="$LIBS" , LIBS="$LIBS -lsocket")
@@ -322,8 +310,8 @@
 CFLAGS="$CFLAGS $MYSQL_CFLAGS"
 LDFLAGS="$LDFLAGS $MYSQL_LDFLAGS"
 
-CFLAGS="$CFLAGS $POSTGRESQL_CFLAGS"
-LDFLAGS="$LDFLAGS $POSTGRESQL_LDFLAGS"
+CFLAGS="$POSTGRESQL_CFLAGS $CFLAGS"
+LDFLAGS="$POSTGRESQL_LDFLAGS $LDFLAGS"
 
 
 dnl Check for 'ant' for packaging Jemboss and export result
@@ -443,13 +431,33 @@
 
 dnl Test if --enable-systemlibs given
 have_systemlibs=no
+DEFINE_USE_SYSTEM_PCRE="#undef"
 AC_ARG_ENABLE(systemlibs,
    AS_HELP_STRING([--enable-systemlibs], [utility for RPM/dpkg bundles]))
 if test "${enable_systemlibs}" = "yes" ; then
     have_systemlibs=yes
+    DEFINE_USE_SYSTEM_PCRE="#define"
+    PKG_CHECK_MODULES(PLPLOT, [plplotd])
+else
+    dnl X11 is only used by plplot
+    dnl Intel MacOSX 10.6 puts X11 in a non-standard place
+    if test "${with_x}" != "no" ; then
+    if test "`uname -a | grep Darwin`"; then
+    OSXX=`sw_vers -productVersion | sed 's/\(10\.[[0-9]]*\).*/\1/'`
+    if test ${OSXX} '>' '10.4'; then
+    CFLAGS="$CFLAGS -I/usr/X11/include -L/usr/X11/lib"
+    fi
+    fi
+    fi
+    if test "${with_x}" != "no" ; then
+    LF_EMBOSS_PATH_XLIB
+    fi
 fi          
 AM_CONDITIONAL(ESYSTEMLIBS, test "$have_systemlibs" = "yes")
 AC_SUBST(ESYSTEMLIBS)
+AC_SUBST(DEFINE_USE_SYSTEM_PCRE)
+AC_SUBST(PLPLOT_CFLAGS)
+AC_SUBST(PLPLOT_LIBS)
 
 
 
@@ -683,6 +691,7 @@
 
 
 AC_OUTPUT([plplot/Makefile plplot/lib/Makefile nucleus/Makefile ajax/Makefile
+ajax/core/ajax-pcre-config.h
 ajax/pcre/Makefile ajax/expat/Makefile ajax/zlib/Makefile ajax/core/Makefile
 ajax/graphics/Makefile ajax/ensembl/Makefile ajax/ajaxdb/Makefile
 ajax/acd/Makefile
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/emboss/Makefile.am EMBOSS-6.3.1/emboss/Makefile.am
--- EMBOSS-6.3.1.orig/emboss/Makefile.am	2010-06-16 06:26:45.000000000 -0400
+++ EMBOSS-6.3.1/emboss/Makefile.am	2010-08-06 05:50:53.000000000 -0400
@@ -79,14 +79,17 @@
 yank
 
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre
+else
+EXTRA_INCLUDES = $(PLPLOT_CFLAGS)
 endif
 
-INCLUDES = -I$(top_srcdir)/nucleus -I$(top_srcdir)/ajax/pcre \
+INCLUDES = -I$(top_srcdir)/nucleus \
 	$(EXTRA_INCLUDES) \
 	-I$(top_srcdir)/ajax/core -I$(top_srcdir)/ajax/graphics \
 	-I$(top_srcdir)/ajax/ensembl -I$(top_srcdir)/ajax/ajaxdb \
-	-I$(top_srcdir)/ajax/acd -I$(top_srcdir)/plplot
+	-I$(top_srcdir)/ajax/acd
 
 
 aaindexextract_SOURCES = aaindexextract.c
@@ -319,7 +322,7 @@
 treetypedisplay_SOURCES = treetypedisplay.c
 
 if !ESYSTEMLIBS
-EXTRA_LDS = ../ajax/zlib/libezlib.la ../ajax/expat/libeexpat.la
+EXTRA_LDS = ../ajax/zlib/libezlib.la ../ajax/expat/libeexpat.la ../plplot/libeplplot.la ../ajax/pcre/libepcre.la
 endif
 
 
@@ -327,7 +330,6 @@
 	../ajax/ajaxdb/libajaxdb.la ../ajax/ensembl/libensembl.la \
 	../ajax/graphics/libajaxg.la ../ajax/core/libajax.la \
 	$(EXTRA_LDS) \
-	../ajax/pcre/libepcre.la ../plplot/libeplplot.la \
 	$(XLIB)
 
 pkgdata_DATA = emboss.default.template
diff -Nurd -x'*~' EMBOSS-6.3.1.orig/nucleus/Makefile.am EMBOSS-6.3.1/nucleus/Makefile.am
--- EMBOSS-6.3.1.orig/nucleus/Makefile.am	2010-06-16 07:36:00.000000000 -0400
+++ EMBOSS-6.3.1/nucleus/Makefile.am	2010-08-06 05:20:16.000000000 -0400
@@ -19,13 +19,16 @@
 -lezlib -leplplot
 else
 if !ESYSTEMLIBS
-EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib
+EXTRA_INCLUDES = -I$(top_srcdir)/ajax/expat -I$(top_srcdir)/ajax/zlib \
+-I$(top_srcdir)/plplot -I$(top_srcdir)/ajax/pcre
+else
+EXTRA_INCLUDES = $(PLPLOT_CFLAGS)
 endif
 endif
 
 
-INCLUDES = -I$(top_srcdir)/plplot $(X_CFLAGS) -I$(srcdir)/ \
-	-I$(top_srcdir)/ajax -I$(top_srcdir)/ajax/pcre \
+INCLUDES = $(X_CFLAGS) -I$(srcdir)/ \
+	-I$(top_srcdir)/ajax \
 	$(EXTRA_INCLUDES) \
 	-I$(top_srcdir)/ajax/core -I$(top_srcdir)/ajax/graphics \
 	-I$(top_srcdir)/ajax/ensembl -I$(top_srcdir)/ajax/ajaxdb \
@@ -55,3 +58,4 @@
 endif
 
 libnucleus_la_LDFLAGS =  $(LINKFLAGS)
+libnucleus_la_LIBADD = ../ajax/core/libajax.la ../ajax/graphics/libajaxg.la ../ajax/acd/libacd.la
