blob: 55efcea0e4381e2d583e26a7f661b47093f10682 [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"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400202
Jason Evans7372b152012-02-10 20:22:09 -0800203dnl Heap profiling uses the log(3) function.
204LIBS="$LIBS -lm"
205
Jason Evansb7924f52009-06-23 19:01:18 -0700206dnl Platform-specific settings. abi and RPATH can probably be determined
207dnl programmatically, but doing so is error-prone, which makes it generally
208dnl not worth the trouble.
209dnl
210dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
211dnl definitions need to be seen before any headers are included, which is a pain
212dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700213default_munmap="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700214case "${host}" in
215 *-*-darwin*)
Jason Evans9022bf92012-03-23 16:14:08 -0700216 CFLAGS="$CFLAGS -fno-common"
Jason Evansb7924f52009-06-23 19:01:18 -0700217 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700218 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700219 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400220 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700221 so="dylib"
Jason Evansb80581d2012-03-23 16:17:43 -0700222 force_tls="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700223 ;;
224 *-*-freebsd*)
225 CFLAGS="$CFLAGS"
226 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700227 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700228 RPATH="-Wl,-rpath,"
Jason Evansfd4fcef2012-03-23 17:40:58 -0700229 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700230 ;;
231 *-*-linux*)
232 CFLAGS="$CFLAGS"
233 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
234 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700235 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700236 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700237 RPATH="-Wl,-rpath,"
Jason Evans59ae2762012-04-16 17:52:27 -0700238 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700239 ;;
240 *-*-netbsd*)
241 AC_MSG_CHECKING([ABI])
242 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
243[[#ifdef __ELF__
244/* ELF */
245#else
246#error aout
247#endif
248]])],
249 [CFLAGS="$CFLAGS"; abi="elf"],
250 [abi="aout"])
251 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700252 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700253 RPATH="-Wl,-rpath,"
254 ;;
255 *-*-solaris2*)
256 CFLAGS="$CFLAGS"
257 abi="elf"
258 RPATH="-Wl,-R,"
259 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"
272 RPATH="-Wl,-rpath,"
273 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700274 *)
275 AC_MSG_RESULT([Unsupported operating system: ${host}])
276 abi="elf"
277 RPATH="-Wl,-rpath,"
278 ;;
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])
Jason Evansb7924f52009-06-23 19:01:18 -0700288
Jason Evansfa5d2452011-03-15 10:25:59 -0700289JE_COMPILABLE([__attribute__ syntax],
290 [static __attribute__((unused)) void foo(void){}],
291 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800292 [je_cv_attribute])
293if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700294 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
295 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
296 JE_CFLAGS_APPEND([-fvisibility=hidden])
297 fi
298fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700299dnl Check for tls_model attribute support (clang 3.0 still lacks support).
300SAVED_CFLAGS="${CFLAGS}"
301JE_CFLAGS_APPEND([-Werror])
302JE_COMPILABLE([tls_model attribute], [],
303 [static __thread int
304 __attribute__((tls_model("initial-exec"))) foo;
305 foo = 0;],
306 [je_cv_tls_model])
307CFLAGS="${SAVED_CFLAGS}"
308if test "x${je_cv_tls_model}" = "xyes" ; then
309 AC_DEFINE([JEMALLOC_TLS_MODEL],
310 [__attribute__((tls_model("initial-exec")))])
311else
312 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
313fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700314
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800315JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
316#define _GNU_SOURCE
317#include <sys/mman.h>
318], [
319void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
Jason Evans6684cac2012-03-05 12:15:36 -0800320], [je_cv_mremap_fixed])
321if test "x${je_cv_mremap_fixed}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700322 AC_DEFINE([JEMALLOC_MREMAP_FIXED], [ ])
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800323fi
324
Jason Evansb7924f52009-06-23 19:01:18 -0700325dnl Support optional additions to rpath.
326AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800327 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700328if test "x$with_rpath" = "xno" ; then
329 RPATH_EXTRA=
330else
331 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
332fi,
333 RPATH_EXTRA=
334)
335AC_SUBST([RPATH_EXTRA])
336
337dnl Disable rules that do automatic regeneration of configure output by default.
338AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800339 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700340if test "x$enable_autogen" = "xno" ; then
341 enable_autogen="0"
342else
343 enable_autogen="1"
344fi
345,
346enable_autogen="0"
347)
348AC_SUBST([enable_autogen])
349
350AC_PROG_INSTALL
351AC_PROG_RANLIB
352AC_PATH_PROG([AR], [ar], , [$PATH])
353AC_PATH_PROG([LD], [ld], , [$PATH])
354AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
355
Jason Evans0a0bbf62012-03-13 12:55:21 -0700356public_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 -0800357
358dnl Check for allocator-related functions that should be wrapped.
359AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700360 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800361 public_syms="${public_syms} memalign"])
362AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700363 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800364 public_syms="${public_syms} valloc"])
365
366dnl Support the experimental API by default.
367AC_ARG_ENABLE([experimental],
368 [AS_HELP_STRING([--disable-experimental],
369 [Disable support for the experimental API])],
370[if test "x$enable_experimental" = "xno" ; then
371 enable_experimental="0"
372else
373 enable_experimental="1"
374fi
375],
376[enable_experimental="1"]
377)
378if test "x$enable_experimental" = "x1" ; then
379 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
380 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
381fi
382AC_SUBST([enable_experimental])
383
Jason Evans0a5489e2012-03-01 17:19:20 -0800384dnl Perform no name mangling by default.
385AC_ARG_WITH([mangling],
386 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
387 [mangling_map="$with_mangling"], [mangling_map=""])
388for nm in `echo ${mangling_map} |tr ',' ' '` ; do
Jason Evans08fc3b22012-03-12 15:07:53 -0700389 k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
390 n="je_${k}"
Jason Evans0a5489e2012-03-01 17:19:20 -0800391 m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
392 AC_DEFINE_UNQUOTED([${n}], [${m}])
Jason Evans08fc3b22012-03-12 15:07:53 -0700393 dnl Remove key from public_syms so that it isn't redefined later.
394 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
Jason Evans0a5489e2012-03-01 17:19:20 -0800395done
396
Jason Evans90895cf2009-12-29 00:09:15 -0800397dnl Do not prefix public APIs by default.
398AC_ARG_WITH([jemalloc_prefix],
399 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800400 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700401 [if test "x$abi" != "xmacho" ; then
402 JEMALLOC_PREFIX=""
403else
404 JEMALLOC_PREFIX="je_"
405fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800406)
407if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700408 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
409 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
410 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800411fi
Jason Evans0a5489e2012-03-01 17:19:20 -0800412dnl Generate macros to rename public symbols. All public symbols are prefixed
413dnl with je_ in the source code, so these macro definitions are needed even if
414dnl --with-jemalloc-prefix wasn't specified.
Jason Evans7e77eaf2012-03-02 17:47:37 -0800415for stem in ${public_syms}; do
Jason Evans0a5489e2012-03-01 17:19:20 -0800416 n="je_${stem}"
417 m="${JEMALLOC_PREFIX}${stem}"
418 AC_DEFINE_UNQUOTED([${n}], [${m}])
419done
Jason Evans90895cf2009-12-29 00:09:15 -0800420
Jason Evans746e77a2011-07-30 16:40:52 -0700421dnl Do not mangle library-private APIs by default.
422AC_ARG_WITH([private_namespace],
423 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
424 [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
425 [JEMALLOC_PRIVATE_NAMESPACE=""]
426)
427AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
428if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
429 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])
430else
431 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])
432fi
433
Jason Evansb0fd5012010-01-17 01:49:20 -0800434dnl Do not add suffix to installed files by default.
435AC_ARG_WITH([install_suffix],
436 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
437 [INSTALL_SUFFIX="$with_install_suffix"],
438 [INSTALL_SUFFIX=]
439)
440install_suffix="$INSTALL_SUFFIX"
441AC_SUBST([install_suffix])
442
Jason Evansaee7fd22010-11-24 22:00:02 -0800443cfgoutputs_in="${srcroot}Makefile.in"
444cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
445cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
446cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700447cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
448cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700449cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800450
Jason Evansaee7fd22010-11-24 22:00:02 -0800451cfgoutputs_out="Makefile"
452cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
453cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
454cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
Jason Evans376b1522010-02-11 14:45:59 -0800455cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
456cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700457cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800458
Jason Evansaee7fd22010-11-24 22:00:02 -0800459cfgoutputs_tup="Makefile"
460cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
461cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
462cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
Jason Evans376b1522010-02-11 14:45:59 -0800463cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
464cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700465cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800466
Jason Evans0656ec02010-04-07 23:37:35 -0700467cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb1726102012-02-28 16:50:47 -0800468cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansb0fd5012010-01-17 01:49:20 -0800469
Jason Evans376b1522010-02-11 14:45:59 -0800470cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb1726102012-02-28 16:50:47 -0800471cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800472
Jason Evans376b1522010-02-11 14:45:59 -0800473cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800474
Jason Evans355b4382010-09-20 19:20:48 -0700475dnl Do not silence irrelevant compiler warnings by default, since enabling this
476dnl option incurs a performance penalty.
477AC_ARG_ENABLE([cc-silence],
478 [AS_HELP_STRING([--enable-cc-silence],
479 [Silence irrelevant compiler warnings])],
480[if test "x$enable_cc_silence" = "xno" ; then
481 enable_cc_silence="0"
482else
483 enable_cc_silence="1"
484fi
485],
486[enable_cc_silence="0"]
487)
488if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700489 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700490fi
491
Jason Evansb7924f52009-06-23 19:01:18 -0700492dnl Do not compile with debugging by default.
493AC_ARG_ENABLE([debug],
494 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
495[if test "x$enable_debug" = "xno" ; then
496 enable_debug="0"
497else
498 enable_debug="1"
499fi
500],
501[enable_debug="0"]
502)
503if test "x$enable_debug" = "x1" ; then
504 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700505 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700506fi
507AC_SUBST([enable_debug])
508
509dnl Only optimize if not debugging.
510if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
511 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700512 optimize="no"
513 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
514 if test "x${optimize}" = "xyes" ; then
515 if test "x$GCC" = "xyes" ; then
516 JE_CFLAGS_APPEND([-O3])
517 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700518 else
519 JE_CFLAGS_APPEND([-O])
520 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700521 fi
522fi
523
Jason Evansd073a322012-02-28 20:41:16 -0800524dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700525AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800526 [AS_HELP_STRING([--disable-stats],
527 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700528[if test "x$enable_stats" = "xno" ; then
529 enable_stats="0"
530else
531 enable_stats="1"
532fi
533],
Jason Evansd073a322012-02-28 20:41:16 -0800534[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700535)
536if test "x$enable_stats" = "x1" ; then
537 AC_DEFINE([JEMALLOC_STATS], [ ])
538fi
539AC_SUBST([enable_stats])
540
Jason Evans6109fe02010-02-10 10:37:56 -0800541dnl Do not enable profiling by default.
542AC_ARG_ENABLE([prof],
543 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
544[if test "x$enable_prof" = "xno" ; then
545 enable_prof="0"
546else
547 enable_prof="1"
548fi
549],
550[enable_prof="0"]
551)
Jason Evans77f350b2011-03-15 22:23:12 -0700552if test "x$enable_prof" = "x1" ; then
553 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800554else
Jason Evans77f350b2011-03-15 22:23:12 -0700555 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800556fi
Jason Evans77f350b2011-03-15 22:23:12 -0700557
Jason Evans6109fe02010-02-10 10:37:56 -0800558AC_ARG_ENABLE([prof-libunwind],
559 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
560[if test "x$enable_prof_libunwind" = "xno" ; then
561 enable_prof_libunwind="0"
562else
563 enable_prof_libunwind="1"
564fi
565],
566[enable_prof_libunwind="0"]
567)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800568AC_ARG_WITH([static_libunwind],
569 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
570 [Path to static libunwind library; use rather than dynamically linking])],
571if test "x$with_static_libunwind" = "xno" ; then
572 LUNWIND="-lunwind"
573else
574 if test ! -f "$with_static_libunwind" ; then
575 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
576 fi
577 LUNWIND="$with_static_libunwind"
578fi,
579 LUNWIND="-lunwind"
580)
Jason Evans77f350b2011-03-15 22:23:12 -0700581if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
582 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
583 if test "x$LUNWIND" = "x-lunwind" ; then
584 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
585 [enable_prof_libunwind="0"])
586 else
587 LIBS="$LIBS $LUNWIND"
588 fi
589 if test "x${enable_prof_libunwind}" = "x1" ; then
590 backtrace_method="libunwind"
591 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
592 fi
593fi
594
595AC_ARG_ENABLE([prof-libgcc],
596 [AS_HELP_STRING([--disable-prof-libgcc],
597 [Do not use libgcc for backtracing])],
598[if test "x$enable_prof_libgcc" = "xno" ; then
599 enable_prof_libgcc="0"
600else
601 enable_prof_libgcc="1"
602fi
603],
604[enable_prof_libgcc="1"]
605)
606if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
607 -a "x$GCC" = "xyes" ; then
608 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
609 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
610 dnl The following is conservative, in that it only has entries for CPUs on
611 dnl which jemalloc has been tested.
612 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
613 case "${host_cpu}" in
614 i[[3456]]86)
615 AC_MSG_RESULT([unreliable])
616 enable_prof_libgcc="0";
617 ;;
618 x86_64)
619 AC_MSG_RESULT([reliable])
620 ;;
621 *)
622 AC_MSG_RESULT([unreliable])
623 enable_prof_libgcc="0";
624 ;;
625 esac
626 if test "x${enable_prof_libgcc}" = "x1" ; then
627 backtrace_method="libgcc"
628 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
629 fi
630else
631 enable_prof_libgcc="0"
632fi
633
634AC_ARG_ENABLE([prof-gcc],
635 [AS_HELP_STRING([--disable-prof-gcc],
636 [Do not use gcc intrinsics for backtracing])],
637[if test "x$enable_prof_gcc" = "xno" ; then
638 enable_prof_gcc="0"
639else
640 enable_prof_gcc="1"
641fi
642],
643[enable_prof_gcc="1"]
644)
645if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
646 -a "x$GCC" = "xyes" ; then
647 backtrace_method="gcc intrinsics"
648 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
649else
650 enable_prof_gcc="0"
651fi
652
653if test "x$backtrace_method" = "x" ; then
654 backtrace_method="none (disabling profiling)"
655 enable_prof="0"
656fi
657AC_MSG_CHECKING([configured backtracing method])
658AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700659if test "x$enable_prof" = "x1" ; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700660 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700661fi
662AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700663
Jason Evans84cbbcb2009-12-29 00:09:15 -0800664dnl Enable thread-specific caching by default.
665AC_ARG_ENABLE([tcache],
666 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
667[if test "x$enable_tcache" = "xno" ; then
668 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700669else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800670 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700671fi
672],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800673[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700674)
Jason Evans2dbecf12010-09-05 10:35:13 -0700675if test "x$enable_tcache" = "x1" ; then
676 AC_DEFINE([JEMALLOC_TCACHE], [ ])
677fi
678AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700679
Jason Evans59ae2762012-04-16 17:52:27 -0700680dnl Enable VM deallocation via munmap() by default.
681AC_ARG_ENABLE([munmap],
682 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
683[if test "x$enable_munmap" = "xno" ; then
684 enable_munmap="0"
685else
686 enable_munmap="1"
687fi
688],
689[enable_munmap="${default_munmap}"]
690)
691if test "x$enable_munmap" = "x1" ; then
692 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
693fi
694AC_SUBST([enable_munmap])
695
Jason Evansb7924f52009-06-23 19:01:18 -0700696dnl Do not enable allocation from DSS by default.
697AC_ARG_ENABLE([dss],
698 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
699[if test "x$enable_dss" = "xno" ; then
700 enable_dss="0"
701else
702 enable_dss="1"
703fi
704],
705[enable_dss="0"]
706)
Mike Hommey83c324a2012-04-12 10:13:03 +0200707dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
708AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
709if test "x$have_sbrk" = "x1" ; then
710 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
711else
712 enable_dss="0"
713fi
714
Jason Evansb7924f52009-06-23 19:01:18 -0700715if test "x$enable_dss" = "x1" ; then
716 AC_DEFINE([JEMALLOC_DSS], [ ])
717fi
718AC_SUBST([enable_dss])
719
Jason Evans777c1912012-02-28 20:49:22 -0800720dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700721AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700722 [AS_HELP_STRING([--disable-fill],
723 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700724[if test "x$enable_fill" = "xno" ; then
725 enable_fill="0"
726else
727 enable_fill="1"
728fi
729],
Jason Evans777c1912012-02-28 20:49:22 -0800730[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700731)
732if test "x$enable_fill" = "x1" ; then
733 AC_DEFINE([JEMALLOC_FILL], [ ])
734fi
735AC_SUBST([enable_fill])
736
Jason Evansb1476112012-04-05 13:36:17 -0700737dnl Disable utrace(2)-based tracing by default.
738AC_ARG_ENABLE([utrace],
739 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
740[if test "x$enable_utrace" = "xno" ; then
741 enable_utrace="0"
742else
743 enable_utrace="1"
744fi
745],
746[enable_utrace="0"]
747)
748JE_COMPILABLE([utrace(2)], [
749#include <sys/types.h>
750#include <sys/param.h>
751#include <sys/time.h>
752#include <sys/uio.h>
753#include <sys/ktrace.h>
754], [
755 utrace((void *)0, 0);
756], [je_cv_utrace])
757if test "x${je_cv_utrace}" = "xno" ; then
758 enable_utrace="0"
759fi
760if test "x$enable_utrace" = "x1" ; then
761 AC_DEFINE([JEMALLOC_UTRACE], [ ])
762fi
763AC_SUBST([enable_utrace])
764
Jason Evans122449b2012-04-06 00:35:09 -0700765dnl Support Valgrind by default.
766AC_ARG_ENABLE([valgrind],
767 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
768[if test "x$enable_valgrind" = "xno" ; then
769 enable_valgrind="0"
770else
771 enable_valgrind="1"
772fi
773],
774[enable_valgrind="1"]
775)
776if test "x$enable_valgrind" = "x1" ; then
777 JE_COMPILABLE([valgrind], [
778#include <valgrind/valgrind.h>
779#include <valgrind/memcheck.h>
780
781#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
782 && (__VALGRIND_MAJOR__ > 3 || (__VALGRIND_MAJOR__ == 3 && \
783 __VALGRIND_MINOR__ >= 6))
784#else
785# error "Incompatible Valgrind version"
786#endif
787], [], [je_cv_valgrind])
788 if test "x${je_cv_valgrind}" = "xno" ; then
789 enable_valgrind="0"
790 fi
791 if test "x$enable_valgrind" = "x1" ; then
792 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
793 fi
794fi
795AC_SUBST([enable_valgrind])
796
Jason Evansb7924f52009-06-23 19:01:18 -0700797dnl Do not support the xmalloc option by default.
798AC_ARG_ENABLE([xmalloc],
799 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
800[if test "x$enable_xmalloc" = "xno" ; then
801 enable_xmalloc="0"
802else
803 enable_xmalloc="1"
804fi
805],
806[enable_xmalloc="0"]
807)
808if test "x$enable_xmalloc" = "x1" ; then
809 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
810fi
811AC_SUBST([enable_xmalloc])
812
Jason Evans6684cac2012-03-05 12:15:36 -0800813AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
814 [je_cv_static_page_shift],
815 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansb7924f52009-06-23 19:01:18 -0700816[[#include <stdio.h>
817#include <unistd.h>
818#include <strings.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800819]],
820[[
Jason Evansb7924f52009-06-23 19:01:18 -0700821 long result;
822 FILE *f;
823
824 result = sysconf(_SC_PAGESIZE);
825 if (result == -1) {
826 return 1;
827 }
828 f = fopen("conftest.out", "w");
829 if (f == NULL) {
830 return 1;
831 }
832 fprintf(f, "%u\n", ffs((int)result) - 1);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700833 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700834
835 return 0;
836]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800837 [je_cv_static_page_shift=`cat conftest.out`],
838 [je_cv_static_page_shift=undefined]))
839
840if test "x$je_cv_static_page_shift" != "xundefined"; then
841 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
842else
843 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
844fi
Jason Evansb7924f52009-06-23 19:01:18 -0700845
846dnl ============================================================================
847dnl jemalloc configuration.
848dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800849
850dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700851if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700852 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800853fi
Jason Evansb7924f52009-06-23 19:01:18 -0700854jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800855jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
856jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
857jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
858jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
859jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700860AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800861AC_SUBST([jemalloc_version_major])
862AC_SUBST([jemalloc_version_minor])
863AC_SUBST([jemalloc_version_bugfix])
864AC_SUBST([jemalloc_version_nrev])
865AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700866
867dnl ============================================================================
868dnl Configure pthreads.
869
870AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
Jason Evans39006f92012-03-16 16:57:02 -0700871dnl Some systems may embed pthreads functionality in libc; check for libpthread
872dnl first, but try libc too before failing.
Jason Evansb7924f52009-06-23 19:01:18 -0700873AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
Jason Evans39006f92012-03-16 16:57:02 -0700874 [AC_SEARCH_LIBS([pthread_create], , ,
875 AC_MSG_ERROR([libpthread is missing]))])
Jason Evansb7924f52009-06-23 19:01:18 -0700876
877CPPFLAGS="$CPPFLAGS -D_REENTRANT"
878
Jason Evanscd9a1342012-03-21 18:33:03 -0700879dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
880dnl it rather than pthreads TSD cleanup functions to support cleanup during
881dnl thread exit, in order to avoid pthreads library recursion during
882dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -0700883AC_CHECK_FUNC([_malloc_thread_cleanup],
884 [have__malloc_thread_cleanup="1"],
885 [have__malloc_thread_cleanup="0"]
886 )
887if test "x$have__malloc_thread_cleanup" = "x1" ; then
888 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
889 force_tls="1"
890fi
891
Jason Evans41b6afb2012-02-02 22:04:57 -0800892dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
893dnl so, mutex initialization causes allocation, and we need to implement this
894dnl callback function in order to prevent recursive allocation.
895AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
896 [have__pthread_mutex_init_calloc_cb="1"],
897 [have__pthread_mutex_init_calloc_cb="0"]
898 )
899if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
900 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
901fi
902
Jason Evans0fee70d2012-02-13 12:36:11 -0800903dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700904AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -0800905 [AS_HELP_STRING([--enable-lazy-lock],
906 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700907[if test "x$enable_lazy_lock" = "xno" ; then
908 enable_lazy_lock="0"
909else
910 enable_lazy_lock="1"
911fi
912],
Jason Evans0fee70d2012-02-13 12:36:11 -0800913[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -0700914)
Jason Evansfd4fcef2012-03-23 17:40:58 -0700915if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
916 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
917 enable_lazy_lock="1"
918fi
Jason Evansb7924f52009-06-23 19:01:18 -0700919if test "x$enable_lazy_lock" = "x1" ; then
920 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
Jason Evans650285d2012-03-19 10:25:27 -0700921 AC_CHECK_FUNC([dlsym], [],
922 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
923 [AC_MSG_ERROR([libdl is missing])])
924 ])
Jason Evansb7924f52009-06-23 19:01:18 -0700925 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
926fi
927AC_SUBST([enable_lazy_lock])
928
Jason Evans78d815c2010-01-17 14:06:20 -0800929AC_ARG_ENABLE([tls],
930 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
931if test "x$enable_tls" = "xno" ; then
932 enable_tls="0"
933else
934 enable_tls="1"
935fi
936,
937enable_tls="1"
938)
Jason Evanscd9a1342012-03-21 18:33:03 -0700939if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
940 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
941 enable_tls="1"
942fi
Jason Evansb80581d2012-03-23 16:17:43 -0700943if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
944 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
945 enable_tls="0"
946fi
Jason Evans78d815c2010-01-17 14:06:20 -0800947if test "x${enable_tls}" = "x1" ; then
948AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -0800949AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -0800950[[
951 __thread int x;
952]], [[
953 x = 42;
954
955 return 0;
956]])],
957 AC_MSG_RESULT([yes]),
958 AC_MSG_RESULT([no])
959 enable_tls="0")
960fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700961AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -0700962if test "x${enable_tls}" = "x1" ; then
963 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -0700964elif test "x${force_tls}" = "x1" ; then
965 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -0800966fi
967
Jason Evans2dbecf12010-09-05 10:35:13 -0700968dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700969dnl Check for ffsl(3), and fail if not found. This function exists on all
970dnl platforms that jemalloc currently has a chance of functioning on without
971dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -0700972JE_COMPILABLE([a program using ffsl], [
Jason Evans382132e2012-04-04 15:25:43 -0700973#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -0700974#include <string.h>
975], [
976 {
977 int rv = ffsl(0x08);
978 }
979], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -0800980if test "x${je_cv_function_ffsl}" != "xyes" ; then
981 AC_MSG_ERROR([Cannot build without ffsl(3)])
982fi
Jason Evans84c8eef2011-03-16 10:30:13 -0700983
984dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -0700985dnl Check for atomic(3) operations as provided on Darwin.
986
987JE_COMPILABLE([Darwin OSAtomic*()], [
988#include <libkern/OSAtomic.h>
989#include <inttypes.h>
990], [
991 {
992 int32_t x32 = 0;
993 volatile int32_t *x32p = &x32;
994 OSAtomicAdd32(1, x32p);
995 }
996 {
997 int64_t x64 = 0;
998 volatile int64_t *x64p = &x64;
999 OSAtomicAdd64(1, x64p);
1000 }
Jason Evans6684cac2012-03-05 12:15:36 -08001001], [je_cv_osatomic])
1002if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001003 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001004fi
1005
1006dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001007dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1008dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1009
1010AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1011 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1012 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001013 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1014 #include <stdint.h>
1015 ],
1016 [
1017 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1018 {
1019 uint$1_t x$1 = 0;
1020 __sync_add_and_fetch(&x$1, 42);
1021 __sync_sub_and_fetch(&x$1, 1);
1022 }
1023 #else
1024 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1025 #endif
1026 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001027 [je_cv_sync_compare_and_swap_$2=yes],
1028 [je_cv_sync_compare_and_swap_$2=no])])
1029
1030 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1031 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1032 fi
1033])
1034
1035if test "x${je_cv_osatomic}" != "xyes" ; then
1036 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1037 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1038fi
1039
1040dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001041dnl Check for spinlock(3) operations as provided on Darwin.
1042
1043JE_COMPILABLE([Darwin OSSpin*()], [
1044#include <libkern/OSAtomic.h>
1045#include <inttypes.h>
1046], [
1047 OSSpinLock lock = 0;
1048 OSSpinLockLock(&lock);
1049 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001050], [je_cv_osspin])
1051if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001052 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001053fi
1054
1055dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001056dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001057
Jason Evans2dbecf12010-09-05 10:35:13 -07001058if test "x${abi}" = "xmacho" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001059 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1060 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001061
Jason Evans2dbecf12010-09-05 10:35:13 -07001062 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1063 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1064 dnl 10.6, which is the only source-level indication of the change.
1065 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001066 AC_DEFUN([JE_ZONE_PROGRAM],
1067 [AC_LANG_PROGRAM(
1068 [#include <malloc/malloc.h>],
1069 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1070 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001071
Mike Hommey154829d2012-03-20 18:01:38 +01001072 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1073 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1074 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1075 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1076 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1077 )])],[
1078 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1079 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1080 )])])])])
1081 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1082 AC_MSG_RESULT([unsupported])
1083 AC_MSG_ERROR([Unsupported malloc zone version])
1084 fi
1085 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1086 JEMALLOC_ZONE_VERSION=8
1087 AC_MSG_RESULT([> 8])
1088 else
1089 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1090 fi
1091 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001092fi
1093
Jason Evansb7924f52009-06-23 19:01:18 -07001094dnl ============================================================================
1095dnl Check for typedefs, structures, and compiler characteristics.
1096AC_HEADER_STDBOOL
1097
Jason Evansb1726102012-02-28 16:50:47 -08001098AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1099 mkdir -p "include/jemalloc/internal"
1100 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1101])
1102
Jason Evansb7924f52009-06-23 19:01:18 -07001103dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001104AC_SUBST([cfghdrs_in])
1105AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001106AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001107
1108dnl ============================================================================
1109dnl Generate outputs.
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001110AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001111AC_SUBST([cfgoutputs_in])
1112AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001113AC_OUTPUT
1114
1115dnl ============================================================================
1116dnl Print out the results of configuration.
1117AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001118AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1119AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001120AC_MSG_RESULT([])
1121AC_MSG_RESULT([CC : ${CC}])
1122AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1123AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1124AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1125AC_MSG_RESULT([LIBS : ${LIBS}])
1126AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1127AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001128AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1129AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1130AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001131AC_MSG_RESULT([PREFIX : ${PREFIX}])
1132AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001133AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1134AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001135AC_MSG_RESULT([DATADIR : ${DATADIR}])
1136AC_MSG_RESULT([MANDIR : ${MANDIR}])
1137AC_MSG_RESULT([])
1138AC_MSG_RESULT([srcroot : ${srcroot}])
1139AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1140AC_MSG_RESULT([objroot : ${objroot}])
1141AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1142AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001143AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001144AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1145AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001146AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001147AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001148AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001149AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001150AC_MSG_RESULT([debug : ${enable_debug}])
1151AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001152AC_MSG_RESULT([prof : ${enable_prof}])
1153AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001154AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1155AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001156AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001157AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001158AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001159AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1160AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001161AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001162AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001163AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001164AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001165AC_MSG_RESULT([===============================================================================])