blob: 045f62e2546695e486316c446dd6d5809547ce67 [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])
Mike Hommey8c615752014-05-29 16:58:21 +0900144 JE_CFLAGS_APPEND([-FS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200145 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat"
Jason Evanscfeccd32010-03-03 15:48:20 -0800146 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700147fi
148dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
149if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700150 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700151fi
152AC_PROG_CPP
153
Jason Evansdf3f2702014-03-30 16:27:08 -0700154AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
155if test "x${ac_cv_big_endian}" = "x1" ; then
156 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
157fi
158
Mike Hommeyff2e9992014-05-29 16:33:02 +0900159if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
160 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat/C99"
161fi
162
Jason Evansb7924f52009-06-23 19:01:18 -0700163AC_CHECK_SIZEOF([void *])
164if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800165 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700166elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800167 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700168else
169 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
170fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800171AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
172
173AC_CHECK_SIZEOF([int])
174if test "x${ac_cv_sizeof_int}" = "x8" ; then
175 LG_SIZEOF_INT=3
176elif test "x${ac_cv_sizeof_int}" = "x4" ; then
177 LG_SIZEOF_INT=2
178else
179 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
180fi
181AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700182
Jason Evans84c8eef2011-03-16 10:30:13 -0700183AC_CHECK_SIZEOF([long])
184if test "x${ac_cv_sizeof_long}" = "x8" ; then
185 LG_SIZEOF_LONG=3
186elif test "x${ac_cv_sizeof_long}" = "x4" ; then
187 LG_SIZEOF_LONG=2
188else
189 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
190fi
191AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
192
Jason Evansd81e4bd2012-03-06 14:57:45 -0800193AC_CHECK_SIZEOF([intmax_t])
194if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
195 LG_SIZEOF_INTMAX_T=4
196elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
197 LG_SIZEOF_INTMAX_T=3
198elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
199 LG_SIZEOF_INTMAX_T=2
200else
Mike Hommey14103d32012-04-20 08:38:39 +0200201 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800202fi
203AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
204
Jason Evansb7924f52009-06-23 19:01:18 -0700205AC_CANONICAL_HOST
206dnl CPU-specific settings.
207CPU_SPINWAIT=""
208case "${host_cpu}" in
209 i[[345]]86)
210 ;;
Jason Evanscb657e32014-02-25 11:21:41 -0800211 i686|x86_64)
212 JE_COMPILABLE([pause instruction], [],
213 [[__asm__ volatile("pause"); return 0;]],
214 [je_cv_pause])
215 if test "x${je_cv_pause}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700216 CPU_SPINWAIT='__asm__ volatile("pause")'
217 fi
Jason Evanscb657e32014-02-25 11:21:41 -0800218 dnl emmintrin.h fails to compile unless MMX, SSE, and SSE2 are
219 dnl supported.
220 JE_COMPILABLE([SSE2 intrinsics], [
221#include <emmintrin.h>
222], [], [je_cv_sse2])
223 if test "x${je_cv_sse2}" = "xyes" ; then
224 AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ])
Jason Evansf3340ca2009-06-30 16:17:05 -0700225 fi
Jason Evans80061b62013-12-09 13:21:08 -0800226 ;;
227 powerpc)
228 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700229 ;;
230 *)
231 ;;
232esac
233AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
234
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400235LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700236so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200237importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200238o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200239a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200240exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700241libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200242DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
243RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200244SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200245PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200246CTARGET='-o $@'
247LDTARGET='-o $@'
248EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100249ARFLAGS='crus'
250AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200251CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800252
Jory A. Prattad505e02013-08-11 09:44:59 -0500253AN_MAKEVAR([AR], [AC_PROG_AR])
254AN_PROGRAM([ar], [AC_PROG_AR])
255AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
256AC_PROG_AR
257
Jason Evansb7924f52009-06-23 19:01:18 -0700258dnl Platform-specific settings. abi and RPATH can probably be determined
259dnl programmatically, but doing so is error-prone, which makes it generally
260dnl not worth the trouble.
261dnl
262dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
263dnl definitions need to be seen before any headers are included, which is a pain
264dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700265default_munmap="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700266case "${host}" in
267 *-*-darwin*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200268 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700269 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700270 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700271 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400272 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700273 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200274 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700275 force_tls="0"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200276 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200277 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800278 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700279 ;;
280 *-*-freebsd*)
281 CFLAGS="$CFLAGS"
282 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700283 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700284 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700285 ;;
286 *-*-linux*)
287 CFLAGS="$CFLAGS"
288 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
289 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800290 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700291 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700292 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700293 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700294 ;;
295 *-*-netbsd*)
296 AC_MSG_CHECKING([ABI])
297 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
298[[#ifdef __ELF__
299/* ELF */
300#else
301#error aout
302#endif
303]])],
304 [CFLAGS="$CFLAGS"; abi="elf"],
305 [abi="aout"])
306 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700307 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700308 ;;
309 *-*-solaris2*)
310 CFLAGS="$CFLAGS"
311 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000312 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200313 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700314 dnl Solaris needs this for sigwait().
315 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
316 LIBS="$LIBS -lposix4 -lsocket -lnsl"
317 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400318 *-ibm-aix*)
319 if "$LG_SIZEOF_PTR" = "8"; then
320 dnl 64bit AIX
321 LD_PRELOAD_VAR="LDR_PRELOAD64"
322 else
323 dnl 32bit AIX
324 LD_PRELOAD_VAR="LDR_PRELOAD"
325 fi
326 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400327 ;;
Mike Hommeya19e87f2012-04-21 21:27:46 -0700328 *-*-mingw*)
329 abi="pecoff"
330 force_tls="0"
331 RPATH=""
332 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200333 if test "x$je_cv_msvc" = "xyes" ; then
334 importlib="lib"
335 DSO_LDFLAGS="-LD"
336 EXTRA_LDFLAGS="-link -DEBUG"
337 CTARGET='-Fo$@'
338 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500339 AR='lib'
340 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100341 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200342 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200343 else
344 importlib="${so}"
345 DSO_LDFLAGS="-shared"
346 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700347 a="lib"
348 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200349 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700350 PIC_CFLAGS=""
351 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700352 *)
353 AC_MSG_RESULT([Unsupported operating system: ${host}])
354 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700355 ;;
356esac
Mike Hommeyaffe0092014-05-28 08:10:12 +0900357
358JEMALLOC_USABLE_SIZE_CONST=const
359AC_CHECK_HEADERS([malloc.h], [
360 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
361 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
362 [#include <malloc.h>
363 #include <stddef.h>
364 size_t malloc_usable_size(const void *ptr);
365 ],
366 [])],[
367 AC_MSG_RESULT([yes])
368 ],[
369 JEMALLOC_USABLE_SIZE_CONST=
370 AC_MSG_RESULT([no])
371 ])
372])
Jason Evans247d1242012-10-09 16:20:10 -0700373AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700374AC_SUBST([abi])
375AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400376AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700377AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200378AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200379AC_SUBST([o])
380AC_SUBST([a])
381AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700382AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200383AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200384AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200385AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200386AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200387AC_SUBST([CTARGET])
388AC_SUBST([LDTARGET])
389AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100390AC_SUBST([ARFLAGS])
391AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200392AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200393
Jason Evansfa5d2452011-03-15 10:25:59 -0700394JE_COMPILABLE([__attribute__ syntax],
395 [static __attribute__((unused)) void foo(void){}],
396 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800397 [je_cv_attribute])
398if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700399 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
400 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
401 JE_CFLAGS_APPEND([-fvisibility=hidden])
402 fi
403fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700404dnl Check for tls_model attribute support (clang 3.0 still lacks support).
405SAVED_CFLAGS="${CFLAGS}"
406JE_CFLAGS_APPEND([-Werror])
407JE_COMPILABLE([tls_model attribute], [],
408 [static __thread int
409 __attribute__((tls_model("initial-exec"))) foo;
410 foo = 0;],
411 [je_cv_tls_model])
412CFLAGS="${SAVED_CFLAGS}"
413if test "x${je_cv_tls_model}" = "xyes" ; then
414 AC_DEFINE([JEMALLOC_TLS_MODEL],
415 [__attribute__((tls_model("initial-exec")))])
416else
417 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
418fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700419
Jason Evansb7924f52009-06-23 19:01:18 -0700420dnl Support optional additions to rpath.
421AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800422 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700423if test "x$with_rpath" = "xno" ; then
424 RPATH_EXTRA=
425else
426 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
427fi,
428 RPATH_EXTRA=
429)
430AC_SUBST([RPATH_EXTRA])
431
432dnl Disable rules that do automatic regeneration of configure output by default.
433AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800434 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700435if test "x$enable_autogen" = "xno" ; then
436 enable_autogen="0"
437else
438 enable_autogen="1"
439fi
440,
441enable_autogen="0"
442)
443AC_SUBST([enable_autogen])
444
445AC_PROG_INSTALL
446AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800447AC_PATH_PROG([LD], [ld], [false], [$PATH])
448AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700449
Jason Evansd82a5e62013-12-12 22:35:52 -0800450public_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 -0800451
452dnl Check for allocator-related functions that should be wrapped.
453AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700454 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800455 public_syms="${public_syms} memalign"])
456AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700457 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800458 public_syms="${public_syms} valloc"])
459
Jason Evans748dfac2013-12-06 18:27:33 -0800460dnl Do not compute test code coverage by default.
461GCOV_FLAGS=
462AC_ARG_ENABLE([code-coverage],
463 [AS_HELP_STRING([--enable-code-coverage],
464 [Enable code coverage])],
465[if test "x$enable_code_coverage" = "xno" ; then
466 enable_code_coverage="0"
467else
468 enable_code_coverage="1"
469fi
470],
471[enable_code_coverage="0"]
472)
473if test "x$enable_code_coverage" = "x1" ; then
474 deoptimize="no"
475 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
476 if test "x${deoptimize}" = "xyes" ; then
477 JE_CFLAGS_APPEND([-O0])
478 fi
479 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
480 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
481 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
482fi
483AC_SUBST([enable_code_coverage])
484
Jason Evans0a5489e2012-03-01 17:19:20 -0800485dnl Perform no name mangling by default.
486AC_ARG_WITH([mangling],
487 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
488 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800489
Jason Evans90895cf2009-12-29 00:09:15 -0800490dnl Do not prefix public APIs by default.
491AC_ARG_WITH([jemalloc_prefix],
492 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800493 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200494 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700495 JEMALLOC_PREFIX=""
496else
497 JEMALLOC_PREFIX="je_"
498fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800499)
500if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700501 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
502 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
503 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800504fi
505
Mike Hommey99066602012-11-19 10:55:26 +0100506AC_ARG_WITH([export],
507 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
508 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800509 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100510fi]
511)
512
Jason Evans86abd0d2013-11-30 15:25:42 -0800513dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700514AC_ARG_WITH([private_namespace],
515 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800516 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
517 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700518)
Jason Evans86abd0d2013-11-30 15:25:42 -0800519AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
520private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
521AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700522
Jason Evansb0fd5012010-01-17 01:49:20 -0800523dnl Do not add suffix to installed files by default.
524AC_ARG_WITH([install_suffix],
525 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
526 [INSTALL_SUFFIX="$with_install_suffix"],
527 [INSTALL_SUFFIX=]
528)
529install_suffix="$INSTALL_SUFFIX"
530AC_SUBST([install_suffix])
531
Jason Evans86abd0d2013-11-30 15:25:42 -0800532dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
533dnl jemalloc_protos_jet.h easy.
534je_="je_"
535AC_SUBST([je_])
536
Jason Evansaee7fd22010-11-24 22:00:02 -0800537cfgoutputs_in="${srcroot}Makefile.in"
538cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
539cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
540cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800541cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc_macros.h.in"
542cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc_protos.h.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700543cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800544cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/test.sh.in"
545cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800546
Jason Evansaee7fd22010-11-24 22:00:02 -0800547cfgoutputs_out="Makefile"
548cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
549cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800550cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
551cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
552cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans376b1522010-02-11 14:45:59 -0800553cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800554cfgoutputs_out="${cfgoutputs_out} test/test.sh"
555cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800556
Jason Evansaee7fd22010-11-24 22:00:02 -0800557cfgoutputs_tup="Makefile"
558cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
559cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800560cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
561cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
562cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800563cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800564cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
565cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800566
Jason Evans0656ec02010-04-07 23:37:35 -0700567cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800568cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal_defs.h.in"
569cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_namespace.sh"
570cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_unnamespace.sh"
Jason Evansf234dc52014-01-16 17:38:01 -0800571cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800572cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/public_namespace.sh"
573cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/public_unnamespace.sh"
Jason Evansb1726102012-02-28 16:50:47 -0800574cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansf234dc52014-01-16 17:38:01 -0800575cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc_rename.sh"
576cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc_mangle.sh"
Jason Evansdc1bed62013-12-05 21:43:46 -0800577cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc.sh"
Jason Evans80061b62013-12-09 13:21:08 -0800578cfghdrs_in="${cfghdrs_in} ${srcroot}test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800579
Jason Evans86abd0d2013-11-30 15:25:42 -0800580cfghdrs_out="include/jemalloc/jemalloc_defs.h"
581cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800582cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
583cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800584cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800585cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
586cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800587cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800588cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
589cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
590cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
591cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
592cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800593cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800594
Jason Evans86abd0d2013-11-30 15:25:42 -0800595cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
596cfghdrs_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 -0800597cfghdrs_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 -0800598
Jason Evans644d4142014-04-14 22:49:23 -0700599dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700600AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700601 [AS_HELP_STRING([--disable-cc-silence],
602 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700603[if test "x$enable_cc_silence" = "xno" ; then
604 enable_cc_silence="0"
605else
606 enable_cc_silence="1"
607fi
608],
Jason Evans644d4142014-04-14 22:49:23 -0700609[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700610)
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
Jason Evans05125b82014-04-22 20:48:07 -0700724 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700725 [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"])
Jason Evans77f350b2011-03-15 22:23:12 -0700750 if test "x${enable_prof_libgcc}" = "x1" ; then
751 backtrace_method="libgcc"
752 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
753 fi
754else
755 enable_prof_libgcc="0"
756fi
757
758AC_ARG_ENABLE([prof-gcc],
759 [AS_HELP_STRING([--disable-prof-gcc],
760 [Do not use gcc intrinsics for backtracing])],
761[if test "x$enable_prof_gcc" = "xno" ; then
762 enable_prof_gcc="0"
763else
764 enable_prof_gcc="1"
765fi
766],
767[enable_prof_gcc="1"]
768)
769if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
770 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700771 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700772 backtrace_method="gcc intrinsics"
773 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
774else
775 enable_prof_gcc="0"
776fi
777
778if test "x$backtrace_method" = "x" ; then
779 backtrace_method="none (disabling profiling)"
780 enable_prof="0"
781fi
782AC_MSG_CHECKING([configured backtracing method])
783AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700784if test "x$enable_prof" = "x1" ; then
Jason Evans6716aa82012-04-23 13:04:55 -0700785 if test "x${force_tls}" = "x0" ; then
786 AC_MSG_ERROR([Heap profiling requires TLS]);
787 fi
788 force_tls="1"
Jason Evansd37d5ad2013-12-05 23:01:50 -0800789
790 if test "x$abi" != "xpecoff"; then
791 dnl Heap profiling uses the log(3) function.
792 LIBS="$LIBS -lm"
793 fi
794
Jason Evans2dbecf12010-09-05 10:35:13 -0700795 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700796fi
797AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700798
Jason Evans84cbbcb2009-12-29 00:09:15 -0800799dnl Enable thread-specific caching by default.
800AC_ARG_ENABLE([tcache],
801 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
802[if test "x$enable_tcache" = "xno" ; then
803 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700804else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800805 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700806fi
807],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800808[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700809)
Jason Evans2dbecf12010-09-05 10:35:13 -0700810if test "x$enable_tcache" = "x1" ; then
811 AC_DEFINE([JEMALLOC_TCACHE], [ ])
812fi
813AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700814
Jason Evans59ae2762012-04-16 17:52:27 -0700815dnl Enable VM deallocation via munmap() by default.
816AC_ARG_ENABLE([munmap],
817 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
818[if test "x$enable_munmap" = "xno" ; then
819 enable_munmap="0"
820else
821 enable_munmap="1"
822fi
823],
824[enable_munmap="${default_munmap}"]
825)
826if test "x$enable_munmap" = "x1" ; then
827 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
828fi
829AC_SUBST([enable_munmap])
830
Jason Evans4d434ad2014-04-15 12:09:48 -0700831dnl Enable allocation from DSS if supported by the OS.
832have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200833dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
834AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
835if test "x$have_sbrk" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800836 if test "x$sbrk_deprecated" == "x1" ; then
837 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700838 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800839 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200840else
Jason Evans4d434ad2014-04-15 12:09:48 -0700841 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200842fi
843
Jason Evans4d434ad2014-04-15 12:09:48 -0700844if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700845 AC_DEFINE([JEMALLOC_DSS], [ ])
846fi
Jason Evansb7924f52009-06-23 19:01:18 -0700847
Jason Evans777c1912012-02-28 20:49:22 -0800848dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700849AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700850 [AS_HELP_STRING([--disable-fill],
851 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700852[if test "x$enable_fill" = "xno" ; then
853 enable_fill="0"
854else
855 enable_fill="1"
856fi
857],
Jason Evans777c1912012-02-28 20:49:22 -0800858[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700859)
860if test "x$enable_fill" = "x1" ; then
861 AC_DEFINE([JEMALLOC_FILL], [ ])
862fi
863AC_SUBST([enable_fill])
864
Jason Evansb1476112012-04-05 13:36:17 -0700865dnl Disable utrace(2)-based tracing by default.
866AC_ARG_ENABLE([utrace],
867 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
868[if test "x$enable_utrace" = "xno" ; then
869 enable_utrace="0"
870else
871 enable_utrace="1"
872fi
873],
874[enable_utrace="0"]
875)
876JE_COMPILABLE([utrace(2)], [
877#include <sys/types.h>
878#include <sys/param.h>
879#include <sys/time.h>
880#include <sys/uio.h>
881#include <sys/ktrace.h>
882], [
883 utrace((void *)0, 0);
884], [je_cv_utrace])
885if test "x${je_cv_utrace}" = "xno" ; then
886 enable_utrace="0"
887fi
888if test "x$enable_utrace" = "x1" ; then
889 AC_DEFINE([JEMALLOC_UTRACE], [ ])
890fi
891AC_SUBST([enable_utrace])
892
Jason Evans122449b2012-04-06 00:35:09 -0700893dnl Support Valgrind by default.
894AC_ARG_ENABLE([valgrind],
895 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
896[if test "x$enable_valgrind" = "xno" ; then
897 enable_valgrind="0"
898else
899 enable_valgrind="1"
900fi
901],
902[enable_valgrind="1"]
903)
904if test "x$enable_valgrind" = "x1" ; then
905 JE_COMPILABLE([valgrind], [
906#include <valgrind/valgrind.h>
907#include <valgrind/memcheck.h>
908
Mike Hommey7bfecf42012-04-30 15:15:15 +0200909#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -0700910# error "Incompatible Valgrind version"
911#endif
912], [], [je_cv_valgrind])
913 if test "x${je_cv_valgrind}" = "xno" ; then
914 enable_valgrind="0"
915 fi
916 if test "x$enable_valgrind" = "x1" ; then
917 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
918 fi
919fi
920AC_SUBST([enable_valgrind])
921
Jason Evansb7924f52009-06-23 19:01:18 -0700922dnl Do not support the xmalloc option by default.
923AC_ARG_ENABLE([xmalloc],
924 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
925[if test "x$enable_xmalloc" = "xno" ; then
926 enable_xmalloc="0"
927else
928 enable_xmalloc="1"
929fi
930],
931[enable_xmalloc="0"]
932)
933if test "x$enable_xmalloc" = "x1" ; then
934 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
935fi
936AC_SUBST([enable_xmalloc])
937
Jason Evans6684cac2012-03-05 12:15:36 -0800938AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
939 [je_cv_static_page_shift],
940 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -0700941[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200942#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700943#ifdef _WIN32
944#include <windows.h>
945#else
Jason Evansb7924f52009-06-23 19:01:18 -0700946#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700947#endif
948#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800949]],
950[[
Garrett Cooper72c1e592012-12-02 17:57:28 -0800951 int result;
Jason Evansb7924f52009-06-23 19:01:18 -0700952 FILE *f;
953
Mike Hommeya19e87f2012-04-21 21:27:46 -0700954#ifdef _WIN32
955 SYSTEM_INFO si;
956 GetSystemInfo(&si);
957 result = si.dwPageSize;
958#else
Jason Evansb7924f52009-06-23 19:01:18 -0700959 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -0700960#endif
Jason Evansb7924f52009-06-23 19:01:18 -0700961 if (result == -1) {
962 return 1;
963 }
Mike Hommeya19e87f2012-04-21 21:27:46 -0700964 result = ffsl(result) - 1;
965
Jason Evansb7924f52009-06-23 19:01:18 -0700966 f = fopen("conftest.out", "w");
967 if (f == NULL) {
968 return 1;
969 }
Garrett Cooper72c1e592012-12-02 17:57:28 -0800970 fprintf(f, "%d\n", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700971 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -0700972
973 return 0;
974]])],
Jason Evans6684cac2012-03-05 12:15:36 -0800975 [je_cv_static_page_shift=`cat conftest.out`],
Daniel Micayccf04662014-05-07 01:17:05 -0400976 [je_cv_static_page_shift=undefined],
977 [je_cv_static_page_shift=12]))
Jason Evans6684cac2012-03-05 12:15:36 -0800978
979if test "x$je_cv_static_page_shift" != "xundefined"; then
980 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
981else
982 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
983fi
Jason Evansb7924f52009-06-23 19:01:18 -0700984
985dnl ============================================================================
986dnl jemalloc configuration.
987dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800988
989dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700990if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700991 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800992fi
Jason Evansb7924f52009-06-23 19:01:18 -0700993jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800994jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
995jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
996jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
997jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
998jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700999AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001000AC_SUBST([jemalloc_version_major])
1001AC_SUBST([jemalloc_version_minor])
1002AC_SUBST([jemalloc_version_bugfix])
1003AC_SUBST([jemalloc_version_nrev])
1004AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001005
1006dnl ============================================================================
1007dnl Configure pthreads.
1008
Mike Hommeya19e87f2012-04-21 21:27:46 -07001009if test "x$abi" != "xpecoff" ; then
1010 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1011 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1012 dnl first, but try libc too before failing.
1013 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1014 [AC_SEARCH_LIBS([pthread_create], , ,
1015 AC_MSG_ERROR([libpthread is missing]))])
1016fi
Jason Evansb7924f52009-06-23 19:01:18 -07001017
1018CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1019
Jason Evanscd9a1342012-03-21 18:33:03 -07001020dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1021dnl it rather than pthreads TSD cleanup functions to support cleanup during
1022dnl thread exit, in order to avoid pthreads library recursion during
1023dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001024AC_CHECK_FUNC([_malloc_thread_cleanup],
1025 [have__malloc_thread_cleanup="1"],
1026 [have__malloc_thread_cleanup="0"]
1027 )
1028if test "x$have__malloc_thread_cleanup" = "x1" ; then
1029 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1030 force_tls="1"
1031fi
1032
Jason Evans41b6afb2012-02-02 22:04:57 -08001033dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1034dnl so, mutex initialization causes allocation, and we need to implement this
1035dnl callback function in order to prevent recursive allocation.
1036AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1037 [have__pthread_mutex_init_calloc_cb="1"],
1038 [have__pthread_mutex_init_calloc_cb="0"]
1039 )
1040if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1041 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1042fi
1043
Jason Evans0fee70d2012-02-13 12:36:11 -08001044dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001045AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001046 [AS_HELP_STRING([--enable-lazy-lock],
1047 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001048[if test "x$enable_lazy_lock" = "xno" ; then
1049 enable_lazy_lock="0"
1050else
1051 enable_lazy_lock="1"
1052fi
1053],
Jason Evans0fee70d2012-02-13 12:36:11 -08001054[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -07001055)
Jason Evansfd4fcef2012-03-23 17:40:58 -07001056if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1057 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1058 enable_lazy_lock="1"
1059fi
Jason Evansb7924f52009-06-23 19:01:18 -07001060if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001061 if test "x$abi" != "xpecoff" ; then
1062 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1063 AC_CHECK_FUNC([dlsym], [],
1064 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1065 [AC_MSG_ERROR([libdl is missing])])
1066 ])
1067 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001068 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1069fi
1070AC_SUBST([enable_lazy_lock])
1071
Jason Evans78d815c2010-01-17 14:06:20 -08001072AC_ARG_ENABLE([tls],
1073 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1074if test "x$enable_tls" = "xno" ; then
1075 enable_tls="0"
1076else
1077 enable_tls="1"
1078fi
1079,
1080enable_tls="1"
1081)
Jason Evanscd9a1342012-03-21 18:33:03 -07001082if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1083 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1084 enable_tls="1"
1085fi
Jason Evansb80581d2012-03-23 16:17:43 -07001086if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1087 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1088 enable_tls="0"
1089fi
Jason Evans78d815c2010-01-17 14:06:20 -08001090if test "x${enable_tls}" = "x1" ; then
1091AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001092AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001093[[
1094 __thread int x;
1095]], [[
1096 x = 42;
1097
1098 return 0;
1099]])],
1100 AC_MSG_RESULT([yes]),
1101 AC_MSG_RESULT([no])
1102 enable_tls="0")
1103fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001104AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001105if test "x${enable_tls}" = "x1" ; then
1106 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001107elif test "x${force_tls}" = "x1" ; then
1108 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -08001109fi
1110
Jason Evans2dbecf12010-09-05 10:35:13 -07001111dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -07001112dnl Check for ffsl(3), and fail if not found. This function exists on all
1113dnl platforms that jemalloc currently has a chance of functioning on without
1114dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -07001115JE_COMPILABLE([a program using ffsl], [
Garrett Cooper72c1e592012-12-02 17:57:28 -08001116#include <stdio.h>
Jason Evans382132e2012-04-04 15:25:43 -07001117#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -07001118#include <string.h>
1119], [
1120 {
1121 int rv = ffsl(0x08);
Garrett Cooper72c1e592012-12-02 17:57:28 -08001122 printf("%d\n", rv);
Jason Evans4c2faa82012-03-13 11:09:23 -07001123 }
1124], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -08001125if test "x${je_cv_function_ffsl}" != "xyes" ; then
1126 AC_MSG_ERROR([Cannot build without ffsl(3)])
1127fi
Jason Evans84c8eef2011-03-16 10:30:13 -07001128
1129dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001130dnl Check for atomic(9) operations as provided on FreeBSD.
1131
1132JE_COMPILABLE([atomic(9)], [
1133#include <sys/types.h>
1134#include <machine/atomic.h>
1135#include <inttypes.h>
1136], [
1137 {
1138 uint32_t x32 = 0;
1139 volatile uint32_t *x32p = &x32;
1140 atomic_fetchadd_32(x32p, 1);
1141 }
1142 {
1143 unsigned long xlong = 0;
1144 volatile unsigned long *xlongp = &xlong;
1145 atomic_fetchadd_long(xlongp, 1);
1146 }
1147], [je_cv_atomic9])
1148if test "x${je_cv_atomic9}" = "xyes" ; then
1149 AC_DEFINE([JEMALLOC_ATOMIC9])
1150fi
1151
1152dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001153dnl Check for atomic(3) operations as provided on Darwin.
1154
1155JE_COMPILABLE([Darwin OSAtomic*()], [
1156#include <libkern/OSAtomic.h>
1157#include <inttypes.h>
1158], [
1159 {
1160 int32_t x32 = 0;
1161 volatile int32_t *x32p = &x32;
1162 OSAtomicAdd32(1, x32p);
1163 }
1164 {
1165 int64_t x64 = 0;
1166 volatile int64_t *x64p = &x64;
1167 OSAtomicAdd64(1, x64p);
1168 }
Jason Evans6684cac2012-03-05 12:15:36 -08001169], [je_cv_osatomic])
1170if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001171 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001172fi
1173
1174dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001175dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1176dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1177
1178AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1179 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1180 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001181 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1182 #include <stdint.h>
1183 ],
1184 [
1185 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1186 {
1187 uint$1_t x$1 = 0;
1188 __sync_add_and_fetch(&x$1, 42);
1189 __sync_sub_and_fetch(&x$1, 1);
1190 }
1191 #else
1192 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1193 #endif
1194 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001195 [je_cv_sync_compare_and_swap_$2=yes],
1196 [je_cv_sync_compare_and_swap_$2=no])])
1197
1198 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1199 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1200 fi
1201])
1202
Jason Evansb57d3ec2012-04-17 13:17:54 -07001203if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001204 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1205 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1206fi
1207
1208dnl ============================================================================
Jason Evansd04047c2014-05-28 16:11:55 -07001209dnl Check for __builtin_clz() and __builtin_clzl().
1210
1211AC_CACHE_CHECK([for __builtin_clz],
1212 [je_cv_builtin_clz],
1213 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1214 [
1215 {
1216 unsigned x = 0;
1217 int y = __builtin_clz(x);
1218 }
1219 {
1220 unsigned long x = 0;
1221 int y = __builtin_clzl(x);
1222 }
1223 ])],
1224 [je_cv_builtin_clz=yes],
1225 [je_cv_builtin_clz=no])])
1226
1227if test "x${je_cv_builtin_clz}" = "xyes" ; then
1228 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1229fi
1230
1231dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001232dnl Check for spinlock(3) operations as provided on Darwin.
1233
1234JE_COMPILABLE([Darwin OSSpin*()], [
1235#include <libkern/OSAtomic.h>
1236#include <inttypes.h>
1237], [
1238 OSSpinLock lock = 0;
1239 OSSpinLockLock(&lock);
1240 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001241], [je_cv_osspin])
1242if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001243 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001244fi
1245
1246dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001247dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001248
Mike Hommeyd0357f72012-11-26 18:52:41 +01001249AC_ARG_ENABLE([zone-allocator],
1250 [AS_HELP_STRING([--disable-zone-allocator],
1251 [Disable zone allocator for Darwin])],
1252[if test "x$enable_zone_allocator" = "xno" ; then
1253 enable_zone_allocator="0"
1254else
1255 enable_zone_allocator="1"
1256fi
1257],
1258[if test "x${abi}" = "xmacho"; then
1259 enable_zone_allocator="1"
1260fi
1261]
1262)
1263AC_SUBST([enable_zone_allocator])
1264
1265if test "x${enable_zone_allocator}" = "x1" ; then
1266 if test "x${abi}" != "xmacho"; then
1267 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1268 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001269 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1270 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001271
Jason Evans2dbecf12010-09-05 10:35:13 -07001272 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1273 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1274 dnl 10.6, which is the only source-level indication of the change.
1275 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001276 AC_DEFUN([JE_ZONE_PROGRAM],
1277 [AC_LANG_PROGRAM(
1278 [#include <malloc/malloc.h>],
1279 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1280 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001281
Mike Hommey154829d2012-03-20 18:01:38 +01001282 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1283 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1284 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1285 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1286 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1287 )])],[
1288 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1289 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1290 )])])])])
1291 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1292 AC_MSG_RESULT([unsupported])
1293 AC_MSG_ERROR([Unsupported malloc zone version])
1294 fi
1295 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1296 JEMALLOC_ZONE_VERSION=8
1297 AC_MSG_RESULT([> 8])
1298 else
1299 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1300 fi
1301 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001302fi
1303
Jason Evansb7924f52009-06-23 19:01:18 -07001304dnl ============================================================================
1305dnl Check for typedefs, structures, and compiler characteristics.
1306AC_HEADER_STDBOOL
1307
Jason Evans748dfac2013-12-06 18:27:33 -08001308dnl ============================================================================
1309dnl Define commands that generate output files.
1310
Jason Evans86abd0d2013-11-30 15:25:42 -08001311AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1312 mkdir -p "${objroot}include/jemalloc/internal"
1313 "${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 -08001314], [
1315 srcdir="${srcdir}"
1316 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001317])
1318AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1319 mkdir -p "${objroot}include/jemalloc/internal"
1320 "${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 -08001321], [
1322 srcdir="${srcdir}"
1323 objroot="${objroot}"
1324])
1325AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1326 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1327 mkdir -p "${objroot}include/jemalloc/internal"
1328 cp /dev/null "${f}"
1329 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1330 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1331 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1332 echo "${n}:${m}" >> "${f}"
1333 dnl Remove name from public_syms so that it isn't redefined later.
1334 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1335 done
1336 for sym in ${public_syms} ; do
1337 n="${sym}"
1338 m="${JEMALLOC_PREFIX}${sym}"
1339 echo "${n}:${m}" >> "${f}"
1340 done
1341], [
1342 srcdir="${srcdir}"
1343 objroot="${objroot}"
1344 mangling_map="${mangling_map}"
1345 public_syms="${public_syms}"
1346 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001347])
1348AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1349 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001350 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1351], [
1352 srcdir="${srcdir}"
1353 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001354])
1355AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1356 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001357 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1358], [
1359 srcdir="${srcdir}"
1360 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001361])
Jason Evansb1726102012-02-28 16:50:47 -08001362AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001363 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansb1726102012-02-28 16:50:47 -08001364 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001365], [
1366 srcdir="${srcdir}"
1367 objroot="${objroot}"
Jason Evansb1726102012-02-28 16:50:47 -08001368])
Jason Evans86abd0d2013-11-30 15:25:42 -08001369AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1370 mkdir -p "${objroot}include/jemalloc"
1371 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 -08001372], [
1373 srcdir="${srcdir}"
1374 objroot="${objroot}"
1375])
1376AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1377 mkdir -p "${objroot}include/jemalloc"
1378 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1379], [
1380 srcdir="${srcdir}"
1381 objroot="${objroot}"
1382])
1383AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1384 mkdir -p "${objroot}include/jemalloc"
1385 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1386], [
1387 srcdir="${srcdir}"
1388 objroot="${objroot}"
1389])
1390AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1391 mkdir -p "${objroot}include/jemalloc"
1392 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1393], [
1394 srcdir="${srcdir}"
1395 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001396])
1397AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1398 mkdir -p "${objroot}include/jemalloc"
1399 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001400], [
1401 srcdir="${srcdir}"
1402 objroot="${objroot}"
1403 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001404])
Jason Evansb1726102012-02-28 16:50:47 -08001405
Jason Evansb7924f52009-06-23 19:01:18 -07001406dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001407AC_SUBST([cfghdrs_in])
1408AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001409AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001410
1411dnl ============================================================================
1412dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001413
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001414AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001415AC_SUBST([cfgoutputs_in])
1416AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001417AC_OUTPUT
1418
1419dnl ============================================================================
1420dnl Print out the results of configuration.
1421AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001422AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1423AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001424AC_MSG_RESULT([])
1425AC_MSG_RESULT([CC : ${CC}])
1426AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1427AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1428AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001429AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001430AC_MSG_RESULT([LIBS : ${LIBS}])
1431AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1432AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001433AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1434AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1435AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001436AC_MSG_RESULT([PREFIX : ${PREFIX}])
1437AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001438AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1439AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001440AC_MSG_RESULT([DATADIR : ${DATADIR}])
1441AC_MSG_RESULT([MANDIR : ${MANDIR}])
1442AC_MSG_RESULT([])
1443AC_MSG_RESULT([srcroot : ${srcroot}])
1444AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1445AC_MSG_RESULT([objroot : ${objroot}])
1446AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1447AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001448AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001449AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1450AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001451AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001452AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001453AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001454AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001455AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001456AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001457AC_MSG_RESULT([prof : ${enable_prof}])
1458AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001459AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1460AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001461AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001462AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001463AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001464AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1465AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001466AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001467AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001468AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001469AC_MSG_RESULT([===============================================================================])