Home | History | Annotate | Download | only in jemalloc_new
      1 dnl Process this file with autoconf to produce a configure script.
      2 AC_PREREQ(2.68)
      3 AC_INIT([Makefile.in])
      4 
      5 AC_CONFIG_AUX_DIR([build-aux])
      6 
      7 dnl ============================================================================
      8 dnl Custom macro definitions.
      9 
     10 dnl JE_CONCAT_VVV(r, a, b)
     11 dnl
     12 dnl Set $r to the concatenation of $a and $b, with a space separating them iff
     13 dnl both $a and $b are non-empty.
     14 AC_DEFUN([JE_CONCAT_VVV],
     15 if test "x[$]{$2}" = "x" -o "x[$]{$3}" = "x" ; then
     16   $1="[$]{$2}[$]{$3}"
     17 else
     18   $1="[$]{$2} [$]{$3}"
     19 fi
     20 )
     21 
     22 dnl JE_APPEND_VS(a, b)
     23 dnl
     24 dnl Set $a to the concatenation of $a and b, with a space separating them iff
     25 dnl both $a and b are non-empty.
     26 AC_DEFUN([JE_APPEND_VS],
     27   T_APPEND_V=$2
     28   JE_CONCAT_VVV($1, $1, T_APPEND_V)
     29 )
     30 
     31 CONFIGURE_CFLAGS=
     32 SPECIFIED_CFLAGS="${CFLAGS}"
     33 dnl JE_CFLAGS_ADD(cflag)
     34 dnl
     35 dnl CFLAGS is the concatenation of CONFIGURE_CFLAGS and SPECIFIED_CFLAGS
     36 dnl (ignoring EXTRA_CFLAGS, which does not impact configure tests.  This macro
     37 dnl appends to CONFIGURE_CFLAGS and regenerates CFLAGS.
     38 AC_DEFUN([JE_CFLAGS_ADD],
     39 [
     40 AC_MSG_CHECKING([whether compiler supports $1])
     41 T_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
     42 JE_APPEND_VS(CONFIGURE_CFLAGS, $1)
     43 JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
     44 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
     45 [[
     46 ]], [[
     47     return 0;
     48 ]])],
     49               [je_cv_cflags_added=$1]
     50               AC_MSG_RESULT([yes]),
     51               [je_cv_cflags_added=]
     52               AC_MSG_RESULT([no])
     53               [CONFIGURE_CFLAGS="${T_CONFIGURE_CFLAGS}"]
     54 )
     55 JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
     56 ])
     57 
     58 dnl JE_CFLAGS_SAVE()
     59 dnl JE_CFLAGS_RESTORE()
     60 dnl
     61 dnl Save/restore CFLAGS.  Nesting is not supported.
     62 AC_DEFUN([JE_CFLAGS_SAVE],
     63 SAVED_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
     64 )
     65 AC_DEFUN([JE_CFLAGS_RESTORE],
     66 CONFIGURE_CFLAGS="${SAVED_CONFIGURE_CFLAGS}"
     67 JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
     68 )
     69 
     70 CONFIGURE_CXXFLAGS=
     71 SPECIFIED_CXXFLAGS="${CXXFLAGS}"
     72 dnl JE_CXXFLAGS_ADD(cxxflag)
     73 AC_DEFUN([JE_CXXFLAGS_ADD],
     74 [
     75 AC_MSG_CHECKING([whether compiler supports $1])
     76 T_CONFIGURE_CXXFLAGS="${CONFIGURE_CXXFLAGS}"
     77 JE_APPEND_VS(CONFIGURE_CXXFLAGS, $1)
     78 JE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
     79 AC_LANG_PUSH([C++])
     80 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
     81 [[
     82 ]], [[
     83     return 0;
     84 ]])],
     85               [je_cv_cxxflags_added=$1]
     86               AC_MSG_RESULT([yes]),
     87               [je_cv_cxxflags_added=]
     88               AC_MSG_RESULT([no])
     89               [CONFIGURE_CXXFLAGS="${T_CONFIGURE_CXXFLAGS}"]
     90 )
     91 AC_LANG_POP([C++])
     92 JE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
     93 ])
     94 
     95 dnl JE_COMPILABLE(label, hcode, mcode, rvar)
     96 dnl
     97 dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
     98 dnl cause failure.
     99 AC_DEFUN([JE_COMPILABLE],
    100 [
    101 AC_CACHE_CHECK([whether $1 is compilable],
    102                [$4],
    103                [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
    104                                                 [$3])],
    105                                [$4=yes],
    106                                [$4=no])])
    107 ])
    108 
    109 dnl ============================================================================
    110 
    111 CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
    112 AC_SUBST([CONFIG])
    113 
    114 dnl Library revision.
    115 rev=2
    116 AC_SUBST([rev])
    117 
    118 srcroot=$srcdir
    119 if test "x${srcroot}" = "x." ; then
    120   srcroot=""
    121 else
    122   srcroot="${srcroot}/"
    123 fi
    124 AC_SUBST([srcroot])
    125 abs_srcroot="`cd \"${srcdir}\"; pwd`/"
    126 AC_SUBST([abs_srcroot])
    127 
    128 objroot=""
    129 AC_SUBST([objroot])
    130 abs_objroot="`pwd`/"
    131 AC_SUBST([abs_objroot])
    132 
    133 dnl Munge install path variables.
    134 if test "x$prefix" = "xNONE" ; then
    135   prefix="/usr/local"
    136 fi
    137 if test "x$exec_prefix" = "xNONE" ; then
    138   exec_prefix=$prefix
    139 fi
    140 PREFIX=$prefix
    141 AC_SUBST([PREFIX])
    142 BINDIR=`eval echo $bindir`
    143 BINDIR=`eval echo $BINDIR`
    144 AC_SUBST([BINDIR])
    145 INCLUDEDIR=`eval echo $includedir`
    146 INCLUDEDIR=`eval echo $INCLUDEDIR`
    147 AC_SUBST([INCLUDEDIR])
    148 LIBDIR=`eval echo $libdir`
    149 LIBDIR=`eval echo $LIBDIR`
    150 AC_SUBST([LIBDIR])
    151 DATADIR=`eval echo $datadir`
    152 DATADIR=`eval echo $DATADIR`
    153 AC_SUBST([DATADIR])
    154 MANDIR=`eval echo $mandir`
    155 MANDIR=`eval echo $MANDIR`
    156 AC_SUBST([MANDIR])
    157 
    158 dnl Support for building documentation.
    159 AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
    160 if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
    161   DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
    162 elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
    163   DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
    164 else
    165   dnl Documentation building will fail if this default gets used.
    166   DEFAULT_XSLROOT=""
    167 fi
    168 AC_ARG_WITH([xslroot],
    169   [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
    170 if test "x$with_xslroot" = "xno" ; then
    171   XSLROOT="${DEFAULT_XSLROOT}"
    172 else
    173   XSLROOT="${with_xslroot}"
    174 fi
    175 ],
    176   XSLROOT="${DEFAULT_XSLROOT}"
    177 )
    178 AC_SUBST([XSLROOT])
    179 
    180 dnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
    181 dnl just prevent autoconf from molesting CFLAGS.
    182 CFLAGS=$CFLAGS
    183 AC_PROG_CC
    184 
    185 if test "x$GCC" != "xyes" ; then
    186   AC_CACHE_CHECK([whether compiler is MSVC],
    187                  [je_cv_msvc],
    188                  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
    189                                                      [
    190 #ifndef _MSC_VER
    191   int fail[-1];
    192 #endif
    193 ])],
    194                                [je_cv_msvc=yes],
    195                                [je_cv_msvc=no])])
    196 fi
    197 
    198 dnl check if a cray prgenv wrapper compiler is being used
    199 je_cv_cray_prgenv_wrapper=""
    200 if test "x${PE_ENV}" != "x" ; then
    201   case "${CC}" in
    202     CC|cc)
    203 	je_cv_cray_prgenv_wrapper="yes"
    204 	;;
    205     *)
    206        ;;
    207   esac
    208 fi
    209 
    210 AC_CACHE_CHECK([whether compiler is cray],
    211               [je_cv_cray],
    212               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
    213                                                   [
    214 #ifndef _CRAYC
    215   int fail[-1];
    216 #endif
    217 ])],
    218                             [je_cv_cray=yes],
    219                             [je_cv_cray=no])])
    220 
    221 if test "x${je_cv_cray}" = "xyes" ; then
    222   AC_CACHE_CHECK([whether cray compiler version is 8.4],
    223                 [je_cv_cray_84],
    224                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
    225                                                       [
    226 #if !(_RELEASE_MAJOR == 8 && _RELEASE_MINOR == 4)
    227   int fail[-1];
    228 #endif
    229 ])],
    230                               [je_cv_cray_84=yes],
    231                               [je_cv_cray_84=no])])
    232 fi
    233 
    234 if test "x$GCC" = "xyes" ; then
    235   JE_CFLAGS_ADD([-std=gnu11])
    236   if test "x$je_cv_cflags_added" = "x-std=gnu11" ; then
    237     AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
    238   else
    239     JE_CFLAGS_ADD([-std=gnu99])
    240     if test "x$je_cv_cflags_added" = "x-std=gnu99" ; then
    241       AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
    242     fi
    243   fi
    244   JE_CFLAGS_ADD([-Wall])
    245   JE_CFLAGS_ADD([-Wshorten-64-to-32])
    246   JE_CFLAGS_ADD([-Wsign-compare])
    247   JE_CFLAGS_ADD([-Wundef])
    248   JE_CFLAGS_ADD([-Wno-format-zero-length])
    249   JE_CFLAGS_ADD([-pipe])
    250   JE_CFLAGS_ADD([-g3])
    251 elif test "x$je_cv_msvc" = "xyes" ; then
    252   CC="$CC -nologo"
    253   JE_CFLAGS_ADD([-Zi])
    254   JE_CFLAGS_ADD([-MT])
    255   JE_CFLAGS_ADD([-W3])
    256   JE_CFLAGS_ADD([-FS])
    257   JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat)
    258 fi
    259 if test "x$je_cv_cray" = "xyes" ; then
    260   dnl cray compiler 8.4 has an inlining bug
    261   if test "x$je_cv_cray_84" = "xyes" ; then
    262     JE_CFLAGS_ADD([-hipa2])
    263     JE_CFLAGS_ADD([-hnognu])
    264   fi
    265   dnl ignore unreachable code warning
    266   JE_CFLAGS_ADD([-hnomessage=128])
    267   dnl ignore redefinition of "malloc", "free", etc warning
    268   JE_CFLAGS_ADD([-hnomessage=1357])
    269 fi
    270 AC_SUBST([CONFIGURE_CFLAGS])
    271 AC_SUBST([SPECIFIED_CFLAGS])
    272 AC_SUBST([EXTRA_CFLAGS])
    273 AC_PROG_CPP
    274 
    275 AC_ARG_ENABLE([cxx],
    276   [AS_HELP_STRING([--disable-cxx], [Disable C++ integration])],
    277 if test "x$enable_cxx" = "xno" ; then
    278   enable_cxx="0"
    279 else
    280   enable_cxx="1"
    281 fi
    282 ,
    283 enable_cxx="1"
    284 )
    285 if test "x$enable_cxx" = "x1" ; then
    286   dnl Require at least c++14, which is the first version to support sized
    287   dnl deallocation.  C++ support is not compiled otherwise.
    288   m4_include([m4/ax_cxx_compile_stdcxx.m4])
    289   AX_CXX_COMPILE_STDCXX([14], [noext], [optional])
    290   if test "x${HAVE_CXX14}" = "x1" ; then
    291     JE_CXXFLAGS_ADD([-Wall])
    292     JE_CXXFLAGS_ADD([-g3])
    293 
    294     SAVED_LIBS="${LIBS}"
    295     JE_APPEND_VS(LIBS, -lstdc++)
    296     JE_COMPILABLE([libstdc++ linkage], [
    297 #include <stdlib.h>
    298 ], [[
    299 	int *arr = (int *)malloc(sizeof(int) * 42);
    300 	if (arr == NULL)
    301 		return 1;
    302 ]], [je_cv_libstdcxx])
    303     if test "x${je_cv_libstdcxx}" = "xno" ; then
    304       LIBS="${SAVED_LIBS}"
    305     fi
    306   else
    307     enable_cxx="0"
    308   fi
    309 fi
    310 AC_SUBST([enable_cxx])
    311 AC_SUBST([CONFIGURE_CXXFLAGS])
    312 AC_SUBST([SPECIFIED_CXXFLAGS])
    313 AC_SUBST([EXTRA_CXXFLAGS])
    314 
    315 AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
    316 if test "x${ac_cv_big_endian}" = "x1" ; then
    317   AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
    318 fi
    319 
    320 if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
    321   JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat/C99)
    322 fi
    323 
    324 if test "x${je_cv_msvc}" = "xyes" ; then
    325   LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
    326   AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
    327 else
    328   AC_CHECK_SIZEOF([void *])
    329   if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
    330     LG_SIZEOF_PTR=3
    331   elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
    332     LG_SIZEOF_PTR=2
    333   else
    334     AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
    335   fi
    336 fi
    337 AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
    338 
    339 AC_CHECK_SIZEOF([int])
    340 if test "x${ac_cv_sizeof_int}" = "x8" ; then
    341   LG_SIZEOF_INT=3
    342 elif test "x${ac_cv_sizeof_int}" = "x4" ; then
    343   LG_SIZEOF_INT=2
    344 else
    345   AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
    346 fi
    347 AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
    348 
    349 AC_CHECK_SIZEOF([long])
    350 if test "x${ac_cv_sizeof_long}" = "x8" ; then
    351   LG_SIZEOF_LONG=3
    352 elif test "x${ac_cv_sizeof_long}" = "x4" ; then
    353   LG_SIZEOF_LONG=2
    354 else
    355   AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
    356 fi
    357 AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
    358 
    359 AC_CHECK_SIZEOF([long long])
    360 if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
    361   LG_SIZEOF_LONG_LONG=3
    362 elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
    363   LG_SIZEOF_LONG_LONG=2
    364 else
    365   AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
    366 fi
    367 AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
    368 
    369 AC_CHECK_SIZEOF([intmax_t])
    370 if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
    371   LG_SIZEOF_INTMAX_T=4
    372 elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
    373   LG_SIZEOF_INTMAX_T=3
    374 elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
    375   LG_SIZEOF_INTMAX_T=2
    376 else
    377   AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
    378 fi
    379 AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
    380 
    381 AC_CANONICAL_HOST
    382 dnl CPU-specific settings.
    383 CPU_SPINWAIT=""
    384 case "${host_cpu}" in
    385   i686|x86_64)
    386 	HAVE_CPU_SPINWAIT=1
    387 	if test "x${je_cv_msvc}" = "xyes" ; then
    388 	    AC_CACHE_VAL([je_cv_pause_msvc],
    389 	      [JE_COMPILABLE([pause instruction MSVC], [],
    390 					[[_mm_pause(); return 0;]],
    391 					[je_cv_pause_msvc])])
    392 	    if test "x${je_cv_pause_msvc}" = "xyes" ; then
    393 		CPU_SPINWAIT='_mm_pause()'
    394 	    fi
    395 	else
    396 	    AC_CACHE_VAL([je_cv_pause],
    397 	      [JE_COMPILABLE([pause instruction], [],
    398 					[[__asm__ volatile("pause"); return 0;]],
    399 					[je_cv_pause])])
    400 	    if test "x${je_cv_pause}" = "xyes" ; then
    401 		CPU_SPINWAIT='__asm__ volatile("pause")'
    402 	    fi
    403 	fi
    404 	;;
    405   *)
    406 	HAVE_CPU_SPINWAIT=0
    407 	;;
    408 esac
    409 AC_DEFINE_UNQUOTED([HAVE_CPU_SPINWAIT], [$HAVE_CPU_SPINWAIT])
    410 AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
    411 
    412 AC_ARG_WITH([lg_vaddr],
    413   [AS_HELP_STRING([--with-lg-vaddr=<lg-vaddr>], [Number of significant virtual address bits])],
    414   [LG_VADDR="$with_lg_vaddr"], [LG_VADDR="detect"])
    415 
    416 case "${host_cpu}" in
    417   aarch64)
    418     if test "x$LG_VADDR" = "xdetect"; then
    419       AC_MSG_CHECKING([number of significant virtual address bits])
    420       if test "x${LG_SIZEOF_PTR}" = "x2" ; then
    421         #aarch64 ILP32
    422         LG_VADDR=32
    423       else
    424         #aarch64 LP64
    425         LG_VADDR=48
    426       fi
    427       AC_MSG_RESULT([$LG_VADDR])
    428     fi
    429     ;;
    430   x86_64)
    431     if test "x$LG_VADDR" = "xdetect"; then
    432       AC_CACHE_CHECK([number of significant virtual address bits],
    433                      [je_cv_lg_vaddr],
    434                      AC_RUN_IFELSE([AC_LANG_PROGRAM(
    435 [[
    436 #include <stdio.h>
    437 #ifdef _WIN32
    438 #include <limits.h>
    439 #include <intrin.h>
    440 typedef unsigned __int32 uint32_t;
    441 #else
    442 #include <stdint.h>
    443 #endif
    444 ]], [[
    445 	uint32_t r[[4]];
    446 	uint32_t eax_in = 0x80000008U;
    447 #ifdef _WIN32
    448 	__cpuid((int *)r, (int)eax_in);
    449 #else
    450 	asm volatile ("cpuid"
    451 	    : "=a" (r[[0]]), "=b" (r[[1]]), "=c" (r[[2]]), "=d" (r[[3]])
    452 	    : "a" (eax_in), "c" (0)
    453 	);
    454 #endif
    455 	uint32_t eax_out = r[[0]];
    456 	uint32_t vaddr = ((eax_out & 0x0000ff00U) >> 8);
    457 	FILE *f = fopen("conftest.out", "w");
    458 	if (f == NULL) {
    459 		return 1;
    460 	}
    461 	if (vaddr > (sizeof(void *) << 3)) {
    462 		vaddr = sizeof(void *) << 3;
    463 	}
    464 	fprintf(f, "%u", vaddr);
    465 	fclose(f);
    466 	return 0;
    467 ]])],
    468                    [je_cv_lg_vaddr=`cat conftest.out`],
    469                    [je_cv_lg_vaddr=error],
    470                    [je_cv_lg_vaddr=57]))
    471       if test "x${je_cv_lg_vaddr}" != "x" ; then
    472         LG_VADDR="${je_cv_lg_vaddr}"
    473       fi
    474       if test "x${LG_VADDR}" != "xerror" ; then
    475         AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
    476       else
    477         AC_MSG_ERROR([cannot determine number of significant virtual address bits])
    478       fi
    479     fi
    480     ;;
    481   *)
    482     if test "x$LG_VADDR" = "xdetect"; then
    483       AC_MSG_CHECKING([number of significant virtual address bits])
    484       if test "x${LG_SIZEOF_PTR}" = "x3" ; then
    485         LG_VADDR=64
    486       elif test "x${LG_SIZEOF_PTR}" = "x2" ; then
    487         LG_VADDR=32
    488       elif test "x${LG_SIZEOF_PTR}" = "xLG_SIZEOF_PTR_WIN" ; then
    489         LG_VADDR="(1U << (LG_SIZEOF_PTR_WIN+3))"
    490       else
    491         AC_MSG_ERROR([Unsupported lg(pointer size): ${LG_SIZEOF_PTR}])
    492       fi
    493       AC_MSG_RESULT([$LG_VADDR])
    494     fi
    495     ;;
    496 esac
    497 AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
    498 
    499 LD_PRELOAD_VAR="LD_PRELOAD"
    500 so="so"
    501 importlib="${so}"
    502 o="$ac_objext"
    503 a="a"
    504 exe="$ac_exeext"
    505 libprefix="lib"
    506 link_whole_archive="0"
    507 DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
    508 RPATH='-Wl,-rpath,$(1)'
    509 SOREV="${so}.${rev}"
    510 PIC_CFLAGS='-fPIC -DPIC'
    511 CTARGET='-o $@'
    512 LDTARGET='-o $@'
    513 TEST_LD_MODE=
    514 EXTRA_LDFLAGS=
    515 ARFLAGS='crus'
    516 AROUT=' $@'
    517 CC_MM=1
    518 
    519 if test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
    520   TEST_LD_MODE='-dynamic'
    521 fi
    522 
    523 if test "x${je_cv_cray}" = "xyes" ; then
    524   CC_MM=
    525 fi
    526 
    527 AN_MAKEVAR([AR], [AC_PROG_AR])
    528 AN_PROGRAM([ar], [AC_PROG_AR])
    529 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
    530 AC_PROG_AR
    531 
    532 AN_MAKEVAR([NM], [AC_PROG_NM])
    533 AN_PROGRAM([nm], [AC_PROG_NM])
    534 AC_DEFUN([AC_PROG_NM], [AC_CHECK_TOOL(NM, nm, :)])
    535 AC_PROG_NM
    536 
    537 AC_PROG_AWK
    538 
    539 dnl Platform-specific settings.  abi and RPATH can probably be determined
    540 dnl programmatically, but doing so is error-prone, which makes it generally
    541 dnl not worth the trouble.
    542 dnl
    543 dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
    544 dnl definitions need to be seen before any headers are included, which is a pain
    545 dnl to make happen otherwise.
    546 default_retain="0"
    547 maps_coalesce="1"
    548 DUMP_SYMS="${NM} -a"
    549 SYM_PREFIX=""
    550 case "${host}" in
    551   *-*-darwin* | *-*-ios*)
    552 	abi="macho"
    553 	RPATH=""
    554 	LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
    555 	so="dylib"
    556 	importlib="${so}"
    557 	force_tls="0"
    558 	DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
    559 	SOREV="${rev}.${so}"
    560 	sbrk_deprecated="1"
    561 	SYM_PREFIX="_"
    562 	;;
    563   *-*-freebsd*)
    564 	abi="elf"
    565 	AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
    566 	force_lazy_lock="1"
    567 	;;
    568   *-*-dragonfly*)
    569 	abi="elf"
    570 	;;
    571   *-*-openbsd*)
    572 	abi="elf"
    573 	force_tls="0"
    574 	;;
    575   *-*-bitrig*)
    576 	abi="elf"
    577 	;;
    578   *-*-linux-android)
    579 	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
    580 	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
    581 	abi="elf"
    582 	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
    583 	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
    584 	AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
    585 	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
    586 	AC_DEFINE([JEMALLOC_C11_ATOMICS])
    587 	force_tls="0"
    588 	if test "${LG_SIZEOF_PTR}" = "3"; then
    589 	  default_retain="1"
    590 	fi
    591 	;;
    592   *-*-linux*)
    593 	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
    594 	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
    595 	abi="elf"
    596 	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
    597 	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
    598 	AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
    599 	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
    600 	AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
    601 	if test "${LG_SIZEOF_PTR}" = "3"; then
    602 	  default_retain="1"
    603 	fi
    604 	;;
    605   *-*-kfreebsd*)
    606 	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
    607 	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
    608 	abi="elf"
    609 	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
    610 	AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
    611 	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
    612 	AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
    613 	;;
    614   *-*-netbsd*)
    615 	AC_MSG_CHECKING([ABI])
    616         AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    617 [[#ifdef __ELF__
    618 /* ELF */
    619 #else
    620 #error aout
    621 #endif
    622 ]])],
    623                           [abi="elf"],
    624                           [abi="aout"])
    625 	AC_MSG_RESULT([$abi])
    626 	;;
    627   *-*-solaris2*)
    628 	abi="elf"
    629 	RPATH='-Wl,-R,$(1)'
    630 	dnl Solaris needs this for sigwait().
    631 	JE_APPEND_VS(CPPFLAGS, -D_POSIX_PTHREAD_SEMANTICS)
    632 	JE_APPEND_VS(LIBS, -lposix4 -lsocket -lnsl)
    633 	;;
    634   *-ibm-aix*)
    635 	if test "${LG_SIZEOF_PTR}" = "3"; then
    636 	  dnl 64bit AIX
    637 	  LD_PRELOAD_VAR="LDR_PRELOAD64"
    638 	else
    639 	  dnl 32bit AIX
    640 	  LD_PRELOAD_VAR="LDR_PRELOAD"
    641 	fi
    642 	abi="xcoff"
    643 	;;
    644   *-*-mingw* | *-*-cygwin*)
    645 	abi="pecoff"
    646 	force_tls="0"
    647 	maps_coalesce="0"
    648 	RPATH=""
    649 	so="dll"
    650 	if test "x$je_cv_msvc" = "xyes" ; then
    651 	  importlib="lib"
    652 	  DSO_LDFLAGS="-LD"
    653 	  EXTRA_LDFLAGS="-link -DEBUG"
    654 	  CTARGET='-Fo$@'
    655 	  LDTARGET='-Fe$@'
    656 	  AR='lib'
    657 	  ARFLAGS='-nologo -out:'
    658 	  AROUT='$@'
    659 	  CC_MM=
    660         else
    661 	  importlib="${so}"
    662 	  DSO_LDFLAGS="-shared"
    663 	  link_whole_archive="1"
    664 	fi
    665 	case "${host}" in
    666 	  *-*-cygwin*)
    667 	    DUMP_SYMS="dumpbin /SYMBOLS"
    668 	    ;;
    669 	  *)
    670 	    ;;
    671 	esac
    672 	a="lib"
    673 	libprefix=""
    674 	SOREV="${so}"
    675 	PIC_CFLAGS=""
    676 	;;
    677   *)
    678 	AC_MSG_RESULT([Unsupported operating system: ${host}])
    679 	abi="elf"
    680 	;;
    681 esac
    682 
    683 JEMALLOC_USABLE_SIZE_CONST=const
    684 AC_CHECK_HEADERS([malloc.h], [
    685   AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
    686   AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    687     [#include <malloc.h>
    688      #include <stddef.h>
    689     size_t malloc_usable_size(const void *ptr);
    690     ],
    691     [])],[
    692                 AC_MSG_RESULT([yes])
    693          ],[
    694                 JEMALLOC_USABLE_SIZE_CONST=
    695                 AC_MSG_RESULT([no])
    696          ])
    697 ])
    698 AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
    699 AC_SUBST([abi])
    700 AC_SUBST([RPATH])
    701 AC_SUBST([LD_PRELOAD_VAR])
    702 AC_SUBST([so])
    703 AC_SUBST([importlib])
    704 AC_SUBST([o])
    705 AC_SUBST([a])
    706 AC_SUBST([exe])
    707 AC_SUBST([libprefix])
    708 AC_SUBST([link_whole_archive])
    709 AC_SUBST([DSO_LDFLAGS])
    710 AC_SUBST([EXTRA_LDFLAGS])
    711 AC_SUBST([SOREV])
    712 AC_SUBST([PIC_CFLAGS])
    713 AC_SUBST([CTARGET])
    714 AC_SUBST([LDTARGET])
    715 AC_SUBST([TEST_LD_MODE])
    716 AC_SUBST([MKLIB])
    717 AC_SUBST([ARFLAGS])
    718 AC_SUBST([AROUT])
    719 AC_SUBST([DUMP_SYMS])
    720 AC_SUBST([CC_MM])
    721 
    722 dnl Determine whether libm must be linked to use e.g. log(3).
    723 AC_SEARCH_LIBS([log], [m], , [AC_MSG_ERROR([Missing math functions])])
    724 if test "x$ac_cv_search_log" != "xnone required" ; then
    725   LM="$ac_cv_search_log"
    726 else
    727   LM=
    728 fi
    729 AC_SUBST(LM)
    730 
    731 JE_COMPILABLE([__attribute__ syntax],
    732               [static __attribute__((unused)) void foo(void){}],
    733               [],
    734               [je_cv_attribute])
    735 if test "x${je_cv_attribute}" = "xyes" ; then
    736   AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
    737   if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
    738     JE_CFLAGS_ADD([-fvisibility=hidden])
    739     JE_CXXFLAGS_ADD([-fvisibility=hidden])
    740   fi
    741 fi
    742 dnl Check for tls_model attribute support (clang 3.0 still lacks support).
    743 JE_CFLAGS_SAVE()
    744 JE_CFLAGS_ADD([-Werror])
    745 JE_CFLAGS_ADD([-herror_on_warning])
    746 JE_COMPILABLE([tls_model attribute], [],
    747               [static __thread int
    748                __attribute__((tls_model("initial-exec"), unused)) foo;
    749                foo = 0;],
    750               [je_cv_tls_model])
    751 JE_CFLAGS_RESTORE()
    752 dnl (Setting of JEMALLOC_TLS_MODEL is done later, after we've checked for
    753 dnl --disable-initial-exec-tls)
    754 
    755 dnl Check for alloc_size attribute support.
    756 JE_CFLAGS_SAVE()
    757 JE_CFLAGS_ADD([-Werror])
    758 JE_CFLAGS_ADD([-herror_on_warning])
    759 JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
    760               [void *foo(size_t size) __attribute__((alloc_size(1)));],
    761               [je_cv_alloc_size])
    762 JE_CFLAGS_RESTORE()
    763 if test "x${je_cv_alloc_size}" = "xyes" ; then
    764   AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
    765 fi
    766 dnl Check for format(gnu_printf, ...) attribute support.
    767 JE_CFLAGS_SAVE()
    768 JE_CFLAGS_ADD([-Werror])
    769 JE_CFLAGS_ADD([-herror_on_warning])
    770 JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
    771               [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
    772               [je_cv_format_gnu_printf])
    773 JE_CFLAGS_RESTORE()
    774 if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
    775   AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
    776 fi
    777 dnl Check for format(printf, ...) attribute support.
    778 JE_CFLAGS_SAVE()
    779 JE_CFLAGS_ADD([-Werror])
    780 JE_CFLAGS_ADD([-herror_on_warning])
    781 JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
    782               [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
    783               [je_cv_format_printf])
    784 JE_CFLAGS_RESTORE()
    785 if test "x${je_cv_format_printf}" = "xyes" ; then
    786   AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
    787 fi
    788 
    789 dnl Support optional additions to rpath.
    790 AC_ARG_WITH([rpath],
    791   [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
    792 if test "x$with_rpath" = "xno" ; then
    793   RPATH_EXTRA=
    794 else
    795   RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
    796 fi,
    797   RPATH_EXTRA=
    798 )
    799 AC_SUBST([RPATH_EXTRA])
    800 
    801 dnl Disable rules that do automatic regeneration of configure output by default.
    802 AC_ARG_ENABLE([autogen],
    803   [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
    804 if test "x$enable_autogen" = "xno" ; then
    805   enable_autogen="0"
    806 else
    807   enable_autogen="1"
    808 fi
    809 ,
    810 enable_autogen="0"
    811 )
    812 AC_SUBST([enable_autogen])
    813 
    814 AC_PROG_INSTALL
    815 AC_PROG_RANLIB
    816 AC_PATH_PROG([LD], [ld], [false], [$PATH])
    817 AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
    818 
    819 dnl Perform no name mangling by default.
    820 AC_ARG_WITH([mangling],
    821   [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
    822   [mangling_map="$with_mangling"], [mangling_map=""])
    823 
    824 dnl Do not prefix public APIs by default.
    825 AC_ARG_WITH([jemalloc_prefix],
    826   [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
    827   [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
    828   [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
    829   JEMALLOC_PREFIX=""
    830 else
    831   JEMALLOC_PREFIX="je_"
    832 fi]
    833 )
    834 if test "x$JEMALLOC_PREFIX" = "x" ; then
    835   AC_DEFINE([JEMALLOC_IS_MALLOC])
    836 else
    837   JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
    838   AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
    839   AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
    840 fi
    841 AC_SUBST([JEMALLOC_PREFIX])
    842 AC_SUBST([JEMALLOC_CPREFIX])
    843 
    844 AC_ARG_WITH([export],
    845   [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
    846   [if test "x$with_export" = "xno"; then
    847   AC_DEFINE([JEMALLOC_EXPORT],[])
    848 fi]
    849 )
    850 
    851 public_syms="aligned_alloc calloc dallocx free mallctl mallctlbymib mallctlnametomib malloc malloc_conf malloc_message malloc_stats_print malloc_usable_size mallocx nallocx posix_memalign rallocx realloc sallocx sdallocx xallocx"
    852 dnl Check for additional platform-specific public API functions.
    853 AC_CHECK_FUNC([memalign],
    854 	      [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
    855 	       public_syms="${public_syms} memalign"])
    856 AC_CHECK_FUNC([valloc],
    857 	      [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
    858 	       public_syms="${public_syms} valloc"])
    859 
    860 dnl Check for allocator-related functions that should be wrapped.
    861 wrap_syms=
    862 if test "x${JEMALLOC_PREFIX}" = "x" ; then
    863   AC_CHECK_FUNC([__libc_calloc],
    864 		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_CALLOC], [ ])
    865 		 wrap_syms="${wrap_syms} __libc_calloc"])
    866   AC_CHECK_FUNC([__libc_free],
    867 		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_FREE], [ ])
    868 		 wrap_syms="${wrap_syms} __libc_free"])
    869   AC_CHECK_FUNC([__libc_malloc],
    870 		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MALLOC], [ ])
    871 		 wrap_syms="${wrap_syms} __libc_malloc"])
    872   AC_CHECK_FUNC([__libc_memalign],
    873 		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MEMALIGN], [ ])
    874 		 wrap_syms="${wrap_syms} __libc_memalign"])
    875   AC_CHECK_FUNC([__libc_realloc],
    876 		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_REALLOC], [ ])
    877 		 wrap_syms="${wrap_syms} __libc_realloc"])
    878   AC_CHECK_FUNC([__libc_valloc],
    879 		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_VALLOC], [ ])
    880 		 wrap_syms="${wrap_syms} __libc_valloc"])
    881   AC_CHECK_FUNC([__posix_memalign],
    882 		[AC_DEFINE([JEMALLOC_OVERRIDE___POSIX_MEMALIGN], [ ])
    883 		 wrap_syms="${wrap_syms} __posix_memalign"])
    884 fi
    885 
    886 case "${host}" in
    887   *-*-mingw* | *-*-cygwin*)
    888     wrap_syms="${wrap_syms} tls_callback"
    889     ;;
    890   *)
    891     ;;
    892 esac
    893 
    894 dnl Mangle library-private APIs.
    895 AC_ARG_WITH([private_namespace],
    896   [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
    897   [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
    898   [JEMALLOC_PRIVATE_NAMESPACE="je_"]
    899 )
    900 AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
    901 private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
    902 AC_SUBST([private_namespace])
    903 
    904 dnl Do not add suffix to installed files by default.
    905 AC_ARG_WITH([install_suffix],
    906   [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
    907   [INSTALL_SUFFIX="$with_install_suffix"],
    908   [INSTALL_SUFFIX=]
    909 )
    910 install_suffix="$INSTALL_SUFFIX"
    911 AC_SUBST([install_suffix])
    912 
    913 dnl Specify default malloc_conf.
    914 AC_ARG_WITH([malloc_conf],
    915   [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
    916   [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
    917   [JEMALLOC_CONFIG_MALLOC_CONF=""]
    918 )
    919 config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
    920 AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
    921 
    922 dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
    923 dnl jemalloc_protos_jet.h easy.
    924 je_="je_"
    925 AC_SUBST([je_])
    926 
    927 cfgoutputs_in="Makefile.in"
    928 cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
    929 cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
    930 cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
    931 cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
    932 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
    933 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
    934 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
    935 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_preamble.h.in"
    936 cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
    937 cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
    938 
    939 cfgoutputs_out="Makefile"
    940 cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
    941 cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
    942 cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
    943 cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
    944 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
    945 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
    946 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
    947 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_preamble.h"
    948 cfgoutputs_out="${cfgoutputs_out} test/test.sh"
    949 cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
    950 
    951 cfgoutputs_tup="Makefile"
    952 cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
    953 cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
    954 cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
    955 cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
    956 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
    957 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
    958 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
    959 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_preamble.h"
    960 cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
    961 cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
    962 
    963 cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
    964 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
    965 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.sh"
    966 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
    967 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
    968 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
    969 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
    970 cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
    971 cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
    972 cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
    973 cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
    974 
    975 cfghdrs_out="include/jemalloc/jemalloc_defs.h"
    976 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
    977 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols.awk"
    978 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols_jet.awk"
    979 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
    980 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
    981 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
    982 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
    983 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
    984 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
    985 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
    986 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
    987 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
    988 cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
    989 
    990 cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
    991 cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
    992 cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
    993 
    994 dnl Do not compile with debugging by default.
    995 AC_ARG_ENABLE([debug],
    996   [AS_HELP_STRING([--enable-debug],
    997                   [Build debugging code])],
    998 [if test "x$enable_debug" = "xno" ; then
    999   enable_debug="0"
   1000 else
   1001   enable_debug="1"
   1002 fi
   1003 ],
   1004 [enable_debug="0"]
   1005 )
   1006 if test "x$enable_debug" = "x1" ; then
   1007   AC_DEFINE([JEMALLOC_DEBUG], [ ])
   1008 fi
   1009 if test "x$enable_debug" = "x1" ; then
   1010   AC_DEFINE([JEMALLOC_DEBUG], [ ])
   1011 fi
   1012 AC_SUBST([enable_debug])
   1013 
   1014 dnl Only optimize if not debugging.
   1015 if test "x$enable_debug" = "x0" ; then
   1016   if test "x$GCC" = "xyes" ; then
   1017     JE_CFLAGS_ADD([-O3])
   1018     JE_CXXFLAGS_ADD([-O3])
   1019     JE_CFLAGS_ADD([-funroll-loops])
   1020   elif test "x$je_cv_msvc" = "xyes" ; then
   1021     JE_CFLAGS_ADD([-O2])
   1022     JE_CXXFLAGS_ADD([-O2])
   1023   else
   1024     JE_CFLAGS_ADD([-O])
   1025     JE_CXXFLAGS_ADD([-O])
   1026   fi
   1027 fi
   1028 
   1029 dnl Enable statistics calculation by default.
   1030 AC_ARG_ENABLE([stats],
   1031   [AS_HELP_STRING([--disable-stats],
   1032                   [Disable statistics calculation/reporting])],
   1033 [if test "x$enable_stats" = "xno" ; then
   1034   enable_stats="0"
   1035 else
   1036   enable_stats="1"
   1037 fi
   1038 ],
   1039 [enable_stats="1"]
   1040 )
   1041 if test "x$enable_stats" = "x1" ; then
   1042   AC_DEFINE([JEMALLOC_STATS], [ ])
   1043 fi
   1044 AC_SUBST([enable_stats])
   1045 
   1046 dnl Do not enable profiling by default.
   1047 AC_ARG_ENABLE([prof],
   1048   [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
   1049 [if test "x$enable_prof" = "xno" ; then
   1050   enable_prof="0"
   1051 else
   1052   enable_prof="1"
   1053 fi
   1054 ],
   1055 [enable_prof="0"]
   1056 )
   1057 if test "x$enable_prof" = "x1" ; then
   1058   backtrace_method=""
   1059 else
   1060   backtrace_method="N/A"
   1061 fi
   1062 
   1063 AC_ARG_ENABLE([prof-libunwind],
   1064   [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
   1065 [if test "x$enable_prof_libunwind" = "xno" ; then
   1066   enable_prof_libunwind="0"
   1067 else
   1068   enable_prof_libunwind="1"
   1069 fi
   1070 ],
   1071 [enable_prof_libunwind="0"]
   1072 )
   1073 AC_ARG_WITH([static_libunwind],
   1074   [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
   1075   [Path to static libunwind library; use rather than dynamically linking])],
   1076 if test "x$with_static_libunwind" = "xno" ; then
   1077   LUNWIND="-lunwind"
   1078 else
   1079   if test ! -f "$with_static_libunwind" ; then
   1080     AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
   1081   fi
   1082   LUNWIND="$with_static_libunwind"
   1083 fi,
   1084   LUNWIND="-lunwind"
   1085 )
   1086 if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
   1087   AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
   1088   if test "x$LUNWIND" = "x-lunwind" ; then
   1089     AC_CHECK_LIB([unwind], [unw_backtrace], [JE_APPEND_VS(LIBS, $LUNWIND)],
   1090                  [enable_prof_libunwind="0"])
   1091   else
   1092     JE_APPEND_VS(LIBS, $LUNWIND)
   1093   fi
   1094   if test "x${enable_prof_libunwind}" = "x1" ; then
   1095     backtrace_method="libunwind"
   1096     AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
   1097   fi
   1098 fi
   1099 
   1100 AC_ARG_ENABLE([prof-libgcc],
   1101   [AS_HELP_STRING([--disable-prof-libgcc],
   1102   [Do not use libgcc for backtracing])],
   1103 [if test "x$enable_prof_libgcc" = "xno" ; then
   1104   enable_prof_libgcc="0"
   1105 else
   1106   enable_prof_libgcc="1"
   1107 fi
   1108 ],
   1109 [enable_prof_libgcc="1"]
   1110 )
   1111 if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
   1112      -a "x$GCC" = "xyes" ; then
   1113   AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
   1114   if test "x${enable_prof_libgcc}" = "x1" ; then
   1115     AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [JE_APPEND_VS(LIBS, -lgcc)], [enable_prof_libgcc="0"])
   1116   fi
   1117   if test "x${enable_prof_libgcc}" = "x1" ; then
   1118     backtrace_method="libgcc"
   1119     AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
   1120   fi
   1121 else
   1122   enable_prof_libgcc="0"
   1123 fi
   1124 
   1125 AC_ARG_ENABLE([prof-gcc],
   1126   [AS_HELP_STRING([--disable-prof-gcc],
   1127   [Do not use gcc intrinsics for backtracing])],
   1128 [if test "x$enable_prof_gcc" = "xno" ; then
   1129   enable_prof_gcc="0"
   1130 else
   1131   enable_prof_gcc="1"
   1132 fi
   1133 ],
   1134 [enable_prof_gcc="1"]
   1135 )
   1136 if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
   1137      -a "x$GCC" = "xyes" ; then
   1138   JE_CFLAGS_ADD([-fno-omit-frame-pointer])
   1139   backtrace_method="gcc intrinsics"
   1140   AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
   1141 else
   1142   enable_prof_gcc="0"
   1143 fi
   1144 
   1145 if test "x$backtrace_method" = "x" ; then
   1146   backtrace_method="none (disabling profiling)"
   1147   enable_prof="0"
   1148 fi
   1149 AC_MSG_CHECKING([configured backtracing method])
   1150 AC_MSG_RESULT([$backtrace_method])
   1151 if test "x$enable_prof" = "x1" ; then
   1152   dnl Heap profiling uses the log(3) function.
   1153   JE_APPEND_VS(LIBS, $LM)
   1154 
   1155   AC_DEFINE([JEMALLOC_PROF], [ ])
   1156 fi
   1157 AC_SUBST([enable_prof])
   1158 
   1159 dnl Indicate whether adjacent virtual memory mappings automatically coalesce
   1160 dnl (and fragment on demand).
   1161 if test "x${maps_coalesce}" = "x1" ; then
   1162   AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
   1163 fi
   1164 
   1165 dnl Indicate whether to retain memory (rather than using munmap()) by default.
   1166 if test "x$default_retain" = "x1" ; then
   1167   AC_DEFINE([JEMALLOC_RETAIN], [ ])
   1168 fi
   1169 
   1170 dnl Enable allocation from DSS if supported by the OS.
   1171 have_dss="1"
   1172 dnl Check whether the BSD/SUSv1 sbrk() exists.  If not, disable DSS support.
   1173 AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
   1174 if test "x$have_sbrk" = "x1" ; then
   1175   if test "x$sbrk_deprecated" = "x1" ; then
   1176     AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
   1177     have_dss="0"
   1178   fi
   1179 else
   1180   have_dss="0"
   1181 fi
   1182 
   1183 if test "x$have_dss" = "x1" ; then
   1184   AC_DEFINE([JEMALLOC_DSS], [ ])
   1185 fi
   1186 
   1187 dnl Support the junk/zero filling option by default.
   1188 AC_ARG_ENABLE([fill],
   1189   [AS_HELP_STRING([--disable-fill], [Disable support for junk/zero filling])],
   1190 [if test "x$enable_fill" = "xno" ; then
   1191   enable_fill="0"
   1192 else
   1193   enable_fill="1"
   1194 fi
   1195 ],
   1196 [enable_fill="1"]
   1197 )
   1198 if test "x$enable_fill" = "x1" ; then
   1199   AC_DEFINE([JEMALLOC_FILL], [ ])
   1200 fi
   1201 AC_SUBST([enable_fill])
   1202 
   1203 dnl Disable utrace(2)-based tracing by default.
   1204 AC_ARG_ENABLE([utrace],
   1205   [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
   1206 [if test "x$enable_utrace" = "xno" ; then
   1207   enable_utrace="0"
   1208 else
   1209   enable_utrace="1"
   1210 fi
   1211 ],
   1212 [enable_utrace="0"]
   1213 )
   1214 JE_COMPILABLE([utrace(2)], [
   1215 #include <sys/types.h>
   1216 #include <sys/param.h>
   1217 #include <sys/time.h>
   1218 #include <sys/uio.h>
   1219 #include <sys/ktrace.h>
   1220 ], [
   1221 	utrace((void *)0, 0);
   1222 ], [je_cv_utrace])
   1223 if test "x${je_cv_utrace}" = "xno" ; then
   1224   enable_utrace="0"
   1225 fi
   1226 if test "x$enable_utrace" = "x1" ; then
   1227   AC_DEFINE([JEMALLOC_UTRACE], [ ])
   1228 fi
   1229 AC_SUBST([enable_utrace])
   1230 
   1231 dnl Do not support the xmalloc option by default.
   1232 AC_ARG_ENABLE([xmalloc],
   1233   [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
   1234 [if test "x$enable_xmalloc" = "xno" ; then
   1235   enable_xmalloc="0"
   1236 else
   1237   enable_xmalloc="1"
   1238 fi
   1239 ],
   1240 [enable_xmalloc="0"]
   1241 )
   1242 if test "x$enable_xmalloc" = "x1" ; then
   1243   AC_DEFINE([JEMALLOC_XMALLOC], [ ])
   1244 fi
   1245 AC_SUBST([enable_xmalloc])
   1246 
   1247 dnl Support cache-oblivious allocation alignment by default.
   1248 AC_ARG_ENABLE([cache-oblivious],
   1249   [AS_HELP_STRING([--disable-cache-oblivious],
   1250                   [Disable support for cache-oblivious allocation alignment])],
   1251 [if test "x$enable_cache_oblivious" = "xno" ; then
   1252   enable_cache_oblivious="0"
   1253 else
   1254   enable_cache_oblivious="1"
   1255 fi
   1256 ],
   1257 [enable_cache_oblivious="1"]
   1258 )
   1259 if test "x$enable_cache_oblivious" = "x1" ; then
   1260   AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
   1261 fi
   1262 AC_SUBST([enable_cache_oblivious])
   1263 
   1264 dnl Do not log by default.
   1265 AC_ARG_ENABLE([log],
   1266   [AS_HELP_STRING([--enable-log], [Support debug logging])],
   1267 [if test "x$enable_log" = "xno" ; then
   1268   enable_log="0"
   1269 else
   1270   enable_log="1"
   1271 fi
   1272 ],
   1273 [enable_log="0"]
   1274 )
   1275 if test "x$enable_log" = "x1" ; then
   1276   AC_DEFINE([JEMALLOC_LOG], [ ])
   1277 fi
   1278 AC_SUBST([enable_log])
   1279 
   1280 
   1281 JE_COMPILABLE([a program using __builtin_unreachable], [
   1282 void foo (void) {
   1283   __builtin_unreachable();
   1284 }
   1285 ], [
   1286 	{
   1287 		foo();
   1288 	}
   1289 ], [je_cv_gcc_builtin_unreachable])
   1290 if test "x${je_cv_gcc_builtin_unreachable}" = "xyes" ; then
   1291   AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [__builtin_unreachable])
   1292 else
   1293   AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [abort])
   1294 fi
   1295 
   1296 dnl ============================================================================
   1297 dnl Check for  __builtin_ffsl(), then ffsl(3), and fail if neither are found.
   1298 dnl One of those two functions should (theoretically) exist on all platforms
   1299 dnl that jemalloc currently has a chance of functioning on without modification.
   1300 dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
   1301 dnl ffsl() or __builtin_ffsl() are defined, respectively.
   1302 JE_COMPILABLE([a program using __builtin_ffsl], [
   1303 #include <stdio.h>
   1304 #include <strings.h>
   1305 #include <string.h>
   1306 ], [
   1307 	{
   1308 		int rv = __builtin_ffsl(0x08);
   1309 		printf("%d\n", rv);
   1310 	}
   1311 ], [je_cv_gcc_builtin_ffsl])
   1312 if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
   1313   AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
   1314   AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
   1315   AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
   1316 else
   1317   JE_COMPILABLE([a program using ffsl], [
   1318   #include <stdio.h>
   1319   #include <strings.h>
   1320   #include <string.h>
   1321   ], [
   1322 	{
   1323 		int rv = ffsl(0x08);
   1324 		printf("%d\n", rv);
   1325 	}
   1326   ], [je_cv_function_ffsl])
   1327   if test "x${je_cv_function_ffsl}" = "xyes" ; then
   1328     AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
   1329     AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
   1330     AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
   1331   else
   1332     AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
   1333   fi
   1334 fi
   1335 
   1336 AC_ARG_WITH([lg_quantum],
   1337   [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
   1338    [Base 2 log of minimum allocation alignment])],
   1339   [LG_QUANTA="$with_lg_quantum"],
   1340   [LG_QUANTA="3 4"])
   1341 if test "x$with_lg_quantum" != "x" ; then
   1342   AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
   1343 fi
   1344 
   1345 AC_ARG_WITH([lg_page],
   1346   [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
   1347   [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
   1348 if test "x$LG_PAGE" = "xdetect"; then
   1349   AC_CACHE_CHECK([LG_PAGE],
   1350                [je_cv_lg_page],
   1351                AC_RUN_IFELSE([AC_LANG_PROGRAM(
   1352 [[
   1353 #include <strings.h>
   1354 #ifdef _WIN32
   1355 #include <windows.h>
   1356 #else
   1357 #include <unistd.h>
   1358 #endif
   1359 #include <stdio.h>
   1360 ]],
   1361 [[
   1362     int result;
   1363     FILE *f;
   1364 
   1365 #ifdef _WIN32
   1366     SYSTEM_INFO si;
   1367     GetSystemInfo(&si);
   1368     result = si.dwPageSize;
   1369 #else
   1370     result = sysconf(_SC_PAGESIZE);
   1371 #endif
   1372     if (result == -1) {
   1373 	return 1;
   1374     }
   1375     result = JEMALLOC_INTERNAL_FFSL(result) - 1;
   1376 
   1377     f = fopen("conftest.out", "w");
   1378     if (f == NULL) {
   1379 	return 1;
   1380     }
   1381     fprintf(f, "%d", result);
   1382     fclose(f);
   1383 
   1384     return 0;
   1385 ]])],
   1386                              [je_cv_lg_page=`cat conftest.out`],
   1387                              [je_cv_lg_page=undefined],
   1388                              [je_cv_lg_page=12]))
   1389 fi
   1390 if test "x${je_cv_lg_page}" != "x" ; then
   1391   LG_PAGE="${je_cv_lg_page}"
   1392 fi
   1393 if test "x${LG_PAGE}" != "xundefined" ; then
   1394    AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
   1395 else
   1396    AC_MSG_ERROR([cannot determine value for LG_PAGE])
   1397 fi
   1398 
   1399 AC_ARG_WITH([lg_hugepage],
   1400   [AS_HELP_STRING([--with-lg-hugepage=<lg-hugepage>],
   1401    [Base 2 log of system huge page size])],
   1402   [je_cv_lg_hugepage="${with_lg_hugepage}"],
   1403   [je_cv_lg_hugepage=""])
   1404 if test "x${je_cv_lg_hugepage}" = "x" ; then
   1405   dnl Look in /proc/meminfo (Linux-specific) for information on the default huge
   1406   dnl page size, if any.  The relevant line looks like:
   1407   dnl
   1408   dnl   Hugepagesize:       2048 kB
   1409   if test -e "/proc/meminfo" ; then
   1410     hpsk=[`cat /proc/meminfo 2>/dev/null | \
   1411           grep -e '^Hugepagesize:[[:space:]]\+[0-9]\+[[:space:]]kB$' | \
   1412           awk '{print $2}'`]
   1413     if test "x${hpsk}" != "x" ; then
   1414       je_cv_lg_hugepage=10
   1415       while test "${hpsk}" -gt 1 ; do
   1416         hpsk="$((hpsk / 2))"
   1417         je_cv_lg_hugepage="$((je_cv_lg_hugepage + 1))"
   1418       done
   1419     fi
   1420   fi
   1421 
   1422   dnl Set default if unable to automatically configure.
   1423   if test "x${je_cv_lg_hugepage}" = "x" ; then
   1424     je_cv_lg_hugepage=21
   1425   fi
   1426 fi
   1427 if test "x${LG_PAGE}" != "xundefined" -a \
   1428         "${je_cv_lg_hugepage}" -lt "${LG_PAGE}" ; then
   1429   AC_MSG_ERROR([Huge page size (2^${je_cv_lg_hugepage}) must be at least page size (2^${LG_PAGE})])
   1430 fi
   1431 AC_DEFINE_UNQUOTED([LG_HUGEPAGE], [${je_cv_lg_hugepage}])
   1432 
   1433 AC_ARG_WITH([lg_page_sizes],
   1434   [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
   1435    [Base 2 logs of system page sizes to support])],
   1436   [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
   1437 
   1438 dnl ============================================================================
   1439 dnl jemalloc configuration.
   1440 dnl
   1441 
   1442 AC_ARG_WITH([version],
   1443   [AS_HELP_STRING([--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid>],
   1444    [Version string])],
   1445   [
   1446     echo "${with_version}" | grep ['^[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+-g[0-9a-f]\+$'] 2>&1 1>/dev/null
   1447     if test $? -eq 0 ; then
   1448       echo "$with_version" > "${objroot}VERSION"
   1449     else
   1450       echo "${with_version}" | grep ['^VERSION$'] 2>&1 1>/dev/null
   1451       if test $? -ne 0 ; then
   1452         AC_MSG_ERROR([${with_version} does not match <major>.<minor>.<bugfix>-<nrev>-g<gid> or VERSION])
   1453       fi
   1454     fi
   1455   ], [
   1456     dnl Set VERSION if source directory is inside a git repository.
   1457     if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
   1458       dnl Pattern globs aren't powerful enough to match both single- and
   1459       dnl double-digit version numbers, so iterate over patterns to support up
   1460       dnl to version 99.99.99 without any accidental matches.
   1461       for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
   1462                      '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
   1463                      '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
   1464                      '[0-9][0-9].[0-9][0-9].[0-9]' \
   1465                      '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
   1466         (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
   1467         if test $? -eq 0 ; then
   1468           mv "${objroot}VERSION.tmp" "${objroot}VERSION"
   1469           break
   1470         fi
   1471       done
   1472     fi
   1473     rm -f "${objroot}VERSION.tmp"
   1474   ])
   1475 
   1476 if test ! -e "${objroot}VERSION" ; then
   1477   if test ! -e "${srcroot}VERSION" ; then
   1478     AC_MSG_RESULT(
   1479       [Missing VERSION file, and unable to generate it; creating bogus VERSION])
   1480     echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
   1481   else
   1482     cp ${srcroot}VERSION ${objroot}VERSION
   1483   fi
   1484 fi
   1485 jemalloc_version=`cat "${objroot}VERSION"`
   1486 jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
   1487 jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
   1488 jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
   1489 jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
   1490 jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
   1491 AC_SUBST([jemalloc_version])
   1492 AC_SUBST([jemalloc_version_major])
   1493 AC_SUBST([jemalloc_version_minor])
   1494 AC_SUBST([jemalloc_version_bugfix])
   1495 AC_SUBST([jemalloc_version_nrev])
   1496 AC_SUBST([jemalloc_version_gid])
   1497 
   1498 dnl ============================================================================
   1499 dnl Configure pthreads.
   1500 
   1501 if test "x$abi" != "xpecoff" ; then
   1502   AC_DEFINE([JEMALLOC_HAVE_PTHREAD], [ ])
   1503   AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
   1504   dnl Some systems may embed pthreads functionality in libc; check for libpthread
   1505   dnl first, but try libc too before failing.
   1506   AC_CHECK_LIB([pthread], [pthread_create], [JE_APPEND_VS(LIBS, -lpthread)],
   1507                [AC_SEARCH_LIBS([pthread_create], , ,
   1508                                AC_MSG_ERROR([libpthread is missing]))])
   1509   wrap_syms="${wrap_syms} pthread_create"
   1510   have_pthread="1"
   1511   dnl Check if we have dlsym support.
   1512   have_dlsym="1"
   1513   AC_CHECK_HEADERS([dlfcn.h],
   1514     AC_CHECK_FUNC([dlsym], [],
   1515       [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"], [have_dlsym="0"])]),
   1516     [have_dlsym="0"])
   1517   if test "x$have_dlsym" = "x1" ; then
   1518     AC_DEFINE([JEMALLOC_HAVE_DLSYM], [ ])
   1519   fi
   1520   JE_COMPILABLE([pthread_atfork(3)], [
   1521 #include <pthread.h>
   1522 ], [
   1523   pthread_atfork((void *)0, (void *)0, (void *)0);
   1524 ], [je_cv_pthread_atfork])
   1525   if test "x${je_cv_pthread_atfork}" = "xyes" ; then
   1526     AC_DEFINE([JEMALLOC_HAVE_PTHREAD_ATFORK], [ ])
   1527   fi
   1528   dnl Check if pthread_setname_np is available with the expected API.
   1529   JE_COMPILABLE([pthread_setname_np(3)], [
   1530 #include <pthread.h>
   1531 ], [
   1532   pthread_setname_np(pthread_self(), "setname_test");
   1533 ], [je_cv_pthread_setname_np])
   1534   if test "x${je_cv_pthread_setname_np}" = "xyes" ; then
   1535     AC_DEFINE([JEMALLOC_HAVE_PTHREAD_SETNAME_NP], [ ])
   1536   fi
   1537 fi
   1538 
   1539 JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
   1540 
   1541 dnl Check whether clock_gettime(2) is in libc or librt.
   1542 AC_SEARCH_LIBS([clock_gettime], [rt])
   1543 
   1544 dnl Cray wrapper compiler often adds `-lrt` when using `-static`. Check with
   1545 dnl `-dynamic` as well in case a user tries to dynamically link in jemalloc
   1546 if test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
   1547   if test "$ac_cv_search_clock_gettime" != "-lrt"; then
   1548     JE_CFLAGS_SAVE()
   1549 
   1550     unset ac_cv_search_clock_gettime
   1551     JE_CFLAGS_ADD([-dynamic])
   1552     AC_SEARCH_LIBS([clock_gettime], [rt])
   1553 
   1554     JE_CFLAGS_RESTORE()
   1555   fi
   1556 fi
   1557 
   1558 dnl check for CLOCK_MONOTONIC_COARSE (Linux-specific).
   1559 JE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC_COARSE, ...)], [
   1560 #include <time.h>
   1561 ], [
   1562 	struct timespec ts;
   1563 
   1564 	clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
   1565 ], [je_cv_clock_monotonic_coarse])
   1566 if test "x${je_cv_clock_monotonic_coarse}" = "xyes" ; then
   1567   AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC_COARSE])
   1568 fi
   1569 
   1570 dnl check for CLOCK_MONOTONIC.
   1571 JE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC, ...)], [
   1572 #include <unistd.h>
   1573 #include <time.h>
   1574 ], [
   1575 	struct timespec ts;
   1576 
   1577 	clock_gettime(CLOCK_MONOTONIC, &ts);
   1578 #if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0
   1579 #  error _POSIX_MONOTONIC_CLOCK missing/invalid
   1580 #endif
   1581 ], [je_cv_clock_monotonic])
   1582 if test "x${je_cv_clock_monotonic}" = "xyes" ; then
   1583   AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC])
   1584 fi
   1585 
   1586 dnl Check for mach_absolute_time().
   1587 JE_COMPILABLE([mach_absolute_time()], [
   1588 #include <mach/mach_time.h>
   1589 ], [
   1590 	mach_absolute_time();
   1591 ], [je_cv_mach_absolute_time])
   1592 if test "x${je_cv_mach_absolute_time}" = "xyes" ; then
   1593   AC_DEFINE([JEMALLOC_HAVE_MACH_ABSOLUTE_TIME])
   1594 fi
   1595 
   1596 dnl Use syscall(2) (if available) by default.
   1597 AC_ARG_ENABLE([syscall],
   1598   [AS_HELP_STRING([--disable-syscall], [Disable use of syscall(2)])],
   1599 [if test "x$enable_syscall" = "xno" ; then
   1600   enable_syscall="0"
   1601 else
   1602   enable_syscall="1"
   1603 fi
   1604 ],
   1605 [enable_syscall="1"]
   1606 )
   1607 if test "x$enable_syscall" = "x1" ; then
   1608   dnl Check if syscall(2) is usable.  Treat warnings as errors, so that e.g. OS
   1609   dnl X 10.12's deprecation warning prevents use.
   1610   JE_CFLAGS_SAVE()
   1611   JE_CFLAGS_ADD([-Werror])
   1612   JE_COMPILABLE([syscall(2)], [
   1613 #include <sys/syscall.h>
   1614 #include <unistd.h>
   1615 ], [
   1616 	syscall(SYS_write, 2, "hello", 5);
   1617 ],
   1618                 [je_cv_syscall])
   1619   JE_CFLAGS_RESTORE()
   1620   if test "x$je_cv_syscall" = "xyes" ; then
   1621     AC_DEFINE([JEMALLOC_USE_SYSCALL], [ ])
   1622   fi
   1623 fi
   1624 
   1625 dnl Check if the GNU-specific secure_getenv function exists.
   1626 AC_CHECK_FUNC([secure_getenv],
   1627               [have_secure_getenv="1"],
   1628               [have_secure_getenv="0"]
   1629              )
   1630 if test "x$have_secure_getenv" = "x1" ; then
   1631   AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
   1632 fi
   1633 
   1634 dnl Check if the GNU-specific sched_getcpu function exists.
   1635 AC_CHECK_FUNC([sched_getcpu],
   1636               [have_sched_getcpu="1"],
   1637               [have_sched_getcpu="0"]
   1638              )
   1639 if test "x$have_sched_getcpu" = "x1" ; then
   1640   AC_DEFINE([JEMALLOC_HAVE_SCHED_GETCPU], [ ])
   1641 fi
   1642 
   1643 dnl Check if the GNU-specific sched_setaffinity function exists.
   1644 AC_CHECK_FUNC([sched_setaffinity],
   1645               [have_sched_setaffinity="1"],
   1646               [have_sched_setaffinity="0"]
   1647              )
   1648 if test "x$have_sched_setaffinity" = "x1" ; then
   1649   AC_DEFINE([JEMALLOC_HAVE_SCHED_SETAFFINITY], [ ])
   1650 fi
   1651 
   1652 dnl Check if the Solaris/BSD issetugid function exists.
   1653 AC_CHECK_FUNC([issetugid],
   1654               [have_issetugid="1"],
   1655               [have_issetugid="0"]
   1656              )
   1657 if test "x$have_issetugid" = "x1" ; then
   1658   AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
   1659 fi
   1660 
   1661 dnl Check whether the BSD-specific _malloc_thread_cleanup() exists.  If so, use
   1662 dnl it rather than pthreads TSD cleanup functions to support cleanup during
   1663 dnl thread exit, in order to avoid pthreads library recursion during
   1664 dnl bootstrapping.
   1665 AC_CHECK_FUNC([_malloc_thread_cleanup],
   1666               [have__malloc_thread_cleanup="1"],
   1667               [have__malloc_thread_cleanup="0"]
   1668              )
   1669 if test "x$have__malloc_thread_cleanup" = "x1" ; then
   1670   AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
   1671   wrap_syms="${wrap_syms} _malloc_thread_cleanup"
   1672   force_tls="1"
   1673 fi
   1674 
   1675 dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists.  If
   1676 dnl so, mutex initialization causes allocation, and we need to implement this
   1677 dnl callback function in order to prevent recursive allocation.
   1678 AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
   1679               [have__pthread_mutex_init_calloc_cb="1"],
   1680               [have__pthread_mutex_init_calloc_cb="0"]
   1681              )
   1682 if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
   1683   AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
   1684   wrap_syms="${wrap_syms} _malloc_prefork _malloc_postfork"
   1685 fi
   1686 
   1687 dnl Disable lazy locking by default.
   1688 AC_ARG_ENABLE([lazy_lock],
   1689   [AS_HELP_STRING([--enable-lazy-lock],
   1690   [Enable lazy locking (only lock when multi-threaded)])],
   1691 [if test "x$enable_lazy_lock" = "xno" ; then
   1692   enable_lazy_lock="0"
   1693 else
   1694   enable_lazy_lock="1"
   1695 fi
   1696 ],
   1697 [enable_lazy_lock=""]
   1698 )
   1699 if test "x${enable_lazy_lock}" = "x" ; then
   1700   if test "x${force_lazy_lock}" = "x1" ; then
   1701     AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
   1702     enable_lazy_lock="1"
   1703   else
   1704     enable_lazy_lock="0"
   1705   fi
   1706 fi
   1707 if test "x${enable_lazy_lock}" = "x1" -a "x${abi}" = "xpecoff" ; then
   1708   AC_MSG_RESULT([Forcing no lazy-lock because thread creation monitoring is unimplemented])
   1709   enable_lazy_lock="0"
   1710 fi
   1711 if test "x$enable_lazy_lock" = "x1" ; then
   1712   if test "x$have_dlsym" = "x1" ; then
   1713     AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
   1714   else
   1715     AC_MSG_ERROR([Missing dlsym support: lazy-lock cannot be enabled.])
   1716   fi
   1717 fi
   1718 AC_SUBST([enable_lazy_lock])
   1719 
   1720 dnl Automatically configure TLS.
   1721 if test "x${force_tls}" = "x1" ; then
   1722   enable_tls="1"
   1723 elif test "x${force_tls}" = "x0" ; then
   1724   enable_tls="0"
   1725 else
   1726   enable_tls="1"
   1727 fi
   1728 if test "x${enable_tls}" = "x1" ; then
   1729 AC_MSG_CHECKING([for TLS])
   1730 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
   1731 [[
   1732     __thread int x;
   1733 ]], [[
   1734     x = 42;
   1735 
   1736     return 0;
   1737 ]])],
   1738               AC_MSG_RESULT([yes]),
   1739               AC_MSG_RESULT([no])
   1740               enable_tls="0")
   1741 else
   1742   enable_tls="0"
   1743 fi
   1744 AC_SUBST([enable_tls])
   1745 if test "x${enable_tls}" = "x1" ; then
   1746   AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
   1747 fi
   1748 
   1749 dnl ============================================================================
   1750 dnl Check for C11 atomics.
   1751 
   1752 JE_COMPILABLE([C11 atomics], [
   1753 #include <stdint.h>
   1754 #if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
   1755 #include <stdatomic.h>
   1756 #else
   1757 #error Atomics not available
   1758 #endif
   1759 ], [
   1760     uint64_t *p = (uint64_t *)0;
   1761     uint64_t x = 1;
   1762     volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
   1763     uint64_t r = atomic_fetch_add(a, x) + x;
   1764     return r == 0;
   1765 ], [je_cv_c11_atomics])
   1766 if test "x${je_cv_c11_atomics}" = "xyes" ; then
   1767   AC_DEFINE([JEMALLOC_C11_ATOMICS])
   1768 fi
   1769 
   1770 dnl ============================================================================
   1771 dnl Check for GCC-style __atomic atomics.
   1772 
   1773 JE_COMPILABLE([GCC __atomic atomics], [
   1774 ], [
   1775     int x = 0;
   1776     int val = 1;
   1777     int y = __atomic_fetch_add(&x, val, __ATOMIC_RELAXED);
   1778     int after_add = x;
   1779     return after_add == 1;
   1780 ], [je_cv_gcc_atomic_atomics])
   1781 if test "x${je_cv_gcc_atomic_atomics}" = "xyes" ; then
   1782   AC_DEFINE([JEMALLOC_GCC_ATOMIC_ATOMICS])
   1783 fi
   1784 
   1785 dnl ============================================================================
   1786 dnl Check for GCC-style __sync atomics.
   1787 
   1788 JE_COMPILABLE([GCC __sync atomics], [
   1789 ], [
   1790     int x = 0;
   1791     int before_add = __sync_fetch_and_add(&x, 1);
   1792     int after_add = x;
   1793     return (before_add == 0) && (after_add == 1);
   1794 ], [je_cv_gcc_sync_atomics])
   1795 if test "x${je_cv_gcc_sync_atomics}" = "xyes" ; then
   1796   AC_DEFINE([JEMALLOC_GCC_SYNC_ATOMICS])
   1797 fi
   1798 
   1799 dnl ============================================================================
   1800 dnl Check for atomic(3) operations as provided on Darwin.
   1801 dnl We need this not for the atomic operations (which are provided above), but
   1802 dnl rather for the OSSpinLock type it exposes.
   1803 
   1804 JE_COMPILABLE([Darwin OSAtomic*()], [
   1805 #include <libkern/OSAtomic.h>
   1806 #include <inttypes.h>
   1807 ], [
   1808 	{
   1809 		int32_t x32 = 0;
   1810 		volatile int32_t *x32p = &x32;
   1811 		OSAtomicAdd32(1, x32p);
   1812 	}
   1813 	{
   1814 		int64_t x64 = 0;
   1815 		volatile int64_t *x64p = &x64;
   1816 		OSAtomicAdd64(1, x64p);
   1817 	}
   1818 ], [je_cv_osatomic])
   1819 if test "x${je_cv_osatomic}" = "xyes" ; then
   1820   AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
   1821 fi
   1822 
   1823 dnl ============================================================================
   1824 dnl Check for madvise(2).
   1825 
   1826 JE_COMPILABLE([madvise(2)], [
   1827 #include <sys/mman.h>
   1828 ], [
   1829 	madvise((void *)0, 0, 0);
   1830 ], [je_cv_madvise])
   1831 if test "x${je_cv_madvise}" = "xyes" ; then
   1832   AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
   1833 
   1834   dnl Check for madvise(..., MADV_FREE).
   1835   JE_COMPILABLE([madvise(..., MADV_FREE)], [
   1836 #include <sys/mman.h>
   1837 ], [
   1838 	madvise((void *)0, 0, MADV_FREE);
   1839 ], [je_cv_madv_free])
   1840   if test "x${je_cv_madv_free}" = "xyes" ; then
   1841     AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
   1842   elif test "x${je_cv_madvise}" = "xyes" ; then
   1843     case "${host_cpu}" in i686|x86_64)
   1844         case "${host}" in *-*-linux*)
   1845             AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
   1846             AC_DEFINE([JEMALLOC_DEFINE_MADVISE_FREE], [ ])
   1847 	    ;;
   1848         esac
   1849         ;;
   1850     esac
   1851   fi
   1852 
   1853   dnl Check for madvise(..., MADV_DONTNEED).
   1854   JE_COMPILABLE([madvise(..., MADV_DONTNEED)], [
   1855 #include <sys/mman.h>
   1856 ], [
   1857 	madvise((void *)0, 0, MADV_DONTNEED);
   1858 ], [je_cv_madv_dontneed])
   1859   if test "x${je_cv_madv_dontneed}" = "xyes" ; then
   1860     AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
   1861   fi
   1862 
   1863   dnl Check for madvise(..., MADV_DO[NT]DUMP).
   1864   JE_COMPILABLE([madvise(..., MADV_DO[[NT]]DUMP)], [
   1865 #include <sys/mman.h>
   1866 ], [
   1867 	madvise((void *)0, 0, MADV_DONTDUMP);
   1868 	madvise((void *)0, 0, MADV_DODUMP);
   1869 ], [je_cv_madv_dontdump])
   1870   if test "x${je_cv_madv_dontdump}" = "xyes" ; then
   1871     AC_DEFINE([JEMALLOC_MADVISE_DONTDUMP], [ ])
   1872   fi
   1873  
   1874   dnl Check for madvise(..., MADV_[NO]HUGEPAGE).
   1875   JE_COMPILABLE([madvise(..., MADV_[[NO]]HUGEPAGE)], [
   1876 #include <sys/mman.h>
   1877 ], [
   1878 	madvise((void *)0, 0, MADV_HUGEPAGE);
   1879 	madvise((void *)0, 0, MADV_NOHUGEPAGE);
   1880 ], [je_cv_thp])
   1881 case "${host_cpu}" in
   1882   arm*)
   1883     ;;
   1884   *)
   1885   if test "x${je_cv_thp}" = "xyes" ; then
   1886     AC_DEFINE([JEMALLOC_HAVE_MADVISE_HUGE], [ ])
   1887   fi
   1888   ;;
   1889 esac
   1890 fi
   1891 
   1892 dnl ============================================================================
   1893 dnl Check whether __sync_{add,sub}_and_fetch() are available despite
   1894 dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
   1895 
   1896 AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
   1897   AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
   1898                [je_cv_sync_compare_and_swap_$2],
   1899                [AC_LINK_IFELSE([AC_LANG_PROGRAM([
   1900                                                  #include <stdint.h>
   1901                                                 ],
   1902                                                 [
   1903                                                  #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
   1904                                                  {
   1905                                                     uint$1_t x$1 = 0;
   1906                                                     __sync_add_and_fetch(&x$1, 42);
   1907                                                     __sync_sub_and_fetch(&x$1, 1);
   1908                                                  }
   1909                                                  #else
   1910                                                  #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
   1911                                                  #endif
   1912                                                 ])],
   1913                                [je_cv_sync_compare_and_swap_$2=yes],
   1914                                [je_cv_sync_compare_and_swap_$2=no])])
   1915 
   1916   if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
   1917     AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
   1918   fi
   1919 ])
   1920 
   1921 if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
   1922   JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
   1923   JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
   1924 fi
   1925 
   1926 dnl ============================================================================
   1927 dnl Check for __builtin_clz() and __builtin_clzl().
   1928 
   1929 AC_CACHE_CHECK([for __builtin_clz],
   1930                [je_cv_builtin_clz],
   1931                [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
   1932                                                 [
   1933                                                 {
   1934                                                         unsigned x = 0;
   1935                                                         int y = __builtin_clz(x);
   1936                                                 }
   1937                                                 {
   1938                                                         unsigned long x = 0;
   1939                                                         int y = __builtin_clzl(x);
   1940                                                 }
   1941                                                 ])],
   1942                                [je_cv_builtin_clz=yes],
   1943                                [je_cv_builtin_clz=no])])
   1944 
   1945 if test "x${je_cv_builtin_clz}" = "xyes" ; then
   1946   AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
   1947 fi
   1948 
   1949 dnl ============================================================================
   1950 dnl Check for os_unfair_lock operations as provided on Darwin.
   1951 
   1952 JE_COMPILABLE([Darwin os_unfair_lock_*()], [
   1953 #include <os/lock.h>
   1954 #include <AvailabilityMacros.h>
   1955 ], [
   1956 	#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
   1957 	#error "os_unfair_lock is not supported"
   1958 	#else
   1959 	os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
   1960 	os_unfair_lock_lock(&lock);
   1961 	os_unfair_lock_unlock(&lock);
   1962 	#endif
   1963 ], [je_cv_os_unfair_lock])
   1964 if test "x${je_cv_os_unfair_lock}" = "xyes" ; then
   1965   AC_DEFINE([JEMALLOC_OS_UNFAIR_LOCK], [ ])
   1966 fi
   1967 
   1968 dnl ============================================================================
   1969 dnl Check for spinlock(3) operations as provided on Darwin.
   1970 
   1971 JE_COMPILABLE([Darwin OSSpin*()], [
   1972 #include <libkern/OSAtomic.h>
   1973 #include <inttypes.h>
   1974 ], [
   1975 	OSSpinLock lock = 0;
   1976 	OSSpinLockLock(&lock);
   1977 	OSSpinLockUnlock(&lock);
   1978 ], [je_cv_osspin])
   1979 if test "x${je_cv_osspin}" = "xyes" ; then
   1980   AC_DEFINE([JEMALLOC_OSSPIN], [ ])
   1981 fi
   1982 
   1983 dnl ============================================================================
   1984 dnl Darwin-related configuration.
   1985 
   1986 AC_ARG_ENABLE([zone-allocator],
   1987   [AS_HELP_STRING([--disable-zone-allocator],
   1988                   [Disable zone allocator for Darwin])],
   1989 [if test "x$enable_zone_allocator" = "xno" ; then
   1990   enable_zone_allocator="0"
   1991 else
   1992   enable_zone_allocator="1"
   1993 fi
   1994 ],
   1995 [if test "x${abi}" = "xmacho"; then
   1996   enable_zone_allocator="1"
   1997 fi
   1998 ]
   1999 )
   2000 AC_SUBST([enable_zone_allocator])
   2001 
   2002 if test "x${enable_zone_allocator}" = "x1" ; then
   2003   if test "x${abi}" != "xmacho"; then
   2004     AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
   2005   fi
   2006   AC_DEFINE([JEMALLOC_ZONE], [ ])
   2007 fi
   2008 
   2009 dnl ============================================================================
   2010 dnl Use initial-exec TLS by default.
   2011 AC_ARG_ENABLE([initial-exec-tls],
   2012   [AS_HELP_STRING([--disable-initial-exec-tls],
   2013                   [Disable the initial-exec tls model])],
   2014 [if test "x$enable_initial_exec_tls" = "xno" ; then
   2015   enable_initial_exec_tls="0"
   2016 else
   2017   enable_initial_exec_tls="1"
   2018 fi
   2019 ],
   2020 [enable_initial_exec_tls="1"]
   2021 )
   2022 AC_SUBST([enable_initial_exec_tls])
   2023 
   2024 if test "x${je_cv_tls_model}" = "xyes" -a \
   2025        "x${enable_initial_exec_tls}" = "x1" ; then
   2026   AC_DEFINE([JEMALLOC_TLS_MODEL],
   2027             [__attribute__((tls_model("initial-exec")))])
   2028 else
   2029   AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
   2030 fi
   2031 
   2032 dnl ============================================================================
   2033 dnl Enable background threads if possible.
   2034 
   2035 if test "x${have_pthread}" = "x1" -a "x${have_dlsym}" = "x1" \
   2036     -a "x${je_cv_os_unfair_lock}" != "xyes" \
   2037     -a "x${je_cv_osspin}" != "xyes" ; then
   2038   AC_DEFINE([JEMALLOC_BACKGROUND_THREAD])
   2039 fi
   2040 
   2041 dnl ============================================================================
   2042 dnl Check for glibc malloc hooks
   2043 
   2044 JE_COMPILABLE([glibc malloc hook], [
   2045 #include <stddef.h>
   2046 
   2047 extern void (* __free_hook)(void *ptr);
   2048 extern void *(* __malloc_hook)(size_t size);
   2049 extern void *(* __realloc_hook)(void *ptr, size_t size);
   2050 ], [
   2051   void *ptr = 0L;
   2052   if (__malloc_hook) ptr = __malloc_hook(1);
   2053   if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
   2054   if (__free_hook && ptr) __free_hook(ptr);
   2055 ], [je_cv_glibc_malloc_hook])
   2056 if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
   2057   if test "x${JEMALLOC_PREFIX}" = "x" ; then
   2058     AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
   2059     wrap_syms="${wrap_syms} __free_hook __malloc_hook __realloc_hook"
   2060   fi
   2061 fi
   2062 
   2063 JE_COMPILABLE([glibc memalign hook], [
   2064 #include <stddef.h>
   2065 
   2066 extern void *(* __memalign_hook)(size_t alignment, size_t size);
   2067 ], [
   2068   void *ptr = 0L;
   2069   if (__memalign_hook) ptr = __memalign_hook(16, 7);
   2070 ], [je_cv_glibc_memalign_hook])
   2071 if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
   2072   if test "x${JEMALLOC_PREFIX}" = "x" ; then
   2073     AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
   2074     wrap_syms="${wrap_syms} __memalign_hook"
   2075   fi
   2076 fi
   2077 
   2078 JE_COMPILABLE([pthreads adaptive mutexes], [
   2079 #include <pthread.h>
   2080 ], [
   2081   pthread_mutexattr_t attr;
   2082   pthread_mutexattr_init(&attr);
   2083   pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
   2084   pthread_mutexattr_destroy(&attr);
   2085 ], [je_cv_pthread_mutex_adaptive_np])
   2086 if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
   2087   AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
   2088 fi
   2089 
   2090 JE_CFLAGS_SAVE()
   2091 JE_CFLAGS_ADD([-D_GNU_SOURCE])
   2092 JE_CFLAGS_ADD([-Werror])
   2093 JE_CFLAGS_ADD([-herror_on_warning])
   2094 JE_COMPILABLE([strerror_r returns char with gnu source], [
   2095 #include <errno.h>
   2096 #include <stdio.h>
   2097 #include <stdlib.h>
   2098 #include <string.h>
   2099 ], [
   2100   char *buffer = (char *) malloc(100);
   2101   char *error = strerror_r(EINVAL, buffer, 100);
   2102   printf("%s\n", error);
   2103 ], [je_cv_strerror_r_returns_char_with_gnu_source])
   2104 JE_CFLAGS_RESTORE()
   2105 if test "x${je_cv_strerror_r_returns_char_with_gnu_source}" = "xyes" ; then
   2106   AC_DEFINE([JEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE], [ ])
   2107 fi
   2108 
   2109 dnl ============================================================================
   2110 dnl Check for typedefs, structures, and compiler characteristics.
   2111 AC_HEADER_STDBOOL
   2112 
   2113 dnl ============================================================================
   2114 dnl Define commands that generate output files.
   2115 
   2116 AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
   2117   f="${objroot}include/jemalloc/internal/public_symbols.txt"
   2118   mkdir -p "${objroot}include/jemalloc/internal"
   2119   cp /dev/null "${f}"
   2120   for nm in `echo ${mangling_map} |tr ',' ' '` ; do
   2121     n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
   2122     m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
   2123     echo "${n}:${m}" >> "${f}"
   2124     dnl Remove name from public_syms so that it isn't redefined later.
   2125     public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
   2126   done
   2127   for sym in ${public_syms} ; do
   2128     n="${sym}"
   2129     m="${JEMALLOC_PREFIX}${sym}"
   2130     echo "${n}:${m}" >> "${f}"
   2131   done
   2132 ], [
   2133   srcdir="${srcdir}"
   2134   objroot="${objroot}"
   2135   mangling_map="${mangling_map}"
   2136   public_syms="${public_syms}"
   2137   JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
   2138 ])
   2139 AC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols.awk], [
   2140   f="${objroot}include/jemalloc/internal/private_symbols.awk"
   2141   mkdir -p "${objroot}include/jemalloc/internal"
   2142   export_syms=`for sym in ${public_syms}; do echo "${JEMALLOC_PREFIX}${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
   2143   "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols.awk"
   2144 ], [
   2145   srcdir="${srcdir}"
   2146   objroot="${objroot}"
   2147   public_syms="${public_syms}"
   2148   wrap_syms="${wrap_syms}"
   2149   SYM_PREFIX="${SYM_PREFIX}"
   2150   JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
   2151 ])
   2152 AC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols_jet.awk], [
   2153   f="${objroot}include/jemalloc/internal/private_symbols_jet.awk"
   2154   mkdir -p "${objroot}include/jemalloc/internal"
   2155   export_syms=`for sym in ${public_syms}; do echo "jet_${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
   2156   "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols_jet.awk"
   2157 ], [
   2158   srcdir="${srcdir}"
   2159   objroot="${objroot}"
   2160   public_syms="${public_syms}"
   2161   wrap_syms="${wrap_syms}"
   2162   SYM_PREFIX="${SYM_PREFIX}"
   2163 ])
   2164 AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
   2165   mkdir -p "${objroot}include/jemalloc/internal"
   2166   "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
   2167 ], [
   2168   srcdir="${srcdir}"
   2169   objroot="${objroot}"
   2170 ])
   2171 AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
   2172   mkdir -p "${objroot}include/jemalloc/internal"
   2173   "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
   2174 ], [
   2175   srcdir="${srcdir}"
   2176   objroot="${objroot}"
   2177 ])
   2178 AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
   2179   mkdir -p "${objroot}include/jemalloc/internal"
   2180   "${SHELL}" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" 3 "${LG_PAGE_SIZES}" 2 > "${objroot}include/jemalloc/internal/size_classes.h"
   2181 ], [
   2182   SHELL="${SHELL}"
   2183   srcdir="${srcdir}"
   2184   objroot="${objroot}"
   2185   LG_QUANTA="${LG_QUANTA}"
   2186   LG_PAGE_SIZES="${LG_PAGE_SIZES}"
   2187 ])
   2188 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
   2189   mkdir -p "${objroot}include/jemalloc"
   2190   cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
   2191 ], [
   2192   srcdir="${srcdir}"
   2193   objroot="${objroot}"
   2194 ])
   2195 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
   2196   mkdir -p "${objroot}include/jemalloc"
   2197   "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
   2198 ], [
   2199   srcdir="${srcdir}"
   2200   objroot="${objroot}"
   2201 ])
   2202 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
   2203   mkdir -p "${objroot}include/jemalloc"
   2204   "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
   2205 ], [
   2206   srcdir="${srcdir}"
   2207   objroot="${objroot}"
   2208 ])
   2209 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
   2210   mkdir -p "${objroot}include/jemalloc"
   2211   "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
   2212 ], [
   2213   srcdir="${srcdir}"
   2214   objroot="${objroot}"
   2215 ])
   2216 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
   2217   mkdir -p "${objroot}include/jemalloc"
   2218   "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
   2219 ], [
   2220   srcdir="${srcdir}"
   2221   objroot="${objroot}"
   2222   install_suffix="${install_suffix}"
   2223 ])
   2224 
   2225 dnl Process .in files.
   2226 AC_SUBST([cfghdrs_in])
   2227 AC_SUBST([cfghdrs_out])
   2228 AC_CONFIG_HEADERS([$cfghdrs_tup])
   2229 
   2230 dnl ============================================================================
   2231 dnl Generate outputs.
   2232 
   2233 AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
   2234 AC_SUBST([cfgoutputs_in])
   2235 AC_SUBST([cfgoutputs_out])
   2236 AC_OUTPUT
   2237 
   2238 dnl ============================================================================
   2239 dnl Print out the results of configuration.
   2240 AC_MSG_RESULT([===============================================================================])
   2241 AC_MSG_RESULT([jemalloc version   : ${jemalloc_version}])
   2242 AC_MSG_RESULT([library revision   : ${rev}])
   2243 AC_MSG_RESULT([])
   2244 AC_MSG_RESULT([CONFIG             : ${CONFIG}])
   2245 AC_MSG_RESULT([CC                 : ${CC}])
   2246 AC_MSG_RESULT([CONFIGURE_CFLAGS   : ${CONFIGURE_CFLAGS}])
   2247 AC_MSG_RESULT([SPECIFIED_CFLAGS   : ${SPECIFIED_CFLAGS}])
   2248 AC_MSG_RESULT([EXTRA_CFLAGS       : ${EXTRA_CFLAGS}])
   2249 AC_MSG_RESULT([CPPFLAGS           : ${CPPFLAGS}])
   2250 AC_MSG_RESULT([CXX                : ${CXX}])
   2251 AC_MSG_RESULT([CONFIGURE_CXXFLAGS : ${CONFIGURE_CXXFLAGS}])
   2252 AC_MSG_RESULT([SPECIFIED_CXXFLAGS : ${SPECIFIED_CXXFLAGS}])
   2253 AC_MSG_RESULT([EXTRA_CXXFLAGS     : ${EXTRA_CXXFLAGS}])
   2254 AC_MSG_RESULT([LDFLAGS            : ${LDFLAGS}])
   2255 AC_MSG_RESULT([EXTRA_LDFLAGS      : ${EXTRA_LDFLAGS}])
   2256 AC_MSG_RESULT([DSO_LDFLAGS        : ${DSO_LDFLAGS}])
   2257 AC_MSG_RESULT([LIBS               : ${LIBS}])
   2258 AC_MSG_RESULT([RPATH_EXTRA        : ${RPATH_EXTRA}])
   2259 AC_MSG_RESULT([])
   2260 AC_MSG_RESULT([XSLTPROC           : ${XSLTPROC}])
   2261 AC_MSG_RESULT([XSLROOT            : ${XSLROOT}])
   2262 AC_MSG_RESULT([])
   2263 AC_MSG_RESULT([PREFIX             : ${PREFIX}])
   2264 AC_MSG_RESULT([BINDIR             : ${BINDIR}])
   2265 AC_MSG_RESULT([DATADIR            : ${DATADIR}])
   2266 AC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
   2267 AC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
   2268 AC_MSG_RESULT([MANDIR             : ${MANDIR}])
   2269 AC_MSG_RESULT([])
   2270 AC_MSG_RESULT([srcroot            : ${srcroot}])
   2271 AC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
   2272 AC_MSG_RESULT([objroot            : ${objroot}])
   2273 AC_MSG_RESULT([abs_objroot        : ${abs_objroot}])
   2274 AC_MSG_RESULT([])
   2275 AC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
   2276 AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
   2277 AC_MSG_RESULT([                   : ${JEMALLOC_PRIVATE_NAMESPACE}])
   2278 AC_MSG_RESULT([install_suffix     : ${install_suffix}])
   2279 AC_MSG_RESULT([malloc_conf        : ${config_malloc_conf}])
   2280 AC_MSG_RESULT([autogen            : ${enable_autogen}])
   2281 AC_MSG_RESULT([debug              : ${enable_debug}])
   2282 AC_MSG_RESULT([stats              : ${enable_stats}])
   2283 AC_MSG_RESULT([prof               : ${enable_prof}])
   2284 AC_MSG_RESULT([prof-libunwind     : ${enable_prof_libunwind}])
   2285 AC_MSG_RESULT([prof-libgcc        : ${enable_prof_libgcc}])
   2286 AC_MSG_RESULT([prof-gcc           : ${enable_prof_gcc}])
   2287 AC_MSG_RESULT([fill               : ${enable_fill}])
   2288 AC_MSG_RESULT([utrace             : ${enable_utrace}])
   2289 AC_MSG_RESULT([xmalloc            : ${enable_xmalloc}])
   2290 AC_MSG_RESULT([log                : ${enable_log}])
   2291 AC_MSG_RESULT([lazy_lock          : ${enable_lazy_lock}])
   2292 AC_MSG_RESULT([cache-oblivious    : ${enable_cache_oblivious}])
   2293 AC_MSG_RESULT([cxx                : ${enable_cxx}])
   2294 AC_MSG_RESULT([===============================================================================])
   2295