xref: /freebsd/contrib/jemalloc/configure.ac (revision bf6039f09a30484c0749a3e3047d6a47b116b466)
1*bf6039f0SWarner Loshdnl Process this file with autoconf to produce a configure script.
2*bf6039f0SWarner LoshAC_PREREQ(2.68)
3*bf6039f0SWarner LoshAC_INIT([Makefile.in])
4*bf6039f0SWarner Losh
5*bf6039f0SWarner LoshAC_CONFIG_AUX_DIR([build-aux])
6*bf6039f0SWarner Losh
7*bf6039f0SWarner Loshdnl ============================================================================
8*bf6039f0SWarner Loshdnl Custom macro definitions.
9*bf6039f0SWarner Losh
10*bf6039f0SWarner Loshdnl JE_CONCAT_VVV(r, a, b)
11*bf6039f0SWarner Loshdnl
12*bf6039f0SWarner Loshdnl Set $r to the concatenation of $a and $b, with a space separating them iff
13*bf6039f0SWarner Loshdnl both $a and $b are non-empty.
14*bf6039f0SWarner LoshAC_DEFUN([JE_CONCAT_VVV],
15*bf6039f0SWarner Loshif test "x[$]{$2}" = "x" -o "x[$]{$3}" = "x" ; then
16*bf6039f0SWarner Losh  $1="[$]{$2}[$]{$3}"
17*bf6039f0SWarner Loshelse
18*bf6039f0SWarner Losh  $1="[$]{$2} [$]{$3}"
19*bf6039f0SWarner Loshfi
20*bf6039f0SWarner Losh)
21*bf6039f0SWarner Losh
22*bf6039f0SWarner Loshdnl JE_APPEND_VS(a, b)
23*bf6039f0SWarner Loshdnl
24*bf6039f0SWarner Loshdnl Set $a to the concatenation of $a and b, with a space separating them iff
25*bf6039f0SWarner Loshdnl both $a and b are non-empty.
26*bf6039f0SWarner LoshAC_DEFUN([JE_APPEND_VS],
27*bf6039f0SWarner Losh  T_APPEND_V=$2
28*bf6039f0SWarner Losh  JE_CONCAT_VVV($1, $1, T_APPEND_V)
29*bf6039f0SWarner Losh)
30*bf6039f0SWarner Losh
31*bf6039f0SWarner LoshCONFIGURE_CFLAGS=
32*bf6039f0SWarner LoshSPECIFIED_CFLAGS="${CFLAGS}"
33*bf6039f0SWarner Loshdnl JE_CFLAGS_ADD(cflag)
34*bf6039f0SWarner Loshdnl
35*bf6039f0SWarner Loshdnl CFLAGS is the concatenation of CONFIGURE_CFLAGS and SPECIFIED_CFLAGS
36*bf6039f0SWarner Loshdnl (ignoring EXTRA_CFLAGS, which does not impact configure tests.  This macro
37*bf6039f0SWarner Loshdnl appends to CONFIGURE_CFLAGS and regenerates CFLAGS.
38*bf6039f0SWarner LoshAC_DEFUN([JE_CFLAGS_ADD],
39*bf6039f0SWarner Losh[
40*bf6039f0SWarner LoshAC_MSG_CHECKING([whether compiler supports $1])
41*bf6039f0SWarner LoshT_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
42*bf6039f0SWarner LoshJE_APPEND_VS(CONFIGURE_CFLAGS, $1)
43*bf6039f0SWarner LoshJE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
44*bf6039f0SWarner LoshAC_COMPILE_IFELSE([AC_LANG_PROGRAM(
45*bf6039f0SWarner Losh[[
46*bf6039f0SWarner Losh]], [[
47*bf6039f0SWarner Losh    return 0;
48*bf6039f0SWarner Losh]])],
49*bf6039f0SWarner Losh              [je_cv_cflags_added=$1]
50*bf6039f0SWarner Losh              AC_MSG_RESULT([yes]),
51*bf6039f0SWarner Losh              [je_cv_cflags_added=]
52*bf6039f0SWarner Losh              AC_MSG_RESULT([no])
53*bf6039f0SWarner Losh              [CONFIGURE_CFLAGS="${T_CONFIGURE_CFLAGS}"]
54*bf6039f0SWarner Losh)
55*bf6039f0SWarner LoshJE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
56*bf6039f0SWarner Losh])
57*bf6039f0SWarner Losh
58*bf6039f0SWarner Loshdnl JE_CFLAGS_SAVE()
59*bf6039f0SWarner Loshdnl JE_CFLAGS_RESTORE()
60*bf6039f0SWarner Loshdnl
61*bf6039f0SWarner Loshdnl Save/restore CFLAGS.  Nesting is not supported.
62*bf6039f0SWarner LoshAC_DEFUN([JE_CFLAGS_SAVE],
63*bf6039f0SWarner LoshSAVED_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
64*bf6039f0SWarner Losh)
65*bf6039f0SWarner LoshAC_DEFUN([JE_CFLAGS_RESTORE],
66*bf6039f0SWarner LoshCONFIGURE_CFLAGS="${SAVED_CONFIGURE_CFLAGS}"
67*bf6039f0SWarner LoshJE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
68*bf6039f0SWarner Losh)
69*bf6039f0SWarner Losh
70*bf6039f0SWarner LoshCONFIGURE_CXXFLAGS=
71*bf6039f0SWarner LoshSPECIFIED_CXXFLAGS="${CXXFLAGS}"
72*bf6039f0SWarner Loshdnl JE_CXXFLAGS_ADD(cxxflag)
73*bf6039f0SWarner LoshAC_DEFUN([JE_CXXFLAGS_ADD],
74*bf6039f0SWarner Losh[
75*bf6039f0SWarner LoshAC_MSG_CHECKING([whether compiler supports $1])
76*bf6039f0SWarner LoshT_CONFIGURE_CXXFLAGS="${CONFIGURE_CXXFLAGS}"
77*bf6039f0SWarner LoshJE_APPEND_VS(CONFIGURE_CXXFLAGS, $1)
78*bf6039f0SWarner LoshJE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
79*bf6039f0SWarner LoshAC_LANG_PUSH([C++])
80*bf6039f0SWarner LoshAC_COMPILE_IFELSE([AC_LANG_PROGRAM(
81*bf6039f0SWarner Losh[[
82*bf6039f0SWarner Losh]], [[
83*bf6039f0SWarner Losh    return 0;
84*bf6039f0SWarner Losh]])],
85*bf6039f0SWarner Losh              [je_cv_cxxflags_added=$1]
86*bf6039f0SWarner Losh              AC_MSG_RESULT([yes]),
87*bf6039f0SWarner Losh              [je_cv_cxxflags_added=]
88*bf6039f0SWarner Losh              AC_MSG_RESULT([no])
89*bf6039f0SWarner Losh              [CONFIGURE_CXXFLAGS="${T_CONFIGURE_CXXFLAGS}"]
90*bf6039f0SWarner Losh)
91*bf6039f0SWarner LoshAC_LANG_POP([C++])
92*bf6039f0SWarner LoshJE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
93*bf6039f0SWarner Losh])
94*bf6039f0SWarner Losh
95*bf6039f0SWarner Loshdnl JE_COMPILABLE(label, hcode, mcode, rvar)
96*bf6039f0SWarner Loshdnl
97*bf6039f0SWarner Loshdnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
98*bf6039f0SWarner Loshdnl cause failure.
99*bf6039f0SWarner LoshAC_DEFUN([JE_COMPILABLE],
100*bf6039f0SWarner Losh[
101*bf6039f0SWarner LoshAC_CACHE_CHECK([whether $1 is compilable],
102*bf6039f0SWarner Losh               [$4],
103*bf6039f0SWarner Losh               [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
104*bf6039f0SWarner Losh                                                [$3])],
105*bf6039f0SWarner Losh                               [$4=yes],
106*bf6039f0SWarner Losh                               [$4=no])])
107*bf6039f0SWarner Losh])
108*bf6039f0SWarner Losh
109*bf6039f0SWarner Loshdnl ============================================================================
110*bf6039f0SWarner Losh
111*bf6039f0SWarner LoshCONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
112*bf6039f0SWarner LoshAC_SUBST([CONFIG])
113*bf6039f0SWarner Losh
114*bf6039f0SWarner Loshdnl Library revision.
115*bf6039f0SWarner Loshrev=2
116*bf6039f0SWarner LoshAC_SUBST([rev])
117*bf6039f0SWarner Losh
118*bf6039f0SWarner Loshsrcroot=$srcdir
119*bf6039f0SWarner Loshif test "x${srcroot}" = "x." ; then
120*bf6039f0SWarner Losh  srcroot=""
121*bf6039f0SWarner Loshelse
122*bf6039f0SWarner Losh  srcroot="${srcroot}/"
123*bf6039f0SWarner Loshfi
124*bf6039f0SWarner LoshAC_SUBST([srcroot])
125*bf6039f0SWarner Loshabs_srcroot="`cd \"${srcdir}\"; pwd`/"
126*bf6039f0SWarner LoshAC_SUBST([abs_srcroot])
127*bf6039f0SWarner Losh
128*bf6039f0SWarner Loshobjroot=""
129*bf6039f0SWarner LoshAC_SUBST([objroot])
130*bf6039f0SWarner Loshabs_objroot="`pwd`/"
131*bf6039f0SWarner LoshAC_SUBST([abs_objroot])
132*bf6039f0SWarner Losh
133*bf6039f0SWarner Loshdnl Munge install path variables.
134*bf6039f0SWarner Loshif test "x$prefix" = "xNONE" ; then
135*bf6039f0SWarner Losh  prefix="/usr/local"
136*bf6039f0SWarner Loshfi
137*bf6039f0SWarner Loshif test "x$exec_prefix" = "xNONE" ; then
138*bf6039f0SWarner Losh  exec_prefix=$prefix
139*bf6039f0SWarner Loshfi
140*bf6039f0SWarner LoshPREFIX=$prefix
141*bf6039f0SWarner LoshAC_SUBST([PREFIX])
142*bf6039f0SWarner LoshBINDIR=`eval echo $bindir`
143*bf6039f0SWarner LoshBINDIR=`eval echo $BINDIR`
144*bf6039f0SWarner LoshAC_SUBST([BINDIR])
145*bf6039f0SWarner LoshINCLUDEDIR=`eval echo $includedir`
146*bf6039f0SWarner LoshINCLUDEDIR=`eval echo $INCLUDEDIR`
147*bf6039f0SWarner LoshAC_SUBST([INCLUDEDIR])
148*bf6039f0SWarner LoshLIBDIR=`eval echo $libdir`
149*bf6039f0SWarner LoshLIBDIR=`eval echo $LIBDIR`
150*bf6039f0SWarner LoshAC_SUBST([LIBDIR])
151*bf6039f0SWarner LoshDATADIR=`eval echo $datadir`
152*bf6039f0SWarner LoshDATADIR=`eval echo $DATADIR`
153*bf6039f0SWarner LoshAC_SUBST([DATADIR])
154*bf6039f0SWarner LoshMANDIR=`eval echo $mandir`
155*bf6039f0SWarner LoshMANDIR=`eval echo $MANDIR`
156*bf6039f0SWarner LoshAC_SUBST([MANDIR])
157*bf6039f0SWarner Losh
158*bf6039f0SWarner Loshdnl Support for building documentation.
159*bf6039f0SWarner LoshAC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
160*bf6039f0SWarner Loshif test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
161*bf6039f0SWarner Losh  DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
162*bf6039f0SWarner Loshelif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
163*bf6039f0SWarner Losh  DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
164*bf6039f0SWarner Loshelse
165*bf6039f0SWarner Losh  dnl Documentation building will fail if this default gets used.
166*bf6039f0SWarner Losh  DEFAULT_XSLROOT=""
167*bf6039f0SWarner Loshfi
168*bf6039f0SWarner LoshAC_ARG_WITH([xslroot],
169*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
170*bf6039f0SWarner Loshif test "x$with_xslroot" = "xno" ; then
171*bf6039f0SWarner Losh  XSLROOT="${DEFAULT_XSLROOT}"
172*bf6039f0SWarner Loshelse
173*bf6039f0SWarner Losh  XSLROOT="${with_xslroot}"
174*bf6039f0SWarner Loshfi
175*bf6039f0SWarner Losh],
176*bf6039f0SWarner Losh  XSLROOT="${DEFAULT_XSLROOT}"
177*bf6039f0SWarner Losh)
178*bf6039f0SWarner Loshif test "x$XSLTPROC" = "xfalse" ; then
179*bf6039f0SWarner Losh  XSLROOT=""
180*bf6039f0SWarner Loshfi
181*bf6039f0SWarner LoshAC_SUBST([XSLROOT])
182*bf6039f0SWarner Losh
183*bf6039f0SWarner Loshdnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
184*bf6039f0SWarner Loshdnl just prevent autoconf from molesting CFLAGS.
185*bf6039f0SWarner LoshCFLAGS=$CFLAGS
186*bf6039f0SWarner LoshAC_PROG_CC
187*bf6039f0SWarner Losh
188*bf6039f0SWarner Loshif test "x$GCC" != "xyes" ; then
189*bf6039f0SWarner Losh  AC_CACHE_CHECK([whether compiler is MSVC],
190*bf6039f0SWarner Losh                 [je_cv_msvc],
191*bf6039f0SWarner Losh                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
192*bf6039f0SWarner Losh                                                     [
193*bf6039f0SWarner Losh#ifndef _MSC_VER
194*bf6039f0SWarner Losh  int fail[-1];
195*bf6039f0SWarner Losh#endif
196*bf6039f0SWarner Losh])],
197*bf6039f0SWarner Losh                               [je_cv_msvc=yes],
198*bf6039f0SWarner Losh                               [je_cv_msvc=no])])
199*bf6039f0SWarner Loshfi
200*bf6039f0SWarner Losh
201*bf6039f0SWarner Loshdnl check if a cray prgenv wrapper compiler is being used
202*bf6039f0SWarner Loshje_cv_cray_prgenv_wrapper=""
203*bf6039f0SWarner Loshif test "x${PE_ENV}" != "x" ; then
204*bf6039f0SWarner Losh  case "${CC}" in
205*bf6039f0SWarner Losh    CC|cc)
206*bf6039f0SWarner Losh	je_cv_cray_prgenv_wrapper="yes"
207*bf6039f0SWarner Losh	;;
208*bf6039f0SWarner Losh    *)
209*bf6039f0SWarner Losh       ;;
210*bf6039f0SWarner Losh  esac
211*bf6039f0SWarner Loshfi
212*bf6039f0SWarner Losh
213*bf6039f0SWarner LoshAC_CACHE_CHECK([whether compiler is cray],
214*bf6039f0SWarner Losh              [je_cv_cray],
215*bf6039f0SWarner Losh              [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
216*bf6039f0SWarner Losh                                                  [
217*bf6039f0SWarner Losh#ifndef _CRAYC
218*bf6039f0SWarner Losh  int fail[-1];
219*bf6039f0SWarner Losh#endif
220*bf6039f0SWarner Losh])],
221*bf6039f0SWarner Losh                            [je_cv_cray=yes],
222*bf6039f0SWarner Losh                            [je_cv_cray=no])])
223*bf6039f0SWarner Losh
224*bf6039f0SWarner Loshif test "x${je_cv_cray}" = "xyes" ; then
225*bf6039f0SWarner Losh  AC_CACHE_CHECK([whether cray compiler version is 8.4],
226*bf6039f0SWarner Losh                [je_cv_cray_84],
227*bf6039f0SWarner Losh                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
228*bf6039f0SWarner Losh                                                      [
229*bf6039f0SWarner Losh#if !(_RELEASE_MAJOR == 8 && _RELEASE_MINOR == 4)
230*bf6039f0SWarner Losh  int fail[-1];
231*bf6039f0SWarner Losh#endif
232*bf6039f0SWarner Losh])],
233*bf6039f0SWarner Losh                              [je_cv_cray_84=yes],
234*bf6039f0SWarner Losh                              [je_cv_cray_84=no])])
235*bf6039f0SWarner Loshfi
236*bf6039f0SWarner Losh
237*bf6039f0SWarner Loshif test "x$GCC" = "xyes" ; then
238*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-std=gnu11])
239*bf6039f0SWarner Losh  if test "x$je_cv_cflags_added" = "x-std=gnu11" ; then
240*bf6039f0SWarner Losh    AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
241*bf6039f0SWarner Losh  else
242*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-std=gnu99])
243*bf6039f0SWarner Losh    if test "x$je_cv_cflags_added" = "x-std=gnu99" ; then
244*bf6039f0SWarner Losh      AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
245*bf6039f0SWarner Losh    fi
246*bf6039f0SWarner Losh  fi
247*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Wall])
248*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Wextra])
249*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Wshorten-64-to-32])
250*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Wsign-compare])
251*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Wundef])
252*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Wno-format-zero-length])
253*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-pipe])
254*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-g3])
255*bf6039f0SWarner Loshelif test "x$je_cv_msvc" = "xyes" ; then
256*bf6039f0SWarner Losh  CC="$CC -nologo"
257*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Zi])
258*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-MT])
259*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-W3])
260*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-FS])
261*bf6039f0SWarner Losh  JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat)
262*bf6039f0SWarner Loshfi
263*bf6039f0SWarner Loshif test "x$je_cv_cray" = "xyes" ; then
264*bf6039f0SWarner Losh  dnl cray compiler 8.4 has an inlining bug
265*bf6039f0SWarner Losh  if test "x$je_cv_cray_84" = "xyes" ; then
266*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-hipa2])
267*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-hnognu])
268*bf6039f0SWarner Losh  fi
269*bf6039f0SWarner Losh  dnl ignore unreachable code warning
270*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-hnomessage=128])
271*bf6039f0SWarner Losh  dnl ignore redefinition of "malloc", "free", etc warning
272*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-hnomessage=1357])
273*bf6039f0SWarner Loshfi
274*bf6039f0SWarner LoshAC_SUBST([CONFIGURE_CFLAGS])
275*bf6039f0SWarner LoshAC_SUBST([SPECIFIED_CFLAGS])
276*bf6039f0SWarner LoshAC_SUBST([EXTRA_CFLAGS])
277*bf6039f0SWarner LoshAC_PROG_CPP
278*bf6039f0SWarner Losh
279*bf6039f0SWarner LoshAC_ARG_ENABLE([cxx],
280*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-cxx], [Disable C++ integration])],
281*bf6039f0SWarner Loshif test "x$enable_cxx" = "xno" ; then
282*bf6039f0SWarner Losh  enable_cxx="0"
283*bf6039f0SWarner Loshelse
284*bf6039f0SWarner Losh  enable_cxx="1"
285*bf6039f0SWarner Loshfi
286*bf6039f0SWarner Losh,
287*bf6039f0SWarner Loshenable_cxx="1"
288*bf6039f0SWarner Losh)
289*bf6039f0SWarner Loshif test "x$enable_cxx" = "x1" ; then
290*bf6039f0SWarner Losh  dnl Require at least c++14, which is the first version to support sized
291*bf6039f0SWarner Losh  dnl deallocation.  C++ support is not compiled otherwise.
292*bf6039f0SWarner Losh  m4_include([m4/ax_cxx_compile_stdcxx.m4])
293*bf6039f0SWarner Losh  AX_CXX_COMPILE_STDCXX([14], [noext], [optional])
294*bf6039f0SWarner Losh  if test "x${HAVE_CXX14}" = "x1" ; then
295*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-Wall])
296*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-Wextra])
297*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-g3])
298*bf6039f0SWarner Losh
299*bf6039f0SWarner Losh    SAVED_LIBS="${LIBS}"
300*bf6039f0SWarner Losh    JE_APPEND_VS(LIBS, -lstdc++)
301*bf6039f0SWarner Losh    JE_COMPILABLE([libstdc++ linkage], [
302*bf6039f0SWarner Losh#include <stdlib.h>
303*bf6039f0SWarner Losh], [[
304*bf6039f0SWarner Losh	int *arr = (int *)malloc(sizeof(int) * 42);
305*bf6039f0SWarner Losh	if (arr == NULL)
306*bf6039f0SWarner Losh		return 1;
307*bf6039f0SWarner Losh]], [je_cv_libstdcxx])
308*bf6039f0SWarner Losh    if test "x${je_cv_libstdcxx}" = "xno" ; then
309*bf6039f0SWarner Losh      LIBS="${SAVED_LIBS}"
310*bf6039f0SWarner Losh    fi
311*bf6039f0SWarner Losh  else
312*bf6039f0SWarner Losh    enable_cxx="0"
313*bf6039f0SWarner Losh  fi
314*bf6039f0SWarner Loshfi
315*bf6039f0SWarner LoshAC_SUBST([enable_cxx])
316*bf6039f0SWarner LoshAC_SUBST([CONFIGURE_CXXFLAGS])
317*bf6039f0SWarner LoshAC_SUBST([SPECIFIED_CXXFLAGS])
318*bf6039f0SWarner LoshAC_SUBST([EXTRA_CXXFLAGS])
319*bf6039f0SWarner Losh
320*bf6039f0SWarner LoshAC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
321*bf6039f0SWarner Loshif test "x${ac_cv_big_endian}" = "x1" ; then
322*bf6039f0SWarner Losh  AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
323*bf6039f0SWarner Loshfi
324*bf6039f0SWarner Losh
325*bf6039f0SWarner Loshif test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
326*bf6039f0SWarner Losh  JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat/C99)
327*bf6039f0SWarner Loshfi
328*bf6039f0SWarner Losh
329*bf6039f0SWarner Loshif test "x${je_cv_msvc}" = "xyes" ; then
330*bf6039f0SWarner Losh  LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
331*bf6039f0SWarner Losh  AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
332*bf6039f0SWarner Loshelse
333*bf6039f0SWarner Losh  AC_CHECK_SIZEOF([void *])
334*bf6039f0SWarner Losh  if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
335*bf6039f0SWarner Losh    LG_SIZEOF_PTR=3
336*bf6039f0SWarner Losh  elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
337*bf6039f0SWarner Losh    LG_SIZEOF_PTR=2
338*bf6039f0SWarner Losh  else
339*bf6039f0SWarner Losh    AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
340*bf6039f0SWarner Losh  fi
341*bf6039f0SWarner Loshfi
342*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
343*bf6039f0SWarner Losh
344*bf6039f0SWarner LoshAC_CHECK_SIZEOF([int])
345*bf6039f0SWarner Loshif test "x${ac_cv_sizeof_int}" = "x8" ; then
346*bf6039f0SWarner Losh  LG_SIZEOF_INT=3
347*bf6039f0SWarner Loshelif test "x${ac_cv_sizeof_int}" = "x4" ; then
348*bf6039f0SWarner Losh  LG_SIZEOF_INT=2
349*bf6039f0SWarner Loshelse
350*bf6039f0SWarner Losh  AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
351*bf6039f0SWarner Loshfi
352*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
353*bf6039f0SWarner Losh
354*bf6039f0SWarner LoshAC_CHECK_SIZEOF([long])
355*bf6039f0SWarner Loshif test "x${ac_cv_sizeof_long}" = "x8" ; then
356*bf6039f0SWarner Losh  LG_SIZEOF_LONG=3
357*bf6039f0SWarner Loshelif test "x${ac_cv_sizeof_long}" = "x4" ; then
358*bf6039f0SWarner Losh  LG_SIZEOF_LONG=2
359*bf6039f0SWarner Loshelse
360*bf6039f0SWarner Losh  AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
361*bf6039f0SWarner Loshfi
362*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
363*bf6039f0SWarner Losh
364*bf6039f0SWarner LoshAC_CHECK_SIZEOF([long long])
365*bf6039f0SWarner Loshif test "x${ac_cv_sizeof_long_long}" = "x8" ; then
366*bf6039f0SWarner Losh  LG_SIZEOF_LONG_LONG=3
367*bf6039f0SWarner Loshelif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
368*bf6039f0SWarner Losh  LG_SIZEOF_LONG_LONG=2
369*bf6039f0SWarner Loshelse
370*bf6039f0SWarner Losh  AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
371*bf6039f0SWarner Loshfi
372*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
373*bf6039f0SWarner Losh
374*bf6039f0SWarner LoshAC_CHECK_SIZEOF([intmax_t])
375*bf6039f0SWarner Loshif test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
376*bf6039f0SWarner Losh  LG_SIZEOF_INTMAX_T=4
377*bf6039f0SWarner Loshelif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
378*bf6039f0SWarner Losh  LG_SIZEOF_INTMAX_T=3
379*bf6039f0SWarner Loshelif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
380*bf6039f0SWarner Losh  LG_SIZEOF_INTMAX_T=2
381*bf6039f0SWarner Loshelse
382*bf6039f0SWarner Losh  AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
383*bf6039f0SWarner Loshfi
384*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
385*bf6039f0SWarner Losh
386*bf6039f0SWarner LoshAC_CANONICAL_HOST
387*bf6039f0SWarner Loshdnl CPU-specific settings.
388*bf6039f0SWarner LoshCPU_SPINWAIT=""
389*bf6039f0SWarner Loshcase "${host_cpu}" in
390*bf6039f0SWarner Losh  i686|x86_64)
391*bf6039f0SWarner Losh	HAVE_CPU_SPINWAIT=1
392*bf6039f0SWarner Losh	if test "x${je_cv_msvc}" = "xyes" ; then
393*bf6039f0SWarner Losh	    AC_CACHE_VAL([je_cv_pause_msvc],
394*bf6039f0SWarner Losh	      [JE_COMPILABLE([pause instruction MSVC], [],
395*bf6039f0SWarner Losh					[[_mm_pause(); return 0;]],
396*bf6039f0SWarner Losh					[je_cv_pause_msvc])])
397*bf6039f0SWarner Losh	    if test "x${je_cv_pause_msvc}" = "xyes" ; then
398*bf6039f0SWarner Losh		CPU_SPINWAIT='_mm_pause()'
399*bf6039f0SWarner Losh	    fi
400*bf6039f0SWarner Losh	else
401*bf6039f0SWarner Losh	    AC_CACHE_VAL([je_cv_pause],
402*bf6039f0SWarner Losh	      [JE_COMPILABLE([pause instruction], [],
403*bf6039f0SWarner Losh					[[__asm__ volatile("pause"); return 0;]],
404*bf6039f0SWarner Losh					[je_cv_pause])])
405*bf6039f0SWarner Losh	    if test "x${je_cv_pause}" = "xyes" ; then
406*bf6039f0SWarner Losh		CPU_SPINWAIT='__asm__ volatile("pause")'
407*bf6039f0SWarner Losh	    fi
408*bf6039f0SWarner Losh	fi
409*bf6039f0SWarner Losh	;;
410*bf6039f0SWarner Losh  *)
411*bf6039f0SWarner Losh	HAVE_CPU_SPINWAIT=0
412*bf6039f0SWarner Losh	;;
413*bf6039f0SWarner Loshesac
414*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([HAVE_CPU_SPINWAIT], [$HAVE_CPU_SPINWAIT])
415*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
416*bf6039f0SWarner Losh
417*bf6039f0SWarner LoshAC_ARG_WITH([lg_vaddr],
418*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-lg-vaddr=<lg-vaddr>], [Number of significant virtual address bits])],
419*bf6039f0SWarner Losh  [LG_VADDR="$with_lg_vaddr"], [LG_VADDR="detect"])
420*bf6039f0SWarner Losh
421*bf6039f0SWarner Loshcase "${host_cpu}" in
422*bf6039f0SWarner Losh  aarch64)
423*bf6039f0SWarner Losh    if test "x$LG_VADDR" = "xdetect"; then
424*bf6039f0SWarner Losh      AC_MSG_CHECKING([number of significant virtual address bits])
425*bf6039f0SWarner Losh      if test "x${LG_SIZEOF_PTR}" = "x2" ; then
426*bf6039f0SWarner Losh        #aarch64 ILP32
427*bf6039f0SWarner Losh        LG_VADDR=32
428*bf6039f0SWarner Losh      else
429*bf6039f0SWarner Losh        #aarch64 LP64
430*bf6039f0SWarner Losh        LG_VADDR=48
431*bf6039f0SWarner Losh      fi
432*bf6039f0SWarner Losh      AC_MSG_RESULT([$LG_VADDR])
433*bf6039f0SWarner Losh    fi
434*bf6039f0SWarner Losh    ;;
435*bf6039f0SWarner Losh  x86_64)
436*bf6039f0SWarner Losh    if test "x$LG_VADDR" = "xdetect"; then
437*bf6039f0SWarner Losh      AC_CACHE_CHECK([number of significant virtual address bits],
438*bf6039f0SWarner Losh                     [je_cv_lg_vaddr],
439*bf6039f0SWarner Losh                     AC_RUN_IFELSE([AC_LANG_PROGRAM(
440*bf6039f0SWarner Losh[[
441*bf6039f0SWarner Losh#include <stdio.h>
442*bf6039f0SWarner Losh#ifdef _WIN32
443*bf6039f0SWarner Losh#include <limits.h>
444*bf6039f0SWarner Losh#include <intrin.h>
445*bf6039f0SWarner Loshtypedef unsigned __int32 uint32_t;
446*bf6039f0SWarner Losh#else
447*bf6039f0SWarner Losh#include <stdint.h>
448*bf6039f0SWarner Losh#endif
449*bf6039f0SWarner Losh]], [[
450*bf6039f0SWarner Losh	uint32_t r[[4]];
451*bf6039f0SWarner Losh	uint32_t eax_in = 0x80000008U;
452*bf6039f0SWarner Losh#ifdef _WIN32
453*bf6039f0SWarner Losh	__cpuid((int *)r, (int)eax_in);
454*bf6039f0SWarner Losh#else
455*bf6039f0SWarner Losh	asm volatile ("cpuid"
456*bf6039f0SWarner Losh	    : "=a" (r[[0]]), "=b" (r[[1]]), "=c" (r[[2]]), "=d" (r[[3]])
457*bf6039f0SWarner Losh	    : "a" (eax_in), "c" (0)
458*bf6039f0SWarner Losh	);
459*bf6039f0SWarner Losh#endif
460*bf6039f0SWarner Losh	uint32_t eax_out = r[[0]];
461*bf6039f0SWarner Losh	uint32_t vaddr = ((eax_out & 0x0000ff00U) >> 8);
462*bf6039f0SWarner Losh	FILE *f = fopen("conftest.out", "w");
463*bf6039f0SWarner Losh	if (f == NULL) {
464*bf6039f0SWarner Losh		return 1;
465*bf6039f0SWarner Losh	}
466*bf6039f0SWarner Losh	if (vaddr > (sizeof(void *) << 3)) {
467*bf6039f0SWarner Losh		vaddr = sizeof(void *) << 3;
468*bf6039f0SWarner Losh	}
469*bf6039f0SWarner Losh	fprintf(f, "%u", vaddr);
470*bf6039f0SWarner Losh	fclose(f);
471*bf6039f0SWarner Losh	return 0;
472*bf6039f0SWarner Losh]])],
473*bf6039f0SWarner Losh                   [je_cv_lg_vaddr=`cat conftest.out`],
474*bf6039f0SWarner Losh                   [je_cv_lg_vaddr=error],
475*bf6039f0SWarner Losh                   [je_cv_lg_vaddr=57]))
476*bf6039f0SWarner Losh      if test "x${je_cv_lg_vaddr}" != "x" ; then
477*bf6039f0SWarner Losh        LG_VADDR="${je_cv_lg_vaddr}"
478*bf6039f0SWarner Losh      fi
479*bf6039f0SWarner Losh      if test "x${LG_VADDR}" != "xerror" ; then
480*bf6039f0SWarner Losh        AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
481*bf6039f0SWarner Losh      else
482*bf6039f0SWarner Losh        AC_MSG_ERROR([cannot determine number of significant virtual address bits])
483*bf6039f0SWarner Losh      fi
484*bf6039f0SWarner Losh    fi
485*bf6039f0SWarner Losh    ;;
486*bf6039f0SWarner Losh  *)
487*bf6039f0SWarner Losh    if test "x$LG_VADDR" = "xdetect"; then
488*bf6039f0SWarner Losh      AC_MSG_CHECKING([number of significant virtual address bits])
489*bf6039f0SWarner Losh      if test "x${LG_SIZEOF_PTR}" = "x3" ; then
490*bf6039f0SWarner Losh        LG_VADDR=64
491*bf6039f0SWarner Losh      elif test "x${LG_SIZEOF_PTR}" = "x2" ; then
492*bf6039f0SWarner Losh        LG_VADDR=32
493*bf6039f0SWarner Losh      elif test "x${LG_SIZEOF_PTR}" = "xLG_SIZEOF_PTR_WIN" ; then
494*bf6039f0SWarner Losh        LG_VADDR="(1U << (LG_SIZEOF_PTR_WIN+3))"
495*bf6039f0SWarner Losh      else
496*bf6039f0SWarner Losh        AC_MSG_ERROR([Unsupported lg(pointer size): ${LG_SIZEOF_PTR}])
497*bf6039f0SWarner Losh      fi
498*bf6039f0SWarner Losh      AC_MSG_RESULT([$LG_VADDR])
499*bf6039f0SWarner Losh    fi
500*bf6039f0SWarner Losh    ;;
501*bf6039f0SWarner Loshesac
502*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
503*bf6039f0SWarner Losh
504*bf6039f0SWarner LoshLD_PRELOAD_VAR="LD_PRELOAD"
505*bf6039f0SWarner Loshso="so"
506*bf6039f0SWarner Loshimportlib="${so}"
507*bf6039f0SWarner Losho="$ac_objext"
508*bf6039f0SWarner Losha="a"
509*bf6039f0SWarner Loshexe="$ac_exeext"
510*bf6039f0SWarner Loshlibprefix="lib"
511*bf6039f0SWarner Loshlink_whole_archive="0"
512*bf6039f0SWarner LoshDSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
513*bf6039f0SWarner LoshRPATH='-Wl,-rpath,$(1)'
514*bf6039f0SWarner LoshSOREV="${so}.${rev}"
515*bf6039f0SWarner LoshPIC_CFLAGS='-fPIC -DPIC'
516*bf6039f0SWarner LoshCTARGET='-o $@'
517*bf6039f0SWarner LoshLDTARGET='-o $@'
518*bf6039f0SWarner LoshTEST_LD_MODE=
519*bf6039f0SWarner LoshEXTRA_LDFLAGS=
520*bf6039f0SWarner LoshARFLAGS='crus'
521*bf6039f0SWarner LoshAROUT=' $@'
522*bf6039f0SWarner LoshCC_MM=1
523*bf6039f0SWarner Losh
524*bf6039f0SWarner Loshif test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
525*bf6039f0SWarner Losh  TEST_LD_MODE='-dynamic'
526*bf6039f0SWarner Loshfi
527*bf6039f0SWarner Losh
528*bf6039f0SWarner Loshif test "x${je_cv_cray}" = "xyes" ; then
529*bf6039f0SWarner Losh  CC_MM=
530*bf6039f0SWarner Loshfi
531*bf6039f0SWarner Losh
532*bf6039f0SWarner LoshAN_MAKEVAR([AR], [AC_PROG_AR])
533*bf6039f0SWarner LoshAN_PROGRAM([ar], [AC_PROG_AR])
534*bf6039f0SWarner LoshAC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
535*bf6039f0SWarner LoshAC_PROG_AR
536*bf6039f0SWarner Losh
537*bf6039f0SWarner LoshAN_MAKEVAR([NM], [AC_PROG_NM])
538*bf6039f0SWarner LoshAN_PROGRAM([nm], [AC_PROG_NM])
539*bf6039f0SWarner LoshAC_DEFUN([AC_PROG_NM], [AC_CHECK_TOOL(NM, nm, :)])
540*bf6039f0SWarner LoshAC_PROG_NM
541*bf6039f0SWarner Losh
542*bf6039f0SWarner LoshAC_PROG_AWK
543*bf6039f0SWarner Losh
544*bf6039f0SWarner Loshdnl ============================================================================
545*bf6039f0SWarner Loshdnl jemalloc version.
546*bf6039f0SWarner Loshdnl
547*bf6039f0SWarner Losh
548*bf6039f0SWarner LoshAC_ARG_WITH([version],
549*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid>],
550*bf6039f0SWarner Losh   [Version string])],
551*bf6039f0SWarner Losh  [
552*bf6039f0SWarner Losh    echo "${with_version}" | grep ['^[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+-g[0-9a-f]\+$'] 2>&1 1>/dev/null
553*bf6039f0SWarner Losh    if test $? -eq 0 ; then
554*bf6039f0SWarner Losh      echo "$with_version" > "${objroot}VERSION"
555*bf6039f0SWarner Losh    else
556*bf6039f0SWarner Losh      echo "${with_version}" | grep ['^VERSION$'] 2>&1 1>/dev/null
557*bf6039f0SWarner Losh      if test $? -ne 0 ; then
558*bf6039f0SWarner Losh        AC_MSG_ERROR([${with_version} does not match <major>.<minor>.<bugfix>-<nrev>-g<gid> or VERSION])
559*bf6039f0SWarner Losh      fi
560*bf6039f0SWarner Losh    fi
561*bf6039f0SWarner Losh  ], [
562*bf6039f0SWarner Losh    dnl Set VERSION if source directory is inside a git repository.
563*bf6039f0SWarner Losh    if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
564*bf6039f0SWarner Losh      dnl Pattern globs aren't powerful enough to match both single- and
565*bf6039f0SWarner Losh      dnl double-digit version numbers, so iterate over patterns to support up
566*bf6039f0SWarner Losh      dnl to version 99.99.99 without any accidental matches.
567*bf6039f0SWarner Losh      for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
568*bf6039f0SWarner Losh                     '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
569*bf6039f0SWarner Losh                     '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
570*bf6039f0SWarner Losh                     '[0-9][0-9].[0-9][0-9].[0-9]' \
571*bf6039f0SWarner Losh                     '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
572*bf6039f0SWarner Losh        (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
573*bf6039f0SWarner Losh        if test $? -eq 0 ; then
574*bf6039f0SWarner Losh          mv "${objroot}VERSION.tmp" "${objroot}VERSION"
575*bf6039f0SWarner Losh          break
576*bf6039f0SWarner Losh        fi
577*bf6039f0SWarner Losh      done
578*bf6039f0SWarner Losh    fi
579*bf6039f0SWarner Losh    rm -f "${objroot}VERSION.tmp"
580*bf6039f0SWarner Losh  ])
581*bf6039f0SWarner Losh
582*bf6039f0SWarner Loshif test ! -e "${objroot}VERSION" ; then
583*bf6039f0SWarner Losh  if test ! -e "${srcroot}VERSION" ; then
584*bf6039f0SWarner Losh    AC_MSG_RESULT(
585*bf6039f0SWarner Losh      [Missing VERSION file, and unable to generate it; creating bogus VERSION])
586*bf6039f0SWarner Losh    echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
587*bf6039f0SWarner Losh  else
588*bf6039f0SWarner Losh    cp ${srcroot}VERSION ${objroot}VERSION
589*bf6039f0SWarner Losh  fi
590*bf6039f0SWarner Loshfi
591*bf6039f0SWarner Loshjemalloc_version=`cat "${objroot}VERSION"`
592*bf6039f0SWarner Loshjemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
593*bf6039f0SWarner Loshjemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
594*bf6039f0SWarner Loshjemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
595*bf6039f0SWarner Loshjemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
596*bf6039f0SWarner Loshjemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
597*bf6039f0SWarner LoshAC_SUBST([jemalloc_version])
598*bf6039f0SWarner LoshAC_SUBST([jemalloc_version_major])
599*bf6039f0SWarner LoshAC_SUBST([jemalloc_version_minor])
600*bf6039f0SWarner LoshAC_SUBST([jemalloc_version_bugfix])
601*bf6039f0SWarner LoshAC_SUBST([jemalloc_version_nrev])
602*bf6039f0SWarner LoshAC_SUBST([jemalloc_version_gid])
603*bf6039f0SWarner Losh
604*bf6039f0SWarner Loshdnl Platform-specific settings.  abi and RPATH can probably be determined
605*bf6039f0SWarner Loshdnl programmatically, but doing so is error-prone, which makes it generally
606*bf6039f0SWarner Loshdnl not worth the trouble.
607*bf6039f0SWarner Loshdnl
608*bf6039f0SWarner Loshdnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
609*bf6039f0SWarner Loshdnl definitions need to be seen before any headers are included, which is a pain
610*bf6039f0SWarner Loshdnl to make happen otherwise.
611*bf6039f0SWarner Loshdefault_retain="0"
612*bf6039f0SWarner Loshmaps_coalesce="1"
613*bf6039f0SWarner LoshDUMP_SYMS="${NM} -a"
614*bf6039f0SWarner LoshSYM_PREFIX=""
615*bf6039f0SWarner Loshcase "${host}" in
616*bf6039f0SWarner Losh  *-*-darwin* | *-*-ios*)
617*bf6039f0SWarner Losh	abi="macho"
618*bf6039f0SWarner Losh	RPATH=""
619*bf6039f0SWarner Losh	LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
620*bf6039f0SWarner Losh	so="dylib"
621*bf6039f0SWarner Losh	importlib="${so}"
622*bf6039f0SWarner Losh	force_tls="0"
623*bf6039f0SWarner Losh	DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
624*bf6039f0SWarner Losh	SOREV="${rev}.${so}"
625*bf6039f0SWarner Losh	sbrk_deprecated="1"
626*bf6039f0SWarner Losh	SYM_PREFIX="_"
627*bf6039f0SWarner Losh	;;
628*bf6039f0SWarner Losh  *-*-freebsd*)
629*bf6039f0SWarner Losh	abi="elf"
630*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
631*bf6039f0SWarner Losh	force_lazy_lock="1"
632*bf6039f0SWarner Losh	;;
633*bf6039f0SWarner Losh  *-*-dragonfly*)
634*bf6039f0SWarner Losh	abi="elf"
635*bf6039f0SWarner Losh	;;
636*bf6039f0SWarner Losh  *-*-openbsd*)
637*bf6039f0SWarner Losh	abi="elf"
638*bf6039f0SWarner Losh	force_tls="0"
639*bf6039f0SWarner Losh	;;
640*bf6039f0SWarner Losh  *-*-bitrig*)
641*bf6039f0SWarner Losh	abi="elf"
642*bf6039f0SWarner Losh	;;
643*bf6039f0SWarner Losh  *-*-linux-android)
644*bf6039f0SWarner Losh	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
645*bf6039f0SWarner Losh	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
646*bf6039f0SWarner Losh	abi="elf"
647*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
648*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
649*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
650*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
651*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_C11_ATOMICS])
652*bf6039f0SWarner Losh	force_tls="0"
653*bf6039f0SWarner Losh	if test "${LG_SIZEOF_PTR}" = "3"; then
654*bf6039f0SWarner Losh	  default_retain="1"
655*bf6039f0SWarner Losh	fi
656*bf6039f0SWarner Losh	;;
657*bf6039f0SWarner Losh  *-*-linux*)
658*bf6039f0SWarner Losh	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
659*bf6039f0SWarner Losh	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
660*bf6039f0SWarner Losh	abi="elf"
661*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
662*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
663*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
664*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
665*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
666*bf6039f0SWarner Losh	if test "${LG_SIZEOF_PTR}" = "3"; then
667*bf6039f0SWarner Losh	  default_retain="1"
668*bf6039f0SWarner Losh	fi
669*bf6039f0SWarner Losh	;;
670*bf6039f0SWarner Losh  *-*-kfreebsd*)
671*bf6039f0SWarner Losh	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
672*bf6039f0SWarner Losh	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
673*bf6039f0SWarner Losh	abi="elf"
674*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
675*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
676*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
677*bf6039f0SWarner Losh	AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
678*bf6039f0SWarner Losh	;;
679*bf6039f0SWarner Losh  *-*-netbsd*)
680*bf6039f0SWarner Losh	AC_MSG_CHECKING([ABI])
681*bf6039f0SWarner Losh        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
682*bf6039f0SWarner Losh[[#ifdef __ELF__
683*bf6039f0SWarner Losh/* ELF */
684*bf6039f0SWarner Losh#else
685*bf6039f0SWarner Losh#error aout
686*bf6039f0SWarner Losh#endif
687*bf6039f0SWarner Losh]])],
688*bf6039f0SWarner Losh                          [abi="elf"],
689*bf6039f0SWarner Losh                          [abi="aout"])
690*bf6039f0SWarner Losh	AC_MSG_RESULT([$abi])
691*bf6039f0SWarner Losh	;;
692*bf6039f0SWarner Losh  *-*-solaris2*)
693*bf6039f0SWarner Losh	abi="elf"
694*bf6039f0SWarner Losh	RPATH='-Wl,-R,$(1)'
695*bf6039f0SWarner Losh	dnl Solaris needs this for sigwait().
696*bf6039f0SWarner Losh	JE_APPEND_VS(CPPFLAGS, -D_POSIX_PTHREAD_SEMANTICS)
697*bf6039f0SWarner Losh	JE_APPEND_VS(LIBS, -lposix4 -lsocket -lnsl)
698*bf6039f0SWarner Losh	;;
699*bf6039f0SWarner Losh  *-ibm-aix*)
700*bf6039f0SWarner Losh	if test "${LG_SIZEOF_PTR}" = "3"; then
701*bf6039f0SWarner Losh	  dnl 64bit AIX
702*bf6039f0SWarner Losh	  LD_PRELOAD_VAR="LDR_PRELOAD64"
703*bf6039f0SWarner Losh	else
704*bf6039f0SWarner Losh	  dnl 32bit AIX
705*bf6039f0SWarner Losh	  LD_PRELOAD_VAR="LDR_PRELOAD"
706*bf6039f0SWarner Losh	fi
707*bf6039f0SWarner Losh	abi="xcoff"
708*bf6039f0SWarner Losh	;;
709*bf6039f0SWarner Losh  *-*-mingw* | *-*-cygwin*)
710*bf6039f0SWarner Losh	abi="pecoff"
711*bf6039f0SWarner Losh	force_tls="0"
712*bf6039f0SWarner Losh	maps_coalesce="0"
713*bf6039f0SWarner Losh	RPATH=""
714*bf6039f0SWarner Losh	so="dll"
715*bf6039f0SWarner Losh	if test "x$je_cv_msvc" = "xyes" ; then
716*bf6039f0SWarner Losh	  importlib="lib"
717*bf6039f0SWarner Losh	  DSO_LDFLAGS="-LD"
718*bf6039f0SWarner Losh	  EXTRA_LDFLAGS="-link -DEBUG"
719*bf6039f0SWarner Losh	  CTARGET='-Fo$@'
720*bf6039f0SWarner Losh	  LDTARGET='-Fe$@'
721*bf6039f0SWarner Losh	  AR='lib'
722*bf6039f0SWarner Losh	  ARFLAGS='-nologo -out:'
723*bf6039f0SWarner Losh	  AROUT='$@'
724*bf6039f0SWarner Losh	  CC_MM=
725*bf6039f0SWarner Losh        else
726*bf6039f0SWarner Losh	  importlib="${so}"
727*bf6039f0SWarner Losh	  DSO_LDFLAGS="-shared"
728*bf6039f0SWarner Losh	  link_whole_archive="1"
729*bf6039f0SWarner Losh	fi
730*bf6039f0SWarner Losh	case "${host}" in
731*bf6039f0SWarner Losh	  *-*-cygwin*)
732*bf6039f0SWarner Losh	    DUMP_SYMS="dumpbin /SYMBOLS"
733*bf6039f0SWarner Losh	    ;;
734*bf6039f0SWarner Losh	  *)
735*bf6039f0SWarner Losh	    ;;
736*bf6039f0SWarner Losh	esac
737*bf6039f0SWarner Losh	a="lib"
738*bf6039f0SWarner Losh	libprefix=""
739*bf6039f0SWarner Losh	SOREV="${so}"
740*bf6039f0SWarner Losh	PIC_CFLAGS=""
741*bf6039f0SWarner Losh	if test "${LG_SIZEOF_PTR}" = "3"; then
742*bf6039f0SWarner Losh	  default_retain="1"
743*bf6039f0SWarner Losh	fi
744*bf6039f0SWarner Losh	;;
745*bf6039f0SWarner Losh  *)
746*bf6039f0SWarner Losh	AC_MSG_RESULT([Unsupported operating system: ${host}])
747*bf6039f0SWarner Losh	abi="elf"
748*bf6039f0SWarner Losh	;;
749*bf6039f0SWarner Loshesac
750*bf6039f0SWarner Losh
751*bf6039f0SWarner LoshJEMALLOC_USABLE_SIZE_CONST=const
752*bf6039f0SWarner LoshAC_CHECK_HEADERS([malloc.h], [
753*bf6039f0SWarner Losh  AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
754*bf6039f0SWarner Losh  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
755*bf6039f0SWarner Losh    [#include <malloc.h>
756*bf6039f0SWarner Losh     #include <stddef.h>
757*bf6039f0SWarner Losh    size_t malloc_usable_size(const void *ptr);
758*bf6039f0SWarner Losh    ],
759*bf6039f0SWarner Losh    [])],[
760*bf6039f0SWarner Losh                AC_MSG_RESULT([yes])
761*bf6039f0SWarner Losh         ],[
762*bf6039f0SWarner Losh                JEMALLOC_USABLE_SIZE_CONST=
763*bf6039f0SWarner Losh                AC_MSG_RESULT([no])
764*bf6039f0SWarner Losh         ])
765*bf6039f0SWarner Losh])
766*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
767*bf6039f0SWarner LoshAC_SUBST([abi])
768*bf6039f0SWarner LoshAC_SUBST([RPATH])
769*bf6039f0SWarner LoshAC_SUBST([LD_PRELOAD_VAR])
770*bf6039f0SWarner LoshAC_SUBST([so])
771*bf6039f0SWarner LoshAC_SUBST([importlib])
772*bf6039f0SWarner LoshAC_SUBST([o])
773*bf6039f0SWarner LoshAC_SUBST([a])
774*bf6039f0SWarner LoshAC_SUBST([exe])
775*bf6039f0SWarner LoshAC_SUBST([libprefix])
776*bf6039f0SWarner LoshAC_SUBST([link_whole_archive])
777*bf6039f0SWarner LoshAC_SUBST([DSO_LDFLAGS])
778*bf6039f0SWarner LoshAC_SUBST([EXTRA_LDFLAGS])
779*bf6039f0SWarner LoshAC_SUBST([SOREV])
780*bf6039f0SWarner LoshAC_SUBST([PIC_CFLAGS])
781*bf6039f0SWarner LoshAC_SUBST([CTARGET])
782*bf6039f0SWarner LoshAC_SUBST([LDTARGET])
783*bf6039f0SWarner LoshAC_SUBST([TEST_LD_MODE])
784*bf6039f0SWarner LoshAC_SUBST([MKLIB])
785*bf6039f0SWarner LoshAC_SUBST([ARFLAGS])
786*bf6039f0SWarner LoshAC_SUBST([AROUT])
787*bf6039f0SWarner LoshAC_SUBST([DUMP_SYMS])
788*bf6039f0SWarner LoshAC_SUBST([CC_MM])
789*bf6039f0SWarner Losh
790*bf6039f0SWarner Loshdnl Determine whether libm must be linked to use e.g. log(3).
791*bf6039f0SWarner LoshAC_SEARCH_LIBS([log], [m], , [AC_MSG_ERROR([Missing math functions])])
792*bf6039f0SWarner Loshif test "x$ac_cv_search_log" != "xnone required" ; then
793*bf6039f0SWarner Losh  LM="$ac_cv_search_log"
794*bf6039f0SWarner Loshelse
795*bf6039f0SWarner Losh  LM=
796*bf6039f0SWarner Loshfi
797*bf6039f0SWarner LoshAC_SUBST(LM)
798*bf6039f0SWarner Losh
799*bf6039f0SWarner LoshJE_COMPILABLE([__attribute__ syntax],
800*bf6039f0SWarner Losh              [static __attribute__((unused)) void foo(void){}],
801*bf6039f0SWarner Losh              [],
802*bf6039f0SWarner Losh              [je_cv_attribute])
803*bf6039f0SWarner Loshif test "x${je_cv_attribute}" = "xyes" ; then
804*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
805*bf6039f0SWarner Losh  if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
806*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-fvisibility=hidden])
807*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-fvisibility=hidden])
808*bf6039f0SWarner Losh  fi
809*bf6039f0SWarner Loshfi
810*bf6039f0SWarner Loshdnl Check for tls_model attribute support (clang 3.0 still lacks support).
811*bf6039f0SWarner LoshJE_CFLAGS_SAVE()
812*bf6039f0SWarner LoshJE_CFLAGS_ADD([-Werror])
813*bf6039f0SWarner LoshJE_CFLAGS_ADD([-herror_on_warning])
814*bf6039f0SWarner LoshJE_COMPILABLE([tls_model attribute], [],
815*bf6039f0SWarner Losh              [static __thread int
816*bf6039f0SWarner Losh               __attribute__((tls_model("initial-exec"), unused)) foo;
817*bf6039f0SWarner Losh               foo = 0;],
818*bf6039f0SWarner Losh              [je_cv_tls_model])
819*bf6039f0SWarner LoshJE_CFLAGS_RESTORE()
820*bf6039f0SWarner Loshdnl (Setting of JEMALLOC_TLS_MODEL is done later, after we've checked for
821*bf6039f0SWarner Loshdnl --disable-initial-exec-tls)
822*bf6039f0SWarner Losh
823*bf6039f0SWarner Loshdnl Check for alloc_size attribute support.
824*bf6039f0SWarner LoshJE_CFLAGS_SAVE()
825*bf6039f0SWarner LoshJE_CFLAGS_ADD([-Werror])
826*bf6039f0SWarner LoshJE_CFLAGS_ADD([-herror_on_warning])
827*bf6039f0SWarner LoshJE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
828*bf6039f0SWarner Losh              [void *foo(size_t size) __attribute__((alloc_size(1)));],
829*bf6039f0SWarner Losh              [je_cv_alloc_size])
830*bf6039f0SWarner LoshJE_CFLAGS_RESTORE()
831*bf6039f0SWarner Loshif test "x${je_cv_alloc_size}" = "xyes" ; then
832*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
833*bf6039f0SWarner Loshfi
834*bf6039f0SWarner Loshdnl Check for format(gnu_printf, ...) attribute support.
835*bf6039f0SWarner LoshJE_CFLAGS_SAVE()
836*bf6039f0SWarner LoshJE_CFLAGS_ADD([-Werror])
837*bf6039f0SWarner LoshJE_CFLAGS_ADD([-herror_on_warning])
838*bf6039f0SWarner LoshJE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
839*bf6039f0SWarner Losh              [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
840*bf6039f0SWarner Losh              [je_cv_format_gnu_printf])
841*bf6039f0SWarner LoshJE_CFLAGS_RESTORE()
842*bf6039f0SWarner Loshif test "x${je_cv_format_gnu_printf}" = "xyes" ; then
843*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
844*bf6039f0SWarner Loshfi
845*bf6039f0SWarner Loshdnl Check for format(printf, ...) attribute support.
846*bf6039f0SWarner LoshJE_CFLAGS_SAVE()
847*bf6039f0SWarner LoshJE_CFLAGS_ADD([-Werror])
848*bf6039f0SWarner LoshJE_CFLAGS_ADD([-herror_on_warning])
849*bf6039f0SWarner LoshJE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
850*bf6039f0SWarner Losh              [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
851*bf6039f0SWarner Losh              [je_cv_format_printf])
852*bf6039f0SWarner LoshJE_CFLAGS_RESTORE()
853*bf6039f0SWarner Loshif test "x${je_cv_format_printf}" = "xyes" ; then
854*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
855*bf6039f0SWarner Loshfi
856*bf6039f0SWarner Losh
857*bf6039f0SWarner Loshdnl Check for format_arg(...) attribute support.
858*bf6039f0SWarner LoshJE_CFLAGS_SAVE()
859*bf6039f0SWarner LoshJE_CFLAGS_ADD([-Werror])
860*bf6039f0SWarner LoshJE_CFLAGS_ADD([-herror_on_warning])
861*bf6039f0SWarner LoshJE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
862*bf6039f0SWarner Losh              [const char * __attribute__((__format_arg__(1))) foo(const char *format);],
863*bf6039f0SWarner Losh              [je_cv_format_arg])
864*bf6039f0SWarner LoshJE_CFLAGS_RESTORE()
865*bf6039f0SWarner Loshif test "x${je_cv_format_arg}" = "xyes" ; then
866*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_ARG], [ ])
867*bf6039f0SWarner Loshfi
868*bf6039f0SWarner Losh
869*bf6039f0SWarner Loshdnl Support optional additions to rpath.
870*bf6039f0SWarner LoshAC_ARG_WITH([rpath],
871*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
872*bf6039f0SWarner Loshif test "x$with_rpath" = "xno" ; then
873*bf6039f0SWarner Losh  RPATH_EXTRA=
874*bf6039f0SWarner Loshelse
875*bf6039f0SWarner Losh  RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
876*bf6039f0SWarner Loshfi,
877*bf6039f0SWarner Losh  RPATH_EXTRA=
878*bf6039f0SWarner Losh)
879*bf6039f0SWarner LoshAC_SUBST([RPATH_EXTRA])
880*bf6039f0SWarner Losh
881*bf6039f0SWarner Loshdnl Disable rules that do automatic regeneration of configure output by default.
882*bf6039f0SWarner LoshAC_ARG_ENABLE([autogen],
883*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
884*bf6039f0SWarner Loshif test "x$enable_autogen" = "xno" ; then
885*bf6039f0SWarner Losh  enable_autogen="0"
886*bf6039f0SWarner Loshelse
887*bf6039f0SWarner Losh  enable_autogen="1"
888*bf6039f0SWarner Loshfi
889*bf6039f0SWarner Losh,
890*bf6039f0SWarner Loshenable_autogen="0"
891*bf6039f0SWarner Losh)
892*bf6039f0SWarner LoshAC_SUBST([enable_autogen])
893*bf6039f0SWarner Losh
894*bf6039f0SWarner LoshAC_PROG_INSTALL
895*bf6039f0SWarner LoshAC_PROG_RANLIB
896*bf6039f0SWarner LoshAC_PATH_PROG([LD], [ld], [false], [$PATH])
897*bf6039f0SWarner LoshAC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
898*bf6039f0SWarner Losh
899*bf6039f0SWarner Loshdnl Enable documentation
900*bf6039f0SWarner LoshAC_ARG_ENABLE([doc],
901*bf6039f0SWarner Losh	      [AS_HELP_STRING([--enable-documentation], [Build documentation])],
902*bf6039f0SWarner Loshif test "x$enable_doc" = "xno" ; then
903*bf6039f0SWarner Losh  enable_doc="0"
904*bf6039f0SWarner Loshelse
905*bf6039f0SWarner Losh  enable_doc="1"
906*bf6039f0SWarner Loshfi
907*bf6039f0SWarner Losh,
908*bf6039f0SWarner Loshenable_doc="1"
909*bf6039f0SWarner Losh)
910*bf6039f0SWarner LoshAC_SUBST([enable_doc])
911*bf6039f0SWarner Losh
912*bf6039f0SWarner Loshdnl Enable shared libs
913*bf6039f0SWarner LoshAC_ARG_ENABLE([shared],
914*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-shared], [Build shared libaries])],
915*bf6039f0SWarner Loshif test "x$enable_shared" = "xno" ; then
916*bf6039f0SWarner Losh  enable_shared="0"
917*bf6039f0SWarner Loshelse
918*bf6039f0SWarner Losh  enable_shared="1"
919*bf6039f0SWarner Loshfi
920*bf6039f0SWarner Losh,
921*bf6039f0SWarner Loshenable_shared="1"
922*bf6039f0SWarner Losh)
923*bf6039f0SWarner LoshAC_SUBST([enable_shared])
924*bf6039f0SWarner Losh
925*bf6039f0SWarner Loshdnl Enable static libs
926*bf6039f0SWarner LoshAC_ARG_ENABLE([static],
927*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-static], [Build static libaries])],
928*bf6039f0SWarner Loshif test "x$enable_static" = "xno" ; then
929*bf6039f0SWarner Losh  enable_static="0"
930*bf6039f0SWarner Loshelse
931*bf6039f0SWarner Losh  enable_static="1"
932*bf6039f0SWarner Loshfi
933*bf6039f0SWarner Losh,
934*bf6039f0SWarner Loshenable_static="1"
935*bf6039f0SWarner Losh)
936*bf6039f0SWarner LoshAC_SUBST([enable_static])
937*bf6039f0SWarner Losh
938*bf6039f0SWarner Loshif test "$enable_shared$enable_static" = "00" ; then
939*bf6039f0SWarner Losh  AC_MSG_ERROR([Please enable one of shared or static builds])
940*bf6039f0SWarner Loshfi
941*bf6039f0SWarner Losh
942*bf6039f0SWarner Loshdnl Perform no name mangling by default.
943*bf6039f0SWarner LoshAC_ARG_WITH([mangling],
944*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
945*bf6039f0SWarner Losh  [mangling_map="$with_mangling"], [mangling_map=""])
946*bf6039f0SWarner Losh
947*bf6039f0SWarner Loshdnl Do not prefix public APIs by default.
948*bf6039f0SWarner LoshAC_ARG_WITH([jemalloc_prefix],
949*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
950*bf6039f0SWarner Losh  [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
951*bf6039f0SWarner Losh  [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
952*bf6039f0SWarner Losh  JEMALLOC_PREFIX=""
953*bf6039f0SWarner Loshelse
954*bf6039f0SWarner Losh  JEMALLOC_PREFIX="je_"
955*bf6039f0SWarner Loshfi]
956*bf6039f0SWarner Losh)
957*bf6039f0SWarner Loshif test "x$JEMALLOC_PREFIX" = "x" ; then
958*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_IS_MALLOC])
959*bf6039f0SWarner Loshelse
960*bf6039f0SWarner Losh  JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
961*bf6039f0SWarner Losh  AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
962*bf6039f0SWarner Losh  AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
963*bf6039f0SWarner Loshfi
964*bf6039f0SWarner LoshAC_SUBST([JEMALLOC_PREFIX])
965*bf6039f0SWarner LoshAC_SUBST([JEMALLOC_CPREFIX])
966*bf6039f0SWarner Losh
967*bf6039f0SWarner LoshAC_ARG_WITH([export],
968*bf6039f0SWarner Losh  [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
969*bf6039f0SWarner Losh  [if test "x$with_export" = "xno"; then
970*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_EXPORT],[])
971*bf6039f0SWarner Loshfi]
972*bf6039f0SWarner Losh)
973*bf6039f0SWarner Losh
974*bf6039f0SWarner Loshpublic_syms="aligned_alloc calloc dallocx free mallctl mallctlbymib mallctlnametomib malloc malloc_conf malloc_message malloc_stats_print malloc_usable_size mallocx smallocx_${jemalloc_version_gid} nallocx posix_memalign rallocx realloc sallocx sdallocx xallocx"
975*bf6039f0SWarner Loshdnl Check for additional platform-specific public API functions.
976*bf6039f0SWarner LoshAC_CHECK_FUNC([memalign],
977*bf6039f0SWarner Losh	      [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
978*bf6039f0SWarner Losh	       public_syms="${public_syms} memalign"])
979*bf6039f0SWarner LoshAC_CHECK_FUNC([valloc],
980*bf6039f0SWarner Losh	      [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
981*bf6039f0SWarner Losh	       public_syms="${public_syms} valloc"])
982*bf6039f0SWarner Losh
983*bf6039f0SWarner Loshdnl Check for allocator-related functions that should be wrapped.
984*bf6039f0SWarner Loshwrap_syms=
985*bf6039f0SWarner Loshif test "x${JEMALLOC_PREFIX}" = "x" ; then
986*bf6039f0SWarner Losh  AC_CHECK_FUNC([__libc_calloc],
987*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_CALLOC], [ ])
988*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __libc_calloc"])
989*bf6039f0SWarner Losh  AC_CHECK_FUNC([__libc_free],
990*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_FREE], [ ])
991*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __libc_free"])
992*bf6039f0SWarner Losh  AC_CHECK_FUNC([__libc_malloc],
993*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MALLOC], [ ])
994*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __libc_malloc"])
995*bf6039f0SWarner Losh  AC_CHECK_FUNC([__libc_memalign],
996*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MEMALIGN], [ ])
997*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __libc_memalign"])
998*bf6039f0SWarner Losh  AC_CHECK_FUNC([__libc_realloc],
999*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_REALLOC], [ ])
1000*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __libc_realloc"])
1001*bf6039f0SWarner Losh  AC_CHECK_FUNC([__libc_valloc],
1002*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_VALLOC], [ ])
1003*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __libc_valloc"])
1004*bf6039f0SWarner Losh  AC_CHECK_FUNC([__posix_memalign],
1005*bf6039f0SWarner Losh		[AC_DEFINE([JEMALLOC_OVERRIDE___POSIX_MEMALIGN], [ ])
1006*bf6039f0SWarner Losh		 wrap_syms="${wrap_syms} __posix_memalign"])
1007*bf6039f0SWarner Loshfi
1008*bf6039f0SWarner Losh
1009*bf6039f0SWarner Loshcase "${host}" in
1010*bf6039f0SWarner Losh  *-*-mingw* | *-*-cygwin*)
1011*bf6039f0SWarner Losh    wrap_syms="${wrap_syms} tls_callback"
1012*bf6039f0SWarner Losh    ;;
1013*bf6039f0SWarner Losh  *)
1014*bf6039f0SWarner Losh    ;;
1015*bf6039f0SWarner Loshesac
1016*bf6039f0SWarner Losh
1017*bf6039f0SWarner Loshdnl Mangle library-private APIs.
1018*bf6039f0SWarner LoshAC_ARG_WITH([private_namespace],
1019*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
1020*bf6039f0SWarner Losh  [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
1021*bf6039f0SWarner Losh  [JEMALLOC_PRIVATE_NAMESPACE="je_"]
1022*bf6039f0SWarner Losh)
1023*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
1024*bf6039f0SWarner Loshprivate_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
1025*bf6039f0SWarner LoshAC_SUBST([private_namespace])
1026*bf6039f0SWarner Losh
1027*bf6039f0SWarner Loshdnl Do not add suffix to installed files by default.
1028*bf6039f0SWarner LoshAC_ARG_WITH([install_suffix],
1029*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
1030*bf6039f0SWarner Losh  [INSTALL_SUFFIX="$with_install_suffix"],
1031*bf6039f0SWarner Losh  [INSTALL_SUFFIX=]
1032*bf6039f0SWarner Losh)
1033*bf6039f0SWarner Loshinstall_suffix="$INSTALL_SUFFIX"
1034*bf6039f0SWarner LoshAC_SUBST([install_suffix])
1035*bf6039f0SWarner Losh
1036*bf6039f0SWarner Loshdnl Specify default malloc_conf.
1037*bf6039f0SWarner LoshAC_ARG_WITH([malloc_conf],
1038*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
1039*bf6039f0SWarner Losh  [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
1040*bf6039f0SWarner Losh  [JEMALLOC_CONFIG_MALLOC_CONF=""]
1041*bf6039f0SWarner Losh)
1042*bf6039f0SWarner Loshconfig_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
1043*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
1044*bf6039f0SWarner Losh
1045*bf6039f0SWarner Loshdnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
1046*bf6039f0SWarner Loshdnl jemalloc_protos_jet.h easy.
1047*bf6039f0SWarner Loshje_="je_"
1048*bf6039f0SWarner LoshAC_SUBST([je_])
1049*bf6039f0SWarner Losh
1050*bf6039f0SWarner Loshcfgoutputs_in="Makefile.in"
1051*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
1052*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
1053*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
1054*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
1055*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
1056*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
1057*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
1058*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_preamble.h.in"
1059*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
1060*bf6039f0SWarner Loshcfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
1061*bf6039f0SWarner Losh
1062*bf6039f0SWarner Loshcfgoutputs_out="Makefile"
1063*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
1064*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
1065*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
1066*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
1067*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
1068*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
1069*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
1070*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_preamble.h"
1071*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} test/test.sh"
1072*bf6039f0SWarner Loshcfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
1073*bf6039f0SWarner Losh
1074*bf6039f0SWarner Loshcfgoutputs_tup="Makefile"
1075*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
1076*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
1077*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
1078*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
1079*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
1080*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
1081*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
1082*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_preamble.h"
1083*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
1084*bf6039f0SWarner Loshcfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
1085*bf6039f0SWarner Losh
1086*bf6039f0SWarner Loshcfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
1087*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
1088*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.sh"
1089*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
1090*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
1091*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
1092*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
1093*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
1094*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
1095*bf6039f0SWarner Loshcfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
1096*bf6039f0SWarner Losh
1097*bf6039f0SWarner Loshcfghdrs_out="include/jemalloc/jemalloc_defs.h"
1098*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
1099*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols.awk"
1100*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols_jet.awk"
1101*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
1102*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
1103*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
1104*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
1105*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
1106*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
1107*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
1108*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
1109*bf6039f0SWarner Loshcfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
1110*bf6039f0SWarner Losh
1111*bf6039f0SWarner Loshcfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
1112*bf6039f0SWarner Loshcfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
1113*bf6039f0SWarner Loshcfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
1114*bf6039f0SWarner Losh
1115*bf6039f0SWarner Loshdnl ============================================================================
1116*bf6039f0SWarner Loshdnl jemalloc build options.
1117*bf6039f0SWarner Loshdnl
1118*bf6039f0SWarner Losh
1119*bf6039f0SWarner Loshdnl Do not compile with debugging by default.
1120*bf6039f0SWarner LoshAC_ARG_ENABLE([debug],
1121*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-debug],
1122*bf6039f0SWarner Losh                  [Build debugging code])],
1123*bf6039f0SWarner Losh[if test "x$enable_debug" = "xno" ; then
1124*bf6039f0SWarner Losh  enable_debug="0"
1125*bf6039f0SWarner Loshelse
1126*bf6039f0SWarner Losh  enable_debug="1"
1127*bf6039f0SWarner Loshfi
1128*bf6039f0SWarner Losh],
1129*bf6039f0SWarner Losh[enable_debug="0"]
1130*bf6039f0SWarner Losh)
1131*bf6039f0SWarner Loshif test "x$enable_debug" = "x1" ; then
1132*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_DEBUG], [ ])
1133*bf6039f0SWarner Loshfi
1134*bf6039f0SWarner Loshif test "x$enable_debug" = "x1" ; then
1135*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_DEBUG], [ ])
1136*bf6039f0SWarner Loshfi
1137*bf6039f0SWarner LoshAC_SUBST([enable_debug])
1138*bf6039f0SWarner Losh
1139*bf6039f0SWarner Loshdnl Only optimize if not debugging.
1140*bf6039f0SWarner Loshif test "x$enable_debug" = "x0" ; then
1141*bf6039f0SWarner Losh  if test "x$GCC" = "xyes" ; then
1142*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-O3])
1143*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-O3])
1144*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-funroll-loops])
1145*bf6039f0SWarner Losh  elif test "x$je_cv_msvc" = "xyes" ; then
1146*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-O2])
1147*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-O2])
1148*bf6039f0SWarner Losh  else
1149*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-O])
1150*bf6039f0SWarner Losh    JE_CXXFLAGS_ADD([-O])
1151*bf6039f0SWarner Losh  fi
1152*bf6039f0SWarner Loshfi
1153*bf6039f0SWarner Losh
1154*bf6039f0SWarner Loshdnl Enable statistics calculation by default.
1155*bf6039f0SWarner LoshAC_ARG_ENABLE([stats],
1156*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-stats],
1157*bf6039f0SWarner Losh                  [Disable statistics calculation/reporting])],
1158*bf6039f0SWarner Losh[if test "x$enable_stats" = "xno" ; then
1159*bf6039f0SWarner Losh  enable_stats="0"
1160*bf6039f0SWarner Loshelse
1161*bf6039f0SWarner Losh  enable_stats="1"
1162*bf6039f0SWarner Loshfi
1163*bf6039f0SWarner Losh],
1164*bf6039f0SWarner Losh[enable_stats="1"]
1165*bf6039f0SWarner Losh)
1166*bf6039f0SWarner Loshif test "x$enable_stats" = "x1" ; then
1167*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_STATS], [ ])
1168*bf6039f0SWarner Loshfi
1169*bf6039f0SWarner LoshAC_SUBST([enable_stats])
1170*bf6039f0SWarner Losh
1171*bf6039f0SWarner Loshdnl Do not enable smallocx by default.
1172*bf6039f0SWarner LoshAC_ARG_ENABLE([experimental_smallocx],
1173*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-experimental-smallocx], [Enable experimental smallocx API])],
1174*bf6039f0SWarner Losh[if test "x$enable_experimental_smallocx" = "xno" ; then
1175*bf6039f0SWarner Loshenable_experimental_smallocx="0"
1176*bf6039f0SWarner Loshelse
1177*bf6039f0SWarner Loshenable_experimental_smallocx="1"
1178*bf6039f0SWarner Loshfi
1179*bf6039f0SWarner Losh],
1180*bf6039f0SWarner Losh[enable_experimental_smallocx="0"]
1181*bf6039f0SWarner Losh)
1182*bf6039f0SWarner Loshif test "x$enable_experimental_smallocx" = "x1" ; then
1183*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_EXPERIMENTAL_SMALLOCX_API])
1184*bf6039f0SWarner Loshfi
1185*bf6039f0SWarner LoshAC_SUBST([enable_experimental_smallocx])
1186*bf6039f0SWarner Losh
1187*bf6039f0SWarner Loshdnl Do not enable profiling by default.
1188*bf6039f0SWarner LoshAC_ARG_ENABLE([prof],
1189*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
1190*bf6039f0SWarner Losh[if test "x$enable_prof" = "xno" ; then
1191*bf6039f0SWarner Losh  enable_prof="0"
1192*bf6039f0SWarner Loshelse
1193*bf6039f0SWarner Losh  enable_prof="1"
1194*bf6039f0SWarner Loshfi
1195*bf6039f0SWarner Losh],
1196*bf6039f0SWarner Losh[enable_prof="0"]
1197*bf6039f0SWarner Losh)
1198*bf6039f0SWarner Loshif test "x$enable_prof" = "x1" ; then
1199*bf6039f0SWarner Losh  backtrace_method=""
1200*bf6039f0SWarner Loshelse
1201*bf6039f0SWarner Losh  backtrace_method="N/A"
1202*bf6039f0SWarner Loshfi
1203*bf6039f0SWarner Losh
1204*bf6039f0SWarner LoshAC_ARG_ENABLE([prof-libunwind],
1205*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
1206*bf6039f0SWarner Losh[if test "x$enable_prof_libunwind" = "xno" ; then
1207*bf6039f0SWarner Losh  enable_prof_libunwind="0"
1208*bf6039f0SWarner Loshelse
1209*bf6039f0SWarner Losh  enable_prof_libunwind="1"
1210*bf6039f0SWarner Loshfi
1211*bf6039f0SWarner Losh],
1212*bf6039f0SWarner Losh[enable_prof_libunwind="0"]
1213*bf6039f0SWarner Losh)
1214*bf6039f0SWarner LoshAC_ARG_WITH([static_libunwind],
1215*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
1216*bf6039f0SWarner Losh  [Path to static libunwind library; use rather than dynamically linking])],
1217*bf6039f0SWarner Loshif test "x$with_static_libunwind" = "xno" ; then
1218*bf6039f0SWarner Losh  LUNWIND="-lunwind"
1219*bf6039f0SWarner Loshelse
1220*bf6039f0SWarner Losh  if test ! -f "$with_static_libunwind" ; then
1221*bf6039f0SWarner Losh    AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
1222*bf6039f0SWarner Losh  fi
1223*bf6039f0SWarner Losh  LUNWIND="$with_static_libunwind"
1224*bf6039f0SWarner Loshfi,
1225*bf6039f0SWarner Losh  LUNWIND="-lunwind"
1226*bf6039f0SWarner Losh)
1227*bf6039f0SWarner Loshif test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
1228*bf6039f0SWarner Losh  AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
1229*bf6039f0SWarner Losh  if test "x$LUNWIND" = "x-lunwind" ; then
1230*bf6039f0SWarner Losh    AC_CHECK_LIB([unwind], [unw_backtrace], [JE_APPEND_VS(LIBS, $LUNWIND)],
1231*bf6039f0SWarner Losh                 [enable_prof_libunwind="0"])
1232*bf6039f0SWarner Losh  else
1233*bf6039f0SWarner Losh    JE_APPEND_VS(LIBS, $LUNWIND)
1234*bf6039f0SWarner Losh  fi
1235*bf6039f0SWarner Losh  if test "x${enable_prof_libunwind}" = "x1" ; then
1236*bf6039f0SWarner Losh    backtrace_method="libunwind"
1237*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
1238*bf6039f0SWarner Losh  fi
1239*bf6039f0SWarner Loshfi
1240*bf6039f0SWarner Losh
1241*bf6039f0SWarner LoshAC_ARG_ENABLE([prof-libgcc],
1242*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-prof-libgcc],
1243*bf6039f0SWarner Losh  [Do not use libgcc for backtracing])],
1244*bf6039f0SWarner Losh[if test "x$enable_prof_libgcc" = "xno" ; then
1245*bf6039f0SWarner Losh  enable_prof_libgcc="0"
1246*bf6039f0SWarner Loshelse
1247*bf6039f0SWarner Losh  enable_prof_libgcc="1"
1248*bf6039f0SWarner Loshfi
1249*bf6039f0SWarner Losh],
1250*bf6039f0SWarner Losh[enable_prof_libgcc="1"]
1251*bf6039f0SWarner Losh)
1252*bf6039f0SWarner Loshif test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
1253*bf6039f0SWarner Losh     -a "x$GCC" = "xyes" ; then
1254*bf6039f0SWarner Losh  AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
1255*bf6039f0SWarner Losh  if test "x${enable_prof_libgcc}" = "x1" ; then
1256*bf6039f0SWarner Losh    AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [JE_APPEND_VS(LIBS, -lgcc)], [enable_prof_libgcc="0"])
1257*bf6039f0SWarner Losh  fi
1258*bf6039f0SWarner Losh  if test "x${enable_prof_libgcc}" = "x1" ; then
1259*bf6039f0SWarner Losh    backtrace_method="libgcc"
1260*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
1261*bf6039f0SWarner Losh  fi
1262*bf6039f0SWarner Loshelse
1263*bf6039f0SWarner Losh  enable_prof_libgcc="0"
1264*bf6039f0SWarner Loshfi
1265*bf6039f0SWarner Losh
1266*bf6039f0SWarner LoshAC_ARG_ENABLE([prof-gcc],
1267*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-prof-gcc],
1268*bf6039f0SWarner Losh  [Do not use gcc intrinsics for backtracing])],
1269*bf6039f0SWarner Losh[if test "x$enable_prof_gcc" = "xno" ; then
1270*bf6039f0SWarner Losh  enable_prof_gcc="0"
1271*bf6039f0SWarner Loshelse
1272*bf6039f0SWarner Losh  enable_prof_gcc="1"
1273*bf6039f0SWarner Loshfi
1274*bf6039f0SWarner Losh],
1275*bf6039f0SWarner Losh[enable_prof_gcc="1"]
1276*bf6039f0SWarner Losh)
1277*bf6039f0SWarner Loshif test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
1278*bf6039f0SWarner Losh     -a "x$GCC" = "xyes" ; then
1279*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-fno-omit-frame-pointer])
1280*bf6039f0SWarner Losh  backtrace_method="gcc intrinsics"
1281*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
1282*bf6039f0SWarner Loshelse
1283*bf6039f0SWarner Losh  enable_prof_gcc="0"
1284*bf6039f0SWarner Loshfi
1285*bf6039f0SWarner Losh
1286*bf6039f0SWarner Loshif test "x$backtrace_method" = "x" ; then
1287*bf6039f0SWarner Losh  backtrace_method="none (disabling profiling)"
1288*bf6039f0SWarner Losh  enable_prof="0"
1289*bf6039f0SWarner Loshfi
1290*bf6039f0SWarner LoshAC_MSG_CHECKING([configured backtracing method])
1291*bf6039f0SWarner LoshAC_MSG_RESULT([$backtrace_method])
1292*bf6039f0SWarner Loshif test "x$enable_prof" = "x1" ; then
1293*bf6039f0SWarner Losh  dnl Heap profiling uses the log(3) function.
1294*bf6039f0SWarner Losh  JE_APPEND_VS(LIBS, $LM)
1295*bf6039f0SWarner Losh
1296*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_PROF], [ ])
1297*bf6039f0SWarner Loshfi
1298*bf6039f0SWarner LoshAC_SUBST([enable_prof])
1299*bf6039f0SWarner Losh
1300*bf6039f0SWarner Loshdnl Indicate whether adjacent virtual memory mappings automatically coalesce
1301*bf6039f0SWarner Loshdnl (and fragment on demand).
1302*bf6039f0SWarner Loshif test "x${maps_coalesce}" = "x1" ; then
1303*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
1304*bf6039f0SWarner Loshfi
1305*bf6039f0SWarner Losh
1306*bf6039f0SWarner Loshdnl Indicate whether to retain memory (rather than using munmap()) by default.
1307*bf6039f0SWarner Loshif test "x$default_retain" = "x1" ; then
1308*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_RETAIN], [ ])
1309*bf6039f0SWarner Loshfi
1310*bf6039f0SWarner Losh
1311*bf6039f0SWarner Loshdnl Enable allocation from DSS if supported by the OS.
1312*bf6039f0SWarner Loshhave_dss="1"
1313*bf6039f0SWarner Loshdnl Check whether the BSD/SUSv1 sbrk() exists.  If not, disable DSS support.
1314*bf6039f0SWarner LoshAC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
1315*bf6039f0SWarner Loshif test "x$have_sbrk" = "x1" ; then
1316*bf6039f0SWarner Losh  if test "x$sbrk_deprecated" = "x1" ; then
1317*bf6039f0SWarner Losh    AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
1318*bf6039f0SWarner Losh    have_dss="0"
1319*bf6039f0SWarner Losh  fi
1320*bf6039f0SWarner Loshelse
1321*bf6039f0SWarner Losh  have_dss="0"
1322*bf6039f0SWarner Loshfi
1323*bf6039f0SWarner Losh
1324*bf6039f0SWarner Loshif test "x$have_dss" = "x1" ; then
1325*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_DSS], [ ])
1326*bf6039f0SWarner Loshfi
1327*bf6039f0SWarner Losh
1328*bf6039f0SWarner Loshdnl Support the junk/zero filling option by default.
1329*bf6039f0SWarner LoshAC_ARG_ENABLE([fill],
1330*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-fill], [Disable support for junk/zero filling])],
1331*bf6039f0SWarner Losh[if test "x$enable_fill" = "xno" ; then
1332*bf6039f0SWarner Losh  enable_fill="0"
1333*bf6039f0SWarner Loshelse
1334*bf6039f0SWarner Losh  enable_fill="1"
1335*bf6039f0SWarner Loshfi
1336*bf6039f0SWarner Losh],
1337*bf6039f0SWarner Losh[enable_fill="1"]
1338*bf6039f0SWarner Losh)
1339*bf6039f0SWarner Loshif test "x$enable_fill" = "x1" ; then
1340*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_FILL], [ ])
1341*bf6039f0SWarner Loshfi
1342*bf6039f0SWarner LoshAC_SUBST([enable_fill])
1343*bf6039f0SWarner Losh
1344*bf6039f0SWarner Loshdnl Disable utrace(2)-based tracing by default.
1345*bf6039f0SWarner LoshAC_ARG_ENABLE([utrace],
1346*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
1347*bf6039f0SWarner Losh[if test "x$enable_utrace" = "xno" ; then
1348*bf6039f0SWarner Losh  enable_utrace="0"
1349*bf6039f0SWarner Loshelse
1350*bf6039f0SWarner Losh  enable_utrace="1"
1351*bf6039f0SWarner Loshfi
1352*bf6039f0SWarner Losh],
1353*bf6039f0SWarner Losh[enable_utrace="0"]
1354*bf6039f0SWarner Losh)
1355*bf6039f0SWarner LoshJE_COMPILABLE([utrace(2)], [
1356*bf6039f0SWarner Losh#include <sys/types.h>
1357*bf6039f0SWarner Losh#include <sys/param.h>
1358*bf6039f0SWarner Losh#include <sys/time.h>
1359*bf6039f0SWarner Losh#include <sys/uio.h>
1360*bf6039f0SWarner Losh#include <sys/ktrace.h>
1361*bf6039f0SWarner Losh], [
1362*bf6039f0SWarner Losh	utrace((void *)0, 0);
1363*bf6039f0SWarner Losh], [je_cv_utrace])
1364*bf6039f0SWarner Loshif test "x${je_cv_utrace}" = "xno" ; then
1365*bf6039f0SWarner Losh  enable_utrace="0"
1366*bf6039f0SWarner Loshfi
1367*bf6039f0SWarner Loshif test "x$enable_utrace" = "x1" ; then
1368*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_UTRACE], [ ])
1369*bf6039f0SWarner Loshfi
1370*bf6039f0SWarner LoshAC_SUBST([enable_utrace])
1371*bf6039f0SWarner Losh
1372*bf6039f0SWarner Loshdnl Do not support the xmalloc option by default.
1373*bf6039f0SWarner LoshAC_ARG_ENABLE([xmalloc],
1374*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1375*bf6039f0SWarner Losh[if test "x$enable_xmalloc" = "xno" ; then
1376*bf6039f0SWarner Losh  enable_xmalloc="0"
1377*bf6039f0SWarner Loshelse
1378*bf6039f0SWarner Losh  enable_xmalloc="1"
1379*bf6039f0SWarner Loshfi
1380*bf6039f0SWarner Losh],
1381*bf6039f0SWarner Losh[enable_xmalloc="0"]
1382*bf6039f0SWarner Losh)
1383*bf6039f0SWarner Loshif test "x$enable_xmalloc" = "x1" ; then
1384*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1385*bf6039f0SWarner Loshfi
1386*bf6039f0SWarner LoshAC_SUBST([enable_xmalloc])
1387*bf6039f0SWarner Losh
1388*bf6039f0SWarner Loshdnl Support cache-oblivious allocation alignment by default.
1389*bf6039f0SWarner LoshAC_ARG_ENABLE([cache-oblivious],
1390*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-cache-oblivious],
1391*bf6039f0SWarner Losh                  [Disable support for cache-oblivious allocation alignment])],
1392*bf6039f0SWarner Losh[if test "x$enable_cache_oblivious" = "xno" ; then
1393*bf6039f0SWarner Losh  enable_cache_oblivious="0"
1394*bf6039f0SWarner Loshelse
1395*bf6039f0SWarner Losh  enable_cache_oblivious="1"
1396*bf6039f0SWarner Loshfi
1397*bf6039f0SWarner Losh],
1398*bf6039f0SWarner Losh[enable_cache_oblivious="1"]
1399*bf6039f0SWarner Losh)
1400*bf6039f0SWarner Loshif test "x$enable_cache_oblivious" = "x1" ; then
1401*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1402*bf6039f0SWarner Loshfi
1403*bf6039f0SWarner LoshAC_SUBST([enable_cache_oblivious])
1404*bf6039f0SWarner Losh
1405*bf6039f0SWarner Loshdnl Do not log by default.
1406*bf6039f0SWarner LoshAC_ARG_ENABLE([log],
1407*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-log], [Support debug logging])],
1408*bf6039f0SWarner Losh[if test "x$enable_log" = "xno" ; then
1409*bf6039f0SWarner Losh  enable_log="0"
1410*bf6039f0SWarner Loshelse
1411*bf6039f0SWarner Losh  enable_log="1"
1412*bf6039f0SWarner Loshfi
1413*bf6039f0SWarner Losh],
1414*bf6039f0SWarner Losh[enable_log="0"]
1415*bf6039f0SWarner Losh)
1416*bf6039f0SWarner Loshif test "x$enable_log" = "x1" ; then
1417*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_LOG], [ ])
1418*bf6039f0SWarner Loshfi
1419*bf6039f0SWarner LoshAC_SUBST([enable_log])
1420*bf6039f0SWarner Losh
1421*bf6039f0SWarner Loshdnl Do not use readlinkat by default
1422*bf6039f0SWarner LoshAC_ARG_ENABLE([readlinkat],
1423*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-readlinkat], [Use readlinkat over readlink])],
1424*bf6039f0SWarner Losh[if test "x$enable_readlinkat" = "xno" ; then
1425*bf6039f0SWarner Losh  enable_readlinkat="0"
1426*bf6039f0SWarner Loshelse
1427*bf6039f0SWarner Losh  enable_readlinkat="1"
1428*bf6039f0SWarner Loshfi
1429*bf6039f0SWarner Losh],
1430*bf6039f0SWarner Losh[enable_readlinkat="0"]
1431*bf6039f0SWarner Losh)
1432*bf6039f0SWarner Loshif test "x$enable_readlinkat" = "x1" ; then
1433*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_READLINKAT], [ ])
1434*bf6039f0SWarner Loshfi
1435*bf6039f0SWarner LoshAC_SUBST([enable_readlinkat])
1436*bf6039f0SWarner Losh
1437*bf6039f0SWarner Loshdnl Avoid extra safety checks by default
1438*bf6039f0SWarner LoshAC_ARG_ENABLE([opt-safety-checks],
1439*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-opt-safety-checks],
1440*bf6039f0SWarner Losh  [Perform certain low-overhead checks, even in opt mode])],
1441*bf6039f0SWarner Losh[if test "x$enable_opt_safety_checks" = "xno" ; then
1442*bf6039f0SWarner Losh  enable_opt_safety_checks="0"
1443*bf6039f0SWarner Loshelse
1444*bf6039f0SWarner Losh  enable_opt_safety_checks="1"
1445*bf6039f0SWarner Loshfi
1446*bf6039f0SWarner Losh],
1447*bf6039f0SWarner Losh[enable_opt_safety_checks="0"]
1448*bf6039f0SWarner Losh)
1449*bf6039f0SWarner Loshif test "x$enable_opt_safety_checks" = "x1" ; then
1450*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_OPT_SAFETY_CHECKS], [ ])
1451*bf6039f0SWarner Loshfi
1452*bf6039f0SWarner LoshAC_SUBST([enable_opt_safety_checks])
1453*bf6039f0SWarner Losh
1454*bf6039f0SWarner LoshJE_COMPILABLE([a program using __builtin_unreachable], [
1455*bf6039f0SWarner Loshvoid foo (void) {
1456*bf6039f0SWarner Losh  __builtin_unreachable();
1457*bf6039f0SWarner Losh}
1458*bf6039f0SWarner Losh], [
1459*bf6039f0SWarner Losh	{
1460*bf6039f0SWarner Losh		foo();
1461*bf6039f0SWarner Losh	}
1462*bf6039f0SWarner Losh], [je_cv_gcc_builtin_unreachable])
1463*bf6039f0SWarner Loshif test "x${je_cv_gcc_builtin_unreachable}" = "xyes" ; then
1464*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [__builtin_unreachable])
1465*bf6039f0SWarner Loshelse
1466*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [abort])
1467*bf6039f0SWarner Loshfi
1468*bf6039f0SWarner Losh
1469*bf6039f0SWarner Loshdnl ============================================================================
1470*bf6039f0SWarner Loshdnl Check for  __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1471*bf6039f0SWarner Loshdnl One of those two functions should (theoretically) exist on all platforms
1472*bf6039f0SWarner Loshdnl that jemalloc currently has a chance of functioning on without modification.
1473*bf6039f0SWarner Loshdnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
1474*bf6039f0SWarner Loshdnl ffsl() or __builtin_ffsl() are defined, respectively.
1475*bf6039f0SWarner LoshJE_COMPILABLE([a program using __builtin_ffsl], [
1476*bf6039f0SWarner Losh#include <stdio.h>
1477*bf6039f0SWarner Losh#include <strings.h>
1478*bf6039f0SWarner Losh#include <string.h>
1479*bf6039f0SWarner Losh], [
1480*bf6039f0SWarner Losh	{
1481*bf6039f0SWarner Losh		int rv = __builtin_ffsl(0x08);
1482*bf6039f0SWarner Losh		printf("%d\n", rv);
1483*bf6039f0SWarner Losh	}
1484*bf6039f0SWarner Losh], [je_cv_gcc_builtin_ffsl])
1485*bf6039f0SWarner Loshif test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
1486*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
1487*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1488*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1489*bf6039f0SWarner Loshelse
1490*bf6039f0SWarner Losh  JE_COMPILABLE([a program using ffsl], [
1491*bf6039f0SWarner Losh  #include <stdio.h>
1492*bf6039f0SWarner Losh  #include <strings.h>
1493*bf6039f0SWarner Losh  #include <string.h>
1494*bf6039f0SWarner Losh  ], [
1495*bf6039f0SWarner Losh	{
1496*bf6039f0SWarner Losh		int rv = ffsl(0x08);
1497*bf6039f0SWarner Losh		printf("%d\n", rv);
1498*bf6039f0SWarner Losh	}
1499*bf6039f0SWarner Losh  ], [je_cv_function_ffsl])
1500*bf6039f0SWarner Losh  if test "x${je_cv_function_ffsl}" = "xyes" ; then
1501*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
1502*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1503*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1504*bf6039f0SWarner Losh  else
1505*bf6039f0SWarner Losh    AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1506*bf6039f0SWarner Losh  fi
1507*bf6039f0SWarner Loshfi
1508*bf6039f0SWarner Losh
1509*bf6039f0SWarner LoshJE_COMPILABLE([a program using __builtin_popcountl], [
1510*bf6039f0SWarner Losh#include <stdio.h>
1511*bf6039f0SWarner Losh#include <strings.h>
1512*bf6039f0SWarner Losh#include <string.h>
1513*bf6039f0SWarner Losh], [
1514*bf6039f0SWarner Losh	{
1515*bf6039f0SWarner Losh		int rv = __builtin_popcountl(0x08);
1516*bf6039f0SWarner Losh		printf("%d\n", rv);
1517*bf6039f0SWarner Losh	}
1518*bf6039f0SWarner Losh], [je_cv_gcc_builtin_popcountl])
1519*bf6039f0SWarner Loshif test "x${je_cv_gcc_builtin_popcountl}" = "xyes" ; then
1520*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_POPCOUNT], [__builtin_popcount])
1521*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_INTERNAL_POPCOUNTL], [__builtin_popcountl])
1522*bf6039f0SWarner Loshfi
1523*bf6039f0SWarner Losh
1524*bf6039f0SWarner LoshAC_ARG_WITH([lg_quantum],
1525*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1526*bf6039f0SWarner Losh   [Base 2 log of minimum allocation alignment])],
1527*bf6039f0SWarner Losh  [LG_QUANTA="$with_lg_quantum"],
1528*bf6039f0SWarner Losh  [LG_QUANTA="3 4"])
1529*bf6039f0SWarner Loshif test "x$with_lg_quantum" != "x" ; then
1530*bf6039f0SWarner Losh  AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1531*bf6039f0SWarner Loshfi
1532*bf6039f0SWarner Losh
1533*bf6039f0SWarner LoshAC_ARG_WITH([lg_page],
1534*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1535*bf6039f0SWarner Losh  [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
1536*bf6039f0SWarner Loshif test "x$LG_PAGE" = "xdetect"; then
1537*bf6039f0SWarner Losh  AC_CACHE_CHECK([LG_PAGE],
1538*bf6039f0SWarner Losh               [je_cv_lg_page],
1539*bf6039f0SWarner Losh               AC_RUN_IFELSE([AC_LANG_PROGRAM(
1540*bf6039f0SWarner Losh[[
1541*bf6039f0SWarner Losh#include <strings.h>
1542*bf6039f0SWarner Losh#ifdef _WIN32
1543*bf6039f0SWarner Losh#include <windows.h>
1544*bf6039f0SWarner Losh#else
1545*bf6039f0SWarner Losh#include <unistd.h>
1546*bf6039f0SWarner Losh#endif
1547*bf6039f0SWarner Losh#include <stdio.h>
1548*bf6039f0SWarner Losh]],
1549*bf6039f0SWarner Losh[[
1550*bf6039f0SWarner Losh    int result;
1551*bf6039f0SWarner Losh    FILE *f;
1552*bf6039f0SWarner Losh
1553*bf6039f0SWarner Losh#ifdef _WIN32
1554*bf6039f0SWarner Losh    SYSTEM_INFO si;
1555*bf6039f0SWarner Losh    GetSystemInfo(&si);
1556*bf6039f0SWarner Losh    result = si.dwPageSize;
1557*bf6039f0SWarner Losh#else
1558*bf6039f0SWarner Losh    result = sysconf(_SC_PAGESIZE);
1559*bf6039f0SWarner Losh#endif
1560*bf6039f0SWarner Losh    if (result == -1) {
1561*bf6039f0SWarner Losh	return 1;
1562*bf6039f0SWarner Losh    }
1563*bf6039f0SWarner Losh    result = JEMALLOC_INTERNAL_FFSL(result) - 1;
1564*bf6039f0SWarner Losh
1565*bf6039f0SWarner Losh    f = fopen("conftest.out", "w");
1566*bf6039f0SWarner Losh    if (f == NULL) {
1567*bf6039f0SWarner Losh	return 1;
1568*bf6039f0SWarner Losh    }
1569*bf6039f0SWarner Losh    fprintf(f, "%d", result);
1570*bf6039f0SWarner Losh    fclose(f);
1571*bf6039f0SWarner Losh
1572*bf6039f0SWarner Losh    return 0;
1573*bf6039f0SWarner Losh]])],
1574*bf6039f0SWarner Losh                             [je_cv_lg_page=`cat conftest.out`],
1575*bf6039f0SWarner Losh                             [je_cv_lg_page=undefined],
1576*bf6039f0SWarner Losh                             [je_cv_lg_page=12]))
1577*bf6039f0SWarner Loshfi
1578*bf6039f0SWarner Loshif test "x${je_cv_lg_page}" != "x" ; then
1579*bf6039f0SWarner Losh  LG_PAGE="${je_cv_lg_page}"
1580*bf6039f0SWarner Loshfi
1581*bf6039f0SWarner Loshif test "x${LG_PAGE}" != "xundefined" ; then
1582*bf6039f0SWarner Losh   AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1583*bf6039f0SWarner Loshelse
1584*bf6039f0SWarner Losh   AC_MSG_ERROR([cannot determine value for LG_PAGE])
1585*bf6039f0SWarner Loshfi
1586*bf6039f0SWarner Losh
1587*bf6039f0SWarner LoshAC_ARG_WITH([lg_hugepage],
1588*bf6039f0SWarner Losh  [AS_HELP_STRING([--with-lg-hugepage=<lg-hugepage>],
1589*bf6039f0SWarner Losh   [Base 2 log of system huge page size])],
1590*bf6039f0SWarner Losh  [je_cv_lg_hugepage="${with_lg_hugepage}"],
1591*bf6039f0SWarner Losh  [je_cv_lg_hugepage=""])
1592*bf6039f0SWarner Loshif test "x${je_cv_lg_hugepage}" = "x" ; then
1593*bf6039f0SWarner Losh  dnl Look in /proc/meminfo (Linux-specific) for information on the default huge
1594*bf6039f0SWarner Losh  dnl page size, if any.  The relevant line looks like:
1595*bf6039f0SWarner Losh  dnl
1596*bf6039f0SWarner Losh  dnl   Hugepagesize:       2048 kB
1597*bf6039f0SWarner Losh  if test -e "/proc/meminfo" ; then
1598*bf6039f0SWarner Losh    hpsk=[`cat /proc/meminfo 2>/dev/null | \
1599*bf6039f0SWarner Losh          grep -e '^Hugepagesize:[[:space:]]\+[0-9]\+[[:space:]]kB$' | \
1600*bf6039f0SWarner Losh          awk '{print $2}'`]
1601*bf6039f0SWarner Losh    if test "x${hpsk}" != "x" ; then
1602*bf6039f0SWarner Losh      je_cv_lg_hugepage=10
1603*bf6039f0SWarner Losh      while test "${hpsk}" -gt 1 ; do
1604*bf6039f0SWarner Losh        hpsk="$((hpsk / 2))"
1605*bf6039f0SWarner Losh        je_cv_lg_hugepage="$((je_cv_lg_hugepage + 1))"
1606*bf6039f0SWarner Losh      done
1607*bf6039f0SWarner Losh    fi
1608*bf6039f0SWarner Losh  fi
1609*bf6039f0SWarner Losh
1610*bf6039f0SWarner Losh  dnl Set default if unable to automatically configure.
1611*bf6039f0SWarner Losh  if test "x${je_cv_lg_hugepage}" = "x" ; then
1612*bf6039f0SWarner Losh    je_cv_lg_hugepage=21
1613*bf6039f0SWarner Losh  fi
1614*bf6039f0SWarner Loshfi
1615*bf6039f0SWarner Loshif test "x${LG_PAGE}" != "xundefined" -a \
1616*bf6039f0SWarner Losh        "${je_cv_lg_hugepage}" -lt "${LG_PAGE}" ; then
1617*bf6039f0SWarner Losh  AC_MSG_ERROR([Huge page size (2^${je_cv_lg_hugepage}) must be at least page size (2^${LG_PAGE})])
1618*bf6039f0SWarner Loshfi
1619*bf6039f0SWarner LoshAC_DEFINE_UNQUOTED([LG_HUGEPAGE], [${je_cv_lg_hugepage}])
1620*bf6039f0SWarner Losh
1621*bf6039f0SWarner Loshdnl ============================================================================
1622*bf6039f0SWarner Loshdnl Enable libdl by default.
1623*bf6039f0SWarner LoshAC_ARG_ENABLE([libdl],
1624*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-libdl],
1625*bf6039f0SWarner Losh  [Do not use libdl])],
1626*bf6039f0SWarner Losh[if test "x$enable_libdl" = "xno" ; then
1627*bf6039f0SWarner Losh  enable_libdl="0"
1628*bf6039f0SWarner Loshelse
1629*bf6039f0SWarner Losh  enable_libdl="1"
1630*bf6039f0SWarner Loshfi
1631*bf6039f0SWarner Losh],
1632*bf6039f0SWarner Losh[enable_libdl="1"]
1633*bf6039f0SWarner Losh)
1634*bf6039f0SWarner LoshAC_SUBST([libdl])
1635*bf6039f0SWarner Losh
1636*bf6039f0SWarner Loshdnl ============================================================================
1637*bf6039f0SWarner Loshdnl Configure pthreads.
1638*bf6039f0SWarner Losh
1639*bf6039f0SWarner Loshif test "x$abi" != "xpecoff" ; then
1640*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_PTHREAD], [ ])
1641*bf6039f0SWarner Losh  AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1642*bf6039f0SWarner Losh  dnl Some systems may embed pthreads functionality in libc; check for libpthread
1643*bf6039f0SWarner Losh  dnl first, but try libc too before failing.
1644*bf6039f0SWarner Losh  AC_CHECK_LIB([pthread], [pthread_create], [JE_APPEND_VS(LIBS, -pthread)],
1645*bf6039f0SWarner Losh               [AC_SEARCH_LIBS([pthread_create], , ,
1646*bf6039f0SWarner Losh                               AC_MSG_ERROR([libpthread is missing]))])
1647*bf6039f0SWarner Losh  wrap_syms="${wrap_syms} pthread_create"
1648*bf6039f0SWarner Losh  have_pthread="1"
1649*bf6039f0SWarner Losh
1650*bf6039f0SWarner Loshdnl Check if we have dlsym support.
1651*bf6039f0SWarner Losh  if test "x$enable_libdl" = "x1" ; then
1652*bf6039f0SWarner Losh    have_dlsym="1"
1653*bf6039f0SWarner Losh    AC_CHECK_HEADERS([dlfcn.h],
1654*bf6039f0SWarner Losh      AC_CHECK_FUNC([dlsym], [],
1655*bf6039f0SWarner Losh        [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"], [have_dlsym="0"])]),
1656*bf6039f0SWarner Losh      [have_dlsym="0"])
1657*bf6039f0SWarner Losh    if test "x$have_dlsym" = "x1" ; then
1658*bf6039f0SWarner Losh      AC_DEFINE([JEMALLOC_HAVE_DLSYM], [ ])
1659*bf6039f0SWarner Losh    fi
1660*bf6039f0SWarner Losh  else
1661*bf6039f0SWarner Losh    have_dlsym="0"
1662*bf6039f0SWarner Losh  fi
1663*bf6039f0SWarner Losh
1664*bf6039f0SWarner Losh  JE_COMPILABLE([pthread_atfork(3)], [
1665*bf6039f0SWarner Losh#include <pthread.h>
1666*bf6039f0SWarner Losh], [
1667*bf6039f0SWarner Losh  pthread_atfork((void *)0, (void *)0, (void *)0);
1668*bf6039f0SWarner Losh], [je_cv_pthread_atfork])
1669*bf6039f0SWarner Losh  if test "x${je_cv_pthread_atfork}" = "xyes" ; then
1670*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_HAVE_PTHREAD_ATFORK], [ ])
1671*bf6039f0SWarner Losh  fi
1672*bf6039f0SWarner Losh  dnl Check if pthread_setname_np is available with the expected API.
1673*bf6039f0SWarner Losh  JE_COMPILABLE([pthread_setname_np(3)], [
1674*bf6039f0SWarner Losh#include <pthread.h>
1675*bf6039f0SWarner Losh], [
1676*bf6039f0SWarner Losh  pthread_setname_np(pthread_self(), "setname_test");
1677*bf6039f0SWarner Losh], [je_cv_pthread_setname_np])
1678*bf6039f0SWarner Losh  if test "x${je_cv_pthread_setname_np}" = "xyes" ; then
1679*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_HAVE_PTHREAD_SETNAME_NP], [ ])
1680*bf6039f0SWarner Losh  fi
1681*bf6039f0SWarner Loshfi
1682*bf6039f0SWarner Losh
1683*bf6039f0SWarner LoshJE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
1684*bf6039f0SWarner Losh
1685*bf6039f0SWarner Loshdnl Check whether clock_gettime(2) is in libc or librt.
1686*bf6039f0SWarner LoshAC_SEARCH_LIBS([clock_gettime], [rt])
1687*bf6039f0SWarner Losh
1688*bf6039f0SWarner Loshdnl Cray wrapper compiler often adds `-lrt` when using `-static`. Check with
1689*bf6039f0SWarner Loshdnl `-dynamic` as well in case a user tries to dynamically link in jemalloc
1690*bf6039f0SWarner Loshif test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
1691*bf6039f0SWarner Losh  if test "$ac_cv_search_clock_gettime" != "-lrt"; then
1692*bf6039f0SWarner Losh    JE_CFLAGS_SAVE()
1693*bf6039f0SWarner Losh
1694*bf6039f0SWarner Losh    unset ac_cv_search_clock_gettime
1695*bf6039f0SWarner Losh    JE_CFLAGS_ADD([-dynamic])
1696*bf6039f0SWarner Losh    AC_SEARCH_LIBS([clock_gettime], [rt])
1697*bf6039f0SWarner Losh
1698*bf6039f0SWarner Losh    JE_CFLAGS_RESTORE()
1699*bf6039f0SWarner Losh  fi
1700*bf6039f0SWarner Loshfi
1701*bf6039f0SWarner Losh
1702*bf6039f0SWarner Loshdnl check for CLOCK_MONOTONIC_COARSE (Linux-specific).
1703*bf6039f0SWarner LoshJE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC_COARSE, ...)], [
1704*bf6039f0SWarner Losh#include <time.h>
1705*bf6039f0SWarner Losh], [
1706*bf6039f0SWarner Losh	struct timespec ts;
1707*bf6039f0SWarner Losh
1708*bf6039f0SWarner Losh	clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
1709*bf6039f0SWarner Losh], [je_cv_clock_monotonic_coarse])
1710*bf6039f0SWarner Loshif test "x${je_cv_clock_monotonic_coarse}" = "xyes" ; then
1711*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC_COARSE])
1712*bf6039f0SWarner Loshfi
1713*bf6039f0SWarner Losh
1714*bf6039f0SWarner Loshdnl check for CLOCK_MONOTONIC.
1715*bf6039f0SWarner LoshJE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC, ...)], [
1716*bf6039f0SWarner Losh#include <unistd.h>
1717*bf6039f0SWarner Losh#include <time.h>
1718*bf6039f0SWarner Losh], [
1719*bf6039f0SWarner Losh	struct timespec ts;
1720*bf6039f0SWarner Losh
1721*bf6039f0SWarner Losh	clock_gettime(CLOCK_MONOTONIC, &ts);
1722*bf6039f0SWarner Losh#if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0
1723*bf6039f0SWarner Losh#  error _POSIX_MONOTONIC_CLOCK missing/invalid
1724*bf6039f0SWarner Losh#endif
1725*bf6039f0SWarner Losh], [je_cv_clock_monotonic])
1726*bf6039f0SWarner Loshif test "x${je_cv_clock_monotonic}" = "xyes" ; then
1727*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC])
1728*bf6039f0SWarner Loshfi
1729*bf6039f0SWarner Losh
1730*bf6039f0SWarner Loshdnl Check for mach_absolute_time().
1731*bf6039f0SWarner LoshJE_COMPILABLE([mach_absolute_time()], [
1732*bf6039f0SWarner Losh#include <mach/mach_time.h>
1733*bf6039f0SWarner Losh], [
1734*bf6039f0SWarner Losh	mach_absolute_time();
1735*bf6039f0SWarner Losh], [je_cv_mach_absolute_time])
1736*bf6039f0SWarner Loshif test "x${je_cv_mach_absolute_time}" = "xyes" ; then
1737*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_MACH_ABSOLUTE_TIME])
1738*bf6039f0SWarner Loshfi
1739*bf6039f0SWarner Losh
1740*bf6039f0SWarner Loshdnl Use syscall(2) (if available) by default.
1741*bf6039f0SWarner LoshAC_ARG_ENABLE([syscall],
1742*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-syscall], [Disable use of syscall(2)])],
1743*bf6039f0SWarner Losh[if test "x$enable_syscall" = "xno" ; then
1744*bf6039f0SWarner Losh  enable_syscall="0"
1745*bf6039f0SWarner Loshelse
1746*bf6039f0SWarner Losh  enable_syscall="1"
1747*bf6039f0SWarner Loshfi
1748*bf6039f0SWarner Losh],
1749*bf6039f0SWarner Losh[enable_syscall="1"]
1750*bf6039f0SWarner Losh)
1751*bf6039f0SWarner Loshif test "x$enable_syscall" = "x1" ; then
1752*bf6039f0SWarner Losh  dnl Check if syscall(2) is usable.  Treat warnings as errors, so that e.g. OS
1753*bf6039f0SWarner Losh  dnl X 10.12's deprecation warning prevents use.
1754*bf6039f0SWarner Losh  JE_CFLAGS_SAVE()
1755*bf6039f0SWarner Losh  JE_CFLAGS_ADD([-Werror])
1756*bf6039f0SWarner Losh  JE_COMPILABLE([syscall(2)], [
1757*bf6039f0SWarner Losh#include <sys/syscall.h>
1758*bf6039f0SWarner Losh#include <unistd.h>
1759*bf6039f0SWarner Losh], [
1760*bf6039f0SWarner Losh	syscall(SYS_write, 2, "hello", 5);
1761*bf6039f0SWarner Losh],
1762*bf6039f0SWarner Losh                [je_cv_syscall])
1763*bf6039f0SWarner Losh  JE_CFLAGS_RESTORE()
1764*bf6039f0SWarner Losh  if test "x$je_cv_syscall" = "xyes" ; then
1765*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_USE_SYSCALL], [ ])
1766*bf6039f0SWarner Losh  fi
1767*bf6039f0SWarner Loshfi
1768*bf6039f0SWarner Losh
1769*bf6039f0SWarner Loshdnl Check if the GNU-specific secure_getenv function exists.
1770*bf6039f0SWarner LoshAC_CHECK_FUNC([secure_getenv],
1771*bf6039f0SWarner Losh              [have_secure_getenv="1"],
1772*bf6039f0SWarner Losh              [have_secure_getenv="0"]
1773*bf6039f0SWarner Losh             )
1774*bf6039f0SWarner Loshif test "x$have_secure_getenv" = "x1" ; then
1775*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1776*bf6039f0SWarner Loshfi
1777*bf6039f0SWarner Losh
1778*bf6039f0SWarner Loshdnl Check if the GNU-specific sched_getcpu function exists.
1779*bf6039f0SWarner LoshAC_CHECK_FUNC([sched_getcpu],
1780*bf6039f0SWarner Losh              [have_sched_getcpu="1"],
1781*bf6039f0SWarner Losh              [have_sched_getcpu="0"]
1782*bf6039f0SWarner Losh             )
1783*bf6039f0SWarner Loshif test "x$have_sched_getcpu" = "x1" ; then
1784*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_SCHED_GETCPU], [ ])
1785*bf6039f0SWarner Loshfi
1786*bf6039f0SWarner Losh
1787*bf6039f0SWarner Loshdnl Check if the GNU-specific sched_setaffinity function exists.
1788*bf6039f0SWarner LoshAC_CHECK_FUNC([sched_setaffinity],
1789*bf6039f0SWarner Losh              [have_sched_setaffinity="1"],
1790*bf6039f0SWarner Losh              [have_sched_setaffinity="0"]
1791*bf6039f0SWarner Losh             )
1792*bf6039f0SWarner Loshif test "x$have_sched_setaffinity" = "x1" ; then
1793*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_SCHED_SETAFFINITY], [ ])
1794*bf6039f0SWarner Loshfi
1795*bf6039f0SWarner Losh
1796*bf6039f0SWarner Loshdnl Check if the Solaris/BSD issetugid function exists.
1797*bf6039f0SWarner LoshAC_CHECK_FUNC([issetugid],
1798*bf6039f0SWarner Losh              [have_issetugid="1"],
1799*bf6039f0SWarner Losh              [have_issetugid="0"]
1800*bf6039f0SWarner Losh             )
1801*bf6039f0SWarner Loshif test "x$have_issetugid" = "x1" ; then
1802*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1803*bf6039f0SWarner Loshfi
1804*bf6039f0SWarner Losh
1805*bf6039f0SWarner Loshdnl Check whether the BSD-specific _malloc_thread_cleanup() exists.  If so, use
1806*bf6039f0SWarner Loshdnl it rather than pthreads TSD cleanup functions to support cleanup during
1807*bf6039f0SWarner Loshdnl thread exit, in order to avoid pthreads library recursion during
1808*bf6039f0SWarner Loshdnl bootstrapping.
1809*bf6039f0SWarner LoshAC_CHECK_FUNC([_malloc_thread_cleanup],
1810*bf6039f0SWarner Losh              [have__malloc_thread_cleanup="1"],
1811*bf6039f0SWarner Losh              [have__malloc_thread_cleanup="0"]
1812*bf6039f0SWarner Losh             )
1813*bf6039f0SWarner Loshif test "x$have__malloc_thread_cleanup" = "x1" ; then
1814*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1815*bf6039f0SWarner Losh  wrap_syms="${wrap_syms} _malloc_thread_cleanup"
1816*bf6039f0SWarner Losh  force_tls="1"
1817*bf6039f0SWarner Loshfi
1818*bf6039f0SWarner Losh
1819*bf6039f0SWarner Loshdnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists.  If
1820*bf6039f0SWarner Loshdnl so, mutex initialization causes allocation, and we need to implement this
1821*bf6039f0SWarner Loshdnl callback function in order to prevent recursive allocation.
1822*bf6039f0SWarner LoshAC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1823*bf6039f0SWarner Losh              [have__pthread_mutex_init_calloc_cb="1"],
1824*bf6039f0SWarner Losh              [have__pthread_mutex_init_calloc_cb="0"]
1825*bf6039f0SWarner Losh             )
1826*bf6039f0SWarner Loshif test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1827*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1828*bf6039f0SWarner Losh  wrap_syms="${wrap_syms} _malloc_prefork _malloc_postfork"
1829*bf6039f0SWarner Loshfi
1830*bf6039f0SWarner Losh
1831*bf6039f0SWarner Loshdnl Disable lazy locking by default.
1832*bf6039f0SWarner LoshAC_ARG_ENABLE([lazy_lock],
1833*bf6039f0SWarner Losh  [AS_HELP_STRING([--enable-lazy-lock],
1834*bf6039f0SWarner Losh  [Enable lazy locking (only lock when multi-threaded)])],
1835*bf6039f0SWarner Losh[if test "x$enable_lazy_lock" = "xno" ; then
1836*bf6039f0SWarner Losh  enable_lazy_lock="0"
1837*bf6039f0SWarner Loshelse
1838*bf6039f0SWarner Losh  enable_lazy_lock="1"
1839*bf6039f0SWarner Loshfi
1840*bf6039f0SWarner Losh],
1841*bf6039f0SWarner Losh[enable_lazy_lock=""]
1842*bf6039f0SWarner Losh)
1843*bf6039f0SWarner Loshif test "x${enable_lazy_lock}" = "x" ; then
1844*bf6039f0SWarner Losh  if test "x${force_lazy_lock}" = "x1" ; then
1845*bf6039f0SWarner Losh    AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1846*bf6039f0SWarner Losh    enable_lazy_lock="1"
1847*bf6039f0SWarner Losh  else
1848*bf6039f0SWarner Losh    enable_lazy_lock="0"
1849*bf6039f0SWarner Losh  fi
1850*bf6039f0SWarner Loshfi
1851*bf6039f0SWarner Loshif test "x${enable_lazy_lock}" = "x1" -a "x${abi}" = "xpecoff" ; then
1852*bf6039f0SWarner Losh  AC_MSG_RESULT([Forcing no lazy-lock because thread creation monitoring is unimplemented])
1853*bf6039f0SWarner Losh  enable_lazy_lock="0"
1854*bf6039f0SWarner Loshfi
1855*bf6039f0SWarner Loshif test "x$enable_lazy_lock" = "x1" ; then
1856*bf6039f0SWarner Losh  if test "x$have_dlsym" = "x1" ; then
1857*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1858*bf6039f0SWarner Losh  else
1859*bf6039f0SWarner Losh    AC_MSG_ERROR([Missing dlsym support: lazy-lock cannot be enabled.])
1860*bf6039f0SWarner Losh  fi
1861*bf6039f0SWarner Loshfi
1862*bf6039f0SWarner LoshAC_SUBST([enable_lazy_lock])
1863*bf6039f0SWarner Losh
1864*bf6039f0SWarner Loshdnl Automatically configure TLS.
1865*bf6039f0SWarner Loshif test "x${force_tls}" = "x1" ; then
1866*bf6039f0SWarner Losh  enable_tls="1"
1867*bf6039f0SWarner Loshelif test "x${force_tls}" = "x0" ; then
1868*bf6039f0SWarner Losh  enable_tls="0"
1869*bf6039f0SWarner Loshelse
1870*bf6039f0SWarner Losh  enable_tls="1"
1871*bf6039f0SWarner Loshfi
1872*bf6039f0SWarner Loshif test "x${enable_tls}" = "x1" ; then
1873*bf6039f0SWarner LoshAC_MSG_CHECKING([for TLS])
1874*bf6039f0SWarner LoshAC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1875*bf6039f0SWarner Losh[[
1876*bf6039f0SWarner Losh    __thread int x;
1877*bf6039f0SWarner Losh]], [[
1878*bf6039f0SWarner Losh    x = 42;
1879*bf6039f0SWarner Losh
1880*bf6039f0SWarner Losh    return 0;
1881*bf6039f0SWarner Losh]])],
1882*bf6039f0SWarner Losh              AC_MSG_RESULT([yes]),
1883*bf6039f0SWarner Losh              AC_MSG_RESULT([no])
1884*bf6039f0SWarner Losh              enable_tls="0")
1885*bf6039f0SWarner Loshelse
1886*bf6039f0SWarner Losh  enable_tls="0"
1887*bf6039f0SWarner Loshfi
1888*bf6039f0SWarner LoshAC_SUBST([enable_tls])
1889*bf6039f0SWarner Loshif test "x${enable_tls}" = "x1" ; then
1890*bf6039f0SWarner Losh  AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1891*bf6039f0SWarner Loshfi
1892*bf6039f0SWarner Losh
1893*bf6039f0SWarner Loshdnl ============================================================================
1894*bf6039f0SWarner Loshdnl Check for C11 atomics.
1895*bf6039f0SWarner Losh
1896*bf6039f0SWarner LoshJE_COMPILABLE([C11 atomics], [
1897*bf6039f0SWarner Losh#include <stdint.h>
1898*bf6039f0SWarner Losh#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1899*bf6039f0SWarner Losh#include <stdatomic.h>
1900*bf6039f0SWarner Losh#else
1901*bf6039f0SWarner Losh#error Atomics not available
1902*bf6039f0SWarner Losh#endif
1903*bf6039f0SWarner Losh], [
1904*bf6039f0SWarner Losh    uint64_t *p = (uint64_t *)0;
1905*bf6039f0SWarner Losh    uint64_t x = 1;
1906*bf6039f0SWarner Losh    volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1907*bf6039f0SWarner Losh    uint64_t r = atomic_fetch_add(a, x) + x;
1908*bf6039f0SWarner Losh    return r == 0;
1909*bf6039f0SWarner Losh], [je_cv_c11_atomics])
1910*bf6039f0SWarner Loshif test "x${je_cv_c11_atomics}" = "xyes" ; then
1911*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_C11_ATOMICS])
1912*bf6039f0SWarner Loshfi
1913*bf6039f0SWarner Losh
1914*bf6039f0SWarner Loshdnl ============================================================================
1915*bf6039f0SWarner Loshdnl Check for GCC-style __atomic atomics.
1916*bf6039f0SWarner Losh
1917*bf6039f0SWarner LoshJE_COMPILABLE([GCC __atomic atomics], [
1918*bf6039f0SWarner Losh], [
1919*bf6039f0SWarner Losh    int x = 0;
1920*bf6039f0SWarner Losh    int val = 1;
1921*bf6039f0SWarner Losh    int y = __atomic_fetch_add(&x, val, __ATOMIC_RELAXED);
1922*bf6039f0SWarner Losh    int after_add = x;
1923*bf6039f0SWarner Losh    return after_add == 1;
1924*bf6039f0SWarner Losh], [je_cv_gcc_atomic_atomics])
1925*bf6039f0SWarner Loshif test "x${je_cv_gcc_atomic_atomics}" = "xyes" ; then
1926*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_GCC_ATOMIC_ATOMICS])
1927*bf6039f0SWarner Losh
1928*bf6039f0SWarner Losh  dnl check for 8-bit atomic support
1929*bf6039f0SWarner Losh  JE_COMPILABLE([GCC 8-bit __atomic atomics], [
1930*bf6039f0SWarner Losh  ], [
1931*bf6039f0SWarner Losh      unsigned char x = 0;
1932*bf6039f0SWarner Losh      int val = 1;
1933*bf6039f0SWarner Losh      int y = __atomic_fetch_add(&x, val, __ATOMIC_RELAXED);
1934*bf6039f0SWarner Losh      int after_add = (int)x;
1935*bf6039f0SWarner Losh      return after_add == 1;
1936*bf6039f0SWarner Losh  ], [je_cv_gcc_u8_atomic_atomics])
1937*bf6039f0SWarner Losh  if test "x${je_cv_gcc_u8_atomic_atomics}" = "xyes" ; then
1938*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_GCC_U8_ATOMIC_ATOMICS])
1939*bf6039f0SWarner Losh  fi
1940*bf6039f0SWarner Loshfi
1941*bf6039f0SWarner Losh
1942*bf6039f0SWarner Loshdnl ============================================================================
1943*bf6039f0SWarner Loshdnl Check for GCC-style __sync atomics.
1944*bf6039f0SWarner Losh
1945*bf6039f0SWarner LoshJE_COMPILABLE([GCC __sync atomics], [
1946*bf6039f0SWarner Losh], [
1947*bf6039f0SWarner Losh    int x = 0;
1948*bf6039f0SWarner Losh    int before_add = __sync_fetch_and_add(&x, 1);
1949*bf6039f0SWarner Losh    int after_add = x;
1950*bf6039f0SWarner Losh    return (before_add == 0) && (after_add == 1);
1951*bf6039f0SWarner Losh], [je_cv_gcc_sync_atomics])
1952*bf6039f0SWarner Loshif test "x${je_cv_gcc_sync_atomics}" = "xyes" ; then
1953*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_GCC_SYNC_ATOMICS])
1954*bf6039f0SWarner Losh
1955*bf6039f0SWarner Losh  dnl check for 8-bit atomic support
1956*bf6039f0SWarner Losh  JE_COMPILABLE([GCC 8-bit __sync atomics], [
1957*bf6039f0SWarner Losh  ], [
1958*bf6039f0SWarner Losh      unsigned char x = 0;
1959*bf6039f0SWarner Losh      int before_add = __sync_fetch_and_add(&x, 1);
1960*bf6039f0SWarner Losh      int after_add = (int)x;
1961*bf6039f0SWarner Losh      return (before_add == 0) && (after_add == 1);
1962*bf6039f0SWarner Losh  ], [je_cv_gcc_u8_sync_atomics])
1963*bf6039f0SWarner Losh  if test "x${je_cv_gcc_u8_sync_atomics}" = "xyes" ; then
1964*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_GCC_U8_SYNC_ATOMICS])
1965*bf6039f0SWarner Losh  fi
1966*bf6039f0SWarner Loshfi
1967*bf6039f0SWarner Losh
1968*bf6039f0SWarner Loshdnl ============================================================================
1969*bf6039f0SWarner Loshdnl Check for atomic(3) operations as provided on Darwin.
1970*bf6039f0SWarner Loshdnl We need this not for the atomic operations (which are provided above), but
1971*bf6039f0SWarner Loshdnl rather for the OS_unfair_lock type it exposes.
1972*bf6039f0SWarner Losh
1973*bf6039f0SWarner LoshJE_COMPILABLE([Darwin OSAtomic*()], [
1974*bf6039f0SWarner Losh#include <libkern/OSAtomic.h>
1975*bf6039f0SWarner Losh#include <inttypes.h>
1976*bf6039f0SWarner Losh], [
1977*bf6039f0SWarner Losh	{
1978*bf6039f0SWarner Losh		int32_t x32 = 0;
1979*bf6039f0SWarner Losh		volatile int32_t *x32p = &x32;
1980*bf6039f0SWarner Losh		OSAtomicAdd32(1, x32p);
1981*bf6039f0SWarner Losh	}
1982*bf6039f0SWarner Losh	{
1983*bf6039f0SWarner Losh		int64_t x64 = 0;
1984*bf6039f0SWarner Losh		volatile int64_t *x64p = &x64;
1985*bf6039f0SWarner Losh		OSAtomicAdd64(1, x64p);
1986*bf6039f0SWarner Losh	}
1987*bf6039f0SWarner Losh], [je_cv_osatomic])
1988*bf6039f0SWarner Loshif test "x${je_cv_osatomic}" = "xyes" ; then
1989*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1990*bf6039f0SWarner Loshfi
1991*bf6039f0SWarner Losh
1992*bf6039f0SWarner Loshdnl ============================================================================
1993*bf6039f0SWarner Loshdnl Check for madvise(2).
1994*bf6039f0SWarner Losh
1995*bf6039f0SWarner LoshJE_COMPILABLE([madvise(2)], [
1996*bf6039f0SWarner Losh#include <sys/mman.h>
1997*bf6039f0SWarner Losh], [
1998*bf6039f0SWarner Losh	madvise((void *)0, 0, 0);
1999*bf6039f0SWarner Losh], [je_cv_madvise])
2000*bf6039f0SWarner Loshif test "x${je_cv_madvise}" = "xyes" ; then
2001*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
2002*bf6039f0SWarner Losh
2003*bf6039f0SWarner Losh  dnl Check for madvise(..., MADV_FREE).
2004*bf6039f0SWarner Losh  JE_COMPILABLE([madvise(..., MADV_FREE)], [
2005*bf6039f0SWarner Losh#include <sys/mman.h>
2006*bf6039f0SWarner Losh], [
2007*bf6039f0SWarner Losh	madvise((void *)0, 0, MADV_FREE);
2008*bf6039f0SWarner Losh], [je_cv_madv_free])
2009*bf6039f0SWarner Losh  if test "x${je_cv_madv_free}" = "xyes" ; then
2010*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
2011*bf6039f0SWarner Losh  elif test "x${je_cv_madvise}" = "xyes" ; then
2012*bf6039f0SWarner Losh    case "${host_cpu}" in i686|x86_64)
2013*bf6039f0SWarner Losh        case "${host}" in *-*-linux*)
2014*bf6039f0SWarner Losh            AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
2015*bf6039f0SWarner Losh            AC_DEFINE([JEMALLOC_DEFINE_MADVISE_FREE], [ ])
2016*bf6039f0SWarner Losh	    ;;
2017*bf6039f0SWarner Losh        esac
2018*bf6039f0SWarner Losh        ;;
2019*bf6039f0SWarner Losh    esac
2020*bf6039f0SWarner Losh  fi
2021*bf6039f0SWarner Losh
2022*bf6039f0SWarner Losh  dnl Check for madvise(..., MADV_DONTNEED).
2023*bf6039f0SWarner Losh  JE_COMPILABLE([madvise(..., MADV_DONTNEED)], [
2024*bf6039f0SWarner Losh#include <sys/mman.h>
2025*bf6039f0SWarner Losh], [
2026*bf6039f0SWarner Losh	madvise((void *)0, 0, MADV_DONTNEED);
2027*bf6039f0SWarner Losh], [je_cv_madv_dontneed])
2028*bf6039f0SWarner Losh  if test "x${je_cv_madv_dontneed}" = "xyes" ; then
2029*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
2030*bf6039f0SWarner Losh  fi
2031*bf6039f0SWarner Losh
2032*bf6039f0SWarner Losh  dnl Check for madvise(..., MADV_DO[NT]DUMP).
2033*bf6039f0SWarner Losh  JE_COMPILABLE([madvise(..., MADV_DO[[NT]]DUMP)], [
2034*bf6039f0SWarner Losh#include <sys/mman.h>
2035*bf6039f0SWarner Losh], [
2036*bf6039f0SWarner Losh	madvise((void *)0, 0, MADV_DONTDUMP);
2037*bf6039f0SWarner Losh	madvise((void *)0, 0, MADV_DODUMP);
2038*bf6039f0SWarner Losh], [je_cv_madv_dontdump])
2039*bf6039f0SWarner Losh  if test "x${je_cv_madv_dontdump}" = "xyes" ; then
2040*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_MADVISE_DONTDUMP], [ ])
2041*bf6039f0SWarner Losh  fi
2042*bf6039f0SWarner Losh
2043*bf6039f0SWarner Losh  dnl Check for madvise(..., MADV_[NO]HUGEPAGE).
2044*bf6039f0SWarner Losh  JE_COMPILABLE([madvise(..., MADV_[[NO]]HUGEPAGE)], [
2045*bf6039f0SWarner Losh#include <sys/mman.h>
2046*bf6039f0SWarner Losh], [
2047*bf6039f0SWarner Losh	madvise((void *)0, 0, MADV_HUGEPAGE);
2048*bf6039f0SWarner Losh	madvise((void *)0, 0, MADV_NOHUGEPAGE);
2049*bf6039f0SWarner Losh], [je_cv_thp])
2050*bf6039f0SWarner Loshcase "${host_cpu}" in
2051*bf6039f0SWarner Losh  arm*)
2052*bf6039f0SWarner Losh    ;;
2053*bf6039f0SWarner Losh  *)
2054*bf6039f0SWarner Losh  if test "x${je_cv_thp}" = "xyes" ; then
2055*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_HAVE_MADVISE_HUGE], [ ])
2056*bf6039f0SWarner Losh  fi
2057*bf6039f0SWarner Losh  ;;
2058*bf6039f0SWarner Loshesac
2059*bf6039f0SWarner Loshfi
2060*bf6039f0SWarner Losh
2061*bf6039f0SWarner Loshdnl ============================================================================
2062*bf6039f0SWarner Loshdnl Check for __builtin_clz() and __builtin_clzl().
2063*bf6039f0SWarner Losh
2064*bf6039f0SWarner LoshAC_CACHE_CHECK([for __builtin_clz],
2065*bf6039f0SWarner Losh               [je_cv_builtin_clz],
2066*bf6039f0SWarner Losh               [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
2067*bf6039f0SWarner Losh                                                [
2068*bf6039f0SWarner Losh                                                {
2069*bf6039f0SWarner Losh                                                        unsigned x = 0;
2070*bf6039f0SWarner Losh                                                        int y = __builtin_clz(x);
2071*bf6039f0SWarner Losh                                                }
2072*bf6039f0SWarner Losh                                                {
2073*bf6039f0SWarner Losh                                                        unsigned long x = 0;
2074*bf6039f0SWarner Losh                                                        int y = __builtin_clzl(x);
2075*bf6039f0SWarner Losh                                                }
2076*bf6039f0SWarner Losh                                                ])],
2077*bf6039f0SWarner Losh                               [je_cv_builtin_clz=yes],
2078*bf6039f0SWarner Losh                               [je_cv_builtin_clz=no])])
2079*bf6039f0SWarner Losh
2080*bf6039f0SWarner Loshif test "x${je_cv_builtin_clz}" = "xyes" ; then
2081*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
2082*bf6039f0SWarner Loshfi
2083*bf6039f0SWarner Losh
2084*bf6039f0SWarner Loshdnl ============================================================================
2085*bf6039f0SWarner Loshdnl Check for os_unfair_lock operations as provided on Darwin.
2086*bf6039f0SWarner Losh
2087*bf6039f0SWarner LoshJE_COMPILABLE([Darwin os_unfair_lock_*()], [
2088*bf6039f0SWarner Losh#include <os/lock.h>
2089*bf6039f0SWarner Losh#include <AvailabilityMacros.h>
2090*bf6039f0SWarner Losh], [
2091*bf6039f0SWarner Losh	#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
2092*bf6039f0SWarner Losh	#error "os_unfair_lock is not supported"
2093*bf6039f0SWarner Losh	#else
2094*bf6039f0SWarner Losh	os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
2095*bf6039f0SWarner Losh	os_unfair_lock_lock(&lock);
2096*bf6039f0SWarner Losh	os_unfair_lock_unlock(&lock);
2097*bf6039f0SWarner Losh	#endif
2098*bf6039f0SWarner Losh], [je_cv_os_unfair_lock])
2099*bf6039f0SWarner Loshif test "x${je_cv_os_unfair_lock}" = "xyes" ; then
2100*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_OS_UNFAIR_LOCK], [ ])
2101*bf6039f0SWarner Loshfi
2102*bf6039f0SWarner Losh
2103*bf6039f0SWarner Loshdnl ============================================================================
2104*bf6039f0SWarner Loshdnl Darwin-related configuration.
2105*bf6039f0SWarner Losh
2106*bf6039f0SWarner LoshAC_ARG_ENABLE([zone-allocator],
2107*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-zone-allocator],
2108*bf6039f0SWarner Losh                  [Disable zone allocator for Darwin])],
2109*bf6039f0SWarner Losh[if test "x$enable_zone_allocator" = "xno" ; then
2110*bf6039f0SWarner Losh  enable_zone_allocator="0"
2111*bf6039f0SWarner Loshelse
2112*bf6039f0SWarner Losh  enable_zone_allocator="1"
2113*bf6039f0SWarner Loshfi
2114*bf6039f0SWarner Losh],
2115*bf6039f0SWarner Losh[if test "x${abi}" = "xmacho"; then
2116*bf6039f0SWarner Losh  enable_zone_allocator="1"
2117*bf6039f0SWarner Loshfi
2118*bf6039f0SWarner Losh]
2119*bf6039f0SWarner Losh)
2120*bf6039f0SWarner LoshAC_SUBST([enable_zone_allocator])
2121*bf6039f0SWarner Losh
2122*bf6039f0SWarner Loshif test "x${enable_zone_allocator}" = "x1" ; then
2123*bf6039f0SWarner Losh  if test "x${abi}" != "xmacho"; then
2124*bf6039f0SWarner Losh    AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
2125*bf6039f0SWarner Losh  fi
2126*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_ZONE], [ ])
2127*bf6039f0SWarner Loshfi
2128*bf6039f0SWarner Losh
2129*bf6039f0SWarner Loshdnl ============================================================================
2130*bf6039f0SWarner Loshdnl Use initial-exec TLS by default.
2131*bf6039f0SWarner LoshAC_ARG_ENABLE([initial-exec-tls],
2132*bf6039f0SWarner Losh  [AS_HELP_STRING([--disable-initial-exec-tls],
2133*bf6039f0SWarner Losh                  [Disable the initial-exec tls model])],
2134*bf6039f0SWarner Losh[if test "x$enable_initial_exec_tls" = "xno" ; then
2135*bf6039f0SWarner Losh  enable_initial_exec_tls="0"
2136*bf6039f0SWarner Loshelse
2137*bf6039f0SWarner Losh  enable_initial_exec_tls="1"
2138*bf6039f0SWarner Loshfi
2139*bf6039f0SWarner Losh],
2140*bf6039f0SWarner Losh[enable_initial_exec_tls="1"]
2141*bf6039f0SWarner Losh)
2142*bf6039f0SWarner LoshAC_SUBST([enable_initial_exec_tls])
2143*bf6039f0SWarner Losh
2144*bf6039f0SWarner Loshif test "x${je_cv_tls_model}" = "xyes" -a \
2145*bf6039f0SWarner Losh       "x${enable_initial_exec_tls}" = "x1" ; then
2146*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_TLS_MODEL],
2147*bf6039f0SWarner Losh            [__attribute__((tls_model("initial-exec")))])
2148*bf6039f0SWarner Loshelse
2149*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
2150*bf6039f0SWarner Loshfi
2151*bf6039f0SWarner Losh
2152*bf6039f0SWarner Loshdnl ============================================================================
2153*bf6039f0SWarner Loshdnl Enable background threads if possible.
2154*bf6039f0SWarner Losh
2155*bf6039f0SWarner Loshif test "x${have_pthread}" = "x1" -a "x${je_cv_os_unfair_lock}" != "xyes" ; then
2156*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_BACKGROUND_THREAD])
2157*bf6039f0SWarner Loshfi
2158*bf6039f0SWarner Losh
2159*bf6039f0SWarner Loshdnl ============================================================================
2160*bf6039f0SWarner Loshdnl Check for glibc malloc hooks
2161*bf6039f0SWarner Losh
2162*bf6039f0SWarner LoshJE_COMPILABLE([glibc malloc hook], [
2163*bf6039f0SWarner Losh#include <stddef.h>
2164*bf6039f0SWarner Losh
2165*bf6039f0SWarner Loshextern void (* __free_hook)(void *ptr);
2166*bf6039f0SWarner Loshextern void *(* __malloc_hook)(size_t size);
2167*bf6039f0SWarner Loshextern void *(* __realloc_hook)(void *ptr, size_t size);
2168*bf6039f0SWarner Losh], [
2169*bf6039f0SWarner Losh  void *ptr = 0L;
2170*bf6039f0SWarner Losh  if (__malloc_hook) ptr = __malloc_hook(1);
2171*bf6039f0SWarner Losh  if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
2172*bf6039f0SWarner Losh  if (__free_hook && ptr) __free_hook(ptr);
2173*bf6039f0SWarner Losh], [je_cv_glibc_malloc_hook])
2174*bf6039f0SWarner Loshif test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
2175*bf6039f0SWarner Losh  if test "x${JEMALLOC_PREFIX}" = "x" ; then
2176*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
2177*bf6039f0SWarner Losh    wrap_syms="${wrap_syms} __free_hook __malloc_hook __realloc_hook"
2178*bf6039f0SWarner Losh  fi
2179*bf6039f0SWarner Loshfi
2180*bf6039f0SWarner Losh
2181*bf6039f0SWarner LoshJE_COMPILABLE([glibc memalign hook], [
2182*bf6039f0SWarner Losh#include <stddef.h>
2183*bf6039f0SWarner Losh
2184*bf6039f0SWarner Loshextern void *(* __memalign_hook)(size_t alignment, size_t size);
2185*bf6039f0SWarner Losh], [
2186*bf6039f0SWarner Losh  void *ptr = 0L;
2187*bf6039f0SWarner Losh  if (__memalign_hook) ptr = __memalign_hook(16, 7);
2188*bf6039f0SWarner Losh], [je_cv_glibc_memalign_hook])
2189*bf6039f0SWarner Loshif test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
2190*bf6039f0SWarner Losh  if test "x${JEMALLOC_PREFIX}" = "x" ; then
2191*bf6039f0SWarner Losh    AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
2192*bf6039f0SWarner Losh    wrap_syms="${wrap_syms} __memalign_hook"
2193*bf6039f0SWarner Losh  fi
2194*bf6039f0SWarner Loshfi
2195*bf6039f0SWarner Losh
2196*bf6039f0SWarner LoshJE_COMPILABLE([pthreads adaptive mutexes], [
2197*bf6039f0SWarner Losh#include <pthread.h>
2198*bf6039f0SWarner Losh], [
2199*bf6039f0SWarner Losh  pthread_mutexattr_t attr;
2200*bf6039f0SWarner Losh  pthread_mutexattr_init(&attr);
2201*bf6039f0SWarner Losh  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
2202*bf6039f0SWarner Losh  pthread_mutexattr_destroy(&attr);
2203*bf6039f0SWarner Losh], [je_cv_pthread_mutex_adaptive_np])
2204*bf6039f0SWarner Loshif test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
2205*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
2206*bf6039f0SWarner Loshfi
2207*bf6039f0SWarner Losh
2208*bf6039f0SWarner LoshJE_CFLAGS_SAVE()
2209*bf6039f0SWarner LoshJE_CFLAGS_ADD([-D_GNU_SOURCE])
2210*bf6039f0SWarner LoshJE_CFLAGS_ADD([-Werror])
2211*bf6039f0SWarner LoshJE_CFLAGS_ADD([-herror_on_warning])
2212*bf6039f0SWarner LoshJE_COMPILABLE([strerror_r returns char with gnu source], [
2213*bf6039f0SWarner Losh#include <errno.h>
2214*bf6039f0SWarner Losh#include <stdio.h>
2215*bf6039f0SWarner Losh#include <stdlib.h>
2216*bf6039f0SWarner Losh#include <string.h>
2217*bf6039f0SWarner Losh], [
2218*bf6039f0SWarner Losh  char *buffer = (char *) malloc(100);
2219*bf6039f0SWarner Losh  char *error = strerror_r(EINVAL, buffer, 100);
2220*bf6039f0SWarner Losh  printf("%s\n", error);
2221*bf6039f0SWarner Losh], [je_cv_strerror_r_returns_char_with_gnu_source])
2222*bf6039f0SWarner LoshJE_CFLAGS_RESTORE()
2223*bf6039f0SWarner Loshif test "x${je_cv_strerror_r_returns_char_with_gnu_source}" = "xyes" ; then
2224*bf6039f0SWarner Losh  AC_DEFINE([JEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE], [ ])
2225*bf6039f0SWarner Loshfi
2226*bf6039f0SWarner Losh
2227*bf6039f0SWarner Loshdnl ============================================================================
2228*bf6039f0SWarner Loshdnl Check for typedefs, structures, and compiler characteristics.
2229*bf6039f0SWarner LoshAC_HEADER_STDBOOL
2230*bf6039f0SWarner Losh
2231*bf6039f0SWarner Loshdnl ============================================================================
2232*bf6039f0SWarner Loshdnl Define commands that generate output files.
2233*bf6039f0SWarner Losh
2234*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
2235*bf6039f0SWarner Losh  f="${objroot}include/jemalloc/internal/public_symbols.txt"
2236*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc/internal"
2237*bf6039f0SWarner Losh  cp /dev/null "${f}"
2238*bf6039f0SWarner Losh  for nm in `echo ${mangling_map} |tr ',' ' '` ; do
2239*bf6039f0SWarner Losh    n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
2240*bf6039f0SWarner Losh    m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
2241*bf6039f0SWarner Losh    echo "${n}:${m}" >> "${f}"
2242*bf6039f0SWarner Losh    dnl Remove name from public_syms so that it isn't redefined later.
2243*bf6039f0SWarner Losh    public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
2244*bf6039f0SWarner Losh  done
2245*bf6039f0SWarner Losh  for sym in ${public_syms} ; do
2246*bf6039f0SWarner Losh    n="${sym}"
2247*bf6039f0SWarner Losh    m="${JEMALLOC_PREFIX}${sym}"
2248*bf6039f0SWarner Losh    echo "${n}:${m}" >> "${f}"
2249*bf6039f0SWarner Losh  done
2250*bf6039f0SWarner Losh], [
2251*bf6039f0SWarner Losh  srcdir="${srcdir}"
2252*bf6039f0SWarner Losh  objroot="${objroot}"
2253*bf6039f0SWarner Losh  mangling_map="${mangling_map}"
2254*bf6039f0SWarner Losh  public_syms="${public_syms}"
2255*bf6039f0SWarner Losh  JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
2256*bf6039f0SWarner Losh])
2257*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols.awk], [
2258*bf6039f0SWarner Losh  f="${objroot}include/jemalloc/internal/private_symbols.awk"
2259*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc/internal"
2260*bf6039f0SWarner Losh  export_syms=`for sym in ${public_syms}; do echo "${JEMALLOC_PREFIX}${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
2261*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols.awk"
2262*bf6039f0SWarner Losh], [
2263*bf6039f0SWarner Losh  srcdir="${srcdir}"
2264*bf6039f0SWarner Losh  objroot="${objroot}"
2265*bf6039f0SWarner Losh  public_syms="${public_syms}"
2266*bf6039f0SWarner Losh  wrap_syms="${wrap_syms}"
2267*bf6039f0SWarner Losh  SYM_PREFIX="${SYM_PREFIX}"
2268*bf6039f0SWarner Losh  JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
2269*bf6039f0SWarner Losh])
2270*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols_jet.awk], [
2271*bf6039f0SWarner Losh  f="${objroot}include/jemalloc/internal/private_symbols_jet.awk"
2272*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc/internal"
2273*bf6039f0SWarner Losh  export_syms=`for sym in ${public_syms}; do echo "jet_${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
2274*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols_jet.awk"
2275*bf6039f0SWarner Losh], [
2276*bf6039f0SWarner Losh  srcdir="${srcdir}"
2277*bf6039f0SWarner Losh  objroot="${objroot}"
2278*bf6039f0SWarner Losh  public_syms="${public_syms}"
2279*bf6039f0SWarner Losh  wrap_syms="${wrap_syms}"
2280*bf6039f0SWarner Losh  SYM_PREFIX="${SYM_PREFIX}"
2281*bf6039f0SWarner Losh])
2282*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
2283*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc/internal"
2284*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
2285*bf6039f0SWarner Losh], [
2286*bf6039f0SWarner Losh  srcdir="${srcdir}"
2287*bf6039f0SWarner Losh  objroot="${objroot}"
2288*bf6039f0SWarner Losh])
2289*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
2290*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc/internal"
2291*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
2292*bf6039f0SWarner Losh], [
2293*bf6039f0SWarner Losh  srcdir="${srcdir}"
2294*bf6039f0SWarner Losh  objroot="${objroot}"
2295*bf6039f0SWarner Losh])
2296*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
2297*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc"
2298*bf6039f0SWarner Losh  cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
2299*bf6039f0SWarner Losh], [
2300*bf6039f0SWarner Losh  srcdir="${srcdir}"
2301*bf6039f0SWarner Losh  objroot="${objroot}"
2302*bf6039f0SWarner Losh])
2303*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
2304*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc"
2305*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
2306*bf6039f0SWarner Losh], [
2307*bf6039f0SWarner Losh  srcdir="${srcdir}"
2308*bf6039f0SWarner Losh  objroot="${objroot}"
2309*bf6039f0SWarner Losh])
2310*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
2311*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc"
2312*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
2313*bf6039f0SWarner Losh], [
2314*bf6039f0SWarner Losh  srcdir="${srcdir}"
2315*bf6039f0SWarner Losh  objroot="${objroot}"
2316*bf6039f0SWarner Losh])
2317*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
2318*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc"
2319*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
2320*bf6039f0SWarner Losh], [
2321*bf6039f0SWarner Losh  srcdir="${srcdir}"
2322*bf6039f0SWarner Losh  objroot="${objroot}"
2323*bf6039f0SWarner Losh])
2324*bf6039f0SWarner LoshAC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
2325*bf6039f0SWarner Losh  mkdir -p "${objroot}include/jemalloc"
2326*bf6039f0SWarner Losh  "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
2327*bf6039f0SWarner Losh], [
2328*bf6039f0SWarner Losh  srcdir="${srcdir}"
2329*bf6039f0SWarner Losh  objroot="${objroot}"
2330*bf6039f0SWarner Losh  install_suffix="${install_suffix}"
2331*bf6039f0SWarner Losh])
2332*bf6039f0SWarner Losh
2333*bf6039f0SWarner Loshdnl Process .in files.
2334*bf6039f0SWarner LoshAC_SUBST([cfghdrs_in])
2335*bf6039f0SWarner LoshAC_SUBST([cfghdrs_out])
2336*bf6039f0SWarner LoshAC_CONFIG_HEADERS([$cfghdrs_tup])
2337*bf6039f0SWarner Losh
2338*bf6039f0SWarner Loshdnl ============================================================================
2339*bf6039f0SWarner Loshdnl Generate outputs.
2340*bf6039f0SWarner Losh
2341*bf6039f0SWarner LoshAC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
2342*bf6039f0SWarner LoshAC_SUBST([cfgoutputs_in])
2343*bf6039f0SWarner LoshAC_SUBST([cfgoutputs_out])
2344*bf6039f0SWarner LoshAC_OUTPUT
2345*bf6039f0SWarner Losh
2346*bf6039f0SWarner Loshdnl ============================================================================
2347*bf6039f0SWarner Loshdnl Print out the results of configuration.
2348*bf6039f0SWarner LoshAC_MSG_RESULT([===============================================================================])
2349*bf6039f0SWarner LoshAC_MSG_RESULT([jemalloc version   : ${jemalloc_version}])
2350*bf6039f0SWarner LoshAC_MSG_RESULT([library revision   : ${rev}])
2351*bf6039f0SWarner LoshAC_MSG_RESULT([])
2352*bf6039f0SWarner LoshAC_MSG_RESULT([CONFIG             : ${CONFIG}])
2353*bf6039f0SWarner LoshAC_MSG_RESULT([CC                 : ${CC}])
2354*bf6039f0SWarner LoshAC_MSG_RESULT([CONFIGURE_CFLAGS   : ${CONFIGURE_CFLAGS}])
2355*bf6039f0SWarner LoshAC_MSG_RESULT([SPECIFIED_CFLAGS   : ${SPECIFIED_CFLAGS}])
2356*bf6039f0SWarner LoshAC_MSG_RESULT([EXTRA_CFLAGS       : ${EXTRA_CFLAGS}])
2357*bf6039f0SWarner LoshAC_MSG_RESULT([CPPFLAGS           : ${CPPFLAGS}])
2358*bf6039f0SWarner LoshAC_MSG_RESULT([CXX                : ${CXX}])
2359*bf6039f0SWarner LoshAC_MSG_RESULT([CONFIGURE_CXXFLAGS : ${CONFIGURE_CXXFLAGS}])
2360*bf6039f0SWarner LoshAC_MSG_RESULT([SPECIFIED_CXXFLAGS : ${SPECIFIED_CXXFLAGS}])
2361*bf6039f0SWarner LoshAC_MSG_RESULT([EXTRA_CXXFLAGS     : ${EXTRA_CXXFLAGS}])
2362*bf6039f0SWarner LoshAC_MSG_RESULT([LDFLAGS            : ${LDFLAGS}])
2363*bf6039f0SWarner LoshAC_MSG_RESULT([EXTRA_LDFLAGS      : ${EXTRA_LDFLAGS}])
2364*bf6039f0SWarner LoshAC_MSG_RESULT([DSO_LDFLAGS        : ${DSO_LDFLAGS}])
2365*bf6039f0SWarner LoshAC_MSG_RESULT([LIBS               : ${LIBS}])
2366*bf6039f0SWarner LoshAC_MSG_RESULT([RPATH_EXTRA        : ${RPATH_EXTRA}])
2367*bf6039f0SWarner LoshAC_MSG_RESULT([])
2368*bf6039f0SWarner LoshAC_MSG_RESULT([XSLTPROC           : ${XSLTPROC}])
2369*bf6039f0SWarner LoshAC_MSG_RESULT([XSLROOT            : ${XSLROOT}])
2370*bf6039f0SWarner LoshAC_MSG_RESULT([])
2371*bf6039f0SWarner LoshAC_MSG_RESULT([PREFIX             : ${PREFIX}])
2372*bf6039f0SWarner LoshAC_MSG_RESULT([BINDIR             : ${BINDIR}])
2373*bf6039f0SWarner LoshAC_MSG_RESULT([DATADIR            : ${DATADIR}])
2374*bf6039f0SWarner LoshAC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
2375*bf6039f0SWarner LoshAC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
2376*bf6039f0SWarner LoshAC_MSG_RESULT([MANDIR             : ${MANDIR}])
2377*bf6039f0SWarner LoshAC_MSG_RESULT([])
2378*bf6039f0SWarner LoshAC_MSG_RESULT([srcroot            : ${srcroot}])
2379*bf6039f0SWarner LoshAC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
2380*bf6039f0SWarner LoshAC_MSG_RESULT([objroot            : ${objroot}])
2381*bf6039f0SWarner LoshAC_MSG_RESULT([abs_objroot        : ${abs_objroot}])
2382*bf6039f0SWarner LoshAC_MSG_RESULT([])
2383*bf6039f0SWarner LoshAC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
2384*bf6039f0SWarner LoshAC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
2385*bf6039f0SWarner LoshAC_MSG_RESULT([                   : ${JEMALLOC_PRIVATE_NAMESPACE}])
2386*bf6039f0SWarner LoshAC_MSG_RESULT([install_suffix     : ${install_suffix}])
2387*bf6039f0SWarner LoshAC_MSG_RESULT([malloc_conf        : ${config_malloc_conf}])
2388*bf6039f0SWarner LoshAC_MSG_RESULT([documentation      : ${enable_doc}])
2389*bf6039f0SWarner LoshAC_MSG_RESULT([shared libs        : ${enable_shared}])
2390*bf6039f0SWarner LoshAC_MSG_RESULT([static libs        : ${enable_static}])
2391*bf6039f0SWarner LoshAC_MSG_RESULT([autogen            : ${enable_autogen}])
2392*bf6039f0SWarner LoshAC_MSG_RESULT([debug              : ${enable_debug}])
2393*bf6039f0SWarner LoshAC_MSG_RESULT([stats              : ${enable_stats}])
2394*bf6039f0SWarner LoshAC_MSG_RESULT([experimetal_smallocx : ${enable_experimental_smallocx}])
2395*bf6039f0SWarner LoshAC_MSG_RESULT([prof               : ${enable_prof}])
2396*bf6039f0SWarner LoshAC_MSG_RESULT([prof-libunwind     : ${enable_prof_libunwind}])
2397*bf6039f0SWarner LoshAC_MSG_RESULT([prof-libgcc        : ${enable_prof_libgcc}])
2398*bf6039f0SWarner LoshAC_MSG_RESULT([prof-gcc           : ${enable_prof_gcc}])
2399*bf6039f0SWarner LoshAC_MSG_RESULT([fill               : ${enable_fill}])
2400*bf6039f0SWarner LoshAC_MSG_RESULT([utrace             : ${enable_utrace}])
2401*bf6039f0SWarner LoshAC_MSG_RESULT([xmalloc            : ${enable_xmalloc}])
2402*bf6039f0SWarner LoshAC_MSG_RESULT([log                : ${enable_log}])
2403*bf6039f0SWarner LoshAC_MSG_RESULT([lazy_lock          : ${enable_lazy_lock}])
2404*bf6039f0SWarner LoshAC_MSG_RESULT([cache-oblivious    : ${enable_cache_oblivious}])
2405*bf6039f0SWarner LoshAC_MSG_RESULT([cxx                : ${enable_cxx}])
2406*bf6039f0SWarner LoshAC_MSG_RESULT([===============================================================================])
2407