blob: 8adb6f7b6264120f4906f79693263fd2b7642ebc [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 Evans3a923192015-11-12 11:23:39 -08004AC_CONFIG_AUX_DIR([build-aux])
5
Jason Evansf3340ca2009-06-30 16:17:05 -07006dnl ============================================================================
7dnl Custom macro definitions.
8
9dnl JE_CFLAGS_APPEND(cflag)
10AC_DEFUN([JE_CFLAGS_APPEND],
11[
12AC_MSG_CHECKING([whether compiler supports $1])
13TCFLAGS="${CFLAGS}"
14if test "x${CFLAGS}" = "x" ; then
15 CFLAGS="$1"
16else
17 CFLAGS="${CFLAGS} $1"
18fi
Jason Evans6684cac2012-03-05 12:15:36 -080019AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evansf3340ca2009-06-30 16:17:05 -070020[[
21]], [[
22 return 0;
23]])],
Jason Evans99b0fbb2014-02-24 16:08:38 -080024 [je_cv_cflags_appended=$1]
Jason Evansf3340ca2009-06-30 16:17:05 -070025 AC_MSG_RESULT([yes]),
Jason Evans99b0fbb2014-02-24 16:08:38 -080026 [je_cv_cflags_appended=]
Jason Evansf3340ca2009-06-30 16:17:05 -070027 AC_MSG_RESULT([no])
28 [CFLAGS="${TCFLAGS}"]
29)
30])
31
32dnl JE_COMPILABLE(label, hcode, mcode, rvar)
Jason Evans4c2faa82012-03-13 11:09:23 -070033dnl
Jason Evansf3e139a2012-03-19 09:54:20 -070034dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
Jason Evans4c2faa82012-03-13 11:09:23 -070035dnl cause failure.
Jason Evansf3340ca2009-06-30 16:17:05 -070036AC_DEFUN([JE_COMPILABLE],
37[
Jason Evans6684cac2012-03-05 12:15:36 -080038AC_CACHE_CHECK([whether $1 is compilable],
39 [$4],
Jason Evansf3e139a2012-03-19 09:54:20 -070040 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
41 [$3])],
42 [$4=yes],
43 [$4=no])])
Jason Evansf3340ca2009-06-30 16:17:05 -070044])
45
46dnl ============================================================================
47
Jason Evans41f2e692015-01-25 20:15:13 -080048CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
Jason Evansbec6a8d2015-01-22 17:55:58 -080049AC_SUBST([CONFIG])
50
Jason Evansf576c632011-11-01 22:27:41 -070051dnl Library revision.
Jason Evans9790b962014-04-14 22:32:31 -070052rev=2
Jason Evansf576c632011-11-01 22:27:41 -070053AC_SUBST([rev])
54
Jason Evansb7924f52009-06-23 19:01:18 -070055srcroot=$srcdir
56if test "x${srcroot}" = "x." ; then
57 srcroot=""
58else
59 srcroot="${srcroot}/"
60fi
61AC_SUBST([srcroot])
62abs_srcroot="`cd \"${srcdir}\"; pwd`/"
63AC_SUBST([abs_srcroot])
64
65objroot=""
66AC_SUBST([objroot])
67abs_objroot="`pwd`/"
68AC_SUBST([abs_objroot])
69
70dnl Munge install path variables.
71if test "x$prefix" = "xNONE" ; then
72 prefix="/usr/local"
73fi
74if test "x$exec_prefix" = "xNONE" ; then
75 exec_prefix=$prefix
76fi
77PREFIX=$prefix
78AC_SUBST([PREFIX])
79BINDIR=`eval echo $bindir`
80BINDIR=`eval echo $BINDIR`
81AC_SUBST([BINDIR])
82INCLUDEDIR=`eval echo $includedir`
83INCLUDEDIR=`eval echo $INCLUDEDIR`
84AC_SUBST([INCLUDEDIR])
85LIBDIR=`eval echo $libdir`
86LIBDIR=`eval echo $LIBDIR`
87AC_SUBST([LIBDIR])
88DATADIR=`eval echo $datadir`
89DATADIR=`eval echo $DATADIR`
90AC_SUBST([DATADIR])
91MANDIR=`eval echo $mandir`
92MANDIR=`eval echo $MANDIR`
93AC_SUBST([MANDIR])
94
Jason Evansaee7fd22010-11-24 22:00:02 -080095dnl Support for building documentation.
Jason Evans7329a4f2013-01-22 10:53:29 -080096AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
Jason Evans7091b412012-03-19 09:36:44 -070097if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
98 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
99elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
100 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
101else
102 dnl Documentation building will fail if this default gets used.
103 DEFAULT_XSLROOT=""
104fi
Jason Evansaee7fd22010-11-24 22:00:02 -0800105AC_ARG_WITH([xslroot],
Jason Evans7091b412012-03-19 09:36:44 -0700106 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
Jason Evansaee7fd22010-11-24 22:00:02 -0800107if test "x$with_xslroot" = "xno" ; then
Jason Evans7091b412012-03-19 09:36:44 -0700108 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800109else
110 XSLROOT="${with_xslroot}"
Jason Evans7091b412012-03-19 09:36:44 -0700111fi
112],
113 XSLROOT="${DEFAULT_XSLROOT}"
Jason Evansaee7fd22010-11-24 22:00:02 -0800114)
115AC_SUBST([XSLROOT])
116
Jason Evansf3340ca2009-06-30 16:17:05 -0700117dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
118dnl just prevent autoconf from molesting CFLAGS.
Jason Evansb7924f52009-06-23 19:01:18 -0700119CFLAGS=$CFLAGS
120AC_PROG_CC
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200121if test "x$GCC" != "xyes" ; then
122 AC_CACHE_CHECK([whether compiler is MSVC],
123 [je_cv_msvc],
124 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
125 [
126#ifndef _MSC_VER
127 int fail[-1];
128#endif
129])],
130 [je_cv_msvc=yes],
131 [je_cv_msvc=no])])
132fi
133
Jason Evansb7924f52009-06-23 19:01:18 -0700134if test "x$CFLAGS" = "x" ; then
135 no_CFLAGS="yes"
Jason Evanscfeccd32010-03-03 15:48:20 -0800136 if test "x$GCC" = "xyes" ; then
137 JE_CFLAGS_APPEND([-std=gnu99])
Jason Evans99b0fbb2014-02-24 16:08:38 -0800138 if test "x$je_cv_cflags_appended" = "x-std=gnu99" ; then
139 AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
140 fi
Jason Evanscfeccd32010-03-03 15:48:20 -0800141 JE_CFLAGS_APPEND([-Wall])
Mike Hommeyb7b44df2014-12-18 15:12:53 +0900142 JE_CFLAGS_APPEND([-Werror=declaration-after-statement])
Jason Evanscfeccd32010-03-03 15:48:20 -0800143 JE_CFLAGS_APPEND([-pipe])
144 JE_CFLAGS_APPEND([-g3])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200145 elif test "x$je_cv_msvc" = "xyes" ; then
146 CC="$CC -nologo"
147 JE_CFLAGS_APPEND([-Zi])
148 JE_CFLAGS_APPEND([-MT])
149 JE_CFLAGS_APPEND([-W3])
Mike Hommey8c615752014-05-29 16:58:21 +0900150 JE_CFLAGS_APPEND([-FS])
Mike Hommey6f6704c2014-05-29 17:01:10 +0900151 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat"
Jason Evanscfeccd32010-03-03 15:48:20 -0800152 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700153fi
154dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
155if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700156 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700157fi
158AC_PROG_CPP
159
Jason Evansdf3f2702014-03-30 16:27:08 -0700160AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
161if test "x${ac_cv_big_endian}" = "x1" ; then
162 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
163fi
164
Mike Hommeyff2e9992014-05-29 16:33:02 +0900165if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
Mike Hommey6f6704c2014-05-29 17:01:10 +0900166 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
Mike Hommeyff2e9992014-05-29 16:33:02 +0900167fi
168
rustyx46e0b232016-01-30 13:37:26 +0100169if test "x${je_cv_msvc}" = "xyes" ; then
170 LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
171 AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
Jason Evansb7924f52009-06-23 19:01:18 -0700172else
rustyx46e0b232016-01-30 13:37:26 +0100173 AC_CHECK_SIZEOF([void *])
174 if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
175 LG_SIZEOF_PTR=3
176 elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
177 LG_SIZEOF_PTR=2
178 else
179 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
180 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700181fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800182AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
183
184AC_CHECK_SIZEOF([int])
185if test "x${ac_cv_sizeof_int}" = "x8" ; then
186 LG_SIZEOF_INT=3
187elif test "x${ac_cv_sizeof_int}" = "x4" ; then
188 LG_SIZEOF_INT=2
189else
190 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
191fi
192AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700193
Jason Evans84c8eef2011-03-16 10:30:13 -0700194AC_CHECK_SIZEOF([long])
195if test "x${ac_cv_sizeof_long}" = "x8" ; then
196 LG_SIZEOF_LONG=3
197elif test "x${ac_cv_sizeof_long}" = "x4" ; then
198 LG_SIZEOF_LONG=2
199else
200 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
201fi
202AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
203
Jason Evansd81e4bd2012-03-06 14:57:45 -0800204AC_CHECK_SIZEOF([intmax_t])
205if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
206 LG_SIZEOF_INTMAX_T=4
207elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
208 LG_SIZEOF_INTMAX_T=3
209elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
210 LG_SIZEOF_INTMAX_T=2
211else
Mike Hommey14103d32012-04-20 08:38:39 +0200212 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800213fi
214AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
215
Jason Evansb7924f52009-06-23 19:01:18 -0700216AC_CANONICAL_HOST
217dnl CPU-specific settings.
218CPU_SPINWAIT=""
219case "${host_cpu}" in
Jason Evanscb657e32014-02-25 11:21:41 -0800220 i686|x86_64)
rustyx90c72692016-01-30 13:41:09 +0100221 if test "x${je_cv_msvc}" = "xyes" ; then
222 AC_CACHE_VAL([je_cv_pause_msvc],
223 [JE_COMPILABLE([pause instruction MSVC], [],
224 [[_mm_pause(); return 0;]],
225 [je_cv_pause_msvc])])
226 if test "x${je_cv_pause_msvc}" = "xyes" ; then
227 CPU_SPINWAIT='_mm_pause()'
228 fi
229 else
230 AC_CACHE_VAL([je_cv_pause],
231 [JE_COMPILABLE([pause instruction], [],
232 [[__asm__ volatile("pause"); return 0;]],
233 [je_cv_pause])])
234 if test "x${je_cv_pause}" = "xyes" ; then
235 CPU_SPINWAIT='__asm__ volatile("pause")'
236 fi
Jason Evansf3340ca2009-06-30 16:17:05 -0700237 fi
Jason Evans80061b62013-12-09 13:21:08 -0800238 ;;
239 powerpc)
240 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700241 ;;
242 *)
243 ;;
244esac
245AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
246
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400247LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700248so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200249importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200250o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200251a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200252exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700253libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200254DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
255RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200256SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200257PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200258CTARGET='-o $@'
259LDTARGET='-o $@'
260EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100261ARFLAGS='crus'
262AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200263CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800264
Jory A. Prattad505e02013-08-11 09:44:59 -0500265AN_MAKEVAR([AR], [AC_PROG_AR])
266AN_PROGRAM([ar], [AC_PROG_AR])
267AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
268AC_PROG_AR
269
Jason Evansb7924f52009-06-23 19:01:18 -0700270dnl Platform-specific settings. abi and RPATH can probably be determined
271dnl programmatically, but doing so is error-prone, which makes it generally
272dnl not worth the trouble.
273dnl
274dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
275dnl definitions need to be seen before any headers are included, which is a pain
276dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700277default_munmap="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700278maps_coalesce="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700279case "${host}" in
Valerii Hiora5921ba72014-05-16 16:28:20 +0300280 *-*-darwin* | *-*-ios*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200281 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700282 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700283 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700284 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400285 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700286 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200287 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700288 force_tls="0"
Jason Evansf1f2b452015-05-01 08:57:41 -0700289 DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200290 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800291 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700292 ;;
293 *-*-freebsd*)
294 CFLAGS="$CFLAGS"
295 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700296 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700297 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700298 ;;
Michael Neumann1aa25a32014-08-05 03:06:02 +0200299 *-*-dragonfly*)
300 CFLAGS="$CFLAGS"
301 abi="elf"
302 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
303 ;;
Sébastien Marieb80fbcb2015-04-07 12:21:19 +0200304 *-*-openbsd*)
305 CFLAGS="$CFLAGS"
306 abi="elf"
307 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
308 force_tls="0"
309 ;;
310 *-*-bitrig*)
Sébastien Marie77d597e2015-01-25 10:18:32 +0100311 CFLAGS="$CFLAGS"
312 abi="elf"
313 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
314 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700315 *-*-linux*)
316 CFLAGS="$CFLAGS"
317 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
318 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800319 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700320 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700321 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansae93d6b2015-07-10 14:33:00 -0700322 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700323 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700324 ;;
325 *-*-netbsd*)
326 AC_MSG_CHECKING([ABI])
327 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
328[[#ifdef __ELF__
329/* ELF */
330#else
331#error aout
332#endif
333]])],
334 [CFLAGS="$CFLAGS"; abi="elf"],
335 [abi="aout"])
336 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700337 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700338 ;;
339 *-*-solaris2*)
340 CFLAGS="$CFLAGS"
341 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000342 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200343 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700344 dnl Solaris needs this for sigwait().
345 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
346 LIBS="$LIBS -lposix4 -lsocket -lnsl"
347 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400348 *-ibm-aix*)
349 if "$LG_SIZEOF_PTR" = "8"; then
350 dnl 64bit AIX
351 LD_PRELOAD_VAR="LDR_PRELOAD64"
352 else
353 dnl 32bit AIX
354 LD_PRELOAD_VAR="LDR_PRELOAD"
355 fi
356 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400357 ;;
Dave Rigby70bdee02014-09-22 15:53:16 +0100358 *-*-mingw* | *-*-cygwin*)
Mike Hommeya19e87f2012-04-21 21:27:46 -0700359 abi="pecoff"
360 force_tls="0"
Jason Evans13473c72015-07-23 14:08:49 -0700361 force_lazy_lock="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700362 maps_coalesce="0"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700363 RPATH=""
364 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200365 if test "x$je_cv_msvc" = "xyes" ; then
366 importlib="lib"
367 DSO_LDFLAGS="-LD"
368 EXTRA_LDFLAGS="-link -DEBUG"
369 CTARGET='-Fo$@'
370 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500371 AR='lib'
372 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100373 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200374 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200375 else
376 importlib="${so}"
377 DSO_LDFLAGS="-shared"
378 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700379 a="lib"
380 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200381 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700382 PIC_CFLAGS=""
383 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700384 *)
385 AC_MSG_RESULT([Unsupported operating system: ${host}])
386 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700387 ;;
388esac
Mike Hommeyaffe0092014-05-28 08:10:12 +0900389
390JEMALLOC_USABLE_SIZE_CONST=const
391AC_CHECK_HEADERS([malloc.h], [
392 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
393 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
394 [#include <malloc.h>
395 #include <stddef.h>
396 size_t malloc_usable_size(const void *ptr);
397 ],
398 [])],[
399 AC_MSG_RESULT([yes])
400 ],[
401 JEMALLOC_USABLE_SIZE_CONST=
402 AC_MSG_RESULT([no])
403 ])
404])
Jason Evans247d1242012-10-09 16:20:10 -0700405AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700406AC_SUBST([abi])
407AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400408AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700409AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200410AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200411AC_SUBST([o])
412AC_SUBST([a])
413AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700414AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200415AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200416AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200417AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200418AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200419AC_SUBST([CTARGET])
420AC_SUBST([LDTARGET])
421AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100422AC_SUBST([ARFLAGS])
423AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200424AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200425
Jason Evansfa5d2452011-03-15 10:25:59 -0700426JE_COMPILABLE([__attribute__ syntax],
427 [static __attribute__((unused)) void foo(void){}],
428 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800429 [je_cv_attribute])
430if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700431 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
432 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
433 JE_CFLAGS_APPEND([-fvisibility=hidden])
434 fi
435fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700436dnl Check for tls_model attribute support (clang 3.0 still lacks support).
437SAVED_CFLAGS="${CFLAGS}"
438JE_CFLAGS_APPEND([-Werror])
439JE_COMPILABLE([tls_model attribute], [],
440 [static __thread int
Daniel Micayf1cf3ea2014-09-16 04:42:33 -0400441 __attribute__((tls_model("initial-exec"), unused)) foo;
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700442 foo = 0;],
443 [je_cv_tls_model])
444CFLAGS="${SAVED_CFLAGS}"
445if test "x${je_cv_tls_model}" = "xyes" ; then
446 AC_DEFINE([JEMALLOC_TLS_MODEL],
447 [__attribute__((tls_model("initial-exec")))])
448else
449 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
450fi
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700451dnl Check for alloc_size attribute support.
452SAVED_CFLAGS="${CFLAGS}"
453JE_CFLAGS_APPEND([-Werror])
Jason Evans92d72ee2015-07-10 16:45:32 -0700454JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
455 [void *foo(size_t size) __attribute__((alloc_size(1)));],
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700456 [je_cv_alloc_size])
457CFLAGS="${SAVED_CFLAGS}"
458if test "x${je_cv_alloc_size}" = "xyes" ; then
459 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
460fi
Jason Evanse42c3092015-07-22 15:44:47 -0700461dnl Check for format(gnu_printf, ...) attribute support.
462SAVED_CFLAGS="${CFLAGS}"
463JE_CFLAGS_APPEND([-Werror])
464JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
465 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
466 [je_cv_format_gnu_printf])
467CFLAGS="${SAVED_CFLAGS}"
468if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
469 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
470fi
471dnl Check for format(printf, ...) attribute support.
472SAVED_CFLAGS="${CFLAGS}"
473JE_CFLAGS_APPEND([-Werror])
474JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
475 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
476 [je_cv_format_printf])
477CFLAGS="${SAVED_CFLAGS}"
478if test "x${je_cv_format_printf}" = "xyes" ; then
479 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
480fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700481
Jason Evansb7924f52009-06-23 19:01:18 -0700482dnl Support optional additions to rpath.
483AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800484 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700485if test "x$with_rpath" = "xno" ; then
486 RPATH_EXTRA=
487else
488 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
489fi,
490 RPATH_EXTRA=
491)
492AC_SUBST([RPATH_EXTRA])
493
494dnl Disable rules that do automatic regeneration of configure output by default.
495AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800496 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700497if test "x$enable_autogen" = "xno" ; then
498 enable_autogen="0"
499else
500 enable_autogen="1"
501fi
502,
503enable_autogen="0"
504)
505AC_SUBST([enable_autogen])
506
507AC_PROG_INSTALL
508AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800509AC_PATH_PROG([LD], [ld], [false], [$PATH])
510AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700511
Daniel Micay4cfe5512014-08-28 15:41:48 -0400512public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx sdallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size"
Jason Evans7e77eaf2012-03-02 17:47:37 -0800513
514dnl Check for allocator-related functions that should be wrapped.
515AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700516 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800517 public_syms="${public_syms} memalign"])
518AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700519 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800520 public_syms="${public_syms} valloc"])
521
Jason Evans748dfac2013-12-06 18:27:33 -0800522dnl Do not compute test code coverage by default.
523GCOV_FLAGS=
524AC_ARG_ENABLE([code-coverage],
525 [AS_HELP_STRING([--enable-code-coverage],
526 [Enable code coverage])],
527[if test "x$enable_code_coverage" = "xno" ; then
528 enable_code_coverage="0"
529else
530 enable_code_coverage="1"
531fi
532],
533[enable_code_coverage="0"]
534)
535if test "x$enable_code_coverage" = "x1" ; then
536 deoptimize="no"
537 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
538 if test "x${deoptimize}" = "xyes" ; then
539 JE_CFLAGS_APPEND([-O0])
540 fi
541 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
542 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
543 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
544fi
545AC_SUBST([enable_code_coverage])
546
Jason Evans0a5489e2012-03-01 17:19:20 -0800547dnl Perform no name mangling by default.
548AC_ARG_WITH([mangling],
549 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
550 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800551
Jason Evans90895cf2009-12-29 00:09:15 -0800552dnl Do not prefix public APIs by default.
553AC_ARG_WITH([jemalloc_prefix],
554 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800555 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200556 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700557 JEMALLOC_PREFIX=""
558else
559 JEMALLOC_PREFIX="je_"
560fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800561)
562if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700563 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
564 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
565 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800566fi
Jason Evans241abc62015-06-23 18:47:07 -0700567AC_SUBST([JEMALLOC_CPREFIX])
Jason Evans90895cf2009-12-29 00:09:15 -0800568
Mike Hommey99066602012-11-19 10:55:26 +0100569AC_ARG_WITH([export],
570 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
571 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800572 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100573fi]
574)
575
Jason Evans86abd0d2013-11-30 15:25:42 -0800576dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700577AC_ARG_WITH([private_namespace],
578 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800579 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
580 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700581)
Jason Evans86abd0d2013-11-30 15:25:42 -0800582AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
583private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
584AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700585
Jason Evansb0fd5012010-01-17 01:49:20 -0800586dnl Do not add suffix to installed files by default.
587AC_ARG_WITH([install_suffix],
588 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
589 [INSTALL_SUFFIX="$with_install_suffix"],
590 [INSTALL_SUFFIX=]
591)
592install_suffix="$INSTALL_SUFFIX"
593AC_SUBST([install_suffix])
594
Jason Evansf8290092016-02-07 14:23:22 -0800595dnl Specify default malloc_conf.
596AC_ARG_WITH([malloc_conf],
597 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
598 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
599 [JEMALLOC_CONFIG_MALLOC_CONF=""]
600)
601config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
602AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
603
Jason Evans86abd0d2013-11-30 15:25:42 -0800604dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
605dnl jemalloc_protos_jet.h easy.
606je_="je_"
607AC_SUBST([je_])
608
Mike Hommeycf6032d2014-07-30 18:16:13 +0900609cfgoutputs_in="Makefile.in"
Nick White913e9a82014-09-19 22:01:23 +0100610cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900611cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
612cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
613cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
614cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
615cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700616cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900617cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
618cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
619cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800620
Jason Evansaee7fd22010-11-24 22:00:02 -0800621cfgoutputs_out="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100622cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
Jason Evansaee7fd22010-11-24 22:00:02 -0800623cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
624cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800625cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
626cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
627cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans82e88d12014-09-07 19:55:03 -0700628cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
Jason Evans376b1522010-02-11 14:45:59 -0800629cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800630cfgoutputs_out="${cfgoutputs_out} test/test.sh"
631cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800632
Jason Evansaee7fd22010-11-24 22:00:02 -0800633cfgoutputs_tup="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100634cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
Jason Evansaee7fd22010-11-24 22:00:02 -0800635cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
636cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800637cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
638cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
639cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700640cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800641cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800642cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
643cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800644
Mike Hommeycf6032d2014-07-30 18:16:13 +0900645cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
646cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
647cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
648cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
649cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
650cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
651cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
652cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
653cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
654cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
655cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
656cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800657
Jason Evans86abd0d2013-11-30 15:25:42 -0800658cfghdrs_out="include/jemalloc/jemalloc_defs.h"
659cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800660cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
661cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800662cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800663cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
664cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800665cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800666cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
667cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
668cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
669cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
670cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800671cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800672
Jason Evans86abd0d2013-11-30 15:25:42 -0800673cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900674cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
675cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800676
Jason Evans644d4142014-04-14 22:49:23 -0700677dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700678AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700679 [AS_HELP_STRING([--disable-cc-silence],
680 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700681[if test "x$enable_cc_silence" = "xno" ; then
682 enable_cc_silence="0"
683else
684 enable_cc_silence="1"
685fi
686],
Jason Evans644d4142014-04-14 22:49:23 -0700687[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700688)
689if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700690 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700691fi
692
Jason Evansb7924f52009-06-23 19:01:18 -0700693dnl Do not compile with debugging by default.
694AC_ARG_ENABLE([debug],
Jason Evanse0a08a12015-03-18 21:06:58 -0700695 [AS_HELP_STRING([--enable-debug],
696 [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700697[if test "x$enable_debug" = "xno" ; then
698 enable_debug="0"
699else
700 enable_debug="1"
701fi
702],
703[enable_debug="0"]
704)
Jason Evans02e5dcf2015-02-15 20:12:06 -0800705if test "x$enable_debug" = "x1" ; then
706 AC_DEFINE([JEMALLOC_DEBUG], [ ])
707fi
Jason Evanse0a08a12015-03-18 21:06:58 -0700708if test "x$enable_debug" = "x1" ; then
709 AC_DEFINE([JEMALLOC_DEBUG], [ ])
710 enable_ivsalloc="1"
711fi
Jason Evansb7924f52009-06-23 19:01:18 -0700712AC_SUBST([enable_debug])
713
Jason Evanse0a08a12015-03-18 21:06:58 -0700714dnl Do not validate pointers by default.
715AC_ARG_ENABLE([ivsalloc],
716 [AS_HELP_STRING([--enable-ivsalloc],
717 [Validate pointers passed through the public API])],
718[if test "x$enable_ivsalloc" = "xno" ; then
719 enable_ivsalloc="0"
720else
721 enable_ivsalloc="1"
722fi
723],
724[enable_ivsalloc="0"]
725)
726if test "x$enable_ivsalloc" = "x1" ; then
727 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
728fi
729
Jason Evansb7924f52009-06-23 19:01:18 -0700730dnl Only optimize if not debugging.
731if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
732 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700733 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800734 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700735 if test "x${optimize}" = "xyes" ; then
736 if test "x$GCC" = "xyes" ; then
737 JE_CFLAGS_APPEND([-O3])
738 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200739 elif test "x$je_cv_msvc" = "xyes" ; then
740 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700741 else
742 JE_CFLAGS_APPEND([-O])
743 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700744 fi
745fi
746
Jason Evansd073a322012-02-28 20:41:16 -0800747dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700748AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800749 [AS_HELP_STRING([--disable-stats],
750 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700751[if test "x$enable_stats" = "xno" ; then
752 enable_stats="0"
753else
754 enable_stats="1"
755fi
756],
Jason Evansd073a322012-02-28 20:41:16 -0800757[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700758)
759if test "x$enable_stats" = "x1" ; then
760 AC_DEFINE([JEMALLOC_STATS], [ ])
761fi
762AC_SUBST([enable_stats])
763
Jason Evans6109fe02010-02-10 10:37:56 -0800764dnl Do not enable profiling by default.
765AC_ARG_ENABLE([prof],
766 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
767[if test "x$enable_prof" = "xno" ; then
768 enable_prof="0"
769else
770 enable_prof="1"
771fi
772],
773[enable_prof="0"]
774)
Jason Evans77f350b2011-03-15 22:23:12 -0700775if test "x$enable_prof" = "x1" ; then
776 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800777else
Jason Evans77f350b2011-03-15 22:23:12 -0700778 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800779fi
Jason Evans77f350b2011-03-15 22:23:12 -0700780
Jason Evans6109fe02010-02-10 10:37:56 -0800781AC_ARG_ENABLE([prof-libunwind],
782 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
783[if test "x$enable_prof_libunwind" = "xno" ; then
784 enable_prof_libunwind="0"
785else
786 enable_prof_libunwind="1"
787fi
788],
789[enable_prof_libunwind="0"]
790)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800791AC_ARG_WITH([static_libunwind],
792 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
793 [Path to static libunwind library; use rather than dynamically linking])],
794if test "x$with_static_libunwind" = "xno" ; then
795 LUNWIND="-lunwind"
796else
797 if test ! -f "$with_static_libunwind" ; then
798 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
799 fi
800 LUNWIND="$with_static_libunwind"
801fi,
802 LUNWIND="-lunwind"
803)
Jason Evans77f350b2011-03-15 22:23:12 -0700804if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
805 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
806 if test "x$LUNWIND" = "x-lunwind" ; then
Jason Evans05125b82014-04-22 20:48:07 -0700807 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700808 [enable_prof_libunwind="0"])
809 else
810 LIBS="$LIBS $LUNWIND"
811 fi
812 if test "x${enable_prof_libunwind}" = "x1" ; then
813 backtrace_method="libunwind"
814 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
815 fi
816fi
817
818AC_ARG_ENABLE([prof-libgcc],
819 [AS_HELP_STRING([--disable-prof-libgcc],
820 [Do not use libgcc for backtracing])],
821[if test "x$enable_prof_libgcc" = "xno" ; then
822 enable_prof_libgcc="0"
823else
824 enable_prof_libgcc="1"
825fi
826],
827[enable_prof_libgcc="1"]
828)
829if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
830 -a "x$GCC" = "xyes" ; then
831 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
832 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
Jason Evans77f350b2011-03-15 22:23:12 -0700833 if test "x${enable_prof_libgcc}" = "x1" ; then
834 backtrace_method="libgcc"
835 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
836 fi
837else
838 enable_prof_libgcc="0"
839fi
840
841AC_ARG_ENABLE([prof-gcc],
842 [AS_HELP_STRING([--disable-prof-gcc],
843 [Do not use gcc intrinsics for backtracing])],
844[if test "x$enable_prof_gcc" = "xno" ; then
845 enable_prof_gcc="0"
846else
847 enable_prof_gcc="1"
848fi
849],
850[enable_prof_gcc="1"]
851)
852if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
853 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700854 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700855 backtrace_method="gcc intrinsics"
856 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
857else
858 enable_prof_gcc="0"
859fi
860
861if test "x$backtrace_method" = "x" ; then
862 backtrace_method="none (disabling profiling)"
863 enable_prof="0"
864fi
865AC_MSG_CHECKING([configured backtracing method])
866AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700867if test "x$enable_prof" = "x1" ; then
Jason Evansd37d5ad2013-12-05 23:01:50 -0800868 if test "x$abi" != "xpecoff"; then
869 dnl Heap profiling uses the log(3) function.
870 LIBS="$LIBS -lm"
871 fi
872
Jason Evans2dbecf12010-09-05 10:35:13 -0700873 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700874fi
875AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700876
Jason Evans84cbbcb2009-12-29 00:09:15 -0800877dnl Enable thread-specific caching by default.
878AC_ARG_ENABLE([tcache],
879 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
880[if test "x$enable_tcache" = "xno" ; then
881 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700882else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800883 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700884fi
885],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800886[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700887)
Jason Evans2dbecf12010-09-05 10:35:13 -0700888if test "x$enable_tcache" = "x1" ; then
889 AC_DEFINE([JEMALLOC_TCACHE], [ ])
890fi
891AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700892
Jason Evansd059b9d2015-07-24 18:21:42 -0700893dnl Indicate whether adjacent virtual memory mappings automatically coalesce
894dnl (and fragment on demand).
895if test "x${maps_coalesce}" = "x1" ; then
896 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
897fi
898
Jason Evans59ae2762012-04-16 17:52:27 -0700899dnl Enable VM deallocation via munmap() by default.
900AC_ARG_ENABLE([munmap],
901 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
902[if test "x$enable_munmap" = "xno" ; then
903 enable_munmap="0"
904else
905 enable_munmap="1"
906fi
907],
908[enable_munmap="${default_munmap}"]
909)
910if test "x$enable_munmap" = "x1" ; then
911 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
912fi
913AC_SUBST([enable_munmap])
914
Jason Evans4d434ad2014-04-15 12:09:48 -0700915dnl Enable allocation from DSS if supported by the OS.
916have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200917dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
918AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
919if test "x$have_sbrk" = "x1" ; then
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -0700920 if test "x$sbrk_deprecated" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800921 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700922 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800923 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200924else
Jason Evans4d434ad2014-04-15 12:09:48 -0700925 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200926fi
927
Jason Evans4d434ad2014-04-15 12:09:48 -0700928if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700929 AC_DEFINE([JEMALLOC_DSS], [ ])
930fi
Jason Evansb7924f52009-06-23 19:01:18 -0700931
Jason Evans777c1912012-02-28 20:49:22 -0800932dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700933AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700934 [AS_HELP_STRING([--disable-fill],
935 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700936[if test "x$enable_fill" = "xno" ; then
937 enable_fill="0"
938else
939 enable_fill="1"
940fi
941],
Jason Evans777c1912012-02-28 20:49:22 -0800942[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700943)
944if test "x$enable_fill" = "x1" ; then
945 AC_DEFINE([JEMALLOC_FILL], [ ])
946fi
947AC_SUBST([enable_fill])
948
Jason Evansb1476112012-04-05 13:36:17 -0700949dnl Disable utrace(2)-based tracing by default.
950AC_ARG_ENABLE([utrace],
951 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
952[if test "x$enable_utrace" = "xno" ; then
953 enable_utrace="0"
954else
955 enable_utrace="1"
956fi
957],
958[enable_utrace="0"]
959)
960JE_COMPILABLE([utrace(2)], [
961#include <sys/types.h>
962#include <sys/param.h>
963#include <sys/time.h>
964#include <sys/uio.h>
965#include <sys/ktrace.h>
966], [
967 utrace((void *)0, 0);
968], [je_cv_utrace])
969if test "x${je_cv_utrace}" = "xno" ; then
970 enable_utrace="0"
971fi
972if test "x$enable_utrace" = "x1" ; then
973 AC_DEFINE([JEMALLOC_UTRACE], [ ])
974fi
975AC_SUBST([enable_utrace])
976
Jason Evans122449b2012-04-06 00:35:09 -0700977dnl Support Valgrind by default.
978AC_ARG_ENABLE([valgrind],
979 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
980[if test "x$enable_valgrind" = "xno" ; then
981 enable_valgrind="0"
982else
983 enable_valgrind="1"
984fi
985],
986[enable_valgrind="1"]
987)
988if test "x$enable_valgrind" = "x1" ; then
989 JE_COMPILABLE([valgrind], [
990#include <valgrind/valgrind.h>
991#include <valgrind/memcheck.h>
992
Mike Hommey7bfecf42012-04-30 15:15:15 +0200993#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -0700994# error "Incompatible Valgrind version"
995#endif
996], [], [je_cv_valgrind])
997 if test "x${je_cv_valgrind}" = "xno" ; then
998 enable_valgrind="0"
999 fi
1000 if test "x$enable_valgrind" = "x1" ; then
1001 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1002 fi
1003fi
1004AC_SUBST([enable_valgrind])
1005
Jason Evansb7924f52009-06-23 19:01:18 -07001006dnl Do not support the xmalloc option by default.
1007AC_ARG_ENABLE([xmalloc],
1008 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1009[if test "x$enable_xmalloc" = "xno" ; then
1010 enable_xmalloc="0"
1011else
1012 enable_xmalloc="1"
1013fi
1014],
1015[enable_xmalloc="0"]
1016)
1017if test "x$enable_xmalloc" = "x1" ; then
1018 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1019fi
1020AC_SUBST([enable_xmalloc])
1021
Jason Evans8a03cf02015-05-04 09:58:36 -07001022dnl Support cache-oblivious allocation alignment by default.
1023AC_ARG_ENABLE([cache-oblivious],
1024 [AS_HELP_STRING([--disable-cache-oblivious],
1025 [Disable support for cache-oblivious allocation alignment])],
1026[if test "x$enable_cache_oblivious" = "xno" ; then
1027 enable_cache_oblivious="0"
1028else
1029 enable_cache_oblivious="1"
1030fi
1031],
1032[enable_cache_oblivious="1"]
1033)
1034if test "x$enable_cache_oblivious" = "x1" ; then
1035 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1036fi
1037AC_SUBST([enable_cache_oblivious])
1038
Mike Hommey8f50ec82014-06-04 12:12:55 +09001039dnl ============================================================================
1040dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1041dnl One of those two functions should (theoretically) exist on all platforms
1042dnl that jemalloc currently has a chance of functioning on without modification.
1043dnl We additionally assume ffs() or __builtin_ffs() are defined if
1044dnl ffsl() or __builtin_ffsl() are defined, respectively.
1045JE_COMPILABLE([a program using __builtin_ffsl], [
1046#include <stdio.h>
1047#include <strings.h>
1048#include <string.h>
1049], [
1050 {
1051 int rv = __builtin_ffsl(0x08);
1052 printf("%d\n", rv);
1053 }
1054], [je_cv_gcc_builtin_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001055if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
Mike Hommey8f50ec82014-06-04 12:12:55 +09001056 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1057 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1058else
1059 JE_COMPILABLE([a program using ffsl], [
1060 #include <stdio.h>
1061 #include <strings.h>
1062 #include <string.h>
1063 ], [
1064 {
1065 int rv = ffsl(0x08);
1066 printf("%d\n", rv);
1067 }
1068 ], [je_cv_function_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001069 if test "x${je_cv_function_ffsl}" = "xyes" ; then
Mike Hommey8f50ec82014-06-04 12:12:55 +09001070 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1071 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1072 else
1073 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1074 fi
1075fi
1076
Jason Evans81e54752014-10-10 22:34:25 -07001077AC_ARG_WITH([lg_tiny_min],
1078 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1079 [Base 2 log of minimum tiny size class to support])],
1080 [LG_TINY_MIN="$with_lg_tiny_min"],
1081 [LG_TINY_MIN="3"])
1082AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1083
Jason Evansfc0b3b72014-10-09 17:54:06 -07001084AC_ARG_WITH([lg_quantum],
1085 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1086 [Base 2 log of minimum allocation alignment])],
Jason Evans81e54752014-10-10 22:34:25 -07001087 [LG_QUANTA="$with_lg_quantum"],
1088 [LG_QUANTA="3 4"])
1089if test "x$with_lg_quantum" != "x" ; then
1090 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1091fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001092
1093AC_ARG_WITH([lg_page],
1094 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1095 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
Jason Evansb0808d52015-02-03 12:39:31 -08001096if test "x$LG_PAGE" = "xdetect"; then
Jason Evansfc0b3b72014-10-09 17:54:06 -07001097 AC_CACHE_CHECK([LG_PAGE],
1098 [je_cv_lg_page],
Jason Evans6684cac2012-03-05 12:15:36 -08001099 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -07001100[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +02001101#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001102#ifdef _WIN32
1103#include <windows.h>
1104#else
Jason Evansb7924f52009-06-23 19:01:18 -07001105#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001106#endif
1107#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -08001108]],
1109[[
Garrett Cooper72c1e592012-12-02 17:57:28 -08001110 int result;
Jason Evansb7924f52009-06-23 19:01:18 -07001111 FILE *f;
1112
Mike Hommeya19e87f2012-04-21 21:27:46 -07001113#ifdef _WIN32
1114 SYSTEM_INFO si;
1115 GetSystemInfo(&si);
1116 result = si.dwPageSize;
1117#else
Jason Evansb7924f52009-06-23 19:01:18 -07001118 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001119#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001120 if (result == -1) {
1121 return 1;
1122 }
Mike Hommey8f50ec82014-06-04 12:12:55 +09001123 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
Mike Hommeya19e87f2012-04-21 21:27:46 -07001124
Jason Evansb7924f52009-06-23 19:01:18 -07001125 f = fopen("conftest.out", "w");
1126 if (f == NULL) {
1127 return 1;
1128 }
rustyxbc498632016-01-30 13:38:33 +01001129 fprintf(f, "%d", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001130 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001131
1132 return 0;
1133]])],
Jason Evansfc0b3b72014-10-09 17:54:06 -07001134 [je_cv_lg_page=`cat conftest.out`],
1135 [je_cv_lg_page=undefined],
1136 [je_cv_lg_page=12]))
Jason Evans6684cac2012-03-05 12:15:36 -08001137fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001138if test "x${je_cv_lg_page}" != "x" ; then
1139 LG_PAGE="${je_cv_lg_page}"
1140fi
1141if test "x${LG_PAGE}" != "xundefined" ; then
1142 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1143else
1144 AC_MSG_ERROR([cannot determine value for LG_PAGE])
1145fi
1146
1147AC_ARG_WITH([lg_page_sizes],
1148 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1149 [Base 2 logs of system page sizes to support])],
1150 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1151
1152AC_ARG_WITH([lg_size_class_group],
1153 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1154 [Base 2 log of size classes per doubling])],
1155 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1156 [LG_SIZE_CLASS_GROUP="2"])
Jason Evansb7924f52009-06-23 19:01:18 -07001157
1158dnl ============================================================================
1159dnl jemalloc configuration.
1160dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001161
Jason Evansa5a658a2014-09-02 15:07:07 -07001162dnl Set VERSION if source directory is inside a git repository.
Dan McGregorf8880312014-12-23 16:10:08 -06001163if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
Jason Evansa5a658a2014-09-02 15:07:07 -07001164 dnl Pattern globs aren't powerful enough to match both single- and
1165 dnl double-digit version numbers, so iterate over patterns to support up to
1166 dnl version 99.99.99 without any accidental matches.
Dan McGregorf8880312014-12-23 16:10:08 -06001167 rm -f "${objroot}VERSION"
Jason Evansa5a658a2014-09-02 15:07:07 -07001168 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1169 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1170 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1171 '[0-9][0-9].[0-9][0-9].[0-9]' \
1172 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
Dan McGregorf8880312014-12-23 16:10:08 -06001173 if test ! -e "${objroot}VERSION" ; then
1174 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
Jason Evansa5a658a2014-09-02 15:07:07 -07001175 if test $? -eq 0 ; then
Dan McGregorf8880312014-12-23 16:10:08 -06001176 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
Jason Evansa5a658a2014-09-02 15:07:07 -07001177 break
1178 fi
1179 fi
1180 done
Jason Evansa40bc7a2010-03-02 13:01:16 -08001181fi
Dan McGregorf8880312014-12-23 16:10:08 -06001182rm -f "${objroot}VERSION.tmp"
1183if test ! -e "${objroot}VERSION" ; then
1184 if test ! -e "${srcroot}VERSION" ; then
1185 AC_MSG_RESULT(
1186 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1187 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1188 else
1189 cp ${srcroot}VERSION ${objroot}VERSION
1190 fi
Jason Evansa5a658a2014-09-02 15:07:07 -07001191fi
Dan McGregorf8880312014-12-23 16:10:08 -06001192jemalloc_version=`cat "${objroot}VERSION"`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001193jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1194jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1195jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1196jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1197jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001198AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001199AC_SUBST([jemalloc_version_major])
1200AC_SUBST([jemalloc_version_minor])
1201AC_SUBST([jemalloc_version_bugfix])
1202AC_SUBST([jemalloc_version_nrev])
1203AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001204
1205dnl ============================================================================
1206dnl Configure pthreads.
1207
Mike Hommeya19e87f2012-04-21 21:27:46 -07001208if test "x$abi" != "xpecoff" ; then
1209 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1210 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1211 dnl first, but try libc too before failing.
1212 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1213 [AC_SEARCH_LIBS([pthread_create], , ,
1214 AC_MSG_ERROR([libpthread is missing]))])
1215fi
Jason Evansb7924f52009-06-23 19:01:18 -07001216
1217CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1218
Jason Evans345c1b02015-09-15 14:59:56 -07001219dnl Check whether clock_gettime(2) is in libc or librt. This function is only
1220dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
1221SAVED_LIBS="${LIBS}"
1222LIBS=
1223AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
1224AC_SUBST([TESTLIBS])
1225LIBS="${SAVED_LIBS}"
1226
Daniel Micayb74041f2014-12-09 17:41:34 -05001227dnl Check if the GNU-specific secure_getenv function exists.
1228AC_CHECK_FUNC([secure_getenv],
1229 [have_secure_getenv="1"],
1230 [have_secure_getenv="0"]
1231 )
1232if test "x$have_secure_getenv" = "x1" ; then
1233 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1234fi
1235
1236dnl Check if the Solaris/BSD issetugid function exists.
1237AC_CHECK_FUNC([issetugid],
1238 [have_issetugid="1"],
1239 [have_issetugid="0"]
1240 )
1241if test "x$have_issetugid" = "x1" ; then
1242 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1243fi
1244
Jason Evanscd9a1342012-03-21 18:33:03 -07001245dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1246dnl it rather than pthreads TSD cleanup functions to support cleanup during
1247dnl thread exit, in order to avoid pthreads library recursion during
1248dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001249AC_CHECK_FUNC([_malloc_thread_cleanup],
1250 [have__malloc_thread_cleanup="1"],
1251 [have__malloc_thread_cleanup="0"]
1252 )
1253if test "x$have__malloc_thread_cleanup" = "x1" ; then
1254 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1255 force_tls="1"
1256fi
1257
Jason Evans41b6afb2012-02-02 22:04:57 -08001258dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1259dnl so, mutex initialization causes allocation, and we need to implement this
1260dnl callback function in order to prevent recursive allocation.
1261AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1262 [have__pthread_mutex_init_calloc_cb="1"],
1263 [have__pthread_mutex_init_calloc_cb="0"]
1264 )
1265if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1266 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1267fi
1268
Jason Evans0fee70d2012-02-13 12:36:11 -08001269dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001270AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001271 [AS_HELP_STRING([--enable-lazy-lock],
1272 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001273[if test "x$enable_lazy_lock" = "xno" ; then
1274 enable_lazy_lock="0"
1275else
1276 enable_lazy_lock="1"
1277fi
1278],
Mike Hommeyac5db022015-08-11 14:01:59 +09001279[enable_lazy_lock=""]
Jason Evansb7924f52009-06-23 19:01:18 -07001280)
Mike Hommeyac5db022015-08-11 14:01:59 +09001281if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
Jason Evansfd4fcef2012-03-23 17:40:58 -07001282 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1283 enable_lazy_lock="1"
1284fi
Jason Evansb7924f52009-06-23 19:01:18 -07001285if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001286 if test "x$abi" != "xpecoff" ; then
1287 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1288 AC_CHECK_FUNC([dlsym], [],
1289 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1290 [AC_MSG_ERROR([libdl is missing])])
1291 ])
1292 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001293 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
Mike Hommeyac5db022015-08-11 14:01:59 +09001294else
1295 enable_lazy_lock="0"
Jason Evansb7924f52009-06-23 19:01:18 -07001296fi
1297AC_SUBST([enable_lazy_lock])
1298
Jason Evans78d815c2010-01-17 14:06:20 -08001299AC_ARG_ENABLE([tls],
1300 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1301if test "x$enable_tls" = "xno" ; then
1302 enable_tls="0"
1303else
1304 enable_tls="1"
1305fi
1306,
Mike Hommeyac5db022015-08-11 14:01:59 +09001307enable_tls=""
Jason Evans78d815c2010-01-17 14:06:20 -08001308)
Jason Evansc0f43b62015-09-02 12:46:35 -07001309if test "x${enable_tls}" = "x" ; then
1310 if test "x${force_tls}" = "x1" ; then
1311 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1312 enable_tls="1"
1313 elif test "x${force_tls}" = "x0" ; then
1314 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1315 enable_tls="0"
1316 else
1317 enable_tls="1"
1318 fi
Jason Evansb80581d2012-03-23 16:17:43 -07001319fi
Jason Evans78d815c2010-01-17 14:06:20 -08001320if test "x${enable_tls}" = "x1" ; then
1321AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001322AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001323[[
1324 __thread int x;
1325]], [[
1326 x = 42;
1327
1328 return 0;
1329]])],
1330 AC_MSG_RESULT([yes]),
1331 AC_MSG_RESULT([no])
1332 enable_tls="0")
Mike Hommeyac5db022015-08-11 14:01:59 +09001333else
1334 enable_tls="0"
Jason Evans78d815c2010-01-17 14:06:20 -08001335fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001336AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001337if test "x${enable_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001338 if test "x${force_tls}" = "x0" ; then
1339 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1340 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001341 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001342elif test "x${force_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001343 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
Jason Evans78d815c2010-01-17 14:06:20 -08001344fi
1345
Jason Evans2dbecf12010-09-05 10:35:13 -07001346dnl ============================================================================
Chih-hung Hsieh59cd80e2014-12-05 17:42:41 -08001347dnl Check for C11 atomics.
1348
1349JE_COMPILABLE([C11 atomics], [
1350#include <stdint.h>
1351#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1352#include <stdatomic.h>
1353#else
1354#error Atomics not available
1355#endif
1356], [
1357 uint64_t *p = (uint64_t *)0;
1358 uint64_t x = 1;
1359 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1360 uint64_t r = atomic_fetch_add(a, x) + x;
1361 return (r == 0);
1362], [je_cv_c11atomics])
1363if test "x${je_cv_c11atomics}" = "xyes" ; then
1364 AC_DEFINE([JEMALLOC_C11ATOMICS])
1365fi
1366
1367dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001368dnl Check for atomic(9) operations as provided on FreeBSD.
1369
1370JE_COMPILABLE([atomic(9)], [
1371#include <sys/types.h>
1372#include <machine/atomic.h>
1373#include <inttypes.h>
1374], [
1375 {
1376 uint32_t x32 = 0;
1377 volatile uint32_t *x32p = &x32;
1378 atomic_fetchadd_32(x32p, 1);
1379 }
1380 {
1381 unsigned long xlong = 0;
1382 volatile unsigned long *xlongp = &xlong;
1383 atomic_fetchadd_long(xlongp, 1);
1384 }
1385], [je_cv_atomic9])
1386if test "x${je_cv_atomic9}" = "xyes" ; then
1387 AC_DEFINE([JEMALLOC_ATOMIC9])
1388fi
1389
1390dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001391dnl Check for atomic(3) operations as provided on Darwin.
1392
1393JE_COMPILABLE([Darwin OSAtomic*()], [
1394#include <libkern/OSAtomic.h>
1395#include <inttypes.h>
1396], [
1397 {
1398 int32_t x32 = 0;
1399 volatile int32_t *x32p = &x32;
1400 OSAtomicAdd32(1, x32p);
1401 }
1402 {
1403 int64_t x64 = 0;
1404 volatile int64_t *x64p = &x64;
1405 OSAtomicAdd64(1, x64p);
1406 }
Jason Evans6684cac2012-03-05 12:15:36 -08001407], [je_cv_osatomic])
1408if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001409 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001410fi
1411
1412dnl ============================================================================
Richard Diamond994fad92014-06-03 02:39:18 -05001413dnl Check for madvise(2).
1414
1415JE_COMPILABLE([madvise(2)], [
1416#include <sys/mman.h>
1417], [
1418 {
1419 madvise((void *)0, 0, 0);
1420 }
1421], [je_cv_madvise])
1422if test "x${je_cv_madvise}" = "xyes" ; then
1423 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1424fi
1425
1426dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001427dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1428dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1429
1430AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1431 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1432 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001433 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1434 #include <stdint.h>
1435 ],
1436 [
1437 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1438 {
1439 uint$1_t x$1 = 0;
1440 __sync_add_and_fetch(&x$1, 42);
1441 __sync_sub_and_fetch(&x$1, 1);
1442 }
1443 #else
1444 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1445 #endif
1446 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001447 [je_cv_sync_compare_and_swap_$2=yes],
1448 [je_cv_sync_compare_and_swap_$2=no])])
1449
1450 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1451 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1452 fi
1453])
1454
Jason Evansb57d3ec2012-04-17 13:17:54 -07001455if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001456 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1457 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1458fi
1459
1460dnl ============================================================================
Jason Evansd04047c2014-05-28 16:11:55 -07001461dnl Check for __builtin_clz() and __builtin_clzl().
1462
1463AC_CACHE_CHECK([for __builtin_clz],
1464 [je_cv_builtin_clz],
1465 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1466 [
1467 {
1468 unsigned x = 0;
1469 int y = __builtin_clz(x);
1470 }
1471 {
1472 unsigned long x = 0;
1473 int y = __builtin_clzl(x);
1474 }
1475 ])],
1476 [je_cv_builtin_clz=yes],
1477 [je_cv_builtin_clz=no])])
1478
1479if test "x${je_cv_builtin_clz}" = "xyes" ; then
1480 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1481fi
1482
1483dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001484dnl Check for spinlock(3) operations as provided on Darwin.
1485
1486JE_COMPILABLE([Darwin OSSpin*()], [
1487#include <libkern/OSAtomic.h>
1488#include <inttypes.h>
1489], [
1490 OSSpinLock lock = 0;
1491 OSSpinLockLock(&lock);
1492 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001493], [je_cv_osspin])
1494if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001495 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001496fi
1497
1498dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001499dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001500
Mike Hommeyd0357f72012-11-26 18:52:41 +01001501AC_ARG_ENABLE([zone-allocator],
1502 [AS_HELP_STRING([--disable-zone-allocator],
1503 [Disable zone allocator for Darwin])],
1504[if test "x$enable_zone_allocator" = "xno" ; then
1505 enable_zone_allocator="0"
1506else
1507 enable_zone_allocator="1"
1508fi
1509],
1510[if test "x${abi}" = "xmacho"; then
1511 enable_zone_allocator="1"
1512fi
1513]
1514)
1515AC_SUBST([enable_zone_allocator])
1516
1517if test "x${enable_zone_allocator}" = "x1" ; then
1518 if test "x${abi}" != "xmacho"; then
1519 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1520 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001521 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001522
Jason Evans2dbecf12010-09-05 10:35:13 -07001523 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1524 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1525 dnl 10.6, which is the only source-level indication of the change.
1526 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001527 AC_DEFUN([JE_ZONE_PROGRAM],
1528 [AC_LANG_PROGRAM(
1529 [#include <malloc/malloc.h>],
Guilherme Goncalves79725aa2014-10-20 14:08:37 -02001530 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
Mike Hommey154829d2012-03-20 18:01:38 +01001531 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001532
Mike Hommey154829d2012-03-20 18:01:38 +01001533 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1534 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1535 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1536 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1537 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1538 )])],[
1539 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1540 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1541 )])])])])
1542 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1543 AC_MSG_RESULT([unsupported])
1544 AC_MSG_ERROR([Unsupported malloc zone version])
1545 fi
1546 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1547 JEMALLOC_ZONE_VERSION=8
1548 AC_MSG_RESULT([> 8])
1549 else
1550 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1551 fi
1552 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001553fi
1554
Jason Evansb7924f52009-06-23 19:01:18 -07001555dnl ============================================================================
Sara Golemon3e24afa2014-08-18 13:06:39 -07001556dnl Check for glibc malloc hooks
1557
1558JE_COMPILABLE([glibc malloc hook], [
1559#include <stddef.h>
1560
1561extern void (* __free_hook)(void *ptr);
1562extern void *(* __malloc_hook)(size_t size);
1563extern void *(* __realloc_hook)(void *ptr, size_t size);
1564], [
1565 void *ptr = 0L;
1566 if (__malloc_hook) ptr = __malloc_hook(1);
1567 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1568 if (__free_hook && ptr) __free_hook(ptr);
1569], [je_cv_glibc_malloc_hook])
1570if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1571 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1572fi
1573
1574JE_COMPILABLE([glibc memalign hook], [
1575#include <stddef.h>
1576
1577extern void *(* __memalign_hook)(size_t alignment, size_t size);
1578], [
1579 void *ptr = 0L;
1580 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1581], [je_cv_glibc_memalign_hook])
1582if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1583 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1584fi
1585
Eric Wong4dcf04b2014-08-31 03:57:06 +00001586JE_COMPILABLE([pthreads adaptive mutexes], [
1587#include <pthread.h>
1588], [
1589 pthread_mutexattr_t attr;
1590 pthread_mutexattr_init(&attr);
1591 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1592 pthread_mutexattr_destroy(&attr);
1593], [je_cv_pthread_mutex_adaptive_np])
1594if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1595 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1596fi
1597
Sara Golemon3e24afa2014-08-18 13:06:39 -07001598dnl ============================================================================
Jason Evansb7924f52009-06-23 19:01:18 -07001599dnl Check for typedefs, structures, and compiler characteristics.
1600AC_HEADER_STDBOOL
1601
Jason Evans748dfac2013-12-06 18:27:33 -08001602dnl ============================================================================
1603dnl Define commands that generate output files.
1604
Jason Evans86abd0d2013-11-30 15:25:42 -08001605AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1606 mkdir -p "${objroot}include/jemalloc/internal"
1607 "${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 -08001608], [
1609 srcdir="${srcdir}"
1610 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001611])
1612AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1613 mkdir -p "${objroot}include/jemalloc/internal"
1614 "${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 -08001615], [
1616 srcdir="${srcdir}"
1617 objroot="${objroot}"
1618])
1619AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1620 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1621 mkdir -p "${objroot}include/jemalloc/internal"
1622 cp /dev/null "${f}"
1623 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1624 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1625 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1626 echo "${n}:${m}" >> "${f}"
1627 dnl Remove name from public_syms so that it isn't redefined later.
1628 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1629 done
1630 for sym in ${public_syms} ; do
1631 n="${sym}"
1632 m="${JEMALLOC_PREFIX}${sym}"
1633 echo "${n}:${m}" >> "${f}"
1634 done
1635], [
1636 srcdir="${srcdir}"
1637 objroot="${objroot}"
1638 mangling_map="${mangling_map}"
1639 public_syms="${public_syms}"
1640 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001641])
1642AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1643 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001644 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1645], [
1646 srcdir="${srcdir}"
1647 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001648])
1649AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1650 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001651 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1652], [
1653 srcdir="${srcdir}"
1654 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001655])
Jason Evansb1726102012-02-28 16:50:47 -08001656AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001657 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evans6d919292015-09-15 10:42:36 -07001658 "${SHELL}" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" ${LG_TINY_MIN} "${LG_PAGE_SIZES}" ${LG_SIZE_CLASS_GROUP} > "${objroot}include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001659], [
Jason Evans6d919292015-09-15 10:42:36 -07001660 SHELL="${SHELL}"
Jason Evansf234dc52014-01-16 17:38:01 -08001661 srcdir="${srcdir}"
1662 objroot="${objroot}"
Jason Evans81e54752014-10-10 22:34:25 -07001663 LG_QUANTA="${LG_QUANTA}"
1664 LG_TINY_MIN=${LG_TINY_MIN}
1665 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
Jason Evansfc0b3b72014-10-09 17:54:06 -07001666 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
Jason Evansb1726102012-02-28 16:50:47 -08001667])
Jason Evans86abd0d2013-11-30 15:25:42 -08001668AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1669 mkdir -p "${objroot}include/jemalloc"
1670 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 -08001671], [
1672 srcdir="${srcdir}"
1673 objroot="${objroot}"
1674])
1675AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1676 mkdir -p "${objroot}include/jemalloc"
1677 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1678], [
1679 srcdir="${srcdir}"
1680 objroot="${objroot}"
1681])
1682AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1683 mkdir -p "${objroot}include/jemalloc"
1684 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1685], [
1686 srcdir="${srcdir}"
1687 objroot="${objroot}"
1688])
1689AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1690 mkdir -p "${objroot}include/jemalloc"
1691 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1692], [
1693 srcdir="${srcdir}"
1694 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001695])
1696AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1697 mkdir -p "${objroot}include/jemalloc"
1698 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001699], [
1700 srcdir="${srcdir}"
1701 objroot="${objroot}"
1702 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001703])
Jason Evansb1726102012-02-28 16:50:47 -08001704
Jason Evansb7924f52009-06-23 19:01:18 -07001705dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001706AC_SUBST([cfghdrs_in])
1707AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001708AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001709
1710dnl ============================================================================
1711dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001712
Jason Evans70417202015-05-01 12:31:12 -07001713AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
Jason Evansb0fd5012010-01-17 01:49:20 -08001714AC_SUBST([cfgoutputs_in])
1715AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001716AC_OUTPUT
1717
1718dnl ============================================================================
1719dnl Print out the results of configuration.
1720AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001721AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1722AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001723AC_MSG_RESULT([])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001724AC_MSG_RESULT([CONFIG : ${CONFIG}])
Jason Evansb7924f52009-06-23 19:01:18 -07001725AC_MSG_RESULT([CC : ${CC}])
Jason Evansb7924f52009-06-23 19:01:18 -07001726AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001727AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001728AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001729AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001730AC_MSG_RESULT([LIBS : ${LIBS}])
Jason Evans345c1b02015-09-15 14:59:56 -07001731AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001732AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1733AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001734AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1735AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1736AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001737AC_MSG_RESULT([PREFIX : ${PREFIX}])
1738AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001739AC_MSG_RESULT([DATADIR : ${DATADIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001740AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1741AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001742AC_MSG_RESULT([MANDIR : ${MANDIR}])
1743AC_MSG_RESULT([])
1744AC_MSG_RESULT([srcroot : ${srcroot}])
1745AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1746AC_MSG_RESULT([objroot : ${objroot}])
1747AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1748AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001749AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001750AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1751AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001752AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansf8290092016-02-07 14:23:22 -08001753AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
Jason Evansb7924f52009-06-23 19:01:18 -07001754AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001755AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001756AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001757AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001758AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001759AC_MSG_RESULT([prof : ${enable_prof}])
1760AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001761AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1762AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001763AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001764AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001765AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001766AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1767AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001768AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001769AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001770AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evans8a03cf02015-05-04 09:58:36 -07001771AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
Jason Evansb7924f52009-06-23 19:01:18 -07001772AC_MSG_RESULT([===============================================================================])