blob: 0f0de905f6ceeec9d136ea73399f945404d0b90e [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)'
Mike Hommey85221d52012-04-18 18:29:40 +0200204SOREV='$(SO).$(REV)'
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400205
Jason Evans7372b152012-02-10 20:22:09 -0800206dnl Heap profiling uses the log(3) function.
207LIBS="$LIBS -lm"
208
Jason Evansb7924f52009-06-23 19:01:18 -0700209dnl Platform-specific settings. abi and RPATH can probably be determined
210dnl programmatically, but doing so is error-prone, which makes it generally
211dnl not worth the trouble.
212dnl
213dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
214dnl definitions need to be seen before any headers are included, which is a pain
215dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700216default_munmap="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700217case "${host}" in
218 *-*-darwin*)
Jason Evans9022bf92012-03-23 16:14:08 -0700219 CFLAGS="$CFLAGS -fno-common"
Jason Evansb7924f52009-06-23 19:01:18 -0700220 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700221 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700222 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400223 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700224 so="dylib"
Jason Evansb80581d2012-03-23 16:17:43 -0700225 force_tls="0"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200226 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
Mike Hommey85221d52012-04-18 18:29:40 +0200227 SOREV='$(REV).$(SO)'
Jason Evansb7924f52009-06-23 19:01:18 -0700228 ;;
229 *-*-freebsd*)
230 CFLAGS="$CFLAGS"
231 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700232 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700233 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700234 ;;
235 *-*-linux*)
236 CFLAGS="$CFLAGS"
237 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
238 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700239 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700240 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700241 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700242 ;;
243 *-*-netbsd*)
244 AC_MSG_CHECKING([ABI])
245 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
246[[#ifdef __ELF__
247/* ELF */
248#else
249#error aout
250#endif
251]])],
252 [CFLAGS="$CFLAGS"; abi="elf"],
253 [abi="aout"])
254 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700255 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700256 ;;
257 *-*-solaris2*)
258 CFLAGS="$CFLAGS"
259 abi="elf"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200260 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700261 dnl Solaris needs this for sigwait().
262 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
263 LIBS="$LIBS -lposix4 -lsocket -lnsl"
264 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400265 *-ibm-aix*)
266 if "$LG_SIZEOF_PTR" = "8"; then
267 dnl 64bit AIX
268 LD_PRELOAD_VAR="LDR_PRELOAD64"
269 else
270 dnl 32bit AIX
271 LD_PRELOAD_VAR="LDR_PRELOAD"
272 fi
273 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400274 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700275 *)
276 AC_MSG_RESULT([Unsupported operating system: ${host}])
277 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700278 ;;
279esac
280AC_SUBST([abi])
281AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400282AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700283AC_SUBST([so])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200284AC_SUBST([o])
285AC_SUBST([a])
286AC_SUBST([exe])
287AC_SUBST([lib])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200288AC_SUBST([DSO_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200289AC_SUBST([SOREV])
Jason Evansb7924f52009-06-23 19:01:18 -0700290
Jason Evansfa5d2452011-03-15 10:25:59 -0700291JE_COMPILABLE([__attribute__ syntax],
292 [static __attribute__((unused)) void foo(void){}],
293 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800294 [je_cv_attribute])
295if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700296 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
297 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
298 JE_CFLAGS_APPEND([-fvisibility=hidden])
299 fi
300fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700301dnl Check for tls_model attribute support (clang 3.0 still lacks support).
302SAVED_CFLAGS="${CFLAGS}"
303JE_CFLAGS_APPEND([-Werror])
304JE_COMPILABLE([tls_model attribute], [],
305 [static __thread int
306 __attribute__((tls_model("initial-exec"))) foo;
307 foo = 0;],
308 [je_cv_tls_model])
309CFLAGS="${SAVED_CFLAGS}"
310if test "x${je_cv_tls_model}" = "xyes" ; then
311 AC_DEFINE([JEMALLOC_TLS_MODEL],
312 [__attribute__((tls_model("initial-exec")))])
313else
314 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
315fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700316
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800317JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
318#define _GNU_SOURCE
319#include <sys/mman.h>
320], [
321void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
Jason Evans6684cac2012-03-05 12:15:36 -0800322], [je_cv_mremap_fixed])
323if test "x${je_cv_mremap_fixed}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700324 AC_DEFINE([JEMALLOC_MREMAP_FIXED], [ ])
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800325fi
326
Jason Evansb7924f52009-06-23 19:01:18 -0700327dnl Support optional additions to rpath.
328AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800329 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700330if test "x$with_rpath" = "xno" ; then
331 RPATH_EXTRA=
332else
333 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
334fi,
335 RPATH_EXTRA=
336)
337AC_SUBST([RPATH_EXTRA])
338
339dnl Disable rules that do automatic regeneration of configure output by default.
340AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800341 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700342if test "x$enable_autogen" = "xno" ; then
343 enable_autogen="0"
344else
345 enable_autogen="1"
346fi
347,
348enable_autogen="0"
349)
350AC_SUBST([enable_autogen])
351
352AC_PROG_INSTALL
353AC_PROG_RANLIB
354AC_PATH_PROG([AR], [ar], , [$PATH])
355AC_PATH_PROG([LD], [ld], , [$PATH])
356AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
357
Jason Evans0a0bbf62012-03-13 12:55:21 -0700358public_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 -0800359
360dnl Check for allocator-related functions that should be wrapped.
361AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700362 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800363 public_syms="${public_syms} memalign"])
364AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700365 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800366 public_syms="${public_syms} valloc"])
367
368dnl Support the experimental API by default.
369AC_ARG_ENABLE([experimental],
370 [AS_HELP_STRING([--disable-experimental],
371 [Disable support for the experimental API])],
372[if test "x$enable_experimental" = "xno" ; then
373 enable_experimental="0"
374else
375 enable_experimental="1"
376fi
377],
378[enable_experimental="1"]
379)
380if test "x$enable_experimental" = "x1" ; then
381 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
382 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
383fi
384AC_SUBST([enable_experimental])
385
Jason Evans0a5489e2012-03-01 17:19:20 -0800386dnl Perform no name mangling by default.
387AC_ARG_WITH([mangling],
388 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
389 [mangling_map="$with_mangling"], [mangling_map=""])
390for nm in `echo ${mangling_map} |tr ',' ' '` ; do
Jason Evans08fc3b22012-03-12 15:07:53 -0700391 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
392 n="je_${k}"
Jason Evans0a5489e2012-03-01 17:19:20 -0800393 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
394 AC_DEFINE_UNQUOTED([${n}], [${m}])
Jason Evans08fc3b22012-03-12 15:07:53 -0700395 dnl Remove key from public_syms so that it isn't redefined later.
396 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
Jason Evans0a5489e2012-03-01 17:19:20 -0800397done
398
Jason Evans90895cf2009-12-29 00:09:15 -0800399dnl Do not prefix public APIs by default.
400AC_ARG_WITH([jemalloc_prefix],
401 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800402 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700403 [if test "x$abi" != "xmacho" ; then
404 JEMALLOC_PREFIX=""
405else
406 JEMALLOC_PREFIX="je_"
407fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800408)
409if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700410 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
411 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
412 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800413fi
Jason Evans0a5489e2012-03-01 17:19:20 -0800414dnl Generate macros to rename public symbols. All public symbols are prefixed
415dnl with je_ in the source code, so these macro definitions are needed even if
416dnl --with-jemalloc-prefix wasn't specified.
Jason Evans7e77eaf2012-03-02 17:47:37 -0800417for stem in ${public_syms}; do
Jason Evans0a5489e2012-03-01 17:19:20 -0800418 n="je_${stem}"
419 m="${JEMALLOC_PREFIX}${stem}"
420 AC_DEFINE_UNQUOTED([${n}], [${m}])
421done
Jason Evans90895cf2009-12-29 00:09:15 -0800422
Jason Evans746e77a2011-07-30 16:40:52 -0700423dnl Do not mangle library-private APIs by default.
424AC_ARG_WITH([private_namespace],
425 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
426 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
427 [JEMALLOC_PRIVATE_NAMESPACE=""]
428)
429AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
430if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
431 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])
432else
433 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])
434fi
435
Jason Evansb0fd5012010-01-17 01:49:20 -0800436dnl Do not add suffix to installed files by default.
437AC_ARG_WITH([install_suffix],
438 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
439 [INSTALL_SUFFIX="$with_install_suffix"],
440 [INSTALL_SUFFIX=]
441)
442install_suffix="$INSTALL_SUFFIX"
443AC_SUBST([install_suffix])
444
Jason Evansaee7fd22010-11-24 22:00:02 -0800445cfgoutputs_in="${srcroot}Makefile.in"
446cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
447cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
448cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700449cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
450cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700451cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800452
Jason Evansaee7fd22010-11-24 22:00:02 -0800453cfgoutputs_out="Makefile"
454cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
455cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
456cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
Jason Evans376b1522010-02-11 14:45:59 -0800457cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
458cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700459cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800460
Jason Evansaee7fd22010-11-24 22:00:02 -0800461cfgoutputs_tup="Makefile"
462cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
463cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
464cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
Jason Evans376b1522010-02-11 14:45:59 -0800465cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
466cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700467cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800468
Jason Evans0656ec02010-04-07 23:37:35 -0700469cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb1726102012-02-28 16:50:47 -0800470cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansb0fd5012010-01-17 01:49:20 -0800471
Jason Evans376b1522010-02-11 14:45:59 -0800472cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb1726102012-02-28 16:50:47 -0800473cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800474
Jason Evans376b1522010-02-11 14:45:59 -0800475cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800476
Jason Evans355b4382010-09-20 19:20:48 -0700477dnl Do not silence irrelevant compiler warnings by default, since enabling this
478dnl option incurs a performance penalty.
479AC_ARG_ENABLE([cc-silence],
480 [AS_HELP_STRING([--enable-cc-silence],
481 [Silence irrelevant compiler warnings])],
482[if test "x$enable_cc_silence" = "xno" ; then
483 enable_cc_silence="0"
484else
485 enable_cc_silence="1"
486fi
487],
488[enable_cc_silence="0"]
489)
490if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700491 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700492fi
493
Jason Evansb7924f52009-06-23 19:01:18 -0700494dnl Do not compile with debugging by default.
495AC_ARG_ENABLE([debug],
496 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
497[if test "x$enable_debug" = "xno" ; then
498 enable_debug="0"
499else
500 enable_debug="1"
501fi
502],
503[enable_debug="0"]
504)
505if test "x$enable_debug" = "x1" ; then
506 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700507 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700508fi
509AC_SUBST([enable_debug])
510
511dnl Only optimize if not debugging.
512if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
513 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700514 optimize="no"
515 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
516 if test "x${optimize}" = "xyes" ; then
517 if test "x$GCC" = "xyes" ; then
518 JE_CFLAGS_APPEND([-O3])
519 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700520 else
521 JE_CFLAGS_APPEND([-O])
522 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700523 fi
524fi
525
Jason Evansd073a322012-02-28 20:41:16 -0800526dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700527AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800528 [AS_HELP_STRING([--disable-stats],
529 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700530[if test "x$enable_stats" = "xno" ; then
531 enable_stats="0"
532else
533 enable_stats="1"
534fi
535],
Jason Evansd073a322012-02-28 20:41:16 -0800536[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700537)
538if test "x$enable_stats" = "x1" ; then
539 AC_DEFINE([JEMALLOC_STATS], [ ])
540fi
541AC_SUBST([enable_stats])
542
Jason Evans6109fe02010-02-10 10:37:56 -0800543dnl Do not enable profiling by default.
544AC_ARG_ENABLE([prof],
545 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
546[if test "x$enable_prof" = "xno" ; then
547 enable_prof="0"
548else
549 enable_prof="1"
550fi
551],
552[enable_prof="0"]
553)
Jason Evans77f350b2011-03-15 22:23:12 -0700554if test "x$enable_prof" = "x1" ; then
555 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800556else
Jason Evans77f350b2011-03-15 22:23:12 -0700557 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800558fi
Jason Evans77f350b2011-03-15 22:23:12 -0700559
Jason Evans6109fe02010-02-10 10:37:56 -0800560AC_ARG_ENABLE([prof-libunwind],
561 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
562[if test "x$enable_prof_libunwind" = "xno" ; then
563 enable_prof_libunwind="0"
564else
565 enable_prof_libunwind="1"
566fi
567],
568[enable_prof_libunwind="0"]
569)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800570AC_ARG_WITH([static_libunwind],
571 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
572 [Path to static libunwind library; use rather than dynamically linking])],
573if test "x$with_static_libunwind" = "xno" ; then
574 LUNWIND="-lunwind"
575else
576 if test ! -f "$with_static_libunwind" ; then
577 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
578 fi
579 LUNWIND="$with_static_libunwind"
580fi,
581 LUNWIND="-lunwind"
582)
Jason Evans77f350b2011-03-15 22:23:12 -0700583if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
584 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
585 if test "x$LUNWIND" = "x-lunwind" ; then
586 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
587 [enable_prof_libunwind="0"])
588 else
589 LIBS="$LIBS $LUNWIND"
590 fi
591 if test "x${enable_prof_libunwind}" = "x1" ; then
592 backtrace_method="libunwind"
593 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
594 fi
595fi
596
597AC_ARG_ENABLE([prof-libgcc],
598 [AS_HELP_STRING([--disable-prof-libgcc],
599 [Do not use libgcc for backtracing])],
600[if test "x$enable_prof_libgcc" = "xno" ; then
601 enable_prof_libgcc="0"
602else
603 enable_prof_libgcc="1"
604fi
605],
606[enable_prof_libgcc="1"]
607)
608if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
609 -a "x$GCC" = "xyes" ; then
610 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
611 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
612 dnl The following is conservative, in that it only has entries for CPUs on
613 dnl which jemalloc has been tested.
614 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
615 case "${host_cpu}" in
616 i[[3456]]86)
617 AC_MSG_RESULT([unreliable])
618 enable_prof_libgcc="0";
619 ;;
620 x86_64)
621 AC_MSG_RESULT([reliable])
622 ;;
623 *)
624 AC_MSG_RESULT([unreliable])
625 enable_prof_libgcc="0";
626 ;;
627 esac
628 if test "x${enable_prof_libgcc}" = "x1" ; then
629 backtrace_method="libgcc"
630 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
631 fi
632else
633 enable_prof_libgcc="0"
634fi
635
636AC_ARG_ENABLE([prof-gcc],
637 [AS_HELP_STRING([--disable-prof-gcc],
638 [Do not use gcc intrinsics for backtracing])],
639[if test "x$enable_prof_gcc" = "xno" ; then
640 enable_prof_gcc="0"
641else
642 enable_prof_gcc="1"
643fi
644],
645[enable_prof_gcc="1"]
646)
647if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
648 -a "x$GCC" = "xyes" ; then
649 backtrace_method="gcc intrinsics"
650 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
651else
652 enable_prof_gcc="0"
653fi
654
655if test "x$backtrace_method" = "x" ; then
656 backtrace_method="none (disabling profiling)"
657 enable_prof="0"
658fi
659AC_MSG_CHECKING([configured backtracing method])
660AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700661if test "x$enable_prof" = "x1" ; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700662 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700663fi
664AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700665
Jason Evans84cbbcb2009-12-29 00:09:15 -0800666dnl Enable thread-specific caching by default.
667AC_ARG_ENABLE([tcache],
668 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
669[if test "x$enable_tcache" = "xno" ; then
670 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700671else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800672 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700673fi
674],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800675[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700676)
Jason Evans2dbecf12010-09-05 10:35:13 -0700677if test "x$enable_tcache" = "x1" ; then
678 AC_DEFINE([JEMALLOC_TCACHE], [ ])
679fi
680AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700681
Jason Evans59ae2762012-04-16 17:52:27 -0700682dnl Enable VM deallocation via munmap() by default.
683AC_ARG_ENABLE([munmap],
684 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
685[if test "x$enable_munmap" = "xno" ; then
686 enable_munmap="0"
687else
688 enable_munmap="1"
689fi
690],
691[enable_munmap="${default_munmap}"]
692)
693if test "x$enable_munmap" = "x1" ; then
694 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
695fi
696AC_SUBST([enable_munmap])
697
Jason Evansb7924f52009-06-23 19:01:18 -0700698dnl Do not enable allocation from DSS by default.
699AC_ARG_ENABLE([dss],
700 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
701[if test "x$enable_dss" = "xno" ; then
702 enable_dss="0"
703else
704 enable_dss="1"
705fi
706],
707[enable_dss="0"]
708)
Mike Hommey83c324a2012-04-12 10:13:03 +0200709dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
710AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
711if test "x$have_sbrk" = "x1" ; then
712 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
713else
714 enable_dss="0"
715fi
716
Jason Evansb7924f52009-06-23 19:01:18 -0700717if test "x$enable_dss" = "x1" ; then
718 AC_DEFINE([JEMALLOC_DSS], [ ])
719fi
720AC_SUBST([enable_dss])
721
Jason Evans777c1912012-02-28 20:49:22 -0800722dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700723AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700724 [AS_HELP_STRING([--disable-fill],
725 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700726[if test "x$enable_fill" = "xno" ; then
727 enable_fill="0"
728else
729 enable_fill="1"
730fi
731],
Jason Evans777c1912012-02-28 20:49:22 -0800732[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700733)
734if test "x$enable_fill" = "x1" ; then
735 AC_DEFINE([JEMALLOC_FILL], [ ])
736fi
737AC_SUBST([enable_fill])
738
Jason Evansb1476112012-04-05 13:36:17 -0700739dnl Disable utrace(2)-based tracing by default.
740AC_ARG_ENABLE([utrace],
741 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
742[if test "x$enable_utrace" = "xno" ; then
743 enable_utrace="0"
744else
745 enable_utrace="1"
746fi
747],
748[enable_utrace="0"]
749)
750JE_COMPILABLE([utrace(2)], [
751#include <sys/types.h>
752#include <sys/param.h>
753#include <sys/time.h>
754#include <sys/uio.h>
755#include <sys/ktrace.h>
756], [
757 utrace((void *)0, 0);
758], [je_cv_utrace])
759if test "x${je_cv_utrace}" = "xno" ; then
760 enable_utrace="0"
761fi
762if test "x$enable_utrace" = "x1" ; then
763 AC_DEFINE([JEMALLOC_UTRACE], [ ])
764fi
765AC_SUBST([enable_utrace])
766
Jason Evans122449b2012-04-06 00:35:09 -0700767dnl Support Valgrind by default.
768AC_ARG_ENABLE([valgrind],
769 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
770[if test "x$enable_valgrind" = "xno" ; then
771 enable_valgrind="0"
772else
773 enable_valgrind="1"
774fi
775],
776[enable_valgrind="1"]
777)
778if test "x$enable_valgrind" = "x1" ; then
779 JE_COMPILABLE([valgrind], [
780#include <valgrind/valgrind.h>
781#include <valgrind/memcheck.h>
782
783#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
784 && (__VALGRIND_MAJOR__ > 3 || (__VALGRIND_MAJOR__ == 3 && \
785 __VALGRIND_MINOR__ >= 6))
786#else
787# error "Incompatible Valgrind version"
788#endif
789], [], [je_cv_valgrind])
790 if test "x${je_cv_valgrind}" = "xno" ; then
791 enable_valgrind="0"
792 fi
793 if test "x$enable_valgrind" = "x1" ; then
794 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
795 fi
796fi
797AC_SUBST([enable_valgrind])
798
Jason Evansb7924f52009-06-23 19:01:18 -0700799dnl Do not support the xmalloc option by default.
800AC_ARG_ENABLE([xmalloc],
801 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
802[if test "x$enable_xmalloc" = "xno" ; then
803 enable_xmalloc="0"
804else
805 enable_xmalloc="1"
806fi
807],
808[enable_xmalloc="0"]
809)
810if test "x$enable_xmalloc" = "x1" ; then
811 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
812fi
813AC_SUBST([enable_xmalloc])
814
Jason Evans6684cac2012-03-05 12:15:36 -0800815AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
816 [je_cv_static_page_shift],
817 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansb7924f52009-06-23 19:01:18 -0700818[[#include <stdio.h>
819#include <unistd.h>
820#include <strings.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800821]],
822[[
Jason Evansb7924f52009-06-23 19:01:18 -0700823 long result;
824 FILE *f;
825
826 result = sysconf(_SC_PAGESIZE);
827 if (result == -1) {
828 return 1;
829 }
830 f = fopen("conftest.out", "w");
831 if (f == NULL) {
832 return 1;
833 }
834 fprintf(f, "%u\n", ffs((int)result) - 1);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700835 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700836
837 return 0;
838]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800839 [je_cv_static_page_shift=`cat conftest.out`],
840 [je_cv_static_page_shift=undefined]))
841
842if test "x$je_cv_static_page_shift" != "xundefined"; then
843 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
844else
845 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
846fi
Jason Evansb7924f52009-06-23 19:01:18 -0700847
848dnl ============================================================================
849dnl jemalloc configuration.
850dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800851
852dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700853if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700854 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800855fi
Jason Evansb7924f52009-06-23 19:01:18 -0700856jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800857jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
858jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
859jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
860jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
861jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700862AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800863AC_SUBST([jemalloc_version_major])
864AC_SUBST([jemalloc_version_minor])
865AC_SUBST([jemalloc_version_bugfix])
866AC_SUBST([jemalloc_version_nrev])
867AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700868
869dnl ============================================================================
870dnl Configure pthreads.
871
872AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
Jason Evans39006f92012-03-16 16:57:02 -0700873dnl Some systems may embed pthreads functionality in libc; check for libpthread
874dnl first, but try libc too before failing.
Jason Evansb7924f52009-06-23 19:01:18 -0700875AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
Jason Evans39006f92012-03-16 16:57:02 -0700876 [AC_SEARCH_LIBS([pthread_create], , ,
877 AC_MSG_ERROR([libpthread is missing]))])
Jason Evansb7924f52009-06-23 19:01:18 -0700878
879CPPFLAGS="$CPPFLAGS -D_REENTRANT"
880
Jason Evanscd9a1342012-03-21 18:33:03 -0700881dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
882dnl it rather than pthreads TSD cleanup functions to support cleanup during
883dnl thread exit, in order to avoid pthreads library recursion during
884dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -0700885AC_CHECK_FUNC([_malloc_thread_cleanup],
886 [have__malloc_thread_cleanup="1"],
887 [have__malloc_thread_cleanup="0"]
888 )
889if test "x$have__malloc_thread_cleanup" = "x1" ; then
890 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
891 force_tls="1"
892fi
893
Jason Evans41b6afb2012-02-02 22:04:57 -0800894dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
895dnl so, mutex initialization causes allocation, and we need to implement this
896dnl callback function in order to prevent recursive allocation.
897AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
898 [have__pthread_mutex_init_calloc_cb="1"],
899 [have__pthread_mutex_init_calloc_cb="0"]
900 )
901if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
902 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
903fi
904
Jason Evans0fee70d2012-02-13 12:36:11 -0800905dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700906AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -0800907 [AS_HELP_STRING([--enable-lazy-lock],
908 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700909[if test "x$enable_lazy_lock" = "xno" ; then
910 enable_lazy_lock="0"
911else
912 enable_lazy_lock="1"
913fi
914],
Jason Evans0fee70d2012-02-13 12:36:11 -0800915[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -0700916)
Jason Evansfd4fcef2012-03-23 17:40:58 -0700917if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
918 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
919 enable_lazy_lock="1"
920fi
Jason Evansb7924f52009-06-23 19:01:18 -0700921if test "x$enable_lazy_lock" = "x1" ; then
922 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
Jason Evans650285d2012-03-19 10:25:27 -0700923 AC_CHECK_FUNC([dlsym], [],
924 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
925 [AC_MSG_ERROR([libdl is missing])])
926 ])
Jason Evansb7924f52009-06-23 19:01:18 -0700927 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
928fi
929AC_SUBST([enable_lazy_lock])
930
Jason Evans78d815c2010-01-17 14:06:20 -0800931AC_ARG_ENABLE([tls],
932 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
933if test "x$enable_tls" = "xno" ; then
934 enable_tls="0"
935else
936 enable_tls="1"
937fi
938,
939enable_tls="1"
940)
Jason Evanscd9a1342012-03-21 18:33:03 -0700941if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
942 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
943 enable_tls="1"
944fi
Jason Evansb80581d2012-03-23 16:17:43 -0700945if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
946 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
947 enable_tls="0"
948fi
Jason Evans78d815c2010-01-17 14:06:20 -0800949if test "x${enable_tls}" = "x1" ; then
950AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -0800951AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -0800952[[
953 __thread int x;
954]], [[
955 x = 42;
956
957 return 0;
958]])],
959 AC_MSG_RESULT([yes]),
960 AC_MSG_RESULT([no])
961 enable_tls="0")
962fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700963AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -0700964if test "x${enable_tls}" = "x1" ; then
965 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -0700966elif test "x${force_tls}" = "x1" ; then
967 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -0800968fi
969
Jason Evans2dbecf12010-09-05 10:35:13 -0700970dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700971dnl Check for ffsl(3), and fail if not found. This function exists on all
972dnl platforms that jemalloc currently has a chance of functioning on without
973dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -0700974JE_COMPILABLE([a program using ffsl], [
Jason Evans382132e2012-04-04 15:25:43 -0700975#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -0700976#include <string.h>
977], [
978 {
979 int rv = ffsl(0x08);
980 }
981], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -0800982if test "x${je_cv_function_ffsl}" != "xyes" ; then
983 AC_MSG_ERROR([Cannot build without ffsl(3)])
984fi
Jason Evans84c8eef2011-03-16 10:30:13 -0700985
986dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -0700987dnl Check for atomic(9) operations as provided on FreeBSD.
988
989JE_COMPILABLE([atomic(9)], [
990#include <sys/types.h>
991#include <machine/atomic.h>
992#include <inttypes.h>
993], [
994 {
995 uint32_t x32 = 0;
996 volatile uint32_t *x32p = &x32;
997 atomic_fetchadd_32(x32p, 1);
998 }
999 {
1000 unsigned long xlong = 0;
1001 volatile unsigned long *xlongp = &xlong;
1002 atomic_fetchadd_long(xlongp, 1);
1003 }
1004], [je_cv_atomic9])
1005if test "x${je_cv_atomic9}" = "xyes" ; then
1006 AC_DEFINE([JEMALLOC_ATOMIC9])
1007fi
1008
1009dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001010dnl Check for atomic(3) operations as provided on Darwin.
1011
1012JE_COMPILABLE([Darwin OSAtomic*()], [
1013#include <libkern/OSAtomic.h>
1014#include <inttypes.h>
1015], [
1016 {
1017 int32_t x32 = 0;
1018 volatile int32_t *x32p = &x32;
1019 OSAtomicAdd32(1, x32p);
1020 }
1021 {
1022 int64_t x64 = 0;
1023 volatile int64_t *x64p = &x64;
1024 OSAtomicAdd64(1, x64p);
1025 }
Jason Evans6684cac2012-03-05 12:15:36 -08001026], [je_cv_osatomic])
1027if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001028 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001029fi
1030
1031dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001032dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1033dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1034
1035AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1036 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1037 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001038 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1039 #include <stdint.h>
1040 ],
1041 [
1042 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1043 {
1044 uint$1_t x$1 = 0;
1045 __sync_add_and_fetch(&x$1, 42);
1046 __sync_sub_and_fetch(&x$1, 1);
1047 }
1048 #else
1049 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1050 #endif
1051 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001052 [je_cv_sync_compare_and_swap_$2=yes],
1053 [je_cv_sync_compare_and_swap_$2=no])])
1054
1055 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1056 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1057 fi
1058])
1059
Jason Evansb57d3ec2012-04-17 13:17:54 -07001060if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001061 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1062 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1063fi
1064
1065dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001066dnl Check for spinlock(3) operations as provided on Darwin.
1067
1068JE_COMPILABLE([Darwin OSSpin*()], [
1069#include <libkern/OSAtomic.h>
1070#include <inttypes.h>
1071], [
1072 OSSpinLock lock = 0;
1073 OSSpinLockLock(&lock);
1074 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001075], [je_cv_osspin])
1076if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001077 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001078fi
1079
1080dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001081dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001082
Jason Evans2dbecf12010-09-05 10:35:13 -07001083if test "x${abi}" = "xmacho" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001084 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1085 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001086
Jason Evans2dbecf12010-09-05 10:35:13 -07001087 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1088 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1089 dnl 10.6, which is the only source-level indication of the change.
1090 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001091 AC_DEFUN([JE_ZONE_PROGRAM],
1092 [AC_LANG_PROGRAM(
1093 [#include <malloc/malloc.h>],
1094 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1095 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001096
Mike Hommey154829d2012-03-20 18:01:38 +01001097 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1098 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1099 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1100 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1101 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1102 )])],[
1103 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1104 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1105 )])])])])
1106 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1107 AC_MSG_RESULT([unsupported])
1108 AC_MSG_ERROR([Unsupported malloc zone version])
1109 fi
1110 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1111 JEMALLOC_ZONE_VERSION=8
1112 AC_MSG_RESULT([> 8])
1113 else
1114 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1115 fi
1116 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001117fi
1118
Jason Evansb7924f52009-06-23 19:01:18 -07001119dnl ============================================================================
1120dnl Check for typedefs, structures, and compiler characteristics.
1121AC_HEADER_STDBOOL
1122
Jason Evansb1726102012-02-28 16:50:47 -08001123AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1124 mkdir -p "include/jemalloc/internal"
1125 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1126])
1127
Jason Evansb7924f52009-06-23 19:01:18 -07001128dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001129AC_SUBST([cfghdrs_in])
1130AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001131AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001132
1133dnl ============================================================================
1134dnl Generate outputs.
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001135AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001136AC_SUBST([cfgoutputs_in])
1137AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001138AC_OUTPUT
1139
1140dnl ============================================================================
1141dnl Print out the results of configuration.
1142AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001143AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1144AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001145AC_MSG_RESULT([])
1146AC_MSG_RESULT([CC : ${CC}])
1147AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1148AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1149AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1150AC_MSG_RESULT([LIBS : ${LIBS}])
1151AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1152AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001153AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1154AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1155AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001156AC_MSG_RESULT([PREFIX : ${PREFIX}])
1157AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001158AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1159AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001160AC_MSG_RESULT([DATADIR : ${DATADIR}])
1161AC_MSG_RESULT([MANDIR : ${MANDIR}])
1162AC_MSG_RESULT([])
1163AC_MSG_RESULT([srcroot : ${srcroot}])
1164AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1165AC_MSG_RESULT([objroot : ${objroot}])
1166AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1167AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001168AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001169AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1170AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001171AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001172AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001173AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001174AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001175AC_MSG_RESULT([debug : ${enable_debug}])
1176AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001177AC_MSG_RESULT([prof : ${enable_prof}])
1178AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001179AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1180AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001181AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001182AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001183AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001184AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1185AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001186AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001187AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001188AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001189AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001190AC_MSG_RESULT([===============================================================================])