blob: da4ee3ac2d5b8548aac9fc3bf402b98868349788 [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 Evansecae1232016-02-20 23:41:33 -0800204AC_CHECK_SIZEOF([long long])
205if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
206 LG_SIZEOF_LONG_LONG=3
207elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
208 LG_SIZEOF_LONG_LONG=2
209else
210 AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
211fi
212AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
213
Jason Evansd81e4bd2012-03-06 14:57:45 -0800214AC_CHECK_SIZEOF([intmax_t])
215if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
216 LG_SIZEOF_INTMAX_T=4
217elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
218 LG_SIZEOF_INTMAX_T=3
219elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
220 LG_SIZEOF_INTMAX_T=2
221else
Mike Hommey14103d32012-04-20 08:38:39 +0200222 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800223fi
224AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
225
Jason Evansb7924f52009-06-23 19:01:18 -0700226AC_CANONICAL_HOST
227dnl CPU-specific settings.
228CPU_SPINWAIT=""
229case "${host_cpu}" in
Jason Evanscb657e32014-02-25 11:21:41 -0800230 i686|x86_64)
rustyx90c72692016-01-30 13:41:09 +0100231 if test "x${je_cv_msvc}" = "xyes" ; then
232 AC_CACHE_VAL([je_cv_pause_msvc],
233 [JE_COMPILABLE([pause instruction MSVC], [],
234 [[_mm_pause(); return 0;]],
235 [je_cv_pause_msvc])])
236 if test "x${je_cv_pause_msvc}" = "xyes" ; then
237 CPU_SPINWAIT='_mm_pause()'
238 fi
239 else
240 AC_CACHE_VAL([je_cv_pause],
241 [JE_COMPILABLE([pause instruction], [],
242 [[__asm__ volatile("pause"); return 0;]],
243 [je_cv_pause])])
244 if test "x${je_cv_pause}" = "xyes" ; then
245 CPU_SPINWAIT='__asm__ volatile("pause")'
246 fi
Jason Evansf3340ca2009-06-30 16:17:05 -0700247 fi
Jason Evans80061b62013-12-09 13:21:08 -0800248 ;;
249 powerpc)
250 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700251 ;;
252 *)
253 ;;
254esac
255AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
256
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400257LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700258so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200259importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200260o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200261a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200262exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700263libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200264DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
265RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200266SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200267PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200268CTARGET='-o $@'
269LDTARGET='-o $@'
270EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100271ARFLAGS='crus'
272AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200273CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800274
Jory A. Prattad505e02013-08-11 09:44:59 -0500275AN_MAKEVAR([AR], [AC_PROG_AR])
276AN_PROGRAM([ar], [AC_PROG_AR])
277AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
278AC_PROG_AR
279
Jason Evansb7924f52009-06-23 19:01:18 -0700280dnl Platform-specific settings. abi and RPATH can probably be determined
281dnl programmatically, but doing so is error-prone, which makes it generally
282dnl not worth the trouble.
283dnl
284dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
285dnl definitions need to be seen before any headers are included, which is a pain
286dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700287default_munmap="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700288maps_coalesce="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700289case "${host}" in
Valerii Hiora5921ba72014-05-16 16:28:20 +0300290 *-*-darwin* | *-*-ios*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200291 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700292 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700293 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700294 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400295 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700296 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200297 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700298 force_tls="0"
Jason Evansf1f2b452015-05-01 08:57:41 -0700299 DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200300 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800301 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700302 ;;
303 *-*-freebsd*)
304 CFLAGS="$CFLAGS"
305 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700306 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700307 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700308 ;;
Michael Neumann1aa25a32014-08-05 03:06:02 +0200309 *-*-dragonfly*)
310 CFLAGS="$CFLAGS"
311 abi="elf"
312 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
313 ;;
Sébastien Marieb80fbcb2015-04-07 12:21:19 +0200314 *-*-openbsd*)
315 CFLAGS="$CFLAGS"
316 abi="elf"
317 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
318 force_tls="0"
319 ;;
320 *-*-bitrig*)
Sébastien Marie77d597e2015-01-25 10:18:32 +0100321 CFLAGS="$CFLAGS"
322 abi="elf"
323 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
324 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700325 *-*-linux*)
326 CFLAGS="$CFLAGS"
327 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
328 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800329 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700330 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700331 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansae93d6b2015-07-10 14:33:00 -0700332 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700333 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700334 ;;
335 *-*-netbsd*)
336 AC_MSG_CHECKING([ABI])
337 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
338[[#ifdef __ELF__
339/* ELF */
340#else
341#error aout
342#endif
343]])],
344 [CFLAGS="$CFLAGS"; abi="elf"],
345 [abi="aout"])
346 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700347 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700348 ;;
349 *-*-solaris2*)
350 CFLAGS="$CFLAGS"
351 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000352 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200353 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700354 dnl Solaris needs this for sigwait().
355 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
356 LIBS="$LIBS -lposix4 -lsocket -lnsl"
357 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400358 *-ibm-aix*)
359 if "$LG_SIZEOF_PTR" = "8"; then
360 dnl 64bit AIX
361 LD_PRELOAD_VAR="LDR_PRELOAD64"
362 else
363 dnl 32bit AIX
364 LD_PRELOAD_VAR="LDR_PRELOAD"
365 fi
366 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400367 ;;
Dave Rigby70bdee02014-09-22 15:53:16 +0100368 *-*-mingw* | *-*-cygwin*)
Mike Hommeya19e87f2012-04-21 21:27:46 -0700369 abi="pecoff"
370 force_tls="0"
Jason Evans13473c72015-07-23 14:08:49 -0700371 force_lazy_lock="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700372 maps_coalesce="0"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700373 RPATH=""
374 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200375 if test "x$je_cv_msvc" = "xyes" ; then
376 importlib="lib"
377 DSO_LDFLAGS="-LD"
378 EXTRA_LDFLAGS="-link -DEBUG"
379 CTARGET='-Fo$@'
380 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500381 AR='lib'
382 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100383 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200384 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200385 else
386 importlib="${so}"
387 DSO_LDFLAGS="-shared"
388 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700389 a="lib"
390 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200391 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700392 PIC_CFLAGS=""
393 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700394 *)
395 AC_MSG_RESULT([Unsupported operating system: ${host}])
396 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700397 ;;
398esac
Mike Hommeyaffe0092014-05-28 08:10:12 +0900399
400JEMALLOC_USABLE_SIZE_CONST=const
401AC_CHECK_HEADERS([malloc.h], [
402 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
403 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
404 [#include <malloc.h>
405 #include <stddef.h>
406 size_t malloc_usable_size(const void *ptr);
407 ],
408 [])],[
409 AC_MSG_RESULT([yes])
410 ],[
411 JEMALLOC_USABLE_SIZE_CONST=
412 AC_MSG_RESULT([no])
413 ])
414])
Jason Evans247d1242012-10-09 16:20:10 -0700415AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700416AC_SUBST([abi])
417AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400418AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700419AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200420AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200421AC_SUBST([o])
422AC_SUBST([a])
423AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700424AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200425AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200426AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200427AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200428AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200429AC_SUBST([CTARGET])
430AC_SUBST([LDTARGET])
431AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100432AC_SUBST([ARFLAGS])
433AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200434AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200435
Jason Evansfa5d2452011-03-15 10:25:59 -0700436JE_COMPILABLE([__attribute__ syntax],
437 [static __attribute__((unused)) void foo(void){}],
438 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800439 [je_cv_attribute])
440if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700441 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
442 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
443 JE_CFLAGS_APPEND([-fvisibility=hidden])
444 fi
445fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700446dnl Check for tls_model attribute support (clang 3.0 still lacks support).
447SAVED_CFLAGS="${CFLAGS}"
448JE_CFLAGS_APPEND([-Werror])
449JE_COMPILABLE([tls_model attribute], [],
450 [static __thread int
Daniel Micayf1cf3ea2014-09-16 04:42:33 -0400451 __attribute__((tls_model("initial-exec"), unused)) foo;
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700452 foo = 0;],
453 [je_cv_tls_model])
454CFLAGS="${SAVED_CFLAGS}"
455if test "x${je_cv_tls_model}" = "xyes" ; then
456 AC_DEFINE([JEMALLOC_TLS_MODEL],
457 [__attribute__((tls_model("initial-exec")))])
458else
459 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
460fi
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700461dnl Check for alloc_size attribute support.
462SAVED_CFLAGS="${CFLAGS}"
463JE_CFLAGS_APPEND([-Werror])
Jason Evans92d72ee2015-07-10 16:45:32 -0700464JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
465 [void *foo(size_t size) __attribute__((alloc_size(1)));],
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700466 [je_cv_alloc_size])
467CFLAGS="${SAVED_CFLAGS}"
468if test "x${je_cv_alloc_size}" = "xyes" ; then
469 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
470fi
Jason Evanse42c3092015-07-22 15:44:47 -0700471dnl Check for format(gnu_printf, ...) attribute support.
472SAVED_CFLAGS="${CFLAGS}"
473JE_CFLAGS_APPEND([-Werror])
474JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
475 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
476 [je_cv_format_gnu_printf])
477CFLAGS="${SAVED_CFLAGS}"
478if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
479 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
480fi
481dnl Check for format(printf, ...) attribute support.
482SAVED_CFLAGS="${CFLAGS}"
483JE_CFLAGS_APPEND([-Werror])
484JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
485 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
486 [je_cv_format_printf])
487CFLAGS="${SAVED_CFLAGS}"
488if test "x${je_cv_format_printf}" = "xyes" ; then
489 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
490fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700491
Jason Evansb7924f52009-06-23 19:01:18 -0700492dnl Support optional additions to rpath.
493AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800494 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700495if test "x$with_rpath" = "xno" ; then
496 RPATH_EXTRA=
497else
498 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
499fi,
500 RPATH_EXTRA=
501)
502AC_SUBST([RPATH_EXTRA])
503
504dnl Disable rules that do automatic regeneration of configure output by default.
505AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800506 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700507if test "x$enable_autogen" = "xno" ; then
508 enable_autogen="0"
509else
510 enable_autogen="1"
511fi
512,
513enable_autogen="0"
514)
515AC_SUBST([enable_autogen])
516
517AC_PROG_INSTALL
518AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800519AC_PATH_PROG([LD], [ld], [false], [$PATH])
520AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700521
Daniel Micay4cfe5512014-08-28 15:41:48 -0400522public_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 -0800523
524dnl Check for allocator-related functions that should be wrapped.
525AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700526 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800527 public_syms="${public_syms} memalign"])
528AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700529 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800530 public_syms="${public_syms} valloc"])
531
Jason Evans748dfac2013-12-06 18:27:33 -0800532dnl Do not compute test code coverage by default.
533GCOV_FLAGS=
534AC_ARG_ENABLE([code-coverage],
535 [AS_HELP_STRING([--enable-code-coverage],
536 [Enable code coverage])],
537[if test "x$enable_code_coverage" = "xno" ; then
538 enable_code_coverage="0"
539else
540 enable_code_coverage="1"
541fi
542],
543[enable_code_coverage="0"]
544)
545if test "x$enable_code_coverage" = "x1" ; then
546 deoptimize="no"
547 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
548 if test "x${deoptimize}" = "xyes" ; then
549 JE_CFLAGS_APPEND([-O0])
550 fi
551 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
552 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
553 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
554fi
555AC_SUBST([enable_code_coverage])
556
Jason Evans0a5489e2012-03-01 17:19:20 -0800557dnl Perform no name mangling by default.
558AC_ARG_WITH([mangling],
559 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
560 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800561
Jason Evans90895cf2009-12-29 00:09:15 -0800562dnl Do not prefix public APIs by default.
563AC_ARG_WITH([jemalloc_prefix],
564 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800565 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200566 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700567 JEMALLOC_PREFIX=""
568else
569 JEMALLOC_PREFIX="je_"
570fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800571)
572if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700573 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
574 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
575 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800576fi
Jason Evans241abc62015-06-23 18:47:07 -0700577AC_SUBST([JEMALLOC_CPREFIX])
Jason Evans90895cf2009-12-29 00:09:15 -0800578
Mike Hommey99066602012-11-19 10:55:26 +0100579AC_ARG_WITH([export],
580 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
581 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800582 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100583fi]
584)
585
Jason Evans86abd0d2013-11-30 15:25:42 -0800586dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700587AC_ARG_WITH([private_namespace],
588 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800589 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
590 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700591)
Jason Evans86abd0d2013-11-30 15:25:42 -0800592AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
593private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
594AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700595
Jason Evansb0fd5012010-01-17 01:49:20 -0800596dnl Do not add suffix to installed files by default.
597AC_ARG_WITH([install_suffix],
598 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
599 [INSTALL_SUFFIX="$with_install_suffix"],
600 [INSTALL_SUFFIX=]
601)
602install_suffix="$INSTALL_SUFFIX"
603AC_SUBST([install_suffix])
604
Jason Evansf8290092016-02-07 14:23:22 -0800605dnl Specify default malloc_conf.
606AC_ARG_WITH([malloc_conf],
607 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
608 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
609 [JEMALLOC_CONFIG_MALLOC_CONF=""]
610)
611config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
612AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
613
Jason Evans86abd0d2013-11-30 15:25:42 -0800614dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
615dnl jemalloc_protos_jet.h easy.
616je_="je_"
617AC_SUBST([je_])
618
Mike Hommeycf6032d2014-07-30 18:16:13 +0900619cfgoutputs_in="Makefile.in"
Nick White913e9a82014-09-19 22:01:23 +0100620cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900621cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
622cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
623cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
624cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
625cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700626cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900627cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
628cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
629cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800630
Jason Evansaee7fd22010-11-24 22:00:02 -0800631cfgoutputs_out="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100632cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
Jason Evansaee7fd22010-11-24 22:00:02 -0800633cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
634cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800635cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
636cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
637cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans82e88d12014-09-07 19:55:03 -0700638cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
Jason Evans376b1522010-02-11 14:45:59 -0800639cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800640cfgoutputs_out="${cfgoutputs_out} test/test.sh"
641cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800642
Jason Evansaee7fd22010-11-24 22:00:02 -0800643cfgoutputs_tup="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100644cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
Jason Evansaee7fd22010-11-24 22:00:02 -0800645cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
646cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800647cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
648cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
649cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700650cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800651cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800652cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
653cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800654
Mike Hommeycf6032d2014-07-30 18:16:13 +0900655cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
656cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
657cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
658cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
659cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
660cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
661cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
662cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
663cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
664cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
665cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
666cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800667
Jason Evans86abd0d2013-11-30 15:25:42 -0800668cfghdrs_out="include/jemalloc/jemalloc_defs.h"
669cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800670cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
671cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800672cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800673cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
674cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800675cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800676cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
677cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
678cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
679cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
680cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800681cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800682
Jason Evans86abd0d2013-11-30 15:25:42 -0800683cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900684cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
685cfghdrs_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 -0800686
Jason Evans644d4142014-04-14 22:49:23 -0700687dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700688AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700689 [AS_HELP_STRING([--disable-cc-silence],
690 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700691[if test "x$enable_cc_silence" = "xno" ; then
692 enable_cc_silence="0"
693else
694 enable_cc_silence="1"
695fi
696],
Jason Evans644d4142014-04-14 22:49:23 -0700697[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700698)
699if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700700 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700701fi
702
Jason Evansb7924f52009-06-23 19:01:18 -0700703dnl Do not compile with debugging by default.
704AC_ARG_ENABLE([debug],
Jason Evanse0a08a12015-03-18 21:06:58 -0700705 [AS_HELP_STRING([--enable-debug],
706 [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700707[if test "x$enable_debug" = "xno" ; then
708 enable_debug="0"
709else
710 enable_debug="1"
711fi
712],
713[enable_debug="0"]
714)
Jason Evans02e5dcf2015-02-15 20:12:06 -0800715if test "x$enable_debug" = "x1" ; then
716 AC_DEFINE([JEMALLOC_DEBUG], [ ])
717fi
Jason Evanse0a08a12015-03-18 21:06:58 -0700718if test "x$enable_debug" = "x1" ; then
719 AC_DEFINE([JEMALLOC_DEBUG], [ ])
720 enable_ivsalloc="1"
721fi
Jason Evansb7924f52009-06-23 19:01:18 -0700722AC_SUBST([enable_debug])
723
Jason Evanse0a08a12015-03-18 21:06:58 -0700724dnl Do not validate pointers by default.
725AC_ARG_ENABLE([ivsalloc],
726 [AS_HELP_STRING([--enable-ivsalloc],
727 [Validate pointers passed through the public API])],
728[if test "x$enable_ivsalloc" = "xno" ; then
729 enable_ivsalloc="0"
730else
731 enable_ivsalloc="1"
732fi
733],
734[enable_ivsalloc="0"]
735)
736if test "x$enable_ivsalloc" = "x1" ; then
737 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
738fi
739
Jason Evansb7924f52009-06-23 19:01:18 -0700740dnl Only optimize if not debugging.
741if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
742 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700743 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800744 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700745 if test "x${optimize}" = "xyes" ; then
746 if test "x$GCC" = "xyes" ; then
747 JE_CFLAGS_APPEND([-O3])
748 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200749 elif test "x$je_cv_msvc" = "xyes" ; then
750 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700751 else
752 JE_CFLAGS_APPEND([-O])
753 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700754 fi
755fi
756
Jason Evansd073a322012-02-28 20:41:16 -0800757dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700758AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800759 [AS_HELP_STRING([--disable-stats],
760 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700761[if test "x$enable_stats" = "xno" ; then
762 enable_stats="0"
763else
764 enable_stats="1"
765fi
766],
Jason Evansd073a322012-02-28 20:41:16 -0800767[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700768)
769if test "x$enable_stats" = "x1" ; then
770 AC_DEFINE([JEMALLOC_STATS], [ ])
771fi
772AC_SUBST([enable_stats])
773
Jason Evans6109fe02010-02-10 10:37:56 -0800774dnl Do not enable profiling by default.
775AC_ARG_ENABLE([prof],
776 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
777[if test "x$enable_prof" = "xno" ; then
778 enable_prof="0"
779else
780 enable_prof="1"
781fi
782],
783[enable_prof="0"]
784)
Jason Evans77f350b2011-03-15 22:23:12 -0700785if test "x$enable_prof" = "x1" ; then
786 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800787else
Jason Evans77f350b2011-03-15 22:23:12 -0700788 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800789fi
Jason Evans77f350b2011-03-15 22:23:12 -0700790
Jason Evans6109fe02010-02-10 10:37:56 -0800791AC_ARG_ENABLE([prof-libunwind],
792 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
793[if test "x$enable_prof_libunwind" = "xno" ; then
794 enable_prof_libunwind="0"
795else
796 enable_prof_libunwind="1"
797fi
798],
799[enable_prof_libunwind="0"]
800)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800801AC_ARG_WITH([static_libunwind],
802 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
803 [Path to static libunwind library; use rather than dynamically linking])],
804if test "x$with_static_libunwind" = "xno" ; then
805 LUNWIND="-lunwind"
806else
807 if test ! -f "$with_static_libunwind" ; then
808 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
809 fi
810 LUNWIND="$with_static_libunwind"
811fi,
812 LUNWIND="-lunwind"
813)
Jason Evans77f350b2011-03-15 22:23:12 -0700814if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
815 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
816 if test "x$LUNWIND" = "x-lunwind" ; then
Jason Evans05125b82014-04-22 20:48:07 -0700817 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700818 [enable_prof_libunwind="0"])
819 else
820 LIBS="$LIBS $LUNWIND"
821 fi
822 if test "x${enable_prof_libunwind}" = "x1" ; then
823 backtrace_method="libunwind"
824 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
825 fi
826fi
827
828AC_ARG_ENABLE([prof-libgcc],
829 [AS_HELP_STRING([--disable-prof-libgcc],
830 [Do not use libgcc for backtracing])],
831[if test "x$enable_prof_libgcc" = "xno" ; then
832 enable_prof_libgcc="0"
833else
834 enable_prof_libgcc="1"
835fi
836],
837[enable_prof_libgcc="1"]
838)
839if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
840 -a "x$GCC" = "xyes" ; then
841 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
842 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
Jason Evans77f350b2011-03-15 22:23:12 -0700843 if test "x${enable_prof_libgcc}" = "x1" ; then
844 backtrace_method="libgcc"
845 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
846 fi
847else
848 enable_prof_libgcc="0"
849fi
850
851AC_ARG_ENABLE([prof-gcc],
852 [AS_HELP_STRING([--disable-prof-gcc],
853 [Do not use gcc intrinsics for backtracing])],
854[if test "x$enable_prof_gcc" = "xno" ; then
855 enable_prof_gcc="0"
856else
857 enable_prof_gcc="1"
858fi
859],
860[enable_prof_gcc="1"]
861)
862if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
863 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700864 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700865 backtrace_method="gcc intrinsics"
866 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
867else
868 enable_prof_gcc="0"
869fi
870
871if test "x$backtrace_method" = "x" ; then
872 backtrace_method="none (disabling profiling)"
873 enable_prof="0"
874fi
875AC_MSG_CHECKING([configured backtracing method])
876AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700877if test "x$enable_prof" = "x1" ; then
Jason Evansd37d5ad2013-12-05 23:01:50 -0800878 if test "x$abi" != "xpecoff"; then
879 dnl Heap profiling uses the log(3) function.
880 LIBS="$LIBS -lm"
881 fi
882
Jason Evans2dbecf12010-09-05 10:35:13 -0700883 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700884fi
885AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700886
Jason Evans84cbbcb2009-12-29 00:09:15 -0800887dnl Enable thread-specific caching by default.
888AC_ARG_ENABLE([tcache],
889 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
890[if test "x$enable_tcache" = "xno" ; then
891 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700892else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800893 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700894fi
895],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800896[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700897)
Jason Evans2dbecf12010-09-05 10:35:13 -0700898if test "x$enable_tcache" = "x1" ; then
899 AC_DEFINE([JEMALLOC_TCACHE], [ ])
900fi
901AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700902
Jason Evansd059b9d2015-07-24 18:21:42 -0700903dnl Indicate whether adjacent virtual memory mappings automatically coalesce
904dnl (and fragment on demand).
905if test "x${maps_coalesce}" = "x1" ; then
906 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
907fi
908
Jason Evans59ae2762012-04-16 17:52:27 -0700909dnl Enable VM deallocation via munmap() by default.
910AC_ARG_ENABLE([munmap],
911 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
912[if test "x$enable_munmap" = "xno" ; then
913 enable_munmap="0"
914else
915 enable_munmap="1"
916fi
917],
918[enable_munmap="${default_munmap}"]
919)
920if test "x$enable_munmap" = "x1" ; then
921 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
922fi
923AC_SUBST([enable_munmap])
924
Jason Evans4d434ad2014-04-15 12:09:48 -0700925dnl Enable allocation from DSS if supported by the OS.
926have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200927dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
928AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
929if test "x$have_sbrk" = "x1" ; then
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -0700930 if test "x$sbrk_deprecated" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800931 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700932 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800933 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200934else
Jason Evans4d434ad2014-04-15 12:09:48 -0700935 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200936fi
937
Jason Evans4d434ad2014-04-15 12:09:48 -0700938if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700939 AC_DEFINE([JEMALLOC_DSS], [ ])
940fi
Jason Evansb7924f52009-06-23 19:01:18 -0700941
Jason Evans777c1912012-02-28 20:49:22 -0800942dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700943AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700944 [AS_HELP_STRING([--disable-fill],
945 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700946[if test "x$enable_fill" = "xno" ; then
947 enable_fill="0"
948else
949 enable_fill="1"
950fi
951],
Jason Evans777c1912012-02-28 20:49:22 -0800952[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700953)
954if test "x$enable_fill" = "x1" ; then
955 AC_DEFINE([JEMALLOC_FILL], [ ])
956fi
957AC_SUBST([enable_fill])
958
Jason Evansb1476112012-04-05 13:36:17 -0700959dnl Disable utrace(2)-based tracing by default.
960AC_ARG_ENABLE([utrace],
961 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
962[if test "x$enable_utrace" = "xno" ; then
963 enable_utrace="0"
964else
965 enable_utrace="1"
966fi
967],
968[enable_utrace="0"]
969)
970JE_COMPILABLE([utrace(2)], [
971#include <sys/types.h>
972#include <sys/param.h>
973#include <sys/time.h>
974#include <sys/uio.h>
975#include <sys/ktrace.h>
976], [
977 utrace((void *)0, 0);
978], [je_cv_utrace])
979if test "x${je_cv_utrace}" = "xno" ; then
980 enable_utrace="0"
981fi
982if test "x$enable_utrace" = "x1" ; then
983 AC_DEFINE([JEMALLOC_UTRACE], [ ])
984fi
985AC_SUBST([enable_utrace])
986
Jason Evans122449b2012-04-06 00:35:09 -0700987dnl Support Valgrind by default.
988AC_ARG_ENABLE([valgrind],
989 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
990[if test "x$enable_valgrind" = "xno" ; then
991 enable_valgrind="0"
992else
993 enable_valgrind="1"
994fi
995],
996[enable_valgrind="1"]
997)
998if test "x$enable_valgrind" = "x1" ; then
999 JE_COMPILABLE([valgrind], [
1000#include <valgrind/valgrind.h>
1001#include <valgrind/memcheck.h>
1002
Mike Hommey7bfecf42012-04-30 15:15:15 +02001003#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -07001004# error "Incompatible Valgrind version"
1005#endif
1006], [], [je_cv_valgrind])
1007 if test "x${je_cv_valgrind}" = "xno" ; then
1008 enable_valgrind="0"
1009 fi
1010 if test "x$enable_valgrind" = "x1" ; then
1011 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1012 fi
1013fi
1014AC_SUBST([enable_valgrind])
1015
Jason Evansb7924f52009-06-23 19:01:18 -07001016dnl Do not support the xmalloc option by default.
1017AC_ARG_ENABLE([xmalloc],
1018 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1019[if test "x$enable_xmalloc" = "xno" ; then
1020 enable_xmalloc="0"
1021else
1022 enable_xmalloc="1"
1023fi
1024],
1025[enable_xmalloc="0"]
1026)
1027if test "x$enable_xmalloc" = "x1" ; then
1028 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1029fi
1030AC_SUBST([enable_xmalloc])
1031
Jason Evans8a03cf02015-05-04 09:58:36 -07001032dnl Support cache-oblivious allocation alignment by default.
1033AC_ARG_ENABLE([cache-oblivious],
1034 [AS_HELP_STRING([--disable-cache-oblivious],
1035 [Disable support for cache-oblivious allocation alignment])],
1036[if test "x$enable_cache_oblivious" = "xno" ; then
1037 enable_cache_oblivious="0"
1038else
1039 enable_cache_oblivious="1"
1040fi
1041],
1042[enable_cache_oblivious="1"]
1043)
1044if test "x$enable_cache_oblivious" = "x1" ; then
1045 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1046fi
1047AC_SUBST([enable_cache_oblivious])
1048
Mike Hommey8f50ec82014-06-04 12:12:55 +09001049dnl ============================================================================
1050dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1051dnl One of those two functions should (theoretically) exist on all platforms
1052dnl that jemalloc currently has a chance of functioning on without modification.
Jason Evansecae1232016-02-20 23:41:33 -08001053dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
Mike Hommey8f50ec82014-06-04 12:12:55 +09001054dnl ffsl() or __builtin_ffsl() are defined, respectively.
1055JE_COMPILABLE([a program using __builtin_ffsl], [
1056#include <stdio.h>
1057#include <strings.h>
1058#include <string.h>
1059], [
1060 {
1061 int rv = __builtin_ffsl(0x08);
1062 printf("%d\n", rv);
1063 }
1064], [je_cv_gcc_builtin_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001065if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
Jason Evansecae1232016-02-20 23:41:33 -08001066 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
Mike Hommey8f50ec82014-06-04 12:12:55 +09001067 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1068 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1069else
1070 JE_COMPILABLE([a program using ffsl], [
1071 #include <stdio.h>
1072 #include <strings.h>
1073 #include <string.h>
1074 ], [
1075 {
1076 int rv = ffsl(0x08);
1077 printf("%d\n", rv);
1078 }
1079 ], [je_cv_function_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001080 if test "x${je_cv_function_ffsl}" = "xyes" ; then
Jason Evansecae1232016-02-20 23:41:33 -08001081 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
Mike Hommey8f50ec82014-06-04 12:12:55 +09001082 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1083 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1084 else
1085 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1086 fi
1087fi
1088
Jason Evans81e54752014-10-10 22:34:25 -07001089AC_ARG_WITH([lg_tiny_min],
1090 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1091 [Base 2 log of minimum tiny size class to support])],
1092 [LG_TINY_MIN="$with_lg_tiny_min"],
1093 [LG_TINY_MIN="3"])
1094AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1095
Jason Evansfc0b3b72014-10-09 17:54:06 -07001096AC_ARG_WITH([lg_quantum],
1097 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1098 [Base 2 log of minimum allocation alignment])],
Jason Evans81e54752014-10-10 22:34:25 -07001099 [LG_QUANTA="$with_lg_quantum"],
1100 [LG_QUANTA="3 4"])
1101if test "x$with_lg_quantum" != "x" ; then
1102 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1103fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001104
1105AC_ARG_WITH([lg_page],
1106 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1107 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
Jason Evansb0808d52015-02-03 12:39:31 -08001108if test "x$LG_PAGE" = "xdetect"; then
Jason Evansfc0b3b72014-10-09 17:54:06 -07001109 AC_CACHE_CHECK([LG_PAGE],
1110 [je_cv_lg_page],
Jason Evans6684cac2012-03-05 12:15:36 -08001111 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -07001112[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +02001113#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001114#ifdef _WIN32
1115#include <windows.h>
1116#else
Jason Evansb7924f52009-06-23 19:01:18 -07001117#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001118#endif
1119#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -08001120]],
1121[[
Garrett Cooper72c1e592012-12-02 17:57:28 -08001122 int result;
Jason Evansb7924f52009-06-23 19:01:18 -07001123 FILE *f;
1124
Mike Hommeya19e87f2012-04-21 21:27:46 -07001125#ifdef _WIN32
1126 SYSTEM_INFO si;
1127 GetSystemInfo(&si);
1128 result = si.dwPageSize;
1129#else
Jason Evansb7924f52009-06-23 19:01:18 -07001130 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001131#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001132 if (result == -1) {
1133 return 1;
1134 }
Mike Hommey8f50ec82014-06-04 12:12:55 +09001135 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
Mike Hommeya19e87f2012-04-21 21:27:46 -07001136
Jason Evansb7924f52009-06-23 19:01:18 -07001137 f = fopen("conftest.out", "w");
1138 if (f == NULL) {
1139 return 1;
1140 }
rustyxbc498632016-01-30 13:38:33 +01001141 fprintf(f, "%d", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001142 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001143
1144 return 0;
1145]])],
Jason Evansfc0b3b72014-10-09 17:54:06 -07001146 [je_cv_lg_page=`cat conftest.out`],
1147 [je_cv_lg_page=undefined],
1148 [je_cv_lg_page=12]))
Jason Evans6684cac2012-03-05 12:15:36 -08001149fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001150if test "x${je_cv_lg_page}" != "x" ; then
1151 LG_PAGE="${je_cv_lg_page}"
1152fi
1153if test "x${LG_PAGE}" != "xundefined" ; then
1154 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1155else
1156 AC_MSG_ERROR([cannot determine value for LG_PAGE])
1157fi
1158
1159AC_ARG_WITH([lg_page_sizes],
1160 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1161 [Base 2 logs of system page sizes to support])],
1162 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1163
1164AC_ARG_WITH([lg_size_class_group],
1165 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1166 [Base 2 log of size classes per doubling])],
1167 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1168 [LG_SIZE_CLASS_GROUP="2"])
Jason Evansb7924f52009-06-23 19:01:18 -07001169
1170dnl ============================================================================
1171dnl jemalloc configuration.
1172dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001173
Jason Evansa5a658a2014-09-02 15:07:07 -07001174dnl Set VERSION if source directory is inside a git repository.
Dan McGregorf8880312014-12-23 16:10:08 -06001175if 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 -07001176 dnl Pattern globs aren't powerful enough to match both single- and
1177 dnl double-digit version numbers, so iterate over patterns to support up to
1178 dnl version 99.99.99 without any accidental matches.
Dan McGregorf8880312014-12-23 16:10:08 -06001179 rm -f "${objroot}VERSION"
Jason Evansa5a658a2014-09-02 15:07:07 -07001180 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1181 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1182 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1183 '[0-9][0-9].[0-9][0-9].[0-9]' \
1184 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
Dan McGregorf8880312014-12-23 16:10:08 -06001185 if test ! -e "${objroot}VERSION" ; then
1186 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
Jason Evansa5a658a2014-09-02 15:07:07 -07001187 if test $? -eq 0 ; then
Dan McGregorf8880312014-12-23 16:10:08 -06001188 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
Jason Evansa5a658a2014-09-02 15:07:07 -07001189 break
1190 fi
1191 fi
1192 done
Jason Evansa40bc7a2010-03-02 13:01:16 -08001193fi
Dan McGregorf8880312014-12-23 16:10:08 -06001194rm -f "${objroot}VERSION.tmp"
1195if test ! -e "${objroot}VERSION" ; then
1196 if test ! -e "${srcroot}VERSION" ; then
1197 AC_MSG_RESULT(
1198 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1199 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1200 else
1201 cp ${srcroot}VERSION ${objroot}VERSION
1202 fi
Jason Evansa5a658a2014-09-02 15:07:07 -07001203fi
Dan McGregorf8880312014-12-23 16:10:08 -06001204jemalloc_version=`cat "${objroot}VERSION"`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001205jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1206jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1207jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1208jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1209jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001210AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001211AC_SUBST([jemalloc_version_major])
1212AC_SUBST([jemalloc_version_minor])
1213AC_SUBST([jemalloc_version_bugfix])
1214AC_SUBST([jemalloc_version_nrev])
1215AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001216
1217dnl ============================================================================
1218dnl Configure pthreads.
1219
Mike Hommeya19e87f2012-04-21 21:27:46 -07001220if test "x$abi" != "xpecoff" ; then
1221 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1222 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1223 dnl first, but try libc too before failing.
1224 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1225 [AC_SEARCH_LIBS([pthread_create], , ,
1226 AC_MSG_ERROR([libpthread is missing]))])
1227fi
Jason Evansb7924f52009-06-23 19:01:18 -07001228
1229CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1230
Jason Evans345c1b02015-09-15 14:59:56 -07001231dnl Check whether clock_gettime(2) is in libc or librt. This function is only
1232dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
1233SAVED_LIBS="${LIBS}"
1234LIBS=
1235AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
1236AC_SUBST([TESTLIBS])
1237LIBS="${SAVED_LIBS}"
1238
Daniel Micayb74041f2014-12-09 17:41:34 -05001239dnl Check if the GNU-specific secure_getenv function exists.
1240AC_CHECK_FUNC([secure_getenv],
1241 [have_secure_getenv="1"],
1242 [have_secure_getenv="0"]
1243 )
1244if test "x$have_secure_getenv" = "x1" ; then
1245 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1246fi
1247
1248dnl Check if the Solaris/BSD issetugid function exists.
1249AC_CHECK_FUNC([issetugid],
1250 [have_issetugid="1"],
1251 [have_issetugid="0"]
1252 )
1253if test "x$have_issetugid" = "x1" ; then
1254 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1255fi
1256
Jason Evanscd9a1342012-03-21 18:33:03 -07001257dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1258dnl it rather than pthreads TSD cleanup functions to support cleanup during
1259dnl thread exit, in order to avoid pthreads library recursion during
1260dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001261AC_CHECK_FUNC([_malloc_thread_cleanup],
1262 [have__malloc_thread_cleanup="1"],
1263 [have__malloc_thread_cleanup="0"]
1264 )
1265if test "x$have__malloc_thread_cleanup" = "x1" ; then
1266 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1267 force_tls="1"
1268fi
1269
Jason Evans41b6afb2012-02-02 22:04:57 -08001270dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1271dnl so, mutex initialization causes allocation, and we need to implement this
1272dnl callback function in order to prevent recursive allocation.
1273AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1274 [have__pthread_mutex_init_calloc_cb="1"],
1275 [have__pthread_mutex_init_calloc_cb="0"]
1276 )
1277if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1278 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1279fi
1280
Jason Evans0fee70d2012-02-13 12:36:11 -08001281dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001282AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001283 [AS_HELP_STRING([--enable-lazy-lock],
1284 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001285[if test "x$enable_lazy_lock" = "xno" ; then
1286 enable_lazy_lock="0"
1287else
1288 enable_lazy_lock="1"
1289fi
1290],
Mike Hommeyac5db022015-08-11 14:01:59 +09001291[enable_lazy_lock=""]
Jason Evansb7924f52009-06-23 19:01:18 -07001292)
Mike Hommeyac5db022015-08-11 14:01:59 +09001293if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
Jason Evansfd4fcef2012-03-23 17:40:58 -07001294 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1295 enable_lazy_lock="1"
1296fi
Jason Evansb7924f52009-06-23 19:01:18 -07001297if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001298 if test "x$abi" != "xpecoff" ; then
1299 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1300 AC_CHECK_FUNC([dlsym], [],
1301 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1302 [AC_MSG_ERROR([libdl is missing])])
1303 ])
1304 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001305 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
Mike Hommeyac5db022015-08-11 14:01:59 +09001306else
1307 enable_lazy_lock="0"
Jason Evansb7924f52009-06-23 19:01:18 -07001308fi
1309AC_SUBST([enable_lazy_lock])
1310
Jason Evans78d815c2010-01-17 14:06:20 -08001311AC_ARG_ENABLE([tls],
1312 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1313if test "x$enable_tls" = "xno" ; then
1314 enable_tls="0"
1315else
1316 enable_tls="1"
1317fi
1318,
Mike Hommeyac5db022015-08-11 14:01:59 +09001319enable_tls=""
Jason Evans78d815c2010-01-17 14:06:20 -08001320)
Jason Evansc0f43b62015-09-02 12:46:35 -07001321if test "x${enable_tls}" = "x" ; then
1322 if test "x${force_tls}" = "x1" ; then
1323 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1324 enable_tls="1"
1325 elif test "x${force_tls}" = "x0" ; then
1326 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1327 enable_tls="0"
1328 else
1329 enable_tls="1"
1330 fi
Jason Evansb80581d2012-03-23 16:17:43 -07001331fi
Jason Evans78d815c2010-01-17 14:06:20 -08001332if test "x${enable_tls}" = "x1" ; then
1333AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001334AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001335[[
1336 __thread int x;
1337]], [[
1338 x = 42;
1339
1340 return 0;
1341]])],
1342 AC_MSG_RESULT([yes]),
1343 AC_MSG_RESULT([no])
1344 enable_tls="0")
Mike Hommeyac5db022015-08-11 14:01:59 +09001345else
1346 enable_tls="0"
Jason Evans78d815c2010-01-17 14:06:20 -08001347fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001348AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001349if test "x${enable_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001350 if test "x${force_tls}" = "x0" ; then
1351 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1352 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001353 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001354elif test "x${force_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001355 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
Jason Evans78d815c2010-01-17 14:06:20 -08001356fi
1357
Jason Evans2dbecf12010-09-05 10:35:13 -07001358dnl ============================================================================
Chih-hung Hsieh59cd80e2014-12-05 17:42:41 -08001359dnl Check for C11 atomics.
1360
1361JE_COMPILABLE([C11 atomics], [
1362#include <stdint.h>
1363#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1364#include <stdatomic.h>
1365#else
1366#error Atomics not available
1367#endif
1368], [
1369 uint64_t *p = (uint64_t *)0;
1370 uint64_t x = 1;
1371 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1372 uint64_t r = atomic_fetch_add(a, x) + x;
1373 return (r == 0);
1374], [je_cv_c11atomics])
1375if test "x${je_cv_c11atomics}" = "xyes" ; then
1376 AC_DEFINE([JEMALLOC_C11ATOMICS])
1377fi
1378
1379dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001380dnl Check for atomic(9) operations as provided on FreeBSD.
1381
1382JE_COMPILABLE([atomic(9)], [
1383#include <sys/types.h>
1384#include <machine/atomic.h>
1385#include <inttypes.h>
1386], [
1387 {
1388 uint32_t x32 = 0;
1389 volatile uint32_t *x32p = &x32;
1390 atomic_fetchadd_32(x32p, 1);
1391 }
1392 {
1393 unsigned long xlong = 0;
1394 volatile unsigned long *xlongp = &xlong;
1395 atomic_fetchadd_long(xlongp, 1);
1396 }
1397], [je_cv_atomic9])
1398if test "x${je_cv_atomic9}" = "xyes" ; then
1399 AC_DEFINE([JEMALLOC_ATOMIC9])
1400fi
1401
1402dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001403dnl Check for atomic(3) operations as provided on Darwin.
1404
1405JE_COMPILABLE([Darwin OSAtomic*()], [
1406#include <libkern/OSAtomic.h>
1407#include <inttypes.h>
1408], [
1409 {
1410 int32_t x32 = 0;
1411 volatile int32_t *x32p = &x32;
1412 OSAtomicAdd32(1, x32p);
1413 }
1414 {
1415 int64_t x64 = 0;
1416 volatile int64_t *x64p = &x64;
1417 OSAtomicAdd64(1, x64p);
1418 }
Jason Evans6684cac2012-03-05 12:15:36 -08001419], [je_cv_osatomic])
1420if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001421 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001422fi
1423
1424dnl ============================================================================
Richard Diamond994fad92014-06-03 02:39:18 -05001425dnl Check for madvise(2).
1426
1427JE_COMPILABLE([madvise(2)], [
1428#include <sys/mman.h>
1429], [
1430 {
1431 madvise((void *)0, 0, 0);
1432 }
1433], [je_cv_madvise])
1434if test "x${je_cv_madvise}" = "xyes" ; then
1435 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1436fi
1437
1438dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001439dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1440dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1441
1442AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1443 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1444 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001445 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1446 #include <stdint.h>
1447 ],
1448 [
1449 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1450 {
1451 uint$1_t x$1 = 0;
1452 __sync_add_and_fetch(&x$1, 42);
1453 __sync_sub_and_fetch(&x$1, 1);
1454 }
1455 #else
1456 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1457 #endif
1458 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001459 [je_cv_sync_compare_and_swap_$2=yes],
1460 [je_cv_sync_compare_and_swap_$2=no])])
1461
1462 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1463 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1464 fi
1465])
1466
Jason Evansb57d3ec2012-04-17 13:17:54 -07001467if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001468 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1469 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1470fi
1471
1472dnl ============================================================================
Jason Evansd04047c2014-05-28 16:11:55 -07001473dnl Check for __builtin_clz() and __builtin_clzl().
1474
1475AC_CACHE_CHECK([for __builtin_clz],
1476 [je_cv_builtin_clz],
1477 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1478 [
1479 {
1480 unsigned x = 0;
1481 int y = __builtin_clz(x);
1482 }
1483 {
1484 unsigned long x = 0;
1485 int y = __builtin_clzl(x);
1486 }
1487 ])],
1488 [je_cv_builtin_clz=yes],
1489 [je_cv_builtin_clz=no])])
1490
1491if test "x${je_cv_builtin_clz}" = "xyes" ; then
1492 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1493fi
1494
1495dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001496dnl Check for spinlock(3) operations as provided on Darwin.
1497
1498JE_COMPILABLE([Darwin OSSpin*()], [
1499#include <libkern/OSAtomic.h>
1500#include <inttypes.h>
1501], [
1502 OSSpinLock lock = 0;
1503 OSSpinLockLock(&lock);
1504 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001505], [je_cv_osspin])
1506if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001507 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001508fi
1509
1510dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001511dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001512
Mike Hommeyd0357f72012-11-26 18:52:41 +01001513AC_ARG_ENABLE([zone-allocator],
1514 [AS_HELP_STRING([--disable-zone-allocator],
1515 [Disable zone allocator for Darwin])],
1516[if test "x$enable_zone_allocator" = "xno" ; then
1517 enable_zone_allocator="0"
1518else
1519 enable_zone_allocator="1"
1520fi
1521],
1522[if test "x${abi}" = "xmacho"; then
1523 enable_zone_allocator="1"
1524fi
1525]
1526)
1527AC_SUBST([enable_zone_allocator])
1528
1529if test "x${enable_zone_allocator}" = "x1" ; then
1530 if test "x${abi}" != "xmacho"; then
1531 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1532 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001533 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001534
Jason Evans2dbecf12010-09-05 10:35:13 -07001535 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1536 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1537 dnl 10.6, which is the only source-level indication of the change.
1538 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001539 AC_DEFUN([JE_ZONE_PROGRAM],
1540 [AC_LANG_PROGRAM(
1541 [#include <malloc/malloc.h>],
Guilherme Goncalves79725aa2014-10-20 14:08:37 -02001542 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
Mike Hommey154829d2012-03-20 18:01:38 +01001543 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001544
Mike Hommey154829d2012-03-20 18:01:38 +01001545 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1546 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1547 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1548 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1549 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1550 )])],[
1551 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1552 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1553 )])])])])
1554 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1555 AC_MSG_RESULT([unsupported])
1556 AC_MSG_ERROR([Unsupported malloc zone version])
1557 fi
1558 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1559 JEMALLOC_ZONE_VERSION=8
1560 AC_MSG_RESULT([> 8])
1561 else
1562 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1563 fi
1564 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001565fi
1566
Jason Evansb7924f52009-06-23 19:01:18 -07001567dnl ============================================================================
Sara Golemon3e24afa2014-08-18 13:06:39 -07001568dnl Check for glibc malloc hooks
1569
1570JE_COMPILABLE([glibc malloc hook], [
1571#include <stddef.h>
1572
1573extern void (* __free_hook)(void *ptr);
1574extern void *(* __malloc_hook)(size_t size);
1575extern void *(* __realloc_hook)(void *ptr, size_t size);
1576], [
1577 void *ptr = 0L;
1578 if (__malloc_hook) ptr = __malloc_hook(1);
1579 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1580 if (__free_hook && ptr) __free_hook(ptr);
1581], [je_cv_glibc_malloc_hook])
1582if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1583 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1584fi
1585
1586JE_COMPILABLE([glibc memalign hook], [
1587#include <stddef.h>
1588
1589extern void *(* __memalign_hook)(size_t alignment, size_t size);
1590], [
1591 void *ptr = 0L;
1592 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1593], [je_cv_glibc_memalign_hook])
1594if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1595 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1596fi
1597
Eric Wong4dcf04b2014-08-31 03:57:06 +00001598JE_COMPILABLE([pthreads adaptive mutexes], [
1599#include <pthread.h>
1600], [
1601 pthread_mutexattr_t attr;
1602 pthread_mutexattr_init(&attr);
1603 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1604 pthread_mutexattr_destroy(&attr);
1605], [je_cv_pthread_mutex_adaptive_np])
1606if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1607 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1608fi
1609
Sara Golemon3e24afa2014-08-18 13:06:39 -07001610dnl ============================================================================
Jason Evansb7924f52009-06-23 19:01:18 -07001611dnl Check for typedefs, structures, and compiler characteristics.
1612AC_HEADER_STDBOOL
1613
Jason Evans748dfac2013-12-06 18:27:33 -08001614dnl ============================================================================
1615dnl Define commands that generate output files.
1616
Jason Evans86abd0d2013-11-30 15:25:42 -08001617AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1618 mkdir -p "${objroot}include/jemalloc/internal"
1619 "${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 -08001620], [
1621 srcdir="${srcdir}"
1622 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001623])
1624AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1625 mkdir -p "${objroot}include/jemalloc/internal"
1626 "${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 -08001627], [
1628 srcdir="${srcdir}"
1629 objroot="${objroot}"
1630])
1631AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1632 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1633 mkdir -p "${objroot}include/jemalloc/internal"
1634 cp /dev/null "${f}"
1635 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1636 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1637 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1638 echo "${n}:${m}" >> "${f}"
1639 dnl Remove name from public_syms so that it isn't redefined later.
1640 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1641 done
1642 for sym in ${public_syms} ; do
1643 n="${sym}"
1644 m="${JEMALLOC_PREFIX}${sym}"
1645 echo "${n}:${m}" >> "${f}"
1646 done
1647], [
1648 srcdir="${srcdir}"
1649 objroot="${objroot}"
1650 mangling_map="${mangling_map}"
1651 public_syms="${public_syms}"
1652 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001653])
1654AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1655 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001656 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1657], [
1658 srcdir="${srcdir}"
1659 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001660])
1661AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1662 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001663 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1664], [
1665 srcdir="${srcdir}"
1666 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001667])
Jason Evansb1726102012-02-28 16:50:47 -08001668AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001669 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evans6d919292015-09-15 10:42:36 -07001670 "${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 -08001671], [
Jason Evans6d919292015-09-15 10:42:36 -07001672 SHELL="${SHELL}"
Jason Evansf234dc52014-01-16 17:38:01 -08001673 srcdir="${srcdir}"
1674 objroot="${objroot}"
Jason Evans81e54752014-10-10 22:34:25 -07001675 LG_QUANTA="${LG_QUANTA}"
1676 LG_TINY_MIN=${LG_TINY_MIN}
1677 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
Jason Evansfc0b3b72014-10-09 17:54:06 -07001678 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
Jason Evansb1726102012-02-28 16:50:47 -08001679])
Jason Evans86abd0d2013-11-30 15:25:42 -08001680AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1681 mkdir -p "${objroot}include/jemalloc"
1682 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 -08001683], [
1684 srcdir="${srcdir}"
1685 objroot="${objroot}"
1686])
1687AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1688 mkdir -p "${objroot}include/jemalloc"
1689 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1690], [
1691 srcdir="${srcdir}"
1692 objroot="${objroot}"
1693])
1694AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1695 mkdir -p "${objroot}include/jemalloc"
1696 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1697], [
1698 srcdir="${srcdir}"
1699 objroot="${objroot}"
1700])
1701AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1702 mkdir -p "${objroot}include/jemalloc"
1703 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1704], [
1705 srcdir="${srcdir}"
1706 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001707])
1708AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1709 mkdir -p "${objroot}include/jemalloc"
1710 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001711], [
1712 srcdir="${srcdir}"
1713 objroot="${objroot}"
1714 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001715])
Jason Evansb1726102012-02-28 16:50:47 -08001716
Jason Evansb7924f52009-06-23 19:01:18 -07001717dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001718AC_SUBST([cfghdrs_in])
1719AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001720AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001721
1722dnl ============================================================================
1723dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001724
Jason Evans70417202015-05-01 12:31:12 -07001725AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
Jason Evansb0fd5012010-01-17 01:49:20 -08001726AC_SUBST([cfgoutputs_in])
1727AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001728AC_OUTPUT
1729
1730dnl ============================================================================
1731dnl Print out the results of configuration.
1732AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001733AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1734AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001735AC_MSG_RESULT([])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001736AC_MSG_RESULT([CONFIG : ${CONFIG}])
Jason Evansb7924f52009-06-23 19:01:18 -07001737AC_MSG_RESULT([CC : ${CC}])
Jason Evansb7924f52009-06-23 19:01:18 -07001738AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001739AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001740AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001741AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001742AC_MSG_RESULT([LIBS : ${LIBS}])
Jason Evans345c1b02015-09-15 14:59:56 -07001743AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001744AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1745AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001746AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1747AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1748AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001749AC_MSG_RESULT([PREFIX : ${PREFIX}])
1750AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001751AC_MSG_RESULT([DATADIR : ${DATADIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001752AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1753AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001754AC_MSG_RESULT([MANDIR : ${MANDIR}])
1755AC_MSG_RESULT([])
1756AC_MSG_RESULT([srcroot : ${srcroot}])
1757AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1758AC_MSG_RESULT([objroot : ${objroot}])
1759AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1760AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001761AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001762AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1763AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001764AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansf8290092016-02-07 14:23:22 -08001765AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
Jason Evansb7924f52009-06-23 19:01:18 -07001766AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001767AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001768AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001769AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001770AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001771AC_MSG_RESULT([prof : ${enable_prof}])
1772AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001773AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1774AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001775AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001776AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001777AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001778AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1779AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001780AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001781AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001782AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evans8a03cf02015-05-04 09:58:36 -07001783AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
Jason Evansb7924f52009-06-23 19:01:18 -07001784AC_MSG_RESULT([===============================================================================])