blob: 2616b0a60ecd42b5dfc47b2688dfdaf3fe465fe7 [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 Evansb7924f52009-06-23 19:01:18 -0700231 RPATH="-Wl,-rpath,"
232 ;;
233 *-*-netbsd*)
234 AC_MSG_CHECKING([ABI])
235 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
236[[#ifdef __ELF__
237/* ELF */
238#else
239#error aout
240#endif
241]])],
242 [CFLAGS="$CFLAGS"; abi="elf"],
243 [abi="aout"])
244 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700245 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700246 RPATH="-Wl,-rpath,"
247 ;;
248 *-*-solaris2*)
249 CFLAGS="$CFLAGS"
250 abi="elf"
251 RPATH="-Wl,-R,"
252 dnl Solaris needs this for sigwait().
253 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
254 LIBS="$LIBS -lposix4 -lsocket -lnsl"
255 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400256 *-ibm-aix*)
257 if "$LG_SIZEOF_PTR" = "8"; then
258 dnl 64bit AIX
259 LD_PRELOAD_VAR="LDR_PRELOAD64"
260 else
261 dnl 32bit AIX
262 LD_PRELOAD_VAR="LDR_PRELOAD"
263 fi
264 abi="xcoff"
265 RPATH="-Wl,-rpath,"
266 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700267 *)
268 AC_MSG_RESULT([Unsupported operating system: ${host}])
269 abi="elf"
270 RPATH="-Wl,-rpath,"
271 ;;
272esac
273AC_SUBST([abi])
274AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400275AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700276AC_SUBST([so])
Jason Evansb7924f52009-06-23 19:01:18 -0700277
Jason Evansfa5d2452011-03-15 10:25:59 -0700278JE_COMPILABLE([__attribute__ syntax],
279 [static __attribute__((unused)) void foo(void){}],
280 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800281 [je_cv_attribute])
282if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700283 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
284 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
285 JE_CFLAGS_APPEND([-fvisibility=hidden])
286 fi
287fi
288
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800289JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
290#define _GNU_SOURCE
291#include <sys/mman.h>
292], [
293void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
Jason Evans6684cac2012-03-05 12:15:36 -0800294], [je_cv_mremap_fixed])
295if test "x${je_cv_mremap_fixed}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700296 AC_DEFINE([JEMALLOC_MREMAP_FIXED], [ ])
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800297fi
298
Jason Evansb7924f52009-06-23 19:01:18 -0700299dnl Support optional additions to rpath.
300AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800301 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700302if test "x$with_rpath" = "xno" ; then
303 RPATH_EXTRA=
304else
305 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
306fi,
307 RPATH_EXTRA=
308)
309AC_SUBST([RPATH_EXTRA])
310
311dnl Disable rules that do automatic regeneration of configure output by default.
312AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800313 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700314if test "x$enable_autogen" = "xno" ; then
315 enable_autogen="0"
316else
317 enable_autogen="1"
318fi
319,
320enable_autogen="0"
321)
322AC_SUBST([enable_autogen])
323
324AC_PROG_INSTALL
325AC_PROG_RANLIB
326AC_PATH_PROG([AR], [ar], , [$PATH])
327AC_PATH_PROG([LD], [ld], , [$PATH])
328AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
329
Jason Evans0a0bbf62012-03-13 12:55:21 -0700330public_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 -0800331
332dnl Check for allocator-related functions that should be wrapped.
333AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700334 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800335 public_syms="${public_syms} memalign"])
336AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700337 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800338 public_syms="${public_syms} valloc"])
339
340dnl Support the experimental API by default.
341AC_ARG_ENABLE([experimental],
342 [AS_HELP_STRING([--disable-experimental],
343 [Disable support for the experimental API])],
344[if test "x$enable_experimental" = "xno" ; then
345 enable_experimental="0"
346else
347 enable_experimental="1"
348fi
349],
350[enable_experimental="1"]
351)
352if test "x$enable_experimental" = "x1" ; then
353 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
354 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
355fi
356AC_SUBST([enable_experimental])
357
Jason Evans0a5489e2012-03-01 17:19:20 -0800358dnl Perform no name mangling by default.
359AC_ARG_WITH([mangling],
360 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
361 [mangling_map="$with_mangling"], [mangling_map=""])
362for nm in `echo ${mangling_map} |tr ',' ' '` ; do
Jason Evans08fc3b22012-03-12 15:07:53 -0700363 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
364 n="je_${k}"
Jason Evans0a5489e2012-03-01 17:19:20 -0800365 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
366 AC_DEFINE_UNQUOTED([${n}], [${m}])
Jason Evans08fc3b22012-03-12 15:07:53 -0700367 dnl Remove key from public_syms so that it isn't redefined later.
368 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
Jason Evans0a5489e2012-03-01 17:19:20 -0800369done
370
Jason Evans90895cf2009-12-29 00:09:15 -0800371dnl Do not prefix public APIs by default.
372AC_ARG_WITH([jemalloc_prefix],
373 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800374 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700375 [if test "x$abi" != "xmacho" ; then
376 JEMALLOC_PREFIX=""
377else
378 JEMALLOC_PREFIX="je_"
379fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800380)
381if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700382 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
383 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
384 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800385fi
Jason Evans0a5489e2012-03-01 17:19:20 -0800386dnl Generate macros to rename public symbols. All public symbols are prefixed
387dnl with je_ in the source code, so these macro definitions are needed even if
388dnl --with-jemalloc-prefix wasn't specified.
Jason Evans7e77eaf2012-03-02 17:47:37 -0800389for stem in ${public_syms}; do
Jason Evans0a5489e2012-03-01 17:19:20 -0800390 n="je_${stem}"
391 m="${JEMALLOC_PREFIX}${stem}"
392 AC_DEFINE_UNQUOTED([${n}], [${m}])
393done
Jason Evans90895cf2009-12-29 00:09:15 -0800394
Jason Evans746e77a2011-07-30 16:40:52 -0700395dnl Do not mangle library-private APIs by default.
396AC_ARG_WITH([private_namespace],
397 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
398 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
399 [JEMALLOC_PRIVATE_NAMESPACE=""]
400)
401AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
402if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
403 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])
404else
405 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])
406fi
407
Jason Evansb0fd5012010-01-17 01:49:20 -0800408dnl Do not add suffix to installed files by default.
409AC_ARG_WITH([install_suffix],
410 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
411 [INSTALL_SUFFIX="$with_install_suffix"],
412 [INSTALL_SUFFIX=]
413)
414install_suffix="$INSTALL_SUFFIX"
415AC_SUBST([install_suffix])
416
Jason Evansaee7fd22010-11-24 22:00:02 -0800417cfgoutputs_in="${srcroot}Makefile.in"
418cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
419cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
420cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700421cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
422cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700423cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800424
Jason Evansaee7fd22010-11-24 22:00:02 -0800425cfgoutputs_out="Makefile"
426cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
427cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
428cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
Jason Evans376b1522010-02-11 14:45:59 -0800429cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
430cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700431cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800432
Jason Evansaee7fd22010-11-24 22:00:02 -0800433cfgoutputs_tup="Makefile"
434cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
435cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
436cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
Jason Evans376b1522010-02-11 14:45:59 -0800437cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
438cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700439cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800440
Jason Evans0656ec02010-04-07 23:37:35 -0700441cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb1726102012-02-28 16:50:47 -0800442cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansb0fd5012010-01-17 01:49:20 -0800443
Jason Evans376b1522010-02-11 14:45:59 -0800444cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb1726102012-02-28 16:50:47 -0800445cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800446
Jason Evans376b1522010-02-11 14:45:59 -0800447cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800448
Jason Evans355b4382010-09-20 19:20:48 -0700449dnl Do not silence irrelevant compiler warnings by default, since enabling this
450dnl option incurs a performance penalty.
451AC_ARG_ENABLE([cc-silence],
452 [AS_HELP_STRING([--enable-cc-silence],
453 [Silence irrelevant compiler warnings])],
454[if test "x$enable_cc_silence" = "xno" ; then
455 enable_cc_silence="0"
456else
457 enable_cc_silence="1"
458fi
459],
460[enable_cc_silence="0"]
461)
462if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700463 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700464fi
465
Jason Evansb7924f52009-06-23 19:01:18 -0700466dnl Do not compile with debugging by default.
467AC_ARG_ENABLE([debug],
468 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
469[if test "x$enable_debug" = "xno" ; then
470 enable_debug="0"
471else
472 enable_debug="1"
473fi
474],
475[enable_debug="0"]
476)
477if test "x$enable_debug" = "x1" ; then
478 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700479 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700480fi
481AC_SUBST([enable_debug])
482
483dnl Only optimize if not debugging.
484if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
485 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700486 optimize="no"
487 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
488 if test "x${optimize}" = "xyes" ; then
489 if test "x$GCC" = "xyes" ; then
490 JE_CFLAGS_APPEND([-O3])
491 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700492 else
493 JE_CFLAGS_APPEND([-O])
494 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700495 fi
496fi
497
Jason Evansd073a322012-02-28 20:41:16 -0800498dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700499AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800500 [AS_HELP_STRING([--disable-stats],
501 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700502[if test "x$enable_stats" = "xno" ; then
503 enable_stats="0"
504else
505 enable_stats="1"
506fi
507],
Jason Evansd073a322012-02-28 20:41:16 -0800508[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700509)
510if test "x$enable_stats" = "x1" ; then
511 AC_DEFINE([JEMALLOC_STATS], [ ])
512fi
513AC_SUBST([enable_stats])
514
Jason Evans6109fe02010-02-10 10:37:56 -0800515dnl Do not enable profiling by default.
516AC_ARG_ENABLE([prof],
517 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
518[if test "x$enable_prof" = "xno" ; then
519 enable_prof="0"
520else
521 enable_prof="1"
522fi
523],
524[enable_prof="0"]
525)
Jason Evans77f350b2011-03-15 22:23:12 -0700526if test "x$enable_prof" = "x1" ; then
527 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800528else
Jason Evans77f350b2011-03-15 22:23:12 -0700529 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800530fi
Jason Evans77f350b2011-03-15 22:23:12 -0700531
Jason Evans6109fe02010-02-10 10:37:56 -0800532AC_ARG_ENABLE([prof-libunwind],
533 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
534[if test "x$enable_prof_libunwind" = "xno" ; then
535 enable_prof_libunwind="0"
536else
537 enable_prof_libunwind="1"
538fi
539],
540[enable_prof_libunwind="0"]
541)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800542AC_ARG_WITH([static_libunwind],
543 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
544 [Path to static libunwind library; use rather than dynamically linking])],
545if test "x$with_static_libunwind" = "xno" ; then
546 LUNWIND="-lunwind"
547else
548 if test ! -f "$with_static_libunwind" ; then
549 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
550 fi
551 LUNWIND="$with_static_libunwind"
552fi,
553 LUNWIND="-lunwind"
554)
Jason Evans77f350b2011-03-15 22:23:12 -0700555if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
556 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
557 if test "x$LUNWIND" = "x-lunwind" ; then
558 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
559 [enable_prof_libunwind="0"])
560 else
561 LIBS="$LIBS $LUNWIND"
562 fi
563 if test "x${enable_prof_libunwind}" = "x1" ; then
564 backtrace_method="libunwind"
565 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
566 fi
567fi
568
569AC_ARG_ENABLE([prof-libgcc],
570 [AS_HELP_STRING([--disable-prof-libgcc],
571 [Do not use libgcc for backtracing])],
572[if test "x$enable_prof_libgcc" = "xno" ; then
573 enable_prof_libgcc="0"
574else
575 enable_prof_libgcc="1"
576fi
577],
578[enable_prof_libgcc="1"]
579)
580if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
581 -a "x$GCC" = "xyes" ; then
582 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
583 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
584 dnl The following is conservative, in that it only has entries for CPUs on
585 dnl which jemalloc has been tested.
586 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
587 case "${host_cpu}" in
588 i[[3456]]86)
589 AC_MSG_RESULT([unreliable])
590 enable_prof_libgcc="0";
591 ;;
592 x86_64)
593 AC_MSG_RESULT([reliable])
594 ;;
595 *)
596 AC_MSG_RESULT([unreliable])
597 enable_prof_libgcc="0";
598 ;;
599 esac
600 if test "x${enable_prof_libgcc}" = "x1" ; then
601 backtrace_method="libgcc"
602 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
603 fi
604else
605 enable_prof_libgcc="0"
606fi
607
608AC_ARG_ENABLE([prof-gcc],
609 [AS_HELP_STRING([--disable-prof-gcc],
610 [Do not use gcc intrinsics for backtracing])],
611[if test "x$enable_prof_gcc" = "xno" ; then
612 enable_prof_gcc="0"
613else
614 enable_prof_gcc="1"
615fi
616],
617[enable_prof_gcc="1"]
618)
619if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
620 -a "x$GCC" = "xyes" ; then
621 backtrace_method="gcc intrinsics"
622 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
623else
624 enable_prof_gcc="0"
625fi
626
627if test "x$backtrace_method" = "x" ; then
628 backtrace_method="none (disabling profiling)"
629 enable_prof="0"
630fi
631AC_MSG_CHECKING([configured backtracing method])
632AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700633if test "x$enable_prof" = "x1" ; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700634 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700635fi
636AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700637
Jason Evans84cbbcb2009-12-29 00:09:15 -0800638dnl Enable thread-specific caching by default.
639AC_ARG_ENABLE([tcache],
640 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
641[if test "x$enable_tcache" = "xno" ; then
642 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700643else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800644 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700645fi
646],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800647[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700648)
Jason Evans2dbecf12010-09-05 10:35:13 -0700649if test "x$enable_tcache" = "x1" ; then
650 AC_DEFINE([JEMALLOC_TCACHE], [ ])
651fi
652AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700653
Jason Evansb7924f52009-06-23 19:01:18 -0700654dnl Do not enable allocation from DSS by default.
655AC_ARG_ENABLE([dss],
656 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
657[if test "x$enable_dss" = "xno" ; then
658 enable_dss="0"
659else
660 enable_dss="1"
661fi
662],
663[enable_dss="0"]
664)
665if test "x$enable_dss" = "x1" ; then
666 AC_DEFINE([JEMALLOC_DSS], [ ])
667fi
668AC_SUBST([enable_dss])
669
Jason Evans777c1912012-02-28 20:49:22 -0800670dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700671AC_ARG_ENABLE([fill],
Jason Evans777c1912012-02-28 20:49:22 -0800672 [AS_HELP_STRING([--disable-fill], [Disable support for junk/zero filling])],
Jason Evansb7924f52009-06-23 19:01:18 -0700673[if test "x$enable_fill" = "xno" ; then
674 enable_fill="0"
675else
676 enable_fill="1"
677fi
678],
Jason Evans777c1912012-02-28 20:49:22 -0800679[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700680)
681if test "x$enable_fill" = "x1" ; then
682 AC_DEFINE([JEMALLOC_FILL], [ ])
683fi
684AC_SUBST([enable_fill])
685
686dnl Do not support the xmalloc option by default.
687AC_ARG_ENABLE([xmalloc],
688 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
689[if test "x$enable_xmalloc" = "xno" ; then
690 enable_xmalloc="0"
691else
692 enable_xmalloc="1"
693fi
694],
695[enable_xmalloc="0"]
696)
697if test "x$enable_xmalloc" = "x1" ; then
698 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
699fi
700AC_SUBST([enable_xmalloc])
701
Jason Evans6684cac2012-03-05 12:15:36 -0800702AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
703 [je_cv_static_page_shift],
704 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansb7924f52009-06-23 19:01:18 -0700705[[#include <stdio.h>
706#include <unistd.h>
707#include <strings.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800708]],
709[[
Jason Evansb7924f52009-06-23 19:01:18 -0700710 long result;
711 FILE *f;
712
713 result = sysconf(_SC_PAGESIZE);
714 if (result == -1) {
715 return 1;
716 }
717 f = fopen("conftest.out", "w");
718 if (f == NULL) {
719 return 1;
720 }
721 fprintf(f, "%u\n", ffs((int)result) - 1);
722 close(f);
723
724 return 0;
725]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800726 [je_cv_static_page_shift=`cat conftest.out`],
727 [je_cv_static_page_shift=undefined]))
728
729if test "x$je_cv_static_page_shift" != "xundefined"; then
730 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
731else
732 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
733fi
Jason Evansb7924f52009-06-23 19:01:18 -0700734
735dnl ============================================================================
736dnl jemalloc configuration.
737dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800738
739dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700740if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700741 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800742fi
Jason Evansb7924f52009-06-23 19:01:18 -0700743jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800744jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
745jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
746jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
747jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
748jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700749AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800750AC_SUBST([jemalloc_version_major])
751AC_SUBST([jemalloc_version_minor])
752AC_SUBST([jemalloc_version_bugfix])
753AC_SUBST([jemalloc_version_nrev])
754AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700755
756dnl ============================================================================
757dnl Configure pthreads.
758
759AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
Jason Evans39006f92012-03-16 16:57:02 -0700760dnl Some systems may embed pthreads functionality in libc; check for libpthread
761dnl first, but try libc too before failing.
Jason Evansb7924f52009-06-23 19:01:18 -0700762AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
Jason Evans39006f92012-03-16 16:57:02 -0700763 [AC_SEARCH_LIBS([pthread_create], , ,
764 AC_MSG_ERROR([libpthread is missing]))])
Jason Evansb7924f52009-06-23 19:01:18 -0700765
766CPPFLAGS="$CPPFLAGS -D_REENTRANT"
767
Jason Evanscd9a1342012-03-21 18:33:03 -0700768dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
769dnl it rather than pthreads TSD cleanup functions to support cleanup during
770dnl thread exit, in order to avoid pthreads library recursion during
771dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -0700772AC_CHECK_FUNC([_malloc_thread_cleanup],
773 [have__malloc_thread_cleanup="1"],
774 [have__malloc_thread_cleanup="0"]
775 )
776if test "x$have__malloc_thread_cleanup" = "x1" ; then
777 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
778 force_tls="1"
779fi
780
Jason Evans41b6afb2012-02-02 22:04:57 -0800781dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
782dnl so, mutex initialization causes allocation, and we need to implement this
783dnl callback function in order to prevent recursive allocation.
784AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
785 [have__pthread_mutex_init_calloc_cb="1"],
786 [have__pthread_mutex_init_calloc_cb="0"]
787 )
788if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
789 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
790fi
791
Jason Evans0fee70d2012-02-13 12:36:11 -0800792dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700793AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -0800794 [AS_HELP_STRING([--enable-lazy-lock],
795 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700796[if test "x$enable_lazy_lock" = "xno" ; then
797 enable_lazy_lock="0"
798else
799 enable_lazy_lock="1"
800fi
801],
Jason Evans0fee70d2012-02-13 12:36:11 -0800802[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -0700803)
Jason Evansfd4fcef2012-03-23 17:40:58 -0700804if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
805 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
806 enable_lazy_lock="1"
807fi
Jason Evansb7924f52009-06-23 19:01:18 -0700808if test "x$enable_lazy_lock" = "x1" ; then
809 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
Jason Evans650285d2012-03-19 10:25:27 -0700810 AC_CHECK_FUNC([dlsym], [],
811 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
812 [AC_MSG_ERROR([libdl is missing])])
813 ])
Jason Evansb7924f52009-06-23 19:01:18 -0700814 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
815fi
816AC_SUBST([enable_lazy_lock])
817
Jason Evans78d815c2010-01-17 14:06:20 -0800818AC_ARG_ENABLE([tls],
819 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
820if test "x$enable_tls" = "xno" ; then
821 enable_tls="0"
822else
823 enable_tls="1"
824fi
825,
826enable_tls="1"
827)
Jason Evanscd9a1342012-03-21 18:33:03 -0700828if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
829 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
830 enable_tls="1"
831fi
Jason Evansb80581d2012-03-23 16:17:43 -0700832if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
833 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
834 enable_tls="0"
835fi
Jason Evans78d815c2010-01-17 14:06:20 -0800836if test "x${enable_tls}" = "x1" ; then
837AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -0800838AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -0800839[[
840 __thread int x;
841]], [[
842 x = 42;
843
844 return 0;
845]])],
846 AC_MSG_RESULT([yes]),
847 AC_MSG_RESULT([no])
848 enable_tls="0")
849fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700850AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -0700851if test "x${enable_tls}" = "x1" ; then
852 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -0700853elif test "x${force_tls}" = "x1" ; then
854 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -0800855fi
856
Jason Evans2dbecf12010-09-05 10:35:13 -0700857dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700858dnl Check for ffsl(3), and fail if not found. This function exists on all
859dnl platforms that jemalloc currently has a chance of functioning on without
860dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -0700861JE_COMPILABLE([a program using ffsl], [
862#include <string.h>
863], [
864 {
865 int rv = ffsl(0x08);
866 }
867], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -0800868if test "x${je_cv_function_ffsl}" != "xyes" ; then
869 AC_MSG_ERROR([Cannot build without ffsl(3)])
870fi
Jason Evans84c8eef2011-03-16 10:30:13 -0700871
872dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -0700873dnl Check for atomic(3) operations as provided on Darwin.
874
875JE_COMPILABLE([Darwin OSAtomic*()], [
876#include <libkern/OSAtomic.h>
877#include <inttypes.h>
878], [
879 {
880 int32_t x32 = 0;
881 volatile int32_t *x32p = &x32;
882 OSAtomicAdd32(1, x32p);
883 }
884 {
885 int64_t x64 = 0;
886 volatile int64_t *x64p = &x64;
887 OSAtomicAdd64(1, x64p);
888 }
Jason Evans6684cac2012-03-05 12:15:36 -0800889], [je_cv_osatomic])
890if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700891 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -0700892fi
893
894dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +0200895dnl Check whether __sync_{add,sub}_and_fetch() are available despite
896dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
897
898AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
899 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
900 [je_cv_sync_compare_and_swap_$2],
901 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
902 #include <stdint.h>
903 ],
904 [
905 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
906 {
907 uint$1_t x$1 = 0;
908 __sync_add_and_fetch(&x$1, 42);
909 __sync_sub_and_fetch(&x$1, 1);
910 }
911 #else
912 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
913 #endif
914 ])],
915 [je_cv_sync_compare_and_swap_$2=yes],
916 [je_cv_sync_compare_and_swap_$2=no])])
917
918 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
919 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
920 fi
921])
922
923if test "x${je_cv_osatomic}" != "xyes" ; then
924 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
925 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
926fi
927
928dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -0700929dnl Check for spinlock(3) operations as provided on Darwin.
930
931JE_COMPILABLE([Darwin OSSpin*()], [
932#include <libkern/OSAtomic.h>
933#include <inttypes.h>
934], [
935 OSSpinLock lock = 0;
936 OSSpinLockLock(&lock);
937 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -0800938], [je_cv_osspin])
939if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700940 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -0700941fi
942
943dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -0700944dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -0800945
Jason Evans2dbecf12010-09-05 10:35:13 -0700946if test "x${abi}" = "xmacho" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700947 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
948 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -0800949
Jason Evans2dbecf12010-09-05 10:35:13 -0700950 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
951 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
952 dnl 10.6, which is the only source-level indication of the change.
953 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +0100954 AC_DEFUN([JE_ZONE_PROGRAM],
955 [AC_LANG_PROGRAM(
956 [#include <malloc/malloc.h>],
957 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
958 )])
Jason Evans2dbecf12010-09-05 10:35:13 -0700959
Mike Hommey154829d2012-03-20 18:01:38 +0100960 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
961 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
962 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
963 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
964 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
965 )])],[
966 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
967 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
968 )])])])])
969 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
970 AC_MSG_RESULT([unsupported])
971 AC_MSG_ERROR([Unsupported malloc zone version])
972 fi
973 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
974 JEMALLOC_ZONE_VERSION=8
975 AC_MSG_RESULT([> 8])
976 else
977 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
978 fi
979 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -0800980fi
981
Jason Evansb7924f52009-06-23 19:01:18 -0700982dnl ============================================================================
983dnl Check for typedefs, structures, and compiler characteristics.
984AC_HEADER_STDBOOL
985
Jason Evansb1726102012-02-28 16:50:47 -0800986AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
987 mkdir -p "include/jemalloc/internal"
988 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
989])
990
Jason Evansb7924f52009-06-23 19:01:18 -0700991dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -0800992AC_SUBST([cfghdrs_in])
993AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -0700994AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -0700995
996dnl ============================================================================
997dnl Generate outputs.
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400998AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -0800999AC_SUBST([cfgoutputs_in])
1000AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001001AC_OUTPUT
1002
1003dnl ============================================================================
1004dnl Print out the results of configuration.
1005AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001006AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1007AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001008AC_MSG_RESULT([])
1009AC_MSG_RESULT([CC : ${CC}])
1010AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1011AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1012AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1013AC_MSG_RESULT([LIBS : ${LIBS}])
1014AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1015AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001016AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1017AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1018AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001019AC_MSG_RESULT([PREFIX : ${PREFIX}])
1020AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001021AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1022AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001023AC_MSG_RESULT([DATADIR : ${DATADIR}])
1024AC_MSG_RESULT([MANDIR : ${MANDIR}])
1025AC_MSG_RESULT([])
1026AC_MSG_RESULT([srcroot : ${srcroot}])
1027AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1028AC_MSG_RESULT([objroot : ${objroot}])
1029AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1030AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001031AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001032AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1033AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001034AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001035AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001036AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001037AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001038AC_MSG_RESULT([debug : ${enable_debug}])
1039AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001040AC_MSG_RESULT([prof : ${enable_prof}])
1041AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001042AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1043AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001044AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001045AC_MSG_RESULT([fill : ${enable_fill}])
1046AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evansb7924f52009-06-23 19:01:18 -07001047AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001048AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001049AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001050AC_MSG_RESULT([===============================================================================])