blob: 3082916b231c79abfe30dfeeb833143a577996ba [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 Evansb3d00702016-02-24 13:00:40 -0800143 JE_CFLAGS_APPEND([-Wshorten-64-to-32])
Jason Evanscfeccd32010-03-03 15:48:20 -0800144 JE_CFLAGS_APPEND([-pipe])
145 JE_CFLAGS_APPEND([-g3])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200146 elif test "x$je_cv_msvc" = "xyes" ; then
147 CC="$CC -nologo"
148 JE_CFLAGS_APPEND([-Zi])
149 JE_CFLAGS_APPEND([-MT])
150 JE_CFLAGS_APPEND([-W3])
Mike Hommey8c615752014-05-29 16:58:21 +0900151 JE_CFLAGS_APPEND([-FS])
Mike Hommey6f6704c2014-05-29 17:01:10 +0900152 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat"
Jason Evanscfeccd32010-03-03 15:48:20 -0800153 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700154fi
155dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
156if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700157 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700158fi
159AC_PROG_CPP
160
Jason Evansdf3f2702014-03-30 16:27:08 -0700161AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
162if test "x${ac_cv_big_endian}" = "x1" ; then
163 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
164fi
165
Mike Hommeyff2e9992014-05-29 16:33:02 +0900166if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
Mike Hommey6f6704c2014-05-29 17:01:10 +0900167 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
Mike Hommeyff2e9992014-05-29 16:33:02 +0900168fi
169
rustyx46e0b232016-01-30 13:37:26 +0100170if test "x${je_cv_msvc}" = "xyes" ; then
171 LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
172 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 -0700173else
rustyx46e0b232016-01-30 13:37:26 +0100174 AC_CHECK_SIZEOF([void *])
175 if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
176 LG_SIZEOF_PTR=3
177 elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
178 LG_SIZEOF_PTR=2
179 else
180 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
181 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700182fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800183AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
184
185AC_CHECK_SIZEOF([int])
186if test "x${ac_cv_sizeof_int}" = "x8" ; then
187 LG_SIZEOF_INT=3
188elif test "x${ac_cv_sizeof_int}" = "x4" ; then
189 LG_SIZEOF_INT=2
190else
191 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
192fi
193AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700194
Jason Evans84c8eef2011-03-16 10:30:13 -0700195AC_CHECK_SIZEOF([long])
196if test "x${ac_cv_sizeof_long}" = "x8" ; then
197 LG_SIZEOF_LONG=3
198elif test "x${ac_cv_sizeof_long}" = "x4" ; then
199 LG_SIZEOF_LONG=2
200else
201 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
202fi
203AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
204
Jason Evansecae1232016-02-20 23:41:33 -0800205AC_CHECK_SIZEOF([long long])
206if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
207 LG_SIZEOF_LONG_LONG=3
208elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
209 LG_SIZEOF_LONG_LONG=2
210else
211 AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
212fi
213AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
214
Jason Evansd81e4bd2012-03-06 14:57:45 -0800215AC_CHECK_SIZEOF([intmax_t])
216if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
217 LG_SIZEOF_INTMAX_T=4
218elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
219 LG_SIZEOF_INTMAX_T=3
220elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
221 LG_SIZEOF_INTMAX_T=2
222else
Mike Hommey14103d32012-04-20 08:38:39 +0200223 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800224fi
225AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
226
Jason Evansb7924f52009-06-23 19:01:18 -0700227AC_CANONICAL_HOST
228dnl CPU-specific settings.
229CPU_SPINWAIT=""
230case "${host_cpu}" in
Jason Evanscb657e32014-02-25 11:21:41 -0800231 i686|x86_64)
rustyx90c72692016-01-30 13:41:09 +0100232 if test "x${je_cv_msvc}" = "xyes" ; then
233 AC_CACHE_VAL([je_cv_pause_msvc],
234 [JE_COMPILABLE([pause instruction MSVC], [],
235 [[_mm_pause(); return 0;]],
236 [je_cv_pause_msvc])])
237 if test "x${je_cv_pause_msvc}" = "xyes" ; then
238 CPU_SPINWAIT='_mm_pause()'
239 fi
240 else
241 AC_CACHE_VAL([je_cv_pause],
242 [JE_COMPILABLE([pause instruction], [],
243 [[__asm__ volatile("pause"); return 0;]],
244 [je_cv_pause])])
245 if test "x${je_cv_pause}" = "xyes" ; then
246 CPU_SPINWAIT='__asm__ volatile("pause")'
247 fi
Jason Evansf3340ca2009-06-30 16:17:05 -0700248 fi
Jason Evans80061b62013-12-09 13:21:08 -0800249 ;;
250 powerpc)
251 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700252 ;;
253 *)
254 ;;
255esac
256AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
257
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400258LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700259so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200260importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200261o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200262a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200263exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700264libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200265DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
266RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200267SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200268PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200269CTARGET='-o $@'
270LDTARGET='-o $@'
271EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100272ARFLAGS='crus'
273AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200274CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800275
Jory A. Prattad505e02013-08-11 09:44:59 -0500276AN_MAKEVAR([AR], [AC_PROG_AR])
277AN_PROGRAM([ar], [AC_PROG_AR])
278AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
279AC_PROG_AR
280
Jason Evansb7924f52009-06-23 19:01:18 -0700281dnl Platform-specific settings. abi and RPATH can probably be determined
282dnl programmatically, but doing so is error-prone, which makes it generally
283dnl not worth the trouble.
284dnl
285dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
286dnl definitions need to be seen before any headers are included, which is a pain
287dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700288default_munmap="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700289maps_coalesce="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700290case "${host}" in
Valerii Hiora5921ba72014-05-16 16:28:20 +0300291 *-*-darwin* | *-*-ios*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200292 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700293 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700294 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700295 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400296 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700297 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200298 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700299 force_tls="0"
Jason Evansf1f2b452015-05-01 08:57:41 -0700300 DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200301 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800302 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700303 ;;
304 *-*-freebsd*)
305 CFLAGS="$CFLAGS"
306 abi="elf"
Jason Evanse24c7af2012-03-19 10:21:17 -0700307 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700308 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700309 ;;
Michael Neumann1aa25a32014-08-05 03:06:02 +0200310 *-*-dragonfly*)
311 CFLAGS="$CFLAGS"
312 abi="elf"
313 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
314 ;;
Sébastien Marieb80fbcb2015-04-07 12:21:19 +0200315 *-*-openbsd*)
316 CFLAGS="$CFLAGS"
317 abi="elf"
318 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
319 force_tls="0"
320 ;;
321 *-*-bitrig*)
Sébastien Marie77d597e2015-01-25 10:18:32 +0100322 CFLAGS="$CFLAGS"
323 abi="elf"
324 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
325 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700326 *-*-linux*)
327 CFLAGS="$CFLAGS"
328 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
329 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800330 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700331 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700332 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansae93d6b2015-07-10 14:33:00 -0700333 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700334 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700335 ;;
336 *-*-netbsd*)
337 AC_MSG_CHECKING([ABI])
338 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
339[[#ifdef __ELF__
340/* ELF */
341#else
342#error aout
343#endif
344]])],
345 [CFLAGS="$CFLAGS"; abi="elf"],
346 [abi="aout"])
347 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700348 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700349 ;;
350 *-*-solaris2*)
351 CFLAGS="$CFLAGS"
352 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000353 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200354 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700355 dnl Solaris needs this for sigwait().
356 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
357 LIBS="$LIBS -lposix4 -lsocket -lnsl"
358 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400359 *-ibm-aix*)
360 if "$LG_SIZEOF_PTR" = "8"; then
361 dnl 64bit AIX
362 LD_PRELOAD_VAR="LDR_PRELOAD64"
363 else
364 dnl 32bit AIX
365 LD_PRELOAD_VAR="LDR_PRELOAD"
366 fi
367 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400368 ;;
Dave Rigby70bdee02014-09-22 15:53:16 +0100369 *-*-mingw* | *-*-cygwin*)
Mike Hommeya19e87f2012-04-21 21:27:46 -0700370 abi="pecoff"
371 force_tls="0"
Jason Evans13473c72015-07-23 14:08:49 -0700372 force_lazy_lock="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700373 maps_coalesce="0"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700374 RPATH=""
375 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200376 if test "x$je_cv_msvc" = "xyes" ; then
377 importlib="lib"
378 DSO_LDFLAGS="-LD"
379 EXTRA_LDFLAGS="-link -DEBUG"
380 CTARGET='-Fo$@'
381 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500382 AR='lib'
383 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100384 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200385 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200386 else
387 importlib="${so}"
388 DSO_LDFLAGS="-shared"
389 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700390 a="lib"
391 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200392 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700393 PIC_CFLAGS=""
394 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700395 *)
396 AC_MSG_RESULT([Unsupported operating system: ${host}])
397 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700398 ;;
399esac
Mike Hommeyaffe0092014-05-28 08:10:12 +0900400
401JEMALLOC_USABLE_SIZE_CONST=const
402AC_CHECK_HEADERS([malloc.h], [
403 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
404 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
405 [#include <malloc.h>
406 #include <stddef.h>
407 size_t malloc_usable_size(const void *ptr);
408 ],
409 [])],[
410 AC_MSG_RESULT([yes])
411 ],[
412 JEMALLOC_USABLE_SIZE_CONST=
413 AC_MSG_RESULT([no])
414 ])
415])
Jason Evans247d1242012-10-09 16:20:10 -0700416AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700417AC_SUBST([abi])
418AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400419AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700420AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200421AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200422AC_SUBST([o])
423AC_SUBST([a])
424AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700425AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200426AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200427AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200428AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200429AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200430AC_SUBST([CTARGET])
431AC_SUBST([LDTARGET])
432AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100433AC_SUBST([ARFLAGS])
434AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200435AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200436
Jason Evansfa5d2452011-03-15 10:25:59 -0700437JE_COMPILABLE([__attribute__ syntax],
438 [static __attribute__((unused)) void foo(void){}],
439 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800440 [je_cv_attribute])
441if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700442 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
443 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
444 JE_CFLAGS_APPEND([-fvisibility=hidden])
445 fi
446fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700447dnl Check for tls_model attribute support (clang 3.0 still lacks support).
448SAVED_CFLAGS="${CFLAGS}"
449JE_CFLAGS_APPEND([-Werror])
450JE_COMPILABLE([tls_model attribute], [],
451 [static __thread int
Daniel Micayf1cf3ea2014-09-16 04:42:33 -0400452 __attribute__((tls_model("initial-exec"), unused)) foo;
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700453 foo = 0;],
454 [je_cv_tls_model])
455CFLAGS="${SAVED_CFLAGS}"
456if test "x${je_cv_tls_model}" = "xyes" ; then
457 AC_DEFINE([JEMALLOC_TLS_MODEL],
458 [__attribute__((tls_model("initial-exec")))])
459else
460 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
461fi
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700462dnl Check for alloc_size attribute support.
463SAVED_CFLAGS="${CFLAGS}"
464JE_CFLAGS_APPEND([-Werror])
Jason Evans92d72ee2015-07-10 16:45:32 -0700465JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
466 [void *foo(size_t size) __attribute__((alloc_size(1)));],
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700467 [je_cv_alloc_size])
468CFLAGS="${SAVED_CFLAGS}"
469if test "x${je_cv_alloc_size}" = "xyes" ; then
470 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
471fi
Jason Evanse42c3092015-07-22 15:44:47 -0700472dnl Check for format(gnu_printf, ...) attribute support.
473SAVED_CFLAGS="${CFLAGS}"
474JE_CFLAGS_APPEND([-Werror])
475JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
476 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
477 [je_cv_format_gnu_printf])
478CFLAGS="${SAVED_CFLAGS}"
479if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
480 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
481fi
482dnl Check for format(printf, ...) attribute support.
483SAVED_CFLAGS="${CFLAGS}"
484JE_CFLAGS_APPEND([-Werror])
485JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
486 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
487 [je_cv_format_printf])
488CFLAGS="${SAVED_CFLAGS}"
489if test "x${je_cv_format_printf}" = "xyes" ; then
490 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
491fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700492
Jason Evansb7924f52009-06-23 19:01:18 -0700493dnl Support optional additions to rpath.
494AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800495 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700496if test "x$with_rpath" = "xno" ; then
497 RPATH_EXTRA=
498else
499 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
500fi,
501 RPATH_EXTRA=
502)
503AC_SUBST([RPATH_EXTRA])
504
505dnl Disable rules that do automatic regeneration of configure output by default.
506AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800507 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700508if test "x$enable_autogen" = "xno" ; then
509 enable_autogen="0"
510else
511 enable_autogen="1"
512fi
513,
514enable_autogen="0"
515)
516AC_SUBST([enable_autogen])
517
518AC_PROG_INSTALL
519AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800520AC_PATH_PROG([LD], [ld], [false], [$PATH])
521AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700522
Daniel Micay4cfe5512014-08-28 15:41:48 -0400523public_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 -0800524
525dnl Check for allocator-related functions that should be wrapped.
526AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700527 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800528 public_syms="${public_syms} memalign"])
529AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700530 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800531 public_syms="${public_syms} valloc"])
532
Jason Evans748dfac2013-12-06 18:27:33 -0800533dnl Do not compute test code coverage by default.
534GCOV_FLAGS=
535AC_ARG_ENABLE([code-coverage],
536 [AS_HELP_STRING([--enable-code-coverage],
537 [Enable code coverage])],
538[if test "x$enable_code_coverage" = "xno" ; then
539 enable_code_coverage="0"
540else
541 enable_code_coverage="1"
542fi
543],
544[enable_code_coverage="0"]
545)
546if test "x$enable_code_coverage" = "x1" ; then
547 deoptimize="no"
548 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
549 if test "x${deoptimize}" = "xyes" ; then
550 JE_CFLAGS_APPEND([-O0])
551 fi
552 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
553 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
554 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
555fi
556AC_SUBST([enable_code_coverage])
557
Jason Evans0a5489e2012-03-01 17:19:20 -0800558dnl Perform no name mangling by default.
559AC_ARG_WITH([mangling],
560 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
561 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800562
Jason Evans90895cf2009-12-29 00:09:15 -0800563dnl Do not prefix public APIs by default.
564AC_ARG_WITH([jemalloc_prefix],
565 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800566 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200567 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700568 JEMALLOC_PREFIX=""
569else
570 JEMALLOC_PREFIX="je_"
571fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800572)
573if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700574 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
575 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
576 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800577fi
Jason Evans241abc62015-06-23 18:47:07 -0700578AC_SUBST([JEMALLOC_CPREFIX])
Jason Evans90895cf2009-12-29 00:09:15 -0800579
Mike Hommey99066602012-11-19 10:55:26 +0100580AC_ARG_WITH([export],
581 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
582 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800583 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100584fi]
585)
586
Jason Evans86abd0d2013-11-30 15:25:42 -0800587dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700588AC_ARG_WITH([private_namespace],
589 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800590 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
591 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700592)
Jason Evans86abd0d2013-11-30 15:25:42 -0800593AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
594private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
595AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700596
Jason Evansb0fd5012010-01-17 01:49:20 -0800597dnl Do not add suffix to installed files by default.
598AC_ARG_WITH([install_suffix],
599 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
600 [INSTALL_SUFFIX="$with_install_suffix"],
601 [INSTALL_SUFFIX=]
602)
603install_suffix="$INSTALL_SUFFIX"
604AC_SUBST([install_suffix])
605
Jason Evansf8290092016-02-07 14:23:22 -0800606dnl Specify default malloc_conf.
607AC_ARG_WITH([malloc_conf],
608 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
609 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
610 [JEMALLOC_CONFIG_MALLOC_CONF=""]
611)
612config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
613AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
614
Jason Evans86abd0d2013-11-30 15:25:42 -0800615dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
616dnl jemalloc_protos_jet.h easy.
617je_="je_"
618AC_SUBST([je_])
619
Mike Hommeycf6032d2014-07-30 18:16:13 +0900620cfgoutputs_in="Makefile.in"
Nick White913e9a82014-09-19 22:01:23 +0100621cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900622cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
623cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
624cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
625cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
626cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700627cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900628cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
629cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
630cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800631
Jason Evansaee7fd22010-11-24 22:00:02 -0800632cfgoutputs_out="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100633cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
Jason Evansaee7fd22010-11-24 22:00:02 -0800634cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
635cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800636cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
637cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
638cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans82e88d12014-09-07 19:55:03 -0700639cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
Jason Evans376b1522010-02-11 14:45:59 -0800640cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800641cfgoutputs_out="${cfgoutputs_out} test/test.sh"
642cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800643
Jason Evansaee7fd22010-11-24 22:00:02 -0800644cfgoutputs_tup="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100645cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
Jason Evansaee7fd22010-11-24 22:00:02 -0800646cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
647cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800648cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
649cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
650cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700651cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800652cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800653cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
654cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800655
Mike Hommeycf6032d2014-07-30 18:16:13 +0900656cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
657cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
658cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
659cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
660cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
661cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
662cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
663cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
664cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
665cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
666cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
667cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800668
Jason Evans86abd0d2013-11-30 15:25:42 -0800669cfghdrs_out="include/jemalloc/jemalloc_defs.h"
670cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800671cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
672cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800673cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800674cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
675cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800676cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800677cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
678cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
679cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
680cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
681cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800682cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800683
Jason Evans86abd0d2013-11-30 15:25:42 -0800684cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900685cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
686cfghdrs_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 -0800687
Jason Evans644d4142014-04-14 22:49:23 -0700688dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700689AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700690 [AS_HELP_STRING([--disable-cc-silence],
691 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700692[if test "x$enable_cc_silence" = "xno" ; then
693 enable_cc_silence="0"
694else
695 enable_cc_silence="1"
696fi
697],
Jason Evans644d4142014-04-14 22:49:23 -0700698[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700699)
700if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700701 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700702fi
703
Jason Evansb7924f52009-06-23 19:01:18 -0700704dnl Do not compile with debugging by default.
705AC_ARG_ENABLE([debug],
Jason Evanse0a08a12015-03-18 21:06:58 -0700706 [AS_HELP_STRING([--enable-debug],
707 [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700708[if test "x$enable_debug" = "xno" ; then
709 enable_debug="0"
710else
711 enable_debug="1"
712fi
713],
714[enable_debug="0"]
715)
Jason Evans02e5dcf2015-02-15 20:12:06 -0800716if test "x$enable_debug" = "x1" ; then
717 AC_DEFINE([JEMALLOC_DEBUG], [ ])
718fi
Jason Evanse0a08a12015-03-18 21:06:58 -0700719if test "x$enable_debug" = "x1" ; then
720 AC_DEFINE([JEMALLOC_DEBUG], [ ])
721 enable_ivsalloc="1"
722fi
Jason Evansb7924f52009-06-23 19:01:18 -0700723AC_SUBST([enable_debug])
724
Jason Evanse0a08a12015-03-18 21:06:58 -0700725dnl Do not validate pointers by default.
726AC_ARG_ENABLE([ivsalloc],
727 [AS_HELP_STRING([--enable-ivsalloc],
728 [Validate pointers passed through the public API])],
729[if test "x$enable_ivsalloc" = "xno" ; then
730 enable_ivsalloc="0"
731else
732 enable_ivsalloc="1"
733fi
734],
735[enable_ivsalloc="0"]
736)
737if test "x$enable_ivsalloc" = "x1" ; then
738 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
739fi
740
Jason Evansb7924f52009-06-23 19:01:18 -0700741dnl Only optimize if not debugging.
742if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
743 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700744 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800745 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700746 if test "x${optimize}" = "xyes" ; then
747 if test "x$GCC" = "xyes" ; then
748 JE_CFLAGS_APPEND([-O3])
749 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200750 elif test "x$je_cv_msvc" = "xyes" ; then
751 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700752 else
753 JE_CFLAGS_APPEND([-O])
754 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700755 fi
756fi
757
Jason Evansd073a322012-02-28 20:41:16 -0800758dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700759AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800760 [AS_HELP_STRING([--disable-stats],
761 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700762[if test "x$enable_stats" = "xno" ; then
763 enable_stats="0"
764else
765 enable_stats="1"
766fi
767],
Jason Evansd073a322012-02-28 20:41:16 -0800768[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700769)
770if test "x$enable_stats" = "x1" ; then
771 AC_DEFINE([JEMALLOC_STATS], [ ])
772fi
773AC_SUBST([enable_stats])
774
Jason Evans6109fe02010-02-10 10:37:56 -0800775dnl Do not enable profiling by default.
776AC_ARG_ENABLE([prof],
777 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
778[if test "x$enable_prof" = "xno" ; then
779 enable_prof="0"
780else
781 enable_prof="1"
782fi
783],
784[enable_prof="0"]
785)
Jason Evans77f350b2011-03-15 22:23:12 -0700786if test "x$enable_prof" = "x1" ; then
787 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800788else
Jason Evans77f350b2011-03-15 22:23:12 -0700789 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800790fi
Jason Evans77f350b2011-03-15 22:23:12 -0700791
Jason Evans6109fe02010-02-10 10:37:56 -0800792AC_ARG_ENABLE([prof-libunwind],
793 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
794[if test "x$enable_prof_libunwind" = "xno" ; then
795 enable_prof_libunwind="0"
796else
797 enable_prof_libunwind="1"
798fi
799],
800[enable_prof_libunwind="0"]
801)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800802AC_ARG_WITH([static_libunwind],
803 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
804 [Path to static libunwind library; use rather than dynamically linking])],
805if test "x$with_static_libunwind" = "xno" ; then
806 LUNWIND="-lunwind"
807else
808 if test ! -f "$with_static_libunwind" ; then
809 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
810 fi
811 LUNWIND="$with_static_libunwind"
812fi,
813 LUNWIND="-lunwind"
814)
Jason Evans77f350b2011-03-15 22:23:12 -0700815if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
816 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
817 if test "x$LUNWIND" = "x-lunwind" ; then
Jason Evans05125b82014-04-22 20:48:07 -0700818 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700819 [enable_prof_libunwind="0"])
820 else
821 LIBS="$LIBS $LUNWIND"
822 fi
823 if test "x${enable_prof_libunwind}" = "x1" ; then
824 backtrace_method="libunwind"
825 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
826 fi
827fi
828
829AC_ARG_ENABLE([prof-libgcc],
830 [AS_HELP_STRING([--disable-prof-libgcc],
831 [Do not use libgcc for backtracing])],
832[if test "x$enable_prof_libgcc" = "xno" ; then
833 enable_prof_libgcc="0"
834else
835 enable_prof_libgcc="1"
836fi
837],
838[enable_prof_libgcc="1"]
839)
840if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
841 -a "x$GCC" = "xyes" ; then
842 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
843 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
Jason Evans77f350b2011-03-15 22:23:12 -0700844 if test "x${enable_prof_libgcc}" = "x1" ; then
845 backtrace_method="libgcc"
846 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
847 fi
848else
849 enable_prof_libgcc="0"
850fi
851
852AC_ARG_ENABLE([prof-gcc],
853 [AS_HELP_STRING([--disable-prof-gcc],
854 [Do not use gcc intrinsics for backtracing])],
855[if test "x$enable_prof_gcc" = "xno" ; then
856 enable_prof_gcc="0"
857else
858 enable_prof_gcc="1"
859fi
860],
861[enable_prof_gcc="1"]
862)
863if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
864 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700865 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700866 backtrace_method="gcc intrinsics"
867 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
868else
869 enable_prof_gcc="0"
870fi
871
872if test "x$backtrace_method" = "x" ; then
873 backtrace_method="none (disabling profiling)"
874 enable_prof="0"
875fi
876AC_MSG_CHECKING([configured backtracing method])
877AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700878if test "x$enable_prof" = "x1" ; then
Jason Evansd37d5ad2013-12-05 23:01:50 -0800879 if test "x$abi" != "xpecoff"; then
880 dnl Heap profiling uses the log(3) function.
881 LIBS="$LIBS -lm"
882 fi
883
Jason Evans2dbecf12010-09-05 10:35:13 -0700884 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700885fi
886AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700887
Jason Evans84cbbcb2009-12-29 00:09:15 -0800888dnl Enable thread-specific caching by default.
889AC_ARG_ENABLE([tcache],
890 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
891[if test "x$enable_tcache" = "xno" ; then
892 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700893else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800894 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700895fi
896],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800897[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700898)
Jason Evans2dbecf12010-09-05 10:35:13 -0700899if test "x$enable_tcache" = "x1" ; then
900 AC_DEFINE([JEMALLOC_TCACHE], [ ])
901fi
902AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700903
Jason Evansd059b9d2015-07-24 18:21:42 -0700904dnl Indicate whether adjacent virtual memory mappings automatically coalesce
905dnl (and fragment on demand).
906if test "x${maps_coalesce}" = "x1" ; then
907 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
908fi
909
Jason Evans59ae2762012-04-16 17:52:27 -0700910dnl Enable VM deallocation via munmap() by default.
911AC_ARG_ENABLE([munmap],
912 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
913[if test "x$enable_munmap" = "xno" ; then
914 enable_munmap="0"
915else
916 enable_munmap="1"
917fi
918],
919[enable_munmap="${default_munmap}"]
920)
921if test "x$enable_munmap" = "x1" ; then
922 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
923fi
924AC_SUBST([enable_munmap])
925
Jason Evans4d434ad2014-04-15 12:09:48 -0700926dnl Enable allocation from DSS if supported by the OS.
927have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200928dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
929AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
930if test "x$have_sbrk" = "x1" ; then
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -0700931 if test "x$sbrk_deprecated" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800932 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700933 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800934 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200935else
Jason Evans4d434ad2014-04-15 12:09:48 -0700936 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200937fi
938
Jason Evans4d434ad2014-04-15 12:09:48 -0700939if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700940 AC_DEFINE([JEMALLOC_DSS], [ ])
941fi
Jason Evansb7924f52009-06-23 19:01:18 -0700942
Jason Evans777c1912012-02-28 20:49:22 -0800943dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700944AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700945 [AS_HELP_STRING([--disable-fill],
946 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700947[if test "x$enable_fill" = "xno" ; then
948 enable_fill="0"
949else
950 enable_fill="1"
951fi
952],
Jason Evans777c1912012-02-28 20:49:22 -0800953[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700954)
955if test "x$enable_fill" = "x1" ; then
956 AC_DEFINE([JEMALLOC_FILL], [ ])
957fi
958AC_SUBST([enable_fill])
959
Jason Evansb1476112012-04-05 13:36:17 -0700960dnl Disable utrace(2)-based tracing by default.
961AC_ARG_ENABLE([utrace],
962 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
963[if test "x$enable_utrace" = "xno" ; then
964 enable_utrace="0"
965else
966 enable_utrace="1"
967fi
968],
969[enable_utrace="0"]
970)
971JE_COMPILABLE([utrace(2)], [
972#include <sys/types.h>
973#include <sys/param.h>
974#include <sys/time.h>
975#include <sys/uio.h>
976#include <sys/ktrace.h>
977], [
978 utrace((void *)0, 0);
979], [je_cv_utrace])
980if test "x${je_cv_utrace}" = "xno" ; then
981 enable_utrace="0"
982fi
983if test "x$enable_utrace" = "x1" ; then
984 AC_DEFINE([JEMALLOC_UTRACE], [ ])
985fi
986AC_SUBST([enable_utrace])
987
Jason Evans122449b2012-04-06 00:35:09 -0700988dnl Support Valgrind by default.
989AC_ARG_ENABLE([valgrind],
990 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
991[if test "x$enable_valgrind" = "xno" ; then
992 enable_valgrind="0"
993else
994 enable_valgrind="1"
995fi
996],
997[enable_valgrind="1"]
998)
999if test "x$enable_valgrind" = "x1" ; then
1000 JE_COMPILABLE([valgrind], [
1001#include <valgrind/valgrind.h>
1002#include <valgrind/memcheck.h>
1003
Mike Hommey7bfecf42012-04-30 15:15:15 +02001004#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -07001005# error "Incompatible Valgrind version"
1006#endif
1007], [], [je_cv_valgrind])
1008 if test "x${je_cv_valgrind}" = "xno" ; then
1009 enable_valgrind="0"
1010 fi
1011 if test "x$enable_valgrind" = "x1" ; then
1012 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1013 fi
1014fi
1015AC_SUBST([enable_valgrind])
1016
Jason Evansb7924f52009-06-23 19:01:18 -07001017dnl Do not support the xmalloc option by default.
1018AC_ARG_ENABLE([xmalloc],
1019 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1020[if test "x$enable_xmalloc" = "xno" ; then
1021 enable_xmalloc="0"
1022else
1023 enable_xmalloc="1"
1024fi
1025],
1026[enable_xmalloc="0"]
1027)
1028if test "x$enable_xmalloc" = "x1" ; then
1029 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1030fi
1031AC_SUBST([enable_xmalloc])
1032
Jason Evans8a03cf02015-05-04 09:58:36 -07001033dnl Support cache-oblivious allocation alignment by default.
1034AC_ARG_ENABLE([cache-oblivious],
1035 [AS_HELP_STRING([--disable-cache-oblivious],
1036 [Disable support for cache-oblivious allocation alignment])],
1037[if test "x$enable_cache_oblivious" = "xno" ; then
1038 enable_cache_oblivious="0"
1039else
1040 enable_cache_oblivious="1"
1041fi
1042],
1043[enable_cache_oblivious="1"]
1044)
1045if test "x$enable_cache_oblivious" = "x1" ; then
1046 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1047fi
1048AC_SUBST([enable_cache_oblivious])
1049
Mike Hommey8f50ec82014-06-04 12:12:55 +09001050dnl ============================================================================
1051dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1052dnl One of those two functions should (theoretically) exist on all platforms
1053dnl that jemalloc currently has a chance of functioning on without modification.
Jason Evansecae1232016-02-20 23:41:33 -08001054dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
Mike Hommey8f50ec82014-06-04 12:12:55 +09001055dnl ffsl() or __builtin_ffsl() are defined, respectively.
1056JE_COMPILABLE([a program using __builtin_ffsl], [
1057#include <stdio.h>
1058#include <strings.h>
1059#include <string.h>
1060], [
1061 {
1062 int rv = __builtin_ffsl(0x08);
1063 printf("%d\n", rv);
1064 }
1065], [je_cv_gcc_builtin_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001066if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
Jason Evansecae1232016-02-20 23:41:33 -08001067 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
Mike Hommey8f50ec82014-06-04 12:12:55 +09001068 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1069 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1070else
1071 JE_COMPILABLE([a program using ffsl], [
1072 #include <stdio.h>
1073 #include <strings.h>
1074 #include <string.h>
1075 ], [
1076 {
1077 int rv = ffsl(0x08);
1078 printf("%d\n", rv);
1079 }
1080 ], [je_cv_function_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001081 if test "x${je_cv_function_ffsl}" = "xyes" ; then
Jason Evansecae1232016-02-20 23:41:33 -08001082 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
Mike Hommey8f50ec82014-06-04 12:12:55 +09001083 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1084 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1085 else
1086 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1087 fi
1088fi
1089
Jason Evans81e54752014-10-10 22:34:25 -07001090AC_ARG_WITH([lg_tiny_min],
1091 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1092 [Base 2 log of minimum tiny size class to support])],
1093 [LG_TINY_MIN="$with_lg_tiny_min"],
1094 [LG_TINY_MIN="3"])
1095AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1096
Jason Evansfc0b3b72014-10-09 17:54:06 -07001097AC_ARG_WITH([lg_quantum],
1098 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1099 [Base 2 log of minimum allocation alignment])],
Jason Evans81e54752014-10-10 22:34:25 -07001100 [LG_QUANTA="$with_lg_quantum"],
1101 [LG_QUANTA="3 4"])
1102if test "x$with_lg_quantum" != "x" ; then
1103 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1104fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001105
1106AC_ARG_WITH([lg_page],
1107 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1108 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
Jason Evansb0808d52015-02-03 12:39:31 -08001109if test "x$LG_PAGE" = "xdetect"; then
Jason Evansfc0b3b72014-10-09 17:54:06 -07001110 AC_CACHE_CHECK([LG_PAGE],
1111 [je_cv_lg_page],
Jason Evans6684cac2012-03-05 12:15:36 -08001112 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -07001113[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +02001114#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001115#ifdef _WIN32
1116#include <windows.h>
1117#else
Jason Evansb7924f52009-06-23 19:01:18 -07001118#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001119#endif
1120#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -08001121]],
1122[[
Garrett Cooper72c1e592012-12-02 17:57:28 -08001123 int result;
Jason Evansb7924f52009-06-23 19:01:18 -07001124 FILE *f;
1125
Mike Hommeya19e87f2012-04-21 21:27:46 -07001126#ifdef _WIN32
1127 SYSTEM_INFO si;
1128 GetSystemInfo(&si);
1129 result = si.dwPageSize;
1130#else
Jason Evansb7924f52009-06-23 19:01:18 -07001131 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001132#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001133 if (result == -1) {
1134 return 1;
1135 }
Mike Hommey8f50ec82014-06-04 12:12:55 +09001136 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
Mike Hommeya19e87f2012-04-21 21:27:46 -07001137
Jason Evansb7924f52009-06-23 19:01:18 -07001138 f = fopen("conftest.out", "w");
1139 if (f == NULL) {
1140 return 1;
1141 }
rustyxbc498632016-01-30 13:38:33 +01001142 fprintf(f, "%d", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001143 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001144
1145 return 0;
1146]])],
Jason Evansfc0b3b72014-10-09 17:54:06 -07001147 [je_cv_lg_page=`cat conftest.out`],
1148 [je_cv_lg_page=undefined],
1149 [je_cv_lg_page=12]))
Jason Evans6684cac2012-03-05 12:15:36 -08001150fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001151if test "x${je_cv_lg_page}" != "x" ; then
1152 LG_PAGE="${je_cv_lg_page}"
1153fi
1154if test "x${LG_PAGE}" != "xundefined" ; then
1155 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1156else
1157 AC_MSG_ERROR([cannot determine value for LG_PAGE])
1158fi
1159
1160AC_ARG_WITH([lg_page_sizes],
1161 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1162 [Base 2 logs of system page sizes to support])],
1163 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1164
1165AC_ARG_WITH([lg_size_class_group],
1166 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1167 [Base 2 log of size classes per doubling])],
1168 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1169 [LG_SIZE_CLASS_GROUP="2"])
Jason Evansb7924f52009-06-23 19:01:18 -07001170
1171dnl ============================================================================
1172dnl jemalloc configuration.
1173dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001174
Jason Evans434ea642016-03-14 20:19:11 -07001175AC_ARG_WITH([version],
1176 [AS_HELP_STRING([--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid>],
1177 [Version string])],
1178 [
1179 echo "${with_version}" | grep ['^[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+-g[0-9a-f]\+$'] 2>&1 1>/dev/null
1180 if test $? -ne 0 ; then
1181 AC_MSG_ERROR([${with_version} does not match <major>.<minor>.<bugfix>-<nrev>-g<gid>])
Jason Evansa5a658a2014-09-02 15:07:07 -07001182 fi
Jason Evans434ea642016-03-14 20:19:11 -07001183 echo "$with_version" > "${objroot}VERSION"
1184 ], [
1185 dnl Set VERSION if source directory is inside a git repository.
1186 if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
1187 dnl Pattern globs aren't powerful enough to match both single- and
1188 dnl double-digit version numbers, so iterate over patterns to support up
1189 dnl to version 99.99.99 without any accidental matches.
1190 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1191 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1192 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1193 '[0-9][0-9].[0-9][0-9].[0-9]' \
1194 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
1195 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
1196 if test $? -eq 0 ; then
1197 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
1198 break
1199 fi
1200 done
1201 fi
1202 rm -f "${objroot}VERSION.tmp"
1203 ])
1204
Dan McGregorf8880312014-12-23 16:10:08 -06001205if test ! -e "${objroot}VERSION" ; then
1206 if test ! -e "${srcroot}VERSION" ; then
1207 AC_MSG_RESULT(
1208 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1209 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1210 else
1211 cp ${srcroot}VERSION ${objroot}VERSION
1212 fi
Jason Evansa5a658a2014-09-02 15:07:07 -07001213fi
Dan McGregorf8880312014-12-23 16:10:08 -06001214jemalloc_version=`cat "${objroot}VERSION"`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001215jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1216jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1217jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1218jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1219jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001220AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001221AC_SUBST([jemalloc_version_major])
1222AC_SUBST([jemalloc_version_minor])
1223AC_SUBST([jemalloc_version_bugfix])
1224AC_SUBST([jemalloc_version_nrev])
1225AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001226
1227dnl ============================================================================
1228dnl Configure pthreads.
1229
Mike Hommeya19e87f2012-04-21 21:27:46 -07001230if test "x$abi" != "xpecoff" ; then
1231 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1232 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1233 dnl first, but try libc too before failing.
1234 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1235 [AC_SEARCH_LIBS([pthread_create], , ,
1236 AC_MSG_ERROR([libpthread is missing]))])
1237fi
Jason Evansb7924f52009-06-23 19:01:18 -07001238
1239CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1240
Jason Evans345c1b02015-09-15 14:59:56 -07001241dnl Check whether clock_gettime(2) is in libc or librt. This function is only
1242dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
1243SAVED_LIBS="${LIBS}"
1244LIBS=
1245AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
1246AC_SUBST([TESTLIBS])
1247LIBS="${SAVED_LIBS}"
1248
Daniel Micayb74041f2014-12-09 17:41:34 -05001249dnl Check if the GNU-specific secure_getenv function exists.
1250AC_CHECK_FUNC([secure_getenv],
1251 [have_secure_getenv="1"],
1252 [have_secure_getenv="0"]
1253 )
1254if test "x$have_secure_getenv" = "x1" ; then
1255 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1256fi
1257
1258dnl Check if the Solaris/BSD issetugid function exists.
1259AC_CHECK_FUNC([issetugid],
1260 [have_issetugid="1"],
1261 [have_issetugid="0"]
1262 )
1263if test "x$have_issetugid" = "x1" ; then
1264 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1265fi
1266
Jason Evanscd9a1342012-03-21 18:33:03 -07001267dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1268dnl it rather than pthreads TSD cleanup functions to support cleanup during
1269dnl thread exit, in order to avoid pthreads library recursion during
1270dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001271AC_CHECK_FUNC([_malloc_thread_cleanup],
1272 [have__malloc_thread_cleanup="1"],
1273 [have__malloc_thread_cleanup="0"]
1274 )
1275if test "x$have__malloc_thread_cleanup" = "x1" ; then
1276 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1277 force_tls="1"
1278fi
1279
Jason Evans41b6afb2012-02-02 22:04:57 -08001280dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1281dnl so, mutex initialization causes allocation, and we need to implement this
1282dnl callback function in order to prevent recursive allocation.
1283AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1284 [have__pthread_mutex_init_calloc_cb="1"],
1285 [have__pthread_mutex_init_calloc_cb="0"]
1286 )
1287if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1288 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1289fi
1290
Jason Evans0fee70d2012-02-13 12:36:11 -08001291dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001292AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001293 [AS_HELP_STRING([--enable-lazy-lock],
1294 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001295[if test "x$enable_lazy_lock" = "xno" ; then
1296 enable_lazy_lock="0"
1297else
1298 enable_lazy_lock="1"
1299fi
1300],
Mike Hommeyac5db022015-08-11 14:01:59 +09001301[enable_lazy_lock=""]
Jason Evansb7924f52009-06-23 19:01:18 -07001302)
Mike Hommeyac5db022015-08-11 14:01:59 +09001303if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
Jason Evansfd4fcef2012-03-23 17:40:58 -07001304 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1305 enable_lazy_lock="1"
1306fi
Jason Evansb7924f52009-06-23 19:01:18 -07001307if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001308 if test "x$abi" != "xpecoff" ; then
1309 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1310 AC_CHECK_FUNC([dlsym], [],
1311 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1312 [AC_MSG_ERROR([libdl is missing])])
1313 ])
1314 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001315 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
Mike Hommeyac5db022015-08-11 14:01:59 +09001316else
1317 enable_lazy_lock="0"
Jason Evansb7924f52009-06-23 19:01:18 -07001318fi
1319AC_SUBST([enable_lazy_lock])
1320
Jason Evans78d815c2010-01-17 14:06:20 -08001321AC_ARG_ENABLE([tls],
1322 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1323if test "x$enable_tls" = "xno" ; then
1324 enable_tls="0"
1325else
1326 enable_tls="1"
1327fi
1328,
Mike Hommeyac5db022015-08-11 14:01:59 +09001329enable_tls=""
Jason Evans78d815c2010-01-17 14:06:20 -08001330)
Jason Evansc0f43b62015-09-02 12:46:35 -07001331if test "x${enable_tls}" = "x" ; then
1332 if test "x${force_tls}" = "x1" ; then
1333 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1334 enable_tls="1"
1335 elif test "x${force_tls}" = "x0" ; then
1336 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1337 enable_tls="0"
1338 else
1339 enable_tls="1"
1340 fi
Jason Evansb80581d2012-03-23 16:17:43 -07001341fi
Jason Evans78d815c2010-01-17 14:06:20 -08001342if test "x${enable_tls}" = "x1" ; then
1343AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001344AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001345[[
1346 __thread int x;
1347]], [[
1348 x = 42;
1349
1350 return 0;
1351]])],
1352 AC_MSG_RESULT([yes]),
1353 AC_MSG_RESULT([no])
1354 enable_tls="0")
Mike Hommeyac5db022015-08-11 14:01:59 +09001355else
1356 enable_tls="0"
Jason Evans78d815c2010-01-17 14:06:20 -08001357fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001358AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001359if test "x${enable_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001360 if test "x${force_tls}" = "x0" ; then
1361 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1362 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001363 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001364elif test "x${force_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001365 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
Jason Evans78d815c2010-01-17 14:06:20 -08001366fi
1367
Jason Evans2dbecf12010-09-05 10:35:13 -07001368dnl ============================================================================
Chih-hung Hsieh59cd80e2014-12-05 17:42:41 -08001369dnl Check for C11 atomics.
1370
1371JE_COMPILABLE([C11 atomics], [
1372#include <stdint.h>
1373#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1374#include <stdatomic.h>
1375#else
1376#error Atomics not available
1377#endif
1378], [
1379 uint64_t *p = (uint64_t *)0;
1380 uint64_t x = 1;
1381 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1382 uint64_t r = atomic_fetch_add(a, x) + x;
1383 return (r == 0);
1384], [je_cv_c11atomics])
1385if test "x${je_cv_c11atomics}" = "xyes" ; then
1386 AC_DEFINE([JEMALLOC_C11ATOMICS])
1387fi
1388
1389dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001390dnl Check for atomic(9) operations as provided on FreeBSD.
1391
1392JE_COMPILABLE([atomic(9)], [
1393#include <sys/types.h>
1394#include <machine/atomic.h>
1395#include <inttypes.h>
1396], [
1397 {
1398 uint32_t x32 = 0;
1399 volatile uint32_t *x32p = &x32;
1400 atomic_fetchadd_32(x32p, 1);
1401 }
1402 {
1403 unsigned long xlong = 0;
1404 volatile unsigned long *xlongp = &xlong;
1405 atomic_fetchadd_long(xlongp, 1);
1406 }
1407], [je_cv_atomic9])
1408if test "x${je_cv_atomic9}" = "xyes" ; then
1409 AC_DEFINE([JEMALLOC_ATOMIC9])
1410fi
1411
1412dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001413dnl Check for atomic(3) operations as provided on Darwin.
1414
1415JE_COMPILABLE([Darwin OSAtomic*()], [
1416#include <libkern/OSAtomic.h>
1417#include <inttypes.h>
1418], [
1419 {
1420 int32_t x32 = 0;
1421 volatile int32_t *x32p = &x32;
1422 OSAtomicAdd32(1, x32p);
1423 }
1424 {
1425 int64_t x64 = 0;
1426 volatile int64_t *x64p = &x64;
1427 OSAtomicAdd64(1, x64p);
1428 }
Jason Evans6684cac2012-03-05 12:15:36 -08001429], [je_cv_osatomic])
1430if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001431 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001432fi
1433
1434dnl ============================================================================
Richard Diamond994fad92014-06-03 02:39:18 -05001435dnl Check for madvise(2).
1436
1437JE_COMPILABLE([madvise(2)], [
1438#include <sys/mman.h>
1439], [
1440 {
1441 madvise((void *)0, 0, 0);
1442 }
1443], [je_cv_madvise])
1444if test "x${je_cv_madvise}" = "xyes" ; then
1445 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1446fi
1447
1448dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001449dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1450dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1451
1452AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1453 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1454 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001455 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1456 #include <stdint.h>
1457 ],
1458 [
1459 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1460 {
1461 uint$1_t x$1 = 0;
1462 __sync_add_and_fetch(&x$1, 42);
1463 __sync_sub_and_fetch(&x$1, 1);
1464 }
1465 #else
1466 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1467 #endif
1468 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001469 [je_cv_sync_compare_and_swap_$2=yes],
1470 [je_cv_sync_compare_and_swap_$2=no])])
1471
1472 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1473 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1474 fi
1475])
1476
Jason Evansb57d3ec2012-04-17 13:17:54 -07001477if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001478 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1479 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1480fi
1481
1482dnl ============================================================================
Jason Evansd04047c2014-05-28 16:11:55 -07001483dnl Check for __builtin_clz() and __builtin_clzl().
1484
1485AC_CACHE_CHECK([for __builtin_clz],
1486 [je_cv_builtin_clz],
1487 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1488 [
1489 {
1490 unsigned x = 0;
1491 int y = __builtin_clz(x);
1492 }
1493 {
1494 unsigned long x = 0;
1495 int y = __builtin_clzl(x);
1496 }
1497 ])],
1498 [je_cv_builtin_clz=yes],
1499 [je_cv_builtin_clz=no])])
1500
1501if test "x${je_cv_builtin_clz}" = "xyes" ; then
1502 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1503fi
1504
1505dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001506dnl Check for spinlock(3) operations as provided on Darwin.
1507
1508JE_COMPILABLE([Darwin OSSpin*()], [
1509#include <libkern/OSAtomic.h>
1510#include <inttypes.h>
1511], [
1512 OSSpinLock lock = 0;
1513 OSSpinLockLock(&lock);
1514 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001515], [je_cv_osspin])
1516if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001517 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001518fi
1519
1520dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001521dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001522
Mike Hommeyd0357f72012-11-26 18:52:41 +01001523AC_ARG_ENABLE([zone-allocator],
1524 [AS_HELP_STRING([--disable-zone-allocator],
1525 [Disable zone allocator for Darwin])],
1526[if test "x$enable_zone_allocator" = "xno" ; then
1527 enable_zone_allocator="0"
1528else
1529 enable_zone_allocator="1"
1530fi
1531],
1532[if test "x${abi}" = "xmacho"; then
1533 enable_zone_allocator="1"
1534fi
1535]
1536)
1537AC_SUBST([enable_zone_allocator])
1538
1539if test "x${enable_zone_allocator}" = "x1" ; then
1540 if test "x${abi}" != "xmacho"; then
1541 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1542 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001543 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001544
Jason Evans2dbecf12010-09-05 10:35:13 -07001545 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1546 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1547 dnl 10.6, which is the only source-level indication of the change.
1548 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001549 AC_DEFUN([JE_ZONE_PROGRAM],
1550 [AC_LANG_PROGRAM(
1551 [#include <malloc/malloc.h>],
Guilherme Goncalves79725aa2014-10-20 14:08:37 -02001552 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
Mike Hommey154829d2012-03-20 18:01:38 +01001553 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001554
Mike Hommey154829d2012-03-20 18:01:38 +01001555 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1556 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1557 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1558 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1559 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1560 )])],[
1561 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1562 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1563 )])])])])
1564 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1565 AC_MSG_RESULT([unsupported])
1566 AC_MSG_ERROR([Unsupported malloc zone version])
1567 fi
1568 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1569 JEMALLOC_ZONE_VERSION=8
1570 AC_MSG_RESULT([> 8])
1571 else
1572 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1573 fi
1574 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001575fi
1576
Jason Evansb7924f52009-06-23 19:01:18 -07001577dnl ============================================================================
Sara Golemon3e24afa2014-08-18 13:06:39 -07001578dnl Check for glibc malloc hooks
1579
1580JE_COMPILABLE([glibc malloc hook], [
1581#include <stddef.h>
1582
1583extern void (* __free_hook)(void *ptr);
1584extern void *(* __malloc_hook)(size_t size);
1585extern void *(* __realloc_hook)(void *ptr, size_t size);
1586], [
1587 void *ptr = 0L;
1588 if (__malloc_hook) ptr = __malloc_hook(1);
1589 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1590 if (__free_hook && ptr) __free_hook(ptr);
1591], [je_cv_glibc_malloc_hook])
1592if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1593 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1594fi
1595
1596JE_COMPILABLE([glibc memalign hook], [
1597#include <stddef.h>
1598
1599extern void *(* __memalign_hook)(size_t alignment, size_t size);
1600], [
1601 void *ptr = 0L;
1602 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1603], [je_cv_glibc_memalign_hook])
1604if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1605 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1606fi
1607
Eric Wong4dcf04b2014-08-31 03:57:06 +00001608JE_COMPILABLE([pthreads adaptive mutexes], [
1609#include <pthread.h>
1610], [
1611 pthread_mutexattr_t attr;
1612 pthread_mutexattr_init(&attr);
1613 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1614 pthread_mutexattr_destroy(&attr);
1615], [je_cv_pthread_mutex_adaptive_np])
1616if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1617 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1618fi
1619
Sara Golemon3e24afa2014-08-18 13:06:39 -07001620dnl ============================================================================
Jason Evansb7924f52009-06-23 19:01:18 -07001621dnl Check for typedefs, structures, and compiler characteristics.
1622AC_HEADER_STDBOOL
1623
Jason Evans748dfac2013-12-06 18:27:33 -08001624dnl ============================================================================
1625dnl Define commands that generate output files.
1626
Jason Evans86abd0d2013-11-30 15:25:42 -08001627AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1628 mkdir -p "${objroot}include/jemalloc/internal"
1629 "${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 -08001630], [
1631 srcdir="${srcdir}"
1632 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001633])
1634AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1635 mkdir -p "${objroot}include/jemalloc/internal"
1636 "${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 -08001637], [
1638 srcdir="${srcdir}"
1639 objroot="${objroot}"
1640])
1641AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1642 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1643 mkdir -p "${objroot}include/jemalloc/internal"
1644 cp /dev/null "${f}"
1645 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1646 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1647 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1648 echo "${n}:${m}" >> "${f}"
1649 dnl Remove name from public_syms so that it isn't redefined later.
1650 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1651 done
1652 for sym in ${public_syms} ; do
1653 n="${sym}"
1654 m="${JEMALLOC_PREFIX}${sym}"
1655 echo "${n}:${m}" >> "${f}"
1656 done
1657], [
1658 srcdir="${srcdir}"
1659 objroot="${objroot}"
1660 mangling_map="${mangling_map}"
1661 public_syms="${public_syms}"
1662 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001663])
1664AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1665 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001666 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1667], [
1668 srcdir="${srcdir}"
1669 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001670])
1671AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1672 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001673 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1674], [
1675 srcdir="${srcdir}"
1676 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001677])
Jason Evansb1726102012-02-28 16:50:47 -08001678AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001679 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evans6d919292015-09-15 10:42:36 -07001680 "${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 -08001681], [
Jason Evans6d919292015-09-15 10:42:36 -07001682 SHELL="${SHELL}"
Jason Evansf234dc52014-01-16 17:38:01 -08001683 srcdir="${srcdir}"
1684 objroot="${objroot}"
Jason Evans81e54752014-10-10 22:34:25 -07001685 LG_QUANTA="${LG_QUANTA}"
1686 LG_TINY_MIN=${LG_TINY_MIN}
1687 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
Jason Evansfc0b3b72014-10-09 17:54:06 -07001688 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
Jason Evansb1726102012-02-28 16:50:47 -08001689])
Jason Evans86abd0d2013-11-30 15:25:42 -08001690AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1691 mkdir -p "${objroot}include/jemalloc"
1692 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 -08001693], [
1694 srcdir="${srcdir}"
1695 objroot="${objroot}"
1696])
1697AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1698 mkdir -p "${objroot}include/jemalloc"
1699 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1700], [
1701 srcdir="${srcdir}"
1702 objroot="${objroot}"
1703])
1704AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1705 mkdir -p "${objroot}include/jemalloc"
1706 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1707], [
1708 srcdir="${srcdir}"
1709 objroot="${objroot}"
1710])
1711AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1712 mkdir -p "${objroot}include/jemalloc"
1713 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1714], [
1715 srcdir="${srcdir}"
1716 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001717])
1718AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1719 mkdir -p "${objroot}include/jemalloc"
1720 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001721], [
1722 srcdir="${srcdir}"
1723 objroot="${objroot}"
1724 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001725])
Jason Evansb1726102012-02-28 16:50:47 -08001726
Jason Evansb7924f52009-06-23 19:01:18 -07001727dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001728AC_SUBST([cfghdrs_in])
1729AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001730AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001731
1732dnl ============================================================================
1733dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001734
Jason Evans70417202015-05-01 12:31:12 -07001735AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
Jason Evansb0fd5012010-01-17 01:49:20 -08001736AC_SUBST([cfgoutputs_in])
1737AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001738AC_OUTPUT
1739
1740dnl ============================================================================
1741dnl Print out the results of configuration.
1742AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001743AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1744AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001745AC_MSG_RESULT([])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001746AC_MSG_RESULT([CONFIG : ${CONFIG}])
Jason Evansb7924f52009-06-23 19:01:18 -07001747AC_MSG_RESULT([CC : ${CC}])
Jason Evansb7924f52009-06-23 19:01:18 -07001748AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001749AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001750AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001751AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001752AC_MSG_RESULT([LIBS : ${LIBS}])
Jason Evans345c1b02015-09-15 14:59:56 -07001753AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001754AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1755AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001756AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1757AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1758AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001759AC_MSG_RESULT([PREFIX : ${PREFIX}])
1760AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001761AC_MSG_RESULT([DATADIR : ${DATADIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001762AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1763AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001764AC_MSG_RESULT([MANDIR : ${MANDIR}])
1765AC_MSG_RESULT([])
1766AC_MSG_RESULT([srcroot : ${srcroot}])
1767AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1768AC_MSG_RESULT([objroot : ${objroot}])
1769AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1770AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001771AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001772AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1773AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001774AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansf8290092016-02-07 14:23:22 -08001775AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
Jason Evansb7924f52009-06-23 19:01:18 -07001776AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001777AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001778AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001779AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001780AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001781AC_MSG_RESULT([prof : ${enable_prof}])
1782AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001783AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1784AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001785AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001786AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001787AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001788AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1789AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001790AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001791AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001792AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evans8a03cf02015-05-04 09:58:36 -07001793AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
Jason Evansb7924f52009-06-23 19:01:18 -07001794AC_MSG_RESULT([===============================================================================])