Add configure tests for CFLAGS settings.

Add configure test for __asm__ syntax.

Add configure test for __attribute__ syntax.
diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac
index e0bf8f5..1b59f83 100644
--- a/jemalloc/configure.ac
+++ b/jemalloc/configure.ac
@@ -1,6 +1,45 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT([Makefile.in])
 
+dnl ============================================================================
+dnl Custom macro definitions.
+
+dnl JE_CFLAGS_APPEND(cflag)
+AC_DEFUN([JE_CFLAGS_APPEND],
+[
+AC_MSG_CHECKING([whether compiler supports $1])
+TCFLAGS="${CFLAGS}"
+if test "x${CFLAGS}" = "x" ; then
+  CFLAGS="$1"
+else
+  CFLAGS="${CFLAGS} $1"
+fi
+AC_RUN_IFELSE([AC_LANG_PROGRAM(
+[[
+]], [[
+    return 0;
+]])],
+              AC_MSG_RESULT([yes]),
+              AC_MSG_RESULT([no])
+              [CFLAGS="${TCFLAGS}"]
+)
+])
+
+dnl JE_COMPILABLE(label, hcode, mcode, rvar)
+AC_DEFUN([JE_COMPILABLE],
+[
+AC_MSG_CHECKING([whether $1 is compilable])
+AC_RUN_IFELSE([AC_LANG_PROGRAM(
+[$2], [$3])],
+              AC_MSG_RESULT([yes])
+              [$4="yes"],
+              AC_MSG_RESULT([no])
+              [$4="no"]
+)
+])
+
+dnl ============================================================================
+
 srcroot=$srcdir
 if test "x${srcroot}" = "x." ; then
   srcroot=""
@@ -44,23 +83,22 @@
 cfgoutputs="Makefile doc/jemalloc.3"
 cfghdrs="src/jemalloc_defs.h"
 
-dnl If CFLAGS isn't defined and using gcc, set CFLAGS to something reasonable.
-dnl Otherwise, just prevent autoconf from molesting CFLAGS.
+dnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
+dnl just prevent autoconf from molesting CFLAGS.
 CFLAGS=$CFLAGS
 AC_PROG_CC
 if test "x$CFLAGS" = "x" ; then
   no_CFLAGS="yes"
-fi
-if test "x$no_CFLAGS" = "xyes" -a "x$GCC" = "xyes" ; then
- CFLAGS="-std=gnu99 -Wall -pipe -g3"
+  JE_CFLAGS_APPEND([-std=gnu99])
+  JE_CFLAGS_APPEND([-Wall])
+  JE_CFLAGS_APPEND([-pipe])
+  JE_CFLAGS_APPEND([-g3])
+  JE_CFLAGS_APPEND([-march=native])
+  JE_CFLAGS_APPEND([-ftls-model=initial-exec])
 fi
 dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
 if test "x$EXTRA_CFLAGS" != "x" ; then
-  CFLAGS="$CFLAGS $EXTRA_CFLAGS"
-fi
-dnl XXX These flags only work with newer versions of gcc.
-if test "x$GCC" = "xyes" ; then
-  CFLAGS="${CFLAGS} -march=native -ftls-model=initial-exec"
+  JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
 fi
 AC_PROG_CPP
 
@@ -82,16 +120,34 @@
   i[[345]]86)
 	;;
   i686)
-	CPU_SPINWAIT='__asm__ volatile("pause")'
+	JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
+	              [asm])
+	if test "x${asm}" = "xyes" ; then
+	    CPU_SPINWAIT='__asm__ volatile("pause")'
+	fi
 	;;
   x86_64)
-	CPU_SPINWAIT='__asm__ volatile("pause")'
+	JE_COMPILABLE([__asm__ syntax], [],
+	              [[__asm__ volatile("pause"); return 0;]], [asm])
+	if test "x${asm}" = "xyes" ; then
+	    CPU_SPINWAIT='__asm__ volatile("pause")'
+	fi
 	;;
   *)
 	;;
 esac
 AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
 
+JE_COMPILABLE([__attribute__ syntax],
+              [static __attribute__((unused)) void foo(void){}],
+              [],
+              [attribute])
+if test "x${attribute}" = "xyes" ; then
+  AC_DEFINE_UNQUOTED([JEMALLOC_UNUSED], [__attribute__((unused))])
+else
+  AC_DEFINE_UNQUOTED([JEMALLOC_UNUSED], [])
+fi
+
 dnl Platform-specific settings.  abi and RPATH can probably be determined
 dnl programmatically, but doing so is error-prone, which makes it generally
 dnl not worth the trouble.
@@ -197,10 +253,16 @@
 dnl Only optimize if not debugging.
 if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
   dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
-  if test "x$GCC" = "xyes" ; then
-    echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || CFLAGS="$CFLAGS -O3 -funroll-loops -fomit-frame-pointer"
-  else
-    echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || CFLAGS="$CFLAGS -O"
+  optimize="no"
+  echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
+  if test "x${optimize}" = "xyes" ; then
+    if test "x$GCC" = "xyes" ; then
+      JE_CFLAGS_APPEND([-O3])
+      JE_CFLAGS_APPEND([-funroll-loops])
+      JE_CFLAGS_APPEND([-fomit-frame-pointer])
+    else
+      JE_CFLAGS_APPEND([-O])
+    fi
   fi
 fi
 
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c
index 01fb878..378d4c8 100644
--- a/jemalloc/src/jemalloc.c
+++ b/jemalloc/src/jemalloc.c
@@ -1799,7 +1799,7 @@
 }
 
 /* Wrap red-black tree macros in functions. */
-rb_wrap(static __attribute__((unused)), extent_tree_szad_, extent_tree_t, extent_node_t,
+rb_wrap(static JEMALLOC_UNUSED, extent_tree_szad_, extent_tree_t, extent_node_t,
     link_szad, extent_szad_comp)
 #endif
 
@@ -1813,7 +1813,7 @@
 }
 
 /* Wrap red-black tree macros in functions. */
-rb_wrap(static __attribute__((unused)), extent_tree_ad_, extent_tree_t, extent_node_t, link_ad,
+rb_wrap(static JEMALLOC_UNUSED, extent_tree_ad_, extent_tree_t, extent_node_t, link_ad,
     extent_ad_comp)
 
 /*
@@ -2361,7 +2361,7 @@
 }
 
 /* Wrap red-black tree macros in functions. */
-rb_wrap(static __attribute__((unused)), arena_chunk_tree_dirty_, arena_chunk_tree_t,
+rb_wrap(static JEMALLOC_UNUSED, arena_chunk_tree_dirty_, arena_chunk_tree_t,
     arena_chunk_t, link_dirty, arena_chunk_comp)
 
 static inline int
@@ -2377,7 +2377,7 @@
 }
 
 /* Wrap red-black tree macros in functions. */
-rb_wrap(static __attribute__((unused)), arena_run_tree_, arena_run_tree_t, arena_chunk_map_t,
+rb_wrap(static JEMALLOC_UNUSED, arena_run_tree_, arena_run_tree_t, arena_chunk_map_t,
     link, arena_run_comp)
 
 static inline int
@@ -2409,7 +2409,7 @@
 }
 
 /* Wrap red-black tree macros in functions. */
-rb_wrap(static __attribute__((unused)), arena_avail_tree_, arena_avail_tree_t,
+rb_wrap(static JEMALLOC_UNUSED, arena_avail_tree_, arena_avail_tree_t,
     arena_chunk_map_t, link, arena_avail_comp)
 
 static inline void *
diff --git a/jemalloc/src/jemalloc_defs.h.in b/jemalloc/src/jemalloc_defs.h.in
index eae3d0a..9ee1dca 100644
--- a/jemalloc/src/jemalloc_defs.h.in
+++ b/jemalloc/src/jemalloc_defs.h.in
@@ -43,6 +43,13 @@
 #undef CPU_SPINWAIT
 
 /*
+ * Attribute with which to mark potentially unused functions.  For gcc this is:
+ *
+ *   __attribute__((unused))
+ */
+#undef JEMALLOC_UNUSED
+
+/*
  * JEMALLOC_DEBUG enables assertions and other sanity checks, and disables
  * inline functions.
  */