Add the --with-install-suffix configure option.

Fix some bugs in the Makefile's install target.
diff --git a/.gitignore b/.gitignore
index 02018fe..35acc25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,5 +8,9 @@
 /jemalloc/doc/jemalloc.3
 /jemalloc/lib/
 /jemalloc/Makefile
+/jemalloc/src/internal/jemalloc_internal\.h
+/jemalloc/src/internal/mtrgraph_defs\.h
+/jemalloc/src/internal/mtrplay_defs\.h
+/jemalloc/src/jemalloc\.h
 /jemalloc/src/jemalloc_defs\.h
 /jemalloc/src/*.[od]
diff --git a/jemalloc/INSTALL b/jemalloc/INSTALL
index c24895a..5cccb4e 100644
--- a/jemalloc/INSTALL
+++ b/jemalloc/INSTALL
@@ -31,6 +31,11 @@
     becomes <prefix>malloc().  This makes it possible to use jemalloc at the
     same time as the system allocator.
 
+--with-install-suffix=<suffix>
+    Append <suffix> to the base name of all installed files, such that multiple
+    versions of jemalloc can coexist in the same installation directory.  For
+    example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
+
 --enable-debug
     Enable assertions and validation code.  This incurs a substantial
     performance hit, but is very useful during application development.
diff --git a/jemalloc/Makefile.in b/jemalloc/Makefile.in
index a044011..0e6f929 100644
--- a/jemalloc/Makefile.in
+++ b/jemalloc/Makefile.in
@@ -17,7 +17,7 @@
 MANDIR := @MANDIR@
 
 # Build parameters.
-CPPFLAGS := @CPPFLAGS@
+CPPFLAGS := @CPPFLAGS@ -I@srcroot@src -I@objroot@src
 CFLAGS := @CFLAGS@ -fPIC -DPIC
 ifeq (macho, @abi@)
 CFLAGS += -dynamic
@@ -33,17 +33,19 @@
 endif
 REV := 0
 
-# List of files to be installed.
+# Lists of files.
 BINS := @bins@
-CHDRS := @srcroot@src/jemalloc.h @objroot@src/jemalloc_defs.h
+CHDRS := @objroot@src/jemalloc@install_suffix@.h \
+	@objroot@src/jemalloc_defs@install_suffix@.h
 CSRCS := @srcroot@src/jemalloc.c @srcroot@src/jemalloc_arena.c \
 	@srcroot@src/jemalloc_base.c @srcroot@src/jemalloc_chunk.c \
 	@srcroot@src/jemalloc_extent.c @srcroot@src/jemalloc_huge.c \
 	@srcroot@src/jemalloc_mutex.c @srcroot@src/jemalloc_stats.c \
 	@srcroot@src/jemalloc_tcache.c @srcroot@src/jemalloc_trace.c
-DSOS := @objroot@lib/libjemalloc.so.$(REV) @objroot@lib/libjemalloc.so \
-	@objroot@lib/libjemalloc_pic.a
-MAN3 := @objroot@doc/jemalloc.3
+DSOS := @objroot@lib/libjemalloc@install_suffix@.so.$(REV) \
+	@objroot@lib/libjemalloc@install_suffix@.so \
+	@objroot@lib/libjemalloc@install_suffix@_pic.a
+MAN3 := @objroot@doc/jemalloc@install_suffix@.3
 
 .PHONY: all dist install check clean distclean relclean
 
@@ -62,16 +64,16 @@
 $(DSOS): $(CSRCS:@srcroot@%.c=@objroot@%.o)
 	@mkdir -p $(@D)
 	$(CC) -shared -o $@ $+ $(LDFLAGS) $(LIBS)
-	ln -sf libjemalloc.so.$(REV) lib/libjemalloc.so
-	ar crus @objroot@lib/libjemalloc_pic.a $+
+	ln -sf libjemalloc@install_suffix@.so.$(REV) lib/libjemalloc@install_suffix@.so
+	ar crus @objroot@lib/libjemalloc@install_suffix@_pic.a $+
 
 bins: $(BINS)
 
-@objroot@bin/mtrgraph: @objroot@src/mtrgraph.o
+@objroot@bin/mtrgraph@install_suffix@: @objroot@src/mtrgraph.o
 	@mkdir -p $(@D)
 	$(CC) -o $@ $< $(LDFLAGS) $(LIBS) $(GDLIBS)
 
-@objroot@bin/%: @objroot@src/%.o
+@objroot@bin/%@install_suffix@: @objroot@src/%.o
 	@mkdir -p $(@D)
 	$(CC) -o $@ $< $(LDFLAGS) $(LIBS)
 
@@ -87,11 +89,10 @@
 	install -m 644 $$h $(INCLUDEDIR); \
 done
 	install -d $(LIBDIR)
-	@for s in $(DSOS); do \
-	echo "install -m 755 $$s $(LIBDIR)"; \
-	install -m 755 $$s $(LIBDIR); \
-done
-	install -d $(MANDIR)
+	install -m 755 @objroot@lib/libjemalloc@install_suffix@.so.$(REV) $(LIBDIR)
+	ln -sf libjemalloc@install_suffix@.so.$(REV) $(LIBDIR)/libjemalloc@install_suffix@.so
+	install -m 755 @objroot@lib/libjemalloc@install_suffix@_pic.a $(LIBDIR)
+	install -d $(MANDIR)/man3
 	@for m in $(MAN3); do \
 	echo "install -m 644 $$m $(MANDIR)/man3"; \
 	install -m 644 $$m $(MANDIR)/man3; \
@@ -112,8 +113,8 @@
 	rm -f @objroot@config.status
 	rm -f @objroot@cfghdrs.stamp
 	rm -f @objroot@cfgoutputs.stamp
-	rm -f @cfghdrs@
-	rm -f @cfgoutputs@
+	rm -f @cfghdrs_out@
+	rm -f @cfgoutputs_out@
 
 relclean: distclean
 	rm -rf @objroot@autom4te.cache
@@ -133,8 +134,7 @@
 @srcroot@cfghdrs.stamp.in : @srcroot@configure.ac
 	echo stamp > @srcroot@cfghdrs.stamp.in
 
-@objroot@cfghdrs.stamp : $(patsubst %, %.in, @cfghdrs@) \
-			 @srcroot@configure
+@objroot@cfghdrs.stamp : @cfghdrs_in@ @srcroot@configure
 	./@objroot@config.status
 	@touch $@
 
@@ -144,8 +144,7 @@
 @srcroot@cfgoutputs.stamp.in : @srcroot@configure.ac
 	echo stamp > @srcroot@cfgoutputs.stamp.in
 
-@objroot@cfgoutputs.stamp : $(patsubst %, @srcroot@%.in, @cfgoutputs@) \
-			    @srcroot@configure
+@objroot@cfgoutputs.stamp : @cfgoutputs_in@ @srcroot@configure
 	./@objroot@config.status
 	@touch $@
 
diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac
index 07adeb1..f37c2e8 100644
--- a/jemalloc/configure.ac
+++ b/jemalloc/configure.ac
@@ -80,9 +80,6 @@
 MANDIR=`eval echo $MANDIR`
 AC_SUBST([MANDIR])
 
-cfgoutputs="Makefile doc/jemalloc.3"
-cfghdrs="src/jemalloc_defs.h"
-
 dnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
 dnl just prevent autoconf from molesting CFLAGS.
 CFLAGS=$CFLAGS
@@ -246,20 +243,49 @@
 dnl Do not prefix public APIs by default.
 AC_ARG_WITH([jemalloc_prefix],
   [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
-if test "x$with_jemalloc_prefix" = "xno" ; then
-  JEMALLOC_PREFIX=
-else
-  JEMALLOC_PREFIX="$with_jemalloc_prefix"
-fi,
-  JEMALLOC_PREFIX=
+  [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
+  [JEMALLOC_PREFIX=]
 )
 if test "x$JEMALLOC_PREFIX" != "x" ; then
   AC_DEFINE([JEMALLOC_PREFIX], [ ])
-  jemalloc_prefix=$JEMALLOC_PREFIX
+  jemalloc_prefix="$JEMALLOC_PREFIX"
   AC_SUBST([jemalloc_prefix])
   AC_DEFINE_UNQUOTED([JEMALLOC_P(string_that_no_one_should_want_to_use_as_a_jemalloc_API_prefix)], [${JEMALLOC_PREFIX}##string_that_no_one_should_want_to_use_as_a_jemalloc_API_prefix])
 fi
 
+dnl Do not add suffix to installed files by default.
+AC_ARG_WITH([install_suffix],
+  [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
+  [INSTALL_SUFFIX="$with_install_suffix"],
+  [INSTALL_SUFFIX=]
+)
+install_suffix="$INSTALL_SUFFIX"
+AC_SUBST([install_suffix])
+
+cfgoutputs_in="Makefile doc/jemalloc.3.in"
+cfgoutputs_in="${cfgoutputs_in} src/jemalloc.h.in"
+cfgoutputs_in="${cfgoutputs_in} src/internal/jemalloc_internal.h.in"
+
+cfgoutputs_out="Makefile doc/jemalloc${install_suffix}.3"
+cfgoutputs_out="${cfgoutputs_out} src/jemalloc${install_suffix}.h"
+cfgoutputs_out="${cfgoutputs_out} src/internal/jemalloc_internal.h"
+
+cfgoutputs_tup="Makefile doc/jemalloc${install_suffix}.3:doc/jemalloc.3.in"
+cfgoutputs_tup="${cfgoutputs_tup} src/jemalloc${install_suffix}.h:src/jemalloc.h.in"
+cfgoutputs_tup="${cfgoutputs_tup} src/internal/jemalloc_internal.h"
+
+cfghdrs_in="src/jemalloc_defs.h.in"
+cfghdrs_in="${cfghdrs_in} src/internal/mtrgraph_defs.h.in"
+cfghdrs_in="${cfghdrs_in} src/internal/mtrplay_defs.h.in"
+
+cfghdrs_out="src/jemalloc_defs${install_suffix}.h"
+cfghdrs_out="${cfghdrs_out} src/internal/mtrgraph_defs.h"
+cfghdrs_out="${cfghdrs_out} src/internal/mtrplay_defs.h"
+
+cfghdrs_tup="src/jemalloc_defs${install_suffix}.h:src/jemalloc_defs.h.in"
+cfghdrs_tup="${cfghdrs_tup} src/internal/mtrgraph_defs.h"
+cfghdrs_tup="${cfghdrs_tup} src/internal/mtrplay_defs.h"
+
 dnl Do not compile with debugging by default.
 AC_ARG_ENABLE([debug],
   [AS_HELP_STRING([--enable-debug], [Build debugging code])],
@@ -577,7 +603,8 @@
 
 dnl ============================================================================
 dnl Configure libgd for mtrgraph.
-bins="${objroot}bin/jemtr2mtr ${objroot}bin/mtrplay"
+bins="${objroot}bin/jemtr2mtr${install_suffix}"
+bins="${bins} ${objroot}bin/mtrplay${install_suffix}"
 GDLIBS=""
 
 have_libgd="yes"
@@ -590,7 +617,7 @@
 AC_CHECK_LIB([gd], [gdImageCreate], [GDLIBS="-lgd"], [have_libgd="no"])
 
 if test "x${have_libgd}" = "xyes" ; then
-  bins="${bins} ${objroot}bin/mtrgraph"
+  bins="${bins} ${objroot}bin/mtrgraph${install_suffix}"
 fi
 AC_SUBST([bins])
 AC_SUBST([GDLIBS])
@@ -600,13 +627,15 @@
 AC_HEADER_STDBOOL
 
 dnl Process .in files.
-AC_SUBST([cfghdrs])
-AC_CONFIG_HEADERS([$cfghdrs cfghdrs.stamp])
+AC_SUBST([cfghdrs_in])
+AC_SUBST([cfghdrs_out])
+AC_CONFIG_HEADERS([$cfghdrs_tup cfghdrs.stamp])
 
 dnl ============================================================================
 dnl Generate outputs.
-AC_CONFIG_FILES([$cfgoutputs cfgoutputs.stamp])
-AC_SUBST([cfgoutputs])
+AC_CONFIG_FILES([$cfgoutputs_tup cfgoutputs.stamp])
+AC_SUBST([cfgoutputs_in])
+AC_SUBST([cfgoutputs_out])
 AC_OUTPUT
 
 dnl ============================================================================
@@ -636,6 +665,7 @@
 AC_MSG_RESULT([bins               : ${bins}])
 AC_MSG_RESULT([])
 AC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
+AC_MSG_RESULT([install_suffix     : ${install_suffix}])
 AC_MSG_RESULT([autogen            : ${enable_autogen}])
 AC_MSG_RESULT([debug              : ${enable_debug}])
 AC_MSG_RESULT([stats              : ${enable_stats}])
diff --git a/jemalloc/doc/jemalloc.3.in b/jemalloc/doc/jemalloc.3.in
index f55325e..ca8deb1 100644
--- a/jemalloc/doc/jemalloc.3.in
+++ b/jemalloc/doc/jemalloc.3.in
@@ -38,7 +38,7 @@
 .\"     @(#)malloc.3	8.1 (Berkeley) 6/4/93
 .\" $FreeBSD: head/lib/libc/stdlib/malloc.3 182225 2008-08-27 02:00:53Z jasone $
 .\"
-.Dd January 3, 2010
+.Dd January 17, 2010
 .Dt JEMALLOC 3
 .Os
 .Sh NAME
@@ -46,10 +46,10 @@
 @roff_no_tcache@.Nm @jemalloc_prefix@malloc , @jemalloc_prefix@calloc , @jemalloc_prefix@posix_memalign , @jemalloc_prefix@realloc , @jemalloc_prefix@free , @jemalloc_prefix@malloc_usable_size , @jemalloc_prefix@malloc_stats_print
 .Nd general purpose memory allocation functions
 .Sh LIBRARY
-.Lb libjemalloc
+.Lb libjemalloc@install_suffix@
 .Sh SYNOPSIS
 .In stdlib.h
-.In jemalloc.h
+.In jemalloc@install_suffix@.h
 .Ft void *
 .Fn @jemalloc_prefix@malloc "size_t size"
 .Ft void *
diff --git a/jemalloc/src/jemalloc_arena.h b/jemalloc/src/internal/jemalloc_arena.h
similarity index 100%
rename from jemalloc/src/jemalloc_arena.h
rename to jemalloc/src/internal/jemalloc_arena.h
diff --git a/jemalloc/src/jemalloc_base.h b/jemalloc/src/internal/jemalloc_base.h
similarity index 100%
rename from jemalloc/src/jemalloc_base.h
rename to jemalloc/src/internal/jemalloc_base.h
diff --git a/jemalloc/src/jemalloc_chunk.h b/jemalloc/src/internal/jemalloc_chunk.h
similarity index 100%
rename from jemalloc/src/jemalloc_chunk.h
rename to jemalloc/src/internal/jemalloc_chunk.h
diff --git a/jemalloc/src/jemalloc_extent.h b/jemalloc/src/internal/jemalloc_extent.h
similarity index 100%
rename from jemalloc/src/jemalloc_extent.h
rename to jemalloc/src/internal/jemalloc_extent.h
diff --git a/jemalloc/src/jemalloc_huge.h b/jemalloc/src/internal/jemalloc_huge.h
similarity index 100%
rename from jemalloc/src/jemalloc_huge.h
rename to jemalloc/src/internal/jemalloc_huge.h
diff --git a/jemalloc/src/jemalloc_internal.h b/jemalloc/src/internal/jemalloc_internal.h.in
similarity index 85%
rename from jemalloc/src/jemalloc_internal.h
rename to jemalloc/src/internal/jemalloc_internal.h.in
index 5be40da..139c0e7 100644
--- a/jemalloc/src/jemalloc_internal.h
+++ b/jemalloc/src/internal/jemalloc_internal.h.in
@@ -24,16 +24,16 @@
 #include <pthread.h>
 
 #define	JEMALLOC_MANGLE
-#include "jemalloc.h"
+#include "../jemalloc@install_suffix@.h"
 
 #ifdef JEMALLOC_LAZY_LOCK
 #include <dlfcn.h>
 #endif
 
-#include "rb.h"
+#include "internal/rb.h"
 #if (defined(JEMALLOC_TCACHE) && defined(JEMALLOC_STATS))
-#include "qr.h"
-#include "ql.h"
+#include "internal/qr.h"
+#include "internal/ql.h"
 #endif
 
 extern void	(*JEMALLOC_P(malloc_message))(const char *p1, const char *p2,
@@ -168,29 +168,29 @@
 #define	PAGE_CEILING(s)							\
 	(((s) + PAGE_MASK) & ~PAGE_MASK)
 
-#include "jemalloc_stats.h"
-#include "jemalloc_mutex.h"
-#include "jemalloc_extent.h"
-#include "jemalloc_arena.h"
-#include "jemalloc_base.h"
-#include "jemalloc_chunk.h"
-#include "jemalloc_huge.h"
-#include "jemalloc_tcache.h"
-#include "jemalloc_trace.h"
+#include "internal/jemalloc_stats.h"
+#include "internal/jemalloc_mutex.h"
+#include "internal/jemalloc_extent.h"
+#include "internal/jemalloc_arena.h"
+#include "internal/jemalloc_base.h"
+#include "internal/jemalloc_chunk.h"
+#include "internal/jemalloc_huge.h"
+#include "internal/jemalloc_tcache.h"
+#include "internal/jemalloc_trace.h"
 
 #undef JEMALLOC_H_TYPES
 /******************************************************************************/
 #define JEMALLOC_H_STRUCTS
 
-#include "jemalloc_stats.h"
-#include "jemalloc_mutex.h"
-#include "jemalloc_extent.h"
-#include "jemalloc_arena.h"
-#include "jemalloc_base.h"
-#include "jemalloc_chunk.h"
-#include "jemalloc_huge.h"
-#include "jemalloc_tcache.h"
-#include "jemalloc_trace.h"
+#include "internal/jemalloc_stats.h"
+#include "internal/jemalloc_mutex.h"
+#include "internal/jemalloc_extent.h"
+#include "internal/jemalloc_arena.h"
+#include "internal/jemalloc_base.h"
+#include "internal/jemalloc_chunk.h"
+#include "internal/jemalloc_huge.h"
+#include "internal/jemalloc_tcache.h"
+#include "internal/jemalloc_trace.h"
 
 #undef JEMALLOC_H_STRUCTS
 /******************************************************************************/
@@ -238,26 +238,26 @@
 arena_t	*choose_arena_hard(void);
 #endif
 
-#include "jemalloc_stats.h"
-#include "jemalloc_mutex.h"
-#include "jemalloc_extent.h"
-#include "jemalloc_arena.h"
-#include "jemalloc_base.h"
-#include "jemalloc_chunk.h"
-#include "jemalloc_huge.h"
-#include "jemalloc_tcache.h"
-#include "jemalloc_trace.h"
+#include "internal/jemalloc_stats.h"
+#include "internal/jemalloc_mutex.h"
+#include "internal/jemalloc_extent.h"
+#include "internal/jemalloc_arena.h"
+#include "internal/jemalloc_base.h"
+#include "internal/jemalloc_chunk.h"
+#include "internal/jemalloc_huge.h"
+#include "internal/jemalloc_tcache.h"
+#include "internal/jemalloc_trace.h"
 
 #undef JEMALLOC_H_EXTERNS
 /******************************************************************************/
 #define JEMALLOC_H_INLINES
 
-#include "jemalloc_stats.h"
-#include "jemalloc_mutex.h"
-#include "jemalloc_extent.h"
-#include "jemalloc_base.h"
-#include "jemalloc_chunk.h"
-#include "jemalloc_huge.h"
+#include "internal/jemalloc_stats.h"
+#include "internal/jemalloc_mutex.h"
+#include "internal/jemalloc_extent.h"
+#include "internal/jemalloc_base.h"
+#include "internal/jemalloc_chunk.h"
+#include "internal/jemalloc_huge.h"
 
 #ifndef JEMALLOC_ENABLE_INLINE
 void	malloc_write4(const char *p1, const char *p2, const char *p3,
@@ -346,9 +346,9 @@
 }
 #endif
 
-#include "jemalloc_tcache.h"
-#include "jemalloc_arena.h"
-#include "jemalloc_trace.h"
+#include "internal/jemalloc_tcache.h"
+#include "internal/jemalloc_arena.h"
+#include "internal/jemalloc_trace.h"
 
 #ifndef JEMALLOC_ENABLE_INLINE
 void	*imalloc(size_t size);
diff --git a/jemalloc/src/jemalloc_mutex.h b/jemalloc/src/internal/jemalloc_mutex.h
similarity index 100%
rename from jemalloc/src/jemalloc_mutex.h
rename to jemalloc/src/internal/jemalloc_mutex.h
diff --git a/jemalloc/src/jemalloc_stats.h b/jemalloc/src/internal/jemalloc_stats.h
similarity index 100%
rename from jemalloc/src/jemalloc_stats.h
rename to jemalloc/src/internal/jemalloc_stats.h
diff --git a/jemalloc/src/jemalloc_tcache.h b/jemalloc/src/internal/jemalloc_tcache.h
similarity index 100%
rename from jemalloc/src/jemalloc_tcache.h
rename to jemalloc/src/internal/jemalloc_tcache.h
diff --git a/jemalloc/src/jemalloc_trace.h b/jemalloc/src/internal/jemalloc_trace.h
similarity index 100%
rename from jemalloc/src/jemalloc_trace.h
rename to jemalloc/src/internal/jemalloc_trace.h
diff --git a/jemalloc/src/internal/mtrgraph_defs.h.in b/jemalloc/src/internal/mtrgraph_defs.h.in
new file mode 100644
index 0000000..7a81e3c
--- /dev/null
+++ b/jemalloc/src/internal/mtrgraph_defs.h.in
@@ -0,0 +1,14 @@
+#ifndef MTRGRAPH_DEFS_H_
+#define	MTRGRAPH_DEFS_H_
+
+/* Defined if __attribute__((...)) syntax is supported. */
+#undef JEMALLOC_HAVE_ATTR
+#ifdef JEMALLOC_HAVE_ATTR
+#  define JEMALLOC_ATTR(s) __attribute__((s))
+#else
+#  define JEMALLOC_ATTR(s)
+#endif
+
+#undef JEMALLOC_DEBUG
+
+#endif /* MTRGRAPH_DEFS_H_ */
diff --git a/jemalloc/src/internal/mtrplay_defs.h.in b/jemalloc/src/internal/mtrplay_defs.h.in
new file mode 100644
index 0000000..8b62625
--- /dev/null
+++ b/jemalloc/src/internal/mtrplay_defs.h.in
@@ -0,0 +1,14 @@
+#ifndef MTRPLAY_DEFS_H_
+#define	MTRPLAY_DEFS_H_
+
+/* Defined if __attribute__((...)) syntax is supported. */
+#undef JEMALLOC_HAVE_ATTR
+#ifdef JEMALLOC_HAVE_ATTR
+#  define JEMALLOC_ATTR(s) __attribute__((s))
+#else
+#  define JEMALLOC_ATTR(s)
+#endif
+
+#undef JEMALLOC_DEBUG
+
+#endif /* MTRPLAY_DEFS_H_ */
diff --git a/jemalloc/src/ql.h b/jemalloc/src/internal/ql.h
similarity index 100%
rename from jemalloc/src/ql.h
rename to jemalloc/src/internal/ql.h
diff --git a/jemalloc/src/qr.h b/jemalloc/src/internal/qr.h
similarity index 100%
rename from jemalloc/src/qr.h
rename to jemalloc/src/internal/qr.h
diff --git a/jemalloc/src/rb.h b/jemalloc/src/internal/rb.h
similarity index 100%
rename from jemalloc/src/rb.h
rename to jemalloc/src/internal/rb.h
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c
index 8a0d97a..7a9f906 100644
--- a/jemalloc/src/jemalloc.c
+++ b/jemalloc/src/jemalloc.c
@@ -90,7 +90,7 @@
  */
 
 #define	JEMALLOC_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc.h b/jemalloc/src/jemalloc.h.in
similarity index 94%
rename from jemalloc/src/jemalloc.h
rename to jemalloc/src/jemalloc.h.in
index 71c46b6..f2a89f5 100644
--- a/jemalloc/src/jemalloc.h
+++ b/jemalloc/src/jemalloc.h.in
@@ -4,7 +4,7 @@
 extern "C" {
 #endif
 
-#include "jemalloc_defs.h"
+#include "jemalloc_defs@install_suffix@.h"
 #ifndef JEMALLOC_P
 #  define JEMALLOC_P(s) s
 #endif
diff --git a/jemalloc/src/jemalloc_arena.c b/jemalloc/src/jemalloc_arena.c
index 5c8ea23..0f031c1 100644
--- a/jemalloc/src/jemalloc_arena.c
+++ b/jemalloc/src/jemalloc_arena.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_ARENA_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc_base.c b/jemalloc/src/jemalloc_base.c
index 83499f6..af83cec 100644
--- a/jemalloc/src/jemalloc_base.c
+++ b/jemalloc/src/jemalloc_base.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_BASE_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 #ifdef JEMALLOC_STATS
 size_t	base_mapped;
diff --git a/jemalloc/src/jemalloc_chunk.c b/jemalloc/src/jemalloc_chunk.c
index caa941a..9cd0c21 100644
--- a/jemalloc/src/jemalloc_chunk.c
+++ b/jemalloc/src/jemalloc_chunk.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_CHUNK_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc_extent.c b/jemalloc/src/jemalloc_extent.c
index 8f287f7..cbe7c4b 100644
--- a/jemalloc/src/jemalloc_extent.c
+++ b/jemalloc/src/jemalloc_extent.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_EXTENT_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 
diff --git a/jemalloc/src/jemalloc_huge.c b/jemalloc/src/jemalloc_huge.c
index 6d71f65..b325927 100644
--- a/jemalloc/src/jemalloc_huge.c
+++ b/jemalloc/src/jemalloc_huge.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_HUGE_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc_mutex.c b/jemalloc/src/jemalloc_mutex.c
index 26292e5..5e3cab3 100644
--- a/jemalloc/src/jemalloc_mutex.c
+++ b/jemalloc/src/jemalloc_mutex.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_MUTEX_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc_stats.c b/jemalloc/src/jemalloc_stats.c
index 2db7740..e39bcfe 100644
--- a/jemalloc/src/jemalloc_stats.c
+++ b/jemalloc/src/jemalloc_stats.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_STATS_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc_tcache.c b/jemalloc/src/jemalloc_tcache.c
index 1257703..fe572eb 100644
--- a/jemalloc/src/jemalloc_tcache.c
+++ b/jemalloc/src/jemalloc_tcache.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_TCACHE_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 #ifdef JEMALLOC_TCACHE
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/jemalloc_trace.c b/jemalloc/src/jemalloc_trace.c
index 8163019..657a096 100644
--- a/jemalloc/src/jemalloc_trace.c
+++ b/jemalloc/src/jemalloc_trace.c
@@ -1,5 +1,5 @@
 #define	JEMALLOC_TRACE_C_
-#include "jemalloc_internal.h"
+#include "internal/jemalloc_internal.h"
 #ifdef JEMALLOC_TRACE
 /******************************************************************************/
 /* Data. */
diff --git a/jemalloc/src/mtrgraph.c b/jemalloc/src/mtrgraph.c
index cc17be2..c5f9dd3 100644
--- a/jemalloc/src/mtrgraph.c
+++ b/jemalloc/src/mtrgraph.c
@@ -15,12 +15,12 @@
 #include <gdfontl.h>
 #include <gdfontg.h>
 
-#include "jemalloc.h"
+#include "internal/mtrgraph_defs.h"
 #ifndef JEMALLOC_DEBUG
 #  define NDEBUG
 #endif
 #include <assert.h>
-#include "rb.h"
+#include "internal/rb.h"
 
 typedef struct
 {
diff --git a/jemalloc/src/mtrplay.c b/jemalloc/src/mtrplay.c
index 776ca26..134930f 100644
--- a/jemalloc/src/mtrplay.c
+++ b/jemalloc/src/mtrplay.c
@@ -16,12 +16,12 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 
-#include "jemalloc_defs.h"
+#include "internal/mtrplay_defs.h"
 #ifndef JEMALLOC_DEBUG
 #  define NDEBUG
 #endif
 #include <assert.h>
-#include "rb.h"
+#include "internal/rb.h"
 
 typedef struct record_s record_t;
 struct record_s {