blob: 739cfa9aa254ecedd5359655ebeb7a86799012ce [file] [log] [blame]
Jason Evansb7924f52009-06-23 19:01:18 -07001dnl Process this file with autoconf to produce a configure script.
2AC_INIT([Makefile.in])
3
Jason Evansf3340ca2009-06-30 16:17:05 -07004dnl ============================================================================
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
Jason Evans6684cac2012-03-05 12:15:36 -080017AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evansf3340ca2009-06-30 16:17:05 -070018[[
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)
Jason Evans4c2faa82012-03-13 11:09:23 -070029dnl
Jason Evansf3e139a2012-03-19 09:54:20 -070030dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
Jason Evans4c2faa82012-03-13 11:09:23 -070031dnl cause failure.
Jason Evansf3340ca2009-06-30 16:17:05 -070032AC_DEFUN([JE_COMPILABLE],
33[
Jason Evans6684cac2012-03-05 12:15:36 -080034AC_CACHE_CHECK([whether $1 is compilable],
35 [$4],
Jason Evansf3e139a2012-03-19 09:54:20 -070036 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
37 [$3])],
38 [$4=yes],
39 [$4=no])])
Jason Evansf3340ca2009-06-30 16:17:05 -070040])
41
42dnl ============================================================================
43
Jason Evansf576c632011-11-01 22:27:41 -070044dnl Library revision.
45rev=1
46AC_SUBST([rev])
47
Jason Evansb7924f52009-06-23 19:01:18 -070048srcroot=$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
Jason Evansaee7fd22010-11-24 22:00:02 -080088dnl Support for building documentation.
89AC_PATH_PROG([XSLTPROC], [xsltproc], , [$PATH])
Jason Evans7091b412012-03-19 09:36:44 -070090if 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
Jason Evansaee7fd22010-11-24 22:00:02 -080098AC_ARG_WITH([xslroot],
Jason Evans7091b412012-03-19 09:36:44 -070099 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
Jason Evansaee7fd22010-11-24 22:00:02 -0800100if test "x$with_xslroot" = "xno" ; then
Jason Evans7091b412012-03-19 09:36:44 -0700101 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800102else
103 XSLROOT="${with_xslroot}"
Jason Evans7091b412012-03-19 09:36:44 -0700104fi
105],
106 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800107)
108AC_SUBST([XSLROOT])
109
Jason Evansf3340ca2009-06-30 16:17:05 -0700110dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
111dnl just prevent autoconf from molesting CFLAGS.
Jason Evansb7924f52009-06-23 19:01:18 -0700112CFLAGS=$CFLAGS
113AC_PROG_CC
114if test "x$CFLAGS" = "x" ; then
115 no_CFLAGS="yes"
Jason Evanscfeccd32010-03-03 15:48:20 -0800116 if test "x$GCC" = "xyes" ; then
117 JE_CFLAGS_APPEND([-std=gnu99])
118 JE_CFLAGS_APPEND([-Wall])
119 JE_CFLAGS_APPEND([-pipe])
120 JE_CFLAGS_APPEND([-g3])
121 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700122fi
123dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
124if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700125 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700126fi
127AC_PROG_CPP
128
Jason Evansb7924f52009-06-23 19:01:18 -0700129AC_CHECK_SIZEOF([void *])
130if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800131 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700132elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800133 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700134else
135 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
136fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800137AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
138
139AC_CHECK_SIZEOF([int])
140if test "x${ac_cv_sizeof_int}" = "x8" ; then
141 LG_SIZEOF_INT=3
142elif test "x${ac_cv_sizeof_int}" = "x4" ; then
143 LG_SIZEOF_INT=2
144else
145 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
146fi
147AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700148
Jason Evans84c8eef2011-03-16 10:30:13 -0700149AC_CHECK_SIZEOF([long])
150if test "x${ac_cv_sizeof_long}" = "x8" ; then
151 LG_SIZEOF_LONG=3
152elif test "x${ac_cv_sizeof_long}" = "x4" ; then
153 LG_SIZEOF_LONG=2
154else
155 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
156fi
157AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
158
Jason Evansd81e4bd2012-03-06 14:57:45 -0800159AC_CHECK_SIZEOF([intmax_t])
160if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
161 LG_SIZEOF_INTMAX_T=4
162elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
163 LG_SIZEOF_INTMAX_T=3
164elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
165 LG_SIZEOF_INTMAX_T=2
166else
167 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_long}])
168fi
169AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
170
Jason Evansb7924f52009-06-23 19:01:18 -0700171AC_CANONICAL_HOST
172dnl CPU-specific settings.
173CPU_SPINWAIT=""
174case "${host_cpu}" in
175 i[[345]]86)
176 ;;
177 i686)
Jason Evansf3340ca2009-06-30 16:17:05 -0700178 JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
Jason Evans6684cac2012-03-05 12:15:36 -0800179 [je_cv_asm])
180 if test "x${je_cv_asm}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700181 CPU_SPINWAIT='__asm__ volatile("pause")'
182 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700183 ;;
184 x86_64)
Jason Evansf3340ca2009-06-30 16:17:05 -0700185 JE_COMPILABLE([__asm__ syntax], [],
Jason Evans6684cac2012-03-05 12:15:36 -0800186 [[__asm__ volatile("pause"); return 0;]], [je_cv_asm])
187 if test "x${je_cv_asm}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700188 CPU_SPINWAIT='__asm__ volatile("pause")'
189 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700190 ;;
191 *)
192 ;;
193esac
194AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
195
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400196LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700197so="so"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400198
Jason Evans7372b152012-02-10 20:22:09 -0800199dnl Heap profiling uses the log(3) function.
200LIBS="$LIBS -lm"
201
Jason Evansb7924f52009-06-23 19:01:18 -0700202dnl Platform-specific settings. abi and RPATH can probably be determined
203dnl programmatically, but doing so is error-prone, which makes it generally
204dnl not worth the trouble.
205dnl
206dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
207dnl definitions need to be seen before any headers are included, which is a pain
208dnl to make happen otherwise.
209case "${host}" in
210 *-*-darwin*)
Jason Evans9022bf92012-03-23 16:14:08 -0700211 CFLAGS="$CFLAGS -fno-common"
Jason Evansb7924f52009-06-23 19:01:18 -0700212 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700213 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700214 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400215 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700216 so="dylib"
Jason Evansb80581d2012-03-23 16:17:43 -0700217 force_tls="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700218 ;;
219 *-*-freebsd*)
220 CFLAGS="$CFLAGS"
221 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700222 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700223 RPATH="-Wl,-rpath,"
Jason Evansfd4fcef2012-03-23 17:40:58 -0700224 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700225 ;;
226 *-*-linux*)
227 CFLAGS="$CFLAGS"
228 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
229 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700230 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700231 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700232 RPATH="-Wl,-rpath,"
233 ;;
234 *-*-netbsd*)
235 AC_MSG_CHECKING([ABI])
236 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
237[[#ifdef __ELF__
238/* ELF */
239#else
240#error aout
241#endif
242]])],
243 [CFLAGS="$CFLAGS"; abi="elf"],
244 [abi="aout"])
245 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700246 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700247 RPATH="-Wl,-rpath,"
248 ;;
249 *-*-solaris2*)
250 CFLAGS="$CFLAGS"
251 abi="elf"
252 RPATH="-Wl,-R,"
253 dnl Solaris needs this for sigwait().
254 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
255 LIBS="$LIBS -lposix4 -lsocket -lnsl"
256 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400257 *-ibm-aix*)
258 if "$LG_SIZEOF_PTR" = "8"; then
259 dnl 64bit AIX
260 LD_PRELOAD_VAR="LDR_PRELOAD64"
261 else
262 dnl 32bit AIX
263 LD_PRELOAD_VAR="LDR_PRELOAD"
264 fi
265 abi="xcoff"
266 RPATH="-Wl,-rpath,"
267 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700268 *)
269 AC_MSG_RESULT([Unsupported operating system: ${host}])
270 abi="elf"
271 RPATH="-Wl,-rpath,"
272 ;;
273esac
274AC_SUBST([abi])
275AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400276AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700277AC_SUBST([so])
Jason Evansb7924f52009-06-23 19:01:18 -0700278
Jason Evansfa5d2452011-03-15 10:25:59 -0700279JE_COMPILABLE([__attribute__ syntax],
280 [static __attribute__((unused)) void foo(void){}],
281 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800282 [je_cv_attribute])
283if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700284 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
285 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
286 JE_CFLAGS_APPEND([-fvisibility=hidden])
287 fi
288fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700289dnl Check for tls_model attribute support (clang 3.0 still lacks support).
290SAVED_CFLAGS="${CFLAGS}"
291JE_CFLAGS_APPEND([-Werror])
292JE_COMPILABLE([tls_model attribute], [],
293 [static __thread int
294 __attribute__((tls_model("initial-exec"))) foo;
295 foo = 0;],
296 [je_cv_tls_model])
297CFLAGS="${SAVED_CFLAGS}"
298if test "x${je_cv_tls_model}" = "xyes" ; then
299 AC_DEFINE([JEMALLOC_TLS_MODEL],
300 [__attribute__((tls_model("initial-exec")))])
301else
302 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
303fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700304
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800305JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
306#define _GNU_SOURCE
307#include <sys/mman.h>
308], [
309void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
Jason Evans6684cac2012-03-05 12:15:36 -0800310], [je_cv_mremap_fixed])
311if test "x${je_cv_mremap_fixed}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700312 AC_DEFINE([JEMALLOC_MREMAP_FIXED], [ ])
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800313fi
314
Jason Evansb7924f52009-06-23 19:01:18 -0700315dnl Support optional additions to rpath.
316AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800317 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700318if test "x$with_rpath" = "xno" ; then
319 RPATH_EXTRA=
320else
321 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
322fi,
323 RPATH_EXTRA=
324)
325AC_SUBST([RPATH_EXTRA])
326
327dnl Disable rules that do automatic regeneration of configure output by default.
328AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800329 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700330if test "x$enable_autogen" = "xno" ; then
331 enable_autogen="0"
332else
333 enable_autogen="1"
334fi
335,
336enable_autogen="0"
337)
338AC_SUBST([enable_autogen])
339
340AC_PROG_INSTALL
341AC_PROG_RANLIB
342AC_PATH_PROG([AR], [ar], , [$PATH])
343AC_PATH_PROG([LD], [ld], , [$PATH])
344AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
345
Jason Evans0a0bbf62012-03-13 12:55:21 -0700346public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib"
Jason Evans7e77eaf2012-03-02 17:47:37 -0800347
348dnl Check for allocator-related functions that should be wrapped.
349AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700350 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800351 public_syms="${public_syms} memalign"])
352AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700353 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800354 public_syms="${public_syms} valloc"])
355
356dnl Support the experimental API by default.
357AC_ARG_ENABLE([experimental],
358 [AS_HELP_STRING([--disable-experimental],
359 [Disable support for the experimental API])],
360[if test "x$enable_experimental" = "xno" ; then
361 enable_experimental="0"
362else
363 enable_experimental="1"
364fi
365],
366[enable_experimental="1"]
367)
368if test "x$enable_experimental" = "x1" ; then
369 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
370 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
371fi
372AC_SUBST([enable_experimental])
373
Jason Evans0a5489e2012-03-01 17:19:20 -0800374dnl Perform no name mangling by default.
375AC_ARG_WITH([mangling],
376 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
377 [mangling_map="$with_mangling"], [mangling_map=""])
378for nm in `echo ${mangling_map} |tr ',' ' '` ; do
Jason Evans08fc3b22012-03-12 15:07:53 -0700379 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
380 n="je_${k}"
Jason Evans0a5489e2012-03-01 17:19:20 -0800381 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
382 AC_DEFINE_UNQUOTED([${n}], [${m}])
Jason Evans08fc3b22012-03-12 15:07:53 -0700383 dnl Remove key from public_syms so that it isn't redefined later.
384 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
Jason Evans0a5489e2012-03-01 17:19:20 -0800385done
386
Jason Evans90895cf2009-12-29 00:09:15 -0800387dnl Do not prefix public APIs by default.
388AC_ARG_WITH([jemalloc_prefix],
389 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800390 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700391 [if test "x$abi" != "xmacho" ; then
392 JEMALLOC_PREFIX=""
393else
394 JEMALLOC_PREFIX="je_"
395fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800396)
397if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700398 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
399 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
400 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800401fi
Jason Evans0a5489e2012-03-01 17:19:20 -0800402dnl Generate macros to rename public symbols. All public symbols are prefixed
403dnl with je_ in the source code, so these macro definitions are needed even if
404dnl --with-jemalloc-prefix wasn't specified.
Jason Evans7e77eaf2012-03-02 17:47:37 -0800405for stem in ${public_syms}; do
Jason Evans0a5489e2012-03-01 17:19:20 -0800406 n="je_${stem}"
407 m="${JEMALLOC_PREFIX}${stem}"
408 AC_DEFINE_UNQUOTED([${n}], [${m}])
409done
Jason Evans90895cf2009-12-29 00:09:15 -0800410
Jason Evans746e77a2011-07-30 16:40:52 -0700411dnl Do not mangle library-private APIs by default.
412AC_ARG_WITH([private_namespace],
413 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
414 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
415 [JEMALLOC_PRIVATE_NAMESPACE=""]
416)
417AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
418if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
419 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])
420else
421 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])
422fi
423
Jason Evansb0fd5012010-01-17 01:49:20 -0800424dnl Do not add suffix to installed files by default.
425AC_ARG_WITH([install_suffix],
426 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
427 [INSTALL_SUFFIX="$with_install_suffix"],
428 [INSTALL_SUFFIX=]
429)
430install_suffix="$INSTALL_SUFFIX"
431AC_SUBST([install_suffix])
432
Jason Evansaee7fd22010-11-24 22:00:02 -0800433cfgoutputs_in="${srcroot}Makefile.in"
434cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
435cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
436cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700437cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
438cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700439cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800440
Jason Evansaee7fd22010-11-24 22:00:02 -0800441cfgoutputs_out="Makefile"
442cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
443cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
444cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
Jason Evans376b1522010-02-11 14:45:59 -0800445cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
446cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700447cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800448
Jason Evansaee7fd22010-11-24 22:00:02 -0800449cfgoutputs_tup="Makefile"
450cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
451cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
452cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
Jason Evans376b1522010-02-11 14:45:59 -0800453cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
454cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700455cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800456
Jason Evans0656ec02010-04-07 23:37:35 -0700457cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb1726102012-02-28 16:50:47 -0800458cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansb0fd5012010-01-17 01:49:20 -0800459
Jason Evans376b1522010-02-11 14:45:59 -0800460cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb1726102012-02-28 16:50:47 -0800461cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800462
Jason Evans376b1522010-02-11 14:45:59 -0800463cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800464
Jason Evans355b4382010-09-20 19:20:48 -0700465dnl Do not silence irrelevant compiler warnings by default, since enabling this
466dnl option incurs a performance penalty.
467AC_ARG_ENABLE([cc-silence],
468 [AS_HELP_STRING([--enable-cc-silence],
469 [Silence irrelevant compiler warnings])],
470[if test "x$enable_cc_silence" = "xno" ; then
471 enable_cc_silence="0"
472else
473 enable_cc_silence="1"
474fi
475],
476[enable_cc_silence="0"]
477)
478if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700479 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700480fi
481
Jason Evansb7924f52009-06-23 19:01:18 -0700482dnl Do not compile with debugging by default.
483AC_ARG_ENABLE([debug],
484 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
485[if test "x$enable_debug" = "xno" ; then
486 enable_debug="0"
487else
488 enable_debug="1"
489fi
490],
491[enable_debug="0"]
492)
493if test "x$enable_debug" = "x1" ; then
494 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700495 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700496fi
497AC_SUBST([enable_debug])
498
499dnl Only optimize if not debugging.
500if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
501 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700502 optimize="no"
503 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
504 if test "x${optimize}" = "xyes" ; then
505 if test "x$GCC" = "xyes" ; then
506 JE_CFLAGS_APPEND([-O3])
507 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700508 else
509 JE_CFLAGS_APPEND([-O])
510 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700511 fi
512fi
513
Jason Evansd073a322012-02-28 20:41:16 -0800514dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700515AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800516 [AS_HELP_STRING([--disable-stats],
517 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700518[if test "x$enable_stats" = "xno" ; then
519 enable_stats="0"
520else
521 enable_stats="1"
522fi
523],
Jason Evansd073a322012-02-28 20:41:16 -0800524[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700525)
526if test "x$enable_stats" = "x1" ; then
527 AC_DEFINE([JEMALLOC_STATS], [ ])
528fi
529AC_SUBST([enable_stats])
530
Jason Evans6109fe02010-02-10 10:37:56 -0800531dnl Do not enable profiling by default.
532AC_ARG_ENABLE([prof],
533 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
534[if test "x$enable_prof" = "xno" ; then
535 enable_prof="0"
536else
537 enable_prof="1"
538fi
539],
540[enable_prof="0"]
541)
Jason Evans77f350b2011-03-15 22:23:12 -0700542if test "x$enable_prof" = "x1" ; then
543 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800544else
Jason Evans77f350b2011-03-15 22:23:12 -0700545 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800546fi
Jason Evans77f350b2011-03-15 22:23:12 -0700547
Jason Evans6109fe02010-02-10 10:37:56 -0800548AC_ARG_ENABLE([prof-libunwind],
549 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
550[if test "x$enable_prof_libunwind" = "xno" ; then
551 enable_prof_libunwind="0"
552else
553 enable_prof_libunwind="1"
554fi
555],
556[enable_prof_libunwind="0"]
557)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800558AC_ARG_WITH([static_libunwind],
559 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
560 [Path to static libunwind library; use rather than dynamically linking])],
561if test "x$with_static_libunwind" = "xno" ; then
562 LUNWIND="-lunwind"
563else
564 if test ! -f "$with_static_libunwind" ; then
565 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
566 fi
567 LUNWIND="$with_static_libunwind"
568fi,
569 LUNWIND="-lunwind"
570)
Jason Evans77f350b2011-03-15 22:23:12 -0700571if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
572 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
573 if test "x$LUNWIND" = "x-lunwind" ; then
574 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
575 [enable_prof_libunwind="0"])
576 else
577 LIBS="$LIBS $LUNWIND"
578 fi
579 if test "x${enable_prof_libunwind}" = "x1" ; then
580 backtrace_method="libunwind"
581 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
582 fi
583fi
584
585AC_ARG_ENABLE([prof-libgcc],
586 [AS_HELP_STRING([--disable-prof-libgcc],
587 [Do not use libgcc for backtracing])],
588[if test "x$enable_prof_libgcc" = "xno" ; then
589 enable_prof_libgcc="0"
590else
591 enable_prof_libgcc="1"
592fi
593],
594[enable_prof_libgcc="1"]
595)
596if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
597 -a "x$GCC" = "xyes" ; then
598 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
599 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
600 dnl The following is conservative, in that it only has entries for CPUs on
601 dnl which jemalloc has been tested.
602 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
603 case "${host_cpu}" in
604 i[[3456]]86)
605 AC_MSG_RESULT([unreliable])
606 enable_prof_libgcc="0";
607 ;;
608 x86_64)
609 AC_MSG_RESULT([reliable])
610 ;;
611 *)
612 AC_MSG_RESULT([unreliable])
613 enable_prof_libgcc="0";
614 ;;
615 esac
616 if test "x${enable_prof_libgcc}" = "x1" ; then
617 backtrace_method="libgcc"
618 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
619 fi
620else
621 enable_prof_libgcc="0"
622fi
623
624AC_ARG_ENABLE([prof-gcc],
625 [AS_HELP_STRING([--disable-prof-gcc],
626 [Do not use gcc intrinsics for backtracing])],
627[if test "x$enable_prof_gcc" = "xno" ; then
628 enable_prof_gcc="0"
629else
630 enable_prof_gcc="1"
631fi
632],
633[enable_prof_gcc="1"]
634)
635if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
636 -a "x$GCC" = "xyes" ; then
637 backtrace_method="gcc intrinsics"
638 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
639else
640 enable_prof_gcc="0"
641fi
642
643if test "x$backtrace_method" = "x" ; then
644 backtrace_method="none (disabling profiling)"
645 enable_prof="0"
646fi
647AC_MSG_CHECKING([configured backtracing method])
648AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700649if test "x$enable_prof" = "x1" ; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700650 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700651fi
652AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700653
Jason Evans84cbbcb2009-12-29 00:09:15 -0800654dnl Enable thread-specific caching by default.
655AC_ARG_ENABLE([tcache],
656 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
657[if test "x$enable_tcache" = "xno" ; then
658 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700659else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800660 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700661fi
662],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800663[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700664)
Jason Evans2dbecf12010-09-05 10:35:13 -0700665if test "x$enable_tcache" = "x1" ; then
666 AC_DEFINE([JEMALLOC_TCACHE], [ ])
667fi
668AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700669
Jason Evansb7924f52009-06-23 19:01:18 -0700670dnl Do not enable allocation from DSS by default.
671AC_ARG_ENABLE([dss],
672 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
673[if test "x$enable_dss" = "xno" ; then
674 enable_dss="0"
675else
676 enable_dss="1"
677fi
678],
679[enable_dss="0"]
680)
Mike Hommey83c324a2012-04-12 10:13:03 +0200681dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
682AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
683if test "x$have_sbrk" = "x1" ; then
684 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
685else
686 enable_dss="0"
687fi
688
Jason Evansb7924f52009-06-23 19:01:18 -0700689if test "x$enable_dss" = "x1" ; then
690 AC_DEFINE([JEMALLOC_DSS], [ ])
691fi
692AC_SUBST([enable_dss])
693
Jason Evans777c1912012-02-28 20:49:22 -0800694dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700695AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700696 [AS_HELP_STRING([--disable-fill],
697 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700698[if test "x$enable_fill" = "xno" ; then
699 enable_fill="0"
700else
701 enable_fill="1"
702fi
703],
Jason Evans777c1912012-02-28 20:49:22 -0800704[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700705)
706if test "x$enable_fill" = "x1" ; then
707 AC_DEFINE([JEMALLOC_FILL], [ ])
708fi
709AC_SUBST([enable_fill])
710
Jason Evansb1476112012-04-05 13:36:17 -0700711dnl Disable utrace(2)-based tracing by default.
712AC_ARG_ENABLE([utrace],
713 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
714[if test "x$enable_utrace" = "xno" ; then
715 enable_utrace="0"
716else
717 enable_utrace="1"
718fi
719],
720[enable_utrace="0"]
721)
722JE_COMPILABLE([utrace(2)], [
723#include <sys/types.h>
724#include <sys/param.h>
725#include <sys/time.h>
726#include <sys/uio.h>
727#include <sys/ktrace.h>
728], [
729 utrace((void *)0, 0);
730], [je_cv_utrace])
731if test "x${je_cv_utrace}" = "xno" ; then
732 enable_utrace="0"
733fi
734if test "x$enable_utrace" = "x1" ; then
735 AC_DEFINE([JEMALLOC_UTRACE], [ ])
736fi
737AC_SUBST([enable_utrace])
738
Jason Evans122449b2012-04-06 00:35:09 -0700739dnl Support Valgrind by default.
740AC_ARG_ENABLE([valgrind],
741 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
742[if test "x$enable_valgrind" = "xno" ; then
743 enable_valgrind="0"
744else
745 enable_valgrind="1"
746fi
747],
748[enable_valgrind="1"]
749)
750if test "x$enable_valgrind" = "x1" ; then
751 JE_COMPILABLE([valgrind], [
752#include <valgrind/valgrind.h>
753#include <valgrind/memcheck.h>
754
755#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
756 && (__VALGRIND_MAJOR__ > 3 || (__VALGRIND_MAJOR__ == 3 && \
757 __VALGRIND_MINOR__ >= 6))
758#else
759# error "Incompatible Valgrind version"
760#endif
761], [], [je_cv_valgrind])
762 if test "x${je_cv_valgrind}" = "xno" ; then
763 enable_valgrind="0"
764 fi
765 if test "x$enable_valgrind" = "x1" ; then
766 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
767 fi
768fi
769AC_SUBST([enable_valgrind])
770
Jason Evansb7924f52009-06-23 19:01:18 -0700771dnl Do not support the xmalloc option by default.
772AC_ARG_ENABLE([xmalloc],
773 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
774[if test "x$enable_xmalloc" = "xno" ; then
775 enable_xmalloc="0"
776else
777 enable_xmalloc="1"
778fi
779],
780[enable_xmalloc="0"]
781)
782if test "x$enable_xmalloc" = "x1" ; then
783 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
784fi
785AC_SUBST([enable_xmalloc])
786
Jason Evans6684cac2012-03-05 12:15:36 -0800787AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
788 [je_cv_static_page_shift],
789 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansb7924f52009-06-23 19:01:18 -0700790[[#include <stdio.h>
791#include <unistd.h>
792#include <strings.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800793]],
794[[
Jason Evansb7924f52009-06-23 19:01:18 -0700795 long result;
796 FILE *f;
797
798 result = sysconf(_SC_PAGESIZE);
799 if (result == -1) {
800 return 1;
801 }
802 f = fopen("conftest.out", "w");
803 if (f == NULL) {
804 return 1;
805 }
806 fprintf(f, "%u\n", ffs((int)result) - 1);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700807 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700808
809 return 0;
810]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800811 [je_cv_static_page_shift=`cat conftest.out`],
812 [je_cv_static_page_shift=undefined]))
813
814if test "x$je_cv_static_page_shift" != "xundefined"; then
815 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
816else
817 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
818fi
Jason Evansb7924f52009-06-23 19:01:18 -0700819
820dnl ============================================================================
821dnl jemalloc configuration.
822dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800823
824dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700825if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700826 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800827fi
Jason Evansb7924f52009-06-23 19:01:18 -0700828jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800829jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
830jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
831jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
832jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
833jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700834AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800835AC_SUBST([jemalloc_version_major])
836AC_SUBST([jemalloc_version_minor])
837AC_SUBST([jemalloc_version_bugfix])
838AC_SUBST([jemalloc_version_nrev])
839AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700840
841dnl ============================================================================
842dnl Configure pthreads.
843
844AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
Jason Evans39006f92012-03-16 16:57:02 -0700845dnl Some systems may embed pthreads functionality in libc; check for libpthread
846dnl first, but try libc too before failing.
Jason Evansb7924f52009-06-23 19:01:18 -0700847AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
Jason Evans39006f92012-03-16 16:57:02 -0700848 [AC_SEARCH_LIBS([pthread_create], , ,
849 AC_MSG_ERROR([libpthread is missing]))])
Jason Evansb7924f52009-06-23 19:01:18 -0700850
851CPPFLAGS="$CPPFLAGS -D_REENTRANT"
852
Jason Evanscd9a1342012-03-21 18:33:03 -0700853dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
854dnl it rather than pthreads TSD cleanup functions to support cleanup during
855dnl thread exit, in order to avoid pthreads library recursion during
856dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -0700857AC_CHECK_FUNC([_malloc_thread_cleanup],
858 [have__malloc_thread_cleanup="1"],
859 [have__malloc_thread_cleanup="0"]
860 )
861if test "x$have__malloc_thread_cleanup" = "x1" ; then
862 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
863 force_tls="1"
864fi
865
Jason Evans41b6afb2012-02-02 22:04:57 -0800866dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
867dnl so, mutex initialization causes allocation, and we need to implement this
868dnl callback function in order to prevent recursive allocation.
869AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
870 [have__pthread_mutex_init_calloc_cb="1"],
871 [have__pthread_mutex_init_calloc_cb="0"]
872 )
873if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
874 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
875fi
876
Jason Evans0fee70d2012-02-13 12:36:11 -0800877dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700878AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -0800879 [AS_HELP_STRING([--enable-lazy-lock],
880 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700881[if test "x$enable_lazy_lock" = "xno" ; then
882 enable_lazy_lock="0"
883else
884 enable_lazy_lock="1"
885fi
886],
Jason Evans0fee70d2012-02-13 12:36:11 -0800887[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -0700888)
Jason Evansfd4fcef2012-03-23 17:40:58 -0700889if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
890 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
891 enable_lazy_lock="1"
892fi
Jason Evansb7924f52009-06-23 19:01:18 -0700893if test "x$enable_lazy_lock" = "x1" ; then
894 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
Jason Evans650285d2012-03-19 10:25:27 -0700895 AC_CHECK_FUNC([dlsym], [],
896 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
897 [AC_MSG_ERROR([libdl is missing])])
898 ])
Jason Evansb7924f52009-06-23 19:01:18 -0700899 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
900fi
901AC_SUBST([enable_lazy_lock])
902
Jason Evans78d815c2010-01-17 14:06:20 -0800903AC_ARG_ENABLE([tls],
904 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
905if test "x$enable_tls" = "xno" ; then
906 enable_tls="0"
907else
908 enable_tls="1"
909fi
910,
911enable_tls="1"
912)
Jason Evanscd9a1342012-03-21 18:33:03 -0700913if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
914 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
915 enable_tls="1"
916fi
Jason Evansb80581d2012-03-23 16:17:43 -0700917if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
918 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
919 enable_tls="0"
920fi
Jason Evans78d815c2010-01-17 14:06:20 -0800921if test "x${enable_tls}" = "x1" ; then
922AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -0800923AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -0800924[[
925 __thread int x;
926]], [[
927 x = 42;
928
929 return 0;
930]])],
931 AC_MSG_RESULT([yes]),
932 AC_MSG_RESULT([no])
933 enable_tls="0")
934fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700935AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -0700936if test "x${enable_tls}" = "x1" ; then
937 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -0700938elif test "x${force_tls}" = "x1" ; then
939 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -0800940fi
941
Jason Evans2dbecf12010-09-05 10:35:13 -0700942dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700943dnl Check for ffsl(3), and fail if not found. This function exists on all
944dnl platforms that jemalloc currently has a chance of functioning on without
945dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -0700946JE_COMPILABLE([a program using ffsl], [
Jason Evans382132e2012-04-04 15:25:43 -0700947#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -0700948#include <string.h>
949], [
950 {
951 int rv = ffsl(0x08);
952 }
953], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -0800954if test "x${je_cv_function_ffsl}" != "xyes" ; then
955 AC_MSG_ERROR([Cannot build without ffsl(3)])
956fi
Jason Evans84c8eef2011-03-16 10:30:13 -0700957
958dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -0700959dnl Check for atomic(3) operations as provided on Darwin.
960
961JE_COMPILABLE([Darwin OSAtomic*()], [
962#include <libkern/OSAtomic.h>
963#include <inttypes.h>
964], [
965 {
966 int32_t x32 = 0;
967 volatile int32_t *x32p = &x32;
968 OSAtomicAdd32(1, x32p);
969 }
970 {
971 int64_t x64 = 0;
972 volatile int64_t *x64p = &x64;
973 OSAtomicAdd64(1, x64p);
974 }
Jason Evans6684cac2012-03-05 12:15:36 -0800975], [je_cv_osatomic])
976if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700977 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -0700978fi
979
980dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +0200981dnl Check whether __sync_{add,sub}_and_fetch() are available despite
982dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
983
984AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
985 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
986 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +0200987 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
988 #include <stdint.h>
989 ],
990 [
991 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
992 {
993 uint$1_t x$1 = 0;
994 __sync_add_and_fetch(&x$1, 42);
995 __sync_sub_and_fetch(&x$1, 1);
996 }
997 #else
998 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
999 #endif
1000 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001001 [je_cv_sync_compare_and_swap_$2=yes],
1002 [je_cv_sync_compare_and_swap_$2=no])])
1003
1004 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1005 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1006 fi
1007])
1008
1009if test "x${je_cv_osatomic}" != "xyes" ; then
1010 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1011 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1012fi
1013
1014dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001015dnl Check for spinlock(3) operations as provided on Darwin.
1016
1017JE_COMPILABLE([Darwin OSSpin*()], [
1018#include <libkern/OSAtomic.h>
1019#include <inttypes.h>
1020], [
1021 OSSpinLock lock = 0;
1022 OSSpinLockLock(&lock);
1023 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001024], [je_cv_osspin])
1025if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001026 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001027fi
1028
1029dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001030dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001031
Jason Evans2dbecf12010-09-05 10:35:13 -07001032if test "x${abi}" = "xmacho" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001033 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1034 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001035
Jason Evans2dbecf12010-09-05 10:35:13 -07001036 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1037 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1038 dnl 10.6, which is the only source-level indication of the change.
1039 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001040 AC_DEFUN([JE_ZONE_PROGRAM],
1041 [AC_LANG_PROGRAM(
1042 [#include <malloc/malloc.h>],
1043 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1044 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001045
Mike Hommey154829d2012-03-20 18:01:38 +01001046 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1047 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1048 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1049 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1050 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1051 )])],[
1052 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1053 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1054 )])])])])
1055 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1056 AC_MSG_RESULT([unsupported])
1057 AC_MSG_ERROR([Unsupported malloc zone version])
1058 fi
1059 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1060 JEMALLOC_ZONE_VERSION=8
1061 AC_MSG_RESULT([> 8])
1062 else
1063 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1064 fi
1065 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001066fi
1067
Jason Evansb7924f52009-06-23 19:01:18 -07001068dnl ============================================================================
1069dnl Check for typedefs, structures, and compiler characteristics.
1070AC_HEADER_STDBOOL
1071
Jason Evansb1726102012-02-28 16:50:47 -08001072AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1073 mkdir -p "include/jemalloc/internal"
1074 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1075])
1076
Jason Evansb7924f52009-06-23 19:01:18 -07001077dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001078AC_SUBST([cfghdrs_in])
1079AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001080AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001081
1082dnl ============================================================================
1083dnl Generate outputs.
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001084AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001085AC_SUBST([cfgoutputs_in])
1086AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001087AC_OUTPUT
1088
1089dnl ============================================================================
1090dnl Print out the results of configuration.
1091AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001092AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1093AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001094AC_MSG_RESULT([])
1095AC_MSG_RESULT([CC : ${CC}])
1096AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1097AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1098AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1099AC_MSG_RESULT([LIBS : ${LIBS}])
1100AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1101AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001102AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1103AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1104AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001105AC_MSG_RESULT([PREFIX : ${PREFIX}])
1106AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001107AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1108AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001109AC_MSG_RESULT([DATADIR : ${DATADIR}])
1110AC_MSG_RESULT([MANDIR : ${MANDIR}])
1111AC_MSG_RESULT([])
1112AC_MSG_RESULT([srcroot : ${srcroot}])
1113AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1114AC_MSG_RESULT([objroot : ${objroot}])
1115AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1116AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001117AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001118AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1119AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001120AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001121AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001122AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001123AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001124AC_MSG_RESULT([debug : ${enable_debug}])
1125AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001126AC_MSG_RESULT([prof : ${enable_prof}])
1127AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001128AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1129AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001130AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001131AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001132AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001133AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1134AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evansb7924f52009-06-23 19:01:18 -07001135AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001136AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001137AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001138AC_MSG_RESULT([===============================================================================])