]> git.saurik.com Git - redis.git/blame - deps/jemalloc/configure.ac
Jemalloc updated to 3.0.0.
[redis.git] / deps / jemalloc / configure.ac
CommitLineData
a78e148b 1dnl Process this file with autoconf to produce a configure script.
2AC_INIT([Makefile.in])
3
4dnl ============================================================================
5dnl Custom macro definitions.
6
7dnl JE_CFLAGS_APPEND(cflag)
8AC_DEFUN([JE_CFLAGS_APPEND],
9[
10AC_MSG_CHECKING([whether compiler supports $1])
11TCFLAGS="${CFLAGS}"
12if test "x${CFLAGS}" = "x" ; then
13 CFLAGS="$1"
14else
15 CFLAGS="${CFLAGS} $1"
16fi
4934f93d 17AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
a78e148b 18[[
19]], [[
20 return 0;
21]])],
22 AC_MSG_RESULT([yes]),
23 AC_MSG_RESULT([no])
24 [CFLAGS="${TCFLAGS}"]
25)
26])
27
28dnl JE_COMPILABLE(label, hcode, mcode, rvar)
4934f93d 29dnl
30dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
31dnl cause failure.
a78e148b 32AC_DEFUN([JE_COMPILABLE],
33[
4934f93d 34AC_CACHE_CHECK([whether $1 is compilable],
35 [$4],
36 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
37 [$3])],
38 [$4=yes],
39 [$4=no])])
a78e148b 40])
41
42dnl ============================================================================
43
4934f93d 44dnl Library revision.
45rev=1
46AC_SUBST([rev])
47
a78e148b 48srcroot=$srcdir
49if test "x${srcroot}" = "x." ; then
50 srcroot=""
51else
52 srcroot="${srcroot}/"
53fi
54AC_SUBST([srcroot])
55abs_srcroot="`cd \"${srcdir}\"; pwd`/"
56AC_SUBST([abs_srcroot])
57
58objroot=""
59AC_SUBST([objroot])
60abs_objroot="`pwd`/"
61AC_SUBST([abs_objroot])
62
63dnl Munge install path variables.
64if test "x$prefix" = "xNONE" ; then
65 prefix="/usr/local"
66fi
67if test "x$exec_prefix" = "xNONE" ; then
68 exec_prefix=$prefix
69fi
70PREFIX=$prefix
71AC_SUBST([PREFIX])
72BINDIR=`eval echo $bindir`
73BINDIR=`eval echo $BINDIR`
74AC_SUBST([BINDIR])
75INCLUDEDIR=`eval echo $includedir`
76INCLUDEDIR=`eval echo $INCLUDEDIR`
77AC_SUBST([INCLUDEDIR])
78LIBDIR=`eval echo $libdir`
79LIBDIR=`eval echo $LIBDIR`
80AC_SUBST([LIBDIR])
81DATADIR=`eval echo $datadir`
82DATADIR=`eval echo $DATADIR`
83AC_SUBST([DATADIR])
84MANDIR=`eval echo $mandir`
85MANDIR=`eval echo $MANDIR`
86AC_SUBST([MANDIR])
87
88dnl Support for building documentation.
89AC_PATH_PROG([XSLTPROC], [xsltproc], , [$PATH])
4934f93d 90if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
91 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
92elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
93 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
94else
95 dnl Documentation building will fail if this default gets used.
96 DEFAULT_XSLROOT=""
97fi
a78e148b 98AC_ARG_WITH([xslroot],
4934f93d 99 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
a78e148b 100if test "x$with_xslroot" = "xno" ; then
4934f93d 101 XSLROOT="${DEFAULT_XSLROOT}"
a78e148b 102else
103 XSLROOT="${with_xslroot}"
4934f93d 104fi
105],
106 XSLROOT="${DEFAULT_XSLROOT}"
a78e148b 107)
108AC_SUBST([XSLROOT])
109
110dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
111dnl just prevent autoconf from molesting CFLAGS.
112CFLAGS=$CFLAGS
113AC_PROG_CC
4934f93d 114if test "x$GCC" != "xyes" ; then
115 AC_CACHE_CHECK([whether compiler is MSVC],
116 [je_cv_msvc],
117 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
118 [
119#ifndef _MSC_VER
120 int fail[-1];
121#endif
122])],
123 [je_cv_msvc=yes],
124 [je_cv_msvc=no])])
125fi
126
a78e148b 127if test "x$CFLAGS" = "x" ; then
128 no_CFLAGS="yes"
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])
4934f93d 134 elif test "x$je_cv_msvc" = "xyes" ; then
135 CC="$CC -nologo"
136 JE_CFLAGS_APPEND([-Zi])
137 JE_CFLAGS_APPEND([-MT])
138 JE_CFLAGS_APPEND([-W3])
139 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat"
a78e148b 140 fi
141fi
142dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
143if test "x$EXTRA_CFLAGS" != "x" ; then
144 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
145fi
146AC_PROG_CPP
147
148AC_CHECK_SIZEOF([void *])
149if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
150 LG_SIZEOF_PTR=3
151elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
152 LG_SIZEOF_PTR=2
153else
154 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
155fi
156AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
157
158AC_CHECK_SIZEOF([int])
159if test "x${ac_cv_sizeof_int}" = "x8" ; then
160 LG_SIZEOF_INT=3
161elif test "x${ac_cv_sizeof_int}" = "x4" ; then
162 LG_SIZEOF_INT=2
163else
164 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
165fi
166AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
167
168AC_CHECK_SIZEOF([long])
169if test "x${ac_cv_sizeof_long}" = "x8" ; then
170 LG_SIZEOF_LONG=3
171elif test "x${ac_cv_sizeof_long}" = "x4" ; then
172 LG_SIZEOF_LONG=2
173else
174 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
175fi
176AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
177
4934f93d 178AC_CHECK_SIZEOF([intmax_t])
179if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
180 LG_SIZEOF_INTMAX_T=4
181elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
182 LG_SIZEOF_INTMAX_T=3
183elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
184 LG_SIZEOF_INTMAX_T=2
185else
186 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
187fi
188AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
189
a78e148b 190AC_CANONICAL_HOST
191dnl CPU-specific settings.
192CPU_SPINWAIT=""
193case "${host_cpu}" in
194 i[[345]]86)
195 ;;
196 i686)
197 JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
4934f93d 198 [je_cv_asm])
199 if test "x${je_cv_asm}" = "xyes" ; then
a78e148b 200 CPU_SPINWAIT='__asm__ volatile("pause")'
201 fi
202 ;;
203 x86_64)
204 JE_COMPILABLE([__asm__ syntax], [],
4934f93d 205 [[__asm__ volatile("pause"); return 0;]], [je_cv_asm])
206 if test "x${je_cv_asm}" = "xyes" ; then
a78e148b 207 CPU_SPINWAIT='__asm__ volatile("pause")'
208 fi
209 ;;
210 *)
211 ;;
212esac
213AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
214
4934f93d 215LD_PRELOAD_VAR="LD_PRELOAD"
216so="so"
217importlib="${so}"
218o="$ac_objext"
219a="a"
220exe="$ac_exeext"
221libprefix="lib"
222DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
223RPATH='-Wl,-rpath,$(1)'
224SOREV="${so}.${rev}"
225PIC_CFLAGS='-fPIC -DPIC'
226CTARGET='-o $@'
227LDTARGET='-o $@'
228EXTRA_LDFLAGS=
229MKLIB='ar crus $@'
230CC_MM=1
231
a78e148b 232dnl Platform-specific settings. abi and RPATH can probably be determined
233dnl programmatically, but doing so is error-prone, which makes it generally
234dnl not worth the trouble.
235dnl
236dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
237dnl definitions need to be seen before any headers are included, which is a pain
238dnl to make happen otherwise.
4934f93d 239default_munmap="1"
a78e148b 240case "${host}" in
241 *-*-darwin*)
4934f93d 242 CFLAGS="$CFLAGS"
a78e148b 243 abi="macho"
4934f93d 244 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
a78e148b 245 RPATH=""
4934f93d 246 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
247 so="dylib"
248 importlib="${so}"
249 force_tls="0"
250 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
251 SOREV="${rev}.${so}"
a78e148b 252 ;;
253 *-*-freebsd*)
254 CFLAGS="$CFLAGS"
255 abi="elf"
4934f93d 256 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
257 force_lazy_lock="1"
a78e148b 258 ;;
259 *-*-linux*)
260 CFLAGS="$CFLAGS"
261 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
262 abi="elf"
4934f93d 263 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
264 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
265 default_munmap="0"
a78e148b 266 ;;
267 *-*-netbsd*)
268 AC_MSG_CHECKING([ABI])
269 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
270[[#ifdef __ELF__
271/* ELF */
272#else
273#error aout
274#endif
275]])],
276 [CFLAGS="$CFLAGS"; abi="elf"],
277 [abi="aout"])
278 AC_MSG_RESULT([$abi])
4934f93d 279 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
a78e148b 280 ;;
281 *-*-solaris2*)
282 CFLAGS="$CFLAGS"
283 abi="elf"
4934f93d 284 RPATH='-Wl,-R,$(1)'
a78e148b 285 dnl Solaris needs this for sigwait().
286 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
287 LIBS="$LIBS -lposix4 -lsocket -lnsl"
288 ;;
4934f93d 289 *-ibm-aix*)
290 if "$LG_SIZEOF_PTR" = "8"; then
291 dnl 64bit AIX
292 LD_PRELOAD_VAR="LDR_PRELOAD64"
293 else
294 dnl 32bit AIX
295 LD_PRELOAD_VAR="LDR_PRELOAD"
296 fi
297 abi="xcoff"
298 ;;
299 *-*-mingw*)
300 abi="pecoff"
301 force_tls="0"
302 RPATH=""
303 so="dll"
304 if test "x$je_cv_msvc" = "xyes" ; then
305 importlib="lib"
306 DSO_LDFLAGS="-LD"
307 EXTRA_LDFLAGS="-link -DEBUG"
308 CTARGET='-Fo$@'
309 LDTARGET='-Fe$@'
310 MKLIB='lib -nologo -out:$@'
311 CC_MM=
312 else
313 importlib="${so}"
314 DSO_LDFLAGS="-shared"
315 fi
316 a="lib"
317 libprefix=""
318 SOREV="${so}"
319 PIC_CFLAGS=""
320 ;;
a78e148b 321 *)
322 AC_MSG_RESULT([Unsupported operating system: ${host}])
323 abi="elf"
a78e148b 324 ;;
325esac
326AC_SUBST([abi])
327AC_SUBST([RPATH])
4934f93d 328AC_SUBST([LD_PRELOAD_VAR])
329AC_SUBST([so])
330AC_SUBST([importlib])
331AC_SUBST([o])
332AC_SUBST([a])
333AC_SUBST([exe])
334AC_SUBST([libprefix])
335AC_SUBST([DSO_LDFLAGS])
336AC_SUBST([EXTRA_LDFLAGS])
337AC_SUBST([SOREV])
338AC_SUBST([PIC_CFLAGS])
339AC_SUBST([CTARGET])
340AC_SUBST([LDTARGET])
341AC_SUBST([MKLIB])
342AC_SUBST([CC_MM])
343
344if test "x$abi" != "xpecoff"; then
345 dnl Heap profiling uses the log(3) function.
346 LIBS="$LIBS -lm"
347fi
a78e148b 348
349JE_COMPILABLE([__attribute__ syntax],
350 [static __attribute__((unused)) void foo(void){}],
351 [],
4934f93d 352 [je_cv_attribute])
353if test "x${je_cv_attribute}" = "xyes" ; then
a78e148b 354 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
355 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
356 JE_CFLAGS_APPEND([-fvisibility=hidden])
357 fi
358fi
4934f93d 359dnl Check for tls_model attribute support (clang 3.0 still lacks support).
360SAVED_CFLAGS="${CFLAGS}"
361JE_CFLAGS_APPEND([-Werror])
362JE_COMPILABLE([tls_model attribute], [],
363 [static __thread int
364 __attribute__((tls_model("initial-exec"))) foo;
365 foo = 0;],
366 [je_cv_tls_model])
367CFLAGS="${SAVED_CFLAGS}"
368if test "x${je_cv_tls_model}" = "xyes" ; then
369 AC_DEFINE([JEMALLOC_TLS_MODEL],
370 [__attribute__((tls_model("initial-exec")))])
371else
372 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
a78e148b 373fi
374
375dnl Support optional additions to rpath.
376AC_ARG_WITH([rpath],
377 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
378if test "x$with_rpath" = "xno" ; then
379 RPATH_EXTRA=
380else
381 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
382fi,
383 RPATH_EXTRA=
384)
385AC_SUBST([RPATH_EXTRA])
386
387dnl Disable rules that do automatic regeneration of configure output by default.
388AC_ARG_ENABLE([autogen],
389 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
390if test "x$enable_autogen" = "xno" ; then
391 enable_autogen="0"
392else
393 enable_autogen="1"
394fi
395,
396enable_autogen="0"
397)
398AC_SUBST([enable_autogen])
399
400AC_PROG_INSTALL
401AC_PROG_RANLIB
402AC_PATH_PROG([AR], [ar], , [$PATH])
403AC_PATH_PROG([LD], [ld], , [$PATH])
404AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
405
4934f93d 406public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib"
407
408dnl Check for allocator-related functions that should be wrapped.
409AC_CHECK_FUNC([memalign],
410 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
411 public_syms="${public_syms} memalign"])
412AC_CHECK_FUNC([valloc],
413 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
414 public_syms="${public_syms} valloc"])
415
416dnl Support the experimental API by default.
417AC_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"
422else
423 enable_experimental="1"
424fi
425],
426[enable_experimental="1"]
427)
428if test "x$enable_experimental" = "x1" ; then
429 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
430 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
431fi
432AC_SUBST([enable_experimental])
433
434dnl Perform no name mangling by default.
435AC_ARG_WITH([mangling],
436 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
437 [mangling_map="$with_mangling"], [mangling_map=""])
438for nm in `echo ${mangling_map} |tr ',' ' '` ; do
439 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
440 n="je_${k}"
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' ' '`
445done
446
a78e148b 447dnl Do not prefix public APIs by default.
448AC_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"],
4934f93d 451 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
a78e148b 452 JEMALLOC_PREFIX=""
453else
454 JEMALLOC_PREFIX="je_"
455fi]
456)
457if 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"])
a78e148b 461fi
4934f93d 462dnl Generate macros to rename public symbols. All public symbols are prefixed
463dnl with je_ in the source code, so these macro definitions are needed even if
464dnl --with-jemalloc-prefix wasn't specified.
465for stem in ${public_syms}; do
466 n="je_${stem}"
467 m="${JEMALLOC_PREFIX}${stem}"
468 AC_DEFINE_UNQUOTED([${n}], [${m}])
469done
a78e148b 470
1d03c1c9 471dnl Do not mangle library-private APIs by default.
472AC_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=""]
476)
477AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
478if 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])
480else
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])
482fi
483
a78e148b 484dnl Do not add suffix to installed files by default.
485AC_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"],
488 [INSTALL_SUFFIX=]
489)
490install_suffix="$INSTALL_SUFFIX"
491AC_SUBST([install_suffix])
492
493cfgoutputs_in="${srcroot}Makefile.in"
494cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
495cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
496cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
497cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
498cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
499cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
500
501cfgoutputs_out="Makefile"
502cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
503cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
504cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
505cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
506cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
507cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
508
509cfgoutputs_tup="Makefile"
510cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
511cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
512cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
513cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
514cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
515cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
516
517cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
4934f93d 518cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
a78e148b 519
520cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
4934f93d 521cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
a78e148b 522
523cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
524
525dnl Do not silence irrelevant compiler warnings by default, since enabling this
526dnl option incurs a performance penalty.
527AC_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"
532else
533 enable_cc_silence="1"
534fi
535],
536[enable_cc_silence="0"]
537)
538if test "x$enable_cc_silence" = "x1" ; then
4934f93d 539 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
a78e148b 540fi
541
542dnl Do not compile with debugging by default.
543AC_ARG_ENABLE([debug],
544 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
545[if test "x$enable_debug" = "xno" ; then
546 enable_debug="0"
547else
548 enable_debug="1"
549fi
550],
551[enable_debug="0"]
552)
553if test "x$enable_debug" = "x1" ; then
554 AC_DEFINE([JEMALLOC_DEBUG], [ ])
555 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
556fi
557AC_SUBST([enable_debug])
558
559dnl Only optimize if not debugging.
560if 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.
562 optimize="no"
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])
4934f93d 568 elif test "x$je_cv_msvc" = "xyes" ; then
569 JE_CFLAGS_APPEND([-O2])
a78e148b 570 else
571 JE_CFLAGS_APPEND([-O])
572 fi
573 fi
574fi
575
4934f93d 576dnl Enable statistics calculation by default.
a78e148b 577AC_ARG_ENABLE([stats],
4934f93d 578 [AS_HELP_STRING([--disable-stats],
579 [Disable statistics calculation/reporting])],
a78e148b 580[if test "x$enable_stats" = "xno" ; then
581 enable_stats="0"
582else
583 enable_stats="1"
584fi
585],
4934f93d 586[enable_stats="1"]
a78e148b 587)
588if test "x$enable_stats" = "x1" ; then
589 AC_DEFINE([JEMALLOC_STATS], [ ])
590fi
591AC_SUBST([enable_stats])
592
593dnl Do not enable profiling by default.
594AC_ARG_ENABLE([prof],
595 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
596[if test "x$enable_prof" = "xno" ; then
597 enable_prof="0"
598else
599 enable_prof="1"
600fi
601],
602[enable_prof="0"]
603)
604if test "x$enable_prof" = "x1" ; then
605 backtrace_method=""
606else
607 backtrace_method="N/A"
608fi
609
610AC_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"
614else
615 enable_prof_libunwind="1"
616fi
617],
618[enable_prof_libunwind="0"]
619)
620AC_ARG_WITH([static_libunwind],
621 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
622 [Path to static libunwind library; use rather than dynamically linking])],
623if test "x$with_static_libunwind" = "xno" ; then
624 LUNWIND="-lunwind"
625else
626 if test ! -f "$with_static_libunwind" ; then
627 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
628 fi
629 LUNWIND="$with_static_libunwind"
630fi,
631 LUNWIND="-lunwind"
632)
633if 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"])
638 else
639 LIBS="$LIBS $LUNWIND"
640 fi
641 if test "x${enable_prof_libunwind}" = "x1" ; then
642 backtrace_method="libunwind"
643 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
644 fi
645fi
646
647AC_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"
652else
653 enable_prof_libgcc="1"
654fi
655],
656[enable_prof_libgcc="1"]
657)
658if 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
666 i[[3456]]86)
667 AC_MSG_RESULT([unreliable])
668 enable_prof_libgcc="0";
669 ;;
670 x86_64)
671 AC_MSG_RESULT([reliable])
672 ;;
673 *)
674 AC_MSG_RESULT([unreliable])
675 enable_prof_libgcc="0";
676 ;;
677 esac
678 if test "x${enable_prof_libgcc}" = "x1" ; then
679 backtrace_method="libgcc"
680 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
681 fi
682else
683 enable_prof_libgcc="0"
684fi
685
686AC_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
690 enable_prof_gcc="0"
691else
692 enable_prof_gcc="1"
693fi
694],
695[enable_prof_gcc="1"]
696)
697if 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], [ ])
701else
702 enable_prof_gcc="0"
703fi
704
705if test "x$backtrace_method" = "x" ; then
706 backtrace_method="none (disabling profiling)"
707 enable_prof="0"
708fi
709AC_MSG_CHECKING([configured backtracing method])
710AC_MSG_RESULT([$backtrace_method])
711if test "x$enable_prof" = "x1" ; then
4934f93d 712 if test "x${force_tls}" = "x0" ; then
713 AC_MSG_ERROR([Heap profiling requires TLS]);
714 fi
715 force_tls="1"
a78e148b 716 AC_DEFINE([JEMALLOC_PROF], [ ])
717fi
718AC_SUBST([enable_prof])
719
a78e148b 720dnl Enable thread-specific caching by default.
721AC_ARG_ENABLE([tcache],
722 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
723[if test "x$enable_tcache" = "xno" ; then
724 enable_tcache="0"
725else
726 enable_tcache="1"
727fi
728],
729[enable_tcache="1"]
730)
731if test "x$enable_tcache" = "x1" ; then
732 AC_DEFINE([JEMALLOC_TCACHE], [ ])
733fi
734AC_SUBST([enable_tcache])
735
4934f93d 736dnl Disable mremap() for huge realloc() by default.
737AC_ARG_ENABLE([mremap],
738 [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
739[if test "x$enable_mremap" = "xno" ; then
740 enable_mremap="0"
a78e148b 741else
4934f93d 742 enable_mremap="1"
a78e148b 743fi
744],
4934f93d 745[enable_mremap="0"]
a78e148b 746)
4934f93d 747if test "x$enable_mremap" = "x1" ; then
748 JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
749#define _GNU_SOURCE
750#include <sys/mman.h>
751], [
752void *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
755 enable_mremap="0"
756 fi
757fi
758if test "x$enable_mremap" = "x1" ; then
759 AC_DEFINE([JEMALLOC_MREMAP], [ ])
a78e148b 760fi
4934f93d 761AC_SUBST([enable_mremap])
762
763dnl Enable VM deallocation via munmap() by default.
764AC_ARG_ENABLE([munmap],
765 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
766[if test "x$enable_munmap" = "xno" ; then
767 enable_munmap="0"
768else
769 enable_munmap="1"
770fi
771],
772[enable_munmap="${default_munmap}"]
773)
774if test "x$enable_munmap" = "x1" ; then
775 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
776fi
777AC_SUBST([enable_munmap])
a78e148b 778
779dnl Do not enable allocation from DSS by default.
780AC_ARG_ENABLE([dss],
781 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
782[if test "x$enable_dss" = "xno" ; then
783 enable_dss="0"
784else
785 enable_dss="1"
786fi
787],
788[enable_dss="0"]
789)
4934f93d 790dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
791AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
792if test "x$have_sbrk" = "x1" ; then
793 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
794else
795 enable_dss="0"
796fi
797
a78e148b 798if test "x$enable_dss" = "x1" ; then
799 AC_DEFINE([JEMALLOC_DSS], [ ])
800fi
801AC_SUBST([enable_dss])
802
4934f93d 803dnl Support the junk/zero filling option by default.
a78e148b 804AC_ARG_ENABLE([fill],
4934f93d 805 [AS_HELP_STRING([--disable-fill],
806 [Disable support for junk/zero filling, quarantine, and redzones])],
a78e148b 807[if test "x$enable_fill" = "xno" ; then
808 enable_fill="0"
809else
810 enable_fill="1"
811fi
812],
4934f93d 813[enable_fill="1"]
a78e148b 814)
815if test "x$enable_fill" = "x1" ; then
816 AC_DEFINE([JEMALLOC_FILL], [ ])
817fi
818AC_SUBST([enable_fill])
819
4934f93d 820dnl Disable utrace(2)-based tracing by default.
821AC_ARG_ENABLE([utrace],
822 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
823[if test "x$enable_utrace" = "xno" ; then
824 enable_utrace="0"
a78e148b 825else
4934f93d 826 enable_utrace="1"
a78e148b 827fi
828],
4934f93d 829[enable_utrace="0"]
a78e148b 830)
4934f93d 831JE_COMPILABLE([utrace(2)], [
832#include <sys/types.h>
833#include <sys/param.h>
834#include <sys/time.h>
835#include <sys/uio.h>
836#include <sys/ktrace.h>
837], [
838 utrace((void *)0, 0);
839], [je_cv_utrace])
840if test "x${je_cv_utrace}" = "xno" ; then
841 enable_utrace="0"
a78e148b 842fi
4934f93d 843if test "x$enable_utrace" = "x1" ; then
844 AC_DEFINE([JEMALLOC_UTRACE], [ ])
845fi
846AC_SUBST([enable_utrace])
a78e148b 847
4934f93d 848dnl Support Valgrind by default.
849AC_ARG_ENABLE([valgrind],
850 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
851[if test "x$enable_valgrind" = "xno" ; then
852 enable_valgrind="0"
a78e148b 853else
4934f93d 854 enable_valgrind="1"
a78e148b 855fi
856],
4934f93d 857[enable_valgrind="1"]
a78e148b 858)
4934f93d 859if test "x$enable_valgrind" = "x1" ; then
860 JE_COMPILABLE([valgrind], [
861#include <valgrind/valgrind.h>
862#include <valgrind/memcheck.h>
863
864#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
865# error "Incompatible Valgrind version"
866#endif
867], [], [je_cv_valgrind])
868 if test "x${je_cv_valgrind}" = "xno" ; then
869 enable_valgrind="0"
870 fi
871 if test "x$enable_valgrind" = "x1" ; then
872 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
873 fi
a78e148b 874fi
4934f93d 875AC_SUBST([enable_valgrind])
a78e148b 876
4934f93d 877dnl Do not support the xmalloc option by default.
878AC_ARG_ENABLE([xmalloc],
879 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
880[if test "x$enable_xmalloc" = "xno" ; then
881 enable_xmalloc="0"
a78e148b 882else
4934f93d 883 enable_xmalloc="1"
a78e148b 884fi
885],
4934f93d 886[enable_xmalloc="0"]
a78e148b 887)
4934f93d 888if test "x$enable_xmalloc" = "x1" ; then
889 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
a78e148b 890fi
4934f93d 891AC_SUBST([enable_xmalloc])
a78e148b 892
4934f93d 893AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
894 [je_cv_static_page_shift],
895 AC_RUN_IFELSE([AC_LANG_PROGRAM(
896[[
a78e148b 897#include <strings.h>
4934f93d 898#ifdef _WIN32
899#include <windows.h>
900#else
901#include <unistd.h>
902#endif
903#include <stdio.h>
904]],
905[[
a78e148b 906 long result;
907 FILE *f;
908
4934f93d 909#ifdef _WIN32
910 SYSTEM_INFO si;
911 GetSystemInfo(&si);
912 result = si.dwPageSize;
913#else
a78e148b 914 result = sysconf(_SC_PAGESIZE);
4934f93d 915#endif
a78e148b 916 if (result == -1) {
917 return 1;
918 }
4934f93d 919 result = ffsl(result) - 1;
920
a78e148b 921 f = fopen("conftest.out", "w");
922 if (f == NULL) {
923 return 1;
924 }
4934f93d 925 fprintf(f, "%u\n", result);
926 fclose(f);
a78e148b 927
928 return 0;
929]])],
4934f93d 930 [je_cv_static_page_shift=`cat conftest.out`],
931 [je_cv_static_page_shift=undefined]))
932
933if test "x$je_cv_static_page_shift" != "xundefined"; then
934 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
935else
936 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
937fi
a78e148b 938
939dnl ============================================================================
940dnl jemalloc configuration.
941dnl
942
943dnl Set VERSION if source directory has an embedded git repository.
1d03c1c9 944if test -d "${srcroot}.git" ; then
a78e148b 945 git describe --long --abbrev=40 > ${srcroot}VERSION
946fi
947jemalloc_version=`cat ${srcroot}VERSION`
948jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
949jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
950jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
951jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
952jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
953AC_SUBST([jemalloc_version])
954AC_SUBST([jemalloc_version_major])
955AC_SUBST([jemalloc_version_minor])
956AC_SUBST([jemalloc_version_bugfix])
957AC_SUBST([jemalloc_version_nrev])
958AC_SUBST([jemalloc_version_gid])
959
960dnl ============================================================================
961dnl Configure pthreads.
962
4934f93d 963if 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]))])
970fi
a78e148b 971
972CPPFLAGS="$CPPFLAGS -D_REENTRANT"
973
4934f93d 974dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
975dnl it rather than pthreads TSD cleanup functions to support cleanup during
976dnl thread exit, in order to avoid pthreads library recursion during
977dnl bootstrapping.
978AC_CHECK_FUNC([_malloc_thread_cleanup],
979 [have__malloc_thread_cleanup="1"],
980 [have__malloc_thread_cleanup="0"]
981 )
982if test "x$have__malloc_thread_cleanup" = "x1" ; then
983 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
984 force_tls="1"
985fi
986
987dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
988dnl so, mutex initialization causes allocation, and we need to implement this
989dnl callback function in order to prevent recursive allocation.
990AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
991 [have__pthread_mutex_init_calloc_cb="1"],
992 [have__pthread_mutex_init_calloc_cb="0"]
993 )
994if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
995 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
996fi
997
998dnl Disable lazy locking by default.
a78e148b 999AC_ARG_ENABLE([lazy_lock],
4934f93d 1000 [AS_HELP_STRING([--enable-lazy-lock],
1001 [Enable lazy locking (only lock when multi-threaded)])],
a78e148b 1002[if test "x$enable_lazy_lock" = "xno" ; then
1003 enable_lazy_lock="0"
1004else
1005 enable_lazy_lock="1"
1006fi
1007],
4934f93d 1008[enable_lazy_lock="0"]
a78e148b 1009)
4934f93d 1010if 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"
1013fi
a78e148b 1014if test "x$enable_lazy_lock" = "x1" ; then
4934f93d 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])])
1020 ])
1021 fi
a78e148b 1022 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1023fi
1024AC_SUBST([enable_lazy_lock])
1025
1026AC_ARG_ENABLE([tls],
1027 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1028if test "x$enable_tls" = "xno" ; then
1029 enable_tls="0"
1030else
1031 enable_tls="1"
1032fi
1033,
1034enable_tls="1"
1035)
4934f93d 1036if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1037 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1038 enable_tls="1"
1039fi
1040if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1041 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1042 enable_tls="0"
1043fi
a78e148b 1044if test "x${enable_tls}" = "x1" ; then
1045AC_MSG_CHECKING([for TLS])
4934f93d 1046AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
a78e148b 1047[[
1048 __thread int x;
1049]], [[
1050 x = 42;
1051
1052 return 0;
1053]])],
1054 AC_MSG_RESULT([yes]),
1055 AC_MSG_RESULT([no])
1056 enable_tls="0")
1057fi
1058AC_SUBST([enable_tls])
4934f93d 1059if test "x${enable_tls}" = "x1" ; then
1060 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1061elif test "x${force_tls}" = "x1" ; then
1062 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
a78e148b 1063fi
1064
1065dnl ============================================================================
1066dnl Check for ffsl(3), and fail if not found. This function exists on all
1067dnl platforms that jemalloc currently has a chance of functioning on without
1068dnl modification.
4934f93d 1069JE_COMPILABLE([a program using ffsl], [
1070#include <strings.h>
1071#include <string.h>
1072], [
1073 {
1074 int rv = ffsl(0x08);
1075 }
1076], [je_cv_function_ffsl])
1077if test "x${je_cv_function_ffsl}" != "xyes" ; then
1078 AC_MSG_ERROR([Cannot build without ffsl(3)])
1079fi
a78e148b 1080
4934f93d 1081dnl ============================================================================
1082dnl Check for atomic(9) operations as provided on FreeBSD.
1083
1084JE_COMPILABLE([atomic(9)], [
1085#include <sys/types.h>
1086#include <machine/atomic.h>
1087#include <inttypes.h>
1088], [
1089 {
1090 uint32_t x32 = 0;
1091 volatile uint32_t *x32p = &x32;
1092 atomic_fetchadd_32(x32p, 1);
1093 }
1094 {
1095 unsigned long xlong = 0;
1096 volatile unsigned long *xlongp = &xlong;
1097 atomic_fetchadd_long(xlongp, 1);
1098 }
1099], [je_cv_atomic9])
1100if test "x${je_cv_atomic9}" = "xyes" ; then
1101 AC_DEFINE([JEMALLOC_ATOMIC9])
1102fi
a78e148b 1103
1104dnl ============================================================================
1105dnl Check for atomic(3) operations as provided on Darwin.
1106
1107JE_COMPILABLE([Darwin OSAtomic*()], [
1108#include <libkern/OSAtomic.h>
1109#include <inttypes.h>
1110], [
1111 {
1112 int32_t x32 = 0;
1113 volatile int32_t *x32p = &x32;
1114 OSAtomicAdd32(1, x32p);
1115 }
1116 {
1117 int64_t x64 = 0;
1118 volatile int64_t *x64p = &x64;
1119 OSAtomicAdd64(1, x64p);
1120 }
4934f93d 1121], [je_cv_osatomic])
1122if test "x${je_cv_osatomic}" = "xyes" ; then
1123 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1124fi
1125
1126dnl ============================================================================
1127dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1128dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1129
1130AC_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([
1134 #include <stdint.h>
1135 ],
1136 [
1137 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1138 {
1139 uint$1_t x$1 = 0;
1140 __sync_add_and_fetch(&x$1, 42);
1141 __sync_sub_and_fetch(&x$1, 1);
1142 }
1143 #else
1144 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1145 #endif
1146 ])],
1147 [je_cv_sync_compare_and_swap_$2=yes],
1148 [je_cv_sync_compare_and_swap_$2=no])])
1149
1150 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1151 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1152 fi
1153])
1154
1155if 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)
a78e148b 1158fi
1159
1160dnl ============================================================================
1161dnl Check for spinlock(3) operations as provided on Darwin.
1162
1163JE_COMPILABLE([Darwin OSSpin*()], [
1164#include <libkern/OSAtomic.h>
1165#include <inttypes.h>
1166], [
1167 OSSpinLock lock = 0;
1168 OSSpinLockLock(&lock);
1169 OSSpinLockUnlock(&lock);
4934f93d 1170], [je_cv_osspin])
1171if test "x${je_cv_osspin}" = "xyes" ; then
1172 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
a78e148b 1173fi
1174
a78e148b 1175dnl ============================================================================
1176dnl Darwin-related configuration.
1177
1178if test "x${abi}" = "xmacho" ; then
4934f93d 1179 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1180 AC_DEFINE([JEMALLOC_ZONE], [ ])
a78e148b 1181
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])
4934f93d 1186 AC_DEFUN([JE_ZONE_PROGRAM],
1187 [AC_LANG_PROGRAM(
1188 [#include <malloc/malloc.h>],
1189 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1190 )])
1191
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=]
1197 )])],[
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=]
1200 )])])])])
1201 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1202 AC_MSG_RESULT([unsupported])
1203 AC_MSG_ERROR([Unsupported malloc zone version])
1204 fi
1205 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1206 JEMALLOC_ZONE_VERSION=8
1207 AC_MSG_RESULT([> 8])
1208 else
1209 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1210 fi
1211 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
a78e148b 1212fi
1213
1214dnl ============================================================================
1215dnl Check for typedefs, structures, and compiler characteristics.
1216AC_HEADER_STDBOOL
1217
4934f93d 1218AC_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"
1221])
1222
a78e148b 1223dnl Process .in files.
1224AC_SUBST([cfghdrs_in])
1225AC_SUBST([cfghdrs_out])
1226AC_CONFIG_HEADERS([$cfghdrs_tup])
1227
1228dnl ============================================================================
1229dnl Generate outputs.
4934f93d 1230AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
a78e148b 1231AC_SUBST([cfgoutputs_in])
1232AC_SUBST([cfgoutputs_out])
1233AC_OUTPUT
1234
1235dnl ============================================================================
1236dnl Print out the results of configuration.
1237AC_MSG_RESULT([===============================================================================])
4934f93d 1238AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1239AC_MSG_RESULT([library revision : ${rev}])
a78e148b 1240AC_MSG_RESULT([])
1241AC_MSG_RESULT([CC : ${CC}])
1242AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1243AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1244AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1245AC_MSG_RESULT([LIBS : ${LIBS}])
1246AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1247AC_MSG_RESULT([])
1248AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1249AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1250AC_MSG_RESULT([])
1251AC_MSG_RESULT([PREFIX : ${PREFIX}])
1252AC_MSG_RESULT([BINDIR : ${BINDIR}])
1253AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1254AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
1255AC_MSG_RESULT([DATADIR : ${DATADIR}])
1256AC_MSG_RESULT([MANDIR : ${MANDIR}])
1257AC_MSG_RESULT([])
1258AC_MSG_RESULT([srcroot : ${srcroot}])
1259AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1260AC_MSG_RESULT([objroot : ${objroot}])
1261AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1262AC_MSG_RESULT([])
1263AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
1d03c1c9 1264AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1265AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
a78e148b 1266AC_MSG_RESULT([install_suffix : ${install_suffix}])
1267AC_MSG_RESULT([autogen : ${enable_autogen}])
4934f93d 1268AC_MSG_RESULT([experimental : ${enable_experimental}])
a78e148b 1269AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
1270AC_MSG_RESULT([debug : ${enable_debug}])
1271AC_MSG_RESULT([stats : ${enable_stats}])
1272AC_MSG_RESULT([prof : ${enable_prof}])
1273AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
1274AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1275AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
a78e148b 1276AC_MSG_RESULT([tcache : ${enable_tcache}])
1277AC_MSG_RESULT([fill : ${enable_fill}])
4934f93d 1278AC_MSG_RESULT([utrace : ${enable_utrace}])
1279AC_MSG_RESULT([valgrind : ${enable_valgrind}])
a78e148b 1280AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
4934f93d 1281AC_MSG_RESULT([mremap : ${enable_mremap}])
1282AC_MSG_RESULT([munmap : ${enable_munmap}])
a78e148b 1283AC_MSG_RESULT([dss : ${enable_dss}])
a78e148b 1284AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
1285AC_MSG_RESULT([tls : ${enable_tls}])
1286AC_MSG_RESULT([===============================================================================])