]> git.saurik.com Git - redis.git/blame - deps/jemalloc/configure.ac
Query the archive to provide a complete KEYS list.
[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"
21b26915 240JEMALLOC_USABLE_SIZE_CONST="const"
a78e148b 241case "${host}" in
242 *-*-darwin*)
4934f93d 243 CFLAGS="$CFLAGS"
a78e148b 244 abi="macho"
4934f93d 245 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
a78e148b 246 RPATH=""
4934f93d 247 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
248 so="dylib"
249 importlib="${so}"
250 force_tls="0"
251 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
252 SOREV="${rev}.${so}"
a78e148b 253 ;;
254 *-*-freebsd*)
255 CFLAGS="$CFLAGS"
256 abi="elf"
4934f93d 257 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
258 force_lazy_lock="1"
a78e148b 259 ;;
260 *-*-linux*)
261 CFLAGS="$CFLAGS"
262 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
263 abi="elf"
4934f93d 264 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
265 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
21b26915 266 JEMALLOC_USABLE_SIZE_CONST=""
4934f93d 267 default_munmap="0"
a78e148b 268 ;;
269 *-*-netbsd*)
270 AC_MSG_CHECKING([ABI])
271 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
272[[#ifdef __ELF__
273/* ELF */
274#else
275#error aout
276#endif
277]])],
278 [CFLAGS="$CFLAGS"; abi="elf"],
279 [abi="aout"])
280 AC_MSG_RESULT([$abi])
4934f93d 281 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
a78e148b 282 ;;
283 *-*-solaris2*)
284 CFLAGS="$CFLAGS"
285 abi="elf"
4934f93d 286 RPATH='-Wl,-R,$(1)'
a78e148b 287 dnl Solaris needs this for sigwait().
288 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
289 LIBS="$LIBS -lposix4 -lsocket -lnsl"
290 ;;
4934f93d 291 *-ibm-aix*)
292 if "$LG_SIZEOF_PTR" = "8"; then
293 dnl 64bit AIX
294 LD_PRELOAD_VAR="LDR_PRELOAD64"
295 else
296 dnl 32bit AIX
297 LD_PRELOAD_VAR="LDR_PRELOAD"
298 fi
299 abi="xcoff"
300 ;;
301 *-*-mingw*)
302 abi="pecoff"
303 force_tls="0"
304 RPATH=""
305 so="dll"
306 if test "x$je_cv_msvc" = "xyes" ; then
307 importlib="lib"
308 DSO_LDFLAGS="-LD"
309 EXTRA_LDFLAGS="-link -DEBUG"
310 CTARGET='-Fo$@'
311 LDTARGET='-Fe$@'
312 MKLIB='lib -nologo -out:$@'
313 CC_MM=
314 else
315 importlib="${so}"
316 DSO_LDFLAGS="-shared"
317 fi
318 a="lib"
319 libprefix=""
320 SOREV="${so}"
321 PIC_CFLAGS=""
322 ;;
a78e148b 323 *)
324 AC_MSG_RESULT([Unsupported operating system: ${host}])
325 abi="elf"
a78e148b 326 ;;
327esac
21b26915 328AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
a78e148b 329AC_SUBST([abi])
330AC_SUBST([RPATH])
4934f93d 331AC_SUBST([LD_PRELOAD_VAR])
332AC_SUBST([so])
333AC_SUBST([importlib])
334AC_SUBST([o])
335AC_SUBST([a])
336AC_SUBST([exe])
337AC_SUBST([libprefix])
338AC_SUBST([DSO_LDFLAGS])
339AC_SUBST([EXTRA_LDFLAGS])
340AC_SUBST([SOREV])
341AC_SUBST([PIC_CFLAGS])
342AC_SUBST([CTARGET])
343AC_SUBST([LDTARGET])
344AC_SUBST([MKLIB])
345AC_SUBST([CC_MM])
346
347if test "x$abi" != "xpecoff"; then
348 dnl Heap profiling uses the log(3) function.
349 LIBS="$LIBS -lm"
350fi
a78e148b 351
352JE_COMPILABLE([__attribute__ syntax],
353 [static __attribute__((unused)) void foo(void){}],
354 [],
4934f93d 355 [je_cv_attribute])
356if test "x${je_cv_attribute}" = "xyes" ; then
a78e148b 357 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
358 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
359 JE_CFLAGS_APPEND([-fvisibility=hidden])
360 fi
361fi
4934f93d 362dnl Check for tls_model attribute support (clang 3.0 still lacks support).
363SAVED_CFLAGS="${CFLAGS}"
364JE_CFLAGS_APPEND([-Werror])
365JE_COMPILABLE([tls_model attribute], [],
366 [static __thread int
367 __attribute__((tls_model("initial-exec"))) foo;
368 foo = 0;],
369 [je_cv_tls_model])
370CFLAGS="${SAVED_CFLAGS}"
371if test "x${je_cv_tls_model}" = "xyes" ; then
372 AC_DEFINE([JEMALLOC_TLS_MODEL],
373 [__attribute__((tls_model("initial-exec")))])
374else
375 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
a78e148b 376fi
377
378dnl Support optional additions to rpath.
379AC_ARG_WITH([rpath],
380 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
381if test "x$with_rpath" = "xno" ; then
382 RPATH_EXTRA=
383else
384 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
385fi,
386 RPATH_EXTRA=
387)
388AC_SUBST([RPATH_EXTRA])
389
390dnl Disable rules that do automatic regeneration of configure output by default.
391AC_ARG_ENABLE([autogen],
392 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
393if test "x$enable_autogen" = "xno" ; then
394 enable_autogen="0"
395else
396 enable_autogen="1"
397fi
398,
399enable_autogen="0"
400)
401AC_SUBST([enable_autogen])
402
403AC_PROG_INSTALL
404AC_PROG_RANLIB
405AC_PATH_PROG([AR], [ar], , [$PATH])
406AC_PATH_PROG([LD], [ld], , [$PATH])
407AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
408
4934f93d 409public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib"
410
411dnl Check for allocator-related functions that should be wrapped.
412AC_CHECK_FUNC([memalign],
413 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
414 public_syms="${public_syms} memalign"])
415AC_CHECK_FUNC([valloc],
416 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
417 public_syms="${public_syms} valloc"])
418
419dnl Support the experimental API by default.
420AC_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"
425else
426 enable_experimental="1"
427fi
428],
429[enable_experimental="1"]
430)
431if test "x$enable_experimental" = "x1" ; then
432 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
433 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
434fi
435AC_SUBST([enable_experimental])
436
437dnl Perform no name mangling by default.
438AC_ARG_WITH([mangling],
439 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
440 [mangling_map="$with_mangling"], [mangling_map=""])
441for nm in `echo ${mangling_map} |tr ',' ' '` ; do
442 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
443 n="je_${k}"
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' ' '`
448done
449
a78e148b 450dnl Do not prefix public APIs by default.
451AC_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"],
4934f93d 454 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
a78e148b 455 JEMALLOC_PREFIX=""
456else
457 JEMALLOC_PREFIX="je_"
458fi]
459)
460if 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"])
a78e148b 464fi
4934f93d 465dnl Generate macros to rename public symbols. All public symbols are prefixed
466dnl with je_ in the source code, so these macro definitions are needed even if
467dnl --with-jemalloc-prefix wasn't specified.
468for stem in ${public_syms}; do
469 n="je_${stem}"
470 m="${JEMALLOC_PREFIX}${stem}"
471 AC_DEFINE_UNQUOTED([${n}], [${m}])
472done
a78e148b 473
1d03c1c9 474dnl Do not mangle library-private APIs by default.
475AC_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=""]
479)
480AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
481if 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])
483else
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])
485fi
486
a78e148b 487dnl Do not add suffix to installed files by default.
488AC_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"],
491 [INSTALL_SUFFIX=]
492)
493install_suffix="$INSTALL_SUFFIX"
494AC_SUBST([install_suffix])
495
496cfgoutputs_in="${srcroot}Makefile.in"
497cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
498cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
499cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
500cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
501cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
502cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
503
504cfgoutputs_out="Makefile"
505cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
506cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
507cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
508cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
509cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
510cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
511
512cfgoutputs_tup="Makefile"
513cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
514cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
515cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
516cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
517cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
518cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
519
520cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
4934f93d 521cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
a78e148b 522
523cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
4934f93d 524cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
a78e148b 525
526cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
527
528dnl Do not silence irrelevant compiler warnings by default, since enabling this
529dnl option incurs a performance penalty.
530AC_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"
535else
536 enable_cc_silence="1"
537fi
538],
539[enable_cc_silence="0"]
540)
541if test "x$enable_cc_silence" = "x1" ; then
4934f93d 542 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
a78e148b 543fi
544
545dnl Do not compile with debugging by default.
546AC_ARG_ENABLE([debug],
547 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
548[if test "x$enable_debug" = "xno" ; then
549 enable_debug="0"
550else
551 enable_debug="1"
552fi
553],
554[enable_debug="0"]
555)
556if test "x$enable_debug" = "x1" ; then
557 AC_DEFINE([JEMALLOC_DEBUG], [ ])
558 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
559fi
560AC_SUBST([enable_debug])
561
562dnl Only optimize if not debugging.
563if 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.
565 optimize="no"
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])
4934f93d 571 elif test "x$je_cv_msvc" = "xyes" ; then
572 JE_CFLAGS_APPEND([-O2])
a78e148b 573 else
574 JE_CFLAGS_APPEND([-O])
575 fi
576 fi
577fi
578
4934f93d 579dnl Enable statistics calculation by default.
a78e148b 580AC_ARG_ENABLE([stats],
4934f93d 581 [AS_HELP_STRING([--disable-stats],
582 [Disable statistics calculation/reporting])],
a78e148b 583[if test "x$enable_stats" = "xno" ; then
584 enable_stats="0"
585else
586 enable_stats="1"
587fi
588],
4934f93d 589[enable_stats="1"]
a78e148b 590)
591if test "x$enable_stats" = "x1" ; then
592 AC_DEFINE([JEMALLOC_STATS], [ ])
593fi
594AC_SUBST([enable_stats])
595
596dnl Do not enable profiling by default.
597AC_ARG_ENABLE([prof],
598 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
599[if test "x$enable_prof" = "xno" ; then
600 enable_prof="0"
601else
602 enable_prof="1"
603fi
604],
605[enable_prof="0"]
606)
607if test "x$enable_prof" = "x1" ; then
608 backtrace_method=""
609else
610 backtrace_method="N/A"
611fi
612
613AC_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"
617else
618 enable_prof_libunwind="1"
619fi
620],
621[enable_prof_libunwind="0"]
622)
623AC_ARG_WITH([static_libunwind],
624 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
625 [Path to static libunwind library; use rather than dynamically linking])],
626if test "x$with_static_libunwind" = "xno" ; then
627 LUNWIND="-lunwind"
628else
629 if test ! -f "$with_static_libunwind" ; then
630 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
631 fi
632 LUNWIND="$with_static_libunwind"
633fi,
634 LUNWIND="-lunwind"
635)
636if 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"])
641 else
642 LIBS="$LIBS $LUNWIND"
643 fi
644 if test "x${enable_prof_libunwind}" = "x1" ; then
645 backtrace_method="libunwind"
646 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
647 fi
648fi
649
650AC_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"
655else
656 enable_prof_libgcc="1"
657fi
658],
659[enable_prof_libgcc="1"]
660)
661if 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
669 i[[3456]]86)
670 AC_MSG_RESULT([unreliable])
671 enable_prof_libgcc="0";
672 ;;
673 x86_64)
674 AC_MSG_RESULT([reliable])
675 ;;
676 *)
677 AC_MSG_RESULT([unreliable])
678 enable_prof_libgcc="0";
679 ;;
680 esac
681 if test "x${enable_prof_libgcc}" = "x1" ; then
682 backtrace_method="libgcc"
683 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
684 fi
685else
686 enable_prof_libgcc="0"
687fi
688
689AC_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
693 enable_prof_gcc="0"
694else
695 enable_prof_gcc="1"
696fi
697],
698[enable_prof_gcc="1"]
699)
700if 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], [ ])
704else
705 enable_prof_gcc="0"
706fi
707
708if test "x$backtrace_method" = "x" ; then
709 backtrace_method="none (disabling profiling)"
710 enable_prof="0"
711fi
712AC_MSG_CHECKING([configured backtracing method])
713AC_MSG_RESULT([$backtrace_method])
714if test "x$enable_prof" = "x1" ; then
4934f93d 715 if test "x${force_tls}" = "x0" ; then
716 AC_MSG_ERROR([Heap profiling requires TLS]);
717 fi
718 force_tls="1"
a78e148b 719 AC_DEFINE([JEMALLOC_PROF], [ ])
720fi
721AC_SUBST([enable_prof])
722
a78e148b 723dnl Enable thread-specific caching by default.
724AC_ARG_ENABLE([tcache],
725 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
726[if test "x$enable_tcache" = "xno" ; then
727 enable_tcache="0"
728else
729 enable_tcache="1"
730fi
731],
732[enable_tcache="1"]
733)
734if test "x$enable_tcache" = "x1" ; then
735 AC_DEFINE([JEMALLOC_TCACHE], [ ])
736fi
737AC_SUBST([enable_tcache])
738
4934f93d 739dnl Disable mremap() for huge realloc() by default.
740AC_ARG_ENABLE([mremap],
741 [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
742[if test "x$enable_mremap" = "xno" ; then
743 enable_mremap="0"
a78e148b 744else
4934f93d 745 enable_mremap="1"
a78e148b 746fi
747],
4934f93d 748[enable_mremap="0"]
a78e148b 749)
4934f93d 750if test "x$enable_mremap" = "x1" ; then
751 JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
752#define _GNU_SOURCE
753#include <sys/mman.h>
754], [
755void *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
758 enable_mremap="0"
759 fi
760fi
761if test "x$enable_mremap" = "x1" ; then
762 AC_DEFINE([JEMALLOC_MREMAP], [ ])
a78e148b 763fi
4934f93d 764AC_SUBST([enable_mremap])
765
766dnl Enable VM deallocation via munmap() by default.
767AC_ARG_ENABLE([munmap],
768 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
769[if test "x$enable_munmap" = "xno" ; then
770 enable_munmap="0"
771else
772 enable_munmap="1"
773fi
774],
775[enable_munmap="${default_munmap}"]
776)
777if test "x$enable_munmap" = "x1" ; then
778 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
779fi
780AC_SUBST([enable_munmap])
a78e148b 781
782dnl Do not enable allocation from DSS by default.
783AC_ARG_ENABLE([dss],
784 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
785[if test "x$enable_dss" = "xno" ; then
786 enable_dss="0"
787else
788 enable_dss="1"
789fi
790],
791[enable_dss="0"]
792)
4934f93d 793dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
794AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
795if test "x$have_sbrk" = "x1" ; then
796 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
797else
798 enable_dss="0"
799fi
800
a78e148b 801if test "x$enable_dss" = "x1" ; then
802 AC_DEFINE([JEMALLOC_DSS], [ ])
803fi
804AC_SUBST([enable_dss])
805
4934f93d 806dnl Support the junk/zero filling option by default.
a78e148b 807AC_ARG_ENABLE([fill],
4934f93d 808 [AS_HELP_STRING([--disable-fill],
809 [Disable support for junk/zero filling, quarantine, and redzones])],
a78e148b 810[if test "x$enable_fill" = "xno" ; then
811 enable_fill="0"
812else
813 enable_fill="1"
814fi
815],
4934f93d 816[enable_fill="1"]
a78e148b 817)
818if test "x$enable_fill" = "x1" ; then
819 AC_DEFINE([JEMALLOC_FILL], [ ])
820fi
821AC_SUBST([enable_fill])
822
4934f93d 823dnl Disable utrace(2)-based tracing by default.
824AC_ARG_ENABLE([utrace],
825 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
826[if test "x$enable_utrace" = "xno" ; then
827 enable_utrace="0"
a78e148b 828else
4934f93d 829 enable_utrace="1"
a78e148b 830fi
831],
4934f93d 832[enable_utrace="0"]
a78e148b 833)
4934f93d 834JE_COMPILABLE([utrace(2)], [
835#include <sys/types.h>
836#include <sys/param.h>
837#include <sys/time.h>
838#include <sys/uio.h>
839#include <sys/ktrace.h>
840], [
841 utrace((void *)0, 0);
842], [je_cv_utrace])
843if test "x${je_cv_utrace}" = "xno" ; then
844 enable_utrace="0"
a78e148b 845fi
4934f93d 846if test "x$enable_utrace" = "x1" ; then
847 AC_DEFINE([JEMALLOC_UTRACE], [ ])
848fi
849AC_SUBST([enable_utrace])
a78e148b 850
4934f93d 851dnl Support Valgrind by default.
852AC_ARG_ENABLE([valgrind],
853 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
854[if test "x$enable_valgrind" = "xno" ; then
855 enable_valgrind="0"
a78e148b 856else
4934f93d 857 enable_valgrind="1"
a78e148b 858fi
859],
4934f93d 860[enable_valgrind="1"]
a78e148b 861)
4934f93d 862if test "x$enable_valgrind" = "x1" ; then
863 JE_COMPILABLE([valgrind], [
864#include <valgrind/valgrind.h>
865#include <valgrind/memcheck.h>
866
867#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
868# error "Incompatible Valgrind version"
869#endif
870], [], [je_cv_valgrind])
871 if test "x${je_cv_valgrind}" = "xno" ; then
872 enable_valgrind="0"
873 fi
874 if test "x$enable_valgrind" = "x1" ; then
875 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
876 fi
a78e148b 877fi
4934f93d 878AC_SUBST([enable_valgrind])
a78e148b 879
4934f93d 880dnl Do not support the xmalloc option by default.
881AC_ARG_ENABLE([xmalloc],
882 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
883[if test "x$enable_xmalloc" = "xno" ; then
884 enable_xmalloc="0"
a78e148b 885else
4934f93d 886 enable_xmalloc="1"
a78e148b 887fi
888],
4934f93d 889[enable_xmalloc="0"]
a78e148b 890)
4934f93d 891if test "x$enable_xmalloc" = "x1" ; then
892 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
a78e148b 893fi
4934f93d 894AC_SUBST([enable_xmalloc])
a78e148b 895
4934f93d 896AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
897 [je_cv_static_page_shift],
898 AC_RUN_IFELSE([AC_LANG_PROGRAM(
899[[
a78e148b 900#include <strings.h>
4934f93d 901#ifdef _WIN32
902#include <windows.h>
903#else
904#include <unistd.h>
905#endif
906#include <stdio.h>
907]],
908[[
a78e148b 909 long result;
910 FILE *f;
911
4934f93d 912#ifdef _WIN32
913 SYSTEM_INFO si;
914 GetSystemInfo(&si);
915 result = si.dwPageSize;
916#else
a78e148b 917 result = sysconf(_SC_PAGESIZE);
4934f93d 918#endif
a78e148b 919 if (result == -1) {
920 return 1;
921 }
4934f93d 922 result = ffsl(result) - 1;
923
a78e148b 924 f = fopen("conftest.out", "w");
925 if (f == NULL) {
926 return 1;
927 }
4934f93d 928 fprintf(f, "%u\n", result);
929 fclose(f);
a78e148b 930
931 return 0;
932]])],
4934f93d 933 [je_cv_static_page_shift=`cat conftest.out`],
934 [je_cv_static_page_shift=undefined]))
935
936if test "x$je_cv_static_page_shift" != "xundefined"; then
937 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
938else
939 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
940fi
a78e148b 941
942dnl ============================================================================
943dnl jemalloc configuration.
944dnl
945
946dnl Set VERSION if source directory has an embedded git repository.
1d03c1c9 947if test -d "${srcroot}.git" ; then
a78e148b 948 git describe --long --abbrev=40 > ${srcroot}VERSION
949fi
950jemalloc_version=`cat ${srcroot}VERSION`
951jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
952jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
953jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
954jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
955jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
956AC_SUBST([jemalloc_version])
957AC_SUBST([jemalloc_version_major])
958AC_SUBST([jemalloc_version_minor])
959AC_SUBST([jemalloc_version_bugfix])
960AC_SUBST([jemalloc_version_nrev])
961AC_SUBST([jemalloc_version_gid])
962
963dnl ============================================================================
964dnl Configure pthreads.
965
4934f93d 966if 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]))])
973fi
a78e148b 974
975CPPFLAGS="$CPPFLAGS -D_REENTRANT"
976
4934f93d 977dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
978dnl it rather than pthreads TSD cleanup functions to support cleanup during
979dnl thread exit, in order to avoid pthreads library recursion during
980dnl bootstrapping.
981AC_CHECK_FUNC([_malloc_thread_cleanup],
982 [have__malloc_thread_cleanup="1"],
983 [have__malloc_thread_cleanup="0"]
984 )
985if test "x$have__malloc_thread_cleanup" = "x1" ; then
986 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
987 force_tls="1"
988fi
989
990dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
991dnl so, mutex initialization causes allocation, and we need to implement this
992dnl callback function in order to prevent recursive allocation.
993AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
994 [have__pthread_mutex_init_calloc_cb="1"],
995 [have__pthread_mutex_init_calloc_cb="0"]
996 )
997if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
998 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
999fi
1000
1001dnl Disable lazy locking by default.
a78e148b 1002AC_ARG_ENABLE([lazy_lock],
4934f93d 1003 [AS_HELP_STRING([--enable-lazy-lock],
1004 [Enable lazy locking (only lock when multi-threaded)])],
a78e148b 1005[if test "x$enable_lazy_lock" = "xno" ; then
1006 enable_lazy_lock="0"
1007else
1008 enable_lazy_lock="1"
1009fi
1010],
4934f93d 1011[enable_lazy_lock="0"]
a78e148b 1012)
4934f93d 1013if 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"
1016fi
a78e148b 1017if test "x$enable_lazy_lock" = "x1" ; then
4934f93d 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])])
1023 ])
1024 fi
a78e148b 1025 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1026fi
1027AC_SUBST([enable_lazy_lock])
1028
1029AC_ARG_ENABLE([tls],
1030 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1031if test "x$enable_tls" = "xno" ; then
1032 enable_tls="0"
1033else
1034 enable_tls="1"
1035fi
1036,
1037enable_tls="1"
1038)
4934f93d 1039if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1040 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1041 enable_tls="1"
1042fi
1043if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1044 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1045 enable_tls="0"
1046fi
a78e148b 1047if test "x${enable_tls}" = "x1" ; then
1048AC_MSG_CHECKING([for TLS])
4934f93d 1049AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
a78e148b 1050[[
1051 __thread int x;
1052]], [[
1053 x = 42;
1054
1055 return 0;
1056]])],
1057 AC_MSG_RESULT([yes]),
1058 AC_MSG_RESULT([no])
1059 enable_tls="0")
1060fi
1061AC_SUBST([enable_tls])
4934f93d 1062if test "x${enable_tls}" = "x1" ; then
1063 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1064elif test "x${force_tls}" = "x1" ; then
1065 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
a78e148b 1066fi
1067
1068dnl ============================================================================
1069dnl Check for ffsl(3), and fail if not found. This function exists on all
1070dnl platforms that jemalloc currently has a chance of functioning on without
1071dnl modification.
4934f93d 1072JE_COMPILABLE([a program using ffsl], [
1073#include <strings.h>
1074#include <string.h>
1075], [
1076 {
1077 int rv = ffsl(0x08);
1078 }
1079], [je_cv_function_ffsl])
1080if test "x${je_cv_function_ffsl}" != "xyes" ; then
1081 AC_MSG_ERROR([Cannot build without ffsl(3)])
1082fi
a78e148b 1083
4934f93d 1084dnl ============================================================================
1085dnl Check for atomic(9) operations as provided on FreeBSD.
1086
1087JE_COMPILABLE([atomic(9)], [
1088#include <sys/types.h>
1089#include <machine/atomic.h>
1090#include <inttypes.h>
1091], [
1092 {
1093 uint32_t x32 = 0;
1094 volatile uint32_t *x32p = &x32;
1095 atomic_fetchadd_32(x32p, 1);
1096 }
1097 {
1098 unsigned long xlong = 0;
1099 volatile unsigned long *xlongp = &xlong;
1100 atomic_fetchadd_long(xlongp, 1);
1101 }
1102], [je_cv_atomic9])
1103if test "x${je_cv_atomic9}" = "xyes" ; then
1104 AC_DEFINE([JEMALLOC_ATOMIC9])
1105fi
a78e148b 1106
1107dnl ============================================================================
1108dnl Check for atomic(3) operations as provided on Darwin.
1109
1110JE_COMPILABLE([Darwin OSAtomic*()], [
1111#include <libkern/OSAtomic.h>
1112#include <inttypes.h>
1113], [
1114 {
1115 int32_t x32 = 0;
1116 volatile int32_t *x32p = &x32;
1117 OSAtomicAdd32(1, x32p);
1118 }
1119 {
1120 int64_t x64 = 0;
1121 volatile int64_t *x64p = &x64;
1122 OSAtomicAdd64(1, x64p);
1123 }
4934f93d 1124], [je_cv_osatomic])
1125if test "x${je_cv_osatomic}" = "xyes" ; then
1126 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1127fi
1128
1129dnl ============================================================================
1130dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1131dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1132
1133AC_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([
1137 #include <stdint.h>
1138 ],
1139 [
1140 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1141 {
1142 uint$1_t x$1 = 0;
1143 __sync_add_and_fetch(&x$1, 42);
1144 __sync_sub_and_fetch(&x$1, 1);
1145 }
1146 #else
1147 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1148 #endif
1149 ])],
1150 [je_cv_sync_compare_and_swap_$2=yes],
1151 [je_cv_sync_compare_and_swap_$2=no])])
1152
1153 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1154 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1155 fi
1156])
1157
1158if 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)
a78e148b 1161fi
1162
1163dnl ============================================================================
1164dnl Check for spinlock(3) operations as provided on Darwin.
1165
1166JE_COMPILABLE([Darwin OSSpin*()], [
1167#include <libkern/OSAtomic.h>
1168#include <inttypes.h>
1169], [
1170 OSSpinLock lock = 0;
1171 OSSpinLockLock(&lock);
1172 OSSpinLockUnlock(&lock);
4934f93d 1173], [je_cv_osspin])
1174if test "x${je_cv_osspin}" = "xyes" ; then
1175 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
a78e148b 1176fi
1177
a78e148b 1178dnl ============================================================================
1179dnl Darwin-related configuration.
1180
1181if test "x${abi}" = "xmacho" ; then
4934f93d 1182 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1183 AC_DEFINE([JEMALLOC_ZONE], [ ])
a78e148b 1184
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])
4934f93d 1189 AC_DEFUN([JE_ZONE_PROGRAM],
1190 [AC_LANG_PROGRAM(
1191 [#include <malloc/malloc.h>],
1192 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1193 )])
1194
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=]
1200 )])],[
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=]
1203 )])])])])
1204 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1205 AC_MSG_RESULT([unsupported])
1206 AC_MSG_ERROR([Unsupported malloc zone version])
1207 fi
1208 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1209 JEMALLOC_ZONE_VERSION=8
1210 AC_MSG_RESULT([> 8])
1211 else
1212 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1213 fi
1214 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
a78e148b 1215fi
1216
1217dnl ============================================================================
1218dnl Check for typedefs, structures, and compiler characteristics.
1219AC_HEADER_STDBOOL
1220
4934f93d 1221AC_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"
1224])
1225
a78e148b 1226dnl Process .in files.
1227AC_SUBST([cfghdrs_in])
1228AC_SUBST([cfghdrs_out])
1229AC_CONFIG_HEADERS([$cfghdrs_tup])
1230
1231dnl ============================================================================
1232dnl Generate outputs.
4934f93d 1233AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
a78e148b 1234AC_SUBST([cfgoutputs_in])
1235AC_SUBST([cfgoutputs_out])
1236AC_OUTPUT
1237
1238dnl ============================================================================
1239dnl Print out the results of configuration.
1240AC_MSG_RESULT([===============================================================================])
4934f93d 1241AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1242AC_MSG_RESULT([library revision : ${rev}])
a78e148b 1243AC_MSG_RESULT([])
1244AC_MSG_RESULT([CC : ${CC}])
1245AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1246AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1247AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1248AC_MSG_RESULT([LIBS : ${LIBS}])
1249AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1250AC_MSG_RESULT([])
1251AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1252AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1253AC_MSG_RESULT([])
1254AC_MSG_RESULT([PREFIX : ${PREFIX}])
1255AC_MSG_RESULT([BINDIR : ${BINDIR}])
1256AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1257AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
1258AC_MSG_RESULT([DATADIR : ${DATADIR}])
1259AC_MSG_RESULT([MANDIR : ${MANDIR}])
1260AC_MSG_RESULT([])
1261AC_MSG_RESULT([srcroot : ${srcroot}])
1262AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1263AC_MSG_RESULT([objroot : ${objroot}])
1264AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1265AC_MSG_RESULT([])
1266AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
1d03c1c9 1267AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1268AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
a78e148b 1269AC_MSG_RESULT([install_suffix : ${install_suffix}])
1270AC_MSG_RESULT([autogen : ${enable_autogen}])
4934f93d 1271AC_MSG_RESULT([experimental : ${enable_experimental}])
a78e148b 1272AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
1273AC_MSG_RESULT([debug : ${enable_debug}])
1274AC_MSG_RESULT([stats : ${enable_stats}])
1275AC_MSG_RESULT([prof : ${enable_prof}])
1276AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
1277AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1278AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
a78e148b 1279AC_MSG_RESULT([tcache : ${enable_tcache}])
1280AC_MSG_RESULT([fill : ${enable_fill}])
4934f93d 1281AC_MSG_RESULT([utrace : ${enable_utrace}])
1282AC_MSG_RESULT([valgrind : ${enable_valgrind}])
a78e148b 1283AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
4934f93d 1284AC_MSG_RESULT([mremap : ${enable_mremap}])
1285AC_MSG_RESULT([munmap : ${enable_munmap}])
a78e148b 1286AC_MSG_RESULT([dss : ${enable_dss}])
a78e148b 1287AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
1288AC_MSG_RESULT([tls : ${enable_tls}])
1289AC_MSG_RESULT([===============================================================================])