blob: a80c05d1620286e53e780489a61fbd622b616bc5 [file] [log] [blame]
Jason Evansb7924f52009-06-23 19:01:18 -07001dnl Process this file with autoconf to produce a configure script.
2AC_INIT([Makefile.in])
3
Jason Evansf3340ca2009-06-30 16:17:05 -07004dnl ============================================================================
5dnl Custom macro definitions.
6
7dnl JE_CFLAGS_APPEND(cflag)
8AC_DEFUN([JE_CFLAGS_APPEND],
9[
10AC_MSG_CHECKING([whether compiler supports $1])
11TCFLAGS="${CFLAGS}"
12if test "x${CFLAGS}" = "x" ; then
13 CFLAGS="$1"
14else
15 CFLAGS="${CFLAGS} $1"
16fi
Jason Evans6684cac2012-03-05 12:15:36 -080017AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evansf3340ca2009-06-30 16:17:05 -070018[[
19]], [[
20 return 0;
21]])],
22 AC_MSG_RESULT([yes]),
23 AC_MSG_RESULT([no])
24 [CFLAGS="${TCFLAGS}"]
25)
26])
27
28dnl JE_COMPILABLE(label, hcode, mcode, rvar)
Jason Evans4c2faa82012-03-13 11:09:23 -070029dnl
Jason Evansf3e139a2012-03-19 09:54:20 -070030dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
Jason Evans4c2faa82012-03-13 11:09:23 -070031dnl cause failure.
Jason Evansf3340ca2009-06-30 16:17:05 -070032AC_DEFUN([JE_COMPILABLE],
33[
Jason Evans6684cac2012-03-05 12:15:36 -080034AC_CACHE_CHECK([whether $1 is compilable],
35 [$4],
Jason Evansf3e139a2012-03-19 09:54:20 -070036 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
37 [$3])],
38 [$4=yes],
39 [$4=no])])
Jason Evansf3340ca2009-06-30 16:17:05 -070040])
41
42dnl ============================================================================
43
Jason Evansf576c632011-11-01 22:27:41 -070044dnl Library revision.
45rev=1
46AC_SUBST([rev])
47
Jason Evansb7924f52009-06-23 19:01:18 -070048srcroot=$srcdir
49if test "x${srcroot}" = "x." ; then
50 srcroot=""
51else
52 srcroot="${srcroot}/"
53fi
54AC_SUBST([srcroot])
55abs_srcroot="`cd \"${srcdir}\"; pwd`/"
56AC_SUBST([abs_srcroot])
57
58objroot=""
59AC_SUBST([objroot])
60abs_objroot="`pwd`/"
61AC_SUBST([abs_objroot])
62
63dnl Munge install path variables.
64if test "x$prefix" = "xNONE" ; then
65 prefix="/usr/local"
66fi
67if test "x$exec_prefix" = "xNONE" ; then
68 exec_prefix=$prefix
69fi
70PREFIX=$prefix
71AC_SUBST([PREFIX])
72BINDIR=`eval echo $bindir`
73BINDIR=`eval echo $BINDIR`
74AC_SUBST([BINDIR])
75INCLUDEDIR=`eval echo $includedir`
76INCLUDEDIR=`eval echo $INCLUDEDIR`
77AC_SUBST([INCLUDEDIR])
78LIBDIR=`eval echo $libdir`
79LIBDIR=`eval echo $LIBDIR`
80AC_SUBST([LIBDIR])
81DATADIR=`eval echo $datadir`
82DATADIR=`eval echo $DATADIR`
83AC_SUBST([DATADIR])
84MANDIR=`eval echo $mandir`
85MANDIR=`eval echo $MANDIR`
86AC_SUBST([MANDIR])
87
Jason Evansaee7fd22010-11-24 22:00:02 -080088dnl Support for building documentation.
Jason Evans7329a4f2013-01-22 10:53:29 -080089AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
Jason Evans7091b412012-03-19 09:36:44 -070090if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
91 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
92elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
93 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
94else
95 dnl Documentation building will fail if this default gets used.
96 DEFAULT_XSLROOT=""
97fi
Jason Evansaee7fd22010-11-24 22:00:02 -080098AC_ARG_WITH([xslroot],
Jason Evans7091b412012-03-19 09:36:44 -070099 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
Jason Evansaee7fd22010-11-24 22:00:02 -0800100if test "x$with_xslroot" = "xno" ; then
Jason Evans7091b412012-03-19 09:36:44 -0700101 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800102else
103 XSLROOT="${with_xslroot}"
Jason Evans7091b412012-03-19 09:36:44 -0700104fi
105],
106 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800107)
108AC_SUBST([XSLROOT])
109
Jason Evansf3340ca2009-06-30 16:17:05 -0700110dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
111dnl just prevent autoconf from molesting CFLAGS.
Jason Evansb7924f52009-06-23 19:01:18 -0700112CFLAGS=$CFLAGS
113AC_PROG_CC
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200114if test "x$GCC" != "xyes" ; then
115 AC_CACHE_CHECK([whether compiler is MSVC],
116 [je_cv_msvc],
117 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
118 [
119#ifndef _MSC_VER
120 int fail[-1];
121#endif
122])],
123 [je_cv_msvc=yes],
124 [je_cv_msvc=no])])
125fi
126
Jason Evansb7924f52009-06-23 19:01:18 -0700127if test "x$CFLAGS" = "x" ; then
128 no_CFLAGS="yes"
Jason Evanscfeccd32010-03-03 15:48:20 -0800129 if test "x$GCC" = "xyes" ; then
130 JE_CFLAGS_APPEND([-std=gnu99])
131 JE_CFLAGS_APPEND([-Wall])
132 JE_CFLAGS_APPEND([-pipe])
133 JE_CFLAGS_APPEND([-g3])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200134 elif test "x$je_cv_msvc" = "xyes" ; then
135 CC="$CC -nologo"
136 JE_CFLAGS_APPEND([-Zi])
137 JE_CFLAGS_APPEND([-MT])
138 JE_CFLAGS_APPEND([-W3])
139 CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat"
Jason Evanscfeccd32010-03-03 15:48:20 -0800140 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700141fi
142dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
143if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700144 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700145fi
146AC_PROG_CPP
147
Jason Evansb7924f52009-06-23 19:01:18 -0700148AC_CHECK_SIZEOF([void *])
149if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800150 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700151elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800152 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700153else
154 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
155fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800156AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
157
158AC_CHECK_SIZEOF([int])
159if test "x${ac_cv_sizeof_int}" = "x8" ; then
160 LG_SIZEOF_INT=3
161elif test "x${ac_cv_sizeof_int}" = "x4" ; then
162 LG_SIZEOF_INT=2
163else
164 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
165fi
166AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700167
Jason Evans84c8eef2011-03-16 10:30:13 -0700168AC_CHECK_SIZEOF([long])
169if test "x${ac_cv_sizeof_long}" = "x8" ; then
170 LG_SIZEOF_LONG=3
171elif test "x${ac_cv_sizeof_long}" = "x4" ; then
172 LG_SIZEOF_LONG=2
173else
174 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
175fi
176AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
177
Jason Evansd81e4bd2012-03-06 14:57:45 -0800178AC_CHECK_SIZEOF([intmax_t])
179if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
180 LG_SIZEOF_INTMAX_T=4
181elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
182 LG_SIZEOF_INTMAX_T=3
183elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
184 LG_SIZEOF_INTMAX_T=2
185else
Mike Hommey14103d32012-04-20 08:38:39 +0200186 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800187fi
188AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
189
Jason Evansb7924f52009-06-23 19:01:18 -0700190AC_CANONICAL_HOST
191dnl CPU-specific settings.
192CPU_SPINWAIT=""
193case "${host_cpu}" in
194 i[[345]]86)
195 ;;
196 i686)
Jason Evansf3340ca2009-06-30 16:17:05 -0700197 JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
Jason Evans6684cac2012-03-05 12:15:36 -0800198 [je_cv_asm])
199 if test "x${je_cv_asm}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700200 CPU_SPINWAIT='__asm__ volatile("pause")'
201 fi
Jason Evans80061b62013-12-09 13:21:08 -0800202 AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700203 ;;
204 x86_64)
Jason Evansf3340ca2009-06-30 16:17:05 -0700205 JE_COMPILABLE([__asm__ syntax], [],
Jason Evans6684cac2012-03-05 12:15:36 -0800206 [[__asm__ volatile("pause"); return 0;]], [je_cv_asm])
207 if test "x${je_cv_asm}" = "xyes" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700208 CPU_SPINWAIT='__asm__ volatile("pause")'
209 fi
Jason Evans80061b62013-12-09 13:21:08 -0800210 AC_DEFINE_UNQUOTED([HAVE_SSE2], [ ])
211 ;;
212 powerpc)
213 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700214 ;;
215 *)
216 ;;
217esac
218AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
219
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400220LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700221so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200222importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200223o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200224a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200225exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700226libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200227DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
228RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200229SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200230PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200231CTARGET='-o $@'
232LDTARGET='-o $@'
233EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100234ARFLAGS='crus'
235AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200236CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800237
Jory A. Prattad505e02013-08-11 09:44:59 -0500238AN_MAKEVAR([AR], [AC_PROG_AR])
239AN_PROGRAM([ar], [AC_PROG_AR])
240AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
241AC_PROG_AR
242
Jason Evansb7924f52009-06-23 19:01:18 -0700243dnl Platform-specific settings. abi and RPATH can probably be determined
244dnl programmatically, but doing so is error-prone, which makes it generally
245dnl not worth the trouble.
246dnl
247dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
248dnl definitions need to be seen before any headers are included, which is a pain
249dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700250default_munmap="1"
Jason Evans247d1242012-10-09 16:20:10 -0700251JEMALLOC_USABLE_SIZE_CONST="const"
Jason Evansb7924f52009-06-23 19:01:18 -0700252case "${host}" in
253 *-*-darwin*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200254 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700255 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700256 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700257 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400258 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700259 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200260 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700261 force_tls="0"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200262 DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200263 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800264 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700265 ;;
266 *-*-freebsd*)
267 CFLAGS="$CFLAGS"
268 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700269 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700270 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700271 ;;
272 *-*-linux*)
273 CFLAGS="$CFLAGS"
274 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
275 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800276 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700277 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700278 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evans247d1242012-10-09 16:20:10 -0700279 JEMALLOC_USABLE_SIZE_CONST=""
Jason Evans59ae2762012-04-16 17:52:27 -0700280 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700281 ;;
282 *-*-netbsd*)
283 AC_MSG_CHECKING([ABI])
284 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
285[[#ifdef __ELF__
286/* ELF */
287#else
288#error aout
289#endif
290]])],
291 [CFLAGS="$CFLAGS"; abi="elf"],
292 [abi="aout"])
293 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700294 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700295 ;;
296 *-*-solaris2*)
297 CFLAGS="$CFLAGS"
298 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000299 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200300 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700301 dnl Solaris needs this for sigwait().
302 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
303 LIBS="$LIBS -lposix4 -lsocket -lnsl"
304 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400305 *-ibm-aix*)
306 if "$LG_SIZEOF_PTR" = "8"; then
307 dnl 64bit AIX
308 LD_PRELOAD_VAR="LDR_PRELOAD64"
309 else
310 dnl 32bit AIX
311 LD_PRELOAD_VAR="LDR_PRELOAD"
312 fi
313 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400314 ;;
Mike Hommeya19e87f2012-04-21 21:27:46 -0700315 *-*-mingw*)
316 abi="pecoff"
317 force_tls="0"
318 RPATH=""
319 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200320 if test "x$je_cv_msvc" = "xyes" ; then
321 importlib="lib"
322 DSO_LDFLAGS="-LD"
323 EXTRA_LDFLAGS="-link -DEBUG"
324 CTARGET='-Fo$@'
325 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500326 AR='lib'
327 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100328 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200329 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200330 else
331 importlib="${so}"
332 DSO_LDFLAGS="-shared"
333 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700334 a="lib"
335 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200336 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700337 PIC_CFLAGS=""
338 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700339 *)
340 AC_MSG_RESULT([Unsupported operating system: ${host}])
341 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700342 ;;
343esac
Jason Evans247d1242012-10-09 16:20:10 -0700344AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700345AC_SUBST([abi])
346AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400347AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700348AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200349AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200350AC_SUBST([o])
351AC_SUBST([a])
352AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700353AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200354AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200355AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200356AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200357AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200358AC_SUBST([CTARGET])
359AC_SUBST([LDTARGET])
360AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100361AC_SUBST([ARFLAGS])
362AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200363AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200364
Jason Evansfa5d2452011-03-15 10:25:59 -0700365JE_COMPILABLE([__attribute__ syntax],
366 [static __attribute__((unused)) void foo(void){}],
367 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800368 [je_cv_attribute])
369if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700370 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
371 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
372 JE_CFLAGS_APPEND([-fvisibility=hidden])
373 fi
374fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700375dnl Check for tls_model attribute support (clang 3.0 still lacks support).
376SAVED_CFLAGS="${CFLAGS}"
377JE_CFLAGS_APPEND([-Werror])
378JE_COMPILABLE([tls_model attribute], [],
379 [static __thread int
380 __attribute__((tls_model("initial-exec"))) foo;
381 foo = 0;],
382 [je_cv_tls_model])
383CFLAGS="${SAVED_CFLAGS}"
384if test "x${je_cv_tls_model}" = "xyes" ; then
385 AC_DEFINE([JEMALLOC_TLS_MODEL],
386 [__attribute__((tls_model("initial-exec")))])
387else
388 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
389fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700390
Jason Evansb7924f52009-06-23 19:01:18 -0700391dnl Support optional additions to rpath.
392AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800393 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700394if test "x$with_rpath" = "xno" ; then
395 RPATH_EXTRA=
396else
397 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
398fi,
399 RPATH_EXTRA=
400)
401AC_SUBST([RPATH_EXTRA])
402
403dnl Disable rules that do automatic regeneration of configure output by default.
404AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800405 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700406if test "x$enable_autogen" = "xno" ; then
407 enable_autogen="0"
408else
409 enable_autogen="1"
410fi
411,
412enable_autogen="0"
413)
414AC_SUBST([enable_autogen])
415
416AC_PROG_INSTALL
417AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800418AC_PATH_PROG([LD], [ld], [false], [$PATH])
419AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700420
Jason Evansd82a5e62013-12-12 22:35:52 -0800421public_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 -0800422
423dnl Check for allocator-related functions that should be wrapped.
424AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700425 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800426 public_syms="${public_syms} memalign"])
427AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700428 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800429 public_syms="${public_syms} valloc"])
430
431dnl Support the experimental API by default.
432AC_ARG_ENABLE([experimental],
433 [AS_HELP_STRING([--disable-experimental],
434 [Disable support for the experimental API])],
435[if test "x$enable_experimental" = "xno" ; then
436 enable_experimental="0"
437else
438 enable_experimental="1"
439fi
440],
441[enable_experimental="1"]
442)
443if test "x$enable_experimental" = "x1" ; then
444 AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
445 public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
446fi
447AC_SUBST([enable_experimental])
448
Jason Evans748dfac2013-12-06 18:27:33 -0800449dnl Do not compute test code coverage by default.
450GCOV_FLAGS=
451AC_ARG_ENABLE([code-coverage],
452 [AS_HELP_STRING([--enable-code-coverage],
453 [Enable code coverage])],
454[if test "x$enable_code_coverage" = "xno" ; then
455 enable_code_coverage="0"
456else
457 enable_code_coverage="1"
458fi
459],
460[enable_code_coverage="0"]
461)
462if test "x$enable_code_coverage" = "x1" ; then
463 deoptimize="no"
464 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
465 if test "x${deoptimize}" = "xyes" ; then
466 JE_CFLAGS_APPEND([-O0])
467 fi
468 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
469 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
470 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
471fi
472AC_SUBST([enable_code_coverage])
473
Jason Evans0a5489e2012-03-01 17:19:20 -0800474dnl Perform no name mangling by default.
475AC_ARG_WITH([mangling],
476 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
477 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800478
Jason Evans90895cf2009-12-29 00:09:15 -0800479dnl Do not prefix public APIs by default.
480AC_ARG_WITH([jemalloc_prefix],
481 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800482 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200483 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700484 JEMALLOC_PREFIX=""
485else
486 JEMALLOC_PREFIX="je_"
487fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800488)
489if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700490 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
491 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
492 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800493fi
494
Mike Hommey99066602012-11-19 10:55:26 +0100495AC_ARG_WITH([export],
496 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
497 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800498 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100499fi]
500)
501
Jason Evans86abd0d2013-11-30 15:25:42 -0800502dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700503AC_ARG_WITH([private_namespace],
504 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800505 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
506 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700507)
Jason Evans86abd0d2013-11-30 15:25:42 -0800508AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
509private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
510AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700511
Jason Evansb0fd5012010-01-17 01:49:20 -0800512dnl Do not add suffix to installed files by default.
513AC_ARG_WITH([install_suffix],
514 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
515 [INSTALL_SUFFIX="$with_install_suffix"],
516 [INSTALL_SUFFIX=]
517)
518install_suffix="$INSTALL_SUFFIX"
519AC_SUBST([install_suffix])
520
Jason Evans86abd0d2013-11-30 15:25:42 -0800521dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
522dnl jemalloc_protos_jet.h easy.
523je_="je_"
524AC_SUBST([je_])
525
Jason Evansaee7fd22010-11-24 22:00:02 -0800526cfgoutputs_in="${srcroot}Makefile.in"
527cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
528cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
529cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800530cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc_macros.h.in"
531cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc_protos.h.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700532cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800533cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/test.sh.in"
534cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800535
Jason Evansaee7fd22010-11-24 22:00:02 -0800536cfgoutputs_out="Makefile"
537cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
538cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800539cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
540cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
541cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans376b1522010-02-11 14:45:59 -0800542cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800543cfgoutputs_out="${cfgoutputs_out} test/test.sh"
544cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800545
Jason Evansaee7fd22010-11-24 22:00:02 -0800546cfgoutputs_tup="Makefile"
547cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
548cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800549cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
550cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
551cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800552cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800553cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
554cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800555
Jason Evans0656ec02010-04-07 23:37:35 -0700556cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800557cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal_defs.h.in"
558cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_namespace.sh"
559cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_unnamespace.sh"
Jason Evansf234dc52014-01-16 17:38:01 -0800560cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/private_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800561cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/public_namespace.sh"
562cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/public_unnamespace.sh"
Jason Evansb1726102012-02-28 16:50:47 -0800563cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
Jason Evansf234dc52014-01-16 17:38:01 -0800564cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc_rename.sh"
565cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc_mangle.sh"
Jason Evansdc1bed62013-12-05 21:43:46 -0800566cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/jemalloc.sh"
Jason Evans80061b62013-12-09 13:21:08 -0800567cfghdrs_in="${cfghdrs_in} ${srcroot}test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800568
Jason Evans86abd0d2013-11-30 15:25:42 -0800569cfghdrs_out="include/jemalloc/jemalloc_defs.h"
570cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800571cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
572cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800573cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800574cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
575cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800576cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800577cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
578cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
579cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
580cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
581cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800582cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800583
Jason Evans86abd0d2013-11-30 15:25:42 -0800584cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
585cfghdrs_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 -0800586cfghdrs_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 -0800587
Jason Evans355b4382010-09-20 19:20:48 -0700588dnl Do not silence irrelevant compiler warnings by default, since enabling this
589dnl option incurs a performance penalty.
590AC_ARG_ENABLE([cc-silence],
591 [AS_HELP_STRING([--enable-cc-silence],
592 [Silence irrelevant compiler warnings])],
593[if test "x$enable_cc_silence" = "xno" ; then
594 enable_cc_silence="0"
595else
596 enable_cc_silence="1"
597fi
598],
599[enable_cc_silence="0"]
600)
601if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700602 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700603fi
604
Jason Evansb7924f52009-06-23 19:01:18 -0700605dnl Do not compile with debugging by default.
606AC_ARG_ENABLE([debug],
Mike Hommey5135e342012-12-06 22:16:26 +0100607 [AS_HELP_STRING([--enable-debug], [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700608[if test "x$enable_debug" = "xno" ; then
609 enable_debug="0"
610else
611 enable_debug="1"
612fi
613],
614[enable_debug="0"]
615)
616if test "x$enable_debug" = "x1" ; then
617 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Mike Hommey5135e342012-12-06 22:16:26 +0100618 enable_ivsalloc="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700619fi
620AC_SUBST([enable_debug])
621
Mike Hommey5135e342012-12-06 22:16:26 +0100622dnl Do not validate pointers by default.
623AC_ARG_ENABLE([ivsalloc],
624 [AS_HELP_STRING([--enable-ivsalloc], [Validate pointers passed through the public API])],
625[if test "x$enable_ivsalloc" = "xno" ; then
626 enable_ivsalloc="0"
627else
628 enable_ivsalloc="1"
629fi
630],
631[enable_ivsalloc="0"]
632)
633if test "x$enable_ivsalloc" = "x1" ; then
634 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
635fi
636
Jason Evansb7924f52009-06-23 19:01:18 -0700637dnl Only optimize if not debugging.
638if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
639 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700640 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800641 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700642 if test "x${optimize}" = "xyes" ; then
643 if test "x$GCC" = "xyes" ; then
644 JE_CFLAGS_APPEND([-O3])
645 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200646 elif test "x$je_cv_msvc" = "xyes" ; then
647 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700648 else
649 JE_CFLAGS_APPEND([-O])
650 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700651 fi
652fi
653
Jason Evansd073a322012-02-28 20:41:16 -0800654dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700655AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800656 [AS_HELP_STRING([--disable-stats],
657 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700658[if test "x$enable_stats" = "xno" ; then
659 enable_stats="0"
660else
661 enable_stats="1"
662fi
663],
Jason Evansd073a322012-02-28 20:41:16 -0800664[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700665)
666if test "x$enable_stats" = "x1" ; then
667 AC_DEFINE([JEMALLOC_STATS], [ ])
668fi
669AC_SUBST([enable_stats])
670
Jason Evans6109fe02010-02-10 10:37:56 -0800671dnl Do not enable profiling by default.
672AC_ARG_ENABLE([prof],
673 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
674[if test "x$enable_prof" = "xno" ; then
675 enable_prof="0"
676else
677 enable_prof="1"
678fi
679],
680[enable_prof="0"]
681)
Jason Evans77f350b2011-03-15 22:23:12 -0700682if test "x$enable_prof" = "x1" ; then
683 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800684else
Jason Evans77f350b2011-03-15 22:23:12 -0700685 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800686fi
Jason Evans77f350b2011-03-15 22:23:12 -0700687
Jason Evans6109fe02010-02-10 10:37:56 -0800688AC_ARG_ENABLE([prof-libunwind],
689 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
690[if test "x$enable_prof_libunwind" = "xno" ; then
691 enable_prof_libunwind="0"
692else
693 enable_prof_libunwind="1"
694fi
695],
696[enable_prof_libunwind="0"]
697)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800698AC_ARG_WITH([static_libunwind],
699 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
700 [Path to static libunwind library; use rather than dynamically linking])],
701if test "x$with_static_libunwind" = "xno" ; then
702 LUNWIND="-lunwind"
703else
704 if test ! -f "$with_static_libunwind" ; then
705 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
706 fi
707 LUNWIND="$with_static_libunwind"
708fi,
709 LUNWIND="-lunwind"
710)
Jason Evans77f350b2011-03-15 22:23:12 -0700711if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
712 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
713 if test "x$LUNWIND" = "x-lunwind" ; then
714 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
715 [enable_prof_libunwind="0"])
716 else
717 LIBS="$LIBS $LUNWIND"
718 fi
719 if test "x${enable_prof_libunwind}" = "x1" ; then
720 backtrace_method="libunwind"
721 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
722 fi
723fi
724
725AC_ARG_ENABLE([prof-libgcc],
726 [AS_HELP_STRING([--disable-prof-libgcc],
727 [Do not use libgcc for backtracing])],
728[if test "x$enable_prof_libgcc" = "xno" ; then
729 enable_prof_libgcc="0"
730else
731 enable_prof_libgcc="1"
732fi
733],
734[enable_prof_libgcc="1"]
735)
736if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
737 -a "x$GCC" = "xyes" ; then
738 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
739 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
740 dnl The following is conservative, in that it only has entries for CPUs on
741 dnl which jemalloc has been tested.
742 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
743 case "${host_cpu}" in
744 i[[3456]]86)
745 AC_MSG_RESULT([unreliable])
746 enable_prof_libgcc="0";
747 ;;
748 x86_64)
749 AC_MSG_RESULT([reliable])
750 ;;
751 *)
752 AC_MSG_RESULT([unreliable])
753 enable_prof_libgcc="0";
754 ;;
755 esac
756 if test "x${enable_prof_libgcc}" = "x1" ; then
757 backtrace_method="libgcc"
758 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
759 fi
760else
761 enable_prof_libgcc="0"
762fi
763
764AC_ARG_ENABLE([prof-gcc],
765 [AS_HELP_STRING([--disable-prof-gcc],
766 [Do not use gcc intrinsics for backtracing])],
767[if test "x$enable_prof_gcc" = "xno" ; then
768 enable_prof_gcc="0"
769else
770 enable_prof_gcc="1"
771fi
772],
773[enable_prof_gcc="1"]
774)
775if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
776 -a "x$GCC" = "xyes" ; then
777 backtrace_method="gcc intrinsics"
778 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
779else
780 enable_prof_gcc="0"
781fi
782
783if test "x$backtrace_method" = "x" ; then
784 backtrace_method="none (disabling profiling)"
785 enable_prof="0"
786fi
787AC_MSG_CHECKING([configured backtracing method])
788AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700789if test "x$enable_prof" = "x1" ; then
Jason Evans6716aa82012-04-23 13:04:55 -0700790 if test "x${force_tls}" = "x0" ; then
791 AC_MSG_ERROR([Heap profiling requires TLS]);
792 fi
793 force_tls="1"
Jason Evansd37d5ad2013-12-05 23:01:50 -0800794
795 if test "x$abi" != "xpecoff"; then
796 dnl Heap profiling uses the log(3) function.
797 LIBS="$LIBS -lm"
798 fi
799
Jason Evans2dbecf12010-09-05 10:35:13 -0700800 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700801fi
802AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700803
Jason Evans84cbbcb2009-12-29 00:09:15 -0800804dnl Enable thread-specific caching by default.
805AC_ARG_ENABLE([tcache],
806 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
807[if test "x$enable_tcache" = "xno" ; then
808 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700809else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800810 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700811fi
812],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800813[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700814)
Jason Evans2dbecf12010-09-05 10:35:13 -0700815if test "x$enable_tcache" = "x1" ; then
816 AC_DEFINE([JEMALLOC_TCACHE], [ ])
817fi
818AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700819
Jason Evans2e671ff2012-05-09 16:12:00 -0700820dnl Disable mremap() for huge realloc() by default.
821AC_ARG_ENABLE([mremap],
822 [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
823[if test "x$enable_mremap" = "xno" ; then
824 enable_mremap="0"
825else
826 enable_mremap="1"
827fi
828],
829[enable_mremap="0"]
830)
831if test "x$enable_mremap" = "x1" ; then
832 JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
Jason Evansa4f124f2013-12-08 22:28:27 -0800833#define _GNU_SOURCE
Jason Evans2e671ff2012-05-09 16:12:00 -0700834#include <sys/mman.h>
835], [
836void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
837], [je_cv_mremap_fixed])
838 if test "x${je_cv_mremap_fixed}" = "xno" ; then
839 enable_mremap="0"
840 fi
841fi
842if test "x$enable_mremap" = "x1" ; then
843 AC_DEFINE([JEMALLOC_MREMAP], [ ])
844fi
845AC_SUBST([enable_mremap])
846
Jason Evans59ae2762012-04-16 17:52:27 -0700847dnl Enable VM deallocation via munmap() by default.
848AC_ARG_ENABLE([munmap],
849 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
850[if test "x$enable_munmap" = "xno" ; then
851 enable_munmap="0"
852else
853 enable_munmap="1"
854fi
855],
856[enable_munmap="${default_munmap}"]
857)
858if test "x$enable_munmap" = "x1" ; then
859 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
860fi
861AC_SUBST([enable_munmap])
862
Jason Evansb7924f52009-06-23 19:01:18 -0700863dnl Do not enable allocation from DSS by default.
864AC_ARG_ENABLE([dss],
865 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
866[if test "x$enable_dss" = "xno" ; then
867 enable_dss="0"
868else
869 enable_dss="1"
870fi
871],
872[enable_dss="0"]
873)
Mike Hommey83c324a2012-04-12 10:13:03 +0200874dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
875AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
876if test "x$have_sbrk" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800877 if test "x$sbrk_deprecated" == "x1" ; then
878 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
879 enable_dss="0"
880 else
881 AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
882 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200883else
884 enable_dss="0"
885fi
886
Jason Evansb7924f52009-06-23 19:01:18 -0700887if test "x$enable_dss" = "x1" ; then
888 AC_DEFINE([JEMALLOC_DSS], [ ])
889fi
890AC_SUBST([enable_dss])
891
Jason Evans777c1912012-02-28 20:49:22 -0800892dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700893AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700894 [AS_HELP_STRING([--disable-fill],
895 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700896[if test "x$enable_fill" = "xno" ; then
897 enable_fill="0"
898else
899 enable_fill="1"
900fi
901],
Jason Evans777c1912012-02-28 20:49:22 -0800902[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700903)
904if test "x$enable_fill" = "x1" ; then
905 AC_DEFINE([JEMALLOC_FILL], [ ])
906fi
907AC_SUBST([enable_fill])
908
Jason Evansb1476112012-04-05 13:36:17 -0700909dnl Disable utrace(2)-based tracing by default.
910AC_ARG_ENABLE([utrace],
911 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
912[if test "x$enable_utrace" = "xno" ; then
913 enable_utrace="0"
914else
915 enable_utrace="1"
916fi
917],
918[enable_utrace="0"]
919)
920JE_COMPILABLE([utrace(2)], [
921#include <sys/types.h>
922#include <sys/param.h>
923#include <sys/time.h>
924#include <sys/uio.h>
925#include <sys/ktrace.h>
926], [
927 utrace((void *)0, 0);
928], [je_cv_utrace])
929if test "x${je_cv_utrace}" = "xno" ; then
930 enable_utrace="0"
931fi
932if test "x$enable_utrace" = "x1" ; then
933 AC_DEFINE([JEMALLOC_UTRACE], [ ])
934fi
935AC_SUBST([enable_utrace])
936
Jason Evans122449b2012-04-06 00:35:09 -0700937dnl Support Valgrind by default.
938AC_ARG_ENABLE([valgrind],
939 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
940[if test "x$enable_valgrind" = "xno" ; then
941 enable_valgrind="0"
942else
943 enable_valgrind="1"
944fi
945],
946[enable_valgrind="1"]
947)
948if test "x$enable_valgrind" = "x1" ; then
949 JE_COMPILABLE([valgrind], [
950#include <valgrind/valgrind.h>
951#include <valgrind/memcheck.h>
952
Mike Hommey7bfecf42012-04-30 15:15:15 +0200953#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -0700954# error "Incompatible Valgrind version"
955#endif
956], [], [je_cv_valgrind])
957 if test "x${je_cv_valgrind}" = "xno" ; then
958 enable_valgrind="0"
959 fi
960 if test "x$enable_valgrind" = "x1" ; then
961 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
962 fi
963fi
964AC_SUBST([enable_valgrind])
965
Jason Evansb7924f52009-06-23 19:01:18 -0700966dnl Do not support the xmalloc option by default.
967AC_ARG_ENABLE([xmalloc],
968 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
969[if test "x$enable_xmalloc" = "xno" ; then
970 enable_xmalloc="0"
971else
972 enable_xmalloc="1"
973fi
974],
975[enable_xmalloc="0"]
976)
977if test "x$enable_xmalloc" = "x1" ; then
978 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
979fi
980AC_SUBST([enable_xmalloc])
981
Jason Evans6684cac2012-03-05 12:15:36 -0800982AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
983 [je_cv_static_page_shift],
984 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -0700985[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200986#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700987#ifdef _WIN32
988#include <windows.h>
989#else
Jason Evansb7924f52009-06-23 19:01:18 -0700990#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -0700991#endif
992#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -0800993]],
994[[
Garrett Cooper72c1e592012-12-02 17:57:28 -0800995 int result;
Jason Evansb7924f52009-06-23 19:01:18 -0700996 FILE *f;
997
Mike Hommeya19e87f2012-04-21 21:27:46 -0700998#ifdef _WIN32
999 SYSTEM_INFO si;
1000 GetSystemInfo(&si);
1001 result = si.dwPageSize;
1002#else
Jason Evansb7924f52009-06-23 19:01:18 -07001003 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001004#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001005 if (result == -1) {
1006 return 1;
1007 }
Mike Hommeya19e87f2012-04-21 21:27:46 -07001008 result = ffsl(result) - 1;
1009
Jason Evansb7924f52009-06-23 19:01:18 -07001010 f = fopen("conftest.out", "w");
1011 if (f == NULL) {
1012 return 1;
1013 }
Garrett Cooper72c1e592012-12-02 17:57:28 -08001014 fprintf(f, "%d\n", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001015 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001016
1017 return 0;
1018]])],
Jason Evans6684cac2012-03-05 12:15:36 -08001019 [je_cv_static_page_shift=`cat conftest.out`],
1020 [je_cv_static_page_shift=undefined]))
1021
1022if test "x$je_cv_static_page_shift" != "xundefined"; then
1023 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
1024else
1025 AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
1026fi
Jason Evansb7924f52009-06-23 19:01:18 -07001027
1028dnl ============================================================================
1029dnl jemalloc configuration.
1030dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001031
1032dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -07001033if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -07001034 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -08001035fi
Jason Evansb7924f52009-06-23 19:01:18 -07001036jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001037jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1038jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1039jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1040jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1041jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001042AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001043AC_SUBST([jemalloc_version_major])
1044AC_SUBST([jemalloc_version_minor])
1045AC_SUBST([jemalloc_version_bugfix])
1046AC_SUBST([jemalloc_version_nrev])
1047AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001048
1049dnl ============================================================================
1050dnl Configure pthreads.
1051
Mike Hommeya19e87f2012-04-21 21:27:46 -07001052if test "x$abi" != "xpecoff" ; then
1053 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1054 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1055 dnl first, but try libc too before failing.
1056 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1057 [AC_SEARCH_LIBS([pthread_create], , ,
1058 AC_MSG_ERROR([libpthread is missing]))])
1059fi
Jason Evansb7924f52009-06-23 19:01:18 -07001060
1061CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1062
Jason Evanscd9a1342012-03-21 18:33:03 -07001063dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1064dnl it rather than pthreads TSD cleanup functions to support cleanup during
1065dnl thread exit, in order to avoid pthreads library recursion during
1066dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001067AC_CHECK_FUNC([_malloc_thread_cleanup],
1068 [have__malloc_thread_cleanup="1"],
1069 [have__malloc_thread_cleanup="0"]
1070 )
1071if test "x$have__malloc_thread_cleanup" = "x1" ; then
1072 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1073 force_tls="1"
1074fi
1075
Jason Evans41b6afb2012-02-02 22:04:57 -08001076dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1077dnl so, mutex initialization causes allocation, and we need to implement this
1078dnl callback function in order to prevent recursive allocation.
1079AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1080 [have__pthread_mutex_init_calloc_cb="1"],
1081 [have__pthread_mutex_init_calloc_cb="0"]
1082 )
1083if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1084 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1085fi
1086
Jason Evans0fee70d2012-02-13 12:36:11 -08001087dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001088AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001089 [AS_HELP_STRING([--enable-lazy-lock],
1090 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001091[if test "x$enable_lazy_lock" = "xno" ; then
1092 enable_lazy_lock="0"
1093else
1094 enable_lazy_lock="1"
1095fi
1096],
Jason Evans0fee70d2012-02-13 12:36:11 -08001097[enable_lazy_lock="0"]
Jason Evansb7924f52009-06-23 19:01:18 -07001098)
Jason Evansfd4fcef2012-03-23 17:40:58 -07001099if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1100 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1101 enable_lazy_lock="1"
1102fi
Jason Evansb7924f52009-06-23 19:01:18 -07001103if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001104 if test "x$abi" != "xpecoff" ; then
1105 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1106 AC_CHECK_FUNC([dlsym], [],
1107 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1108 [AC_MSG_ERROR([libdl is missing])])
1109 ])
1110 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001111 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1112fi
1113AC_SUBST([enable_lazy_lock])
1114
Jason Evans78d815c2010-01-17 14:06:20 -08001115AC_ARG_ENABLE([tls],
1116 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1117if test "x$enable_tls" = "xno" ; then
1118 enable_tls="0"
1119else
1120 enable_tls="1"
1121fi
1122,
1123enable_tls="1"
1124)
Jason Evanscd9a1342012-03-21 18:33:03 -07001125if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1126 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1127 enable_tls="1"
1128fi
Jason Evansb80581d2012-03-23 16:17:43 -07001129if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1130 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1131 enable_tls="0"
1132fi
Jason Evans78d815c2010-01-17 14:06:20 -08001133if test "x${enable_tls}" = "x1" ; then
1134AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001135AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001136[[
1137 __thread int x;
1138]], [[
1139 x = 42;
1140
1141 return 0;
1142]])],
1143 AC_MSG_RESULT([yes]),
1144 AC_MSG_RESULT([no])
1145 enable_tls="0")
1146fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001147AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001148if test "x${enable_tls}" = "x1" ; then
1149 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001150elif test "x${force_tls}" = "x1" ; then
1151 AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
Jason Evans78d815c2010-01-17 14:06:20 -08001152fi
1153
Jason Evans2dbecf12010-09-05 10:35:13 -07001154dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -07001155dnl Check for ffsl(3), and fail if not found. This function exists on all
1156dnl platforms that jemalloc currently has a chance of functioning on without
1157dnl modification.
Jason Evans4c2faa82012-03-13 11:09:23 -07001158JE_COMPILABLE([a program using ffsl], [
Garrett Cooper72c1e592012-12-02 17:57:28 -08001159#include <stdio.h>
Jason Evans382132e2012-04-04 15:25:43 -07001160#include <strings.h>
Jason Evans4c2faa82012-03-13 11:09:23 -07001161#include <string.h>
1162], [
1163 {
1164 int rv = ffsl(0x08);
Garrett Cooper72c1e592012-12-02 17:57:28 -08001165 printf("%d\n", rv);
Jason Evans4c2faa82012-03-13 11:09:23 -07001166 }
1167], [je_cv_function_ffsl])
Jason Evans6684cac2012-03-05 12:15:36 -08001168if test "x${je_cv_function_ffsl}" != "xyes" ; then
1169 AC_MSG_ERROR([Cannot build without ffsl(3)])
1170fi
Jason Evans84c8eef2011-03-16 10:30:13 -07001171
1172dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001173dnl Check for atomic(9) operations as provided on FreeBSD.
1174
1175JE_COMPILABLE([atomic(9)], [
1176#include <sys/types.h>
1177#include <machine/atomic.h>
1178#include <inttypes.h>
1179], [
1180 {
1181 uint32_t x32 = 0;
1182 volatile uint32_t *x32p = &x32;
1183 atomic_fetchadd_32(x32p, 1);
1184 }
1185 {
1186 unsigned long xlong = 0;
1187 volatile unsigned long *xlongp = &xlong;
1188 atomic_fetchadd_long(xlongp, 1);
1189 }
1190], [je_cv_atomic9])
1191if test "x${je_cv_atomic9}" = "xyes" ; then
1192 AC_DEFINE([JEMALLOC_ATOMIC9])
1193fi
1194
1195dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001196dnl Check for atomic(3) operations as provided on Darwin.
1197
1198JE_COMPILABLE([Darwin OSAtomic*()], [
1199#include <libkern/OSAtomic.h>
1200#include <inttypes.h>
1201], [
1202 {
1203 int32_t x32 = 0;
1204 volatile int32_t *x32p = &x32;
1205 OSAtomicAdd32(1, x32p);
1206 }
1207 {
1208 int64_t x64 = 0;
1209 volatile int64_t *x64p = &x64;
1210 OSAtomicAdd64(1, x64p);
1211 }
Jason Evans6684cac2012-03-05 12:15:36 -08001212], [je_cv_osatomic])
1213if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001214 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001215fi
1216
1217dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001218dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1219dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1220
1221AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1222 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1223 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001224 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1225 #include <stdint.h>
1226 ],
1227 [
1228 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1229 {
1230 uint$1_t x$1 = 0;
1231 __sync_add_and_fetch(&x$1, 42);
1232 __sync_sub_and_fetch(&x$1, 1);
1233 }
1234 #else
1235 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1236 #endif
1237 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001238 [je_cv_sync_compare_and_swap_$2=yes],
1239 [je_cv_sync_compare_and_swap_$2=no])])
1240
1241 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1242 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1243 fi
1244])
1245
Jason Evansb57d3ec2012-04-17 13:17:54 -07001246if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001247 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1248 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1249fi
1250
1251dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001252dnl Check for spinlock(3) operations as provided on Darwin.
1253
1254JE_COMPILABLE([Darwin OSSpin*()], [
1255#include <libkern/OSAtomic.h>
1256#include <inttypes.h>
1257], [
1258 OSSpinLock lock = 0;
1259 OSSpinLockLock(&lock);
1260 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001261], [je_cv_osspin])
1262if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001263 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001264fi
1265
1266dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001267dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001268
Mike Hommeyd0357f72012-11-26 18:52:41 +01001269AC_ARG_ENABLE([zone-allocator],
1270 [AS_HELP_STRING([--disable-zone-allocator],
1271 [Disable zone allocator for Darwin])],
1272[if test "x$enable_zone_allocator" = "xno" ; then
1273 enable_zone_allocator="0"
1274else
1275 enable_zone_allocator="1"
1276fi
1277],
1278[if test "x${abi}" = "xmacho"; then
1279 enable_zone_allocator="1"
1280fi
1281]
1282)
1283AC_SUBST([enable_zone_allocator])
1284
1285if test "x${enable_zone_allocator}" = "x1" ; then
1286 if test "x${abi}" != "xmacho"; then
1287 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1288 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001289 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1290 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001291
Jason Evans2dbecf12010-09-05 10:35:13 -07001292 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1293 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1294 dnl 10.6, which is the only source-level indication of the change.
1295 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001296 AC_DEFUN([JE_ZONE_PROGRAM],
1297 [AC_LANG_PROGRAM(
1298 [#include <malloc/malloc.h>],
1299 [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1300 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001301
Mike Hommey154829d2012-03-20 18:01:38 +01001302 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1303 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1304 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1305 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1306 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1307 )])],[
1308 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1309 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1310 )])])])])
1311 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1312 AC_MSG_RESULT([unsupported])
1313 AC_MSG_ERROR([Unsupported malloc zone version])
1314 fi
1315 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1316 JEMALLOC_ZONE_VERSION=8
1317 AC_MSG_RESULT([> 8])
1318 else
1319 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1320 fi
1321 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001322fi
1323
Jason Evansb7924f52009-06-23 19:01:18 -07001324dnl ============================================================================
1325dnl Check for typedefs, structures, and compiler characteristics.
1326AC_HEADER_STDBOOL
1327
Jason Evans748dfac2013-12-06 18:27:33 -08001328dnl ============================================================================
1329dnl Define commands that generate output files.
1330
Jason Evans86abd0d2013-11-30 15:25:42 -08001331AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1332 mkdir -p "${objroot}include/jemalloc/internal"
1333 "${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 -08001334], [
1335 srcdir="${srcdir}"
1336 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001337])
1338AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1339 mkdir -p "${objroot}include/jemalloc/internal"
1340 "${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 -08001341], [
1342 srcdir="${srcdir}"
1343 objroot="${objroot}"
1344])
1345AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1346 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1347 mkdir -p "${objroot}include/jemalloc/internal"
1348 cp /dev/null "${f}"
1349 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1350 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1351 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1352 echo "${n}:${m}" >> "${f}"
1353 dnl Remove name from public_syms so that it isn't redefined later.
1354 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1355 done
1356 for sym in ${public_syms} ; do
1357 n="${sym}"
1358 m="${JEMALLOC_PREFIX}${sym}"
1359 echo "${n}:${m}" >> "${f}"
1360 done
1361], [
1362 srcdir="${srcdir}"
1363 objroot="${objroot}"
1364 mangling_map="${mangling_map}"
1365 public_syms="${public_syms}"
1366 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001367])
1368AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1369 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001370 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1371], [
1372 srcdir="${srcdir}"
1373 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001374])
1375AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1376 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001377 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1378], [
1379 srcdir="${srcdir}"
1380 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001381])
Jason Evansb1726102012-02-28 16:50:47 -08001382AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001383 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansb1726102012-02-28 16:50:47 -08001384 "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001385], [
1386 srcdir="${srcdir}"
1387 objroot="${objroot}"
Jason Evansb1726102012-02-28 16:50:47 -08001388])
Jason Evans86abd0d2013-11-30 15:25:42 -08001389AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1390 mkdir -p "${objroot}include/jemalloc"
1391 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 -08001392], [
1393 srcdir="${srcdir}"
1394 objroot="${objroot}"
1395])
1396AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1397 mkdir -p "${objroot}include/jemalloc"
1398 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1399], [
1400 srcdir="${srcdir}"
1401 objroot="${objroot}"
1402])
1403AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1404 mkdir -p "${objroot}include/jemalloc"
1405 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1406], [
1407 srcdir="${srcdir}"
1408 objroot="${objroot}"
1409])
1410AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1411 mkdir -p "${objroot}include/jemalloc"
1412 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1413], [
1414 srcdir="${srcdir}"
1415 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001416])
1417AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1418 mkdir -p "${objroot}include/jemalloc"
1419 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001420], [
1421 srcdir="${srcdir}"
1422 objroot="${objroot}"
1423 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001424])
Jason Evansb1726102012-02-28 16:50:47 -08001425
Jason Evansb7924f52009-06-23 19:01:18 -07001426dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001427AC_SUBST([cfghdrs_in])
1428AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001429AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001430
1431dnl ============================================================================
1432dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001433
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +04001434AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
Jason Evansb0fd5012010-01-17 01:49:20 -08001435AC_SUBST([cfgoutputs_in])
1436AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001437AC_OUTPUT
1438
1439dnl ============================================================================
1440dnl Print out the results of configuration.
1441AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001442AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1443AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001444AC_MSG_RESULT([])
1445AC_MSG_RESULT([CC : ${CC}])
1446AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1447AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1448AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001449AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001450AC_MSG_RESULT([LIBS : ${LIBS}])
1451AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1452AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001453AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1454AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1455AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001456AC_MSG_RESULT([PREFIX : ${PREFIX}])
1457AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001458AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1459AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001460AC_MSG_RESULT([DATADIR : ${DATADIR}])
1461AC_MSG_RESULT([MANDIR : ${MANDIR}])
1462AC_MSG_RESULT([])
1463AC_MSG_RESULT([srcroot : ${srcroot}])
1464AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1465AC_MSG_RESULT([objroot : ${objroot}])
1466AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1467AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001468AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001469AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1470AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001471AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -07001472AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans7e77eaf2012-03-02 17:47:37 -08001473AC_MSG_RESULT([experimental : ${enable_experimental}])
Jason Evans355b4382010-09-20 19:20:48 -07001474AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001475AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001476AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001477AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001478AC_MSG_RESULT([prof : ${enable_prof}])
1479AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001480AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1481AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001482AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001483AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001484AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001485AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1486AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans2e671ff2012-05-09 16:12:00 -07001487AC_MSG_RESULT([mremap : ${enable_mremap}])
Jason Evans59ae2762012-04-16 17:52:27 -07001488AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001489AC_MSG_RESULT([dss : ${enable_dss}])
Jason Evansb7924f52009-06-23 19:01:18 -07001490AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001491AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -07001492AC_MSG_RESULT([===============================================================================])