blob: 7f19715d4beb6e383340993bb45fd65e15b7d378 [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])
Chris Peterson18903c52016-03-14 21:44:32 -0700144 JE_CFLAGS_APPEND([-Wsign-compare])
Jason Evanscfeccd32010-03-03 15:48:20 -0800145 JE_CFLAGS_APPEND([-pipe])
146 JE_CFLAGS_APPEND([-g3])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200147 elif test "x$je_cv_msvc" = "xyes" ; then
148 CC="$CC -nologo"
149 JE_CFLAGS_APPEND([-Zi])
150 JE_CFLAGS_APPEND([-MT])
151 JE_CFLAGS_APPEND([-W3])
Mike Hommey8c615752014-05-29 16:58:21 +0900152 JE_CFLAGS_APPEND([-FS])
Mike Hommey6f6704c2014-05-29 17:01:10 +0900153 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat"
Jason Evanscfeccd32010-03-03 15:48:20 -0800154 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700155fi
156dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
157if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700158 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700159fi
160AC_PROG_CPP
161
Jason Evansdf3f2702014-03-30 16:27:08 -0700162AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
163if test "x${ac_cv_big_endian}" = "x1" ; then
164 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
165fi
166
Mike Hommeyff2e9992014-05-29 16:33:02 +0900167if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
Mike Hommey6f6704c2014-05-29 17:01:10 +0900168 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
Mike Hommeyff2e9992014-05-29 16:33:02 +0900169fi
170
rustyx46e0b232016-01-30 13:37:26 +0100171if test "x${je_cv_msvc}" = "xyes" ; then
172 LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
173 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 -0700174else
rustyx46e0b232016-01-30 13:37:26 +0100175 AC_CHECK_SIZEOF([void *])
176 if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
177 LG_SIZEOF_PTR=3
178 elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
179 LG_SIZEOF_PTR=2
180 else
181 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
182 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700183fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800184AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
185
186AC_CHECK_SIZEOF([int])
187if test "x${ac_cv_sizeof_int}" = "x8" ; then
188 LG_SIZEOF_INT=3
189elif test "x${ac_cv_sizeof_int}" = "x4" ; then
190 LG_SIZEOF_INT=2
191else
192 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
193fi
194AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700195
Jason Evans84c8eef2011-03-16 10:30:13 -0700196AC_CHECK_SIZEOF([long])
197if test "x${ac_cv_sizeof_long}" = "x8" ; then
198 LG_SIZEOF_LONG=3
199elif test "x${ac_cv_sizeof_long}" = "x4" ; then
200 LG_SIZEOF_LONG=2
201else
202 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
203fi
204AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
205
Jason Evansecae1232016-02-20 23:41:33 -0800206AC_CHECK_SIZEOF([long long])
207if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
208 LG_SIZEOF_LONG_LONG=3
209elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
210 LG_SIZEOF_LONG_LONG=2
211else
212 AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
213fi
214AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
215
Jason Evansd81e4bd2012-03-06 14:57:45 -0800216AC_CHECK_SIZEOF([intmax_t])
217if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
218 LG_SIZEOF_INTMAX_T=4
219elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
220 LG_SIZEOF_INTMAX_T=3
221elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
222 LG_SIZEOF_INTMAX_T=2
223else
Mike Hommey14103d32012-04-20 08:38:39 +0200224 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
Jason Evansd81e4bd2012-03-06 14:57:45 -0800225fi
226AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
227
Jason Evansb7924f52009-06-23 19:01:18 -0700228AC_CANONICAL_HOST
229dnl CPU-specific settings.
230CPU_SPINWAIT=""
231case "${host_cpu}" in
Jason Evanscb657e32014-02-25 11:21:41 -0800232 i686|x86_64)
rustyx90c72692016-01-30 13:41:09 +0100233 if test "x${je_cv_msvc}" = "xyes" ; then
234 AC_CACHE_VAL([je_cv_pause_msvc],
235 [JE_COMPILABLE([pause instruction MSVC], [],
236 [[_mm_pause(); return 0;]],
237 [je_cv_pause_msvc])])
238 if test "x${je_cv_pause_msvc}" = "xyes" ; then
239 CPU_SPINWAIT='_mm_pause()'
240 fi
241 else
242 AC_CACHE_VAL([je_cv_pause],
243 [JE_COMPILABLE([pause instruction], [],
244 [[__asm__ volatile("pause"); return 0;]],
245 [je_cv_pause])])
246 if test "x${je_cv_pause}" = "xyes" ; then
247 CPU_SPINWAIT='__asm__ volatile("pause")'
248 fi
Jason Evansf3340ca2009-06-30 16:17:05 -0700249 fi
Jason Evans80061b62013-12-09 13:21:08 -0800250 ;;
251 powerpc)
252 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700253 ;;
254 *)
255 ;;
256esac
257AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
258
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400259LD_PRELOAD_VAR="LD_PRELOAD"
Jason Evansf576c632011-11-01 22:27:41 -0700260so="so"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200261importlib="${so}"
Mike Hommey7cdea392012-04-30 12:38:27 +0200262o="$ac_objext"
Mike Hommey5bee66d2012-04-16 16:30:24 +0200263a="a"
Mike Hommey7cdea392012-04-30 12:38:27 +0200264exe="$ac_exeext"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700265libprefix="lib"
Mike Hommeyfa08da72012-04-16 16:30:25 +0200266DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
267RPATH='-Wl,-rpath,$(1)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200268SOREV="${so}.${rev}"
Mike Hommey188da7c2012-04-18 18:29:41 +0200269PIC_CFLAGS='-fPIC -DPIC'
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200270CTARGET='-o $@'
271LDTARGET='-o $@'
272EXTRA_LDFLAGS=
Jason Evans80ddf492013-08-20 11:48:19 +0100273ARFLAGS='crus'
274AROUT=' $@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200275CC_MM=1
Jason Evans7372b152012-02-10 20:22:09 -0800276
Jory A. Prattad505e02013-08-11 09:44:59 -0500277AN_MAKEVAR([AR], [AC_PROG_AR])
278AN_PROGRAM([ar], [AC_PROG_AR])
279AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
280AC_PROG_AR
281
Jason Evansb7924f52009-06-23 19:01:18 -0700282dnl Platform-specific settings. abi and RPATH can probably be determined
283dnl programmatically, but doing so is error-prone, which makes it generally
284dnl not worth the trouble.
285dnl
286dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
287dnl definitions need to be seen before any headers are included, which is a pain
288dnl to make happen otherwise.
Jason Evans59ae2762012-04-16 17:52:27 -0700289default_munmap="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700290maps_coalesce="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700291case "${host}" in
Valerii Hiora5921ba72014-05-16 16:28:20 +0300292 *-*-darwin* | *-*-ios*)
Mike Hommeya6770a72012-05-03 14:12:49 +0200293 CFLAGS="$CFLAGS"
Jason Evansb7924f52009-06-23 19:01:18 -0700294 abi="macho"
Jason Evanse24c7af2012-03-19 10:21:17 -0700295 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700296 RPATH=""
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400297 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
Jason Evansf576c632011-11-01 22:27:41 -0700298 so="dylib"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200299 importlib="${so}"
Jason Evansb80581d2012-03-23 16:17:43 -0700300 force_tls="0"
Jason Evansf1f2b452015-05-01 08:57:41 -0700301 DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
Mike Hommey7cdea392012-04-30 12:38:27 +0200302 SOREV="${rev}.${so}"
Jason Evans66688532013-12-03 21:49:36 -0800303 sbrk_deprecated="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700304 ;;
305 *-*-freebsd*)
306 CFLAGS="$CFLAGS"
307 abi="elf"
Jason Evansc2f970c2016-05-05 17:45:02 -0700308 AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
Jason Evanse24c7af2012-03-19 10:21:17 -0700309 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansfd4fcef2012-03-23 17:40:58 -0700310 force_lazy_lock="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700311 ;;
Michael Neumann1aa25a32014-08-05 03:06:02 +0200312 *-*-dragonfly*)
313 CFLAGS="$CFLAGS"
314 abi="elf"
315 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
316 ;;
Sébastien Marieb80fbcb2015-04-07 12:21:19 +0200317 *-*-openbsd*)
318 CFLAGS="$CFLAGS"
319 abi="elf"
320 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
321 force_tls="0"
322 ;;
323 *-*-bitrig*)
Sébastien Marie77d597e2015-01-25 10:18:32 +0100324 CFLAGS="$CFLAGS"
325 abi="elf"
326 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
327 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700328 *-*-linux*)
329 CFLAGS="$CFLAGS"
330 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
331 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800332 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evansc2f970c2016-05-05 17:45:02 -0700333 AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
Jason Evanse24c7af2012-03-19 10:21:17 -0700334 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700335 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansae93d6b2015-07-10 14:33:00 -0700336 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700337 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700338 ;;
339 *-*-netbsd*)
340 AC_MSG_CHECKING([ABI])
341 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
342[[#ifdef __ELF__
343/* ELF */
344#else
345#error aout
346#endif
347]])],
348 [CFLAGS="$CFLAGS"; abi="elf"],
349 [abi="aout"])
350 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700351 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700352 ;;
353 *-*-solaris2*)
354 CFLAGS="$CFLAGS"
355 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000356 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200357 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700358 dnl Solaris needs this for sigwait().
359 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
360 LIBS="$LIBS -lposix4 -lsocket -lnsl"
361 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400362 *-ibm-aix*)
363 if "$LG_SIZEOF_PTR" = "8"; then
364 dnl 64bit AIX
365 LD_PRELOAD_VAR="LDR_PRELOAD64"
366 else
367 dnl 32bit AIX
368 LD_PRELOAD_VAR="LDR_PRELOAD"
369 fi
370 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400371 ;;
Dave Rigby70bdee02014-09-22 15:53:16 +0100372 *-*-mingw* | *-*-cygwin*)
Mike Hommeya19e87f2012-04-21 21:27:46 -0700373 abi="pecoff"
374 force_tls="0"
Jason Evans13473c72015-07-23 14:08:49 -0700375 force_lazy_lock="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700376 maps_coalesce="0"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700377 RPATH=""
378 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200379 if test "x$je_cv_msvc" = "xyes" ; then
380 importlib="lib"
381 DSO_LDFLAGS="-LD"
382 EXTRA_LDFLAGS="-link -DEBUG"
383 CTARGET='-Fo$@'
384 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500385 AR='lib'
386 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100387 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200388 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200389 else
390 importlib="${so}"
391 DSO_LDFLAGS="-shared"
392 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700393 a="lib"
394 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200395 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700396 PIC_CFLAGS=""
397 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700398 *)
399 AC_MSG_RESULT([Unsupported operating system: ${host}])
400 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700401 ;;
402esac
Mike Hommeyaffe0092014-05-28 08:10:12 +0900403
404JEMALLOC_USABLE_SIZE_CONST=const
405AC_CHECK_HEADERS([malloc.h], [
406 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
407 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
408 [#include <malloc.h>
409 #include <stddef.h>
410 size_t malloc_usable_size(const void *ptr);
411 ],
412 [])],[
413 AC_MSG_RESULT([yes])
414 ],[
415 JEMALLOC_USABLE_SIZE_CONST=
416 AC_MSG_RESULT([no])
417 ])
418])
Jason Evans247d1242012-10-09 16:20:10 -0700419AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700420AC_SUBST([abi])
421AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400422AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700423AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200424AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200425AC_SUBST([o])
426AC_SUBST([a])
427AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700428AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200429AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200430AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200431AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200432AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200433AC_SUBST([CTARGET])
434AC_SUBST([LDTARGET])
435AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100436AC_SUBST([ARFLAGS])
437AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200438AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200439
Jason Evansfa5d2452011-03-15 10:25:59 -0700440JE_COMPILABLE([__attribute__ syntax],
441 [static __attribute__((unused)) void foo(void){}],
442 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800443 [je_cv_attribute])
444if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700445 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
446 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
447 JE_CFLAGS_APPEND([-fvisibility=hidden])
448 fi
449fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700450dnl Check for tls_model attribute support (clang 3.0 still lacks support).
451SAVED_CFLAGS="${CFLAGS}"
452JE_CFLAGS_APPEND([-Werror])
453JE_COMPILABLE([tls_model attribute], [],
454 [static __thread int
Daniel Micayf1cf3ea2014-09-16 04:42:33 -0400455 __attribute__((tls_model("initial-exec"), unused)) foo;
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700456 foo = 0;],
457 [je_cv_tls_model])
458CFLAGS="${SAVED_CFLAGS}"
459if test "x${je_cv_tls_model}" = "xyes" ; then
460 AC_DEFINE([JEMALLOC_TLS_MODEL],
461 [__attribute__((tls_model("initial-exec")))])
462else
463 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
464fi
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700465dnl Check for alloc_size attribute support.
466SAVED_CFLAGS="${CFLAGS}"
467JE_CFLAGS_APPEND([-Werror])
Jason Evans92d72ee2015-07-10 16:45:32 -0700468JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
469 [void *foo(size_t size) __attribute__((alloc_size(1)));],
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700470 [je_cv_alloc_size])
471CFLAGS="${SAVED_CFLAGS}"
472if test "x${je_cv_alloc_size}" = "xyes" ; then
473 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
474fi
Jason Evanse42c3092015-07-22 15:44:47 -0700475dnl Check for format(gnu_printf, ...) attribute support.
476SAVED_CFLAGS="${CFLAGS}"
477JE_CFLAGS_APPEND([-Werror])
478JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
479 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
480 [je_cv_format_gnu_printf])
481CFLAGS="${SAVED_CFLAGS}"
482if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
483 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
484fi
485dnl Check for format(printf, ...) attribute support.
486SAVED_CFLAGS="${CFLAGS}"
487JE_CFLAGS_APPEND([-Werror])
488JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
489 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
490 [je_cv_format_printf])
491CFLAGS="${SAVED_CFLAGS}"
492if test "x${je_cv_format_printf}" = "xyes" ; then
493 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
494fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700495
Jason Evansb7924f52009-06-23 19:01:18 -0700496dnl Support optional additions to rpath.
497AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800498 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700499if test "x$with_rpath" = "xno" ; then
500 RPATH_EXTRA=
501else
502 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
503fi,
504 RPATH_EXTRA=
505)
506AC_SUBST([RPATH_EXTRA])
507
508dnl Disable rules that do automatic regeneration of configure output by default.
509AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800510 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700511if test "x$enable_autogen" = "xno" ; then
512 enable_autogen="0"
513else
514 enable_autogen="1"
515fi
516,
517enable_autogen="0"
518)
519AC_SUBST([enable_autogen])
520
521AC_PROG_INSTALL
522AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800523AC_PATH_PROG([LD], [ld], [false], [$PATH])
524AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700525
Daniel Micay4cfe5512014-08-28 15:41:48 -0400526public_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 -0800527
528dnl Check for allocator-related functions that should be wrapped.
529AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700530 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800531 public_syms="${public_syms} memalign"])
532AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700533 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800534 public_syms="${public_syms} valloc"])
535
Jason Evans748dfac2013-12-06 18:27:33 -0800536dnl Do not compute test code coverage by default.
537GCOV_FLAGS=
538AC_ARG_ENABLE([code-coverage],
539 [AS_HELP_STRING([--enable-code-coverage],
540 [Enable code coverage])],
541[if test "x$enable_code_coverage" = "xno" ; then
542 enable_code_coverage="0"
543else
544 enable_code_coverage="1"
545fi
546],
547[enable_code_coverage="0"]
548)
549if test "x$enable_code_coverage" = "x1" ; then
550 deoptimize="no"
551 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
552 if test "x${deoptimize}" = "xyes" ; then
553 JE_CFLAGS_APPEND([-O0])
554 fi
555 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
556 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
557 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
558fi
559AC_SUBST([enable_code_coverage])
560
Jason Evans0a5489e2012-03-01 17:19:20 -0800561dnl Perform no name mangling by default.
562AC_ARG_WITH([mangling],
563 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
564 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800565
Jason Evans90895cf2009-12-29 00:09:15 -0800566dnl Do not prefix public APIs by default.
567AC_ARG_WITH([jemalloc_prefix],
568 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800569 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200570 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700571 JEMALLOC_PREFIX=""
572else
573 JEMALLOC_PREFIX="je_"
574fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800575)
576if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700577 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
578 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
579 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800580fi
Jason Evans241abc62015-06-23 18:47:07 -0700581AC_SUBST([JEMALLOC_CPREFIX])
Jason Evans90895cf2009-12-29 00:09:15 -0800582
Mike Hommey99066602012-11-19 10:55:26 +0100583AC_ARG_WITH([export],
584 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
585 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800586 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100587fi]
588)
589
Jason Evans86abd0d2013-11-30 15:25:42 -0800590dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700591AC_ARG_WITH([private_namespace],
592 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800593 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
594 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700595)
Jason Evans86abd0d2013-11-30 15:25:42 -0800596AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
597private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
598AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700599
Jason Evansb0fd5012010-01-17 01:49:20 -0800600dnl Do not add suffix to installed files by default.
601AC_ARG_WITH([install_suffix],
602 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
603 [INSTALL_SUFFIX="$with_install_suffix"],
604 [INSTALL_SUFFIX=]
605)
606install_suffix="$INSTALL_SUFFIX"
607AC_SUBST([install_suffix])
608
Jason Evansf8290092016-02-07 14:23:22 -0800609dnl Specify default malloc_conf.
610AC_ARG_WITH([malloc_conf],
611 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
612 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
613 [JEMALLOC_CONFIG_MALLOC_CONF=""]
614)
615config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
616AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
617
Jason Evans86abd0d2013-11-30 15:25:42 -0800618dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
619dnl jemalloc_protos_jet.h easy.
620je_="je_"
621AC_SUBST([je_])
622
Mike Hommeycf6032d2014-07-30 18:16:13 +0900623cfgoutputs_in="Makefile.in"
Nick White913e9a82014-09-19 22:01:23 +0100624cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900625cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
626cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
627cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
628cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
629cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700630cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900631cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
632cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
633cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800634
Jason Evansaee7fd22010-11-24 22:00:02 -0800635cfgoutputs_out="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100636cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
Jason Evansaee7fd22010-11-24 22:00:02 -0800637cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
638cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800639cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
640cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
641cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Jason Evans82e88d12014-09-07 19:55:03 -0700642cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
Jason Evans376b1522010-02-11 14:45:59 -0800643cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800644cfgoutputs_out="${cfgoutputs_out} test/test.sh"
645cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800646
Jason Evansaee7fd22010-11-24 22:00:02 -0800647cfgoutputs_tup="Makefile"
Nick White913e9a82014-09-19 22:01:23 +0100648cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
Jason Evansaee7fd22010-11-24 22:00:02 -0800649cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
650cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800651cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
652cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
653cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Jason Evans82e88d12014-09-07 19:55:03 -0700654cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800655cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800656cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
657cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800658
Mike Hommeycf6032d2014-07-30 18:16:13 +0900659cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
660cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
661cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
662cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
663cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
664cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
665cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
666cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
667cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
668cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
669cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
670cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800671
Jason Evans86abd0d2013-11-30 15:25:42 -0800672cfghdrs_out="include/jemalloc/jemalloc_defs.h"
673cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800674cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
675cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800676cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800677cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
678cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800679cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800680cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
681cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
682cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
683cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
684cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800685cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800686
Jason Evans86abd0d2013-11-30 15:25:42 -0800687cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
Mike Hommeycf6032d2014-07-30 18:16:13 +0900688cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
689cfghdrs_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 -0800690
Jason Evans644d4142014-04-14 22:49:23 -0700691dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700692AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700693 [AS_HELP_STRING([--disable-cc-silence],
694 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700695[if test "x$enable_cc_silence" = "xno" ; then
696 enable_cc_silence="0"
697else
698 enable_cc_silence="1"
699fi
700],
Jason Evans644d4142014-04-14 22:49:23 -0700701[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700702)
703if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700704 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700705fi
706
Jason Evansb7924f52009-06-23 19:01:18 -0700707dnl Do not compile with debugging by default.
708AC_ARG_ENABLE([debug],
Jason Evanse0a08a12015-03-18 21:06:58 -0700709 [AS_HELP_STRING([--enable-debug],
710 [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700711[if test "x$enable_debug" = "xno" ; then
712 enable_debug="0"
713else
714 enable_debug="1"
715fi
716],
717[enable_debug="0"]
718)
Jason Evans02e5dcf2015-02-15 20:12:06 -0800719if test "x$enable_debug" = "x1" ; then
720 AC_DEFINE([JEMALLOC_DEBUG], [ ])
721fi
Jason Evanse0a08a12015-03-18 21:06:58 -0700722if test "x$enable_debug" = "x1" ; then
723 AC_DEFINE([JEMALLOC_DEBUG], [ ])
724 enable_ivsalloc="1"
725fi
Jason Evansb7924f52009-06-23 19:01:18 -0700726AC_SUBST([enable_debug])
727
Jason Evanse0a08a12015-03-18 21:06:58 -0700728dnl Do not validate pointers by default.
729AC_ARG_ENABLE([ivsalloc],
730 [AS_HELP_STRING([--enable-ivsalloc],
731 [Validate pointers passed through the public API])],
732[if test "x$enable_ivsalloc" = "xno" ; then
733 enable_ivsalloc="0"
734else
735 enable_ivsalloc="1"
736fi
737],
738[enable_ivsalloc="0"]
739)
740if test "x$enable_ivsalloc" = "x1" ; then
741 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
742fi
743
Jason Evansb7924f52009-06-23 19:01:18 -0700744dnl Only optimize if not debugging.
745if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
746 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700747 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800748 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700749 if test "x${optimize}" = "xyes" ; then
750 if test "x$GCC" = "xyes" ; then
751 JE_CFLAGS_APPEND([-O3])
752 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200753 elif test "x$je_cv_msvc" = "xyes" ; then
754 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700755 else
756 JE_CFLAGS_APPEND([-O])
757 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700758 fi
759fi
760
Jason Evansd073a322012-02-28 20:41:16 -0800761dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700762AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800763 [AS_HELP_STRING([--disable-stats],
764 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700765[if test "x$enable_stats" = "xno" ; then
766 enable_stats="0"
767else
768 enable_stats="1"
769fi
770],
Jason Evansd073a322012-02-28 20:41:16 -0800771[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700772)
773if test "x$enable_stats" = "x1" ; then
774 AC_DEFINE([JEMALLOC_STATS], [ ])
775fi
776AC_SUBST([enable_stats])
777
Jason Evans6109fe02010-02-10 10:37:56 -0800778dnl Do not enable profiling by default.
779AC_ARG_ENABLE([prof],
780 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
781[if test "x$enable_prof" = "xno" ; then
782 enable_prof="0"
783else
784 enable_prof="1"
785fi
786],
787[enable_prof="0"]
788)
Jason Evans77f350b2011-03-15 22:23:12 -0700789if test "x$enable_prof" = "x1" ; then
790 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800791else
Jason Evans77f350b2011-03-15 22:23:12 -0700792 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800793fi
Jason Evans77f350b2011-03-15 22:23:12 -0700794
Jason Evans6109fe02010-02-10 10:37:56 -0800795AC_ARG_ENABLE([prof-libunwind],
796 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
797[if test "x$enable_prof_libunwind" = "xno" ; then
798 enable_prof_libunwind="0"
799else
800 enable_prof_libunwind="1"
801fi
802],
803[enable_prof_libunwind="0"]
804)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800805AC_ARG_WITH([static_libunwind],
806 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
807 [Path to static libunwind library; use rather than dynamically linking])],
808if test "x$with_static_libunwind" = "xno" ; then
809 LUNWIND="-lunwind"
810else
811 if test ! -f "$with_static_libunwind" ; then
812 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
813 fi
814 LUNWIND="$with_static_libunwind"
815fi,
816 LUNWIND="-lunwind"
817)
Jason Evans77f350b2011-03-15 22:23:12 -0700818if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
819 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
820 if test "x$LUNWIND" = "x-lunwind" ; then
Jason Evans05125b82014-04-22 20:48:07 -0700821 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700822 [enable_prof_libunwind="0"])
823 else
824 LIBS="$LIBS $LUNWIND"
825 fi
826 if test "x${enable_prof_libunwind}" = "x1" ; then
827 backtrace_method="libunwind"
828 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
829 fi
830fi
831
832AC_ARG_ENABLE([prof-libgcc],
833 [AS_HELP_STRING([--disable-prof-libgcc],
834 [Do not use libgcc for backtracing])],
835[if test "x$enable_prof_libgcc" = "xno" ; then
836 enable_prof_libgcc="0"
837else
838 enable_prof_libgcc="1"
839fi
840],
841[enable_prof_libgcc="1"]
842)
843if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
844 -a "x$GCC" = "xyes" ; then
845 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
846 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
Jason Evans77f350b2011-03-15 22:23:12 -0700847 if test "x${enable_prof_libgcc}" = "x1" ; then
848 backtrace_method="libgcc"
849 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
850 fi
851else
852 enable_prof_libgcc="0"
853fi
854
855AC_ARG_ENABLE([prof-gcc],
856 [AS_HELP_STRING([--disable-prof-gcc],
857 [Do not use gcc intrinsics for backtracing])],
858[if test "x$enable_prof_gcc" = "xno" ; then
859 enable_prof_gcc="0"
860else
861 enable_prof_gcc="1"
862fi
863],
864[enable_prof_gcc="1"]
865)
866if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
867 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700868 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700869 backtrace_method="gcc intrinsics"
870 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
871else
872 enable_prof_gcc="0"
873fi
874
875if test "x$backtrace_method" = "x" ; then
876 backtrace_method="none (disabling profiling)"
877 enable_prof="0"
878fi
879AC_MSG_CHECKING([configured backtracing method])
880AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700881if test "x$enable_prof" = "x1" ; then
Jason Evansd37d5ad2013-12-05 23:01:50 -0800882 if test "x$abi" != "xpecoff"; then
883 dnl Heap profiling uses the log(3) function.
884 LIBS="$LIBS -lm"
885 fi
886
Jason Evans2dbecf12010-09-05 10:35:13 -0700887 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700888fi
889AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700890
Jason Evans84cbbcb2009-12-29 00:09:15 -0800891dnl Enable thread-specific caching by default.
892AC_ARG_ENABLE([tcache],
893 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
894[if test "x$enable_tcache" = "xno" ; then
895 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700896else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800897 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700898fi
899],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800900[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700901)
Jason Evans2dbecf12010-09-05 10:35:13 -0700902if test "x$enable_tcache" = "x1" ; then
903 AC_DEFINE([JEMALLOC_TCACHE], [ ])
904fi
905AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700906
Jason Evansd059b9d2015-07-24 18:21:42 -0700907dnl Indicate whether adjacent virtual memory mappings automatically coalesce
908dnl (and fragment on demand).
909if test "x${maps_coalesce}" = "x1" ; then
910 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
911fi
912
Jason Evans59ae2762012-04-16 17:52:27 -0700913dnl Enable VM deallocation via munmap() by default.
914AC_ARG_ENABLE([munmap],
915 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
916[if test "x$enable_munmap" = "xno" ; then
917 enable_munmap="0"
918else
919 enable_munmap="1"
920fi
921],
922[enable_munmap="${default_munmap}"]
923)
924if test "x$enable_munmap" = "x1" ; then
925 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
926fi
927AC_SUBST([enable_munmap])
928
Jason Evans4d434ad2014-04-15 12:09:48 -0700929dnl Enable allocation from DSS if supported by the OS.
930have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200931dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
932AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
933if test "x$have_sbrk" = "x1" ; then
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -0700934 if test "x$sbrk_deprecated" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800935 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700936 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800937 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200938else
Jason Evans4d434ad2014-04-15 12:09:48 -0700939 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200940fi
941
Jason Evans4d434ad2014-04-15 12:09:48 -0700942if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700943 AC_DEFINE([JEMALLOC_DSS], [ ])
944fi
Jason Evansb7924f52009-06-23 19:01:18 -0700945
Jason Evans777c1912012-02-28 20:49:22 -0800946dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700947AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700948 [AS_HELP_STRING([--disable-fill],
949 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700950[if test "x$enable_fill" = "xno" ; then
951 enable_fill="0"
952else
953 enable_fill="1"
954fi
955],
Jason Evans777c1912012-02-28 20:49:22 -0800956[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700957)
958if test "x$enable_fill" = "x1" ; then
959 AC_DEFINE([JEMALLOC_FILL], [ ])
960fi
961AC_SUBST([enable_fill])
962
Jason Evansb1476112012-04-05 13:36:17 -0700963dnl Disable utrace(2)-based tracing by default.
964AC_ARG_ENABLE([utrace],
965 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
966[if test "x$enable_utrace" = "xno" ; then
967 enable_utrace="0"
968else
969 enable_utrace="1"
970fi
971],
972[enable_utrace="0"]
973)
974JE_COMPILABLE([utrace(2)], [
975#include <sys/types.h>
976#include <sys/param.h>
977#include <sys/time.h>
978#include <sys/uio.h>
979#include <sys/ktrace.h>
980], [
981 utrace((void *)0, 0);
982], [je_cv_utrace])
983if test "x${je_cv_utrace}" = "xno" ; then
984 enable_utrace="0"
985fi
986if test "x$enable_utrace" = "x1" ; then
987 AC_DEFINE([JEMALLOC_UTRACE], [ ])
988fi
989AC_SUBST([enable_utrace])
990
Jason Evans122449b2012-04-06 00:35:09 -0700991dnl Support Valgrind by default.
992AC_ARG_ENABLE([valgrind],
993 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
994[if test "x$enable_valgrind" = "xno" ; then
995 enable_valgrind="0"
996else
997 enable_valgrind="1"
998fi
999],
1000[enable_valgrind="1"]
1001)
1002if test "x$enable_valgrind" = "x1" ; then
1003 JE_COMPILABLE([valgrind], [
1004#include <valgrind/valgrind.h>
1005#include <valgrind/memcheck.h>
1006
Mike Hommey7bfecf42012-04-30 15:15:15 +02001007#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -07001008# error "Incompatible Valgrind version"
1009#endif
1010], [], [je_cv_valgrind])
1011 if test "x${je_cv_valgrind}" = "xno" ; then
1012 enable_valgrind="0"
1013 fi
1014 if test "x$enable_valgrind" = "x1" ; then
1015 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1016 fi
1017fi
1018AC_SUBST([enable_valgrind])
1019
Jason Evansb7924f52009-06-23 19:01:18 -07001020dnl Do not support the xmalloc option by default.
1021AC_ARG_ENABLE([xmalloc],
1022 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1023[if test "x$enable_xmalloc" = "xno" ; then
1024 enable_xmalloc="0"
1025else
1026 enable_xmalloc="1"
1027fi
1028],
1029[enable_xmalloc="0"]
1030)
1031if test "x$enable_xmalloc" = "x1" ; then
1032 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1033fi
1034AC_SUBST([enable_xmalloc])
1035
Jason Evans8a03cf02015-05-04 09:58:36 -07001036dnl Support cache-oblivious allocation alignment by default.
1037AC_ARG_ENABLE([cache-oblivious],
1038 [AS_HELP_STRING([--disable-cache-oblivious],
1039 [Disable support for cache-oblivious allocation alignment])],
1040[if test "x$enable_cache_oblivious" = "xno" ; then
1041 enable_cache_oblivious="0"
1042else
1043 enable_cache_oblivious="1"
1044fi
1045],
1046[enable_cache_oblivious="1"]
1047)
1048if test "x$enable_cache_oblivious" = "x1" ; then
1049 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1050fi
1051AC_SUBST([enable_cache_oblivious])
1052
Mike Hommey8f50ec82014-06-04 12:12:55 +09001053dnl ============================================================================
1054dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1055dnl One of those two functions should (theoretically) exist on all platforms
1056dnl that jemalloc currently has a chance of functioning on without modification.
Jason Evansecae1232016-02-20 23:41:33 -08001057dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
Mike Hommey8f50ec82014-06-04 12:12:55 +09001058dnl ffsl() or __builtin_ffsl() are defined, respectively.
1059JE_COMPILABLE([a program using __builtin_ffsl], [
1060#include <stdio.h>
1061#include <strings.h>
1062#include <string.h>
1063], [
1064 {
1065 int rv = __builtin_ffsl(0x08);
1066 printf("%d\n", rv);
1067 }
1068], [je_cv_gcc_builtin_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001069if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
Jason Evansecae1232016-02-20 23:41:33 -08001070 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
Mike Hommey8f50ec82014-06-04 12:12:55 +09001071 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1072 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1073else
1074 JE_COMPILABLE([a program using ffsl], [
1075 #include <stdio.h>
1076 #include <strings.h>
1077 #include <string.h>
1078 ], [
1079 {
1080 int rv = ffsl(0x08);
1081 printf("%d\n", rv);
1082 }
1083 ], [je_cv_function_ffsl])
Steven Stewart-Gallus79230fe2014-06-19 16:11:43 -07001084 if test "x${je_cv_function_ffsl}" = "xyes" ; then
Jason Evansecae1232016-02-20 23:41:33 -08001085 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
Mike Hommey8f50ec82014-06-04 12:12:55 +09001086 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1087 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1088 else
1089 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1090 fi
1091fi
1092
Jason Evans81e54752014-10-10 22:34:25 -07001093AC_ARG_WITH([lg_tiny_min],
1094 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1095 [Base 2 log of minimum tiny size class to support])],
1096 [LG_TINY_MIN="$with_lg_tiny_min"],
1097 [LG_TINY_MIN="3"])
1098AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1099
Jason Evansfc0b3b72014-10-09 17:54:06 -07001100AC_ARG_WITH([lg_quantum],
1101 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1102 [Base 2 log of minimum allocation alignment])],
Jason Evans81e54752014-10-10 22:34:25 -07001103 [LG_QUANTA="$with_lg_quantum"],
1104 [LG_QUANTA="3 4"])
1105if test "x$with_lg_quantum" != "x" ; then
1106 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1107fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001108
1109AC_ARG_WITH([lg_page],
1110 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1111 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
Jason Evansb0808d52015-02-03 12:39:31 -08001112if test "x$LG_PAGE" = "xdetect"; then
Jason Evansfc0b3b72014-10-09 17:54:06 -07001113 AC_CACHE_CHECK([LG_PAGE],
1114 [je_cv_lg_page],
Jason Evans6684cac2012-03-05 12:15:36 -08001115 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -07001116[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +02001117#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001118#ifdef _WIN32
1119#include <windows.h>
1120#else
Jason Evansb7924f52009-06-23 19:01:18 -07001121#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001122#endif
1123#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -08001124]],
1125[[
Garrett Cooper72c1e592012-12-02 17:57:28 -08001126 int result;
Jason Evansb7924f52009-06-23 19:01:18 -07001127 FILE *f;
1128
Mike Hommeya19e87f2012-04-21 21:27:46 -07001129#ifdef _WIN32
1130 SYSTEM_INFO si;
1131 GetSystemInfo(&si);
1132 result = si.dwPageSize;
1133#else
Jason Evansb7924f52009-06-23 19:01:18 -07001134 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001135#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001136 if (result == -1) {
1137 return 1;
1138 }
Mike Hommey8f50ec82014-06-04 12:12:55 +09001139 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
Mike Hommeya19e87f2012-04-21 21:27:46 -07001140
Jason Evansb7924f52009-06-23 19:01:18 -07001141 f = fopen("conftest.out", "w");
1142 if (f == NULL) {
1143 return 1;
1144 }
rustyxbc498632016-01-30 13:38:33 +01001145 fprintf(f, "%d", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001146 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001147
1148 return 0;
1149]])],
Jason Evansfc0b3b72014-10-09 17:54:06 -07001150 [je_cv_lg_page=`cat conftest.out`],
1151 [je_cv_lg_page=undefined],
1152 [je_cv_lg_page=12]))
Jason Evans6684cac2012-03-05 12:15:36 -08001153fi
Jason Evansfc0b3b72014-10-09 17:54:06 -07001154if test "x${je_cv_lg_page}" != "x" ; then
1155 LG_PAGE="${je_cv_lg_page}"
1156fi
1157if test "x${LG_PAGE}" != "xundefined" ; then
1158 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1159else
1160 AC_MSG_ERROR([cannot determine value for LG_PAGE])
1161fi
1162
1163AC_ARG_WITH([lg_page_sizes],
1164 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1165 [Base 2 logs of system page sizes to support])],
1166 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1167
1168AC_ARG_WITH([lg_size_class_group],
1169 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1170 [Base 2 log of size classes per doubling])],
1171 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1172 [LG_SIZE_CLASS_GROUP="2"])
Jason Evansb7924f52009-06-23 19:01:18 -07001173
1174dnl ============================================================================
1175dnl jemalloc configuration.
1176dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001177
Jason Evans434ea642016-03-14 20:19:11 -07001178AC_ARG_WITH([version],
1179 [AS_HELP_STRING([--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid>],
1180 [Version string])],
1181 [
1182 echo "${with_version}" | grep ['^[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+-g[0-9a-f]\+$'] 2>&1 1>/dev/null
1183 if test $? -ne 0 ; then
1184 AC_MSG_ERROR([${with_version} does not match <major>.<minor>.<bugfix>-<nrev>-g<gid>])
Jason Evansa5a658a2014-09-02 15:07:07 -07001185 fi
Jason Evans434ea642016-03-14 20:19:11 -07001186 echo "$with_version" > "${objroot}VERSION"
1187 ], [
1188 dnl Set VERSION if source directory is inside a git repository.
1189 if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
1190 dnl Pattern globs aren't powerful enough to match both single- and
1191 dnl double-digit version numbers, so iterate over patterns to support up
1192 dnl to version 99.99.99 without any accidental matches.
1193 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1194 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1195 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1196 '[0-9][0-9].[0-9][0-9].[0-9]' \
1197 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
1198 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
1199 if test $? -eq 0 ; then
1200 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
1201 break
1202 fi
1203 done
1204 fi
1205 rm -f "${objroot}VERSION.tmp"
1206 ])
1207
Dan McGregorf8880312014-12-23 16:10:08 -06001208if test ! -e "${objroot}VERSION" ; then
1209 if test ! -e "${srcroot}VERSION" ; then
1210 AC_MSG_RESULT(
1211 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1212 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1213 else
1214 cp ${srcroot}VERSION ${objroot}VERSION
1215 fi
Jason Evansa5a658a2014-09-02 15:07:07 -07001216fi
Dan McGregorf8880312014-12-23 16:10:08 -06001217jemalloc_version=`cat "${objroot}VERSION"`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001218jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1219jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1220jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1221jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1222jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001223AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001224AC_SUBST([jemalloc_version_major])
1225AC_SUBST([jemalloc_version_minor])
1226AC_SUBST([jemalloc_version_bugfix])
1227AC_SUBST([jemalloc_version_nrev])
1228AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001229
1230dnl ============================================================================
1231dnl Configure pthreads.
1232
Mike Hommeya19e87f2012-04-21 21:27:46 -07001233if test "x$abi" != "xpecoff" ; then
1234 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1235 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1236 dnl first, but try libc too before failing.
1237 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1238 [AC_SEARCH_LIBS([pthread_create], , ,
1239 AC_MSG_ERROR([libpthread is missing]))])
1240fi
Jason Evansb7924f52009-06-23 19:01:18 -07001241
1242CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1243
Jason Evansc1e9cf42016-05-03 21:28:20 -07001244dnl Check whether clock_gettime(2) is in libc or librt.
1245AC_SEARCH_LIBS([clock_gettime], [rt])
Jason Evans345c1b02015-09-15 14:59:56 -07001246
Daniel Micayb74041f2014-12-09 17:41:34 -05001247dnl Check if the GNU-specific secure_getenv function exists.
1248AC_CHECK_FUNC([secure_getenv],
1249 [have_secure_getenv="1"],
1250 [have_secure_getenv="0"]
1251 )
1252if test "x$have_secure_getenv" = "x1" ; then
1253 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1254fi
1255
1256dnl Check if the Solaris/BSD issetugid function exists.
1257AC_CHECK_FUNC([issetugid],
1258 [have_issetugid="1"],
1259 [have_issetugid="0"]
1260 )
1261if test "x$have_issetugid" = "x1" ; then
1262 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1263fi
1264
Jason Evanscd9a1342012-03-21 18:33:03 -07001265dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1266dnl it rather than pthreads TSD cleanup functions to support cleanup during
1267dnl thread exit, in order to avoid pthreads library recursion during
1268dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001269AC_CHECK_FUNC([_malloc_thread_cleanup],
1270 [have__malloc_thread_cleanup="1"],
1271 [have__malloc_thread_cleanup="0"]
1272 )
1273if test "x$have__malloc_thread_cleanup" = "x1" ; then
1274 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1275 force_tls="1"
1276fi
1277
Jason Evans41b6afb2012-02-02 22:04:57 -08001278dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1279dnl so, mutex initialization causes allocation, and we need to implement this
1280dnl callback function in order to prevent recursive allocation.
1281AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1282 [have__pthread_mutex_init_calloc_cb="1"],
1283 [have__pthread_mutex_init_calloc_cb="0"]
1284 )
1285if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1286 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1287fi
1288
Jason Evans0fee70d2012-02-13 12:36:11 -08001289dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001290AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001291 [AS_HELP_STRING([--enable-lazy-lock],
1292 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001293[if test "x$enable_lazy_lock" = "xno" ; then
1294 enable_lazy_lock="0"
1295else
1296 enable_lazy_lock="1"
1297fi
1298],
Mike Hommeyac5db022015-08-11 14:01:59 +09001299[enable_lazy_lock=""]
Jason Evansb7924f52009-06-23 19:01:18 -07001300)
Mike Hommeyac5db022015-08-11 14:01:59 +09001301if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
Jason Evansfd4fcef2012-03-23 17:40:58 -07001302 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1303 enable_lazy_lock="1"
1304fi
Jason Evansb7924f52009-06-23 19:01:18 -07001305if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001306 if test "x$abi" != "xpecoff" ; then
1307 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1308 AC_CHECK_FUNC([dlsym], [],
1309 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1310 [AC_MSG_ERROR([libdl is missing])])
1311 ])
1312 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001313 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
Mike Hommeyac5db022015-08-11 14:01:59 +09001314else
1315 enable_lazy_lock="0"
Jason Evansb7924f52009-06-23 19:01:18 -07001316fi
1317AC_SUBST([enable_lazy_lock])
1318
Jason Evans78d815c2010-01-17 14:06:20 -08001319AC_ARG_ENABLE([tls],
1320 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1321if test "x$enable_tls" = "xno" ; then
1322 enable_tls="0"
1323else
1324 enable_tls="1"
1325fi
1326,
Mike Hommeyac5db022015-08-11 14:01:59 +09001327enable_tls=""
Jason Evans78d815c2010-01-17 14:06:20 -08001328)
Jason Evansc0f43b62015-09-02 12:46:35 -07001329if test "x${enable_tls}" = "x" ; then
1330 if test "x${force_tls}" = "x1" ; then
1331 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1332 enable_tls="1"
1333 elif test "x${force_tls}" = "x0" ; then
1334 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1335 enable_tls="0"
1336 else
1337 enable_tls="1"
1338 fi
Jason Evansb80581d2012-03-23 16:17:43 -07001339fi
Jason Evans78d815c2010-01-17 14:06:20 -08001340if test "x${enable_tls}" = "x1" ; then
1341AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001342AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001343[[
1344 __thread int x;
1345]], [[
1346 x = 42;
1347
1348 return 0;
1349]])],
1350 AC_MSG_RESULT([yes]),
1351 AC_MSG_RESULT([no])
1352 enable_tls="0")
Mike Hommeyac5db022015-08-11 14:01:59 +09001353else
1354 enable_tls="0"
Jason Evans78d815c2010-01-17 14:06:20 -08001355fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001356AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001357if test "x${enable_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001358 if test "x${force_tls}" = "x0" ; then
1359 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1360 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001361 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001362elif test "x${force_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001363 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
Jason Evans78d815c2010-01-17 14:06:20 -08001364fi
1365
Jason Evans2dbecf12010-09-05 10:35:13 -07001366dnl ============================================================================
Chih-hung Hsieh59cd80e2014-12-05 17:42:41 -08001367dnl Check for C11 atomics.
1368
1369JE_COMPILABLE([C11 atomics], [
1370#include <stdint.h>
1371#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1372#include <stdatomic.h>
1373#else
1374#error Atomics not available
1375#endif
1376], [
1377 uint64_t *p = (uint64_t *)0;
1378 uint64_t x = 1;
1379 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1380 uint64_t r = atomic_fetch_add(a, x) + x;
1381 return (r == 0);
1382], [je_cv_c11atomics])
1383if test "x${je_cv_c11atomics}" = "xyes" ; then
1384 AC_DEFINE([JEMALLOC_C11ATOMICS])
1385fi
1386
1387dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001388dnl Check for atomic(9) operations as provided on FreeBSD.
1389
1390JE_COMPILABLE([atomic(9)], [
1391#include <sys/types.h>
1392#include <machine/atomic.h>
1393#include <inttypes.h>
1394], [
1395 {
1396 uint32_t x32 = 0;
1397 volatile uint32_t *x32p = &x32;
1398 atomic_fetchadd_32(x32p, 1);
1399 }
1400 {
1401 unsigned long xlong = 0;
1402 volatile unsigned long *xlongp = &xlong;
1403 atomic_fetchadd_long(xlongp, 1);
1404 }
1405], [je_cv_atomic9])
1406if test "x${je_cv_atomic9}" = "xyes" ; then
1407 AC_DEFINE([JEMALLOC_ATOMIC9])
1408fi
1409
1410dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001411dnl Check for atomic(3) operations as provided on Darwin.
1412
1413JE_COMPILABLE([Darwin OSAtomic*()], [
1414#include <libkern/OSAtomic.h>
1415#include <inttypes.h>
1416], [
1417 {
1418 int32_t x32 = 0;
1419 volatile int32_t *x32p = &x32;
1420 OSAtomicAdd32(1, x32p);
1421 }
1422 {
1423 int64_t x64 = 0;
1424 volatile int64_t *x64p = &x64;
1425 OSAtomicAdd64(1, x64p);
1426 }
Jason Evans6684cac2012-03-05 12:15:36 -08001427], [je_cv_osatomic])
1428if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001429 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001430fi
1431
1432dnl ============================================================================
Richard Diamond994fad92014-06-03 02:39:18 -05001433dnl Check for madvise(2).
1434
1435JE_COMPILABLE([madvise(2)], [
1436#include <sys/mman.h>
1437], [
1438 {
1439 madvise((void *)0, 0, 0);
1440 }
1441], [je_cv_madvise])
1442if test "x${je_cv_madvise}" = "xyes" ; then
1443 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1444fi
1445
1446dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001447dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1448dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1449
1450AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1451 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1452 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001453 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1454 #include <stdint.h>
1455 ],
1456 [
1457 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1458 {
1459 uint$1_t x$1 = 0;
1460 __sync_add_and_fetch(&x$1, 42);
1461 __sync_sub_and_fetch(&x$1, 1);
1462 }
1463 #else
1464 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1465 #endif
1466 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001467 [je_cv_sync_compare_and_swap_$2=yes],
1468 [je_cv_sync_compare_and_swap_$2=no])])
1469
1470 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1471 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1472 fi
1473])
1474
Jason Evansb57d3ec2012-04-17 13:17:54 -07001475if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001476 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1477 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1478fi
1479
1480dnl ============================================================================
Jason Evansd04047c2014-05-28 16:11:55 -07001481dnl Check for __builtin_clz() and __builtin_clzl().
1482
1483AC_CACHE_CHECK([for __builtin_clz],
1484 [je_cv_builtin_clz],
1485 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1486 [
1487 {
1488 unsigned x = 0;
1489 int y = __builtin_clz(x);
1490 }
1491 {
1492 unsigned long x = 0;
1493 int y = __builtin_clzl(x);
1494 }
1495 ])],
1496 [je_cv_builtin_clz=yes],
1497 [je_cv_builtin_clz=no])])
1498
1499if test "x${je_cv_builtin_clz}" = "xyes" ; then
1500 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1501fi
1502
1503dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001504dnl Check for spinlock(3) operations as provided on Darwin.
1505
1506JE_COMPILABLE([Darwin OSSpin*()], [
1507#include <libkern/OSAtomic.h>
1508#include <inttypes.h>
1509], [
1510 OSSpinLock lock = 0;
1511 OSSpinLockLock(&lock);
1512 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001513], [je_cv_osspin])
1514if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001515 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001516fi
1517
1518dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001519dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001520
Mike Hommeyd0357f72012-11-26 18:52:41 +01001521AC_ARG_ENABLE([zone-allocator],
1522 [AS_HELP_STRING([--disable-zone-allocator],
1523 [Disable zone allocator for Darwin])],
1524[if test "x$enable_zone_allocator" = "xno" ; then
1525 enable_zone_allocator="0"
1526else
1527 enable_zone_allocator="1"
1528fi
1529],
1530[if test "x${abi}" = "xmacho"; then
1531 enable_zone_allocator="1"
1532fi
1533]
1534)
1535AC_SUBST([enable_zone_allocator])
1536
1537if test "x${enable_zone_allocator}" = "x1" ; then
1538 if test "x${abi}" != "xmacho"; then
1539 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1540 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001541 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001542
Jason Evans2dbecf12010-09-05 10:35:13 -07001543 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1544 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1545 dnl 10.6, which is the only source-level indication of the change.
1546 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001547 AC_DEFUN([JE_ZONE_PROGRAM],
1548 [AC_LANG_PROGRAM(
1549 [#include <malloc/malloc.h>],
Guilherme Goncalves79725aa2014-10-20 14:08:37 -02001550 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
Mike Hommey154829d2012-03-20 18:01:38 +01001551 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001552
Mike Hommey154829d2012-03-20 18:01:38 +01001553 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1554 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1555 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1556 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1557 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1558 )])],[
1559 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1560 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1561 )])])])])
1562 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1563 AC_MSG_RESULT([unsupported])
1564 AC_MSG_ERROR([Unsupported malloc zone version])
1565 fi
1566 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1567 JEMALLOC_ZONE_VERSION=8
1568 AC_MSG_RESULT([> 8])
1569 else
1570 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1571 fi
1572 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001573fi
1574
Jason Evansb7924f52009-06-23 19:01:18 -07001575dnl ============================================================================
Sara Golemon3e24afa2014-08-18 13:06:39 -07001576dnl Check for glibc malloc hooks
1577
1578JE_COMPILABLE([glibc malloc hook], [
1579#include <stddef.h>
1580
1581extern void (* __free_hook)(void *ptr);
1582extern void *(* __malloc_hook)(size_t size);
1583extern void *(* __realloc_hook)(void *ptr, size_t size);
1584], [
1585 void *ptr = 0L;
1586 if (__malloc_hook) ptr = __malloc_hook(1);
1587 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1588 if (__free_hook && ptr) __free_hook(ptr);
1589], [je_cv_glibc_malloc_hook])
1590if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1591 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1592fi
1593
1594JE_COMPILABLE([glibc memalign hook], [
1595#include <stddef.h>
1596
1597extern void *(* __memalign_hook)(size_t alignment, size_t size);
1598], [
1599 void *ptr = 0L;
1600 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1601], [je_cv_glibc_memalign_hook])
1602if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1603 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1604fi
1605
Eric Wong4dcf04b2014-08-31 03:57:06 +00001606JE_COMPILABLE([pthreads adaptive mutexes], [
1607#include <pthread.h>
1608], [
1609 pthread_mutexattr_t attr;
1610 pthread_mutexattr_init(&attr);
1611 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1612 pthread_mutexattr_destroy(&attr);
1613], [je_cv_pthread_mutex_adaptive_np])
1614if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1615 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1616fi
1617
Sara Golemon3e24afa2014-08-18 13:06:39 -07001618dnl ============================================================================
Jason Evansb7924f52009-06-23 19:01:18 -07001619dnl Check for typedefs, structures, and compiler characteristics.
1620AC_HEADER_STDBOOL
1621
Jason Evans748dfac2013-12-06 18:27:33 -08001622dnl ============================================================================
1623dnl Define commands that generate output files.
1624
Jason Evans86abd0d2013-11-30 15:25:42 -08001625AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1626 mkdir -p "${objroot}include/jemalloc/internal"
1627 "${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 -08001628], [
1629 srcdir="${srcdir}"
1630 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001631])
1632AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1633 mkdir -p "${objroot}include/jemalloc/internal"
1634 "${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 -08001635], [
1636 srcdir="${srcdir}"
1637 objroot="${objroot}"
1638])
1639AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1640 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1641 mkdir -p "${objroot}include/jemalloc/internal"
1642 cp /dev/null "${f}"
1643 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1644 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1645 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1646 echo "${n}:${m}" >> "${f}"
1647 dnl Remove name from public_syms so that it isn't redefined later.
1648 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1649 done
1650 for sym in ${public_syms} ; do
1651 n="${sym}"
1652 m="${JEMALLOC_PREFIX}${sym}"
1653 echo "${n}:${m}" >> "${f}"
1654 done
1655], [
1656 srcdir="${srcdir}"
1657 objroot="${objroot}"
1658 mangling_map="${mangling_map}"
1659 public_syms="${public_syms}"
1660 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001661])
1662AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1663 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001664 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1665], [
1666 srcdir="${srcdir}"
1667 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001668])
1669AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1670 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001671 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1672], [
1673 srcdir="${srcdir}"
1674 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001675])
Jason Evansb1726102012-02-28 16:50:47 -08001676AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001677 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evans6d919292015-09-15 10:42:36 -07001678 "${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 -08001679], [
Jason Evans6d919292015-09-15 10:42:36 -07001680 SHELL="${SHELL}"
Jason Evansf234dc52014-01-16 17:38:01 -08001681 srcdir="${srcdir}"
1682 objroot="${objroot}"
Jason Evans81e54752014-10-10 22:34:25 -07001683 LG_QUANTA="${LG_QUANTA}"
1684 LG_TINY_MIN=${LG_TINY_MIN}
1685 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
Jason Evansfc0b3b72014-10-09 17:54:06 -07001686 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
Jason Evansb1726102012-02-28 16:50:47 -08001687])
Jason Evans86abd0d2013-11-30 15:25:42 -08001688AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1689 mkdir -p "${objroot}include/jemalloc"
1690 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 -08001691], [
1692 srcdir="${srcdir}"
1693 objroot="${objroot}"
1694])
1695AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1696 mkdir -p "${objroot}include/jemalloc"
1697 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1698], [
1699 srcdir="${srcdir}"
1700 objroot="${objroot}"
1701])
1702AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1703 mkdir -p "${objroot}include/jemalloc"
1704 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1705], [
1706 srcdir="${srcdir}"
1707 objroot="${objroot}"
1708])
1709AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1710 mkdir -p "${objroot}include/jemalloc"
1711 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1712], [
1713 srcdir="${srcdir}"
1714 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001715])
1716AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1717 mkdir -p "${objroot}include/jemalloc"
1718 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001719], [
1720 srcdir="${srcdir}"
1721 objroot="${objroot}"
1722 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001723])
Jason Evansb1726102012-02-28 16:50:47 -08001724
Jason Evansb7924f52009-06-23 19:01:18 -07001725dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001726AC_SUBST([cfghdrs_in])
1727AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001728AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001729
1730dnl ============================================================================
1731dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001732
Jason Evans70417202015-05-01 12:31:12 -07001733AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
Jason Evansb0fd5012010-01-17 01:49:20 -08001734AC_SUBST([cfgoutputs_in])
1735AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001736AC_OUTPUT
1737
1738dnl ============================================================================
1739dnl Print out the results of configuration.
1740AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001741AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1742AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001743AC_MSG_RESULT([])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001744AC_MSG_RESULT([CONFIG : ${CONFIG}])
Jason Evansb7924f52009-06-23 19:01:18 -07001745AC_MSG_RESULT([CC : ${CC}])
Jason Evansb7924f52009-06-23 19:01:18 -07001746AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001747AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001748AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001749AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001750AC_MSG_RESULT([LIBS : ${LIBS}])
1751AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1752AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001753AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1754AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1755AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001756AC_MSG_RESULT([PREFIX : ${PREFIX}])
1757AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evansbec6a8d2015-01-22 17:55:58 -08001758AC_MSG_RESULT([DATADIR : ${DATADIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001759AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1760AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001761AC_MSG_RESULT([MANDIR : ${MANDIR}])
1762AC_MSG_RESULT([])
1763AC_MSG_RESULT([srcroot : ${srcroot}])
1764AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1765AC_MSG_RESULT([objroot : ${objroot}])
1766AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1767AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001768AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001769AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1770AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001771AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansf8290092016-02-07 14:23:22 -08001772AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
Jason Evansb7924f52009-06-23 19:01:18 -07001773AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001774AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001775AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001776AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001777AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001778AC_MSG_RESULT([prof : ${enable_prof}])
1779AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001780AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1781AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001782AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001783AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001784AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001785AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1786AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001787AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001788AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001789AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evans8a03cf02015-05-04 09:58:36 -07001790AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
Jason Evansb7924f52009-06-23 19:01:18 -07001791AC_MSG_RESULT([===============================================================================])