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.
240 JEMALLOC_USABLE_SIZE_CONST="const"
245 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
247 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
251 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
257 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
262 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
264 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
265 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
266 JEMALLOC_USABLE_SIZE_CONST=""
270 AC_MSG_CHECKING([ABI])
271 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
278 [CFLAGS="$CFLAGS"; abi="elf"],
280 AC_MSG_RESULT([$abi])
281 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
287 dnl Solaris needs this for sigwait().
288 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
289 LIBS="$LIBS -lposix4 -lsocket -lnsl"
292 if "$LG_SIZEOF_PTR" = "8"; then
294 LD_PRELOAD_VAR="LDR_PRELOAD64"
297 LD_PRELOAD_VAR="LDR_PRELOAD"
306 if test "x$je_cv_msvc" = "xyes" ; then
309 EXTRA_LDFLAGS="-link -DEBUG"
312 MKLIB='lib -nologo -out:$@'
316 DSO_LDFLAGS="-shared"
324 AC_MSG_RESULT([Unsupported operating system: ${host}])
328 AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
331 AC_SUBST([LD_PRELOAD_VAR])
333 AC_SUBST([importlib])
337 AC_SUBST([libprefix])
338 AC_SUBST([DSO_LDFLAGS])
339 AC_SUBST([EXTRA_LDFLAGS])
341 AC_SUBST([PIC_CFLAGS])
347 if test "x$abi" != "xpecoff"; then
348 dnl Heap profiling uses the log(3) function.
352 JE_COMPILABLE([__attribute__ syntax],
353 [static __attribute__((unused)) void foo(void){}],
356 if test "x${je_cv_attribute}" = "xyes" ; then
357 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
358 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
359 JE_CFLAGS_APPEND([-fvisibility=hidden])
362 dnl Check for tls_model attribute support (clang 3.0 still lacks support).
363 SAVED_CFLAGS="${CFLAGS}"
364 JE_CFLAGS_APPEND([-Werror])
365 JE_COMPILABLE([tls_model attribute], [],
367 __attribute__((tls_model("initial-exec"))) foo;
370 CFLAGS="${SAVED_CFLAGS}"
371 if test "x${je_cv_tls_model}" = "xyes" ; then
372 AC_DEFINE([JEMALLOC_TLS_MODEL],
373 [__attribute__((tls_model("initial-exec")))])
375 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
378 dnl Support optional additions to rpath.
380 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
381 if test "x$with_rpath" = "xno" ; then
384 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
388 AC_SUBST([RPATH_EXTRA])
390 dnl Disable rules that do automatic regeneration of configure output by default.
391 AC_ARG_ENABLE([autogen],
392 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
393 if test "x$enable_autogen" = "xno" ; then
401 AC_SUBST([enable_autogen])
405 AC_PATH_PROG([AR], [ar], , [$PATH])
406 AC_PATH_PROG([LD], [ld], , [$PATH])
407 AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
409 public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib"
411 dnl Check for allocator-related functions that should be wrapped.
412 AC_CHECK_FUNC([memalign],
413 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
414 public_syms="${public_syms} memalign"])
415 AC_CHECK_FUNC([valloc],
416 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
417 public_syms="${public_syms} valloc"])
419 dnl Support the experimental API by default.
420 AC_ARG_ENABLE([experimental],
421 [AS_HELP_STRING([--disable-experimental],
422 [Disable support for the experimental API])],
423 [if test "x$enable_experimental" = "xno" ; then
424 enable_experimental="0"
426 enable_experimental="1"
429 [enable_experimental="1"]
431 if test "x$enable_experimental" = "x1" ; then
432 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
433 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
435 AC_SUBST([enable_experimental])
437 dnl Perform no name mangling by default.
438 AC_ARG_WITH([mangling],
439 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
440 [mangling_map="$with_mangling"], [mangling_map=""])
441 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
442 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
444 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
445 AC_DEFINE_UNQUOTED([${n}], [${m}])
446 dnl Remove key from public_syms so that it isn't redefined later.
447 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
450 dnl Do not prefix public APIs by default.
451 AC_ARG_WITH([jemalloc_prefix],
452 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
453 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
454 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
457 JEMALLOC_PREFIX="je_"
460 if test "x$JEMALLOC_PREFIX" != "x" ; then
461 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
462 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
463 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
465 dnl Generate macros to rename public symbols. All public symbols are prefixed
466 dnl with je_ in the source code, so these macro definitions are needed even if
467 dnl --with-jemalloc-prefix wasn't specified.
468 for stem in ${public_syms}; do
470 m="${JEMALLOC_PREFIX}${stem}"
471 AC_DEFINE_UNQUOTED([${n}], [${m}])
474 dnl Do not mangle library-private APIs by default.
475 AC_ARG_WITH([private_namespace],
476 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
477 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
478 [JEMALLOC_PRIVATE_NAMESPACE=""]
480 AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
481 if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
482 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])
484 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])
487 dnl Do not add suffix to installed files by default.
488 AC_ARG_WITH([install_suffix],
489 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
490 [INSTALL_SUFFIX="$with_install_suffix"],
493 install_suffix="$INSTALL_SUFFIX"
494 AC_SUBST([install_suffix])
496 cfgoutputs_in="${srcroot}Makefile.in"
497 cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
498 cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
499 cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
500 cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
501 cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
502 cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
504 cfgoutputs_out="Makefile"
505 cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
506 cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
507 cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
508 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
509 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
510 cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
512 cfgoutputs_tup="Makefile"
513 cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
514 cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
515 cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
516 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
517 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
518 cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
520 cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
521 cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
523 cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
524 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
526 cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
528 dnl Do not silence irrelevant compiler warnings by default, since enabling this
529 dnl option incurs a performance penalty.
530 AC_ARG_ENABLE([cc-silence],
531 [AS_HELP_STRING([--enable-cc-silence],
532 [Silence irrelevant compiler warnings])],
533 [if test "x$enable_cc_silence" = "xno" ; then
534 enable_cc_silence="0"
536 enable_cc_silence="1"
539 [enable_cc_silence="0"]
541 if test "x$enable_cc_silence" = "x1" ; then
542 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
545 dnl Do not compile with debugging by default.
546 AC_ARG_ENABLE([debug],
547 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
548 [if test "x$enable_debug" = "xno" ; then
556 if test "x$enable_debug" = "x1" ; then
557 AC_DEFINE([JEMALLOC_DEBUG], [ ])
558 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
560 AC_SUBST([enable_debug])
562 dnl Only optimize if not debugging.
563 if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
564 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
566 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
567 if test "x${optimize}" = "xyes" ; then
568 if test "x$GCC" = "xyes" ; then
569 JE_CFLAGS_APPEND([-O3])
570 JE_CFLAGS_APPEND([-funroll-loops])
571 elif test "x$je_cv_msvc" = "xyes" ; then
572 JE_CFLAGS_APPEND([-O2])
574 JE_CFLAGS_APPEND([-O])
579 dnl Enable statistics calculation by default.
580 AC_ARG_ENABLE([stats],
581 [AS_HELP_STRING([--disable-stats],
582 [Disable statistics calculation/reporting])],
583 [if test "x$enable_stats" = "xno" ; then
591 if test "x$enable_stats" = "x1" ; then
592 AC_DEFINE([JEMALLOC_STATS], [ ])
594 AC_SUBST([enable_stats])
596 dnl Do not enable profiling by default.
597 AC_ARG_ENABLE([prof],
598 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
599 [if test "x$enable_prof" = "xno" ; then
607 if test "x$enable_prof" = "x1" ; then
610 backtrace_method="N/A"
613 AC_ARG_ENABLE([prof-libunwind],
614 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
615 [if test "x$enable_prof_libunwind" = "xno" ; then
616 enable_prof_libunwind="0"
618 enable_prof_libunwind="1"
621 [enable_prof_libunwind="0"]
623 AC_ARG_WITH([static_libunwind],
624 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
625 [Path to static libunwind library; use rather than dynamically linking])],
626 if test "x$with_static_libunwind" = "xno" ; then
629 if test ! -f "$with_static_libunwind" ; then
630 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
632 LUNWIND="$with_static_libunwind"
636 if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
637 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
638 if test "x$LUNWIND" = "x-lunwind" ; then
639 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
640 [enable_prof_libunwind="0"])
642 LIBS="$LIBS $LUNWIND"
644 if test "x${enable_prof_libunwind}" = "x1" ; then
645 backtrace_method="libunwind"
646 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
650 AC_ARG_ENABLE([prof-libgcc],
651 [AS_HELP_STRING([--disable-prof-libgcc],
652 [Do not use libgcc for backtracing])],
653 [if test "x$enable_prof_libgcc" = "xno" ; then
654 enable_prof_libgcc="0"
656 enable_prof_libgcc="1"
659 [enable_prof_libgcc="1"]
661 if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
662 -a "x$GCC" = "xyes" ; then
663 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
664 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
665 dnl The following is conservative, in that it only has entries for CPUs on
666 dnl which jemalloc has been tested.
667 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
668 case "${host_cpu}" in
670 AC_MSG_RESULT([unreliable])
671 enable_prof_libgcc="0";
674 AC_MSG_RESULT([reliable])
677 AC_MSG_RESULT([unreliable])
678 enable_prof_libgcc="0";
681 if test "x${enable_prof_libgcc}" = "x1" ; then
682 backtrace_method="libgcc"
683 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
686 enable_prof_libgcc="0"
689 AC_ARG_ENABLE([prof-gcc],
690 [AS_HELP_STRING([--disable-prof-gcc],
691 [Do not use gcc intrinsics for backtracing])],
692 [if test "x$enable_prof_gcc" = "xno" ; then
698 [enable_prof_gcc="1"]
700 if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
701 -a "x$GCC" = "xyes" ; then
702 backtrace_method="gcc intrinsics"
703 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
708 if test "x$backtrace_method" = "x" ; then
709 backtrace_method="none (disabling profiling)"
712 AC_MSG_CHECKING([configured backtracing method])
713 AC_MSG_RESULT([$backtrace_method])
714 if test "x$enable_prof" = "x1" ; then
715 if test "x${force_tls}" = "x0" ; then
716 AC_MSG_ERROR([Heap profiling requires TLS]);
719 AC_DEFINE([JEMALLOC_PROF], [ ])
721 AC_SUBST([enable_prof])
723 dnl Enable thread-specific caching by default.
724 AC_ARG_ENABLE([tcache],
725 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
726 [if test "x$enable_tcache" = "xno" ; then
734 if test "x$enable_tcache" = "x1" ; then
735 AC_DEFINE([JEMALLOC_TCACHE], [ ])
737 AC_SUBST([enable_tcache])
739 dnl Disable mremap() for huge realloc() by default.
740 AC_ARG_ENABLE([mremap],
741 [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
742 [if test "x$enable_mremap" = "xno" ; then
750 if test "x$enable_mremap" = "x1" ; then
751 JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
753 #include <sys/mman.h>
755 void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
756 ], [je_cv_mremap_fixed])
757 if test "x${je_cv_mremap_fixed}" = "xno" ; then
761 if test "x$enable_mremap" = "x1" ; then
762 AC_DEFINE([JEMALLOC_MREMAP], [ ])
764 AC_SUBST([enable_mremap])
766 dnl Enable VM deallocation via munmap() by default.
767 AC_ARG_ENABLE([munmap],
768 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
769 [if test "x$enable_munmap" = "xno" ; then
775 [enable_munmap="${default_munmap}"]
777 if test "x$enable_munmap" = "x1" ; then
778 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
780 AC_SUBST([enable_munmap])
782 dnl Do not enable allocation from DSS by default.
784 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
785 [if test "x$enable_dss" = "xno" ; then
793 dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
794 AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
795 if test "x$have_sbrk" = "x1" ; then
796 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
801 if test "x$enable_dss" = "x1" ; then
802 AC_DEFINE([JEMALLOC_DSS], [ ])
804 AC_SUBST([enable_dss])
806 dnl Support the junk/zero filling option by default.
807 AC_ARG_ENABLE([fill],
808 [AS_HELP_STRING([--disable-fill],
809 [Disable support for junk/zero filling, quarantine, and redzones])],
810 [if test "x$enable_fill" = "xno" ; then
818 if test "x$enable_fill" = "x1" ; then
819 AC_DEFINE([JEMALLOC_FILL], [ ])
821 AC_SUBST([enable_fill])
823 dnl Disable utrace(2)-based tracing by default.
824 AC_ARG_ENABLE([utrace],
825 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
826 [if test "x$enable_utrace" = "xno" ; then
834 JE_COMPILABLE([utrace(2)], [
835 #include <sys/types.h>
836 #include <sys/param.h>
837 #include <sys/time.h>
839 #include <sys/ktrace.h>
841 utrace((void *)0, 0);
843 if test "x${je_cv_utrace}" = "xno" ; then
846 if test "x$enable_utrace" = "x1" ; then
847 AC_DEFINE([JEMALLOC_UTRACE], [ ])
849 AC_SUBST([enable_utrace])
851 dnl Support Valgrind by default.
852 AC_ARG_ENABLE([valgrind],
853 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
854 [if test "x$enable_valgrind" = "xno" ; then
860 [enable_valgrind="1"]
862 if test "x$enable_valgrind" = "x1" ; then
863 JE_COMPILABLE([valgrind], [
864 #include <valgrind/valgrind.h>
865 #include <valgrind/memcheck.h>
867 #if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
868 # error "Incompatible Valgrind version"
870 ], [], [je_cv_valgrind])
871 if test "x${je_cv_valgrind}" = "xno" ; then
874 if test "x$enable_valgrind" = "x1" ; then
875 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
878 AC_SUBST([enable_valgrind])
880 dnl Do not support the xmalloc option by default.
881 AC_ARG_ENABLE([xmalloc],
882 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
883 [if test "x$enable_xmalloc" = "xno" ; then
891 if test "x$enable_xmalloc" = "x1" ; then
892 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
894 AC_SUBST([enable_xmalloc])
896 AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
897 [je_cv_static_page_shift],
898 AC_RUN_IFELSE([AC_LANG_PROGRAM(
915 result = si.dwPageSize;
917 result = sysconf(_SC_PAGESIZE);
922 result = ffsl(result) - 1;
924 f = fopen("conftest.out", "w");
928 fprintf(f, "%u\n", result);
933 [je_cv_static_page_shift=`cat conftest.out`],
934 [je_cv_static_page_shift=undefined]))
936 if test "x$je_cv_static_page_shift" != "xundefined"; then
937 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
939 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
942 dnl ============================================================================
943 dnl jemalloc configuration.
946 dnl Set VERSION if source directory has an embedded git repository.
947 if test -d "${srcroot}.git" ; then
948 git describe --long --abbrev=40 > ${srcroot}VERSION
950 jemalloc_version=`cat ${srcroot}VERSION`
951 jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
952 jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
953 jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
954 jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
955 jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
956 AC_SUBST([jemalloc_version])
957 AC_SUBST([jemalloc_version_major])
958 AC_SUBST([jemalloc_version_minor])
959 AC_SUBST([jemalloc_version_bugfix])
960 AC_SUBST([jemalloc_version_nrev])
961 AC_SUBST([jemalloc_version_gid])
963 dnl ============================================================================
964 dnl Configure pthreads.
966 if test "x$abi" != "xpecoff" ; then
967 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
968 dnl Some systems may embed pthreads functionality in libc; check for libpthread
969 dnl first, but try libc too before failing.
970 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
971 [AC_SEARCH_LIBS([pthread_create], , ,
972 AC_MSG_ERROR([libpthread is missing]))])
975 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
977 dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
978 dnl it rather than pthreads TSD cleanup functions to support cleanup during
979 dnl thread exit, in order to avoid pthreads library recursion during
981 AC_CHECK_FUNC([_malloc_thread_cleanup],
982 [have__malloc_thread_cleanup="1"],
983 [have__malloc_thread_cleanup="0"]
985 if test "x$have__malloc_thread_cleanup" = "x1" ; then
986 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
990 dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
991 dnl so, mutex initialization causes allocation, and we need to implement this
992 dnl callback function in order to prevent recursive allocation.
993 AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
994 [have__pthread_mutex_init_calloc_cb="1"],
995 [have__pthread_mutex_init_calloc_cb="0"]
997 if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
998 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1001 dnl Disable lazy locking by default.
1002 AC_ARG_ENABLE([lazy_lock],
1003 [AS_HELP_STRING([--enable-lazy-lock],
1004 [Enable lazy locking (only lock when multi-threaded)])],
1005 [if test "x$enable_lazy_lock" = "xno" ; then
1006 enable_lazy_lock="0"
1008 enable_lazy_lock="1"
1011 [enable_lazy_lock="0"]
1013 if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1014 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1015 enable_lazy_lock="1"
1017 if test "x$enable_lazy_lock" = "x1" ; then
1018 if test "x$abi" != "xpecoff" ; then
1019 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1020 AC_CHECK_FUNC([dlsym], [],
1021 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1022 [AC_MSG_ERROR([libdl is missing])])
1025 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1027 AC_SUBST([enable_lazy_lock])
1029 AC_ARG_ENABLE([tls],
1030 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1031 if test "x$enable_tls" = "xno" ; then
1039 if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1040 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1043 if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1044 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1047 if test "x${enable_tls}" = "x1" ; then
1048 AC_MSG_CHECKING([for TLS])
1049 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1057 AC_MSG_RESULT([yes]),
1061 AC_SUBST([enable_tls])
1062 if test "x${enable_tls}" = "x1" ; then
1063 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1064 elif test "x${force_tls}" = "x1" ; then
1065 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
1068 dnl ============================================================================
1069 dnl Check for ffsl(3), and fail if not found. This function exists on all
1070 dnl platforms that jemalloc currently has a chance of functioning on without
1072 JE_COMPILABLE([a program using ffsl], [
1073 #include <strings.h>
1077 int rv = ffsl(0x08);
1079 ], [je_cv_function_ffsl])
1080 if test "x${je_cv_function_ffsl}" != "xyes" ; then
1081 AC_MSG_ERROR([Cannot build without ffsl(3)])
1084 dnl ============================================================================
1085 dnl Check for atomic(9) operations as provided on FreeBSD.
1087 JE_COMPILABLE([atomic(9)], [
1088 #include <sys/types.h>
1089 #include <machine/atomic.h>
1090 #include <inttypes.h>
1094 volatile uint32_t *x32p = &x32;
1095 atomic_fetchadd_32(x32p, 1);
1098 unsigned long xlong = 0;
1099 volatile unsigned long *xlongp = &xlong;
1100 atomic_fetchadd_long(xlongp, 1);
1103 if test "x${je_cv_atomic9}" = "xyes" ; then
1104 AC_DEFINE([JEMALLOC_ATOMIC9])
1107 dnl ============================================================================
1108 dnl Check for atomic(3) operations as provided on Darwin.
1110 JE_COMPILABLE([Darwin OSAtomic*()], [
1111 #include <libkern/OSAtomic.h>
1112 #include <inttypes.h>
1116 volatile int32_t *x32p = &x32;
1117 OSAtomicAdd32(1, x32p);
1121 volatile int64_t *x64p = &x64;
1122 OSAtomicAdd64(1, x64p);
1124 ], [je_cv_osatomic])
1125 if test "x${je_cv_osatomic}" = "xyes" ; then
1126 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1129 dnl ============================================================================
1130 dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1131 dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1133 AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1134 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1135 [je_cv_sync_compare_and_swap_$2],
1136 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1140 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1143 __sync_add_and_fetch(&x$1, 42);
1144 __sync_sub_and_fetch(&x$1, 1);
1147 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1150 [je_cv_sync_compare_and_swap_$2=yes],
1151 [je_cv_sync_compare_and_swap_$2=no])])
1153 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1154 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1158 if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
1159 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1160 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1163 dnl ============================================================================
1164 dnl Check for spinlock(3) operations as provided on Darwin.
1166 JE_COMPILABLE([Darwin OSSpin*()], [
1167 #include <libkern/OSAtomic.h>
1168 #include <inttypes.h>
1170 OSSpinLock lock = 0;
1171 OSSpinLockLock(&lock);
1172 OSSpinLockUnlock(&lock);
1174 if test "x${je_cv_osspin}" = "xyes" ; then
1175 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
1178 dnl ============================================================================
1179 dnl Darwin-related configuration.
1181 if test "x${abi}" = "xmacho" ; then
1182 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1183 AC_DEFINE([JEMALLOC_ZONE], [ ])
1185 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1186 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1187 dnl 10.6, which is the only source-level indication of the change.
1188 AC_MSG_CHECKING([malloc zone version])
1189 AC_DEFUN([JE_ZONE_PROGRAM],
1191 [#include <malloc/malloc.h>],
1192 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1195 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1196 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1197 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1198 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1199 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1201 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1202 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1204 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1205 AC_MSG_RESULT([unsupported])
1206 AC_MSG_ERROR([Unsupported malloc zone version])
1208 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1209 JEMALLOC_ZONE_VERSION=8
1210 AC_MSG_RESULT([> 8])
1212 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1214 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
1217 dnl ============================================================================
1218 dnl Check for typedefs, structures, and compiler characteristics.
1221 AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1222 mkdir -p "include/jemalloc/internal"
1223 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1226 dnl Process .in files.
1227 AC_SUBST([cfghdrs_in])
1228 AC_SUBST([cfghdrs_out])
1229 AC_CONFIG_HEADERS([$cfghdrs_tup])
1231 dnl ============================================================================
1232 dnl Generate outputs.
1233 AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
1234 AC_SUBST([cfgoutputs_in])
1235 AC_SUBST([cfgoutputs_out])
1238 dnl ============================================================================
1239 dnl Print out the results of configuration.
1240 AC_MSG_RESULT([===============================================================================])
1241 AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1242 AC_MSG_RESULT([library revision : ${rev}])
1244 AC_MSG_RESULT([CC : ${CC}])
1245 AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1246 AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1247 AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1248 AC_MSG_RESULT([LIBS : ${LIBS}])
1249 AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1251 AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1252 AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1254 AC_MSG_RESULT([PREFIX : ${PREFIX}])
1255 AC_MSG_RESULT([BINDIR : ${BINDIR}])
1256 AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1257 AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
1258 AC_MSG_RESULT([DATADIR : ${DATADIR}])
1259 AC_MSG_RESULT([MANDIR : ${MANDIR}])
1261 AC_MSG_RESULT([srcroot : ${srcroot}])
1262 AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1263 AC_MSG_RESULT([objroot : ${objroot}])
1264 AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1266 AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
1267 AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1268 AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
1269 AC_MSG_RESULT([install_suffix : ${install_suffix}])
1270 AC_MSG_RESULT([autogen : ${enable_autogen}])
1271 AC_MSG_RESULT([experimental : ${enable_experimental}])
1272 AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
1273 AC_MSG_RESULT([debug : ${enable_debug}])
1274 AC_MSG_RESULT([stats : ${enable_stats}])
1275 AC_MSG_RESULT([prof : ${enable_prof}])
1276 AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
1277 AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1278 AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
1279 AC_MSG_RESULT([tcache : ${enable_tcache}])
1280 AC_MSG_RESULT([fill : ${enable_fill}])
1281 AC_MSG_RESULT([utrace : ${enable_utrace}])
1282 AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1283 AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
1284 AC_MSG_RESULT([mremap : ${enable_mremap}])
1285 AC_MSG_RESULT([munmap : ${enable_munmap}])
1286 AC_MSG_RESULT([dss : ${enable_dss}])
1287 AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
1288 AC_MSG_RESULT([tls : ${enable_tls}])
1289 AC_MSG_RESULT([===============================================================================])