blob: 7d64ada4878d785d4c7bbfa8bdc4bb98881b09e3 [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
Christopher Ferris83e57672015-04-22 06:59:28 +000048CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
49AC_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])
Christopher Ferris83e57672015-04-22 06:59:28 +0000142 JE_CFLAGS_APPEND([-Werror=declaration-after-statement])
Christopher Ferrise4294032016-03-02 14:33:02 -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 Hommeydc22ae52014-05-29 16:58:21 +0900151 JE_CFLAGS_APPEND([-FS])
Mike Hommey8ba88b72014-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 Hommeyc2bc2a42014-05-29 16:33:02 +0900166if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
Mike Hommey8ba88b72014-05-29 17:01:10 +0900167 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
Mike Hommeyc2bc2a42014-05-29 16:33:02 +0900168fi
169
Christopher Ferrise4294032016-03-02 14:33:02 -0800170if 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
Christopher Ferrise4294032016-03-02 14:33:02 -0800174 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
Christopher Ferrise4294032016-03-02 14:33:02 -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)
Christopher Ferrise4294032016-03-02 14:33:02 -0800232 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 Hiora90ecea92014-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 Evansbad7ed02015-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 ;;
Christopher Ferris83e57672015-04-22 06:59:28 +0000310 *-*-dragonfly*)
311 CFLAGS="$CFLAGS"
312 abi="elf"
313 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
314 ;;
315 *-*-openbsd*|*-*-bitrig*)
316 CFLAGS="$CFLAGS"
317 abi="elf"
318 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
319 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700320 *-*-linux*)
321 CFLAGS="$CFLAGS"
322 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
323 abi="elf"
Garrett Cooper13e4e242012-12-02 17:58:40 -0800324 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
Jason Evanse24c7af2012-03-19 10:21:17 -0700325 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
Jason Evans02b23122012-04-05 11:06:23 -0700326 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
Jason Evansae93d6b2015-07-10 14:33:00 -0700327 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
Jason Evans59ae2762012-04-16 17:52:27 -0700328 default_munmap="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700329 ;;
330 *-*-netbsd*)
331 AC_MSG_CHECKING([ABI])
332 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
333[[#ifdef __ELF__
334/* ELF */
335#else
336#error aout
337#endif
338]])],
339 [CFLAGS="$CFLAGS"; abi="elf"],
340 [abi="aout"])
341 AC_MSG_RESULT([$abi])
Jason Evanse24c7af2012-03-19 10:21:17 -0700342 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700343 ;;
344 *-*-solaris2*)
345 CFLAGS="$CFLAGS"
346 abi="elf"
George Koladdd6bd42014-02-12 23:05:45 +0000347 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200348 RPATH='-Wl,-R,$(1)'
Jason Evansb7924f52009-06-23 19:01:18 -0700349 dnl Solaris needs this for sigwait().
350 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
351 LIBS="$LIBS -lposix4 -lsocket -lnsl"
352 ;;
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400353 *-ibm-aix*)
354 if "$LG_SIZEOF_PTR" = "8"; then
355 dnl 64bit AIX
356 LD_PRELOAD_VAR="LDR_PRELOAD64"
357 else
358 dnl 32bit AIX
359 LD_PRELOAD_VAR="LDR_PRELOAD"
360 fi
361 abi="xcoff"
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400362 ;;
Christopher Ferris83e57672015-04-22 06:59:28 +0000363 *-*-mingw* | *-*-cygwin*)
Mike Hommeya19e87f2012-04-21 21:27:46 -0700364 abi="pecoff"
365 force_tls="0"
Jason Evans13473c72015-07-23 14:08:49 -0700366 force_lazy_lock="1"
Jason Evansd059b9d2015-07-24 18:21:42 -0700367 maps_coalesce="0"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700368 RPATH=""
369 so="dll"
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200370 if test "x$je_cv_msvc" = "xyes" ; then
371 importlib="lib"
372 DSO_LDFLAGS="-LD"
373 EXTRA_LDFLAGS="-link -DEBUG"
374 CTARGET='-Fo$@'
375 LDTARGET='-Fe$@'
Jory A. Prattad505e02013-08-11 09:44:59 -0500376 AR='lib'
377 ARFLAGS='-nologo -out:'
Jason Evans80ddf492013-08-20 11:48:19 +0100378 AROUT='$@'
Mike Hommey79c4bca2012-05-02 21:30:51 +0200379 CC_MM=
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200380 else
381 importlib="${so}"
382 DSO_LDFLAGS="-shared"
383 fi
Mike Hommeya19e87f2012-04-21 21:27:46 -0700384 a="lib"
385 libprefix=""
Mike Hommey7cdea392012-04-30 12:38:27 +0200386 SOREV="${so}"
Mike Hommeya19e87f2012-04-21 21:27:46 -0700387 PIC_CFLAGS=""
388 ;;
Jason Evansb7924f52009-06-23 19:01:18 -0700389 *)
390 AC_MSG_RESULT([Unsupported operating system: ${host}])
391 abi="elf"
Jason Evansb7924f52009-06-23 19:01:18 -0700392 ;;
393esac
Mike Hommey5fb06562014-05-28 08:10:12 +0900394
395JEMALLOC_USABLE_SIZE_CONST=const
396AC_CHECK_HEADERS([malloc.h], [
397 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
398 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
399 [#include <malloc.h>
400 #include <stddef.h>
401 size_t malloc_usable_size(const void *ptr);
402 ],
403 [])],[
404 AC_MSG_RESULT([yes])
405 ],[
406 JEMALLOC_USABLE_SIZE_CONST=
407 AC_MSG_RESULT([no])
408 ])
409])
Jason Evans247d1242012-10-09 16:20:10 -0700410AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
Jason Evansb7924f52009-06-23 19:01:18 -0700411AC_SUBST([abi])
412AC_SUBST([RPATH])
Antony Dovgal2bd3cbc2011-10-13 09:33:33 +0400413AC_SUBST([LD_PRELOAD_VAR])
Jason Evansf576c632011-11-01 22:27:41 -0700414AC_SUBST([so])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200415AC_SUBST([importlib])
Mike Hommey5bee66d2012-04-16 16:30:24 +0200416AC_SUBST([o])
417AC_SUBST([a])
418AC_SUBST([exe])
Mike Hommeya19e87f2012-04-21 21:27:46 -0700419AC_SUBST([libprefix])
Mike Hommeyfa08da72012-04-16 16:30:25 +0200420AC_SUBST([DSO_LDFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200421AC_SUBST([EXTRA_LDFLAGS])
Mike Hommey85221d52012-04-18 18:29:40 +0200422AC_SUBST([SOREV])
Mike Hommey188da7c2012-04-18 18:29:41 +0200423AC_SUBST([PIC_CFLAGS])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200424AC_SUBST([CTARGET])
425AC_SUBST([LDTARGET])
426AC_SUBST([MKLIB])
Jason Evans80ddf492013-08-20 11:48:19 +0100427AC_SUBST([ARFLAGS])
428AC_SUBST([AROUT])
Mike Hommey79c4bca2012-05-02 21:30:51 +0200429AC_SUBST([CC_MM])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200430
Jason Evansfa5d2452011-03-15 10:25:59 -0700431JE_COMPILABLE([__attribute__ syntax],
432 [static __attribute__((unused)) void foo(void){}],
433 [],
Jason Evans6684cac2012-03-05 12:15:36 -0800434 [je_cv_attribute])
435if test "x${je_cv_attribute}" = "xyes" ; then
Jason Evansfa5d2452011-03-15 10:25:59 -0700436 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
437 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
438 JE_CFLAGS_APPEND([-fvisibility=hidden])
439 fi
440fi
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700441dnl Check for tls_model attribute support (clang 3.0 still lacks support).
442SAVED_CFLAGS="${CFLAGS}"
443JE_CFLAGS_APPEND([-Werror])
444JE_COMPILABLE([tls_model attribute], [],
445 [static __thread int
Christopher Ferris83e57672015-04-22 06:59:28 +0000446 __attribute__((tls_model("initial-exec"), unused)) foo;
Jason Evans3cc1f1a2012-04-03 22:30:05 -0700447 foo = 0;],
448 [je_cv_tls_model])
449CFLAGS="${SAVED_CFLAGS}"
450if test "x${je_cv_tls_model}" = "xyes" ; then
451 AC_DEFINE([JEMALLOC_TLS_MODEL],
452 [__attribute__((tls_model("initial-exec")))])
453else
454 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
455fi
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700456dnl Check for alloc_size attribute support.
457SAVED_CFLAGS="${CFLAGS}"
458JE_CFLAGS_APPEND([-Werror])
Jason Evans92d72ee2015-07-10 16:45:32 -0700459JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
460 [void *foo(size_t size) __attribute__((alloc_size(1)));],
Jason Evans0b8f0bc2015-07-10 16:41:12 -0700461 [je_cv_alloc_size])
462CFLAGS="${SAVED_CFLAGS}"
463if test "x${je_cv_alloc_size}" = "xyes" ; then
464 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
465fi
Jason Evanse42c3092015-07-22 15:44:47 -0700466dnl Check for format(gnu_printf, ...) attribute support.
467SAVED_CFLAGS="${CFLAGS}"
468JE_CFLAGS_APPEND([-Werror])
469JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
470 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
471 [je_cv_format_gnu_printf])
472CFLAGS="${SAVED_CFLAGS}"
473if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
474 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
475fi
476dnl Check for format(printf, ...) attribute support.
477SAVED_CFLAGS="${CFLAGS}"
478JE_CFLAGS_APPEND([-Werror])
479JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
480 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
481 [je_cv_format_printf])
482CFLAGS="${SAVED_CFLAGS}"
483if test "x${je_cv_format_printf}" = "xyes" ; then
484 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
485fi
Jason Evansfa5d2452011-03-15 10:25:59 -0700486
Jason Evansb7924f52009-06-23 19:01:18 -0700487dnl Support optional additions to rpath.
488AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800489 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700490if test "x$with_rpath" = "xno" ; then
491 RPATH_EXTRA=
492else
493 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
494fi,
495 RPATH_EXTRA=
496)
497AC_SUBST([RPATH_EXTRA])
498
499dnl Disable rules that do automatic regeneration of configure output by default.
500AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800501 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700502if test "x$enable_autogen" = "xno" ; then
503 enable_autogen="0"
504else
505 enable_autogen="1"
506fi
507,
508enable_autogen="0"
509)
510AC_SUBST([enable_autogen])
511
512AC_PROG_INSTALL
513AC_PROG_RANLIB
Jason Evans7329a4f2013-01-22 10:53:29 -0800514AC_PATH_PROG([LD], [ld], [false], [$PATH])
515AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
Jason Evansb7924f52009-06-23 19:01:18 -0700516
Christopher Ferris83e57672015-04-22 06:59:28 +0000517public_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 -0800518
519dnl Check for allocator-related functions that should be wrapped.
520AC_CHECK_FUNC([memalign],
Jason Evanse24c7af2012-03-19 10:21:17 -0700521 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800522 public_syms="${public_syms} memalign"])
523AC_CHECK_FUNC([valloc],
Jason Evanse24c7af2012-03-19 10:21:17 -0700524 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
Jason Evans7e77eaf2012-03-02 17:47:37 -0800525 public_syms="${public_syms} valloc"])
526
Jason Evans748dfac2013-12-06 18:27:33 -0800527dnl Do not compute test code coverage by default.
528GCOV_FLAGS=
529AC_ARG_ENABLE([code-coverage],
530 [AS_HELP_STRING([--enable-code-coverage],
531 [Enable code coverage])],
532[if test "x$enable_code_coverage" = "xno" ; then
533 enable_code_coverage="0"
534else
535 enable_code_coverage="1"
536fi
537],
538[enable_code_coverage="0"]
539)
540if test "x$enable_code_coverage" = "x1" ; then
541 deoptimize="no"
542 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
543 if test "x${deoptimize}" = "xyes" ; then
544 JE_CFLAGS_APPEND([-O0])
545 fi
546 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
547 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
548 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
549fi
550AC_SUBST([enable_code_coverage])
551
Jason Evans0a5489e2012-03-01 17:19:20 -0800552dnl Perform no name mangling by default.
553AC_ARG_WITH([mangling],
554 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
555 [mangling_map="$with_mangling"], [mangling_map=""])
Jason Evans0a5489e2012-03-01 17:19:20 -0800556
Jason Evans90895cf2009-12-29 00:09:15 -0800557dnl Do not prefix public APIs by default.
558AC_ARG_WITH([jemalloc_prefix],
559 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800560 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Mike Hommey7cdea392012-04-30 12:38:27 +0200561 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
Jason Evans2dbecf12010-09-05 10:35:13 -0700562 JEMALLOC_PREFIX=""
563else
564 JEMALLOC_PREFIX="je_"
565fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800566)
567if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700568 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
569 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
570 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evans90895cf2009-12-29 00:09:15 -0800571fi
Jason Evans241abc62015-06-23 18:47:07 -0700572AC_SUBST([JEMALLOC_CPREFIX])
Jason Evans90895cf2009-12-29 00:09:15 -0800573
Mike Hommey99066602012-11-19 10:55:26 +0100574AC_ARG_WITH([export],
575 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
576 [if test "x$with_export" = "xno"; then
Jason Evans2625c892013-01-22 16:46:27 -0800577 AC_DEFINE([JEMALLOC_EXPORT],[])
Mike Hommey99066602012-11-19 10:55:26 +0100578fi]
579)
580
Jason Evans86abd0d2013-11-30 15:25:42 -0800581dnl Mangle library-private APIs.
Jason Evans746e77a2011-07-30 16:40:52 -0700582AC_ARG_WITH([private_namespace],
583 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
Jason Evans86abd0d2013-11-30 15:25:42 -0800584 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
585 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
Jason Evans746e77a2011-07-30 16:40:52 -0700586)
Jason Evans86abd0d2013-11-30 15:25:42 -0800587AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
588private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
589AC_SUBST([private_namespace])
Jason Evans746e77a2011-07-30 16:40:52 -0700590
Jason Evansb0fd5012010-01-17 01:49:20 -0800591dnl Do not add suffix to installed files by default.
592AC_ARG_WITH([install_suffix],
593 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
594 [INSTALL_SUFFIX="$with_install_suffix"],
595 [INSTALL_SUFFIX=]
596)
597install_suffix="$INSTALL_SUFFIX"
598AC_SUBST([install_suffix])
599
Christopher Ferrise4294032016-03-02 14:33:02 -0800600dnl Specify default malloc_conf.
601AC_ARG_WITH([malloc_conf],
602 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
603 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
604 [JEMALLOC_CONFIG_MALLOC_CONF=""]
605)
606config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
607AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
608
Jason Evans86abd0d2013-11-30 15:25:42 -0800609dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
610dnl jemalloc_protos_jet.h easy.
611je_="je_"
612AC_SUBST([je_])
613
Christopher Ferris83e57672015-04-22 06:59:28 +0000614cfgoutputs_in="Makefile.in"
615cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
616cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
617cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
618cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
619cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
620cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
621cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
622cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
623cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
624cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800625
Jason Evansaee7fd22010-11-24 22:00:02 -0800626cfgoutputs_out="Makefile"
Christopher Ferris83e57672015-04-22 06:59:28 +0000627cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
Jason Evansaee7fd22010-11-24 22:00:02 -0800628cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
629cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
Jason Evans86abd0d2013-11-30 15:25:42 -0800630cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
631cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
632cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
Christopher Ferris83e57672015-04-22 06:59:28 +0000633cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
Jason Evans376b1522010-02-11 14:45:59 -0800634cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800635cfgoutputs_out="${cfgoutputs_out} test/test.sh"
636cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800637
Jason Evansaee7fd22010-11-24 22:00:02 -0800638cfgoutputs_tup="Makefile"
Christopher Ferris83e57672015-04-22 06:59:28 +0000639cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
Jason Evansaee7fd22010-11-24 22:00:02 -0800640cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
641cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
Jason Evans86abd0d2013-11-30 15:25:42 -0800642cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
643cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
644cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
Christopher Ferris83e57672015-04-22 06:59:28 +0000645cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
Jason Evans376b1522010-02-11 14:45:59 -0800646cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800647cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
648cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800649
Christopher Ferris83e57672015-04-22 06:59:28 +0000650cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
651cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
652cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
653cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
654cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
655cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
656cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
657cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
658cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
659cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
660cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
661cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800662
Jason Evans86abd0d2013-11-30 15:25:42 -0800663cfghdrs_out="include/jemalloc/jemalloc_defs.h"
664cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
Jason Evans86abd0d2013-11-30 15:25:42 -0800665cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
666cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800667cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
Jason Evans86abd0d2013-11-30 15:25:42 -0800668cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
669cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
Jason Evansb1726102012-02-28 16:50:47 -0800670cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
Jason Evansf234dc52014-01-16 17:38:01 -0800671cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
672cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
673cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
674cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
675cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
Jason Evans80061b62013-12-09 13:21:08 -0800676cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800677
Jason Evans86abd0d2013-11-30 15:25:42 -0800678cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
Christopher Ferris83e57672015-04-22 06:59:28 +0000679cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
680cfghdrs_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 -0800681
Jason Evans644d4142014-04-14 22:49:23 -0700682dnl Silence irrelevant compiler warnings by default.
Jason Evans355b4382010-09-20 19:20:48 -0700683AC_ARG_ENABLE([cc-silence],
Jason Evans644d4142014-04-14 22:49:23 -0700684 [AS_HELP_STRING([--disable-cc-silence],
685 [Do not silence irrelevant compiler warnings])],
Jason Evans355b4382010-09-20 19:20:48 -0700686[if test "x$enable_cc_silence" = "xno" ; then
687 enable_cc_silence="0"
688else
689 enable_cc_silence="1"
690fi
691],
Jason Evans644d4142014-04-14 22:49:23 -0700692[enable_cc_silence="1"]
Jason Evans355b4382010-09-20 19:20:48 -0700693)
694if test "x$enable_cc_silence" = "x1" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -0700695 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
Jason Evans355b4382010-09-20 19:20:48 -0700696fi
697
Jason Evansb7924f52009-06-23 19:01:18 -0700698dnl Do not compile with debugging by default.
699AC_ARG_ENABLE([debug],
Christopher Ferris83e57672015-04-22 06:59:28 +0000700 [AS_HELP_STRING([--enable-debug],
701 [Build debugging code (implies --enable-ivsalloc)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700702[if test "x$enable_debug" = "xno" ; then
703 enable_debug="0"
704else
705 enable_debug="1"
706fi
707],
708[enable_debug="0"]
709)
710if test "x$enable_debug" = "x1" ; then
711 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Christopher Ferris83e57672015-04-22 06:59:28 +0000712fi
713if test "x$enable_debug" = "x1" ; then
714 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Mike Hommey5135e342012-12-06 22:16:26 +0100715 enable_ivsalloc="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700716fi
717AC_SUBST([enable_debug])
718
Mike Hommey5135e342012-12-06 22:16:26 +0100719dnl Do not validate pointers by default.
720AC_ARG_ENABLE([ivsalloc],
Christopher Ferris83e57672015-04-22 06:59:28 +0000721 [AS_HELP_STRING([--enable-ivsalloc],
722 [Validate pointers passed through the public API])],
Mike Hommey5135e342012-12-06 22:16:26 +0100723[if test "x$enable_ivsalloc" = "xno" ; then
724 enable_ivsalloc="0"
725else
726 enable_ivsalloc="1"
727fi
728],
729[enable_ivsalloc="0"]
730)
731if test "x$enable_ivsalloc" = "x1" ; then
732 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
733fi
734
Jason Evansb7924f52009-06-23 19:01:18 -0700735dnl Only optimize if not debugging.
736if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
737 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700738 optimize="no"
Jason Evans748dfac2013-12-06 18:27:33 -0800739 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
Jason Evansf3340ca2009-06-30 16:17:05 -0700740 if test "x${optimize}" = "xyes" ; then
741 if test "x$GCC" = "xyes" ; then
742 JE_CFLAGS_APPEND([-O3])
743 JE_CFLAGS_APPEND([-funroll-loops])
Mike Hommeyfd97b1d2012-04-30 12:38:31 +0200744 elif test "x$je_cv_msvc" = "xyes" ; then
745 JE_CFLAGS_APPEND([-O2])
Jason Evansf3340ca2009-06-30 16:17:05 -0700746 else
747 JE_CFLAGS_APPEND([-O])
748 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700749 fi
750fi
751
Jason Evansd073a322012-02-28 20:41:16 -0800752dnl Enable statistics calculation by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700753AC_ARG_ENABLE([stats],
Jason Evans777c1912012-02-28 20:49:22 -0800754 [AS_HELP_STRING([--disable-stats],
755 [Disable statistics calculation/reporting])],
Jason Evansb7924f52009-06-23 19:01:18 -0700756[if test "x$enable_stats" = "xno" ; then
757 enable_stats="0"
758else
759 enable_stats="1"
760fi
761],
Jason Evansd073a322012-02-28 20:41:16 -0800762[enable_stats="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700763)
764if test "x$enable_stats" = "x1" ; then
765 AC_DEFINE([JEMALLOC_STATS], [ ])
766fi
767AC_SUBST([enable_stats])
768
Jason Evans6109fe02010-02-10 10:37:56 -0800769dnl Do not enable profiling by default.
770AC_ARG_ENABLE([prof],
771 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
772[if test "x$enable_prof" = "xno" ; then
773 enable_prof="0"
774else
775 enable_prof="1"
776fi
777],
778[enable_prof="0"]
779)
Jason Evans77f350b2011-03-15 22:23:12 -0700780if test "x$enable_prof" = "x1" ; then
781 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800782else
Jason Evans77f350b2011-03-15 22:23:12 -0700783 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800784fi
Jason Evans77f350b2011-03-15 22:23:12 -0700785
Jason Evans6109fe02010-02-10 10:37:56 -0800786AC_ARG_ENABLE([prof-libunwind],
787 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
788[if test "x$enable_prof_libunwind" = "xno" ; then
789 enable_prof_libunwind="0"
790else
791 enable_prof_libunwind="1"
792fi
793],
794[enable_prof_libunwind="0"]
795)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800796AC_ARG_WITH([static_libunwind],
797 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
798 [Path to static libunwind library; use rather than dynamically linking])],
799if test "x$with_static_libunwind" = "xno" ; then
800 LUNWIND="-lunwind"
801else
802 if test ! -f "$with_static_libunwind" ; then
803 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
804 fi
805 LUNWIND="$with_static_libunwind"
806fi,
807 LUNWIND="-lunwind"
808)
Jason Evans77f350b2011-03-15 22:23:12 -0700809if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
810 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
811 if test "x$LUNWIND" = "x-lunwind" ; then
Jason Evans835cc0a2014-04-22 20:48:07 -0700812 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
Jason Evans77f350b2011-03-15 22:23:12 -0700813 [enable_prof_libunwind="0"])
814 else
815 LIBS="$LIBS $LUNWIND"
816 fi
817 if test "x${enable_prof_libunwind}" = "x1" ; then
818 backtrace_method="libunwind"
819 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
820 fi
821fi
822
823AC_ARG_ENABLE([prof-libgcc],
824 [AS_HELP_STRING([--disable-prof-libgcc],
825 [Do not use libgcc for backtracing])],
826[if test "x$enable_prof_libgcc" = "xno" ; then
827 enable_prof_libgcc="0"
828else
829 enable_prof_libgcc="1"
830fi
831],
832[enable_prof_libgcc="1"]
833)
834if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
835 -a "x$GCC" = "xyes" ; then
836 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
837 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
Jason Evans77f350b2011-03-15 22:23:12 -0700838 if test "x${enable_prof_libgcc}" = "x1" ; then
839 backtrace_method="libgcc"
840 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
841 fi
842else
843 enable_prof_libgcc="0"
844fi
845
846AC_ARG_ENABLE([prof-gcc],
847 [AS_HELP_STRING([--disable-prof-gcc],
848 [Do not use gcc intrinsics for backtracing])],
849[if test "x$enable_prof_gcc" = "xno" ; then
850 enable_prof_gcc="0"
851else
852 enable_prof_gcc="1"
853fi
854],
855[enable_prof_gcc="1"]
856)
857if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
858 -a "x$GCC" = "xyes" ; then
Jason Evanse181f5a2014-03-30 18:58:32 -0700859 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
Jason Evans77f350b2011-03-15 22:23:12 -0700860 backtrace_method="gcc intrinsics"
861 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
862else
863 enable_prof_gcc="0"
864fi
865
866if test "x$backtrace_method" = "x" ; then
867 backtrace_method="none (disabling profiling)"
868 enable_prof="0"
869fi
870AC_MSG_CHECKING([configured backtracing method])
871AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700872if test "x$enable_prof" = "x1" ; then
Jason Evansd37d5ad2013-12-05 23:01:50 -0800873 if test "x$abi" != "xpecoff"; then
874 dnl Heap profiling uses the log(3) function.
875 LIBS="$LIBS -lm"
876 fi
877
Jason Evans2dbecf12010-09-05 10:35:13 -0700878 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700879fi
880AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700881
Jason Evans84cbbcb2009-12-29 00:09:15 -0800882dnl Enable thread-specific caching by default.
883AC_ARG_ENABLE([tcache],
884 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
885[if test "x$enable_tcache" = "xno" ; then
886 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700887else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800888 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700889fi
890],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800891[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700892)
Jason Evans2dbecf12010-09-05 10:35:13 -0700893if test "x$enable_tcache" = "x1" ; then
894 AC_DEFINE([JEMALLOC_TCACHE], [ ])
895fi
896AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700897
Jason Evansd059b9d2015-07-24 18:21:42 -0700898dnl Indicate whether adjacent virtual memory mappings automatically coalesce
899dnl (and fragment on demand).
900if test "x${maps_coalesce}" = "x1" ; then
901 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
902fi
903
Jason Evans59ae2762012-04-16 17:52:27 -0700904dnl Enable VM deallocation via munmap() by default.
905AC_ARG_ENABLE([munmap],
906 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
907[if test "x$enable_munmap" = "xno" ; then
908 enable_munmap="0"
909else
910 enable_munmap="1"
911fi
912],
913[enable_munmap="${default_munmap}"]
914)
915if test "x$enable_munmap" = "x1" ; then
916 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
917fi
918AC_SUBST([enable_munmap])
919
Jason Evans4d434ad2014-04-15 12:09:48 -0700920dnl Enable allocation from DSS if supported by the OS.
921have_dss="1"
Mike Hommey83c324a2012-04-12 10:13:03 +0200922dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
923AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
924if test "x$have_sbrk" = "x1" ; then
Christopher Ferris83e57672015-04-22 06:59:28 +0000925 if test "x$sbrk_deprecated" = "x1" ; then
Jason Evans66688532013-12-03 21:49:36 -0800926 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
Jason Evans4d434ad2014-04-15 12:09:48 -0700927 have_dss="0"
Jason Evans66688532013-12-03 21:49:36 -0800928 fi
Mike Hommey83c324a2012-04-12 10:13:03 +0200929else
Jason Evans4d434ad2014-04-15 12:09:48 -0700930 have_dss="0"
Mike Hommey83c324a2012-04-12 10:13:03 +0200931fi
932
Jason Evans4d434ad2014-04-15 12:09:48 -0700933if test "x$have_dss" = "x1" ; then
Jason Evansb7924f52009-06-23 19:01:18 -0700934 AC_DEFINE([JEMALLOC_DSS], [ ])
935fi
Jason Evansb7924f52009-06-23 19:01:18 -0700936
Jason Evans777c1912012-02-28 20:49:22 -0800937dnl Support the junk/zero filling option by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700938AC_ARG_ENABLE([fill],
Jason Evans122449b2012-04-06 00:35:09 -0700939 [AS_HELP_STRING([--disable-fill],
940 [Disable support for junk/zero filling, quarantine, and redzones])],
Jason Evansb7924f52009-06-23 19:01:18 -0700941[if test "x$enable_fill" = "xno" ; then
942 enable_fill="0"
943else
944 enable_fill="1"
945fi
946],
Jason Evans777c1912012-02-28 20:49:22 -0800947[enable_fill="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700948)
949if test "x$enable_fill" = "x1" ; then
950 AC_DEFINE([JEMALLOC_FILL], [ ])
951fi
952AC_SUBST([enable_fill])
953
Jason Evansb1476112012-04-05 13:36:17 -0700954dnl Disable utrace(2)-based tracing by default.
955AC_ARG_ENABLE([utrace],
956 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
957[if test "x$enable_utrace" = "xno" ; then
958 enable_utrace="0"
959else
960 enable_utrace="1"
961fi
962],
963[enable_utrace="0"]
964)
965JE_COMPILABLE([utrace(2)], [
966#include <sys/types.h>
967#include <sys/param.h>
968#include <sys/time.h>
969#include <sys/uio.h>
970#include <sys/ktrace.h>
971], [
972 utrace((void *)0, 0);
973], [je_cv_utrace])
974if test "x${je_cv_utrace}" = "xno" ; then
975 enable_utrace="0"
976fi
977if test "x$enable_utrace" = "x1" ; then
978 AC_DEFINE([JEMALLOC_UTRACE], [ ])
979fi
980AC_SUBST([enable_utrace])
981
Jason Evans122449b2012-04-06 00:35:09 -0700982dnl Support Valgrind by default.
983AC_ARG_ENABLE([valgrind],
984 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
985[if test "x$enable_valgrind" = "xno" ; then
986 enable_valgrind="0"
987else
988 enable_valgrind="1"
989fi
990],
991[enable_valgrind="1"]
992)
993if test "x$enable_valgrind" = "x1" ; then
994 JE_COMPILABLE([valgrind], [
995#include <valgrind/valgrind.h>
996#include <valgrind/memcheck.h>
997
Mike Hommey7bfecf42012-04-30 15:15:15 +0200998#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
Jason Evans122449b2012-04-06 00:35:09 -0700999# error "Incompatible Valgrind version"
1000#endif
1001], [], [je_cv_valgrind])
1002 if test "x${je_cv_valgrind}" = "xno" ; then
1003 enable_valgrind="0"
1004 fi
1005 if test "x$enable_valgrind" = "x1" ; then
1006 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1007 fi
1008fi
1009AC_SUBST([enable_valgrind])
1010
Jason Evansb7924f52009-06-23 19:01:18 -07001011dnl Do not support the xmalloc option by default.
1012AC_ARG_ENABLE([xmalloc],
1013 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1014[if test "x$enable_xmalloc" = "xno" ; then
1015 enable_xmalloc="0"
1016else
1017 enable_xmalloc="1"
1018fi
1019],
1020[enable_xmalloc="0"]
1021)
1022if test "x$enable_xmalloc" = "x1" ; then
1023 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1024fi
1025AC_SUBST([enable_xmalloc])
1026
Jason Evans57c788a2015-05-04 09:58:36 -07001027dnl Support cache-oblivious allocation alignment by default.
1028AC_ARG_ENABLE([cache-oblivious],
1029 [AS_HELP_STRING([--disable-cache-oblivious],
1030 [Disable support for cache-oblivious allocation alignment])],
1031[if test "x$enable_cache_oblivious" = "xno" ; then
1032 enable_cache_oblivious="0"
1033else
1034 enable_cache_oblivious="1"
1035fi
1036],
1037[enable_cache_oblivious="1"]
1038)
1039if test "x$enable_cache_oblivious" = "x1" ; then
1040 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1041fi
1042AC_SUBST([enable_cache_oblivious])
1043
Mike Hommey401e5432014-06-04 12:12:55 +09001044dnl ============================================================================
1045dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1046dnl One of those two functions should (theoretically) exist on all platforms
1047dnl that jemalloc currently has a chance of functioning on without modification.
Christopher Ferrise4294032016-03-02 14:33:02 -08001048dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
Mike Hommey401e5432014-06-04 12:12:55 +09001049dnl ffsl() or __builtin_ffsl() are defined, respectively.
1050JE_COMPILABLE([a program using __builtin_ffsl], [
1051#include <stdio.h>
1052#include <strings.h>
1053#include <string.h>
1054], [
1055 {
1056 int rv = __builtin_ffsl(0x08);
1057 printf("%d\n", rv);
1058 }
1059], [je_cv_gcc_builtin_ffsl])
Christopher Ferris83e57672015-04-22 06:59:28 +00001060if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
Christopher Ferrise4294032016-03-02 14:33:02 -08001061 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
Mike Hommey401e5432014-06-04 12:12:55 +09001062 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1063 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1064else
1065 JE_COMPILABLE([a program using ffsl], [
1066 #include <stdio.h>
1067 #include <strings.h>
1068 #include <string.h>
1069 ], [
1070 {
1071 int rv = ffsl(0x08);
1072 printf("%d\n", rv);
1073 }
1074 ], [je_cv_function_ffsl])
Christopher Ferris83e57672015-04-22 06:59:28 +00001075 if test "x${je_cv_function_ffsl}" = "xyes" ; then
Christopher Ferrise4294032016-03-02 14:33:02 -08001076 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
Mike Hommey401e5432014-06-04 12:12:55 +09001077 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1078 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1079 else
1080 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1081 fi
1082fi
1083
Christopher Ferris83e57672015-04-22 06:59:28 +00001084AC_ARG_WITH([lg_tiny_min],
1085 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1086 [Base 2 log of minimum tiny size class to support])],
1087 [LG_TINY_MIN="$with_lg_tiny_min"],
1088 [LG_TINY_MIN="3"])
1089AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1090
1091AC_ARG_WITH([lg_quantum],
1092 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1093 [Base 2 log of minimum allocation alignment])],
1094 [LG_QUANTA="$with_lg_quantum"],
1095 [LG_QUANTA="3 4"])
1096if test "x$with_lg_quantum" != "x" ; then
1097 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1098fi
1099
1100AC_ARG_WITH([lg_page],
1101 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1102 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
1103if test "x$LG_PAGE" = "xdetect"; then
1104 AC_CACHE_CHECK([LG_PAGE],
1105 [je_cv_lg_page],
Jason Evans6684cac2012-03-05 12:15:36 -08001106 AC_RUN_IFELSE([AC_LANG_PROGRAM(
Mike Hommeya19e87f2012-04-21 21:27:46 -07001107[[
Mike Hommeyfd97b1d2012-04-30 12:38:31 +02001108#include <strings.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001109#ifdef _WIN32
1110#include <windows.h>
1111#else
Jason Evansb7924f52009-06-23 19:01:18 -07001112#include <unistd.h>
Mike Hommeya19e87f2012-04-21 21:27:46 -07001113#endif
1114#include <stdio.h>
Jason Evans6684cac2012-03-05 12:15:36 -08001115]],
1116[[
Garrett Cooper72c1e592012-12-02 17:57:28 -08001117 int result;
Jason Evansb7924f52009-06-23 19:01:18 -07001118 FILE *f;
1119
Mike Hommeya19e87f2012-04-21 21:27:46 -07001120#ifdef _WIN32
1121 SYSTEM_INFO si;
1122 GetSystemInfo(&si);
1123 result = si.dwPageSize;
1124#else
Jason Evansb7924f52009-06-23 19:01:18 -07001125 result = sysconf(_SC_PAGESIZE);
Mike Hommeya19e87f2012-04-21 21:27:46 -07001126#endif
Jason Evansb7924f52009-06-23 19:01:18 -07001127 if (result == -1) {
1128 return 1;
1129 }
Mike Hommey401e5432014-06-04 12:12:55 +09001130 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
Mike Hommeya19e87f2012-04-21 21:27:46 -07001131
Jason Evansb7924f52009-06-23 19:01:18 -07001132 f = fopen("conftest.out", "w");
1133 if (f == NULL) {
1134 return 1;
1135 }
Christopher Ferrise4294032016-03-02 14:33:02 -08001136 fprintf(f, "%d", result);
Jason Evans3cc1f1a2012-04-03 22:30:05 -07001137 fclose(f);
Jason Evansb7924f52009-06-23 19:01:18 -07001138
1139 return 0;
1140]])],
Christopher Ferris83e57672015-04-22 06:59:28 +00001141 [je_cv_lg_page=`cat conftest.out`],
1142 [je_cv_lg_page=undefined],
1143 [je_cv_lg_page=12]))
Jason Evansfc0b3b72014-10-09 17:54:06 -07001144fi
Christopher Ferris83e57672015-04-22 06:59:28 +00001145if test "x${je_cv_lg_page}" != "x" ; then
1146 LG_PAGE="${je_cv_lg_page}"
1147fi
1148if test "x${LG_PAGE}" != "xundefined" ; then
1149 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1150else
1151 AC_MSG_ERROR([cannot determine value for LG_PAGE])
1152fi
1153
1154AC_ARG_WITH([lg_page_sizes],
1155 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1156 [Base 2 logs of system page sizes to support])],
1157 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1158
1159AC_ARG_WITH([lg_size_class_group],
1160 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1161 [Base 2 log of size classes per doubling])],
1162 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1163 [LG_SIZE_CLASS_GROUP="2"])
Jason Evansfc0b3b72014-10-09 17:54:06 -07001164
Jason Evansb7924f52009-06-23 19:01:18 -07001165dnl ============================================================================
1166dnl jemalloc configuration.
1167dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -08001168
Christopher Ferris83e57672015-04-22 06:59:28 +00001169dnl Set VERSION if source directory is inside a git repository.
1170if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
1171 dnl Pattern globs aren't powerful enough to match both single- and
1172 dnl double-digit version numbers, so iterate over patterns to support up to
1173 dnl version 99.99.99 without any accidental matches.
1174 rm -f "${objroot}VERSION"
1175 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1176 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1177 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1178 '[0-9][0-9].[0-9][0-9].[0-9]' \
1179 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
1180 if test ! -e "${objroot}VERSION" ; then
1181 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
1182 if test $? -eq 0 ; then
1183 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
1184 break
1185 fi
1186 fi
1187 done
Jason Evansa40bc7a2010-03-02 13:01:16 -08001188fi
Christopher Ferris83e57672015-04-22 06:59:28 +00001189rm -f "${objroot}VERSION.tmp"
1190if test ! -e "${objroot}VERSION" ; then
1191 if test ! -e "${srcroot}VERSION" ; then
1192 AC_MSG_RESULT(
1193 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1194 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1195 else
1196 cp ${srcroot}VERSION ${objroot}VERSION
1197 fi
1198fi
1199jemalloc_version=`cat "${objroot}VERSION"`
Jason Evansa40bc7a2010-03-02 13:01:16 -08001200jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1201jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1202jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1203jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1204jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -07001205AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -08001206AC_SUBST([jemalloc_version_major])
1207AC_SUBST([jemalloc_version_minor])
1208AC_SUBST([jemalloc_version_bugfix])
1209AC_SUBST([jemalloc_version_nrev])
1210AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -07001211
1212dnl ============================================================================
1213dnl Configure pthreads.
1214
Mike Hommeya19e87f2012-04-21 21:27:46 -07001215if test "x$abi" != "xpecoff" ; then
1216 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1217 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1218 dnl first, but try libc too before failing.
1219 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1220 [AC_SEARCH_LIBS([pthread_create], , ,
1221 AC_MSG_ERROR([libpthread is missing]))])
1222fi
Jason Evansb7924f52009-06-23 19:01:18 -07001223
1224CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1225
Jason Evans345c1b02015-09-15 14:59:56 -07001226dnl Check whether clock_gettime(2) is in libc or librt. This function is only
1227dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
1228SAVED_LIBS="${LIBS}"
1229LIBS=
1230AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
1231AC_SUBST([TESTLIBS])
1232LIBS="${SAVED_LIBS}"
1233
Christopher Ferris83e57672015-04-22 06:59:28 +00001234dnl Check if the GNU-specific secure_getenv function exists.
1235AC_CHECK_FUNC([secure_getenv],
1236 [have_secure_getenv="1"],
1237 [have_secure_getenv="0"]
1238 )
1239if test "x$have_secure_getenv" = "x1" ; then
1240 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1241fi
1242
1243dnl Check if the Solaris/BSD issetugid function exists.
1244AC_CHECK_FUNC([issetugid],
1245 [have_issetugid="1"],
1246 [have_issetugid="0"]
1247 )
1248if test "x$have_issetugid" = "x1" ; then
1249 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1250fi
1251
Jason Evanscd9a1342012-03-21 18:33:03 -07001252dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1253dnl it rather than pthreads TSD cleanup functions to support cleanup during
1254dnl thread exit, in order to avoid pthreads library recursion during
1255dnl bootstrapping.
Jason Evanscd9a1342012-03-21 18:33:03 -07001256AC_CHECK_FUNC([_malloc_thread_cleanup],
1257 [have__malloc_thread_cleanup="1"],
1258 [have__malloc_thread_cleanup="0"]
1259 )
1260if test "x$have__malloc_thread_cleanup" = "x1" ; then
1261 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1262 force_tls="1"
1263fi
1264
Jason Evans41b6afb2012-02-02 22:04:57 -08001265dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1266dnl so, mutex initialization causes allocation, and we need to implement this
1267dnl callback function in order to prevent recursive allocation.
1268AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1269 [have__pthread_mutex_init_calloc_cb="1"],
1270 [have__pthread_mutex_init_calloc_cb="0"]
1271 )
1272if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1273 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1274fi
1275
Jason Evans0fee70d2012-02-13 12:36:11 -08001276dnl Disable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -07001277AC_ARG_ENABLE([lazy_lock],
Jason Evans0fee70d2012-02-13 12:36:11 -08001278 [AS_HELP_STRING([--enable-lazy-lock],
1279 [Enable lazy locking (only lock when multi-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -07001280[if test "x$enable_lazy_lock" = "xno" ; then
1281 enable_lazy_lock="0"
1282else
1283 enable_lazy_lock="1"
1284fi
1285],
Mike Hommeyac5db022015-08-11 14:01:59 +09001286[enable_lazy_lock=""]
Jason Evansb7924f52009-06-23 19:01:18 -07001287)
Mike Hommeyac5db022015-08-11 14:01:59 +09001288if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
Jason Evansfd4fcef2012-03-23 17:40:58 -07001289 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1290 enable_lazy_lock="1"
1291fi
Jason Evansb7924f52009-06-23 19:01:18 -07001292if test "x$enable_lazy_lock" = "x1" ; then
Mike Hommeya19e87f2012-04-21 21:27:46 -07001293 if test "x$abi" != "xpecoff" ; then
1294 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1295 AC_CHECK_FUNC([dlsym], [],
1296 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1297 [AC_MSG_ERROR([libdl is missing])])
1298 ])
1299 fi
Jason Evansb7924f52009-06-23 19:01:18 -07001300 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
Mike Hommeyac5db022015-08-11 14:01:59 +09001301else
1302 enable_lazy_lock="0"
Jason Evansb7924f52009-06-23 19:01:18 -07001303fi
1304AC_SUBST([enable_lazy_lock])
1305
Jason Evans78d815c2010-01-17 14:06:20 -08001306AC_ARG_ENABLE([tls],
1307 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1308if test "x$enable_tls" = "xno" ; then
1309 enable_tls="0"
1310else
1311 enable_tls="1"
1312fi
1313,
Mike Hommeyac5db022015-08-11 14:01:59 +09001314enable_tls=""
Jason Evans78d815c2010-01-17 14:06:20 -08001315)
Jason Evansc0f43b62015-09-02 12:46:35 -07001316if test "x${enable_tls}" = "x" ; then
1317 if test "x${force_tls}" = "x1" ; then
1318 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1319 enable_tls="1"
1320 elif test "x${force_tls}" = "x0" ; then
1321 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1322 enable_tls="0"
1323 else
1324 enable_tls="1"
1325 fi
Jason Evansb80581d2012-03-23 16:17:43 -07001326fi
Jason Evans78d815c2010-01-17 14:06:20 -08001327if test "x${enable_tls}" = "x1" ; then
1328AC_MSG_CHECKING([for TLS])
Jason Evans6684cac2012-03-05 12:15:36 -08001329AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
Jason Evans78d815c2010-01-17 14:06:20 -08001330[[
1331 __thread int x;
1332]], [[
1333 x = 42;
1334
1335 return 0;
1336]])],
1337 AC_MSG_RESULT([yes]),
1338 AC_MSG_RESULT([no])
1339 enable_tls="0")
Mike Hommeyac5db022015-08-11 14:01:59 +09001340else
1341 enable_tls="0"
Jason Evans78d815c2010-01-17 14:06:20 -08001342fi
Jason Evansb267d0f2010-08-13 15:42:29 -07001343AC_SUBST([enable_tls])
Jason Evanse24c7af2012-03-19 10:21:17 -07001344if test "x${enable_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001345 if test "x${force_tls}" = "x0" ; then
1346 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1347 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001348 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
Jason Evanscd9a1342012-03-21 18:33:03 -07001349elif test "x${force_tls}" = "x1" ; then
Jason Evansc0f43b62015-09-02 12:46:35 -07001350 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
Jason Evans78d815c2010-01-17 14:06:20 -08001351fi
1352
Jason Evans2dbecf12010-09-05 10:35:13 -07001353dnl ============================================================================
Chih-hung Hsieh1b55a4c2014-12-05 17:42:41 -08001354dnl Check for C11 atomics.
1355
1356JE_COMPILABLE([C11 atomics], [
1357#include <stdint.h>
1358#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1359#include <stdatomic.h>
1360#else
1361#error Atomics not available
1362#endif
1363], [
1364 uint64_t *p = (uint64_t *)0;
1365 uint64_t x = 1;
1366 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1367 uint64_t r = atomic_fetch_add(a, x) + x;
1368 return (r == 0);
1369], [je_cv_c11atomics])
1370if test "x${je_cv_c11atomics}" = "xyes" ; then
1371 AC_DEFINE([JEMALLOC_C11ATOMICS])
1372fi
1373
1374dnl ============================================================================
Jason Evansb57d3ec2012-04-17 13:17:54 -07001375dnl Check for atomic(9) operations as provided on FreeBSD.
1376
1377JE_COMPILABLE([atomic(9)], [
1378#include <sys/types.h>
1379#include <machine/atomic.h>
1380#include <inttypes.h>
1381], [
1382 {
1383 uint32_t x32 = 0;
1384 volatile uint32_t *x32p = &x32;
1385 atomic_fetchadd_32(x32p, 1);
1386 }
1387 {
1388 unsigned long xlong = 0;
1389 volatile unsigned long *xlongp = &xlong;
1390 atomic_fetchadd_long(xlongp, 1);
1391 }
1392], [je_cv_atomic9])
1393if test "x${je_cv_atomic9}" = "xyes" ; then
1394 AC_DEFINE([JEMALLOC_ATOMIC9])
1395fi
1396
1397dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -07001398dnl Check for atomic(3) operations as provided on Darwin.
1399
1400JE_COMPILABLE([Darwin OSAtomic*()], [
1401#include <libkern/OSAtomic.h>
1402#include <inttypes.h>
1403], [
1404 {
1405 int32_t x32 = 0;
1406 volatile int32_t *x32p = &x32;
1407 OSAtomicAdd32(1, x32p);
1408 }
1409 {
1410 int64_t x64 = 0;
1411 volatile int64_t *x64p = &x64;
1412 OSAtomicAdd64(1, x64p);
1413 }
Jason Evans6684cac2012-03-05 12:15:36 -08001414], [je_cv_osatomic])
1415if test "x${je_cv_osatomic}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001416 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
Jason Evans763baa62011-03-18 19:10:31 -07001417fi
1418
1419dnl ============================================================================
Richard Diamond3c958432014-06-03 02:39:18 -05001420dnl Check for madvise(2).
1421
1422JE_COMPILABLE([madvise(2)], [
1423#include <sys/mman.h>
1424], [
1425 {
1426 madvise((void *)0, 0, 0);
1427 }
1428], [je_cv_madvise])
1429if test "x${je_cv_madvise}" = "xyes" ; then
1430 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1431fi
1432
1433dnl ============================================================================
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001434dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1435dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1436
1437AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1438 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1439 [je_cv_sync_compare_and_swap_$2],
Mike Hommey2cfe6d62012-03-27 15:03:07 +02001440 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1441 #include <stdint.h>
1442 ],
1443 [
1444 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1445 {
1446 uint$1_t x$1 = 0;
1447 __sync_add_and_fetch(&x$1, 42);
1448 __sync_sub_and_fetch(&x$1, 1);
1449 }
1450 #else
1451 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1452 #endif
1453 ])],
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001454 [je_cv_sync_compare_and_swap_$2=yes],
1455 [je_cv_sync_compare_and_swap_$2=no])])
1456
1457 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1458 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1459 fi
1460])
1461
Jason Evansb57d3ec2012-04-17 13:17:54 -07001462if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
Mike Hommeyc1e567b2012-03-26 17:03:41 +02001463 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1464 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1465fi
1466
1467dnl ============================================================================
Jason Evans8d8f9ae2014-05-28 16:11:55 -07001468dnl Check for __builtin_clz() and __builtin_clzl().
1469
1470AC_CACHE_CHECK([for __builtin_clz],
1471 [je_cv_builtin_clz],
1472 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1473 [
1474 {
1475 unsigned x = 0;
1476 int y = __builtin_clz(x);
1477 }
1478 {
1479 unsigned long x = 0;
1480 int y = __builtin_clzl(x);
1481 }
1482 ])],
1483 [je_cv_builtin_clz=yes],
1484 [je_cv_builtin_clz=no])])
1485
1486if test "x${je_cv_builtin_clz}" = "xyes" ; then
1487 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1488fi
1489
1490dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -07001491dnl Check for spinlock(3) operations as provided on Darwin.
1492
1493JE_COMPILABLE([Darwin OSSpin*()], [
1494#include <libkern/OSAtomic.h>
1495#include <inttypes.h>
1496], [
1497 OSSpinLock lock = 0;
1498 OSSpinLockLock(&lock);
1499 OSSpinLockUnlock(&lock);
Jason Evans6684cac2012-03-05 12:15:36 -08001500], [je_cv_osspin])
1501if test "x${je_cv_osspin}" = "xyes" ; then
Jason Evanse24c7af2012-03-19 10:21:17 -07001502 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
Jason Evans893a0ed2011-03-18 19:30:18 -07001503fi
1504
1505dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -07001506dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -08001507
Mike Hommeyd0357f72012-11-26 18:52:41 +01001508AC_ARG_ENABLE([zone-allocator],
1509 [AS_HELP_STRING([--disable-zone-allocator],
1510 [Disable zone allocator for Darwin])],
1511[if test "x$enable_zone_allocator" = "xno" ; then
1512 enable_zone_allocator="0"
1513else
1514 enable_zone_allocator="1"
1515fi
1516],
1517[if test "x${abi}" = "xmacho"; then
1518 enable_zone_allocator="1"
1519fi
1520]
1521)
1522AC_SUBST([enable_zone_allocator])
1523
1524if test "x${enable_zone_allocator}" = "x1" ; then
1525 if test "x${abi}" != "xmacho"; then
1526 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1527 fi
Jason Evanse24c7af2012-03-19 10:21:17 -07001528 AC_DEFINE([JEMALLOC_ZONE], [ ])
Jason Evans6109fe02010-02-10 10:37:56 -08001529
Jason Evans2dbecf12010-09-05 10:35:13 -07001530 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1531 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1532 dnl 10.6, which is the only source-level indication of the change.
1533 AC_MSG_CHECKING([malloc zone version])
Mike Hommey154829d2012-03-20 18:01:38 +01001534 AC_DEFUN([JE_ZONE_PROGRAM],
1535 [AC_LANG_PROGRAM(
1536 [#include <malloc/malloc.h>],
Christopher Ferris83e57672015-04-22 06:59:28 +00001537 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
Mike Hommey154829d2012-03-20 18:01:38 +01001538 )])
Jason Evans2dbecf12010-09-05 10:35:13 -07001539
Mike Hommey154829d2012-03-20 18:01:38 +01001540 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1541 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1542 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1543 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1544 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1545 )])],[
1546 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1547 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1548 )])])])])
1549 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1550 AC_MSG_RESULT([unsupported])
1551 AC_MSG_ERROR([Unsupported malloc zone version])
1552 fi
1553 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1554 JEMALLOC_ZONE_VERSION=8
1555 AC_MSG_RESULT([> 8])
1556 else
1557 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1558 fi
1559 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
Jason Evansb27805b2010-02-10 18:15:53 -08001560fi
1561
Jason Evansb7924f52009-06-23 19:01:18 -07001562dnl ============================================================================
Christopher Ferris83e57672015-04-22 06:59:28 +00001563dnl Check for glibc malloc hooks
1564
1565JE_COMPILABLE([glibc malloc hook], [
1566#include <stddef.h>
1567
1568extern void (* __free_hook)(void *ptr);
1569extern void *(* __malloc_hook)(size_t size);
1570extern void *(* __realloc_hook)(void *ptr, size_t size);
1571], [
1572 void *ptr = 0L;
1573 if (__malloc_hook) ptr = __malloc_hook(1);
1574 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1575 if (__free_hook && ptr) __free_hook(ptr);
1576], [je_cv_glibc_malloc_hook])
1577if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1578 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1579fi
1580
1581JE_COMPILABLE([glibc memalign hook], [
1582#include <stddef.h>
1583
1584extern void *(* __memalign_hook)(size_t alignment, size_t size);
1585], [
1586 void *ptr = 0L;
1587 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1588], [je_cv_glibc_memalign_hook])
1589if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1590 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1591fi
1592
1593JE_COMPILABLE([pthreads adaptive mutexes], [
1594#include <pthread.h>
1595], [
1596 pthread_mutexattr_t attr;
1597 pthread_mutexattr_init(&attr);
1598 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1599 pthread_mutexattr_destroy(&attr);
1600], [je_cv_pthread_mutex_adaptive_np])
1601if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1602 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1603fi
1604
1605dnl ============================================================================
Jason Evansb7924f52009-06-23 19:01:18 -07001606dnl Check for typedefs, structures, and compiler characteristics.
1607AC_HEADER_STDBOOL
1608
Jason Evans748dfac2013-12-06 18:27:33 -08001609dnl ============================================================================
1610dnl Define commands that generate output files.
1611
Jason Evans86abd0d2013-11-30 15:25:42 -08001612AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1613 mkdir -p "${objroot}include/jemalloc/internal"
1614 "${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 -08001615], [
1616 srcdir="${srcdir}"
1617 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001618])
1619AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1620 mkdir -p "${objroot}include/jemalloc/internal"
1621 "${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 -08001622], [
1623 srcdir="${srcdir}"
1624 objroot="${objroot}"
1625])
1626AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1627 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1628 mkdir -p "${objroot}include/jemalloc/internal"
1629 cp /dev/null "${f}"
1630 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1631 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1632 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1633 echo "${n}:${m}" >> "${f}"
1634 dnl Remove name from public_syms so that it isn't redefined later.
1635 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1636 done
1637 for sym in ${public_syms} ; do
1638 n="${sym}"
1639 m="${JEMALLOC_PREFIX}${sym}"
1640 echo "${n}:${m}" >> "${f}"
1641 done
1642], [
1643 srcdir="${srcdir}"
1644 objroot="${objroot}"
1645 mangling_map="${mangling_map}"
1646 public_syms="${public_syms}"
1647 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001648])
1649AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1650 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001651 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1652], [
1653 srcdir="${srcdir}"
1654 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001655])
1656AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1657 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evansf234dc52014-01-16 17:38:01 -08001658 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1659], [
1660 srcdir="${srcdir}"
1661 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001662])
Jason Evansb1726102012-02-28 16:50:47 -08001663AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
Jason Evans86abd0d2013-11-30 15:25:42 -08001664 mkdir -p "${objroot}include/jemalloc/internal"
Jason Evans6d919292015-09-15 10:42:36 -07001665 "${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 -08001666], [
Jason Evans6d919292015-09-15 10:42:36 -07001667 SHELL="${SHELL}"
Jason Evansf234dc52014-01-16 17:38:01 -08001668 srcdir="${srcdir}"
1669 objroot="${objroot}"
Christopher Ferris83e57672015-04-22 06:59:28 +00001670 LG_QUANTA="${LG_QUANTA}"
1671 LG_TINY_MIN=${LG_TINY_MIN}
1672 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
1673 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
Jason Evansb1726102012-02-28 16:50:47 -08001674])
Jason Evans86abd0d2013-11-30 15:25:42 -08001675AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1676 mkdir -p "${objroot}include/jemalloc"
1677 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 -08001678], [
1679 srcdir="${srcdir}"
1680 objroot="${objroot}"
1681])
1682AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1683 mkdir -p "${objroot}include/jemalloc"
1684 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1685], [
1686 srcdir="${srcdir}"
1687 objroot="${objroot}"
1688])
1689AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1690 mkdir -p "${objroot}include/jemalloc"
1691 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1692], [
1693 srcdir="${srcdir}"
1694 objroot="${objroot}"
1695])
1696AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1697 mkdir -p "${objroot}include/jemalloc"
1698 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1699], [
1700 srcdir="${srcdir}"
1701 objroot="${objroot}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001702])
1703AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1704 mkdir -p "${objroot}include/jemalloc"
1705 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
Jason Evansf234dc52014-01-16 17:38:01 -08001706], [
1707 srcdir="${srcdir}"
1708 objroot="${objroot}"
1709 install_suffix="${install_suffix}"
Jason Evans86abd0d2013-11-30 15:25:42 -08001710])
Jason Evansb1726102012-02-28 16:50:47 -08001711
Jason Evansb7924f52009-06-23 19:01:18 -07001712dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -08001713AC_SUBST([cfghdrs_in])
1714AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -07001715AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -07001716
1717dnl ============================================================================
1718dnl Generate outputs.
Jason Evans748dfac2013-12-06 18:27:33 -08001719
Jason Evans529cffc2015-05-01 12:31:12 -07001720AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
Jason Evansb0fd5012010-01-17 01:49:20 -08001721AC_SUBST([cfgoutputs_in])
1722AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -07001723AC_OUTPUT
1724
1725dnl ============================================================================
1726dnl Print out the results of configuration.
1727AC_MSG_RESULT([===============================================================================])
Jason Evansf576c632011-11-01 22:27:41 -07001728AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1729AC_MSG_RESULT([library revision : ${rev}])
Jason Evansb7924f52009-06-23 19:01:18 -07001730AC_MSG_RESULT([])
Christopher Ferris83e57672015-04-22 06:59:28 +00001731AC_MSG_RESULT([CONFIG : ${CONFIG}])
Jason Evansb7924f52009-06-23 19:01:18 -07001732AC_MSG_RESULT([CC : ${CC}])
Nicolas Geoffray75929a92015-04-16 11:10:55 +00001733AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
Christopher Ferris83e57672015-04-22 06:59:28 +00001734AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001735AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
Jason Evans748dfac2013-12-06 18:27:33 -08001736AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001737AC_MSG_RESULT([LIBS : ${LIBS}])
Jason Evans345c1b02015-09-15 14:59:56 -07001738AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
Jason Evansb7924f52009-06-23 19:01:18 -07001739AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1740AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -08001741AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1742AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1743AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -07001744AC_MSG_RESULT([PREFIX : ${PREFIX}])
1745AC_MSG_RESULT([BINDIR : ${BINDIR}])
Christopher Ferris83e57672015-04-22 06:59:28 +00001746AC_MSG_RESULT([DATADIR : ${DATADIR}])
Jason Evans662a0172009-07-01 19:24:31 -07001747AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1748AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -07001749AC_MSG_RESULT([MANDIR : ${MANDIR}])
1750AC_MSG_RESULT([])
1751AC_MSG_RESULT([srcroot : ${srcroot}])
1752AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1753AC_MSG_RESULT([objroot : ${objroot}])
1754AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1755AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -08001756AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evans746e77a2011-07-30 16:40:52 -07001757AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1758AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
Jason Evansb0fd5012010-01-17 01:49:20 -08001759AC_MSG_RESULT([install_suffix : ${install_suffix}])
Christopher Ferrise4294032016-03-02 14:33:02 -08001760AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
Jason Evansb7924f52009-06-23 19:01:18 -07001761AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -07001762AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -07001763AC_MSG_RESULT([debug : ${enable_debug}])
Jason Evans748dfac2013-12-06 18:27:33 -08001764AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
Jason Evansb7924f52009-06-23 19:01:18 -07001765AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -08001766AC_MSG_RESULT([prof : ${enable_prof}])
1767AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -07001768AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1769AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evans84cbbcb2009-12-29 00:09:15 -08001770AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -07001771AC_MSG_RESULT([fill : ${enable_fill}])
Jason Evansb1476112012-04-05 13:36:17 -07001772AC_MSG_RESULT([utrace : ${enable_utrace}])
Jason Evans122449b2012-04-06 00:35:09 -07001773AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1774AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
Jason Evans59ae2762012-04-16 17:52:27 -07001775AC_MSG_RESULT([munmap : ${enable_munmap}])
Jason Evansb7924f52009-06-23 19:01:18 -07001776AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -07001777AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evans57c788a2015-05-04 09:58:36 -07001778AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
Jason Evansb7924f52009-06-23 19:01:18 -07001779AC_MSG_RESULT([===============================================================================])