Allow building with --prefix different from Gluster's --prefix.

diff --git a/packaging/TEMPLATES/configure.ac b/packaging/TEMPLATES/configure.ac
index 76594bf..fe8a8ea 100644
--- a/packaging/TEMPLATES/configure.ac
+++ b/packaging/TEMPLATES/configure.ac
@@ -38,7 +38,17 @@ AC_PROG_LIBTOOL
 AC_CHECK_TOOL([LD],[ld])
 
 dnl We don't bother checking for things that GlusterFS already needed.
-AC_CHECK_HEADERS([glusterfs/glusterfs.h])
+dnl AC_CHECK_HEADERS([glusterfs/glusterfs.h]) -- not enough, sets no path
+AC_ARG_VAR([GLUSTERDIR], [path to glusterfs/ include directory])
+if test "x$ac_cv_env_GLUSTERDIR_set" != "xset"; then
+	AC_CHECK_FILE([/usr/local/include/glusterfs/glusterfs.h],
+	              GLUSTERDIR=/usr/local/include/glusterfs,
+	              AC_CHECK_FILE([/usr/include/glusterfs/glusterfs.h],
+	              GLUSTERDIR=/usr/include/glusterfs,
+	              [AC_MSG_ERROR([Missing required glusterfs.h])]))
+fi
+AC_SUBST(GLUSTERDIR)
+
 AC_CHECK_HEADERS([openssl/des.h])
 
 GF_DISTRIBUTION=
diff --git a/pkg/configure.ac b/pkg/configure.ac
index 4388264..101ed3f 100644
--- a/pkg/configure.ac
+++ b/pkg/configure.ac
@@ -39,7 +39,17 @@ AC_PROG_LIBTOOL
 AC_CHECK_TOOL([LD],[ld])
 
 dnl We don't bother checking for things that GlusterFS already needed.
-AC_CHECK_HEADERS([glusterfs/glusterfs.h])
+dnl AC_CHECK_HEADERS([glusterfs/glusterfs.h]) -- not enough, sets no path
+AC_ARG_VAR([GLUSTERDIR], [path to glusterfs/ include directory])
+if test "x$ac_cv_env_GLUSTERDIR_set" != "xset"; then
+	AC_CHECK_FILE([/usr/local/include/glusterfs/glusterfs.h],
+	              GLUSTERDIR=/usr/local/include/glusterfs,
+	              AC_CHECK_FILE([/usr/include/glusterfs/glusterfs.h],
+	              GLUSTERDIR=/usr/include/glusterfs,
+	              [AC_MSG_ERROR([Missing required glusterfs.h])]))
+fi
+AC_SUBST(GLUSTERDIR)
+
 AC_CHECK_HEADERS([openssl/des.h])
 
 GF_DISTRIBUTION=
diff --git a/xlators/cluster/cloud/src/Makefile.am b/xlators/cluster/cloud/src/Makefile.am
index 40efb9c..222040b 100644
--- a/xlators/cluster/cloud/src/Makefile.am
+++ b/xlators/cluster/cloud/src/Makefile.am
@@ -9,10 +9,8 @@ cloud_la_SOURCES = cloud.c
 
 noinst_HEADERS = cloud-mem-types.h
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
-	-iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc -iquote$(GLUSTERDIR)/server \
+	-iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc -iquote@GLUSTERDIR@/server \
 	-shared -nostartfiles $(GF_CFLAGS)
 
 CLEANFILES =
diff --git a/xlators/cluster/login/src/Makefile.am b/xlators/cluster/login/src/Makefile.am
index e6c254e..d49f11f 100644
--- a/xlators/cluster/login/src/Makefile.am
+++ b/xlators/cluster/login/src/Makefile.am
@@ -6,10 +6,8 @@ login_la_LDFLAGS = -module -avoidversion -L@GLUSTER_LIBS@ -lglusterfs
 login_la_SOURCES = login.c
 #login_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
-	-iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc -iquote$(GLUSTERDIR)/server \
+	-iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc -iquote@GLUSTERDIR@/server \
 	-shared -nostartfiles $(GF_CFLAGS)
 
 CLEANFILES =
diff --git a/xlators/encryption/crypt/src/Makefile.am b/xlators/encryption/crypt/src/Makefile.am
index a2d4b4c..bf8802e 100644
--- a/xlators/encryption/crypt/src/Makefile.am
+++ b/xlators/encryption/crypt/src/Makefile.am
@@ -8,10 +8,8 @@ crypt_la_SOURCES = crypt.c
 
 noinst_HEADERS = crypt.h
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
-	-iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc -iquote$(GLUSTERDIR)/server \
+	-iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc -iquote@GLUSTERDIR@/server \
 	-shared -nostartfiles $(GF_CFLAGS)
 
 CLEANFILES =
diff --git a/xlators/features/uidmap/src/Makefile.am b/xlators/features/uidmap/src/Makefile.am
index 77299de..4afd18f 100644
--- a/xlators/features/uidmap/src/Makefile.am
+++ b/xlators/features/uidmap/src/Makefile.am
@@ -12,10 +12,8 @@ libmaprbtree_la_SOURCES = rbmap.c
 
 noinst_HEADERS = uidmap.h
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
-	-iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc -iquote$(GLUSTERDIR)/server \
+	-iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc -iquote@GLUSTERDIR@/server \
 	-DUIDMAP_PLUGIN_DIR=\"$(xlatordir)\" \
 	-shared -nostartfiles $(GF_CFLAGS)
 
diff --git a/xlators/protocol/client/src/Makefile.am b/xlators/protocol/client/src/Makefile.am
index d9b39f0..ec00be9 100644
--- a/xlators/protocol/client/src/Makefile.am
+++ b/xlators/protocol/client/src/Makefile.am
@@ -9,8 +9,6 @@ client2_la_SOURCES = client.c client-helpers.c client3_1-fops.c  \
 	client-handshake.c client-callback.c client-lk.c
 noinst_HEADERS = client.h client-mem-types.h
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
-	-iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc \
+	-iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc \
 	-shared -nostartfiles $(GF_CFLAGS)
diff --git a/xlators/protocol/server/src/Makefile.am b/xlators/protocol/server/src/Makefile.am
index aba05ee..0e799e1 100644
--- a/xlators/protocol/server/src/Makefile.am
+++ b/xlators/protocol/server/src/Makefile.am
@@ -9,10 +9,8 @@ server2_la_SOURCES = server.c server-resolve.c server-helpers.c  \
 
 noinst_HEADERS = server.h server-helpers.h server-mem-types.h authenticate.h
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall    \
-	 -iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc -shared -nostartfiles  \
+	 -iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc -shared -nostartfiles  \
 	-DCONFDIR=\"$(sysconfdir)/glusterfs\" -D$(GF_HOST_OS)   \
 	-DLIBDIR=\"@GLUSTER_AUTHS@\" \
 	$(GF_CFLAGS)
diff --git a/xlators/transport/socket/src/Makefile.am b/xlators/transport/socket/src/Makefile.am
index e280297..cf453e6 100644
--- a/xlators/transport/socket/src/Makefile.am
+++ b/xlators/transport/socket/src/Makefile.am
@@ -8,10 +8,8 @@ ssl_la_SOURCES = socket.c name.c
 
 noinst_HEADERS = socket.h name.h
 
-GLUSTERDIR=$(includedir)/glusterfs
-
 AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
-	-iquote$(GLUSTERDIR) -iquote$(GLUSTERDIR)/rpc \
+	-iquote@GLUSTERDIR@ -iquote@GLUSTERDIR@/rpc \
 	-shared -nostartfiles $(GF_CFLAGS)
 
 CLEANFILES = *~
