blob: 5aeaa08832956917b48a83b4a7a1d2bc56587d20 [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.
Jason Evans9790b962014-04-14 22:32:31 -070047rev=2
Jason Evansf576c632011-11-01 22:27:41 -070048AC_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
Mike Hommeyff2e9992014-05-29 16:33:02 +0900158if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
159 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat/C99"
160fi
161
Jason Evansb7924f52009-06-23 19:01:18 -0700162AC_CHECK_SIZEOF([void *])
163if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800164 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700165elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800166 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700167else
168 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
169fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800170AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
171
172AC_CHECK_SIZEOF([int])
173if test "x${ac_cv_sizeof_int}" = "x8" ; then
174 LG_SIZEOF_INT=3
175elif test "x${ac_cv_sizeof_int}" = "x4" ; then
176 LG_SIZEOF_INT=2
177else
178 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
179fi
180AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700181
Jason Evans84c8eef2011-03-16 10:30:13 -0700182AC_CHECK_SIZEOF([long])
183if test "x${ac_cv_sizeof_long}" = "x8" ; then
184 LG_SIZEOF_LONG=3
185elif test "x${ac_cv_sizeof_long}" = "x4" ; then
186 LG_SIZEOF_LONG=2
187else
188 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
189fi
190AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
191
Jason Evansd81e4bd2012-03-06 14:57:45 -0800192AC_CHECK_SIZEOF([intmax_t])
193if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
194 LG_SIZEOF_INTMAX_T=4
195elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
196 LG_SIZEOF_INTMAX_T=3
197elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
198 LG_SIZEOF_INTMAX_T=2
199else
Mike Hommey14103d32012-04-20 08:38:39 +0200200 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800201fi
202AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
203
Jason Evansb7924f52009-06-23 19:01:18 -0700204AC_CANONICAL_HOST
205dnl CPU-specific settings.
206CPU_SPINWAIT=""
207case "${host_cpu}" in
208 i[[345]]86)
209 ;;
Jason Evanscb657e32014-02-25 11:21:41 -0800210 i686|x86_64)
211 JE_COMPILABLE([pause instruction], [],
212 [[__asm__ volatile("pause"); return 0;]],
213 [je_cv_pause])
214 if test "x${je_cv_pause}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700215 CPU_SPINWAIT='__asm__ volatile("pause")'
216 fi
Jason Evanscb657e32014-02-25 11:21:41 -0800217 dnl emmintrin.h fails to compile unless MMX, SSE, and SSE2 are
218 dnl supported.
219 JE_COMPILABLE([SSE2 intrinsics], [
220#include <emmintrin.h>
221], [], [je_cv_sse2])
222 if test "x${je_cv_sse2}" = "xyes" ; then
223 AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ])
Jason Evansf3340ca2009-06-30 16:17:05 -0700224 fi
Jason Evans80061b62013-12-09 13:21:08 -0800225 ;;
226 powerpc)
227 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700228 ;;
229 *)
230 ;;
231esac
232AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
233
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400234LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700235so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200236importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200237o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200238a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200239exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700240libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200241DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
242RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200243SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200244PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200245CTARGET='-o $@'
246LDTARGET='-o $@'
247EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100248ARFLAGS='crus'
249AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200250CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800251
Jory A. Prattad505e02013-08-11 09:44:59 -0500252AN_MAKEVAR([AR], [AC_PROG_AR])
253AN_PROGRAM([ar], [AC_PROG_AR])
254AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
255AC_PROG_AR
256
Jason Evansb7924f52009-06-23 19:01:18 -0700257dnl Platform-specific settings. abi and RPATH can probably be determined
258dnl programmatically, but doing so is error-prone, which makes it generally
259dnl not worth the trouble.
260dnl
261dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
262dnl definitions need to be seen before any headers are included, which is a pain
263dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700264default_munmap="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700265case "${host}" in
266 *-*-darwin*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200267 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700268 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700269 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700270 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400271 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700272 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200273 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700274 force_tls="0"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200275 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200276 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800277 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700278 ;;
279 *-*-freebsd*)
280 CFLAGS="$CFLAGS"
281 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700282 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700283 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700284 ;;
285 *-*-linux*)
286 CFLAGS="$CFLAGS"
287 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
288 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800289 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700290 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700291 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700292 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700293 ;;
294 *-*-netbsd*)
295 AC_MSG_CHECKING([ABI])
296 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
297[[#ifdef __ELF__
298/* ELF */
299#else
300#error aout
301#endif
302]])],
303 [CFLAGS="$CFLAGS"; abi="elf"],
304 [abi="aout"])
305 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700306 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700307 ;;
308 *-*-solaris2*)
309 CFLAGS="$CFLAGS"
310 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000311 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200312 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700313 dnl Solaris needs this for sigwait().
314 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
315 LIBS="$LIBS -lposix4 -lsocket -lnsl"
316 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400317 *-ibm-aix*)
318 if "$LG_SIZEOF_PTR" = "8"; then
319 dnl 64bit AIX
320 LD_PRELOAD_VAR="LDR_PRELOAD64"
321 else
322 dnl 32bit AIX
323 LD_PRELOAD_VAR="LDR_PRELOAD"
324 fi
325 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400326 ;;
Mike Hommeya19e87f2012-04-21 21:27:46 -0700327 *-*-mingw*)
328 abi="pecoff"
329 force_tls="0"
330 RPATH=""
331 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200332 if test "x$je_cv_msvc" = "xyes" ; then
333 importlib="lib"
334 DSO_LDFLAGS="-LD"
335 EXTRA_LDFLAGS="-link -DEBUG"
336 CTARGET='-Fo$@'
337 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500338 AR='lib'
339 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100340 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200341 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200342 else
343 importlib="${so}"
344 DSO_LDFLAGS="-shared"
345 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700346 a="lib"
347 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200348 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700349 PIC_CFLAGS=""
350 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700351 *)
352 AC_MSG_RESULT([Unsupported operating system: ${host}])
353 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700354 ;;
355esac
Mike Hommeyaffe0092014-05-28 08:10:12 +0900356
357JEMALLOC_USABLE_SIZE_CONST=const
358AC_CHECK_HEADERS([malloc.h], [
359 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
360 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
361 [#include <malloc.h>
362 #include <stddef.h>
363 size_t malloc_usable_size(const void *ptr);
364 ],
365 [])],[
366 AC_MSG_RESULT([yes])
367 ],[
368 JEMALLOC_USABLE_SIZE_CONST=
369 AC_MSG_RESULT([no])
370 ])
371])
Jason Evans247d1242012-10-09 16:20:10 -0700372AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700373AC_SUBST([abi])
374AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400375AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700376AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200377AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200378AC_SUBST([o])
379AC_SUBST([a])
380AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700381AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200382AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200383AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200384AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200385AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200386AC_SUBST([CTARGET])
387AC_SUBST([LDTARGET])
388AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100389AC_SUBST([ARFLAGS])
390AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200391AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200392
Jason Evansfa5d2452011-03-15 10:25:59 -0700393JE_COMPILABLE([__attribute__ syntax],
394 [static __attribute__((unused)) void foo(void){}],
395 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800396 [je_cv_attribute])
397if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700398 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
399 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
400 JE_CFLAGS_APPEND([-fvisibility=hidden])
401 fi
402fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700403dnl Check for tls_model attribute support (clang 3.0 still lacks support).
404SAVED_CFLAGS="${CFLAGS}"
405JE_CFLAGS_APPEND([-Werror])
406JE_COMPILABLE([tls_model attribute], [],
407 [static __thread int
408 __attribute__((tls_model("initial-exec"))) foo;
409 foo = 0;],
410 [je_cv_tls_model])
411CFLAGS="${SAVED_CFLAGS}"
412if test "x${je_cv_tls_model}" = "xyes" ; then
413 AC_DEFINE([JEMALLOC_TLS_MODEL],
414 [__attribute__((tls_model("initial-exec")))])
415else
416 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
417fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700418
Jason Evansb7924f52009-06-23 19:01:18 -0700419dnl Support optional additions to rpath.
420AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800421 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700422if test "x$with_rpath" = "xno" ; then
423 RPATH_EXTRA=
424else
425 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
426fi,
427 RPATH_EXTRA=
428)
429AC_SUBST([RPATH_EXTRA])
430
431dnl Disable rules that do automatic regeneration of configure output by default.
432AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800433 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700434if test "x$enable_autogen" = "xno" ; then
435 enable_autogen="0"
436else
437 enable_autogen="1"
438fi
439,
440enable_autogen="0"
441)
442AC_SUBST([enable_autogen])
443
444AC_PROG_INSTALL
445AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800446AC_PATH_PROG([LD], [ld], [false], [$PATH])
447AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700448
Jason Evansd82a5e62013-12-12 22:35:52 -0800449public_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 -0800450
451dnl Check for allocator-related functions that should be wrapped.
452AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700453 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800454 public_syms="${public_syms} memalign"])
455AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700456 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800457 public_syms="${public_syms} valloc"])
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 Evans644d4142014-04-14 22:49:23 -0700598dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700599AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700600 [AS_HELP_STRING([--disable-cc-silence],
601 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700602[if test "x$enable_cc_silence" = "xno" ; then
603 enable_cc_silence="0"
604else
605 enable_cc_silence="1"
606fi
607],
Jason Evans644d4142014-04-14 22:49:23 -0700608[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700609)
610if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700611 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700612fi
613
Jason Evansb7924f52009-06-23 19:01:18 -0700614dnl Do not compile with debugging by default.
615AC_ARG_ENABLE([debug],
Mike Hommey5135e342012-12-06 22:16:26 +0100616 [AS_HELP_STRING([--enable-debug], [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700617[if test "x$enable_debug" = "xno" ; then
618 enable_debug="0"
619else
620 enable_debug="1"
621fi
622],
623[enable_debug="0"]
624)
625if test "x$enable_debug" = "x1" ; then
626 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Mike Hommey5135e342012-12-06 22:16:26 +0100627 enable_ivsalloc="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700628fi
629AC_SUBST([enable_debug])
630
Mike Hommey5135e342012-12-06 22:16:26 +0100631dnl Do not validate pointers by default.
632AC_ARG_ENABLE([ivsalloc],
633 [AS_HELP_STRING([--enable-ivsalloc], [Validate pointers passed through the public API])],
634[if test "x$enable_ivsalloc" = "xno" ; then
635 enable_ivsalloc="0"
636else
637 enable_ivsalloc="1"
638fi
639],
640[enable_ivsalloc="0"]
641)
642if test "x$enable_ivsalloc" = "x1" ; then
643 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
644fi
645
Jason Evansb7924f52009-06-23 19:01:18 -0700646dnl Only optimize if not debugging.
647if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
648 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700649 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800650 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700651 if test "x${optimize}" = "xyes" ; then
652 if test "x$GCC" = "xyes" ; then
653 JE_CFLAGS_APPEND([-O3])
654 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200655 elif test "x$je_cv_msvc" = "xyes" ; then
656 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700657 else
658 JE_CFLAGS_APPEND([-O])
659 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700660 fi
661fi
662
Jason Evansd073a322012-02-28 20:41:16 -0800663dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700664AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800665 [AS_HELP_STRING([--disable-stats],
666 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700667[if test "x$enable_stats" = "xno" ; then
668 enable_stats="0"
669else
670 enable_stats="1"
671fi
672],
Jason Evansd073a322012-02-28 20:41:16 -0800673[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700674)
675if test "x$enable_stats" = "x1" ; then
676 AC_DEFINE([JEMALLOC_STATS], [ ])
677fi
678AC_SUBST([enable_stats])
679
Jason Evans6109fe02010-02-10 10:37:56 -0800680dnl Do not enable profiling by default.
681AC_ARG_ENABLE([prof],
682 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
683[if test "x$enable_prof" = "xno" ; then
684 enable_prof="0"
685else
686 enable_prof="1"
687fi
688],
689[enable_prof="0"]
690)
Jason Evans77f350b2011-03-15 22:23:12 -0700691if test "x$enable_prof" = "x1" ; then
692 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800693else
Jason Evans77f350b2011-03-15 22:23:12 -0700694 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800695fi
Jason Evans77f350b2011-03-15 22:23:12 -0700696
Jason Evans6109fe02010-02-10 10:37:56 -0800697AC_ARG_ENABLE([prof-libunwind],
698 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
699[if test "x$enable_prof_libunwind" = "xno" ; then
700 enable_prof_libunwind="0"
701else
702 enable_prof_libunwind="1"
703fi
704],
705[enable_prof_libunwind="0"]
706)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800707AC_ARG_WITH([static_libunwind],
708 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
709 [Path to static libunwind library; use rather than dynamically linking])],
710if test "x$with_static_libunwind" = "xno" ; then
711 LUNWIND="-lunwind"
712else
713 if test ! -f "$with_static_libunwind" ; then
714 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
715 fi
716 LUNWIND="$with_static_libunwind"
717fi,
718 LUNWIND="-lunwind"
719)
Jason Evans77f350b2011-03-15 22:23:12 -0700720if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
721 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
722 if test "x$LUNWIND" = "x-lunwind" ; then
Jason Evans05125b82014-04-22 20:48:07 -0700723 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700724 [enable_prof_libunwind="0"])
725 else
726 LIBS="$LIBS $LUNWIND"
727 fi
728 if test "x${enable_prof_libunwind}" = "x1" ; then
729 backtrace_method="libunwind"
730 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
731 fi
732fi
733
734AC_ARG_ENABLE([prof-libgcc],
735 [AS_HELP_STRING([--disable-prof-libgcc],
736 [Do not use libgcc for backtracing])],
737[if test "x$enable_prof_libgcc" = "xno" ; then
738 enable_prof_libgcc="0"
739else
740 enable_prof_libgcc="1"
741fi
742],
743[enable_prof_libgcc="1"]
744)
745if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
746 -a "x$GCC" = "xyes" ; then
747 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
748 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
Jason Evans77f350b2011-03-15 22:23:12 -0700749 if test "x${enable_prof_libgcc}" = "x1" ; then
750 backtrace_method="libgcc"
751 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
752 fi
753else
754 enable_prof_libgcc="0"
755fi
756
757AC_ARG_ENABLE([prof-gcc],
758 [AS_HELP_STRING([--disable-prof-gcc],
759 [Do not use gcc intrinsics for backtracing])],
760[if test "x$enable_prof_gcc" = "xno" ; then
761 enable_prof_gcc="0"
762else
763 enable_prof_gcc="1"
764fi
765],
766[enable_prof_gcc="1"]
767)
768if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
769 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700770 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700771 backtrace_method="gcc intrinsics"
772 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
773else
774 enable_prof_gcc="0"
775fi
776
777if test "x$backtrace_method" = "x" ; then
778 backtrace_method="none (disabling profiling)"
779 enable_prof="0"
780fi
781AC_MSG_CHECKING([configured backtracing method])
782AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700783if test "x$enable_prof" = "x1" ; then
Jason Evans6716aa82012-04-23 13:04:55 -0700784 if test "x${force_tls}" = "x0" ; then
785 AC_MSG_ERROR([Heap profiling requires TLS]);
786 fi
787 force_tls="1"
Jason Evansd37d5ad2013-12-05 23:01:50 -0800788
789 if test "x$abi" != "xpecoff"; then
790 dnl Heap profiling uses the log(3) function.
791 LIBS="$LIBS -lm"
792 fi
793
Jason Evans2dbecf12010-09-05 10:35:13 -0700794 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700795fi
796AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700797
Jason Evans84cbbcb2009-12-29 00:09:15 -0800798dnl Enable thread-specific caching by default.
799AC_ARG_ENABLE([tcache],
800 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
801[if test "x$enable_tcache" = "xno" ; then
802 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700803else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800804 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700805fi
806],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800807[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700808)
Jason Evans2dbecf12010-09-05 10:35:13 -0700809if test "x$enable_tcache" = "x1" ; then
810 AC_DEFINE([JEMALLOC_TCACHE], [ ])
811fi
812AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700813
Jason Evans59ae2762012-04-16 17:52:27 -0700814dnl Enable VM deallocation via munmap() by default.
815AC_ARG_ENABLE([munmap],
816 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
817[if test "x$enable_munmap" = "xno" ; then
818 enable_munmap="0"
819else
820 enable_munmap="1"
821fi
822],
823[enable_munmap="${default_munmap}"]
824)
825if test "x$enable_munmap" = "x1" ; then
826 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
827fi
828AC_SUBST([enable_munmap])
829
Jason Evans4d434ad2014-04-15 12:09:48 -0700830dnl Enable allocation from DSS if supported by the OS.
831have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200832dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
833AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
834if test "x$have_sbrk" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800835 if test "x$sbrk_deprecated" == "x1" ; then
836 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700837 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800838 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200839else
Jason Evans4d434ad2014-04-15 12:09:48 -0700840 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200841fi
842
Jason Evans4d434ad2014-04-15 12:09:48 -0700843if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700844 AC_DEFINE([JEMALLOC_DSS], [ ])
845fi
Jason Evansb7924f52009-06-23 19:01:18 -0700846
Jason Evans777c1912012-02-28 20:49:22 -0800847dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700848AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700849 [AS_HELP_STRING([--disable-fill],
850 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700851[if test "x$enable_fill" = "xno" ; then
852 enable_fill="0"
853else
854 enable_fill="1"
855fi
856],
Jason Evans777c1912012-02-28 20:49:22 -0800857[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700858)
859if test "x$enable_fill" = "x1" ; then
860 AC_DEFINE([JEMALLOC_FILL], [ ])
861fi
862AC_SUBST([enable_fill])
863
Jason Evansb1476112012-04-05 13:36:17 -0700864dnl Disable utrace(2)-based tracing by default.
865AC_ARG_ENABLE([utrace],
866 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
867[if test "x$enable_utrace" = "xno" ; then
868 enable_utrace="0"
869else
870 enable_utrace="1"
871fi
872],
873[enable_utrace="0"]
874)
875JE_COMPILABLE([utrace(2)], [
876#include <sys/types.h>
877#include <sys/param.h>
878#include <sys/time.h>
879#include <sys/uio.h>
880#include <sys/ktrace.h>
881], [
882 utrace((void *)0, 0);
883], [je_cv_utrace])
884if test "x${je_cv_utrace}" = "xno" ; then
885 enable_utrace="0"
886fi
887if test "x$enable_utrace" = "x1" ; then
888 AC_DEFINE([JEMALLOC_UTRACE], [ ])
889fi
890AC_SUBST([enable_utrace])
891
Jason Evans122449b2012-04-06 00:35:09 -0700892dnl Support Valgrind by default.
893AC_ARG_ENABLE([valgrind],
894 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
895[if test "x$enable_valgrind" = "xno" ; then
896 enable_valgrind="0"
897else
898 enable_valgrind="1"
899fi
900],
901[enable_valgrind="1"]
902)
903if test "x$enable_valgrind" = "x1" ; then
904 JE_COMPILABLE([valgrind], [
905#include <valgrind/valgrind.h>
906#include <valgrind/memcheck.h>
907
Mike Hommey7bfecf42012-04-30 15:15:15 +0200908#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -0700909# error "Incompatible Valgrind version"
910#endif
911], [], [je_cv_valgrind])
912 if test "x${je_cv_valgrind}" = "xno" ; then
913 enable_valgrind="0"
914 fi
915 if test "x$enable_valgrind" = "x1" ; then
916 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
917 fi
918fi
919AC_SUBST([enable_valgrind])
920
Jason Evansb7924f52009-06-23 19:01:18 -0700921dnl Do not support the xmalloc option by default.
922AC_ARG_ENABLE([xmalloc],
923 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
924[if test "x$enable_xmalloc" = "xno" ; then
925 enable_xmalloc="0"
926else
927 enable_xmalloc="1"
928fi
929],
930[enable_xmalloc="0"]
931)
932if test "x$enable_xmalloc" = "x1" ; then
933 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
934fi
935AC_SUBST([enable_xmalloc])
936
Jason Evans6684cac2012-03-05 12:15:36 -0800937AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
938 [je_cv_static_page_shift],
939 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -0700940[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200941#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700942#ifdef _WIN32
943#include <windows.h>
944#else
Jason Evansb7924f52009-06-23 19:01:18 -0700945#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700946#endif
947#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800948]],
949[[
Garrett Cooper72c1e592012-12-02 17:57:28 -0800950 int result;
Jason Evansb7924f52009-06-23 19:01:18 -0700951 FILE *f;
952
Mike Hommeya19e87f2012-04-21 21:27:46 -0700953#ifdef _WIN32
954 SYSTEM_INFO si;
955 GetSystemInfo(&si);
956 result = si.dwPageSize;
957#else
Jason Evansb7924f52009-06-23 19:01:18 -0700958 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -0700959#endif
Jason Evansb7924f52009-06-23 19:01:18 -0700960 if (result == -1) {
961 return 1;
962 }
Mike Hommeya19e87f2012-04-21 21:27:46 -0700963 result = ffsl(result) - 1;
964
Jason Evansb7924f52009-06-23 19:01:18 -0700965 f = fopen("conftest.out", "w");
966 if (f == NULL) {
967 return 1;
968 }
Garrett Cooper72c1e592012-12-02 17:57:28 -0800969 fprintf(f, "%d\n", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700970 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700971
972 return 0;
973]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800974 [je_cv_static_page_shift=`cat conftest.out`],
Daniel Micayccf04662014-05-07 01:17:05 -0400975 [je_cv_static_page_shift=undefined],
976 [je_cv_static_page_shift=12]))
Jason Evans6684cac2012-03-05 12:15:36 -0800977
978if test "x$je_cv_static_page_shift" != "xundefined"; then
979 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
980else
981 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
982fi
Jason Evansb7924f52009-06-23 19:01:18 -0700983
984dnl ============================================================================
985dnl jemalloc configuration.
986dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800987
988dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700989if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700990 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800991fi
Jason Evansb7924f52009-06-23 19:01:18 -0700992jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800993jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
994jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
995jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
996jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
997jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700998AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800999AC_SUBST([jemalloc_version_major])
1000AC_SUBST([jemalloc_version_minor])
1001AC_SUBST([jemalloc_version_bugfix])
1002AC_SUBST([jemalloc_version_nrev])
1003AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001004
1005dnl ============================================================================
1006dnl Configure pthreads.
1007
Mike Hommeya19e87f2012-04-21 21:27:46 -07001008if test "x$abi" != "xpecoff" ; then
1009 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1010 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1011 dnl first, but try libc too before failing.
1012 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1013 [AC_SEARCH_LIBS([pthread_create], , ,
1014 AC_MSG_ERROR([libpthread is missing]))])
1015fi
Jason Evansb7924f52009-06-23 19:01:18 -07001016
1017CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1018
Jason Evanscd9a1342012-03-21 18:33:03 -07001019dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1020dnl it rather than pthreads TSD cleanup functions to support cleanup during
1021dnl thread exit, in order to avoid pthreads library recursion during
1022dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001023AC_CHECK_FUNC([_malloc_thread_cleanup],
1024 [have__malloc_thread_cleanup="1"],
1025 [have__malloc_thread_cleanup="0"]
1026 )
1027if test "x$have__malloc_thread_cleanup" = "x1" ; then
1028 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1029 force_tls="1"
1030fi
1031
Jason Evans41b6afb2012-02-02 22:04:57 -08001032dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1033dnl so, mutex initialization causes allocation, and we need to implement this
1034dnl callback function in order to prevent recursive allocation.
1035AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1036 [have__pthread_mutex_init_calloc_cb="1"],
1037 [have__pthread_mutex_init_calloc_cb="0"]
1038 )
1039if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1040 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1041fi
1042
Jason Evans0fee70d2012-02-13 12:36:11 -08001043dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001044AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001045 [AS_HELP_STRING([--enable-lazy-lock],
1046 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001047[if test "x$enable_lazy_lock" = "xno" ; then
1048 enable_lazy_lock="0"
1049else
1050 enable_lazy_lock="1"
1051fi
1052],
Jason Evans0fee70d2012-02-13 12:36:11 -08001053[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -07001054)
Jason Evansfd4fcef2012-03-23 17:40:58 -07001055if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1056 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1057 enable_lazy_lock="1"
1058fi
Jason Evansb7924f52009-06-23 19:01:18 -07001059if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001060 if test "x$abi" != "xpecoff" ; then
1061 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1062 AC_CHECK_FUNC([dlsym], [],
1063 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1064 [AC_MSG_ERROR([libdl is missing])])
1065 ])
1066 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001067 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1068fi
1069AC_SUBST([enable_lazy_lock])
1070
Jason Evans78d815c2010-01-17 14:06:20 -08001071AC_ARG_ENABLE([tls],
1072 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1073if test "x$enable_tls" = "xno" ; then
1074 enable_tls="0"
1075else
1076 enable_tls="1"
1077fi
1078,
1079enable_tls="1"
1080)
Jason Evanscd9a1342012-03-21 18:33:03 -07001081if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1082 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1083 enable_tls="1"
1084fi
Jason Evansb80581d2012-03-23 16:17:43 -07001085if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1086 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1087 enable_tls="0"
1088fi
Jason Evans78d815c2010-01-17 14:06:20 -08001089if test "x${enable_tls}" = "x1" ; then
1090AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001091AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001092[[
1093 __thread int x;
1094]], [[
1095 x = 42;
1096
1097 return 0;
1098]])],
1099 AC_MSG_RESULT([yes]),
1100 AC_MSG_RESULT([no])
1101 enable_tls="0")
1102fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001103AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001104if test "x${enable_tls}" = "x1" ; then
1105 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001106elif test "x${force_tls}" = "x1" ; then
1107 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -08001108fi
1109
Jason Evans2dbecf12010-09-05 10:35:13 -07001110dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -07001111dnl Check for ffsl(3), and fail if not found. This function exists on all
1112dnl platforms that jemalloc currently has a chance of functioning on without
1113dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -07001114JE_COMPILABLE([a program using ffsl], [
Garrett Cooper72c1e592012-12-02 17:57:28 -08001115#include <stdio.h>
Jason Evans382132e2012-04-04 15:25:43 -07001116#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -07001117#include <string.h>
1118], [
1119 {
1120 int rv = ffsl(0x08);
Garrett Cooper72c1e592012-12-02 17:57:28 -08001121 printf("%d\n", rv);
Jason Evans4c2faa82012-03-13 11:09:23 -07001122 }
1123], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -08001124if test "x${je_cv_function_ffsl}" != "xyes" ; then
1125 AC_MSG_ERROR([Cannot build without ffsl(3)])
1126fi
Jason Evans84c8eef2011-03-16 10:30:13 -07001127
1128dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001129dnl Check for atomic(9) operations as provided on FreeBSD.
1130
1131JE_COMPILABLE([atomic(9)], [
1132#include <sys/types.h>
1133#include <machine/atomic.h>
1134#include <inttypes.h>
1135], [
1136 {
1137 uint32_t x32 = 0;
1138 volatile uint32_t *x32p = &x32;
1139 atomic_fetchadd_32(x32p, 1);
1140 }
1141 {
1142 unsigned long xlong = 0;
1143 volatile unsigned long *xlongp = &xlong;
1144 atomic_fetchadd_long(xlongp, 1);
1145 }
1146], [je_cv_atomic9])
1147if test "x${je_cv_atomic9}" = "xyes" ; then
1148 AC_DEFINE([JEMALLOC_ATOMIC9])
1149fi
1150
1151dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001152dnl Check for atomic(3) operations as provided on Darwin.
1153
1154JE_COMPILABLE([Darwin OSAtomic*()], [
1155#include <libkern/OSAtomic.h>
1156#include <inttypes.h>
1157], [
1158 {
1159 int32_t x32 = 0;
1160 volatile int32_t *x32p = &x32;
1161 OSAtomicAdd32(1, x32p);
1162 }
1163 {
1164 int64_t x64 = 0;
1165 volatile int64_t *x64p = &x64;
1166 OSAtomicAdd64(1, x64p);
1167 }
Jason Evans6684cac2012-03-05 12:15:36 -08001168], [je_cv_osatomic])
1169if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001170 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001171fi
1172
1173dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001174dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1175dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1176
1177AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1178 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1179 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001180 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1181 #include <stdint.h>
1182 ],
1183 [
1184 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1185 {
1186 uint$1_t x$1 = 0;
1187 __sync_add_and_fetch(&x$1, 42);
1188 __sync_sub_and_fetch(&x$1, 1);
1189 }
1190 #else
1191 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1192 #endif
1193 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001194 [je_cv_sync_compare_and_swap_$2=yes],
1195 [je_cv_sync_compare_and_swap_$2=no])])
1196
1197 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1198 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1199 fi
1200])
1201
Jason Evansb57d3ec2012-04-17 13:17:54 -07001202if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001203 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1204 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1205fi
1206
1207dnl ============================================================================
Jason Evansd04047c2014-05-28 16:11:55 -07001208dnl Check for __builtin_clz() and __builtin_clzl().
1209
1210AC_CACHE_CHECK([for __builtin_clz],
1211 [je_cv_builtin_clz],
1212 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1213 [
1214 {
1215 unsigned x = 0;
1216 int y = __builtin_clz(x);
1217 }
1218 {
1219 unsigned long x = 0;
1220 int y = __builtin_clzl(x);
1221 }
1222 ])],
1223 [je_cv_builtin_clz=yes],
1224 [je_cv_builtin_clz=no])])
1225
1226if test "x${je_cv_builtin_clz}" = "xyes" ; then
1227 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1228fi
1229
1230dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001231dnl Check for spinlock(3) operations as provided on Darwin.
1232
1233JE_COMPILABLE([Darwin OSSpin*()], [
1234#include <libkern/OSAtomic.h>
1235#include <inttypes.h>
1236], [
1237 OSSpinLock lock = 0;
1238 OSSpinLockLock(&lock);
1239 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001240], [je_cv_osspin])
1241if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001242 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001243fi
1244
1245dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001246dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001247
Mike Hommeyd0357f72012-11-26 18:52:41 +01001248AC_ARG_ENABLE([zone-allocator],
1249 [AS_HELP_STRING([--disable-zone-allocator],
1250 [Disable zone allocator for Darwin])],
1251[if test "x$enable_zone_allocator" = "xno" ; then
1252 enable_zone_allocator="0"
1253else
1254 enable_zone_allocator="1"
1255fi
1256],
1257[if test "x${abi}" = "xmacho"; then
1258 enable_zone_allocator="1"
1259fi
1260]
1261)
1262AC_SUBST([enable_zone_allocator])
1263
1264if test "x${enable_zone_allocator}" = "x1" ; then
1265 if test "x${abi}" != "xmacho"; then
1266 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1267 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001268 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1269 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001270
Jason Evans2dbecf12010-09-05 10:35:13 -07001271 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1272 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1273 dnl 10.6, which is the only source-level indication of the change.
1274 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001275 AC_DEFUN([JE_ZONE_PROGRAM],
1276 [AC_LANG_PROGRAM(
1277 [#include <malloc/malloc.h>],
1278 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1279 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001280
Mike Hommey154829d2012-03-20 18:01:38 +01001281 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1282 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1283 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1284 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1285 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1286 )])],[
1287 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1288 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1289 )])])])])
1290 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1291 AC_MSG_RESULT([unsupported])
1292 AC_MSG_ERROR([Unsupported malloc zone version])
1293 fi
1294 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1295 JEMALLOC_ZONE_VERSION=8
1296 AC_MSG_RESULT([> 8])
1297 else
1298 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1299 fi
1300 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001301fi
1302
Jason Evansb7924f52009-06-23 19:01:18 -07001303dnl ============================================================================
1304dnl Check for typedefs, structures, and compiler characteristics.
1305AC_HEADER_STDBOOL
1306
Jason Evans748dfac2013-12-06 18:27:33 -08001307dnl ============================================================================
1308dnl Define commands that generate output files.
1309
Jason Evans86abd0d2013-11-30 15:25:42 -08001310AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1311 mkdir -p "${objroot}include/jemalloc/internal"
1312 "${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 -08001313], [
1314 srcdir="${srcdir}"
1315 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001316])
1317AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1318 mkdir -p "${objroot}include/jemalloc/internal"
1319 "${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 -08001320], [
1321 srcdir="${srcdir}"
1322 objroot="${objroot}"
1323])
1324AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1325 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1326 mkdir -p "${objroot}include/jemalloc/internal"
1327 cp /dev/null "${f}"
1328 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1329 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1330 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1331 echo "${n}:${m}" >> "${f}"
1332 dnl Remove name from public_syms so that it isn't redefined later.
1333 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1334 done
1335 for sym in ${public_syms} ; do
1336 n="${sym}"
1337 m="${JEMALLOC_PREFIX}${sym}"
1338 echo "${n}:${m}" >> "${f}"
1339 done
1340], [
1341 srcdir="${srcdir}"
1342 objroot="${objroot}"
1343 mangling_map="${mangling_map}"
1344 public_syms="${public_syms}"
1345 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001346])
1347AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1348 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001349 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1350], [
1351 srcdir="${srcdir}"
1352 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001353])
1354AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1355 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001356 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1357], [
1358 srcdir="${srcdir}"
1359 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001360])
Jason Evansb1726102012-02-28 16:50:47 -08001361AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001362 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansb1726102012-02-28 16:50:47 -08001363 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001364], [
1365 srcdir="${srcdir}"
1366 objroot="${objroot}"
Jason Evansb1726102012-02-28 16:50:47 -08001367])
Jason Evans86abd0d2013-11-30 15:25:42 -08001368AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1369 mkdir -p "${objroot}include/jemalloc"
1370 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 -08001371], [
1372 srcdir="${srcdir}"
1373 objroot="${objroot}"
1374])
1375AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1376 mkdir -p "${objroot}include/jemalloc"
1377 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1378], [
1379 srcdir="${srcdir}"
1380 objroot="${objroot}"
1381])
1382AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1383 mkdir -p "${objroot}include/jemalloc"
1384 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1385], [
1386 srcdir="${srcdir}"
1387 objroot="${objroot}"
1388])
1389AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1390 mkdir -p "${objroot}include/jemalloc"
1391 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1392], [
1393 srcdir="${srcdir}"
1394 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001395])
1396AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1397 mkdir -p "${objroot}include/jemalloc"
1398 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001399], [
1400 srcdir="${srcdir}"
1401 objroot="${objroot}"
1402 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001403])
Jason Evansb1726102012-02-28 16:50:47 -08001404
Jason Evansb7924f52009-06-23 19:01:18 -07001405dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001406AC_SUBST([cfghdrs_in])
1407AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001408AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001409
1410dnl ============================================================================
1411dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001412
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001413AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001414AC_SUBST([cfgoutputs_in])
1415AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001416AC_OUTPUT
1417
1418dnl ============================================================================
1419dnl Print out the results of configuration.
1420AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001421AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1422AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001423AC_MSG_RESULT([])
1424AC_MSG_RESULT([CC : ${CC}])
1425AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1426AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1427AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001428AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001429AC_MSG_RESULT([LIBS : ${LIBS}])
1430AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1431AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001432AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1433AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1434AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001435AC_MSG_RESULT([PREFIX : ${PREFIX}])
1436AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001437AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1438AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001439AC_MSG_RESULT([DATADIR : ${DATADIR}])
1440AC_MSG_RESULT([MANDIR : ${MANDIR}])
1441AC_MSG_RESULT([])
1442AC_MSG_RESULT([srcroot : ${srcroot}])
1443AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1444AC_MSG_RESULT([objroot : ${objroot}])
1445AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1446AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001447AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001448AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1449AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001450AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001451AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001452AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001453AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001454AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001455AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001456AC_MSG_RESULT([prof : ${enable_prof}])
1457AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001458AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1459AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001460AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001461AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001462AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001463AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1464AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001465AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001466AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001467AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001468AC_MSG_RESULT([===============================================================================])