1 dnl Process this file with autoconf to produce a configure script.
4 dnl ============================================================================
5 dnl Custom macro definitions.
7 dnl JE_CFLAGS_APPEND(cflag)
8 AC_DEFUN([JE_CFLAGS_APPEND],
10 AC_MSG_CHECKING([whether compiler supports $1])
12 if test "x${CFLAGS}" = "x" ; then
17 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
28 dnl JE_COMPILABLE(label, hcode, mcode, rvar)
30 dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
32 AC_DEFUN([JE_COMPILABLE],
34 AC_CACHE_CHECK([whether $1 is compilable],
36 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
42 dnl ============================================================================
49 if test "x${srcroot}" = "x." ; then
55 abs_srcroot="`cd \"${srcdir}\"; pwd`/"
56 AC_SUBST([abs_srcroot])
61 AC_SUBST([abs_objroot])
63 dnl Munge install path variables.
64 if test "x$prefix" = "xNONE" ; then
67 if test "x$exec_prefix" = "xNONE" ; then
72 BINDIR=`eval echo $bindir`
73 BINDIR=`eval echo $BINDIR`
75 INCLUDEDIR=`eval echo $includedir`
76 INCLUDEDIR=`eval echo $INCLUDEDIR`
77 AC_SUBST([INCLUDEDIR])
78 LIBDIR=`eval echo $libdir`
79 LIBDIR=`eval echo $LIBDIR`
81 DATADIR=`eval echo $datadir`
82 DATADIR=`eval echo $DATADIR`
84 MANDIR=`eval echo $mandir`
85 MANDIR=`eval echo $MANDIR`
88 dnl Support for building documentation.
89 AC_PATH_PROG([XSLTPROC], [xsltproc], , [$PATH])
90 if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
91 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
92 elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
93 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
95 dnl Documentation building will fail if this default gets used.
98 AC_ARG_WITH([xslroot],
99 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
100 if test "x$with_xslroot" = "xno" ; then
101 XSLROOT="${DEFAULT_XSLROOT}"
103 XSLROOT="${with_xslroot}"
106 XSLROOT="${DEFAULT_XSLROOT}"
110 dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
111 dnl just prevent autoconf from molesting CFLAGS.
114 if test "x$GCC" != "xyes" ; then
115 AC_CACHE_CHECK([whether compiler is MSVC],
117 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
127 if test "x$CFLAGS" = "x" ; then
129 if test "x$GCC" = "xyes" ; then
130 JE_CFLAGS_APPEND([-std=gnu99])
131 JE_CFLAGS_APPEND([-Wall])
132 JE_CFLAGS_APPEND([-pipe])
133 JE_CFLAGS_APPEND([-g3])
134 elif test "x$je_cv_msvc" = "xyes" ; then
136 JE_CFLAGS_APPEND([-Zi])
137 JE_CFLAGS_APPEND([-MT])
138 JE_CFLAGS_APPEND([-W3])
139 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat"
142 dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
143 if test "x$EXTRA_CFLAGS" != "x" ; then
144 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
148 AC_CHECK_SIZEOF([void *])
149 if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
151 elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
154 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
156 AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
158 AC_CHECK_SIZEOF([int])
159 if test "x${ac_cv_sizeof_int}" = "x8" ; then
161 elif test "x${ac_cv_sizeof_int}" = "x4" ; then
164 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
166 AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
168 AC_CHECK_SIZEOF([long])
169 if test "x${ac_cv_sizeof_long}" = "x8" ; then
171 elif test "x${ac_cv_sizeof_long}" = "x4" ; then
174 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
176 AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
178 AC_CHECK_SIZEOF([intmax_t])
179 if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
181 elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
183 elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
186 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
188 AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
191 dnl CPU-specific settings.
193 case "${host_cpu}" in
197 JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
199 if test "x${je_cv_asm}" = "xyes" ; then
200 CPU_SPINWAIT='__asm__ volatile("pause")'
204 JE_COMPILABLE([__asm__ syntax], [],
205 [[__asm__ volatile("pause"); return 0;]], [je_cv_asm])
206 if test "x${je_cv_asm}" = "xyes" ; then
207 CPU_SPINWAIT='__asm__ volatile("pause")'
213 AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
215 LD_PRELOAD_VAR="LD_PRELOAD"
222 DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
223 RPATH='-Wl,-rpath,$(1)'
225 PIC_CFLAGS='-fPIC -DPIC'
232 dnl Platform-specific settings. abi and RPATH can probably be determined
233 dnl programmatically, but doing so is error-prone, which makes it generally
234 dnl not worth the trouble.
236 dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
237 dnl definitions need to be seen before any headers are included, which is a pain
238 dnl to make happen otherwise.
244 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
246 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
250 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
256 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
261 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
263 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
264 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
268 AC_MSG_CHECKING([ABI])
269 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
276 [CFLAGS="$CFLAGS"; abi="elf"],
278 AC_MSG_RESULT([$abi])
279 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
285 dnl Solaris needs this for sigwait().
286 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
287 LIBS="$LIBS -lposix4 -lsocket -lnsl"
290 if "$LG_SIZEOF_PTR" = "8"; then
292 LD_PRELOAD_VAR="LDR_PRELOAD64"
295 LD_PRELOAD_VAR="LDR_PRELOAD"
304 if test "x$je_cv_msvc" = "xyes" ; then
307 EXTRA_LDFLAGS="-link -DEBUG"
310 MKLIB='lib -nologo -out:$@'
314 DSO_LDFLAGS="-shared"
322 AC_MSG_RESULT([Unsupported operating system: ${host}])
328 AC_SUBST([LD_PRELOAD_VAR])
330 AC_SUBST([importlib])
334 AC_SUBST([libprefix])
335 AC_SUBST([DSO_LDFLAGS])
336 AC_SUBST([EXTRA_LDFLAGS])
338 AC_SUBST([PIC_CFLAGS])
344 if test "x$abi" != "xpecoff"; then
345 dnl Heap profiling uses the log(3) function.
349 JE_COMPILABLE([__attribute__ syntax],
350 [static __attribute__((unused)) void foo(void){}],
353 if test "x${je_cv_attribute}" = "xyes" ; then
354 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
355 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
356 JE_CFLAGS_APPEND([-fvisibility=hidden])
359 dnl Check for tls_model attribute support (clang 3.0 still lacks support).
360 SAVED_CFLAGS="${CFLAGS}"
361 JE_CFLAGS_APPEND([-Werror])
362 JE_COMPILABLE([tls_model attribute], [],
364 __attribute__((tls_model("initial-exec"))) foo;
367 CFLAGS="${SAVED_CFLAGS}"
368 if test "x${je_cv_tls_model}" = "xyes" ; then
369 AC_DEFINE([JEMALLOC_TLS_MODEL],
370 [__attribute__((tls_model("initial-exec")))])
372 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
375 dnl Support optional additions to rpath.
377 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
378 if test "x$with_rpath" = "xno" ; then
381 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
385 AC_SUBST([RPATH_EXTRA])
387 dnl Disable rules that do automatic regeneration of configure output by default.
388 AC_ARG_ENABLE([autogen],
389 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
390 if test "x$enable_autogen" = "xno" ; then
398 AC_SUBST([enable_autogen])
402 AC_PATH_PROG([AR], [ar], , [$PATH])
403 AC_PATH_PROG([LD], [ld], , [$PATH])
404 AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
406 public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib"
408 dnl Check for allocator-related functions that should be wrapped.
409 AC_CHECK_FUNC([memalign],
410 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
411 public_syms="${public_syms} memalign"])
412 AC_CHECK_FUNC([valloc],
413 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
414 public_syms="${public_syms} valloc"])
416 dnl Support the experimental API by default.
417 AC_ARG_ENABLE([experimental],
418 [AS_HELP_STRING([--disable-experimental],
419 [Disable support for the experimental API])],
420 [if test "x$enable_experimental" = "xno" ; then
421 enable_experimental="0"
423 enable_experimental="1"
426 [enable_experimental="1"]
428 if test "x$enable_experimental" = "x1" ; then
429 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
430 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
432 AC_SUBST([enable_experimental])
434 dnl Perform no name mangling by default.
435 AC_ARG_WITH([mangling],
436 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
437 [mangling_map="$with_mangling"], [mangling_map=""])
438 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
439 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
441 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
442 AC_DEFINE_UNQUOTED([${n}], [${m}])
443 dnl Remove key from public_syms so that it isn't redefined later.
444 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
447 dnl Do not prefix public APIs by default.
448 AC_ARG_WITH([jemalloc_prefix],
449 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
450 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
451 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
454 JEMALLOC_PREFIX="je_"
457 if test "x$JEMALLOC_PREFIX" != "x" ; then
458 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
459 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
460 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
462 dnl Generate macros to rename public symbols. All public symbols are prefixed
463 dnl with je_ in the source code, so these macro definitions are needed even if
464 dnl --with-jemalloc-prefix wasn't specified.
465 for stem in ${public_syms}; do
467 m="${JEMALLOC_PREFIX}${stem}"
468 AC_DEFINE_UNQUOTED([${n}], [${m}])
471 dnl Do not mangle library-private APIs by default.
472 AC_ARG_WITH([private_namespace],
473 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
474 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
475 [JEMALLOC_PRIVATE_NAMESPACE=""]
477 AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
478 if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
479 AC_DEFINE_UNQUOTED([JEMALLOC_N(string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix)], [${JEMALLOC_PRIVATE_NAMESPACE}##string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix])
481 AC_DEFINE_UNQUOTED([JEMALLOC_N(string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix)], [string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix])
484 dnl Do not add suffix to installed files by default.
485 AC_ARG_WITH([install_suffix],
486 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
487 [INSTALL_SUFFIX="$with_install_suffix"],
490 install_suffix="$INSTALL_SUFFIX"
491 AC_SUBST([install_suffix])
493 cfgoutputs_in="${srcroot}Makefile.in"
494 cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
495 cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
496 cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
497 cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
498 cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
499 cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
501 cfgoutputs_out="Makefile"
502 cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
503 cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
504 cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
505 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
506 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
507 cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
509 cfgoutputs_tup="Makefile"
510 cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
511 cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
512 cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
513 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
514 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
515 cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
517 cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
518 cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
520 cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
521 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
523 cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
525 dnl Do not silence irrelevant compiler warnings by default, since enabling this
526 dnl option incurs a performance penalty.
527 AC_ARG_ENABLE([cc-silence],
528 [AS_HELP_STRING([--enable-cc-silence],
529 [Silence irrelevant compiler warnings])],
530 [if test "x$enable_cc_silence" = "xno" ; then
531 enable_cc_silence="0"
533 enable_cc_silence="1"
536 [enable_cc_silence="0"]
538 if test "x$enable_cc_silence" = "x1" ; then
539 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
542 dnl Do not compile with debugging by default.
543 AC_ARG_ENABLE([debug],
544 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
545 [if test "x$enable_debug" = "xno" ; then
553 if test "x$enable_debug" = "x1" ; then
554 AC_DEFINE([JEMALLOC_DEBUG], [ ])
555 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
557 AC_SUBST([enable_debug])
559 dnl Only optimize if not debugging.
560 if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
561 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
563 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
564 if test "x${optimize}" = "xyes" ; then
565 if test "x$GCC" = "xyes" ; then
566 JE_CFLAGS_APPEND([-O3])
567 JE_CFLAGS_APPEND([-funroll-loops])
568 elif test "x$je_cv_msvc" = "xyes" ; then
569 JE_CFLAGS_APPEND([-O2])
571 JE_CFLAGS_APPEND([-O])
576 dnl Enable statistics calculation by default.
577 AC_ARG_ENABLE([stats],
578 [AS_HELP_STRING([--disable-stats],
579 [Disable statistics calculation/reporting])],
580 [if test "x$enable_stats" = "xno" ; then
588 if test "x$enable_stats" = "x1" ; then
589 AC_DEFINE([JEMALLOC_STATS], [ ])
591 AC_SUBST([enable_stats])
593 dnl Do not enable profiling by default.
594 AC_ARG_ENABLE([prof],
595 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
596 [if test "x$enable_prof" = "xno" ; then
604 if test "x$enable_prof" = "x1" ; then
607 backtrace_method="N/A"
610 AC_ARG_ENABLE([prof-libunwind],
611 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
612 [if test "x$enable_prof_libunwind" = "xno" ; then
613 enable_prof_libunwind="0"
615 enable_prof_libunwind="1"
618 [enable_prof_libunwind="0"]
620 AC_ARG_WITH([static_libunwind],
621 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
622 [Path to static libunwind library; use rather than dynamically linking])],
623 if test "x$with_static_libunwind" = "xno" ; then
626 if test ! -f "$with_static_libunwind" ; then
627 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
629 LUNWIND="$with_static_libunwind"
633 if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
634 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
635 if test "x$LUNWIND" = "x-lunwind" ; then
636 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
637 [enable_prof_libunwind="0"])
639 LIBS="$LIBS $LUNWIND"
641 if test "x${enable_prof_libunwind}" = "x1" ; then
642 backtrace_method="libunwind"
643 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
647 AC_ARG_ENABLE([prof-libgcc],
648 [AS_HELP_STRING([--disable-prof-libgcc],
649 [Do not use libgcc for backtracing])],
650 [if test "x$enable_prof_libgcc" = "xno" ; then
651 enable_prof_libgcc="0"
653 enable_prof_libgcc="1"
656 [enable_prof_libgcc="1"]
658 if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
659 -a "x$GCC" = "xyes" ; then
660 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
661 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
662 dnl The following is conservative, in that it only has entries for CPUs on
663 dnl which jemalloc has been tested.
664 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
665 case "${host_cpu}" in
667 AC_MSG_RESULT([unreliable])
668 enable_prof_libgcc="0";
671 AC_MSG_RESULT([reliable])
674 AC_MSG_RESULT([unreliable])
675 enable_prof_libgcc="0";
678 if test "x${enable_prof_libgcc}" = "x1" ; then
679 backtrace_method="libgcc"
680 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
683 enable_prof_libgcc="0"
686 AC_ARG_ENABLE([prof-gcc],
687 [AS_HELP_STRING([--disable-prof-gcc],
688 [Do not use gcc intrinsics for backtracing])],
689 [if test "x$enable_prof_gcc" = "xno" ; then
695 [enable_prof_gcc="1"]
697 if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
698 -a "x$GCC" = "xyes" ; then
699 backtrace_method="gcc intrinsics"
700 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
705 if test "x$backtrace_method" = "x" ; then
706 backtrace_method="none (disabling profiling)"
709 AC_MSG_CHECKING([configured backtracing method])
710 AC_MSG_RESULT([$backtrace_method])
711 if test "x$enable_prof" = "x1" ; then
712 if test "x${force_tls}" = "x0" ; then
713 AC_MSG_ERROR([Heap profiling requires TLS]);
716 AC_DEFINE([JEMALLOC_PROF], [ ])
718 AC_SUBST([enable_prof])
720 dnl Enable thread-specific caching by default.
721 AC_ARG_ENABLE([tcache],
722 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
723 [if test "x$enable_tcache" = "xno" ; then
731 if test "x$enable_tcache" = "x1" ; then
732 AC_DEFINE([JEMALLOC_TCACHE], [ ])
734 AC_SUBST([enable_tcache])
736 dnl Disable mremap() for huge realloc() by default.
737 AC_ARG_ENABLE([mremap],
738 [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
739 [if test "x$enable_mremap" = "xno" ; then
747 if test "x$enable_mremap" = "x1" ; then
748 JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
750 #include <sys/mman.h>
752 void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
753 ], [je_cv_mremap_fixed])
754 if test "x${je_cv_mremap_fixed}" = "xno" ; then
758 if test "x$enable_mremap" = "x1" ; then
759 AC_DEFINE([JEMALLOC_MREMAP], [ ])
761 AC_SUBST([enable_mremap])
763 dnl Enable VM deallocation via munmap() by default.
764 AC_ARG_ENABLE([munmap],
765 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
766 [if test "x$enable_munmap" = "xno" ; then
772 [enable_munmap="${default_munmap}"]
774 if test "x$enable_munmap" = "x1" ; then
775 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
777 AC_SUBST([enable_munmap])
779 dnl Do not enable allocation from DSS by default.
781 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
782 [if test "x$enable_dss" = "xno" ; then
790 dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
791 AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
792 if test "x$have_sbrk" = "x1" ; then
793 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
798 if test "x$enable_dss" = "x1" ; then
799 AC_DEFINE([JEMALLOC_DSS], [ ])
801 AC_SUBST([enable_dss])
803 dnl Support the junk/zero filling option by default.
804 AC_ARG_ENABLE([fill],
805 [AS_HELP_STRING([--disable-fill],
806 [Disable support for junk/zero filling, quarantine, and redzones])],
807 [if test "x$enable_fill" = "xno" ; then
815 if test "x$enable_fill" = "x1" ; then
816 AC_DEFINE([JEMALLOC_FILL], [ ])
818 AC_SUBST([enable_fill])
820 dnl Disable utrace(2)-based tracing by default.
821 AC_ARG_ENABLE([utrace],
822 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
823 [if test "x$enable_utrace" = "xno" ; then
831 JE_COMPILABLE([utrace(2)], [
832 #include <sys/types.h>
833 #include <sys/param.h>
834 #include <sys/time.h>
836 #include <sys/ktrace.h>
838 utrace((void *)0, 0);
840 if test "x${je_cv_utrace}" = "xno" ; then
843 if test "x$enable_utrace" = "x1" ; then
844 AC_DEFINE([JEMALLOC_UTRACE], [ ])
846 AC_SUBST([enable_utrace])
848 dnl Support Valgrind by default.
849 AC_ARG_ENABLE([valgrind],
850 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
851 [if test "x$enable_valgrind" = "xno" ; then
857 [enable_valgrind="1"]
859 if test "x$enable_valgrind" = "x1" ; then
860 JE_COMPILABLE([valgrind], [
861 #include <valgrind/valgrind.h>
862 #include <valgrind/memcheck.h>
864 #if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
865 # error "Incompatible Valgrind version"
867 ], [], [je_cv_valgrind])
868 if test "x${je_cv_valgrind}" = "xno" ; then
871 if test "x$enable_valgrind" = "x1" ; then
872 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
875 AC_SUBST([enable_valgrind])
877 dnl Do not support the xmalloc option by default.
878 AC_ARG_ENABLE([xmalloc],
879 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
880 [if test "x$enable_xmalloc" = "xno" ; then
888 if test "x$enable_xmalloc" = "x1" ; then
889 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
891 AC_SUBST([enable_xmalloc])
893 AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
894 [je_cv_static_page_shift],
895 AC_RUN_IFELSE([AC_LANG_PROGRAM(
912 result = si.dwPageSize;
914 result = sysconf(_SC_PAGESIZE);
919 result = ffsl(result) - 1;
921 f = fopen("conftest.out", "w");
925 fprintf(f, "%u\n", result);
930 [je_cv_static_page_shift=`cat conftest.out`],
931 [je_cv_static_page_shift=undefined]))
933 if test "x$je_cv_static_page_shift" != "xundefined"; then
934 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
936 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
939 dnl ============================================================================
940 dnl jemalloc configuration.
943 dnl Set VERSION if source directory has an embedded git repository.
944 if test -d "${srcroot}.git" ; then
945 git describe --long --abbrev=40 > ${srcroot}VERSION
947 jemalloc_version=`cat ${srcroot}VERSION`
948 jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
949 jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
950 jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
951 jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
952 jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
953 AC_SUBST([jemalloc_version])
954 AC_SUBST([jemalloc_version_major])
955 AC_SUBST([jemalloc_version_minor])
956 AC_SUBST([jemalloc_version_bugfix])
957 AC_SUBST([jemalloc_version_nrev])
958 AC_SUBST([jemalloc_version_gid])
960 dnl ============================================================================
961 dnl Configure pthreads.
963 if test "x$abi" != "xpecoff" ; then
964 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
965 dnl Some systems may embed pthreads functionality in libc; check for libpthread
966 dnl first, but try libc too before failing.
967 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
968 [AC_SEARCH_LIBS([pthread_create], , ,
969 AC_MSG_ERROR([libpthread is missing]))])
972 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
974 dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
975 dnl it rather than pthreads TSD cleanup functions to support cleanup during
976 dnl thread exit, in order to avoid pthreads library recursion during
978 AC_CHECK_FUNC([_malloc_thread_cleanup],
979 [have__malloc_thread_cleanup="1"],
980 [have__malloc_thread_cleanup="0"]
982 if test "x$have__malloc_thread_cleanup" = "x1" ; then
983 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
987 dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
988 dnl so, mutex initialization causes allocation, and we need to implement this
989 dnl callback function in order to prevent recursive allocation.
990 AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
991 [have__pthread_mutex_init_calloc_cb="1"],
992 [have__pthread_mutex_init_calloc_cb="0"]
994 if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
995 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
998 dnl Disable lazy locking by default.
999 AC_ARG_ENABLE([lazy_lock],
1000 [AS_HELP_STRING([--enable-lazy-lock],
1001 [Enable lazy locking (only lock when multi-threaded)])],
1002 [if test "x$enable_lazy_lock" = "xno" ; then
1003 enable_lazy_lock="0"
1005 enable_lazy_lock="1"
1008 [enable_lazy_lock="0"]
1010 if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1011 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1012 enable_lazy_lock="1"
1014 if test "x$enable_lazy_lock" = "x1" ; then
1015 if test "x$abi" != "xpecoff" ; then
1016 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1017 AC_CHECK_FUNC([dlsym], [],
1018 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1019 [AC_MSG_ERROR([libdl is missing])])
1022 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1024 AC_SUBST([enable_lazy_lock])
1026 AC_ARG_ENABLE([tls],
1027 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1028 if test "x$enable_tls" = "xno" ; then
1036 if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1037 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1040 if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1041 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1044 if test "x${enable_tls}" = "x1" ; then
1045 AC_MSG_CHECKING([for TLS])
1046 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1054 AC_MSG_RESULT([yes]),
1058 AC_SUBST([enable_tls])
1059 if test "x${enable_tls}" = "x1" ; then
1060 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1061 elif test "x${force_tls}" = "x1" ; then
1062 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
1065 dnl ============================================================================
1066 dnl Check for ffsl(3), and fail if not found. This function exists on all
1067 dnl platforms that jemalloc currently has a chance of functioning on without
1069 JE_COMPILABLE([a program using ffsl], [
1070 #include <strings.h>
1074 int rv = ffsl(0x08);
1076 ], [je_cv_function_ffsl])
1077 if test "x${je_cv_function_ffsl}" != "xyes" ; then
1078 AC_MSG_ERROR([Cannot build without ffsl(3)])
1081 dnl ============================================================================
1082 dnl Check for atomic(9) operations as provided on FreeBSD.
1084 JE_COMPILABLE([atomic(9)], [
1085 #include <sys/types.h>
1086 #include <machine/atomic.h>
1087 #include <inttypes.h>
1091 volatile uint32_t *x32p = &x32;
1092 atomic_fetchadd_32(x32p, 1);
1095 unsigned long xlong = 0;
1096 volatile unsigned long *xlongp = &xlong;
1097 atomic_fetchadd_long(xlongp, 1);
1100 if test "x${je_cv_atomic9}" = "xyes" ; then
1101 AC_DEFINE([JEMALLOC_ATOMIC9])
1104 dnl ============================================================================
1105 dnl Check for atomic(3) operations as provided on Darwin.
1107 JE_COMPILABLE([Darwin OSAtomic*()], [
1108 #include <libkern/OSAtomic.h>
1109 #include <inttypes.h>
1113 volatile int32_t *x32p = &x32;
1114 OSAtomicAdd32(1, x32p);
1118 volatile int64_t *x64p = &x64;
1119 OSAtomicAdd64(1, x64p);
1121 ], [je_cv_osatomic])
1122 if test "x${je_cv_osatomic}" = "xyes" ; then
1123 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1126 dnl ============================================================================
1127 dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1128 dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1130 AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1131 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1132 [je_cv_sync_compare_and_swap_$2],
1133 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1137 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1140 __sync_add_and_fetch(&x$1, 42);
1141 __sync_sub_and_fetch(&x$1, 1);
1144 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1147 [je_cv_sync_compare_and_swap_$2=yes],
1148 [je_cv_sync_compare_and_swap_$2=no])])
1150 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1151 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1155 if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
1156 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1157 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1160 dnl ============================================================================
1161 dnl Check for spinlock(3) operations as provided on Darwin.
1163 JE_COMPILABLE([Darwin OSSpin*()], [
1164 #include <libkern/OSAtomic.h>
1165 #include <inttypes.h>
1167 OSSpinLock lock = 0;
1168 OSSpinLockLock(&lock);
1169 OSSpinLockUnlock(&lock);
1171 if test "x${je_cv_osspin}" = "xyes" ; then
1172 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
1175 dnl ============================================================================
1176 dnl Darwin-related configuration.
1178 if test "x${abi}" = "xmacho" ; then
1179 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1180 AC_DEFINE([JEMALLOC_ZONE], [ ])
1182 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1183 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1184 dnl 10.6, which is the only source-level indication of the change.
1185 AC_MSG_CHECKING([malloc zone version])
1186 AC_DEFUN([JE_ZONE_PROGRAM],
1188 [#include <malloc/malloc.h>],
1189 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1192 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1193 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1194 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1195 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1196 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1198 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1199 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1201 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1202 AC_MSG_RESULT([unsupported])
1203 AC_MSG_ERROR([Unsupported malloc zone version])
1205 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1206 JEMALLOC_ZONE_VERSION=8
1207 AC_MSG_RESULT([> 8])
1209 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1211 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
1214 dnl ============================================================================
1215 dnl Check for typedefs, structures, and compiler characteristics.
1218 AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1219 mkdir -p "include/jemalloc/internal"
1220 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1223 dnl Process .in files.
1224 AC_SUBST([cfghdrs_in])
1225 AC_SUBST([cfghdrs_out])
1226 AC_CONFIG_HEADERS([$cfghdrs_tup])
1228 dnl ============================================================================
1229 dnl Generate outputs.
1230 AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
1231 AC_SUBST([cfgoutputs_in])
1232 AC_SUBST([cfgoutputs_out])
1235 dnl ============================================================================
1236 dnl Print out the results of configuration.
1237 AC_MSG_RESULT([===============================================================================])
1238 AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1239 AC_MSG_RESULT([library revision : ${rev}])
1241 AC_MSG_RESULT([CC : ${CC}])
1242 AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1243 AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1244 AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1245 AC_MSG_RESULT([LIBS : ${LIBS}])
1246 AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1248 AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1249 AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1251 AC_MSG_RESULT([PREFIX : ${PREFIX}])
1252 AC_MSG_RESULT([BINDIR : ${BINDIR}])
1253 AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1254 AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
1255 AC_MSG_RESULT([DATADIR : ${DATADIR}])
1256 AC_MSG_RESULT([MANDIR : ${MANDIR}])
1258 AC_MSG_RESULT([srcroot : ${srcroot}])
1259 AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1260 AC_MSG_RESULT([objroot : ${objroot}])
1261 AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1263 AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
1264 AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1265 AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
1266 AC_MSG_RESULT([install_suffix : ${install_suffix}])
1267 AC_MSG_RESULT([autogen : ${enable_autogen}])
1268 AC_MSG_RESULT([experimental : ${enable_experimental}])
1269 AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
1270 AC_MSG_RESULT([debug : ${enable_debug}])
1271 AC_MSG_RESULT([stats : ${enable_stats}])
1272 AC_MSG_RESULT([prof : ${enable_prof}])
1273 AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
1274 AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1275 AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
1276 AC_MSG_RESULT([tcache : ${enable_tcache}])
1277 AC_MSG_RESULT([fill : ${enable_fill}])
1278 AC_MSG_RESULT([utrace : ${enable_utrace}])
1279 AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1280 AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
1281 AC_MSG_RESULT([mremap : ${enable_mremap}])
1282 AC_MSG_RESULT([munmap : ${enable_munmap}])
1283 AC_MSG_RESULT([dss : ${enable_dss}])
1284 AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
1285 AC_MSG_RESULT([tls : ${enable_tls}])
1286 AC_MSG_RESULT([===============================================================================])