blob: 8e94b5c9d0e83f474ec0b616885b54808fc926b5 [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)
681if test "x$enable_dss" = "x1" ; then
682 AC_DEFINE([JEMALLOC_DSS], [ ])
683fi
684AC_SUBST([enable_dss])
685
Jason Evans777c1912012-02-28 20:49:22 -0800686dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700687AC_ARG_ENABLE([fill],
Jason Evans777c1912012-02-28 20:49:22 -0800688 [AS_HELP_STRING([--disable-fill], [Disable support for junk/zero filling])],
Jason Evansb7924f52009-06-23 19:01:18 -0700689[if test "x$enable_fill" = "xno" ; then
690 enable_fill="0"
691else
692 enable_fill="1"
693fi
694],
Jason Evans777c1912012-02-28 20:49:22 -0800695[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700696)
697if test "x$enable_fill" = "x1" ; then
698 AC_DEFINE([JEMALLOC_FILL], [ ])
699fi
700AC_SUBST([enable_fill])
701
Jason Evansb1476112012-04-05 13:36:17 -0700702dnl Disable utrace(2)-based tracing by default.
703AC_ARG_ENABLE([utrace],
704 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
705[if test "x$enable_utrace" = "xno" ; then
706 enable_utrace="0"
707else
708 enable_utrace="1"
709fi
710],
711[enable_utrace="0"]
712)
713JE_COMPILABLE([utrace(2)], [
714#include <sys/types.h>
715#include <sys/param.h>
716#include <sys/time.h>
717#include <sys/uio.h>
718#include <sys/ktrace.h>
719], [
720 utrace((void *)0, 0);
721], [je_cv_utrace])
722if test "x${je_cv_utrace}" = "xno" ; then
723 enable_utrace="0"
724fi
725if test "x$enable_utrace" = "x1" ; then
726 AC_DEFINE([JEMALLOC_UTRACE], [ ])
727fi
728AC_SUBST([enable_utrace])
729
Jason Evansb7924f52009-06-23 19:01:18 -0700730dnl Do not support the xmalloc option by default.
731AC_ARG_ENABLE([xmalloc],
732 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
733[if test "x$enable_xmalloc" = "xno" ; then
734 enable_xmalloc="0"
735else
736 enable_xmalloc="1"
737fi
738],
739[enable_xmalloc="0"]
740)
741if test "x$enable_xmalloc" = "x1" ; then
742 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
743fi
744AC_SUBST([enable_xmalloc])
745
Jason Evans6684cac2012-03-05 12:15:36 -0800746AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
747 [je_cv_static_page_shift],
748 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansb7924f52009-06-23 19:01:18 -0700749[[#include <stdio.h>
750#include <unistd.h>
751#include <strings.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800752]],
753[[
Jason Evansb7924f52009-06-23 19:01:18 -0700754 long result;
755 FILE *f;
756
757 result = sysconf(_SC_PAGESIZE);
758 if (result == -1) {
759 return 1;
760 }
761 f = fopen("conftest.out", "w");
762 if (f == NULL) {
763 return 1;
764 }
765 fprintf(f, "%u\n", ffs((int)result) - 1);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700766 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700767
768 return 0;
769]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800770 [je_cv_static_page_shift=`cat conftest.out`],
771 [je_cv_static_page_shift=undefined]))
772
773if test "x$je_cv_static_page_shift" != "xundefined"; then
774 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
775else
776 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
777fi
Jason Evansb7924f52009-06-23 19:01:18 -0700778
779dnl ============================================================================
780dnl jemalloc configuration.
781dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800782
783dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700784if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700785 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800786fi
Jason Evansb7924f52009-06-23 19:01:18 -0700787jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800788jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
789jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
790jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
791jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
792jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700793AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800794AC_SUBST([jemalloc_version_major])
795AC_SUBST([jemalloc_version_minor])
796AC_SUBST([jemalloc_version_bugfix])
797AC_SUBST([jemalloc_version_nrev])
798AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700799
800dnl ============================================================================
801dnl Configure pthreads.
802
803AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
Jason Evans39006f92012-03-16 16:57:02 -0700804dnl Some systems may embed pthreads functionality in libc; check for libpthread
805dnl first, but try libc too before failing.
Jason Evansb7924f52009-06-23 19:01:18 -0700806AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
Jason Evans39006f92012-03-16 16:57:02 -0700807 [AC_SEARCH_LIBS([pthread_create], , ,
808 AC_MSG_ERROR([libpthread is missing]))])
Jason Evansb7924f52009-06-23 19:01:18 -0700809
810CPPFLAGS="$CPPFLAGS -D_REENTRANT"
811
Jason Evanscd9a1342012-03-21 18:33:03 -0700812dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
813dnl it rather than pthreads TSD cleanup functions to support cleanup during
814dnl thread exit, in order to avoid pthreads library recursion during
815dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -0700816AC_CHECK_FUNC([_malloc_thread_cleanup],
817 [have__malloc_thread_cleanup="1"],
818 [have__malloc_thread_cleanup="0"]
819 )
820if test "x$have__malloc_thread_cleanup" = "x1" ; then
821 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
822 force_tls="1"
823fi
824
Jason Evans41b6afb2012-02-02 22:04:57 -0800825dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
826dnl so, mutex initialization causes allocation, and we need to implement this
827dnl callback function in order to prevent recursive allocation.
828AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
829 [have__pthread_mutex_init_calloc_cb="1"],
830 [have__pthread_mutex_init_calloc_cb="0"]
831 )
832if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
833 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
834fi
835
Jason Evans0fee70d2012-02-13 12:36:11 -0800836dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700837AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -0800838 [AS_HELP_STRING([--enable-lazy-lock],
839 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700840[if test "x$enable_lazy_lock" = "xno" ; then
841 enable_lazy_lock="0"
842else
843 enable_lazy_lock="1"
844fi
845],
Jason Evans0fee70d2012-02-13 12:36:11 -0800846[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -0700847)
Jason Evansfd4fcef2012-03-23 17:40:58 -0700848if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
849 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
850 enable_lazy_lock="1"
851fi
Jason Evansb7924f52009-06-23 19:01:18 -0700852if test "x$enable_lazy_lock" = "x1" ; then
853 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
Jason Evans650285d2012-03-19 10:25:27 -0700854 AC_CHECK_FUNC([dlsym], [],
855 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
856 [AC_MSG_ERROR([libdl is missing])])
857 ])
Jason Evansb7924f52009-06-23 19:01:18 -0700858 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
859fi
860AC_SUBST([enable_lazy_lock])
861
Jason Evans78d815c2010-01-17 14:06:20 -0800862AC_ARG_ENABLE([tls],
863 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
864if test "x$enable_tls" = "xno" ; then
865 enable_tls="0"
866else
867 enable_tls="1"
868fi
869,
870enable_tls="1"
871)
Jason Evanscd9a1342012-03-21 18:33:03 -0700872if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
873 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
874 enable_tls="1"
875fi
Jason Evansb80581d2012-03-23 16:17:43 -0700876if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
877 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
878 enable_tls="0"
879fi
Jason Evans78d815c2010-01-17 14:06:20 -0800880if test "x${enable_tls}" = "x1" ; then
881AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -0800882AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -0800883[[
884 __thread int x;
885]], [[
886 x = 42;
887
888 return 0;
889]])],
890 AC_MSG_RESULT([yes]),
891 AC_MSG_RESULT([no])
892 enable_tls="0")
893fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700894AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -0700895if test "x${enable_tls}" = "x1" ; then
896 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -0700897elif test "x${force_tls}" = "x1" ; then
898 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -0800899fi
900
Jason Evans2dbecf12010-09-05 10:35:13 -0700901dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700902dnl Check for ffsl(3), and fail if not found. This function exists on all
903dnl platforms that jemalloc currently has a chance of functioning on without
904dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -0700905JE_COMPILABLE([a program using ffsl], [
Jason Evans382132e2012-04-04 15:25:43 -0700906#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -0700907#include <string.h>
908], [
909 {
910 int rv = ffsl(0x08);
911 }
912], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -0800913if test "x${je_cv_function_ffsl}" != "xyes" ; then
914 AC_MSG_ERROR([Cannot build without ffsl(3)])
915fi
Jason Evans84c8eef2011-03-16 10:30:13 -0700916
917dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -0700918dnl Check for atomic(3) operations as provided on Darwin.
919
920JE_COMPILABLE([Darwin OSAtomic*()], [
921#include <libkern/OSAtomic.h>
922#include <inttypes.h>
923], [
924 {
925 int32_t x32 = 0;
926 volatile int32_t *x32p = &x32;
927 OSAtomicAdd32(1, x32p);
928 }
929 {
930 int64_t x64 = 0;
931 volatile int64_t *x64p = &x64;
932 OSAtomicAdd64(1, x64p);
933 }
Jason Evans6684cac2012-03-05 12:15:36 -0800934], [je_cv_osatomic])
935if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700936 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -0700937fi
938
939dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +0200940dnl Check whether __sync_{add,sub}_and_fetch() are available despite
941dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
942
943AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
944 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
945 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +0200946 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
947 #include <stdint.h>
948 ],
949 [
950 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
951 {
952 uint$1_t x$1 = 0;
953 __sync_add_and_fetch(&x$1, 42);
954 __sync_sub_and_fetch(&x$1, 1);
955 }
956 #else
957 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
958 #endif
959 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +0200960 [je_cv_sync_compare_and_swap_$2=yes],
961 [je_cv_sync_compare_and_swap_$2=no])])
962
963 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
964 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
965 fi
966])
967
968if test "x${je_cv_osatomic}" != "xyes" ; then
969 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
970 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
971fi
972
973dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -0700974dnl Check for spinlock(3) operations as provided on Darwin.
975
976JE_COMPILABLE([Darwin OSSpin*()], [
977#include <libkern/OSAtomic.h>
978#include <inttypes.h>
979], [
980 OSSpinLock lock = 0;
981 OSSpinLockLock(&lock);
982 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -0800983], [je_cv_osspin])
984if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700985 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -0700986fi
987
988dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -0700989dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -0800990
Jason Evans2dbecf12010-09-05 10:35:13 -0700991if test "x${abi}" = "xmacho" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700992 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
993 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -0800994
Jason Evans2dbecf12010-09-05 10:35:13 -0700995 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
996 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
997 dnl 10.6, which is the only source-level indication of the change.
998 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +0100999 AC_DEFUN([JE_ZONE_PROGRAM],
1000 [AC_LANG_PROGRAM(
1001 [#include <malloc/malloc.h>],
1002 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1003 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001004
Mike Hommey154829d2012-03-20 18:01:38 +01001005 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1006 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1007 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1008 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1009 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1010 )])],[
1011 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1012 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1013 )])])])])
1014 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1015 AC_MSG_RESULT([unsupported])
1016 AC_MSG_ERROR([Unsupported malloc zone version])
1017 fi
1018 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1019 JEMALLOC_ZONE_VERSION=8
1020 AC_MSG_RESULT([> 8])
1021 else
1022 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1023 fi
1024 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001025fi
1026
Jason Evansb7924f52009-06-23 19:01:18 -07001027dnl ============================================================================
1028dnl Check for typedefs, structures, and compiler characteristics.
1029AC_HEADER_STDBOOL
1030
Jason Evansb1726102012-02-28 16:50:47 -08001031AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1032 mkdir -p "include/jemalloc/internal"
1033 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1034])
1035
Jason Evansb7924f52009-06-23 19:01:18 -07001036dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001037AC_SUBST([cfghdrs_in])
1038AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001039AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001040
1041dnl ============================================================================
1042dnl Generate outputs.
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001043AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001044AC_SUBST([cfgoutputs_in])
1045AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001046AC_OUTPUT
1047
1048dnl ============================================================================
1049dnl Print out the results of configuration.
1050AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001051AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1052AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001053AC_MSG_RESULT([])
1054AC_MSG_RESULT([CC : ${CC}])
1055AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1056AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1057AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1058AC_MSG_RESULT([LIBS : ${LIBS}])
1059AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1060AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001061AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1062AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1063AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001064AC_MSG_RESULT([PREFIX : ${PREFIX}])
1065AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001066AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1067AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001068AC_MSG_RESULT([DATADIR : ${DATADIR}])
1069AC_MSG_RESULT([MANDIR : ${MANDIR}])
1070AC_MSG_RESULT([])
1071AC_MSG_RESULT([srcroot : ${srcroot}])
1072AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1073AC_MSG_RESULT([objroot : ${objroot}])
1074AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1075AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001076AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001077AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1078AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001079AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001080AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001081AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001082AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001083AC_MSG_RESULT([debug : ${enable_debug}])
1084AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001085AC_MSG_RESULT([prof : ${enable_prof}])
1086AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001087AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1088AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001089AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001090AC_MSG_RESULT([fill : ${enable_fill}])
1091AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evansb1476112012-04-05 13:36:17 -07001092AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evansb7924f52009-06-23 19:01:18 -07001093AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001094AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001095AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001096AC_MSG_RESULT([===============================================================================])