blob: d5c663eb3499d9d685b3d2eaa3aee84373506877 [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]])],
Jason Evans99b0fbb2014-02-24 16:08:38 -080022 [je_cv_cflags_appended=$1]
Jason Evansf3340ca2009-06-30 16:17:05 -070023 AC_MSG_RESULT([yes]),
Jason Evans99b0fbb2014-02-24 16:08:38 -080024 [je_cv_cflags_appended=]
Jason Evansf3340ca2009-06-30 16:17:05 -070025 AC_MSG_RESULT([no])
26 [CFLAGS="${TCFLAGS}"]
27)
28])
29
30dnl JE_COMPILABLE(label, hcode, mcode, rvar)
Jason Evans4c2faa82012-03-13 11:09:23 -070031dnl
Jason Evansf3e139a2012-03-19 09:54:20 -070032dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
Jason Evans4c2faa82012-03-13 11:09:23 -070033dnl cause failure.
Jason Evansf3340ca2009-06-30 16:17:05 -070034AC_DEFUN([JE_COMPILABLE],
35[
Jason Evans6684cac2012-03-05 12:15:36 -080036AC_CACHE_CHECK([whether $1 is compilable],
37 [$4],
Jason Evansf3e139a2012-03-19 09:54:20 -070038 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
39 [$3])],
40 [$4=yes],
41 [$4=no])])
Jason Evansf3340ca2009-06-30 16:17:05 -070042])
43
44dnl ============================================================================
45
Jason Evansf576c632011-11-01 22:27:41 -070046dnl Library revision.
47rev=1
48AC_SUBST([rev])
49
Jason Evansb7924f52009-06-23 19:01:18 -070050srcroot=$srcdir
51if test "x${srcroot}" = "x." ; then
52 srcroot=""
53else
54 srcroot="${srcroot}/"
55fi
56AC_SUBST([srcroot])
57abs_srcroot="`cd \"${srcdir}\"; pwd`/"
58AC_SUBST([abs_srcroot])
59
60objroot=""
61AC_SUBST([objroot])
62abs_objroot="`pwd`/"
63AC_SUBST([abs_objroot])
64
65dnl Munge install path variables.
66if test "x$prefix" = "xNONE" ; then
67 prefix="/usr/local"
68fi
69if test "x$exec_prefix" = "xNONE" ; then
70 exec_prefix=$prefix
71fi
72PREFIX=$prefix
73AC_SUBST([PREFIX])
74BINDIR=`eval echo $bindir`
75BINDIR=`eval echo $BINDIR`
76AC_SUBST([BINDIR])
77INCLUDEDIR=`eval echo $includedir`
78INCLUDEDIR=`eval echo $INCLUDEDIR`
79AC_SUBST([INCLUDEDIR])
80LIBDIR=`eval echo $libdir`
81LIBDIR=`eval echo $LIBDIR`
82AC_SUBST([LIBDIR])
83DATADIR=`eval echo $datadir`
84DATADIR=`eval echo $DATADIR`
85AC_SUBST([DATADIR])
86MANDIR=`eval echo $mandir`
87MANDIR=`eval echo $MANDIR`
88AC_SUBST([MANDIR])
89
Jason Evansaee7fd22010-11-24 22:00:02 -080090dnl Support for building documentation.
Jason Evans7329a4f2013-01-22 10:53:29 -080091AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
Jason Evans7091b412012-03-19 09:36:44 -070092if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
93 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
94elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
95 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
96else
97 dnl Documentation building will fail if this default gets used.
98 DEFAULT_XSLROOT=""
99fi
Jason Evansaee7fd22010-11-24 22:00:02 -0800100AC_ARG_WITH([xslroot],
Jason Evans7091b412012-03-19 09:36:44 -0700101 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
Jason Evansaee7fd22010-11-24 22:00:02 -0800102if test "x$with_xslroot" = "xno" ; then
Jason Evans7091b412012-03-19 09:36:44 -0700103 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800104else
105 XSLROOT="${with_xslroot}"
Jason Evans7091b412012-03-19 09:36:44 -0700106fi
107],
108 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800109)
110AC_SUBST([XSLROOT])
111
Jason Evansf3340ca2009-06-30 16:17:05 -0700112dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
113dnl just prevent autoconf from molesting CFLAGS.
Jason Evansb7924f52009-06-23 19:01:18 -0700114CFLAGS=$CFLAGS
115AC_PROG_CC
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200116if test "x$GCC" != "xyes" ; then
117 AC_CACHE_CHECK([whether compiler is MSVC],
118 [je_cv_msvc],
119 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
120 [
121#ifndef _MSC_VER
122 int fail[-1];
123#endif
124])],
125 [je_cv_msvc=yes],
126 [je_cv_msvc=no])])
127fi
128
Jason Evansb7924f52009-06-23 19:01:18 -0700129if test "x$CFLAGS" = "x" ; then
130 no_CFLAGS="yes"
Jason Evanscfeccd32010-03-03 15:48:20 -0800131 if test "x$GCC" = "xyes" ; then
132 JE_CFLAGS_APPEND([-std=gnu99])
Jason Evans99b0fbb2014-02-24 16:08:38 -0800133 if test "x$je_cv_cflags_appended" = "x-std=gnu99" ; then
134 AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
135 fi
Jason Evanscfeccd32010-03-03 15:48:20 -0800136 JE_CFLAGS_APPEND([-Wall])
137 JE_CFLAGS_APPEND([-pipe])
138 JE_CFLAGS_APPEND([-g3])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200139 elif test "x$je_cv_msvc" = "xyes" ; then
140 CC="$CC -nologo"
141 JE_CFLAGS_APPEND([-Zi])
142 JE_CFLAGS_APPEND([-MT])
143 JE_CFLAGS_APPEND([-W3])
144 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat"
Jason Evanscfeccd32010-03-03 15:48:20 -0800145 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700146fi
147dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
148if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700149 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700150fi
151AC_PROG_CPP
152
Jason Evansdf3f2702014-03-30 16:27:08 -0700153AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
154if test "x${ac_cv_big_endian}" = "x1" ; then
155 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
156fi
157
Jason Evansb7924f52009-06-23 19:01:18 -0700158AC_CHECK_SIZEOF([void *])
159if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800160 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700161elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800162 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700163else
164 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
165fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800166AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
167
168AC_CHECK_SIZEOF([int])
169if test "x${ac_cv_sizeof_int}" = "x8" ; then
170 LG_SIZEOF_INT=3
171elif test "x${ac_cv_sizeof_int}" = "x4" ; then
172 LG_SIZEOF_INT=2
173else
174 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
175fi
176AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700177
Jason Evans84c8eef2011-03-16 10:30:13 -0700178AC_CHECK_SIZEOF([long])
179if test "x${ac_cv_sizeof_long}" = "x8" ; then
180 LG_SIZEOF_LONG=3
181elif test "x${ac_cv_sizeof_long}" = "x4" ; then
182 LG_SIZEOF_LONG=2
183else
184 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
185fi
186AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
187
Jason Evansd81e4bd2012-03-06 14:57:45 -0800188AC_CHECK_SIZEOF([intmax_t])
189if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
190 LG_SIZEOF_INTMAX_T=4
191elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
192 LG_SIZEOF_INTMAX_T=3
193elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
194 LG_SIZEOF_INTMAX_T=2
195else
Mike Hommey14103d32012-04-20 08:38:39 +0200196 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800197fi
198AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
199
Jason Evansb7924f52009-06-23 19:01:18 -0700200AC_CANONICAL_HOST
201dnl CPU-specific settings.
202CPU_SPINWAIT=""
203case "${host_cpu}" in
204 i[[345]]86)
205 ;;
Jason Evanscb657e32014-02-25 11:21:41 -0800206 i686|x86_64)
207 JE_COMPILABLE([pause instruction], [],
208 [[__asm__ volatile("pause"); return 0;]],
209 [je_cv_pause])
210 if test "x${je_cv_pause}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700211 CPU_SPINWAIT='__asm__ volatile("pause")'
212 fi
Jason Evanscb657e32014-02-25 11:21:41 -0800213 dnl emmintrin.h fails to compile unless MMX, SSE, and SSE2 are
214 dnl supported.
215 JE_COMPILABLE([SSE2 intrinsics], [
216#include <emmintrin.h>
217], [], [je_cv_sse2])
218 if test "x${je_cv_sse2}" = "xyes" ; then
219 AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ])
Jason Evansf3340ca2009-06-30 16:17:05 -0700220 fi
Jason Evans80061b62013-12-09 13:21:08 -0800221 ;;
222 powerpc)
223 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700224 ;;
225 *)
226 ;;
227esac
228AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
229
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400230LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700231so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200232importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200233o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200234a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200235exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700236libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200237DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
238RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200239SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200240PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200241CTARGET='-o $@'
242LDTARGET='-o $@'
243EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100244ARFLAGS='crus'
245AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200246CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800247
Jory A. Prattad505e02013-08-11 09:44:59 -0500248AN_MAKEVAR([AR], [AC_PROG_AR])
249AN_PROGRAM([ar], [AC_PROG_AR])
250AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
251AC_PROG_AR
252
Jason Evansb7924f52009-06-23 19:01:18 -0700253dnl Platform-specific settings. abi and RPATH can probably be determined
254dnl programmatically, but doing so is error-prone, which makes it generally
255dnl not worth the trouble.
256dnl
257dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
258dnl definitions need to be seen before any headers are included, which is a pain
259dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700260default_munmap="1"
Jason Evans247d1242012-10-09 16:20:10 -0700261JEMALLOC_USABLE_SIZE_CONST="const"
Jason Evansb7924f52009-06-23 19:01:18 -0700262case "${host}" in
263 *-*-darwin*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200264 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700265 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700266 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700267 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400268 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700269 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200270 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700271 force_tls="0"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200272 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200273 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800274 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700275 ;;
276 *-*-freebsd*)
277 CFLAGS="$CFLAGS"
278 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700279 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700280 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700281 ;;
282 *-*-linux*)
283 CFLAGS="$CFLAGS"
284 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
285 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800286 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700287 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700288 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evans247d1242012-10-09 16:20:10 -0700289 JEMALLOC_USABLE_SIZE_CONST=""
Jason Evans59ae2762012-04-16 17:52:27 -0700290 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700291 ;;
292 *-*-netbsd*)
293 AC_MSG_CHECKING([ABI])
294 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
295[[#ifdef __ELF__
296/* ELF */
297#else
298#error aout
299#endif
300]])],
301 [CFLAGS="$CFLAGS"; abi="elf"],
302 [abi="aout"])
303 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700304 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700305 ;;
306 *-*-solaris2*)
307 CFLAGS="$CFLAGS"
308 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000309 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200310 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700311 dnl Solaris needs this for sigwait().
312 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
313 LIBS="$LIBS -lposix4 -lsocket -lnsl"
314 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400315 *-ibm-aix*)
316 if "$LG_SIZEOF_PTR" = "8"; then
317 dnl 64bit AIX
318 LD_PRELOAD_VAR="LDR_PRELOAD64"
319 else
320 dnl 32bit AIX
321 LD_PRELOAD_VAR="LDR_PRELOAD"
322 fi
323 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400324 ;;
Mike Hommeya19e87f2012-04-21 21:27:46 -0700325 *-*-mingw*)
326 abi="pecoff"
327 force_tls="0"
328 RPATH=""
329 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200330 if test "x$je_cv_msvc" = "xyes" ; then
331 importlib="lib"
332 DSO_LDFLAGS="-LD"
333 EXTRA_LDFLAGS="-link -DEBUG"
334 CTARGET='-Fo$@'
335 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500336 AR='lib'
337 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100338 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200339 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200340 else
341 importlib="${so}"
342 DSO_LDFLAGS="-shared"
343 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700344 a="lib"
345 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200346 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700347 PIC_CFLAGS=""
348 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700349 *)
350 AC_MSG_RESULT([Unsupported operating system: ${host}])
351 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700352 ;;
353esac
Jason Evans247d1242012-10-09 16:20:10 -0700354AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700355AC_SUBST([abi])
356AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400357AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700358AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200359AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200360AC_SUBST([o])
361AC_SUBST([a])
362AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700363AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200364AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200365AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200366AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200367AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200368AC_SUBST([CTARGET])
369AC_SUBST([LDTARGET])
370AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100371AC_SUBST([ARFLAGS])
372AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200373AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200374
Jason Evansfa5d2452011-03-15 10:25:59 -0700375JE_COMPILABLE([__attribute__ syntax],
376 [static __attribute__((unused)) void foo(void){}],
377 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800378 [je_cv_attribute])
379if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700380 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
381 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
382 JE_CFLAGS_APPEND([-fvisibility=hidden])
383 fi
384fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700385dnl Check for tls_model attribute support (clang 3.0 still lacks support).
386SAVED_CFLAGS="${CFLAGS}"
387JE_CFLAGS_APPEND([-Werror])
388JE_COMPILABLE([tls_model attribute], [],
389 [static __thread int
390 __attribute__((tls_model("initial-exec"))) foo;
391 foo = 0;],
392 [je_cv_tls_model])
393CFLAGS="${SAVED_CFLAGS}"
394if test "x${je_cv_tls_model}" = "xyes" ; then
395 AC_DEFINE([JEMALLOC_TLS_MODEL],
396 [__attribute__((tls_model("initial-exec")))])
397else
398 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
399fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700400
Jason Evansb7924f52009-06-23 19:01:18 -0700401dnl Support optional additions to rpath.
402AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800403 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700404if test "x$with_rpath" = "xno" ; then
405 RPATH_EXTRA=
406else
407 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
408fi,
409 RPATH_EXTRA=
410)
411AC_SUBST([RPATH_EXTRA])
412
413dnl Disable rules that do automatic regeneration of configure output by default.
414AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800415 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700416if test "x$enable_autogen" = "xno" ; then
417 enable_autogen="0"
418else
419 enable_autogen="1"
420fi
421,
422enable_autogen="0"
423)
424AC_SUBST([enable_autogen])
425
426AC_PROG_INSTALL
427AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800428AC_PATH_PROG([LD], [ld], [false], [$PATH])
429AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700430
Jason Evansd82a5e62013-12-12 22:35:52 -0800431public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size"
Jason Evans7e77eaf2012-03-02 17:47:37 -0800432
433dnl Check for allocator-related functions that should be wrapped.
434AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700435 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800436 public_syms="${public_syms} memalign"])
437AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700438 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800439 public_syms="${public_syms} valloc"])
440
441dnl Support the experimental API by default.
442AC_ARG_ENABLE([experimental],
443 [AS_HELP_STRING([--disable-experimental],
444 [Disable support for the experimental API])],
445[if test "x$enable_experimental" = "xno" ; then
446 enable_experimental="0"
447else
448 enable_experimental="1"
449fi
450],
451[enable_experimental="1"]
452)
453if test "x$enable_experimental" = "x1" ; then
454 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
455 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
456fi
457AC_SUBST([enable_experimental])
458
Jason Evans748dfac2013-12-06 18:27:33 -0800459dnl Do not compute test code coverage by default.
460GCOV_FLAGS=
461AC_ARG_ENABLE([code-coverage],
462 [AS_HELP_STRING([--enable-code-coverage],
463 [Enable code coverage])],
464[if test "x$enable_code_coverage" = "xno" ; then
465 enable_code_coverage="0"
466else
467 enable_code_coverage="1"
468fi
469],
470[enable_code_coverage="0"]
471)
472if test "x$enable_code_coverage" = "x1" ; then
473 deoptimize="no"
474 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
475 if test "x${deoptimize}" = "xyes" ; then
476 JE_CFLAGS_APPEND([-O0])
477 fi
478 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
479 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
480 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
481fi
482AC_SUBST([enable_code_coverage])
483
Jason Evans0a5489e2012-03-01 17:19:20 -0800484dnl Perform no name mangling by default.
485AC_ARG_WITH([mangling],
486 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
487 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800488
Jason Evans90895cf2009-12-29 00:09:15 -0800489dnl Do not prefix public APIs by default.
490AC_ARG_WITH([jemalloc_prefix],
491 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800492 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200493 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700494 JEMALLOC_PREFIX=""
495else
496 JEMALLOC_PREFIX="je_"
497fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800498)
499if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700500 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
501 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
502 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800503fi
504
Mike Hommey99066602012-11-19 10:55:26 +0100505AC_ARG_WITH([export],
506 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
507 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800508 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100509fi]
510)
511
Jason Evans86abd0d2013-11-30 15:25:42 -0800512dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700513AC_ARG_WITH([private_namespace],
514 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800515 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
516 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700517)
Jason Evans86abd0d2013-11-30 15:25:42 -0800518AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
519private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
520AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700521
Jason Evansb0fd5012010-01-17 01:49:20 -0800522dnl Do not add suffix to installed files by default.
523AC_ARG_WITH([install_suffix],
524 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
525 [INSTALL_SUFFIX="$with_install_suffix"],
526 [INSTALL_SUFFIX=]
527)
528install_suffix="$INSTALL_SUFFIX"
529AC_SUBST([install_suffix])
530
Jason Evans86abd0d2013-11-30 15:25:42 -0800531dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
532dnl jemalloc_protos_jet.h easy.
533je_="je_"
534AC_SUBST([je_])
535
Jason Evansaee7fd22010-11-24 22:00:02 -0800536cfgoutputs_in="${srcroot}Makefile.in"
537cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
538cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
539cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800540cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc_macros.h.in"
541cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc_protos.h.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700542cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800543cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/test.sh.in"
544cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800545
Jason Evansaee7fd22010-11-24 22:00:02 -0800546cfgoutputs_out="Makefile"
547cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
548cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800549cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
550cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
551cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans376b1522010-02-11 14:45:59 -0800552cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800553cfgoutputs_out="${cfgoutputs_out} test/test.sh"
554cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800555
Jason Evansaee7fd22010-11-24 22:00:02 -0800556cfgoutputs_tup="Makefile"
557cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
558cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800559cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
560cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
561cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800562cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800563cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
564cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800565
Jason Evans0656ec02010-04-07 23:37:35 -0700566cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800567cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal_defs.h.in"
568cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_namespace.sh"
569cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_unnamespace.sh"
Jason Evansf234dc52014-01-16 17:38:01 -0800570cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800571cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/public_namespace.sh"
572cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/public_unnamespace.sh"
Jason Evansb1726102012-02-28 16:50:47 -0800573cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansf234dc52014-01-16 17:38:01 -0800574cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc_rename.sh"
575cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc_mangle.sh"
Jason Evansdc1bed62013-12-05 21:43:46 -0800576cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc.sh"
Jason Evans80061b62013-12-09 13:21:08 -0800577cfghdrs_in="${cfghdrs_in} ${srcroot}test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800578
Jason Evans86abd0d2013-11-30 15:25:42 -0800579cfghdrs_out="include/jemalloc/jemalloc_defs.h"
580cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800581cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
582cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800583cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800584cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
585cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800586cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800587cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
588cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
589cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
590cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
591cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800592cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800593
Jason Evans86abd0d2013-11-30 15:25:42 -0800594cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
595cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:${srcroot}include/jemalloc/internal/jemalloc_internal_defs.h.in"
Jason Evans80061b62013-12-09 13:21:08 -0800596cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:${srcroot}test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800597
Jason Evans355b4382010-09-20 19:20:48 -0700598dnl Do not silence irrelevant compiler warnings by default, since enabling this
599dnl option incurs a performance penalty.
600AC_ARG_ENABLE([cc-silence],
601 [AS_HELP_STRING([--enable-cc-silence],
602 [Silence irrelevant compiler warnings])],
603[if test "x$enable_cc_silence" = "xno" ; then
604 enable_cc_silence="0"
605else
606 enable_cc_silence="1"
607fi
608],
609[enable_cc_silence="0"]
610)
611if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700612 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700613fi
614
Jason Evansb7924f52009-06-23 19:01:18 -0700615dnl Do not compile with debugging by default.
616AC_ARG_ENABLE([debug],
Mike Hommey5135e342012-12-06 22:16:26 +0100617 [AS_HELP_STRING([--enable-debug], [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700618[if test "x$enable_debug" = "xno" ; then
619 enable_debug="0"
620else
621 enable_debug="1"
622fi
623],
624[enable_debug="0"]
625)
626if test "x$enable_debug" = "x1" ; then
627 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Mike Hommey5135e342012-12-06 22:16:26 +0100628 enable_ivsalloc="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700629fi
630AC_SUBST([enable_debug])
631
Mike Hommey5135e342012-12-06 22:16:26 +0100632dnl Do not validate pointers by default.
633AC_ARG_ENABLE([ivsalloc],
634 [AS_HELP_STRING([--enable-ivsalloc], [Validate pointers passed through the public API])],
635[if test "x$enable_ivsalloc" = "xno" ; then
636 enable_ivsalloc="0"
637else
638 enable_ivsalloc="1"
639fi
640],
641[enable_ivsalloc="0"]
642)
643if test "x$enable_ivsalloc" = "x1" ; then
644 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
645fi
646
Jason Evansb7924f52009-06-23 19:01:18 -0700647dnl Only optimize if not debugging.
648if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
649 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700650 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800651 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700652 if test "x${optimize}" = "xyes" ; then
653 if test "x$GCC" = "xyes" ; then
654 JE_CFLAGS_APPEND([-O3])
655 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200656 elif test "x$je_cv_msvc" = "xyes" ; then
657 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700658 else
659 JE_CFLAGS_APPEND([-O])
660 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700661 fi
662fi
663
Jason Evansd073a322012-02-28 20:41:16 -0800664dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700665AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800666 [AS_HELP_STRING([--disable-stats],
667 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700668[if test "x$enable_stats" = "xno" ; then
669 enable_stats="0"
670else
671 enable_stats="1"
672fi
673],
Jason Evansd073a322012-02-28 20:41:16 -0800674[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700675)
676if test "x$enable_stats" = "x1" ; then
677 AC_DEFINE([JEMALLOC_STATS], [ ])
678fi
679AC_SUBST([enable_stats])
680
Jason Evans6109fe02010-02-10 10:37:56 -0800681dnl Do not enable profiling by default.
682AC_ARG_ENABLE([prof],
683 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
684[if test "x$enable_prof" = "xno" ; then
685 enable_prof="0"
686else
687 enable_prof="1"
688fi
689],
690[enable_prof="0"]
691)
Jason Evans77f350b2011-03-15 22:23:12 -0700692if test "x$enable_prof" = "x1" ; then
693 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800694else
Jason Evans77f350b2011-03-15 22:23:12 -0700695 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800696fi
Jason Evans77f350b2011-03-15 22:23:12 -0700697
Jason Evans6109fe02010-02-10 10:37:56 -0800698AC_ARG_ENABLE([prof-libunwind],
699 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
700[if test "x$enable_prof_libunwind" = "xno" ; then
701 enable_prof_libunwind="0"
702else
703 enable_prof_libunwind="1"
704fi
705],
706[enable_prof_libunwind="0"]
707)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800708AC_ARG_WITH([static_libunwind],
709 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
710 [Path to static libunwind library; use rather than dynamically linking])],
711if test "x$with_static_libunwind" = "xno" ; then
712 LUNWIND="-lunwind"
713else
714 if test ! -f "$with_static_libunwind" ; then
715 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
716 fi
717 LUNWIND="$with_static_libunwind"
718fi,
719 LUNWIND="-lunwind"
720)
Jason Evans77f350b2011-03-15 22:23:12 -0700721if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
722 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
723 if test "x$LUNWIND" = "x-lunwind" ; then
724 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
725 [enable_prof_libunwind="0"])
726 else
727 LIBS="$LIBS $LUNWIND"
728 fi
729 if test "x${enable_prof_libunwind}" = "x1" ; then
730 backtrace_method="libunwind"
731 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
732 fi
733fi
734
735AC_ARG_ENABLE([prof-libgcc],
736 [AS_HELP_STRING([--disable-prof-libgcc],
737 [Do not use libgcc for backtracing])],
738[if test "x$enable_prof_libgcc" = "xno" ; then
739 enable_prof_libgcc="0"
740else
741 enable_prof_libgcc="1"
742fi
743],
744[enable_prof_libgcc="1"]
745)
746if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
747 -a "x$GCC" = "xyes" ; then
748 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
749 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
750 dnl The following is conservative, in that it only has entries for CPUs on
751 dnl which jemalloc has been tested.
752 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
753 case "${host_cpu}" in
754 i[[3456]]86)
755 AC_MSG_RESULT([unreliable])
756 enable_prof_libgcc="0";
757 ;;
758 x86_64)
759 AC_MSG_RESULT([reliable])
760 ;;
761 *)
762 AC_MSG_RESULT([unreliable])
763 enable_prof_libgcc="0";
764 ;;
765 esac
766 if test "x${enable_prof_libgcc}" = "x1" ; then
767 backtrace_method="libgcc"
768 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
769 fi
770else
771 enable_prof_libgcc="0"
772fi
773
774AC_ARG_ENABLE([prof-gcc],
775 [AS_HELP_STRING([--disable-prof-gcc],
776 [Do not use gcc intrinsics for backtracing])],
777[if test "x$enable_prof_gcc" = "xno" ; then
778 enable_prof_gcc="0"
779else
780 enable_prof_gcc="1"
781fi
782],
783[enable_prof_gcc="1"]
784)
785if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
786 -a "x$GCC" = "xyes" ; then
787 backtrace_method="gcc intrinsics"
788 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
789else
790 enable_prof_gcc="0"
791fi
792
793if test "x$backtrace_method" = "x" ; then
794 backtrace_method="none (disabling profiling)"
795 enable_prof="0"
796fi
797AC_MSG_CHECKING([configured backtracing method])
798AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700799if test "x$enable_prof" = "x1" ; then
Jason Evans6716aa82012-04-23 13:04:55 -0700800 if test "x${force_tls}" = "x0" ; then
801 AC_MSG_ERROR([Heap profiling requires TLS]);
802 fi
803 force_tls="1"
Jason Evansd37d5ad2013-12-05 23:01:50 -0800804
805 if test "x$abi" != "xpecoff"; then
806 dnl Heap profiling uses the log(3) function.
807 LIBS="$LIBS -lm"
808 fi
809
Jason Evans2dbecf12010-09-05 10:35:13 -0700810 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700811fi
812AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700813
Jason Evans84cbbcb2009-12-29 00:09:15 -0800814dnl Enable thread-specific caching by default.
815AC_ARG_ENABLE([tcache],
816 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
817[if test "x$enable_tcache" = "xno" ; then
818 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700819else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800820 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700821fi
822],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800823[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700824)
Jason Evans2dbecf12010-09-05 10:35:13 -0700825if test "x$enable_tcache" = "x1" ; then
826 AC_DEFINE([JEMALLOC_TCACHE], [ ])
827fi
828AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700829
Jason Evans2e671ff2012-05-09 16:12:00 -0700830dnl Disable mremap() for huge realloc() by default.
831AC_ARG_ENABLE([mremap],
832 [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
833[if test "x$enable_mremap" = "xno" ; then
834 enable_mremap="0"
835else
836 enable_mremap="1"
837fi
838],
839[enable_mremap="0"]
840)
841if test "x$enable_mremap" = "x1" ; then
842 JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
Jason Evansa4f124f2013-12-08 22:28:27 -0800843#define _GNU_SOURCE
Jason Evans2e671ff2012-05-09 16:12:00 -0700844#include <sys/mman.h>
845], [
846void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
847], [je_cv_mremap_fixed])
848 if test "x${je_cv_mremap_fixed}" = "xno" ; then
849 enable_mremap="0"
850 fi
851fi
852if test "x$enable_mremap" = "x1" ; then
853 AC_DEFINE([JEMALLOC_MREMAP], [ ])
854fi
855AC_SUBST([enable_mremap])
856
Jason Evans59ae2762012-04-16 17:52:27 -0700857dnl Enable VM deallocation via munmap() by default.
858AC_ARG_ENABLE([munmap],
859 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
860[if test "x$enable_munmap" = "xno" ; then
861 enable_munmap="0"
862else
863 enable_munmap="1"
864fi
865],
866[enable_munmap="${default_munmap}"]
867)
868if test "x$enable_munmap" = "x1" ; then
869 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
870fi
871AC_SUBST([enable_munmap])
872
Jason Evansb7924f52009-06-23 19:01:18 -0700873dnl Do not enable allocation from DSS by default.
874AC_ARG_ENABLE([dss],
875 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
876[if test "x$enable_dss" = "xno" ; then
877 enable_dss="0"
878else
879 enable_dss="1"
880fi
881],
882[enable_dss="0"]
883)
Mike Hommey83c324a2012-04-12 10:13:03 +0200884dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
885AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
886if test "x$have_sbrk" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800887 if test "x$sbrk_deprecated" == "x1" ; then
888 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
889 enable_dss="0"
890 else
891 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
892 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200893else
894 enable_dss="0"
895fi
896
Jason Evansb7924f52009-06-23 19:01:18 -0700897if test "x$enable_dss" = "x1" ; then
898 AC_DEFINE([JEMALLOC_DSS], [ ])
899fi
900AC_SUBST([enable_dss])
901
Jason Evans777c1912012-02-28 20:49:22 -0800902dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700903AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700904 [AS_HELP_STRING([--disable-fill],
905 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700906[if test "x$enable_fill" = "xno" ; then
907 enable_fill="0"
908else
909 enable_fill="1"
910fi
911],
Jason Evans777c1912012-02-28 20:49:22 -0800912[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700913)
914if test "x$enable_fill" = "x1" ; then
915 AC_DEFINE([JEMALLOC_FILL], [ ])
916fi
917AC_SUBST([enable_fill])
918
Jason Evansb1476112012-04-05 13:36:17 -0700919dnl Disable utrace(2)-based tracing by default.
920AC_ARG_ENABLE([utrace],
921 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
922[if test "x$enable_utrace" = "xno" ; then
923 enable_utrace="0"
924else
925 enable_utrace="1"
926fi
927],
928[enable_utrace="0"]
929)
930JE_COMPILABLE([utrace(2)], [
931#include <sys/types.h>
932#include <sys/param.h>
933#include <sys/time.h>
934#include <sys/uio.h>
935#include <sys/ktrace.h>
936], [
937 utrace((void *)0, 0);
938], [je_cv_utrace])
939if test "x${je_cv_utrace}" = "xno" ; then
940 enable_utrace="0"
941fi
942if test "x$enable_utrace" = "x1" ; then
943 AC_DEFINE([JEMALLOC_UTRACE], [ ])
944fi
945AC_SUBST([enable_utrace])
946
Jason Evans122449b2012-04-06 00:35:09 -0700947dnl Support Valgrind by default.
948AC_ARG_ENABLE([valgrind],
949 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
950[if test "x$enable_valgrind" = "xno" ; then
951 enable_valgrind="0"
952else
953 enable_valgrind="1"
954fi
955],
956[enable_valgrind="1"]
957)
958if test "x$enable_valgrind" = "x1" ; then
959 JE_COMPILABLE([valgrind], [
960#include <valgrind/valgrind.h>
961#include <valgrind/memcheck.h>
962
Mike Hommey7bfecf42012-04-30 15:15:15 +0200963#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -0700964# error "Incompatible Valgrind version"
965#endif
966], [], [je_cv_valgrind])
967 if test "x${je_cv_valgrind}" = "xno" ; then
968 enable_valgrind="0"
969 fi
970 if test "x$enable_valgrind" = "x1" ; then
971 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
972 fi
973fi
974AC_SUBST([enable_valgrind])
975
Jason Evansb7924f52009-06-23 19:01:18 -0700976dnl Do not support the xmalloc option by default.
977AC_ARG_ENABLE([xmalloc],
978 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
979[if test "x$enable_xmalloc" = "xno" ; then
980 enable_xmalloc="0"
981else
982 enable_xmalloc="1"
983fi
984],
985[enable_xmalloc="0"]
986)
987if test "x$enable_xmalloc" = "x1" ; then
988 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
989fi
990AC_SUBST([enable_xmalloc])
991
Jason Evans6684cac2012-03-05 12:15:36 -0800992AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
993 [je_cv_static_page_shift],
994 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -0700995[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200996#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700997#ifdef _WIN32
998#include <windows.h>
999#else
Jason Evansb7924f52009-06-23 19:01:18 -07001000#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001001#endif
1002#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -08001003]],
1004[[
Garrett Cooper72c1e592012-12-02 17:57:28 -08001005 int result;
Jason Evansb7924f52009-06-23 19:01:18 -07001006 FILE *f;
1007
Mike Hommeya19e87f2012-04-21 21:27:46 -07001008#ifdef _WIN32
1009 SYSTEM_INFO si;
1010 GetSystemInfo(&si);
1011 result = si.dwPageSize;
1012#else
Jason Evansb7924f52009-06-23 19:01:18 -07001013 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001014#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001015 if (result == -1) {
1016 return 1;
1017 }
Mike Hommeya19e87f2012-04-21 21:27:46 -07001018 result = ffsl(result) - 1;
1019
Jason Evansb7924f52009-06-23 19:01:18 -07001020 f = fopen("conftest.out", "w");
1021 if (f == NULL) {
1022 return 1;
1023 }
Garrett Cooper72c1e592012-12-02 17:57:28 -08001024 fprintf(f, "%d\n", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001025 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001026
1027 return 0;
1028]])],
Jason Evans6684cac2012-03-05 12:15:36 -08001029 [je_cv_static_page_shift=`cat conftest.out`],
1030 [je_cv_static_page_shift=undefined]))
1031
1032if test "x$je_cv_static_page_shift" != "xundefined"; then
1033 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
1034else
1035 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
1036fi
Jason Evansb7924f52009-06-23 19:01:18 -07001037
1038dnl ============================================================================
1039dnl jemalloc configuration.
1040dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001041
1042dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -07001043if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -07001044 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -08001045fi
Jason Evansb7924f52009-06-23 19:01:18 -07001046jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001047jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1048jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1049jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1050jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1051jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001052AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001053AC_SUBST([jemalloc_version_major])
1054AC_SUBST([jemalloc_version_minor])
1055AC_SUBST([jemalloc_version_bugfix])
1056AC_SUBST([jemalloc_version_nrev])
1057AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001058
1059dnl ============================================================================
1060dnl Configure pthreads.
1061
Mike Hommeya19e87f2012-04-21 21:27:46 -07001062if test "x$abi" != "xpecoff" ; then
1063 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1064 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1065 dnl first, but try libc too before failing.
1066 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1067 [AC_SEARCH_LIBS([pthread_create], , ,
1068 AC_MSG_ERROR([libpthread is missing]))])
1069fi
Jason Evansb7924f52009-06-23 19:01:18 -07001070
1071CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1072
Jason Evanscd9a1342012-03-21 18:33:03 -07001073dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1074dnl it rather than pthreads TSD cleanup functions to support cleanup during
1075dnl thread exit, in order to avoid pthreads library recursion during
1076dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001077AC_CHECK_FUNC([_malloc_thread_cleanup],
1078 [have__malloc_thread_cleanup="1"],
1079 [have__malloc_thread_cleanup="0"]
1080 )
1081if test "x$have__malloc_thread_cleanup" = "x1" ; then
1082 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1083 force_tls="1"
1084fi
1085
Jason Evans41b6afb2012-02-02 22:04:57 -08001086dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1087dnl so, mutex initialization causes allocation, and we need to implement this
1088dnl callback function in order to prevent recursive allocation.
1089AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1090 [have__pthread_mutex_init_calloc_cb="1"],
1091 [have__pthread_mutex_init_calloc_cb="0"]
1092 )
1093if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1094 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1095fi
1096
Jason Evans0fee70d2012-02-13 12:36:11 -08001097dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001098AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001099 [AS_HELP_STRING([--enable-lazy-lock],
1100 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001101[if test "x$enable_lazy_lock" = "xno" ; then
1102 enable_lazy_lock="0"
1103else
1104 enable_lazy_lock="1"
1105fi
1106],
Jason Evans0fee70d2012-02-13 12:36:11 -08001107[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -07001108)
Jason Evansfd4fcef2012-03-23 17:40:58 -07001109if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1110 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1111 enable_lazy_lock="1"
1112fi
Jason Evansb7924f52009-06-23 19:01:18 -07001113if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001114 if test "x$abi" != "xpecoff" ; then
1115 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1116 AC_CHECK_FUNC([dlsym], [],
1117 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1118 [AC_MSG_ERROR([libdl is missing])])
1119 ])
1120 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001121 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1122fi
1123AC_SUBST([enable_lazy_lock])
1124
Jason Evans78d815c2010-01-17 14:06:20 -08001125AC_ARG_ENABLE([tls],
1126 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1127if test "x$enable_tls" = "xno" ; then
1128 enable_tls="0"
1129else
1130 enable_tls="1"
1131fi
1132,
1133enable_tls="1"
1134)
Jason Evanscd9a1342012-03-21 18:33:03 -07001135if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1136 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1137 enable_tls="1"
1138fi
Jason Evansb80581d2012-03-23 16:17:43 -07001139if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1140 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1141 enable_tls="0"
1142fi
Jason Evans78d815c2010-01-17 14:06:20 -08001143if test "x${enable_tls}" = "x1" ; then
1144AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001145AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001146[[
1147 __thread int x;
1148]], [[
1149 x = 42;
1150
1151 return 0;
1152]])],
1153 AC_MSG_RESULT([yes]),
1154 AC_MSG_RESULT([no])
1155 enable_tls="0")
1156fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001157AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001158if test "x${enable_tls}" = "x1" ; then
1159 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001160elif test "x${force_tls}" = "x1" ; then
1161 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -08001162fi
1163
Jason Evans2dbecf12010-09-05 10:35:13 -07001164dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -07001165dnl Check for ffsl(3), and fail if not found. This function exists on all
1166dnl platforms that jemalloc currently has a chance of functioning on without
1167dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -07001168JE_COMPILABLE([a program using ffsl], [
Garrett Cooper72c1e592012-12-02 17:57:28 -08001169#include <stdio.h>
Jason Evans382132e2012-04-04 15:25:43 -07001170#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -07001171#include <string.h>
1172], [
1173 {
1174 int rv = ffsl(0x08);
Garrett Cooper72c1e592012-12-02 17:57:28 -08001175 printf("%d\n", rv);
Jason Evans4c2faa82012-03-13 11:09:23 -07001176 }
1177], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -08001178if test "x${je_cv_function_ffsl}" != "xyes" ; then
1179 AC_MSG_ERROR([Cannot build without ffsl(3)])
1180fi
Jason Evans84c8eef2011-03-16 10:30:13 -07001181
1182dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001183dnl Check for atomic(9) operations as provided on FreeBSD.
1184
1185JE_COMPILABLE([atomic(9)], [
1186#include <sys/types.h>
1187#include <machine/atomic.h>
1188#include <inttypes.h>
1189], [
1190 {
1191 uint32_t x32 = 0;
1192 volatile uint32_t *x32p = &x32;
1193 atomic_fetchadd_32(x32p, 1);
1194 }
1195 {
1196 unsigned long xlong = 0;
1197 volatile unsigned long *xlongp = &xlong;
1198 atomic_fetchadd_long(xlongp, 1);
1199 }
1200], [je_cv_atomic9])
1201if test "x${je_cv_atomic9}" = "xyes" ; then
1202 AC_DEFINE([JEMALLOC_ATOMIC9])
1203fi
1204
1205dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001206dnl Check for atomic(3) operations as provided on Darwin.
1207
1208JE_COMPILABLE([Darwin OSAtomic*()], [
1209#include <libkern/OSAtomic.h>
1210#include <inttypes.h>
1211], [
1212 {
1213 int32_t x32 = 0;
1214 volatile int32_t *x32p = &x32;
1215 OSAtomicAdd32(1, x32p);
1216 }
1217 {
1218 int64_t x64 = 0;
1219 volatile int64_t *x64p = &x64;
1220 OSAtomicAdd64(1, x64p);
1221 }
Jason Evans6684cac2012-03-05 12:15:36 -08001222], [je_cv_osatomic])
1223if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001224 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001225fi
1226
1227dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001228dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1229dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1230
1231AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1232 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1233 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001234 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1235 #include <stdint.h>
1236 ],
1237 [
1238 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1239 {
1240 uint$1_t x$1 = 0;
1241 __sync_add_and_fetch(&x$1, 42);
1242 __sync_sub_and_fetch(&x$1, 1);
1243 }
1244 #else
1245 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1246 #endif
1247 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001248 [je_cv_sync_compare_and_swap_$2=yes],
1249 [je_cv_sync_compare_and_swap_$2=no])])
1250
1251 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1252 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1253 fi
1254])
1255
Jason Evansb57d3ec2012-04-17 13:17:54 -07001256if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001257 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1258 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1259fi
1260
1261dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001262dnl Check for spinlock(3) operations as provided on Darwin.
1263
1264JE_COMPILABLE([Darwin OSSpin*()], [
1265#include <libkern/OSAtomic.h>
1266#include <inttypes.h>
1267], [
1268 OSSpinLock lock = 0;
1269 OSSpinLockLock(&lock);
1270 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001271], [je_cv_osspin])
1272if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001273 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001274fi
1275
1276dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001277dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001278
Mike Hommeyd0357f72012-11-26 18:52:41 +01001279AC_ARG_ENABLE([zone-allocator],
1280 [AS_HELP_STRING([--disable-zone-allocator],
1281 [Disable zone allocator for Darwin])],
1282[if test "x$enable_zone_allocator" = "xno" ; then
1283 enable_zone_allocator="0"
1284else
1285 enable_zone_allocator="1"
1286fi
1287],
1288[if test "x${abi}" = "xmacho"; then
1289 enable_zone_allocator="1"
1290fi
1291]
1292)
1293AC_SUBST([enable_zone_allocator])
1294
1295if test "x${enable_zone_allocator}" = "x1" ; then
1296 if test "x${abi}" != "xmacho"; then
1297 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1298 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001299 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1300 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001301
Jason Evans2dbecf12010-09-05 10:35:13 -07001302 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1303 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1304 dnl 10.6, which is the only source-level indication of the change.
1305 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001306 AC_DEFUN([JE_ZONE_PROGRAM],
1307 [AC_LANG_PROGRAM(
1308 [#include <malloc/malloc.h>],
1309 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1310 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001311
Mike Hommey154829d2012-03-20 18:01:38 +01001312 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1313 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1314 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1315 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1316 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1317 )])],[
1318 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1319 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1320 )])])])])
1321 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1322 AC_MSG_RESULT([unsupported])
1323 AC_MSG_ERROR([Unsupported malloc zone version])
1324 fi
1325 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1326 JEMALLOC_ZONE_VERSION=8
1327 AC_MSG_RESULT([> 8])
1328 else
1329 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1330 fi
1331 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001332fi
1333
Jason Evansb7924f52009-06-23 19:01:18 -07001334dnl ============================================================================
1335dnl Check for typedefs, structures, and compiler characteristics.
1336AC_HEADER_STDBOOL
1337
Jason Evans748dfac2013-12-06 18:27:33 -08001338dnl ============================================================================
1339dnl Define commands that generate output files.
1340
Jason Evans86abd0d2013-11-30 15:25:42 -08001341AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1342 mkdir -p "${objroot}include/jemalloc/internal"
1343 "${srcdir}/include/jemalloc/internal/private_namespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_namespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001344], [
1345 srcdir="${srcdir}"
1346 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001347])
1348AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1349 mkdir -p "${objroot}include/jemalloc/internal"
1350 "${srcdir}/include/jemalloc/internal/private_unnamespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001351], [
1352 srcdir="${srcdir}"
1353 objroot="${objroot}"
1354])
1355AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1356 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1357 mkdir -p "${objroot}include/jemalloc/internal"
1358 cp /dev/null "${f}"
1359 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1360 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1361 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1362 echo "${n}:${m}" >> "${f}"
1363 dnl Remove name from public_syms so that it isn't redefined later.
1364 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1365 done
1366 for sym in ${public_syms} ; do
1367 n="${sym}"
1368 m="${JEMALLOC_PREFIX}${sym}"
1369 echo "${n}:${m}" >> "${f}"
1370 done
1371], [
1372 srcdir="${srcdir}"
1373 objroot="${objroot}"
1374 mangling_map="${mangling_map}"
1375 public_syms="${public_syms}"
1376 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001377])
1378AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1379 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001380 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1381], [
1382 srcdir="${srcdir}"
1383 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001384])
1385AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1386 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001387 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1388], [
1389 srcdir="${srcdir}"
1390 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001391])
Jason Evansb1726102012-02-28 16:50:47 -08001392AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001393 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansb1726102012-02-28 16:50:47 -08001394 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001395], [
1396 srcdir="${srcdir}"
1397 objroot="${objroot}"
Jason Evansb1726102012-02-28 16:50:47 -08001398])
Jason Evans86abd0d2013-11-30 15:25:42 -08001399AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1400 mkdir -p "${objroot}include/jemalloc"
1401 cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001402], [
1403 srcdir="${srcdir}"
1404 objroot="${objroot}"
1405])
1406AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1407 mkdir -p "${objroot}include/jemalloc"
1408 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1409], [
1410 srcdir="${srcdir}"
1411 objroot="${objroot}"
1412])
1413AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1414 mkdir -p "${objroot}include/jemalloc"
1415 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1416], [
1417 srcdir="${srcdir}"
1418 objroot="${objroot}"
1419])
1420AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1421 mkdir -p "${objroot}include/jemalloc"
1422 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1423], [
1424 srcdir="${srcdir}"
1425 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001426])
1427AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1428 mkdir -p "${objroot}include/jemalloc"
1429 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001430], [
1431 srcdir="${srcdir}"
1432 objroot="${objroot}"
1433 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001434])
Jason Evansb1726102012-02-28 16:50:47 -08001435
Jason Evansb7924f52009-06-23 19:01:18 -07001436dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001437AC_SUBST([cfghdrs_in])
1438AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001439AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001440
1441dnl ============================================================================
1442dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001443
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001444AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001445AC_SUBST([cfgoutputs_in])
1446AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001447AC_OUTPUT
1448
1449dnl ============================================================================
1450dnl Print out the results of configuration.
1451AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001452AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1453AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001454AC_MSG_RESULT([])
1455AC_MSG_RESULT([CC : ${CC}])
1456AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1457AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1458AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001459AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001460AC_MSG_RESULT([LIBS : ${LIBS}])
1461AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1462AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001463AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1464AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1465AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001466AC_MSG_RESULT([PREFIX : ${PREFIX}])
1467AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001468AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1469AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001470AC_MSG_RESULT([DATADIR : ${DATADIR}])
1471AC_MSG_RESULT([MANDIR : ${MANDIR}])
1472AC_MSG_RESULT([])
1473AC_MSG_RESULT([srcroot : ${srcroot}])
1474AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1475AC_MSG_RESULT([objroot : ${objroot}])
1476AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1477AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001478AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001479AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1480AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001481AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001482AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001483AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001484AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001485AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001486AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001487AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001488AC_MSG_RESULT([prof : ${enable_prof}])
1489AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001490AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1491AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001492AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001493AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001494AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001495AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1496AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans2e671ff2012-05-09 16:12:00 -07001497AC_MSG_RESULT([mremap : ${enable_mremap}])
Jason Evans59ae2762012-04-16 17:52:27 -07001498AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001499AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001500AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001501AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001502AC_MSG_RESULT([===============================================================================])