]> git.proxmox.com Git - rustc.git/blame - src/jemalloc/configure.ac
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / jemalloc / configure.ac
CommitLineData
970d7e83
LB
1dnl Process this file with autoconf to produce a configure script.
2AC_INIT([Makefile.in])
3
54a0048b
SL
4AC_CONFIG_AUX_DIR([build-aux])
5
970d7e83
LB
6dnl ============================================================================
7dnl Custom macro definitions.
8
9dnl JE_CFLAGS_APPEND(cflag)
10AC_DEFUN([JE_CFLAGS_APPEND],
11[
12AC_MSG_CHECKING([whether compiler supports $1])
13TCFLAGS="${CFLAGS}"
14if test "x${CFLAGS}" = "x" ; then
15 CFLAGS="$1"
16else
17 CFLAGS="${CFLAGS} $1"
18fi
19AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
20[[
21]], [[
22 return 0;
23]])],
1a4d82fc 24 [je_cv_cflags_appended=$1]
970d7e83 25 AC_MSG_RESULT([yes]),
1a4d82fc 26 [je_cv_cflags_appended=]
970d7e83
LB
27 AC_MSG_RESULT([no])
28 [CFLAGS="${TCFLAGS}"]
29)
30])
31
32dnl JE_COMPILABLE(label, hcode, mcode, rvar)
33dnl
34dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
35dnl cause failure.
36AC_DEFUN([JE_COMPILABLE],
37[
38AC_CACHE_CHECK([whether $1 is compilable],
39 [$4],
40 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
41 [$3])],
42 [$4=yes],
43 [$4=no])])
44])
45
46dnl ============================================================================
47
54a0048b
SL
48CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
49AC_SUBST([CONFIG])
50
970d7e83 51dnl Library revision.
1a4d82fc 52rev=2
970d7e83
LB
53AC_SUBST([rev])
54
55srcroot=$srcdir
56if test "x${srcroot}" = "x." ; then
57 srcroot=""
58else
59 srcroot="${srcroot}/"
60fi
61AC_SUBST([srcroot])
62abs_srcroot="`cd \"${srcdir}\"; pwd`/"
63AC_SUBST([abs_srcroot])
64
65objroot=""
66AC_SUBST([objroot])
67abs_objroot="`pwd`/"
68AC_SUBST([abs_objroot])
69
70dnl Munge install path variables.
71if test "x$prefix" = "xNONE" ; then
72 prefix="/usr/local"
73fi
74if test "x$exec_prefix" = "xNONE" ; then
75 exec_prefix=$prefix
76fi
77PREFIX=$prefix
78AC_SUBST([PREFIX])
79BINDIR=`eval echo $bindir`
80BINDIR=`eval echo $BINDIR`
81AC_SUBST([BINDIR])
82INCLUDEDIR=`eval echo $includedir`
83INCLUDEDIR=`eval echo $INCLUDEDIR`
84AC_SUBST([INCLUDEDIR])
85LIBDIR=`eval echo $libdir`
86LIBDIR=`eval echo $LIBDIR`
87AC_SUBST([LIBDIR])
88DATADIR=`eval echo $datadir`
89DATADIR=`eval echo $DATADIR`
90AC_SUBST([DATADIR])
91MANDIR=`eval echo $mandir`
92MANDIR=`eval echo $MANDIR`
93AC_SUBST([MANDIR])
94
95dnl Support for building documentation.
96AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
97if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
98 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
99elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
100 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
101else
102 dnl Documentation building will fail if this default gets used.
103 DEFAULT_XSLROOT=""
104fi
105AC_ARG_WITH([xslroot],
106 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
107if test "x$with_xslroot" = "xno" ; then
108 XSLROOT="${DEFAULT_XSLROOT}"
109else
110 XSLROOT="${with_xslroot}"
111fi
112],
113 XSLROOT="${DEFAULT_XSLROOT}"
114)
115AC_SUBST([XSLROOT])
116
117dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
118dnl just prevent autoconf from molesting CFLAGS.
119CFLAGS=$CFLAGS
120AC_PROG_CC
121if test "x$GCC" != "xyes" ; then
122 AC_CACHE_CHECK([whether compiler is MSVC],
123 [je_cv_msvc],
124 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
125 [
126#ifndef _MSC_VER
127 int fail[-1];
128#endif
129])],
130 [je_cv_msvc=yes],
131 [je_cv_msvc=no])])
132fi
133
134if test "x$CFLAGS" = "x" ; then
135 no_CFLAGS="yes"
136 if test "x$GCC" = "xyes" ; then
137 JE_CFLAGS_APPEND([-std=gnu99])
1a4d82fc
JJ
138 if test "x$je_cv_cflags_appended" = "x-std=gnu99" ; then
139 AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
140 fi
970d7e83 141 JE_CFLAGS_APPEND([-Wall])
54a0048b
SL
142 JE_CFLAGS_APPEND([-Werror=declaration-after-statement])
143 JE_CFLAGS_APPEND([-Wshorten-64-to-32])
970d7e83
LB
144 JE_CFLAGS_APPEND([-pipe])
145 JE_CFLAGS_APPEND([-g3])
146 elif test "x$je_cv_msvc" = "xyes" ; then
147 CC="$CC -nologo"
148 JE_CFLAGS_APPEND([-Zi])
149 JE_CFLAGS_APPEND([-MT])
150 JE_CFLAGS_APPEND([-W3])
1a4d82fc
JJ
151 JE_CFLAGS_APPEND([-FS])
152 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat"
970d7e83
LB
153 fi
154fi
155dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
156if test "x$EXTRA_CFLAGS" != "x" ; then
157 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
158fi
159AC_PROG_CPP
160
1a4d82fc
JJ
161AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
162if test "x${ac_cv_big_endian}" = "x1" ; then
163 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
164fi
165
166if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
167 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
168fi
169
54a0048b
SL
170if test "x${je_cv_msvc}" = "xyes" ; then
171 LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
172 AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
970d7e83 173else
54a0048b
SL
174 AC_CHECK_SIZEOF([void *])
175 if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
176 LG_SIZEOF_PTR=3
177 elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
178 LG_SIZEOF_PTR=2
179 else
180 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
181 fi
970d7e83
LB
182fi
183AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
184
185AC_CHECK_SIZEOF([int])
186if test "x${ac_cv_sizeof_int}" = "x8" ; then
187 LG_SIZEOF_INT=3
188elif test "x${ac_cv_sizeof_int}" = "x4" ; then
189 LG_SIZEOF_INT=2
190else
191 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
192fi
193AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
194
195AC_CHECK_SIZEOF([long])
196if test "x${ac_cv_sizeof_long}" = "x8" ; then
197 LG_SIZEOF_LONG=3
198elif test "x${ac_cv_sizeof_long}" = "x4" ; then
199 LG_SIZEOF_LONG=2
200else
201 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
202fi
203AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
204
54a0048b
SL
205AC_CHECK_SIZEOF([long long])
206if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
207 LG_SIZEOF_LONG_LONG=3
208elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
209 LG_SIZEOF_LONG_LONG=2
210else
211 AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
212fi
213AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
214
970d7e83
LB
215AC_CHECK_SIZEOF([intmax_t])
216if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
217 LG_SIZEOF_INTMAX_T=4
218elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
219 LG_SIZEOF_INTMAX_T=3
220elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
221 LG_SIZEOF_INTMAX_T=2
222else
223 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
224fi
225AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
226
227AC_CANONICAL_HOST
228dnl CPU-specific settings.
229CPU_SPINWAIT=""
230case "${host_cpu}" in
1a4d82fc 231 i686|x86_64)
54a0048b
SL
232 if test "x${je_cv_msvc}" = "xyes" ; then
233 AC_CACHE_VAL([je_cv_pause_msvc],
234 [JE_COMPILABLE([pause instruction MSVC], [],
235 [[_mm_pause(); return 0;]],
236 [je_cv_pause_msvc])])
237 if test "x${je_cv_pause_msvc}" = "xyes" ; then
238 CPU_SPINWAIT='_mm_pause()'
239 fi
240 else
241 AC_CACHE_VAL([je_cv_pause],
242 [JE_COMPILABLE([pause instruction], [],
243 [[__asm__ volatile("pause"); return 0;]],
244 [je_cv_pause])])
245 if test "x${je_cv_pause}" = "xyes" ; then
246 CPU_SPINWAIT='__asm__ volatile("pause")'
247 fi
7453a54e 248 fi
970d7e83 249 ;;
1a4d82fc
JJ
250 powerpc)
251 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
252 ;;
970d7e83
LB
253 *)
254 ;;
255esac
256AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
257
258LD_PRELOAD_VAR="LD_PRELOAD"
259so="so"
260importlib="${so}"
261o="$ac_objext"
262a="a"
263exe="$ac_exeext"
264libprefix="lib"
265DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
266RPATH='-Wl,-rpath,$(1)'
267SOREV="${so}.${rev}"
268PIC_CFLAGS='-fPIC -DPIC'
269CTARGET='-o $@'
270LDTARGET='-o $@'
271EXTRA_LDFLAGS=
1a4d82fc
JJ
272ARFLAGS='crus'
273AROUT=' $@'
970d7e83
LB
274CC_MM=1
275
1a4d82fc
JJ
276AN_MAKEVAR([AR], [AC_PROG_AR])
277AN_PROGRAM([ar], [AC_PROG_AR])
278AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
279AC_PROG_AR
280
970d7e83
LB
281dnl Platform-specific settings. abi and RPATH can probably be determined
282dnl programmatically, but doing so is error-prone, which makes it generally
283dnl not worth the trouble.
284dnl
285dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
286dnl definitions need to be seen before any headers are included, which is a pain
287dnl to make happen otherwise.
288default_munmap="1"
54a0048b 289maps_coalesce="1"
970d7e83 290case "${host}" in
1a4d82fc 291 *-*-darwin* | *-*-ios*)
970d7e83
LB
292 CFLAGS="$CFLAGS"
293 abi="macho"
294 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
295 RPATH=""
296 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
297 so="dylib"
298 importlib="${so}"
299 force_tls="0"
54a0048b 300 DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
970d7e83 301 SOREV="${rev}.${so}"
1a4d82fc 302 sbrk_deprecated="1"
970d7e83
LB
303 ;;
304 *-*-freebsd*)
305 CFLAGS="$CFLAGS"
306 abi="elf"
307 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
308 force_lazy_lock="1"
309 ;;
1a4d82fc
JJ
310 *-*-dragonfly*)
311 CFLAGS="$CFLAGS"
312 abi="elf"
313 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
314 ;;
54a0048b
SL
315 *-*-openbsd*)
316 CFLAGS="$CFLAGS"
317 abi="elf"
318 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
319 force_tls="0"
320 ;;
321 *-*-bitrig*)
c34b1796
AL
322 CFLAGS="$CFLAGS"
323 abi="elf"
324 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
325 ;;
970d7e83
LB
326 *-*-linux*)
327 CFLAGS="$CFLAGS"
328 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
329 abi="elf"
330 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
331 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
332 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
54a0048b 333 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
970d7e83
LB
334 default_munmap="0"
335 ;;
336 *-*-netbsd*)
337 AC_MSG_CHECKING([ABI])
338 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
339[[#ifdef __ELF__
340/* ELF */
341#else
342#error aout
343#endif
344]])],
345 [CFLAGS="$CFLAGS"; abi="elf"],
346 [abi="aout"])
347 AC_MSG_RESULT([$abi])
348 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
349 ;;
350 *-*-solaris2*)
351 CFLAGS="$CFLAGS"
352 abi="elf"
1a4d82fc 353 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
970d7e83
LB
354 RPATH='-Wl,-R,$(1)'
355 dnl Solaris needs this for sigwait().
356 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
357 LIBS="$LIBS -lposix4 -lsocket -lnsl"
358 ;;
359 *-ibm-aix*)
360 if "$LG_SIZEOF_PTR" = "8"; then
361 dnl 64bit AIX
362 LD_PRELOAD_VAR="LDR_PRELOAD64"
363 else
364 dnl 32bit AIX
365 LD_PRELOAD_VAR="LDR_PRELOAD"
366 fi
367 abi="xcoff"
368 ;;
1a4d82fc 369 *-*-mingw* | *-*-cygwin*)
970d7e83
LB
370 abi="pecoff"
371 force_tls="0"
54a0048b
SL
372 force_lazy_lock="1"
373 maps_coalesce="0"
970d7e83
LB
374 RPATH=""
375 so="dll"
376 if test "x$je_cv_msvc" = "xyes" ; then
377 importlib="lib"
378 DSO_LDFLAGS="-LD"
379 EXTRA_LDFLAGS="-link -DEBUG"
380 CTARGET='-Fo$@'
381 LDTARGET='-Fe$@'
1a4d82fc
JJ
382 AR='lib'
383 ARFLAGS='-nologo -out:'
384 AROUT='$@'
970d7e83
LB
385 CC_MM=
386 else
387 importlib="${so}"
388 DSO_LDFLAGS="-shared"
389 fi
390 a="lib"
391 libprefix=""
392 SOREV="${so}"
393 PIC_CFLAGS=""
394 ;;
395 *)
396 AC_MSG_RESULT([Unsupported operating system: ${host}])
397 abi="elf"
398 ;;
399esac
1a4d82fc
JJ
400
401JEMALLOC_USABLE_SIZE_CONST=const
402AC_CHECK_HEADERS([malloc.h], [
403 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
404 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
405 [#include <malloc.h>
406 #include <stddef.h>
407 size_t malloc_usable_size(const void *ptr);
408 ],
409 [])],[
410 AC_MSG_RESULT([yes])
411 ],[
412 JEMALLOC_USABLE_SIZE_CONST=
413 AC_MSG_RESULT([no])
414 ])
415])
970d7e83
LB
416AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
417AC_SUBST([abi])
418AC_SUBST([RPATH])
419AC_SUBST([LD_PRELOAD_VAR])
420AC_SUBST([so])
421AC_SUBST([importlib])
422AC_SUBST([o])
423AC_SUBST([a])
424AC_SUBST([exe])
425AC_SUBST([libprefix])
426AC_SUBST([DSO_LDFLAGS])
427AC_SUBST([EXTRA_LDFLAGS])
428AC_SUBST([SOREV])
429AC_SUBST([PIC_CFLAGS])
430AC_SUBST([CTARGET])
431AC_SUBST([LDTARGET])
432AC_SUBST([MKLIB])
1a4d82fc
JJ
433AC_SUBST([ARFLAGS])
434AC_SUBST([AROUT])
970d7e83
LB
435AC_SUBST([CC_MM])
436
970d7e83
LB
437JE_COMPILABLE([__attribute__ syntax],
438 [static __attribute__((unused)) void foo(void){}],
439 [],
440 [je_cv_attribute])
441if test "x${je_cv_attribute}" = "xyes" ; then
442 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
443 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
444 JE_CFLAGS_APPEND([-fvisibility=hidden])
445 fi
446fi
447dnl Check for tls_model attribute support (clang 3.0 still lacks support).
448SAVED_CFLAGS="${CFLAGS}"
449JE_CFLAGS_APPEND([-Werror])
450JE_COMPILABLE([tls_model attribute], [],
451 [static __thread int
1a4d82fc 452 __attribute__((tls_model("initial-exec"), unused)) foo;
970d7e83
LB
453 foo = 0;],
454 [je_cv_tls_model])
455CFLAGS="${SAVED_CFLAGS}"
456if test "x${je_cv_tls_model}" = "xyes" ; then
457 AC_DEFINE([JEMALLOC_TLS_MODEL],
458 [__attribute__((tls_model("initial-exec")))])
459else
460 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
461fi
54a0048b
SL
462dnl Check for alloc_size attribute support.
463SAVED_CFLAGS="${CFLAGS}"
464JE_CFLAGS_APPEND([-Werror])
465JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
466 [void *foo(size_t size) __attribute__((alloc_size(1)));],
467 [je_cv_alloc_size])
468CFLAGS="${SAVED_CFLAGS}"
469if test "x${je_cv_alloc_size}" = "xyes" ; then
470 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
471fi
472dnl Check for format(gnu_printf, ...) attribute support.
473SAVED_CFLAGS="${CFLAGS}"
474JE_CFLAGS_APPEND([-Werror])
475JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
476 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
477 [je_cv_format_gnu_printf])
478CFLAGS="${SAVED_CFLAGS}"
479if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
480 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
481fi
482dnl Check for format(printf, ...) attribute support.
483SAVED_CFLAGS="${CFLAGS}"
484JE_CFLAGS_APPEND([-Werror])
485JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
486 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
487 [je_cv_format_printf])
488CFLAGS="${SAVED_CFLAGS}"
489if test "x${je_cv_format_printf}" = "xyes" ; then
490 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
491fi
970d7e83
LB
492
493dnl Support optional additions to rpath.
494AC_ARG_WITH([rpath],
495 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
496if test "x$with_rpath" = "xno" ; then
497 RPATH_EXTRA=
498else
499 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
500fi,
501 RPATH_EXTRA=
502)
503AC_SUBST([RPATH_EXTRA])
504
505dnl Disable rules that do automatic regeneration of configure output by default.
506AC_ARG_ENABLE([autogen],
507 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
508if test "x$enable_autogen" = "xno" ; then
509 enable_autogen="0"
510else
511 enable_autogen="1"
512fi
513,
514enable_autogen="0"
515)
516AC_SUBST([enable_autogen])
517
518AC_PROG_INSTALL
519AC_PROG_RANLIB
970d7e83
LB
520AC_PATH_PROG([LD], [ld], [false], [$PATH])
521AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
522
1a4d82fc 523public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx sdallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size"
970d7e83
LB
524
525dnl Check for allocator-related functions that should be wrapped.
526AC_CHECK_FUNC([memalign],
527 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
528 public_syms="${public_syms} memalign"])
529AC_CHECK_FUNC([valloc],
530 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
531 public_syms="${public_syms} valloc"])
532
1a4d82fc
JJ
533dnl Do not compute test code coverage by default.
534GCOV_FLAGS=
535AC_ARG_ENABLE([code-coverage],
536 [AS_HELP_STRING([--enable-code-coverage],
537 [Enable code coverage])],
538[if test "x$enable_code_coverage" = "xno" ; then
539 enable_code_coverage="0"
970d7e83 540else
1a4d82fc 541 enable_code_coverage="1"
970d7e83
LB
542fi
543],
1a4d82fc 544[enable_code_coverage="0"]
970d7e83 545)
1a4d82fc
JJ
546if test "x$enable_code_coverage" = "x1" ; then
547 deoptimize="no"
548 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
549 if test "x${deoptimize}" = "xyes" ; then
550 JE_CFLAGS_APPEND([-O0])
551 fi
552 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
553 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
554 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
970d7e83 555fi
1a4d82fc 556AC_SUBST([enable_code_coverage])
970d7e83
LB
557
558dnl Perform no name mangling by default.
559AC_ARG_WITH([mangling],
560 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
561 [mangling_map="$with_mangling"], [mangling_map=""])
970d7e83
LB
562
563dnl Do not prefix public APIs by default.
564AC_ARG_WITH([jemalloc_prefix],
565 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
566 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
567 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
568 JEMALLOC_PREFIX=""
569else
570 JEMALLOC_PREFIX="je_"
571fi]
572)
573if test "x$JEMALLOC_PREFIX" != "x" ; then
574 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
575 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
576 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
577fi
54a0048b 578AC_SUBST([JEMALLOC_CPREFIX])
970d7e83
LB
579
580AC_ARG_WITH([export],
581 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
582 [if test "x$with_export" = "xno"; then
583 AC_DEFINE([JEMALLOC_EXPORT],[])
584fi]
585)
586
1a4d82fc 587dnl Mangle library-private APIs.
970d7e83
LB
588AC_ARG_WITH([private_namespace],
589 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
1a4d82fc
JJ
590 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
591 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
970d7e83 592)
1a4d82fc
JJ
593AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
594private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
595AC_SUBST([private_namespace])
970d7e83
LB
596
597dnl Do not add suffix to installed files by default.
598AC_ARG_WITH([install_suffix],
599 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
600 [INSTALL_SUFFIX="$with_install_suffix"],
601 [INSTALL_SUFFIX=]
602)
603install_suffix="$INSTALL_SUFFIX"
604AC_SUBST([install_suffix])
605
54a0048b
SL
606dnl Specify default malloc_conf.
607AC_ARG_WITH([malloc_conf],
608 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
609 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
610 [JEMALLOC_CONFIG_MALLOC_CONF=""]
611)
612config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
613AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
614
1a4d82fc
JJ
615dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
616dnl jemalloc_protos_jet.h easy.
617je_="je_"
618AC_SUBST([je_])
619
620cfgoutputs_in="Makefile.in"
621cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
622cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
623cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
624cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
625cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
626cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
627cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
628cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
629cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
630cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
970d7e83
LB
631
632cfgoutputs_out="Makefile"
1a4d82fc 633cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
970d7e83
LB
634cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
635cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
1a4d82fc
JJ
636cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
637cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
638cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
639cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
970d7e83 640cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
1a4d82fc
JJ
641cfgoutputs_out="${cfgoutputs_out} test/test.sh"
642cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
970d7e83
LB
643
644cfgoutputs_tup="Makefile"
1a4d82fc 645cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
970d7e83
LB
646cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
647cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
1a4d82fc
JJ
648cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
649cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
650cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
651cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
970d7e83 652cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
1a4d82fc
JJ
653cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
654cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
655
656cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
657cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
658cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
659cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
660cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
661cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
662cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
663cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
664cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
665cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
666cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
667cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
668
669cfghdrs_out="include/jemalloc/jemalloc_defs.h"
670cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
671cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
672cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
673cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
674cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
675cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
970d7e83 676cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
1a4d82fc
JJ
677cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
678cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
679cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
680cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
681cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
682cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
683
684cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
685cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
686cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
687
688dnl Silence irrelevant compiler warnings by default.
970d7e83 689AC_ARG_ENABLE([cc-silence],
1a4d82fc
JJ
690 [AS_HELP_STRING([--disable-cc-silence],
691 [Do not silence irrelevant compiler warnings])],
970d7e83
LB
692[if test "x$enable_cc_silence" = "xno" ; then
693 enable_cc_silence="0"
694else
695 enable_cc_silence="1"
696fi
697],
1a4d82fc 698[enable_cc_silence="1"]
970d7e83
LB
699)
700if test "x$enable_cc_silence" = "x1" ; then
701 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
702fi
703
704dnl Do not compile with debugging by default.
705AC_ARG_ENABLE([debug],
54a0048b
SL
706 [AS_HELP_STRING([--enable-debug],
707 [Build debugging code (implies --enable-ivsalloc)])],
970d7e83
LB
708[if test "x$enable_debug" = "xno" ; then
709 enable_debug="0"
710else
711 enable_debug="1"
712fi
713],
714[enable_debug="0"]
715)
54a0048b
SL
716if test "x$enable_debug" = "x1" ; then
717 AC_DEFINE([JEMALLOC_DEBUG], [ ])
718fi
970d7e83
LB
719if test "x$enable_debug" = "x1" ; then
720 AC_DEFINE([JEMALLOC_DEBUG], [ ])
721 enable_ivsalloc="1"
722fi
723AC_SUBST([enable_debug])
724
725dnl Do not validate pointers by default.
726AC_ARG_ENABLE([ivsalloc],
54a0048b
SL
727 [AS_HELP_STRING([--enable-ivsalloc],
728 [Validate pointers passed through the public API])],
970d7e83
LB
729[if test "x$enable_ivsalloc" = "xno" ; then
730 enable_ivsalloc="0"
731else
732 enable_ivsalloc="1"
733fi
734],
735[enable_ivsalloc="0"]
736)
737if test "x$enable_ivsalloc" = "x1" ; then
738 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
739fi
740
741dnl Only optimize if not debugging.
742if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
743 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
744 optimize="no"
1a4d82fc 745 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
970d7e83
LB
746 if test "x${optimize}" = "xyes" ; then
747 if test "x$GCC" = "xyes" ; then
748 JE_CFLAGS_APPEND([-O3])
749 JE_CFLAGS_APPEND([-funroll-loops])
750 elif test "x$je_cv_msvc" = "xyes" ; then
751 JE_CFLAGS_APPEND([-O2])
752 else
753 JE_CFLAGS_APPEND([-O])
754 fi
755 fi
756fi
757
758dnl Enable statistics calculation by default.
759AC_ARG_ENABLE([stats],
760 [AS_HELP_STRING([--disable-stats],
761 [Disable statistics calculation/reporting])],
762[if test "x$enable_stats" = "xno" ; then
763 enable_stats="0"
764else
765 enable_stats="1"
766fi
767],
768[enable_stats="1"]
769)
770if test "x$enable_stats" = "x1" ; then
771 AC_DEFINE([JEMALLOC_STATS], [ ])
772fi
773AC_SUBST([enable_stats])
774
775dnl Do not enable profiling by default.
776AC_ARG_ENABLE([prof],
777 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
778[if test "x$enable_prof" = "xno" ; then
779 enable_prof="0"
780else
781 enable_prof="1"
782fi
783],
784[enable_prof="0"]
785)
786if test "x$enable_prof" = "x1" ; then
787 backtrace_method=""
788else
789 backtrace_method="N/A"
790fi
791
792AC_ARG_ENABLE([prof-libunwind],
793 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
794[if test "x$enable_prof_libunwind" = "xno" ; then
795 enable_prof_libunwind="0"
796else
797 enable_prof_libunwind="1"
798fi
799],
800[enable_prof_libunwind="0"]
801)
802AC_ARG_WITH([static_libunwind],
803 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
804 [Path to static libunwind library; use rather than dynamically linking])],
805if test "x$with_static_libunwind" = "xno" ; then
806 LUNWIND="-lunwind"
807else
808 if test ! -f "$with_static_libunwind" ; then
809 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
810 fi
811 LUNWIND="$with_static_libunwind"
812fi,
813 LUNWIND="-lunwind"
814)
815if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
816 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
817 if test "x$LUNWIND" = "x-lunwind" ; then
1a4d82fc 818 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
970d7e83
LB
819 [enable_prof_libunwind="0"])
820 else
821 LIBS="$LIBS $LUNWIND"
822 fi
823 if test "x${enable_prof_libunwind}" = "x1" ; then
824 backtrace_method="libunwind"
825 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
826 fi
827fi
828
829AC_ARG_ENABLE([prof-libgcc],
830 [AS_HELP_STRING([--disable-prof-libgcc],
831 [Do not use libgcc for backtracing])],
832[if test "x$enable_prof_libgcc" = "xno" ; then
833 enable_prof_libgcc="0"
834else
835 enable_prof_libgcc="1"
836fi
837],
838[enable_prof_libgcc="1"]
839)
840if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
841 -a "x$GCC" = "xyes" ; then
842 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
843 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
970d7e83
LB
844 if test "x${enable_prof_libgcc}" = "x1" ; then
845 backtrace_method="libgcc"
846 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
847 fi
848else
849 enable_prof_libgcc="0"
850fi
851
852AC_ARG_ENABLE([prof-gcc],
853 [AS_HELP_STRING([--disable-prof-gcc],
854 [Do not use gcc intrinsics for backtracing])],
855[if test "x$enable_prof_gcc" = "xno" ; then
856 enable_prof_gcc="0"
857else
858 enable_prof_gcc="1"
859fi
860],
861[enable_prof_gcc="1"]
862)
863if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
864 -a "x$GCC" = "xyes" ; then
1a4d82fc 865 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
970d7e83
LB
866 backtrace_method="gcc intrinsics"
867 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
868else
869 enable_prof_gcc="0"
870fi
871
872if test "x$backtrace_method" = "x" ; then
873 backtrace_method="none (disabling profiling)"
874 enable_prof="0"
875fi
876AC_MSG_CHECKING([configured backtracing method])
877AC_MSG_RESULT([$backtrace_method])
878if test "x$enable_prof" = "x1" ; then
1a4d82fc
JJ
879 if test "x$abi" != "xpecoff"; then
880 dnl Heap profiling uses the log(3) function.
881 LIBS="$LIBS -lm"
970d7e83 882 fi
1a4d82fc 883
970d7e83
LB
884 AC_DEFINE([JEMALLOC_PROF], [ ])
885fi
886AC_SUBST([enable_prof])
887
888dnl Enable thread-specific caching by default.
889AC_ARG_ENABLE([tcache],
890 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
891[if test "x$enable_tcache" = "xno" ; then
892 enable_tcache="0"
893else
894 enable_tcache="1"
895fi
896],
897[enable_tcache="1"]
898)
899if test "x$enable_tcache" = "x1" ; then
900 AC_DEFINE([JEMALLOC_TCACHE], [ ])
901fi
902AC_SUBST([enable_tcache])
903
54a0048b
SL
904dnl Indicate whether adjacent virtual memory mappings automatically coalesce
905dnl (and fragment on demand).
906if test "x${maps_coalesce}" = "x1" ; then
907 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
908fi
909
970d7e83
LB
910dnl Enable VM deallocation via munmap() by default.
911AC_ARG_ENABLE([munmap],
912 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
913[if test "x$enable_munmap" = "xno" ; then
914 enable_munmap="0"
915else
916 enable_munmap="1"
917fi
918],
919[enable_munmap="${default_munmap}"]
920)
921if test "x$enable_munmap" = "x1" ; then
922 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
923fi
924AC_SUBST([enable_munmap])
925
1a4d82fc
JJ
926dnl Enable allocation from DSS if supported by the OS.
927have_dss="1"
970d7e83
LB
928dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
929AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
930if test "x$have_sbrk" = "x1" ; then
1a4d82fc
JJ
931 if test "x$sbrk_deprecated" = "x1" ; then
932 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
933 have_dss="0"
934 fi
970d7e83 935else
1a4d82fc 936 have_dss="0"
970d7e83
LB
937fi
938
1a4d82fc 939if test "x$have_dss" = "x1" ; then
970d7e83
LB
940 AC_DEFINE([JEMALLOC_DSS], [ ])
941fi
970d7e83
LB
942
943dnl Support the junk/zero filling option by default.
944AC_ARG_ENABLE([fill],
945 [AS_HELP_STRING([--disable-fill],
946 [Disable support for junk/zero filling, quarantine, and redzones])],
947[if test "x$enable_fill" = "xno" ; then
948 enable_fill="0"
949else
950 enable_fill="1"
951fi
952],
953[enable_fill="1"]
954)
955if test "x$enable_fill" = "x1" ; then
956 AC_DEFINE([JEMALLOC_FILL], [ ])
957fi
958AC_SUBST([enable_fill])
959
960dnl Disable utrace(2)-based tracing by default.
961AC_ARG_ENABLE([utrace],
962 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
963[if test "x$enable_utrace" = "xno" ; then
964 enable_utrace="0"
965else
966 enable_utrace="1"
967fi
968],
969[enable_utrace="0"]
970)
971JE_COMPILABLE([utrace(2)], [
972#include <sys/types.h>
973#include <sys/param.h>
974#include <sys/time.h>
975#include <sys/uio.h>
976#include <sys/ktrace.h>
977], [
978 utrace((void *)0, 0);
979], [je_cv_utrace])
980if test "x${je_cv_utrace}" = "xno" ; then
981 enable_utrace="0"
982fi
983if test "x$enable_utrace" = "x1" ; then
984 AC_DEFINE([JEMALLOC_UTRACE], [ ])
985fi
986AC_SUBST([enable_utrace])
987
988dnl Support Valgrind by default.
989AC_ARG_ENABLE([valgrind],
990 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
991[if test "x$enable_valgrind" = "xno" ; then
992 enable_valgrind="0"
993else
994 enable_valgrind="1"
995fi
996],
997[enable_valgrind="1"]
998)
999if test "x$enable_valgrind" = "x1" ; then
1000 JE_COMPILABLE([valgrind], [
1001#include <valgrind/valgrind.h>
1002#include <valgrind/memcheck.h>
1003
1004#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
1005# error "Incompatible Valgrind version"
1006#endif
1007], [], [je_cv_valgrind])
1008 if test "x${je_cv_valgrind}" = "xno" ; then
1009 enable_valgrind="0"
1010 fi
1011 if test "x$enable_valgrind" = "x1" ; then
1012 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1013 fi
1014fi
1015AC_SUBST([enable_valgrind])
1016
1017dnl Do not support the xmalloc option by default.
1018AC_ARG_ENABLE([xmalloc],
1019 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1020[if test "x$enable_xmalloc" = "xno" ; then
1021 enable_xmalloc="0"
1022else
1023 enable_xmalloc="1"
1024fi
1025],
1026[enable_xmalloc="0"]
1027)
1028if test "x$enable_xmalloc" = "x1" ; then
1029 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1030fi
1031AC_SUBST([enable_xmalloc])
1032
54a0048b
SL
1033dnl Support cache-oblivious allocation alignment by default.
1034AC_ARG_ENABLE([cache-oblivious],
1035 [AS_HELP_STRING([--disable-cache-oblivious],
1036 [Disable support for cache-oblivious allocation alignment])],
1037[if test "x$enable_cache_oblivious" = "xno" ; then
1038 enable_cache_oblivious="0"
1039else
1040 enable_cache_oblivious="1"
1041fi
1042],
1043[enable_cache_oblivious="1"]
1044)
1045if test "x$enable_cache_oblivious" = "x1" ; then
1046 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1047fi
1048AC_SUBST([enable_cache_oblivious])
1049
1a4d82fc
JJ
1050dnl ============================================================================
1051dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1052dnl One of those two functions should (theoretically) exist on all platforms
1053dnl that jemalloc currently has a chance of functioning on without modification.
54a0048b 1054dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
1a4d82fc
JJ
1055dnl ffsl() or __builtin_ffsl() are defined, respectively.
1056JE_COMPILABLE([a program using __builtin_ffsl], [
1057#include <stdio.h>
1058#include <strings.h>
1059#include <string.h>
1060], [
1061 {
1062 int rv = __builtin_ffsl(0x08);
1063 printf("%d\n", rv);
1064 }
1065], [je_cv_gcc_builtin_ffsl])
1066if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
54a0048b 1067 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
1a4d82fc
JJ
1068 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1069 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1070else
1071 JE_COMPILABLE([a program using ffsl], [
1072 #include <stdio.h>
1073 #include <strings.h>
1074 #include <string.h>
1075 ], [
1076 {
1077 int rv = ffsl(0x08);
1078 printf("%d\n", rv);
1079 }
1080 ], [je_cv_function_ffsl])
1081 if test "x${je_cv_function_ffsl}" = "xyes" ; then
54a0048b 1082 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
1a4d82fc
JJ
1083 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1084 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1085 else
1086 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1087 fi
1088fi
1089
54a0048b
SL
1090AC_ARG_WITH([lg_tiny_min],
1091 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1092 [Base 2 log of minimum tiny size class to support])],
1093 [LG_TINY_MIN="$with_lg_tiny_min"],
1094 [LG_TINY_MIN="3"])
1095AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1096
1097AC_ARG_WITH([lg_quantum],
1098 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1099 [Base 2 log of minimum allocation alignment])],
1100 [LG_QUANTA="$with_lg_quantum"],
1101 [LG_QUANTA="3 4"])
1102if test "x$with_lg_quantum" != "x" ; then
1103 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1104fi
1105
1106AC_ARG_WITH([lg_page],
1107 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1108 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
1109if test "x$LG_PAGE" = "xdetect"; then
1110 AC_CACHE_CHECK([LG_PAGE],
1111 [je_cv_lg_page],
970d7e83
LB
1112 AC_RUN_IFELSE([AC_LANG_PROGRAM(
1113[[
1114#include <strings.h>
1115#ifdef _WIN32
1116#include <windows.h>
1117#else
1118#include <unistd.h>
1119#endif
1120#include <stdio.h>
1121]],
1122[[
1123 int result;
1124 FILE *f;
1125
1126#ifdef _WIN32
1127 SYSTEM_INFO si;
1128 GetSystemInfo(&si);
1129 result = si.dwPageSize;
1130#else
1131 result = sysconf(_SC_PAGESIZE);
1132#endif
1133 if (result == -1) {
1134 return 1;
1135 }
1a4d82fc 1136 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
970d7e83
LB
1137
1138 f = fopen("conftest.out", "w");
1139 if (f == NULL) {
1140 return 1;
1141 }
54a0048b 1142 fprintf(f, "%d", result);
970d7e83
LB
1143 fclose(f);
1144
1145 return 0;
1146]])],
54a0048b
SL
1147 [je_cv_lg_page=`cat conftest.out`],
1148 [je_cv_lg_page=undefined],
1149 [je_cv_lg_page=12]))
1150fi
1151if test "x${je_cv_lg_page}" != "x" ; then
1152 LG_PAGE="${je_cv_lg_page}"
1153fi
1154if test "x${LG_PAGE}" != "xundefined" ; then
1155 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
970d7e83 1156else
54a0048b 1157 AC_MSG_ERROR([cannot determine value for LG_PAGE])
970d7e83
LB
1158fi
1159
54a0048b
SL
1160AC_ARG_WITH([lg_page_sizes],
1161 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1162 [Base 2 logs of system page sizes to support])],
1163 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1164
1165AC_ARG_WITH([lg_size_class_group],
1166 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1167 [Base 2 log of size classes per doubling])],
1168 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1169 [LG_SIZE_CLASS_GROUP="2"])
1170
970d7e83
LB
1171dnl ============================================================================
1172dnl jemalloc configuration.
1173dnl
1174
1a4d82fc 1175dnl Set VERSION if source directory is inside a git repository.
54a0048b 1176if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
1a4d82fc
JJ
1177 dnl Pattern globs aren't powerful enough to match both single- and
1178 dnl double-digit version numbers, so iterate over patterns to support up to
1179 dnl version 99.99.99 without any accidental matches.
54a0048b 1180 rm -f "${objroot}VERSION"
1a4d82fc
JJ
1181 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1182 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1183 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1184 '[0-9][0-9].[0-9][0-9].[0-9]' \
1185 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
54a0048b
SL
1186 if test ! -e "${objroot}VERSION" ; then
1187 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
1a4d82fc 1188 if test $? -eq 0 ; then
54a0048b 1189 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
1a4d82fc
JJ
1190 break
1191 fi
1192 fi
1193 done
1194fi
54a0048b
SL
1195rm -f "${objroot}VERSION.tmp"
1196if test ! -e "${objroot}VERSION" ; then
1197 if test ! -e "${srcroot}VERSION" ; then
1198 AC_MSG_RESULT(
1199 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1200 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1201 else
1202 cp ${srcroot}VERSION ${objroot}VERSION
1203 fi
970d7e83 1204fi
54a0048b 1205jemalloc_version=`cat "${objroot}VERSION"`
970d7e83
LB
1206jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1207jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1208jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1209jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1210jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
1211AC_SUBST([jemalloc_version])
1212AC_SUBST([jemalloc_version_major])
1213AC_SUBST([jemalloc_version_minor])
1214AC_SUBST([jemalloc_version_bugfix])
1215AC_SUBST([jemalloc_version_nrev])
1216AC_SUBST([jemalloc_version_gid])
1217
1218dnl ============================================================================
1219dnl Configure pthreads.
1220
1221if test "x$abi" != "xpecoff" ; then
1222 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1223 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1224 dnl first, but try libc too before failing.
1225 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1226 [AC_SEARCH_LIBS([pthread_create], , ,
1227 AC_MSG_ERROR([libpthread is missing]))])
1228fi
1229
1230CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1231
54a0048b
SL
1232dnl Check whether clock_gettime(2) is in libc or librt. This function is only
1233dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
1234SAVED_LIBS="${LIBS}"
1235LIBS=
1236AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
1237AC_SUBST([TESTLIBS])
1238LIBS="${SAVED_LIBS}"
1239
1240dnl Check if the GNU-specific secure_getenv function exists.
1241AC_CHECK_FUNC([secure_getenv],
1242 [have_secure_getenv="1"],
1243 [have_secure_getenv="0"]
1244 )
1245if test "x$have_secure_getenv" = "x1" ; then
1246 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1247fi
1248
1249dnl Check if the Solaris/BSD issetugid function exists.
1250AC_CHECK_FUNC([issetugid],
1251 [have_issetugid="1"],
1252 [have_issetugid="0"]
1253 )
1254if test "x$have_issetugid" = "x1" ; then
1255 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1256fi
1257
970d7e83
LB
1258dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1259dnl it rather than pthreads TSD cleanup functions to support cleanup during
1260dnl thread exit, in order to avoid pthreads library recursion during
1261dnl bootstrapping.
1262AC_CHECK_FUNC([_malloc_thread_cleanup],
1263 [have__malloc_thread_cleanup="1"],
1264 [have__malloc_thread_cleanup="0"]
1265 )
1266if test "x$have__malloc_thread_cleanup" = "x1" ; then
1267 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1268 force_tls="1"
1269fi
1270
1271dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1272dnl so, mutex initialization causes allocation, and we need to implement this
1273dnl callback function in order to prevent recursive allocation.
1274AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1275 [have__pthread_mutex_init_calloc_cb="1"],
1276 [have__pthread_mutex_init_calloc_cb="0"]
1277 )
1278if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1279 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1280fi
1281
1282dnl Disable lazy locking by default.
1283AC_ARG_ENABLE([lazy_lock],
1284 [AS_HELP_STRING([--enable-lazy-lock],
1285 [Enable lazy locking (only lock when multi-threaded)])],
1286[if test "x$enable_lazy_lock" = "xno" ; then
1287 enable_lazy_lock="0"
1288else
1289 enable_lazy_lock="1"
1290fi
1291],
54a0048b 1292[enable_lazy_lock=""]
970d7e83 1293)
54a0048b 1294if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
970d7e83
LB
1295 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1296 enable_lazy_lock="1"
1297fi
1298if test "x$enable_lazy_lock" = "x1" ; then
1299 if test "x$abi" != "xpecoff" ; then
1300 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1301 AC_CHECK_FUNC([dlsym], [],
1302 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1303 [AC_MSG_ERROR([libdl is missing])])
1304 ])
1305 fi
1306 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
54a0048b
SL
1307else
1308 enable_lazy_lock="0"
970d7e83
LB
1309fi
1310AC_SUBST([enable_lazy_lock])
1311
1312AC_ARG_ENABLE([tls],
1313 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1314if test "x$enable_tls" = "xno" ; then
1315 enable_tls="0"
1316else
1317 enable_tls="1"
1318fi
1319,
54a0048b 1320enable_tls=""
970d7e83 1321)
54a0048b
SL
1322if test "x${enable_tls}" = "x" ; then
1323 if test "x${force_tls}" = "x1" ; then
1324 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1325 enable_tls="1"
1326 elif test "x${force_tls}" = "x0" ; then
1327 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1328 enable_tls="0"
1329 else
1330 enable_tls="1"
1331 fi
970d7e83
LB
1332fi
1333if test "x${enable_tls}" = "x1" ; then
1334AC_MSG_CHECKING([for TLS])
1335AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1336[[
1337 __thread int x;
1338]], [[
1339 x = 42;
1340
1341 return 0;
1342]])],
1343 AC_MSG_RESULT([yes]),
1344 AC_MSG_RESULT([no])
1345 enable_tls="0")
54a0048b
SL
1346else
1347 enable_tls="0"
970d7e83
LB
1348fi
1349AC_SUBST([enable_tls])
1350if test "x${enable_tls}" = "x1" ; then
54a0048b
SL
1351 if test "x${force_tls}" = "x0" ; then
1352 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1353 fi
970d7e83
LB
1354 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1355elif test "x${force_tls}" = "x1" ; then
54a0048b
SL
1356 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
1357fi
1358
1359dnl ============================================================================
1360dnl Check for C11 atomics.
1361
1362JE_COMPILABLE([C11 atomics], [
1363#include <stdint.h>
1364#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1365#include <stdatomic.h>
1366#else
1367#error Atomics not available
1368#endif
1369], [
1370 uint64_t *p = (uint64_t *)0;
1371 uint64_t x = 1;
1372 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1373 uint64_t r = atomic_fetch_add(a, x) + x;
1374 return (r == 0);
1375], [je_cv_c11atomics])
1376if test "x${je_cv_c11atomics}" = "xyes" ; then
1377 AC_DEFINE([JEMALLOC_C11ATOMICS])
970d7e83
LB
1378fi
1379
970d7e83
LB
1380dnl ============================================================================
1381dnl Check for atomic(9) operations as provided on FreeBSD.
1382
1383JE_COMPILABLE([atomic(9)], [
1384#include <sys/types.h>
1385#include <machine/atomic.h>
1386#include <inttypes.h>
1387], [
1388 {
1389 uint32_t x32 = 0;
1390 volatile uint32_t *x32p = &x32;
1391 atomic_fetchadd_32(x32p, 1);
1392 }
1393 {
1394 unsigned long xlong = 0;
1395 volatile unsigned long *xlongp = &xlong;
1396 atomic_fetchadd_long(xlongp, 1);
1397 }
1398], [je_cv_atomic9])
1399if test "x${je_cv_atomic9}" = "xyes" ; then
1400 AC_DEFINE([JEMALLOC_ATOMIC9])
1401fi
1402
1403dnl ============================================================================
1404dnl Check for atomic(3) operations as provided on Darwin.
1405
1406JE_COMPILABLE([Darwin OSAtomic*()], [
1407#include <libkern/OSAtomic.h>
1408#include <inttypes.h>
1409], [
1410 {
1411 int32_t x32 = 0;
1412 volatile int32_t *x32p = &x32;
1413 OSAtomicAdd32(1, x32p);
1414 }
1415 {
1416 int64_t x64 = 0;
1417 volatile int64_t *x64p = &x64;
1418 OSAtomicAdd64(1, x64p);
1419 }
1420], [je_cv_osatomic])
1421if test "x${je_cv_osatomic}" = "xyes" ; then
1422 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1423fi
1424
1a4d82fc
JJ
1425dnl ============================================================================
1426dnl Check for madvise(2).
1427
1428JE_COMPILABLE([madvise(2)], [
1429#include <sys/mman.h>
1430], [
1431 {
1432 madvise((void *)0, 0, 0);
1433 }
1434], [je_cv_madvise])
1435if test "x${je_cv_madvise}" = "xyes" ; then
1436 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1437fi
1438
970d7e83
LB
1439dnl ============================================================================
1440dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1441dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1442
1443AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1444 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1445 [je_cv_sync_compare_and_swap_$2],
1446 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1447 #include <stdint.h>
1448 ],
1449 [
1450 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1451 {
1452 uint$1_t x$1 = 0;
1453 __sync_add_and_fetch(&x$1, 42);
1454 __sync_sub_and_fetch(&x$1, 1);
1455 }
1456 #else
1457 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1458 #endif
1459 ])],
1460 [je_cv_sync_compare_and_swap_$2=yes],
1461 [je_cv_sync_compare_and_swap_$2=no])])
1462
1463 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1464 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1465 fi
1466])
1467
1468if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
1469 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1470 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1471fi
1472
1a4d82fc
JJ
1473dnl ============================================================================
1474dnl Check for __builtin_clz() and __builtin_clzl().
1475
1476AC_CACHE_CHECK([for __builtin_clz],
1477 [je_cv_builtin_clz],
1478 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1479 [
1480 {
1481 unsigned x = 0;
1482 int y = __builtin_clz(x);
1483 }
1484 {
1485 unsigned long x = 0;
1486 int y = __builtin_clzl(x);
1487 }
1488 ])],
1489 [je_cv_builtin_clz=yes],
1490 [je_cv_builtin_clz=no])])
1491
1492if test "x${je_cv_builtin_clz}" = "xyes" ; then
1493 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1494fi
1495
970d7e83
LB
1496dnl ============================================================================
1497dnl Check for spinlock(3) operations as provided on Darwin.
1498
1499JE_COMPILABLE([Darwin OSSpin*()], [
1500#include <libkern/OSAtomic.h>
1501#include <inttypes.h>
1502], [
1503 OSSpinLock lock = 0;
1504 OSSpinLockLock(&lock);
1505 OSSpinLockUnlock(&lock);
1506], [je_cv_osspin])
1507if test "x${je_cv_osspin}" = "xyes" ; then
1508 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
1509fi
1510
1511dnl ============================================================================
1512dnl Darwin-related configuration.
1513
1514AC_ARG_ENABLE([zone-allocator],
1515 [AS_HELP_STRING([--disable-zone-allocator],
1516 [Disable zone allocator for Darwin])],
1517[if test "x$enable_zone_allocator" = "xno" ; then
1518 enable_zone_allocator="0"
1519else
1520 enable_zone_allocator="1"
1521fi
1522],
1523[if test "x${abi}" = "xmacho"; then
1524 enable_zone_allocator="1"
1525fi
1526]
1527)
1528AC_SUBST([enable_zone_allocator])
1529
1530if test "x${enable_zone_allocator}" = "x1" ; then
1531 if test "x${abi}" != "xmacho"; then
1532 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1533 fi
970d7e83
LB
1534 AC_DEFINE([JEMALLOC_ZONE], [ ])
1535
1536 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1537 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1538 dnl 10.6, which is the only source-level indication of the change.
1539 AC_MSG_CHECKING([malloc zone version])
1540 AC_DEFUN([JE_ZONE_PROGRAM],
1541 [AC_LANG_PROGRAM(
1542 [#include <malloc/malloc.h>],
54a0048b 1543 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
970d7e83
LB
1544 )])
1545
1546 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1547 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1548 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1549 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1550 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1551 )])],[
1552 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1553 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1554 )])])])])
1555 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1556 AC_MSG_RESULT([unsupported])
1557 AC_MSG_ERROR([Unsupported malloc zone version])
1558 fi
1559 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1560 JEMALLOC_ZONE_VERSION=8
1561 AC_MSG_RESULT([> 8])
1562 else
1563 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1564 fi
1565 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
1566fi
1567
1a4d82fc
JJ
1568dnl ============================================================================
1569dnl Check for glibc malloc hooks
1570
1571JE_COMPILABLE([glibc malloc hook], [
1572#include <stddef.h>
1573
1574extern void (* __free_hook)(void *ptr);
1575extern void *(* __malloc_hook)(size_t size);
1576extern void *(* __realloc_hook)(void *ptr, size_t size);
1577], [
1578 void *ptr = 0L;
1579 if (__malloc_hook) ptr = __malloc_hook(1);
1580 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1581 if (__free_hook && ptr) __free_hook(ptr);
1582], [je_cv_glibc_malloc_hook])
1583if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1584 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1585fi
1586
1587JE_COMPILABLE([glibc memalign hook], [
1588#include <stddef.h>
1589
1590extern void *(* __memalign_hook)(size_t alignment, size_t size);
1591], [
1592 void *ptr = 0L;
1593 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1594], [je_cv_glibc_memalign_hook])
1595if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1596 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1597fi
1598
1599JE_COMPILABLE([pthreads adaptive mutexes], [
1600#include <pthread.h>
1601], [
1602 pthread_mutexattr_t attr;
1603 pthread_mutexattr_init(&attr);
1604 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1605 pthread_mutexattr_destroy(&attr);
1606], [je_cv_pthread_mutex_adaptive_np])
1607if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1608 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1609fi
1610
970d7e83
LB
1611dnl ============================================================================
1612dnl Check for typedefs, structures, and compiler characteristics.
1613AC_HEADER_STDBOOL
1614
1a4d82fc
JJ
1615dnl ============================================================================
1616dnl Define commands that generate output files.
1617
1618AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1619 mkdir -p "${objroot}include/jemalloc/internal"
1620 "${srcdir}/include/jemalloc/internal/private_namespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_namespace.h"
1621], [
1622 srcdir="${srcdir}"
1623 objroot="${objroot}"
1624])
1625AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1626 mkdir -p "${objroot}include/jemalloc/internal"
1627 "${srcdir}/include/jemalloc/internal/private_unnamespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_unnamespace.h"
1628], [
1629 srcdir="${srcdir}"
1630 objroot="${objroot}"
1631])
1632AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1633 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1634 mkdir -p "${objroot}include/jemalloc/internal"
1635 cp /dev/null "${f}"
1636 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1637 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1638 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1639 echo "${n}:${m}" >> "${f}"
1640 dnl Remove name from public_syms so that it isn't redefined later.
1641 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1642 done
1643 for sym in ${public_syms} ; do
1644 n="${sym}"
1645 m="${JEMALLOC_PREFIX}${sym}"
1646 echo "${n}:${m}" >> "${f}"
1647 done
1648], [
1649 srcdir="${srcdir}"
1650 objroot="${objroot}"
1651 mangling_map="${mangling_map}"
1652 public_syms="${public_syms}"
1653 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
1654])
1655AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1656 mkdir -p "${objroot}include/jemalloc/internal"
1657 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1658], [
1659 srcdir="${srcdir}"
1660 objroot="${objroot}"
1661])
1662AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1663 mkdir -p "${objroot}include/jemalloc/internal"
1664 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1665], [
1666 srcdir="${srcdir}"
1667 objroot="${objroot}"
1668])
970d7e83 1669AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1a4d82fc 1670 mkdir -p "${objroot}include/jemalloc/internal"
54a0048b 1671 "${SHELL}" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" ${LG_TINY_MIN} "${LG_PAGE_SIZES}" ${LG_SIZE_CLASS_GROUP} > "${objroot}include/jemalloc/internal/size_classes.h"
1a4d82fc 1672], [
54a0048b 1673 SHELL="${SHELL}"
1a4d82fc
JJ
1674 srcdir="${srcdir}"
1675 objroot="${objroot}"
54a0048b
SL
1676 LG_QUANTA="${LG_QUANTA}"
1677 LG_TINY_MIN=${LG_TINY_MIN}
1678 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
1679 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
1a4d82fc
JJ
1680])
1681AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1682 mkdir -p "${objroot}include/jemalloc"
1683 cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
1684], [
1685 srcdir="${srcdir}"
1686 objroot="${objroot}"
1687])
1688AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1689 mkdir -p "${objroot}include/jemalloc"
1690 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1691], [
1692 srcdir="${srcdir}"
1693 objroot="${objroot}"
1694])
1695AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1696 mkdir -p "${objroot}include/jemalloc"
1697 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1698], [
1699 srcdir="${srcdir}"
1700 objroot="${objroot}"
1701])
1702AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1703 mkdir -p "${objroot}include/jemalloc"
1704 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1705], [
1706 srcdir="${srcdir}"
1707 objroot="${objroot}"
1708])
1709AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1710 mkdir -p "${objroot}include/jemalloc"
1711 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
1712], [
1713 srcdir="${srcdir}"
1714 objroot="${objroot}"
1715 install_suffix="${install_suffix}"
970d7e83
LB
1716])
1717
1718dnl Process .in files.
1719AC_SUBST([cfghdrs_in])
1720AC_SUBST([cfghdrs_out])
1721AC_CONFIG_HEADERS([$cfghdrs_tup])
1722
1723dnl ============================================================================
1724dnl Generate outputs.
1a4d82fc 1725
54a0048b 1726AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
970d7e83
LB
1727AC_SUBST([cfgoutputs_in])
1728AC_SUBST([cfgoutputs_out])
1729AC_OUTPUT
1730
1731dnl ============================================================================
1732dnl Print out the results of configuration.
1733AC_MSG_RESULT([===============================================================================])
1734AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1735AC_MSG_RESULT([library revision : ${rev}])
1736AC_MSG_RESULT([])
54a0048b 1737AC_MSG_RESULT([CONFIG : ${CONFIG}])
970d7e83 1738AC_MSG_RESULT([CC : ${CC}])
7453a54e 1739AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
54a0048b 1740AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
970d7e83 1741AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1a4d82fc 1742AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
970d7e83 1743AC_MSG_RESULT([LIBS : ${LIBS}])
54a0048b 1744AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
970d7e83
LB
1745AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1746AC_MSG_RESULT([])
1747AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1748AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1749AC_MSG_RESULT([])
1750AC_MSG_RESULT([PREFIX : ${PREFIX}])
1751AC_MSG_RESULT([BINDIR : ${BINDIR}])
54a0048b 1752AC_MSG_RESULT([DATADIR : ${DATADIR}])
970d7e83
LB
1753AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1754AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
970d7e83
LB
1755AC_MSG_RESULT([MANDIR : ${MANDIR}])
1756AC_MSG_RESULT([])
1757AC_MSG_RESULT([srcroot : ${srcroot}])
1758AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1759AC_MSG_RESULT([objroot : ${objroot}])
1760AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1761AC_MSG_RESULT([])
1762AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
1763AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1764AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
1765AC_MSG_RESULT([install_suffix : ${install_suffix}])
54a0048b 1766AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
970d7e83 1767AC_MSG_RESULT([autogen : ${enable_autogen}])
970d7e83
LB
1768AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
1769AC_MSG_RESULT([debug : ${enable_debug}])
1a4d82fc 1770AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
970d7e83
LB
1771AC_MSG_RESULT([stats : ${enable_stats}])
1772AC_MSG_RESULT([prof : ${enable_prof}])
1773AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
1774AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1775AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
1776AC_MSG_RESULT([tcache : ${enable_tcache}])
1777AC_MSG_RESULT([fill : ${enable_fill}])
1778AC_MSG_RESULT([utrace : ${enable_utrace}])
1779AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1780AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
970d7e83 1781AC_MSG_RESULT([munmap : ${enable_munmap}])
970d7e83
LB
1782AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
1783AC_MSG_RESULT([tls : ${enable_tls}])
54a0048b 1784AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
970d7e83 1785AC_MSG_RESULT([===============================================================================])