blob: 3a7a24574309d0dc01fe26cb1e80dcdd70fb82b6 [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"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200198o="o"
199a="a"
200exe=
201lib="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200202DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
203RPATH='-Wl,-rpath,$(1)'
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400204
Jason Evans7372b152012-02-10 20:22:09 -0800205dnl Heap profiling uses the log(3) function.
206LIBS="$LIBS -lm"
207
Jason Evansb7924f52009-06-23 19:01:18 -0700208dnl Platform-specific settings. abi and RPATH can probably be determined
209dnl programmatically, but doing so is error-prone, which makes it generally
210dnl not worth the trouble.
211dnl
212dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
213dnl definitions need to be seen before any headers are included, which is a pain
214dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700215default_munmap="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700216case "${host}" in
217 *-*-darwin*)
Jason Evans9022bf92012-03-23 16:14:08 -0700218 CFLAGS="$CFLAGS -fno-common"
Jason Evansb7924f52009-06-23 19:01:18 -0700219 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700220 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700221 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400222 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700223 so="dylib"
Jason Evansb80581d2012-03-23 16:17:43 -0700224 force_tls="0"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200225 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
Jason Evansb7924f52009-06-23 19:01:18 -0700226 ;;
227 *-*-freebsd*)
228 CFLAGS="$CFLAGS"
229 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700230 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700231 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700232 ;;
233 *-*-linux*)
234 CFLAGS="$CFLAGS"
235 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
236 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700237 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700238 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700239 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700240 ;;
241 *-*-netbsd*)
242 AC_MSG_CHECKING([ABI])
243 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
244[[#ifdef __ELF__
245/* ELF */
246#else
247#error aout
248#endif
249]])],
250 [CFLAGS="$CFLAGS"; abi="elf"],
251 [abi="aout"])
252 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700253 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700254 ;;
255 *-*-solaris2*)
256 CFLAGS="$CFLAGS"
257 abi="elf"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200258 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700259 dnl Solaris needs this for sigwait().
260 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
261 LIBS="$LIBS -lposix4 -lsocket -lnsl"
262 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400263 *-ibm-aix*)
264 if "$LG_SIZEOF_PTR" = "8"; then
265 dnl 64bit AIX
266 LD_PRELOAD_VAR="LDR_PRELOAD64"
267 else
268 dnl 32bit AIX
269 LD_PRELOAD_VAR="LDR_PRELOAD"
270 fi
271 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400272 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700273 *)
274 AC_MSG_RESULT([Unsupported operating system: ${host}])
275 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700276 ;;
277esac
278AC_SUBST([abi])
279AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400280AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700281AC_SUBST([so])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200282AC_SUBST([o])
283AC_SUBST([a])
284AC_SUBST([exe])
285AC_SUBST([lib])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200286AC_SUBST([DSO_LDFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700287
Jason Evansfa5d2452011-03-15 10:25:59 -0700288JE_COMPILABLE([__attribute__ syntax],
289 [static __attribute__((unused)) void foo(void){}],
290 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800291 [je_cv_attribute])
292if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700293 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
294 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
295 JE_CFLAGS_APPEND([-fvisibility=hidden])
296 fi
297fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700298dnl Check for tls_model attribute support (clang 3.0 still lacks support).
299SAVED_CFLAGS="${CFLAGS}"
300JE_CFLAGS_APPEND([-Werror])
301JE_COMPILABLE([tls_model attribute], [],
302 [static __thread int
303 __attribute__((tls_model("initial-exec"))) foo;
304 foo = 0;],
305 [je_cv_tls_model])
306CFLAGS="${SAVED_CFLAGS}"
307if test "x${je_cv_tls_model}" = "xyes" ; then
308 AC_DEFINE([JEMALLOC_TLS_MODEL],
309 [__attribute__((tls_model("initial-exec")))])
310else
311 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
312fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700313
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800314JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
315#define _GNU_SOURCE
316#include <sys/mman.h>
317], [
318void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
Jason Evans6684cac2012-03-05 12:15:36 -0800319], [je_cv_mremap_fixed])
320if test "x${je_cv_mremap_fixed}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700321 AC_DEFINE([JEMALLOC_MREMAP_FIXED], [ ])
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800322fi
323
Jason Evansb7924f52009-06-23 19:01:18 -0700324dnl Support optional additions to rpath.
325AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800326 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700327if test "x$with_rpath" = "xno" ; then
328 RPATH_EXTRA=
329else
330 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
331fi,
332 RPATH_EXTRA=
333)
334AC_SUBST([RPATH_EXTRA])
335
336dnl Disable rules that do automatic regeneration of configure output by default.
337AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800338 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700339if test "x$enable_autogen" = "xno" ; then
340 enable_autogen="0"
341else
342 enable_autogen="1"
343fi
344,
345enable_autogen="0"
346)
347AC_SUBST([enable_autogen])
348
349AC_PROG_INSTALL
350AC_PROG_RANLIB
351AC_PATH_PROG([AR], [ar], , [$PATH])
352AC_PATH_PROG([LD], [ld], , [$PATH])
353AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
354
Jason Evans0a0bbf62012-03-13 12:55:21 -0700355public_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 -0800356
357dnl Check for allocator-related functions that should be wrapped.
358AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700359 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800360 public_syms="${public_syms} memalign"])
361AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700362 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800363 public_syms="${public_syms} valloc"])
364
365dnl Support the experimental API by default.
366AC_ARG_ENABLE([experimental],
367 [AS_HELP_STRING([--disable-experimental],
368 [Disable support for the experimental API])],
369[if test "x$enable_experimental" = "xno" ; then
370 enable_experimental="0"
371else
372 enable_experimental="1"
373fi
374],
375[enable_experimental="1"]
376)
377if test "x$enable_experimental" = "x1" ; then
378 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
379 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
380fi
381AC_SUBST([enable_experimental])
382
Jason Evans0a5489e2012-03-01 17:19:20 -0800383dnl Perform no name mangling by default.
384AC_ARG_WITH([mangling],
385 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
386 [mangling_map="$with_mangling"], [mangling_map=""])
387for nm in `echo ${mangling_map} |tr ',' ' '` ; do
Jason Evans08fc3b22012-03-12 15:07:53 -0700388 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
389 n="je_${k}"
Jason Evans0a5489e2012-03-01 17:19:20 -0800390 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
391 AC_DEFINE_UNQUOTED([${n}], [${m}])
Jason Evans08fc3b22012-03-12 15:07:53 -0700392 dnl Remove key from public_syms so that it isn't redefined later.
393 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
Jason Evans0a5489e2012-03-01 17:19:20 -0800394done
395
Jason Evans90895cf2009-12-29 00:09:15 -0800396dnl Do not prefix public APIs by default.
397AC_ARG_WITH([jemalloc_prefix],
398 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800399 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700400 [if test "x$abi" != "xmacho" ; then
401 JEMALLOC_PREFIX=""
402else
403 JEMALLOC_PREFIX="je_"
404fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800405)
406if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700407 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
408 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
409 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800410fi
Jason Evans0a5489e2012-03-01 17:19:20 -0800411dnl Generate macros to rename public symbols. All public symbols are prefixed
412dnl with je_ in the source code, so these macro definitions are needed even if
413dnl --with-jemalloc-prefix wasn't specified.
Jason Evans7e77eaf2012-03-02 17:47:37 -0800414for stem in ${public_syms}; do
Jason Evans0a5489e2012-03-01 17:19:20 -0800415 n="je_${stem}"
416 m="${JEMALLOC_PREFIX}${stem}"
417 AC_DEFINE_UNQUOTED([${n}], [${m}])
418done
Jason Evans90895cf2009-12-29 00:09:15 -0800419
Jason Evans746e77a2011-07-30 16:40:52 -0700420dnl Do not mangle library-private APIs by default.
421AC_ARG_WITH([private_namespace],
422 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
423 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
424 [JEMALLOC_PRIVATE_NAMESPACE=""]
425)
426AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
427if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
428 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])
429else
430 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])
431fi
432
Jason Evansb0fd5012010-01-17 01:49:20 -0800433dnl Do not add suffix to installed files by default.
434AC_ARG_WITH([install_suffix],
435 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
436 [INSTALL_SUFFIX="$with_install_suffix"],
437 [INSTALL_SUFFIX=]
438)
439install_suffix="$INSTALL_SUFFIX"
440AC_SUBST([install_suffix])
441
Jason Evansaee7fd22010-11-24 22:00:02 -0800442cfgoutputs_in="${srcroot}Makefile.in"
443cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
444cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
445cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700446cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
447cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700448cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800449
Jason Evansaee7fd22010-11-24 22:00:02 -0800450cfgoutputs_out="Makefile"
451cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
452cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
453cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
Jason Evans376b1522010-02-11 14:45:59 -0800454cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
455cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700456cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800457
Jason Evansaee7fd22010-11-24 22:00:02 -0800458cfgoutputs_tup="Makefile"
459cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
460cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
461cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
Jason Evans376b1522010-02-11 14:45:59 -0800462cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
463cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700464cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800465
Jason Evans0656ec02010-04-07 23:37:35 -0700466cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb1726102012-02-28 16:50:47 -0800467cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansb0fd5012010-01-17 01:49:20 -0800468
Jason Evans376b1522010-02-11 14:45:59 -0800469cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb1726102012-02-28 16:50:47 -0800470cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800471
Jason Evans376b1522010-02-11 14:45:59 -0800472cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800473
Jason Evans355b4382010-09-20 19:20:48 -0700474dnl Do not silence irrelevant compiler warnings by default, since enabling this
475dnl option incurs a performance penalty.
476AC_ARG_ENABLE([cc-silence],
477 [AS_HELP_STRING([--enable-cc-silence],
478 [Silence irrelevant compiler warnings])],
479[if test "x$enable_cc_silence" = "xno" ; then
480 enable_cc_silence="0"
481else
482 enable_cc_silence="1"
483fi
484],
485[enable_cc_silence="0"]
486)
487if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700488 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700489fi
490
Jason Evansb7924f52009-06-23 19:01:18 -0700491dnl Do not compile with debugging by default.
492AC_ARG_ENABLE([debug],
493 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
494[if test "x$enable_debug" = "xno" ; then
495 enable_debug="0"
496else
497 enable_debug="1"
498fi
499],
500[enable_debug="0"]
501)
502if test "x$enable_debug" = "x1" ; then
503 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700504 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700505fi
506AC_SUBST([enable_debug])
507
508dnl Only optimize if not debugging.
509if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
510 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700511 optimize="no"
512 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
513 if test "x${optimize}" = "xyes" ; then
514 if test "x$GCC" = "xyes" ; then
515 JE_CFLAGS_APPEND([-O3])
516 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700517 else
518 JE_CFLAGS_APPEND([-O])
519 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700520 fi
521fi
522
Jason Evansd073a322012-02-28 20:41:16 -0800523dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700524AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800525 [AS_HELP_STRING([--disable-stats],
526 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700527[if test "x$enable_stats" = "xno" ; then
528 enable_stats="0"
529else
530 enable_stats="1"
531fi
532],
Jason Evansd073a322012-02-28 20:41:16 -0800533[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700534)
535if test "x$enable_stats" = "x1" ; then
536 AC_DEFINE([JEMALLOC_STATS], [ ])
537fi
538AC_SUBST([enable_stats])
539
Jason Evans6109fe02010-02-10 10:37:56 -0800540dnl Do not enable profiling by default.
541AC_ARG_ENABLE([prof],
542 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
543[if test "x$enable_prof" = "xno" ; then
544 enable_prof="0"
545else
546 enable_prof="1"
547fi
548],
549[enable_prof="0"]
550)
Jason Evans77f350b2011-03-15 22:23:12 -0700551if test "x$enable_prof" = "x1" ; then
552 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800553else
Jason Evans77f350b2011-03-15 22:23:12 -0700554 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800555fi
Jason Evans77f350b2011-03-15 22:23:12 -0700556
Jason Evans6109fe02010-02-10 10:37:56 -0800557AC_ARG_ENABLE([prof-libunwind],
558 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
559[if test "x$enable_prof_libunwind" = "xno" ; then
560 enable_prof_libunwind="0"
561else
562 enable_prof_libunwind="1"
563fi
564],
565[enable_prof_libunwind="0"]
566)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800567AC_ARG_WITH([static_libunwind],
568 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
569 [Path to static libunwind library; use rather than dynamically linking])],
570if test "x$with_static_libunwind" = "xno" ; then
571 LUNWIND="-lunwind"
572else
573 if test ! -f "$with_static_libunwind" ; then
574 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
575 fi
576 LUNWIND="$with_static_libunwind"
577fi,
578 LUNWIND="-lunwind"
579)
Jason Evans77f350b2011-03-15 22:23:12 -0700580if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
581 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
582 if test "x$LUNWIND" = "x-lunwind" ; then
583 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
584 [enable_prof_libunwind="0"])
585 else
586 LIBS="$LIBS $LUNWIND"
587 fi
588 if test "x${enable_prof_libunwind}" = "x1" ; then
589 backtrace_method="libunwind"
590 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
591 fi
592fi
593
594AC_ARG_ENABLE([prof-libgcc],
595 [AS_HELP_STRING([--disable-prof-libgcc],
596 [Do not use libgcc for backtracing])],
597[if test "x$enable_prof_libgcc" = "xno" ; then
598 enable_prof_libgcc="0"
599else
600 enable_prof_libgcc="1"
601fi
602],
603[enable_prof_libgcc="1"]
604)
605if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
606 -a "x$GCC" = "xyes" ; then
607 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
608 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
609 dnl The following is conservative, in that it only has entries for CPUs on
610 dnl which jemalloc has been tested.
611 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
612 case "${host_cpu}" in
613 i[[3456]]86)
614 AC_MSG_RESULT([unreliable])
615 enable_prof_libgcc="0";
616 ;;
617 x86_64)
618 AC_MSG_RESULT([reliable])
619 ;;
620 *)
621 AC_MSG_RESULT([unreliable])
622 enable_prof_libgcc="0";
623 ;;
624 esac
625 if test "x${enable_prof_libgcc}" = "x1" ; then
626 backtrace_method="libgcc"
627 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
628 fi
629else
630 enable_prof_libgcc="0"
631fi
632
633AC_ARG_ENABLE([prof-gcc],
634 [AS_HELP_STRING([--disable-prof-gcc],
635 [Do not use gcc intrinsics for backtracing])],
636[if test "x$enable_prof_gcc" = "xno" ; then
637 enable_prof_gcc="0"
638else
639 enable_prof_gcc="1"
640fi
641],
642[enable_prof_gcc="1"]
643)
644if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
645 -a "x$GCC" = "xyes" ; then
646 backtrace_method="gcc intrinsics"
647 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
648else
649 enable_prof_gcc="0"
650fi
651
652if test "x$backtrace_method" = "x" ; then
653 backtrace_method="none (disabling profiling)"
654 enable_prof="0"
655fi
656AC_MSG_CHECKING([configured backtracing method])
657AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700658if test "x$enable_prof" = "x1" ; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700659 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700660fi
661AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700662
Jason Evans84cbbcb2009-12-29 00:09:15 -0800663dnl Enable thread-specific caching by default.
664AC_ARG_ENABLE([tcache],
665 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
666[if test "x$enable_tcache" = "xno" ; then
667 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700668else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800669 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700670fi
671],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800672[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700673)
Jason Evans2dbecf12010-09-05 10:35:13 -0700674if test "x$enable_tcache" = "x1" ; then
675 AC_DEFINE([JEMALLOC_TCACHE], [ ])
676fi
677AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700678
Jason Evans59ae2762012-04-16 17:52:27 -0700679dnl Enable VM deallocation via munmap() by default.
680AC_ARG_ENABLE([munmap],
681 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
682[if test "x$enable_munmap" = "xno" ; then
683 enable_munmap="0"
684else
685 enable_munmap="1"
686fi
687],
688[enable_munmap="${default_munmap}"]
689)
690if test "x$enable_munmap" = "x1" ; then
691 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
692fi
693AC_SUBST([enable_munmap])
694
Jason Evansb7924f52009-06-23 19:01:18 -0700695dnl Do not enable allocation from DSS by default.
696AC_ARG_ENABLE([dss],
697 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
698[if test "x$enable_dss" = "xno" ; then
699 enable_dss="0"
700else
701 enable_dss="1"
702fi
703],
704[enable_dss="0"]
705)
Mike Hommey83c324a2012-04-12 10:13:03 +0200706dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
707AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
708if test "x$have_sbrk" = "x1" ; then
709 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
710else
711 enable_dss="0"
712fi
713
Jason Evansb7924f52009-06-23 19:01:18 -0700714if test "x$enable_dss" = "x1" ; then
715 AC_DEFINE([JEMALLOC_DSS], [ ])
716fi
717AC_SUBST([enable_dss])
718
Jason Evans777c1912012-02-28 20:49:22 -0800719dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700720AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700721 [AS_HELP_STRING([--disable-fill],
722 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700723[if test "x$enable_fill" = "xno" ; then
724 enable_fill="0"
725else
726 enable_fill="1"
727fi
728],
Jason Evans777c1912012-02-28 20:49:22 -0800729[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700730)
731if test "x$enable_fill" = "x1" ; then
732 AC_DEFINE([JEMALLOC_FILL], [ ])
733fi
734AC_SUBST([enable_fill])
735
Jason Evansb1476112012-04-05 13:36:17 -0700736dnl Disable utrace(2)-based tracing by default.
737AC_ARG_ENABLE([utrace],
738 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
739[if test "x$enable_utrace" = "xno" ; then
740 enable_utrace="0"
741else
742 enable_utrace="1"
743fi
744],
745[enable_utrace="0"]
746)
747JE_COMPILABLE([utrace(2)], [
748#include <sys/types.h>
749#include <sys/param.h>
750#include <sys/time.h>
751#include <sys/uio.h>
752#include <sys/ktrace.h>
753], [
754 utrace((void *)0, 0);
755], [je_cv_utrace])
756if test "x${je_cv_utrace}" = "xno" ; then
757 enable_utrace="0"
758fi
759if test "x$enable_utrace" = "x1" ; then
760 AC_DEFINE([JEMALLOC_UTRACE], [ ])
761fi
762AC_SUBST([enable_utrace])
763
Jason Evans122449b2012-04-06 00:35:09 -0700764dnl Support Valgrind by default.
765AC_ARG_ENABLE([valgrind],
766 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
767[if test "x$enable_valgrind" = "xno" ; then
768 enable_valgrind="0"
769else
770 enable_valgrind="1"
771fi
772],
773[enable_valgrind="1"]
774)
775if test "x$enable_valgrind" = "x1" ; then
776 JE_COMPILABLE([valgrind], [
777#include <valgrind/valgrind.h>
778#include <valgrind/memcheck.h>
779
780#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
781 && (__VALGRIND_MAJOR__ > 3 || (__VALGRIND_MAJOR__ == 3 && \
782 __VALGRIND_MINOR__ >= 6))
783#else
784# error "Incompatible Valgrind version"
785#endif
786], [], [je_cv_valgrind])
787 if test "x${je_cv_valgrind}" = "xno" ; then
788 enable_valgrind="0"
789 fi
790 if test "x$enable_valgrind" = "x1" ; then
791 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
792 fi
793fi
794AC_SUBST([enable_valgrind])
795
Jason Evansb7924f52009-06-23 19:01:18 -0700796dnl Do not support the xmalloc option by default.
797AC_ARG_ENABLE([xmalloc],
798 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
799[if test "x$enable_xmalloc" = "xno" ; then
800 enable_xmalloc="0"
801else
802 enable_xmalloc="1"
803fi
804],
805[enable_xmalloc="0"]
806)
807if test "x$enable_xmalloc" = "x1" ; then
808 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
809fi
810AC_SUBST([enable_xmalloc])
811
Jason Evans6684cac2012-03-05 12:15:36 -0800812AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
813 [je_cv_static_page_shift],
814 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansb7924f52009-06-23 19:01:18 -0700815[[#include <stdio.h>
816#include <unistd.h>
817#include <strings.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800818]],
819[[
Jason Evansb7924f52009-06-23 19:01:18 -0700820 long result;
821 FILE *f;
822
823 result = sysconf(_SC_PAGESIZE);
824 if (result == -1) {
825 return 1;
826 }
827 f = fopen("conftest.out", "w");
828 if (f == NULL) {
829 return 1;
830 }
831 fprintf(f, "%u\n", ffs((int)result) - 1);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700832 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700833
834 return 0;
835]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800836 [je_cv_static_page_shift=`cat conftest.out`],
837 [je_cv_static_page_shift=undefined]))
838
839if test "x$je_cv_static_page_shift" != "xundefined"; then
840 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
841else
842 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
843fi
Jason Evansb7924f52009-06-23 19:01:18 -0700844
845dnl ============================================================================
846dnl jemalloc configuration.
847dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800848
849dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700850if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700851 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800852fi
Jason Evansb7924f52009-06-23 19:01:18 -0700853jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800854jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
855jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
856jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
857jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
858jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700859AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800860AC_SUBST([jemalloc_version_major])
861AC_SUBST([jemalloc_version_minor])
862AC_SUBST([jemalloc_version_bugfix])
863AC_SUBST([jemalloc_version_nrev])
864AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700865
866dnl ============================================================================
867dnl Configure pthreads.
868
869AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
Jason Evans39006f92012-03-16 16:57:02 -0700870dnl Some systems may embed pthreads functionality in libc; check for libpthread
871dnl first, but try libc too before failing.
Jason Evansb7924f52009-06-23 19:01:18 -0700872AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
Jason Evans39006f92012-03-16 16:57:02 -0700873 [AC_SEARCH_LIBS([pthread_create], , ,
874 AC_MSG_ERROR([libpthread is missing]))])
Jason Evansb7924f52009-06-23 19:01:18 -0700875
876CPPFLAGS="$CPPFLAGS -D_REENTRANT"
877
Jason Evanscd9a1342012-03-21 18:33:03 -0700878dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
879dnl it rather than pthreads TSD cleanup functions to support cleanup during
880dnl thread exit, in order to avoid pthreads library recursion during
881dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -0700882AC_CHECK_FUNC([_malloc_thread_cleanup],
883 [have__malloc_thread_cleanup="1"],
884 [have__malloc_thread_cleanup="0"]
885 )
886if test "x$have__malloc_thread_cleanup" = "x1" ; then
887 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
888 force_tls="1"
889fi
890
Jason Evans41b6afb2012-02-02 22:04:57 -0800891dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
892dnl so, mutex initialization causes allocation, and we need to implement this
893dnl callback function in order to prevent recursive allocation.
894AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
895 [have__pthread_mutex_init_calloc_cb="1"],
896 [have__pthread_mutex_init_calloc_cb="0"]
897 )
898if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
899 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
900fi
901
Jason Evans0fee70d2012-02-13 12:36:11 -0800902dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700903AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -0800904 [AS_HELP_STRING([--enable-lazy-lock],
905 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700906[if test "x$enable_lazy_lock" = "xno" ; then
907 enable_lazy_lock="0"
908else
909 enable_lazy_lock="1"
910fi
911],
Jason Evans0fee70d2012-02-13 12:36:11 -0800912[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -0700913)
Jason Evansfd4fcef2012-03-23 17:40:58 -0700914if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
915 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
916 enable_lazy_lock="1"
917fi
Jason Evansb7924f52009-06-23 19:01:18 -0700918if test "x$enable_lazy_lock" = "x1" ; then
919 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
Jason Evans650285d2012-03-19 10:25:27 -0700920 AC_CHECK_FUNC([dlsym], [],
921 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
922 [AC_MSG_ERROR([libdl is missing])])
923 ])
Jason Evansb7924f52009-06-23 19:01:18 -0700924 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
925fi
926AC_SUBST([enable_lazy_lock])
927
Jason Evans78d815c2010-01-17 14:06:20 -0800928AC_ARG_ENABLE([tls],
929 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
930if test "x$enable_tls" = "xno" ; then
931 enable_tls="0"
932else
933 enable_tls="1"
934fi
935,
936enable_tls="1"
937)
Jason Evanscd9a1342012-03-21 18:33:03 -0700938if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
939 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
940 enable_tls="1"
941fi
Jason Evansb80581d2012-03-23 16:17:43 -0700942if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
943 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
944 enable_tls="0"
945fi
Jason Evans78d815c2010-01-17 14:06:20 -0800946if test "x${enable_tls}" = "x1" ; then
947AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -0800948AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -0800949[[
950 __thread int x;
951]], [[
952 x = 42;
953
954 return 0;
955]])],
956 AC_MSG_RESULT([yes]),
957 AC_MSG_RESULT([no])
958 enable_tls="0")
959fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700960AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -0700961if test "x${enable_tls}" = "x1" ; then
962 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -0700963elif test "x${force_tls}" = "x1" ; then
964 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -0800965fi
966
Jason Evans2dbecf12010-09-05 10:35:13 -0700967dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700968dnl Check for ffsl(3), and fail if not found. This function exists on all
969dnl platforms that jemalloc currently has a chance of functioning on without
970dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -0700971JE_COMPILABLE([a program using ffsl], [
Jason Evans382132e2012-04-04 15:25:43 -0700972#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -0700973#include <string.h>
974], [
975 {
976 int rv = ffsl(0x08);
977 }
978], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -0800979if test "x${je_cv_function_ffsl}" != "xyes" ; then
980 AC_MSG_ERROR([Cannot build without ffsl(3)])
981fi
Jason Evans84c8eef2011-03-16 10:30:13 -0700982
983dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -0700984dnl Check for atomic(3) operations as provided on Darwin.
985
986JE_COMPILABLE([Darwin OSAtomic*()], [
987#include <libkern/OSAtomic.h>
988#include <inttypes.h>
989], [
990 {
991 int32_t x32 = 0;
992 volatile int32_t *x32p = &x32;
993 OSAtomicAdd32(1, x32p);
994 }
995 {
996 int64_t x64 = 0;
997 volatile int64_t *x64p = &x64;
998 OSAtomicAdd64(1, x64p);
999 }
Jason Evans6684cac2012-03-05 12:15:36 -08001000], [je_cv_osatomic])
1001if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001002 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001003fi
1004
1005dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001006dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1007dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1008
1009AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1010 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1011 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001012 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1013 #include <stdint.h>
1014 ],
1015 [
1016 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1017 {
1018 uint$1_t x$1 = 0;
1019 __sync_add_and_fetch(&x$1, 42);
1020 __sync_sub_and_fetch(&x$1, 1);
1021 }
1022 #else
1023 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1024 #endif
1025 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001026 [je_cv_sync_compare_and_swap_$2=yes],
1027 [je_cv_sync_compare_and_swap_$2=no])])
1028
1029 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1030 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1031 fi
1032])
1033
1034if test "x${je_cv_osatomic}" != "xyes" ; then
1035 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1036 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1037fi
1038
1039dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001040dnl Check for spinlock(3) operations as provided on Darwin.
1041
1042JE_COMPILABLE([Darwin OSSpin*()], [
1043#include <libkern/OSAtomic.h>
1044#include <inttypes.h>
1045], [
1046 OSSpinLock lock = 0;
1047 OSSpinLockLock(&lock);
1048 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001049], [je_cv_osspin])
1050if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001051 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001052fi
1053
1054dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001055dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001056
Jason Evans2dbecf12010-09-05 10:35:13 -07001057if test "x${abi}" = "xmacho" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001058 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1059 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001060
Jason Evans2dbecf12010-09-05 10:35:13 -07001061 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1062 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1063 dnl 10.6, which is the only source-level indication of the change.
1064 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001065 AC_DEFUN([JE_ZONE_PROGRAM],
1066 [AC_LANG_PROGRAM(
1067 [#include <malloc/malloc.h>],
1068 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1069 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001070
Mike Hommey154829d2012-03-20 18:01:38 +01001071 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1072 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1073 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1074 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1075 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1076 )])],[
1077 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1078 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1079 )])])])])
1080 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1081 AC_MSG_RESULT([unsupported])
1082 AC_MSG_ERROR([Unsupported malloc zone version])
1083 fi
1084 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1085 JEMALLOC_ZONE_VERSION=8
1086 AC_MSG_RESULT([> 8])
1087 else
1088 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1089 fi
1090 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001091fi
1092
Jason Evansb7924f52009-06-23 19:01:18 -07001093dnl ============================================================================
1094dnl Check for typedefs, structures, and compiler characteristics.
1095AC_HEADER_STDBOOL
1096
Jason Evansb1726102012-02-28 16:50:47 -08001097AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1098 mkdir -p "include/jemalloc/internal"
1099 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1100])
1101
Jason Evansb7924f52009-06-23 19:01:18 -07001102dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001103AC_SUBST([cfghdrs_in])
1104AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001105AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001106
1107dnl ============================================================================
1108dnl Generate outputs.
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001109AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001110AC_SUBST([cfgoutputs_in])
1111AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001112AC_OUTPUT
1113
1114dnl ============================================================================
1115dnl Print out the results of configuration.
1116AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001117AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1118AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001119AC_MSG_RESULT([])
1120AC_MSG_RESULT([CC : ${CC}])
1121AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1122AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1123AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1124AC_MSG_RESULT([LIBS : ${LIBS}])
1125AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1126AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001127AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1128AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1129AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001130AC_MSG_RESULT([PREFIX : ${PREFIX}])
1131AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001132AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1133AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001134AC_MSG_RESULT([DATADIR : ${DATADIR}])
1135AC_MSG_RESULT([MANDIR : ${MANDIR}])
1136AC_MSG_RESULT([])
1137AC_MSG_RESULT([srcroot : ${srcroot}])
1138AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1139AC_MSG_RESULT([objroot : ${objroot}])
1140AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1141AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001142AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001143AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1144AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001145AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001146AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001147AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001148AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001149AC_MSG_RESULT([debug : ${enable_debug}])
1150AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001151AC_MSG_RESULT([prof : ${enable_prof}])
1152AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001153AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1154AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001155AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001156AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001157AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001158AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1159AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001160AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001161AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001162AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001163AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001164AC_MSG_RESULT([===============================================================================])