configure.ac revision 13e4e24c42d17492f85cdd550c1e13d6f929307e
1dnl Process this file with autoconf to produce a configure script.
2AC_INIT([Makefile.in])
3
4dnl ============================================================================
5dnl Custom macro definitions.
6
7dnl JE_CFLAGS_APPEND(cflag)
8AC_DEFUN([JE_CFLAGS_APPEND],
9[
10AC_MSG_CHECKING([whether compiler supports $1])
11TCFLAGS="${CFLAGS}"
12if test "x${CFLAGS}" = "x" ; then
13  CFLAGS="$1"
14else
15  CFLAGS="${CFLAGS} $1"
16fi
17AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
18[[
19]], [[
20    return 0;
21]])],
22              AC_MSG_RESULT([yes]),
23              AC_MSG_RESULT([no])
24              [CFLAGS="${TCFLAGS}"]
25)
26])
27
28dnl JE_COMPILABLE(label, hcode, mcode, rvar)
29dnl 
30dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
31dnl cause failure.
32AC_DEFUN([JE_COMPILABLE],
33[
34AC_CACHE_CHECK([whether $1 is compilable],
35               [$4],
36               [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
37                                                [$3])],
38                               [$4=yes],
39                               [$4=no])])
40])
41
42dnl ============================================================================
43
44dnl Library revision.
45rev=1
46AC_SUBST([rev])
47
48srcroot=$srcdir
49if test "x${srcroot}" = "x." ; then
50  srcroot=""
51else
52  srcroot="${srcroot}/"
53fi
54AC_SUBST([srcroot])
55abs_srcroot="`cd \"${srcdir}\"; pwd`/"
56AC_SUBST([abs_srcroot])
57
58objroot=""
59AC_SUBST([objroot])
60abs_objroot="`pwd`/"
61AC_SUBST([abs_objroot])
62
63dnl Munge install path variables.
64if test "x$prefix" = "xNONE" ; then
65  prefix="/usr/local"
66fi
67if test "x$exec_prefix" = "xNONE" ; then
68  exec_prefix=$prefix
69fi
70PREFIX=$prefix
71AC_SUBST([PREFIX])
72BINDIR=`eval echo $bindir`
73BINDIR=`eval echo $BINDIR`
74AC_SUBST([BINDIR])
75INCLUDEDIR=`eval echo $includedir`
76INCLUDEDIR=`eval echo $INCLUDEDIR`
77AC_SUBST([INCLUDEDIR])
78LIBDIR=`eval echo $libdir`
79LIBDIR=`eval echo $LIBDIR`
80AC_SUBST([LIBDIR])
81DATADIR=`eval echo $datadir`
82DATADIR=`eval echo $DATADIR`
83AC_SUBST([DATADIR])
84MANDIR=`eval echo $mandir`
85MANDIR=`eval echo $MANDIR`
86AC_SUBST([MANDIR])
87
88dnl Support for building documentation.
89AC_PATH_PROG([XSLTPROC], [xsltproc], , [$PATH])
90if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
91  DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
92elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
93  DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
94else
95  dnl Documentation building will fail if this default gets used.
96  DEFAULT_XSLROOT=""
97fi
98AC_ARG_WITH([xslroot],
99  [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
100if test "x$with_xslroot" = "xno" ; then
101  XSLROOT="${DEFAULT_XSLROOT}"
102else
103  XSLROOT="${with_xslroot}"
104fi
105],
106  XSLROOT="${DEFAULT_XSLROOT}"
107)
108AC_SUBST([XSLROOT])
109
110dnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
111dnl just prevent autoconf from molesting CFLAGS.
112CFLAGS=$CFLAGS
113AC_PROG_CC
114if test "x$GCC" != "xyes" ; then
115  AC_CACHE_CHECK([whether compiler is MSVC],
116                 [je_cv_msvc],
117                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
118                                                     [
119#ifndef _MSC_VER
120  int fail[-1];
121#endif
122])],
123                               [je_cv_msvc=yes],
124                               [je_cv_msvc=no])])
125fi
126
127if test "x$CFLAGS" = "x" ; then
128  no_CFLAGS="yes"
129  if test "x$GCC" = "xyes" ; then
130    JE_CFLAGS_APPEND([-std=gnu99])
131    JE_CFLAGS_APPEND([-Wall])
132    JE_CFLAGS_APPEND([-pipe])
133    JE_CFLAGS_APPEND([-g3])
134  elif test "x$je_cv_msvc" = "xyes" ; then
135    CC="$CC -nologo"
136    JE_CFLAGS_APPEND([-Zi])
137    JE_CFLAGS_APPEND([-MT])
138    JE_CFLAGS_APPEND([-W3])
139    CPPFLAGS="$CPPFLAGS -I${srcroot}/include/msvc_compat"
140  fi
141fi
142dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
143if test "x$EXTRA_CFLAGS" != "x" ; then
144  JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
145fi
146AC_PROG_CPP
147
148AC_CHECK_SIZEOF([void *])
149if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
150  LG_SIZEOF_PTR=3
151elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
152  LG_SIZEOF_PTR=2
153else
154  AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
155fi
156AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
157
158AC_CHECK_SIZEOF([int])
159if test "x${ac_cv_sizeof_int}" = "x8" ; then
160  LG_SIZEOF_INT=3
161elif test "x${ac_cv_sizeof_int}" = "x4" ; then
162  LG_SIZEOF_INT=2
163else
164  AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
165fi
166AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
167
168AC_CHECK_SIZEOF([long])
169if test "x${ac_cv_sizeof_long}" = "x8" ; then
170  LG_SIZEOF_LONG=3
171elif test "x${ac_cv_sizeof_long}" = "x4" ; then
172  LG_SIZEOF_LONG=2
173else
174  AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
175fi
176AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
177
178AC_CHECK_SIZEOF([intmax_t])
179if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
180  LG_SIZEOF_INTMAX_T=4
181elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
182  LG_SIZEOF_INTMAX_T=3
183elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
184  LG_SIZEOF_INTMAX_T=2
185else
186  AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
187fi
188AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
189
190AC_CANONICAL_HOST
191dnl CPU-specific settings.
192CPU_SPINWAIT=""
193case "${host_cpu}" in
194  i[[345]]86)
195	;;
196  i686)
197	JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
198	              [je_cv_asm])
199	if test "x${je_cv_asm}" = "xyes" ; then
200	    CPU_SPINWAIT='__asm__ volatile("pause")'
201	fi
202	;;
203  x86_64)
204	JE_COMPILABLE([__asm__ syntax], [],
205	              [[__asm__ volatile("pause"); return 0;]], [je_cv_asm])
206	if test "x${je_cv_asm}" = "xyes" ; then
207	    CPU_SPINWAIT='__asm__ volatile("pause")'
208	fi
209	;;
210  *)
211	;;
212esac
213AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
214
215LD_PRELOAD_VAR="LD_PRELOAD"
216so="so"
217importlib="${so}"
218o="$ac_objext"
219a="a"
220exe="$ac_exeext"
221libprefix="lib"
222DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
223RPATH='-Wl,-rpath,$(1)'
224SOREV="${so}.${rev}"
225PIC_CFLAGS='-fPIC -DPIC'
226CTARGET='-o $@'
227LDTARGET='-o $@'
228EXTRA_LDFLAGS=
229MKLIB='ar crus $@'
230CC_MM=1
231
232dnl Platform-specific settings.  abi and RPATH can probably be determined
233dnl programmatically, but doing so is error-prone, which makes it generally
234dnl not worth the trouble.
235dnl 
236dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
237dnl definitions need to be seen before any headers are included, which is a pain
238dnl to make happen otherwise.
239default_munmap="1"
240JEMALLOC_USABLE_SIZE_CONST="const"
241case "${host}" in
242  *-*-darwin*)
243	CFLAGS="$CFLAGS"
244	abi="macho"
245	AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
246	RPATH=""
247	LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
248	so="dylib"
249	importlib="${so}"
250	force_tls="0"
251	DSO_LDFLAGS='-shared -Wl,-dylib_install_name,$(@F)'
252	SOREV="${rev}.${so}"
253	;;
254  *-*-freebsd*)
255	CFLAGS="$CFLAGS"
256	abi="elf"
257	AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
258	force_lazy_lock="1"
259	;;
260  *-*-linux*)
261	CFLAGS="$CFLAGS"
262	CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
263	abi="elf"
264	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
265	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
266	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
267	JEMALLOC_USABLE_SIZE_CONST=""
268	default_munmap="0"
269	;;
270  *-*-netbsd*)
271	AC_MSG_CHECKING([ABI])
272        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
273[[#ifdef __ELF__
274/* ELF */
275#else
276#error aout
277#endif
278]])],
279                          [CFLAGS="$CFLAGS"; abi="elf"],
280                          [abi="aout"])
281	AC_MSG_RESULT([$abi])
282	AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
283	;;
284  *-*-solaris2*)
285	CFLAGS="$CFLAGS"
286	abi="elf"
287	RPATH='-Wl,-R,$(1)'
288	dnl Solaris needs this for sigwait().
289	CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
290	LIBS="$LIBS -lposix4 -lsocket -lnsl"
291	;;
292  *-ibm-aix*)
293	if "$LG_SIZEOF_PTR" = "8"; then
294	  dnl 64bit AIX
295	  LD_PRELOAD_VAR="LDR_PRELOAD64"
296	else
297	  dnl 32bit AIX
298	  LD_PRELOAD_VAR="LDR_PRELOAD"
299	fi
300	abi="xcoff"
301	;;
302  *-*-mingw*)
303	abi="pecoff"
304	force_tls="0"
305	RPATH=""
306	so="dll"
307	if test "x$je_cv_msvc" = "xyes" ; then
308	  importlib="lib"
309	  DSO_LDFLAGS="-LD"
310	  EXTRA_LDFLAGS="-link -DEBUG"
311	  CTARGET='-Fo$@'
312	  LDTARGET='-Fe$@'
313	  MKLIB='lib -nologo -out:$@'
314	  CC_MM=
315        else
316	  importlib="${so}"
317	  DSO_LDFLAGS="-shared"
318	fi
319	a="lib"
320	libprefix=""
321	SOREV="${so}"
322	PIC_CFLAGS=""
323	;;
324  *)
325	AC_MSG_RESULT([Unsupported operating system: ${host}])
326	abi="elf"
327	;;
328esac
329AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
330AC_SUBST([abi])
331AC_SUBST([RPATH])
332AC_SUBST([LD_PRELOAD_VAR])
333AC_SUBST([so])
334AC_SUBST([importlib])
335AC_SUBST([o])
336AC_SUBST([a])
337AC_SUBST([exe])
338AC_SUBST([libprefix])
339AC_SUBST([DSO_LDFLAGS])
340AC_SUBST([EXTRA_LDFLAGS])
341AC_SUBST([SOREV])
342AC_SUBST([PIC_CFLAGS])
343AC_SUBST([CTARGET])
344AC_SUBST([LDTARGET])
345AC_SUBST([MKLIB])
346AC_SUBST([CC_MM])
347
348if test "x$abi" != "xpecoff"; then
349  dnl Heap profiling uses the log(3) function.
350  LIBS="$LIBS -lm"
351fi
352
353JE_COMPILABLE([__attribute__ syntax],
354              [static __attribute__((unused)) void foo(void){}],
355              [],
356              [je_cv_attribute])
357if test "x${je_cv_attribute}" = "xyes" ; then
358  AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
359  if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
360    JE_CFLAGS_APPEND([-fvisibility=hidden])
361  fi
362fi
363dnl Check for tls_model attribute support (clang 3.0 still lacks support).
364SAVED_CFLAGS="${CFLAGS}"
365JE_CFLAGS_APPEND([-Werror])
366JE_COMPILABLE([tls_model attribute], [],
367              [static __thread int
368               __attribute__((tls_model("initial-exec"))) foo;
369               foo = 0;],
370              [je_cv_tls_model])
371CFLAGS="${SAVED_CFLAGS}"
372if test "x${je_cv_tls_model}" = "xyes" ; then
373  AC_DEFINE([JEMALLOC_TLS_MODEL],
374            [__attribute__((tls_model("initial-exec")))])
375else
376  AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
377fi
378
379dnl Support optional additions to rpath.
380AC_ARG_WITH([rpath],
381  [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
382if test "x$with_rpath" = "xno" ; then
383  RPATH_EXTRA=
384else
385  RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
386fi,
387  RPATH_EXTRA=
388)
389AC_SUBST([RPATH_EXTRA])
390
391dnl Disable rules that do automatic regeneration of configure output by default.
392AC_ARG_ENABLE([autogen],
393  [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
394if test "x$enable_autogen" = "xno" ; then
395  enable_autogen="0"
396else
397  enable_autogen="1"
398fi
399,
400enable_autogen="0"
401)
402AC_SUBST([enable_autogen])
403
404AC_PROG_INSTALL
405AC_PROG_RANLIB
406AC_PATH_PROG([AR], [ar], , [$PATH])
407AC_PATH_PROG([LD], [ld], , [$PATH])
408AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
409
410public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free malloc_usable_size malloc_stats_print mallctl mallctlnametomib mallctlbymib"
411
412dnl Check for allocator-related functions that should be wrapped.
413AC_CHECK_FUNC([memalign],
414	      [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
415	       public_syms="${public_syms} memalign"])
416AC_CHECK_FUNC([valloc],
417	      [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
418	       public_syms="${public_syms} valloc"])
419
420dnl Support the experimental API by default.
421AC_ARG_ENABLE([experimental],
422  [AS_HELP_STRING([--disable-experimental],
423   [Disable support for the experimental API])],
424[if test "x$enable_experimental" = "xno" ; then
425  enable_experimental="0"
426else
427  enable_experimental="1"
428fi
429],
430[enable_experimental="1"]
431)
432if test "x$enable_experimental" = "x1" ; then
433  AC_DEFINE([JEMALLOC_EXPERIMENTAL], [ ])
434  public_syms="${public_syms} allocm dallocm nallocm rallocm sallocm"
435fi
436AC_SUBST([enable_experimental])
437
438dnl Perform no name mangling by default.
439AC_ARG_WITH([mangling],
440  [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
441  [mangling_map="$with_mangling"], [mangling_map=""])
442for nm in `echo ${mangling_map} |tr ',' ' '` ; do
443  k="`echo ${nm} |tr ':' ' ' |awk '{print $1}'`"
444  n="je_${k}"
445  m=`echo ${nm} |tr ':' ' ' |awk '{print $2}'`
446  AC_DEFINE_UNQUOTED([${n}], [${m}])
447  dnl Remove key from public_syms so that it isn't redefined later.
448  public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${k}\$" |tr '\n' ' '`
449done
450
451dnl Do not prefix public APIs by default.
452AC_ARG_WITH([jemalloc_prefix],
453  [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
454  [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
455  [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
456  JEMALLOC_PREFIX=""
457else
458  JEMALLOC_PREFIX="je_"
459fi]
460)
461if test "x$JEMALLOC_PREFIX" != "x" ; then
462  JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
463  AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
464  AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
465fi
466dnl Generate macros to rename public symbols.  All public symbols are prefixed
467dnl with je_ in the source code, so these macro definitions are needed even if
468dnl --with-jemalloc-prefix wasn't specified.
469for stem in ${public_syms}; do
470  n="je_${stem}"
471  m="${JEMALLOC_PREFIX}${stem}"
472  AC_DEFINE_UNQUOTED([${n}], [${m}])
473done
474
475AC_ARG_WITH([export],
476  [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
477  [if test "x$with_export" = "xno"; then
478  AC_DEFINE([JEMALLOC_EXPORT],[])]
479fi]
480)
481
482dnl Do not mangle library-private APIs by default.
483AC_ARG_WITH([private_namespace],
484  [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
485  [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
486  [JEMALLOC_PRIVATE_NAMESPACE=""]
487)
488AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
489if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
490  AC_DEFINE_UNQUOTED([JEMALLOC_N(string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix)], [${JEMALLOC_PRIVATE_NAMESPACE}##string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix])
491else
492  AC_DEFINE_UNQUOTED([JEMALLOC_N(string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix)], [string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix])
493fi
494
495dnl Do not add suffix to installed files by default.
496AC_ARG_WITH([install_suffix],
497  [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
498  [INSTALL_SUFFIX="$with_install_suffix"],
499  [INSTALL_SUFFIX=]
500)
501install_suffix="$INSTALL_SUFFIX"
502AC_SUBST([install_suffix])
503
504cfgoutputs_in="${srcroot}Makefile.in"
505cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
506cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
507cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
508cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
509cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
510cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
511
512cfgoutputs_out="Makefile"
513cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
514cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
515cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
516cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
517cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
518cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
519
520cfgoutputs_tup="Makefile"
521cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
522cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
523cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
524cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
525cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
526cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
527
528cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
529cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
530
531cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
532cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
533
534cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
535
536dnl Do not silence irrelevant compiler warnings by default, since enabling this
537dnl option incurs a performance penalty.
538AC_ARG_ENABLE([cc-silence],
539  [AS_HELP_STRING([--enable-cc-silence],
540                  [Silence irrelevant compiler warnings])],
541[if test "x$enable_cc_silence" = "xno" ; then
542  enable_cc_silence="0"
543else
544  enable_cc_silence="1"
545fi
546],
547[enable_cc_silence="0"]
548)
549if test "x$enable_cc_silence" = "x1" ; then
550  AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
551fi
552
553dnl Do not compile with debugging by default.
554AC_ARG_ENABLE([debug],
555  [AS_HELP_STRING([--enable-debug], [Build debugging code (implies --enable-ivsalloc)])],
556[if test "x$enable_debug" = "xno" ; then
557  enable_debug="0"
558else
559  enable_debug="1"
560fi
561],
562[enable_debug="0"]
563)
564if test "x$enable_debug" = "x1" ; then
565  AC_DEFINE([JEMALLOC_DEBUG], [ ])
566  enable_ivsalloc="1"
567fi
568AC_SUBST([enable_debug])
569
570dnl Do not validate pointers by default.
571AC_ARG_ENABLE([ivsalloc],
572  [AS_HELP_STRING([--enable-ivsalloc], [Validate pointers passed through the public API])],
573[if test "x$enable_ivsalloc" = "xno" ; then
574  enable_ivsalloc="0"
575else
576  enable_ivsalloc="1"
577fi
578],
579[enable_ivsalloc="0"]
580)
581if test "x$enable_ivsalloc" = "x1" ; then
582  AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
583fi
584
585dnl Only optimize if not debugging.
586if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
587  dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
588  optimize="no"
589  echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
590  if test "x${optimize}" = "xyes" ; then
591    if test "x$GCC" = "xyes" ; then
592      JE_CFLAGS_APPEND([-O3])
593      JE_CFLAGS_APPEND([-funroll-loops])
594    elif test "x$je_cv_msvc" = "xyes" ; then
595      JE_CFLAGS_APPEND([-O2])
596    else
597      JE_CFLAGS_APPEND([-O])
598    fi
599  fi
600fi
601
602dnl Enable statistics calculation by default.
603AC_ARG_ENABLE([stats],
604  [AS_HELP_STRING([--disable-stats],
605                  [Disable statistics calculation/reporting])],
606[if test "x$enable_stats" = "xno" ; then
607  enable_stats="0"
608else
609  enable_stats="1"
610fi
611],
612[enable_stats="1"]
613)
614if test "x$enable_stats" = "x1" ; then
615  AC_DEFINE([JEMALLOC_STATS], [ ])
616fi
617AC_SUBST([enable_stats])
618
619dnl Do not enable profiling by default.
620AC_ARG_ENABLE([prof],
621  [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
622[if test "x$enable_prof" = "xno" ; then
623  enable_prof="0"
624else
625  enable_prof="1"
626fi
627],
628[enable_prof="0"]
629)
630if test "x$enable_prof" = "x1" ; then
631  backtrace_method=""
632else
633  backtrace_method="N/A"
634fi
635
636AC_ARG_ENABLE([prof-libunwind],
637  [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
638[if test "x$enable_prof_libunwind" = "xno" ; then
639  enable_prof_libunwind="0"
640else
641  enable_prof_libunwind="1"
642fi
643],
644[enable_prof_libunwind="0"]
645)
646AC_ARG_WITH([static_libunwind],
647  [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
648  [Path to static libunwind library; use rather than dynamically linking])],
649if test "x$with_static_libunwind" = "xno" ; then
650  LUNWIND="-lunwind"
651else
652  if test ! -f "$with_static_libunwind" ; then
653    AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
654  fi
655  LUNWIND="$with_static_libunwind"
656fi,
657  LUNWIND="-lunwind"
658)
659if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
660  AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
661  if test "x$LUNWIND" = "x-lunwind" ; then
662    AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
663                 [enable_prof_libunwind="0"])
664  else
665    LIBS="$LIBS $LUNWIND"
666  fi
667  if test "x${enable_prof_libunwind}" = "x1" ; then
668    backtrace_method="libunwind"
669    AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
670  fi
671fi
672
673AC_ARG_ENABLE([prof-libgcc],
674  [AS_HELP_STRING([--disable-prof-libgcc],
675  [Do not use libgcc for backtracing])],
676[if test "x$enable_prof_libgcc" = "xno" ; then
677  enable_prof_libgcc="0"
678else
679  enable_prof_libgcc="1"
680fi
681],
682[enable_prof_libgcc="1"]
683)
684if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
685     -a "x$GCC" = "xyes" ; then
686  AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
687  AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
688  dnl The following is conservative, in that it only has entries for CPUs on
689  dnl which jemalloc has been tested.
690  AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
691  case "${host_cpu}" in
692    i[[3456]]86)
693      AC_MSG_RESULT([unreliable])
694      enable_prof_libgcc="0";
695      ;;
696    x86_64)
697      AC_MSG_RESULT([reliable])
698      ;;
699    *)
700      AC_MSG_RESULT([unreliable])
701      enable_prof_libgcc="0";
702      ;;
703  esac
704  if test "x${enable_prof_libgcc}" = "x1" ; then
705    backtrace_method="libgcc"
706    AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
707  fi
708else
709  enable_prof_libgcc="0"
710fi
711
712AC_ARG_ENABLE([prof-gcc],
713  [AS_HELP_STRING([--disable-prof-gcc],
714  [Do not use gcc intrinsics for backtracing])],
715[if test "x$enable_prof_gcc" = "xno" ; then
716  enable_prof_gcc="0"
717else
718  enable_prof_gcc="1"
719fi
720],
721[enable_prof_gcc="1"]
722)
723if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
724     -a "x$GCC" = "xyes" ; then
725  backtrace_method="gcc intrinsics"
726  AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
727else
728  enable_prof_gcc="0"
729fi
730
731if test "x$backtrace_method" = "x" ; then
732  backtrace_method="none (disabling profiling)"
733  enable_prof="0"
734fi
735AC_MSG_CHECKING([configured backtracing method])
736AC_MSG_RESULT([$backtrace_method])
737if test "x$enable_prof" = "x1" ; then
738  if test "x${force_tls}" = "x0" ; then
739    AC_MSG_ERROR([Heap profiling requires TLS]);
740  fi
741  force_tls="1"
742  AC_DEFINE([JEMALLOC_PROF], [ ])
743fi
744AC_SUBST([enable_prof])
745
746dnl Enable thread-specific caching by default.
747AC_ARG_ENABLE([tcache],
748  [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
749[if test "x$enable_tcache" = "xno" ; then
750  enable_tcache="0"
751else
752  enable_tcache="1"
753fi
754],
755[enable_tcache="1"]
756)
757if test "x$enable_tcache" = "x1" ; then
758  AC_DEFINE([JEMALLOC_TCACHE], [ ])
759fi
760AC_SUBST([enable_tcache])
761
762dnl Disable mremap() for huge realloc() by default.
763AC_ARG_ENABLE([mremap],
764  [AS_HELP_STRING([--enable-mremap], [Enable mremap(2) for huge realloc()])],
765[if test "x$enable_mremap" = "xno" ; then
766  enable_mremap="0"
767else
768  enable_mremap="1"
769fi
770],
771[enable_mremap="0"]
772)
773if test "x$enable_mremap" = "x1" ; then
774  JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
775#define _GNU_SOURCE
776#include <sys/mman.h>
777], [
778void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
779], [je_cv_mremap_fixed])
780  if test "x${je_cv_mremap_fixed}" = "xno" ; then
781    enable_mremap="0"
782  fi
783fi
784if test "x$enable_mremap" = "x1" ; then
785  AC_DEFINE([JEMALLOC_MREMAP], [ ])
786fi
787AC_SUBST([enable_mremap])
788
789dnl Enable VM deallocation via munmap() by default.
790AC_ARG_ENABLE([munmap],
791  [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
792[if test "x$enable_munmap" = "xno" ; then
793  enable_munmap="0"
794else
795  enable_munmap="1"
796fi
797],
798[enable_munmap="${default_munmap}"]
799)
800if test "x$enable_munmap" = "x1" ; then
801  AC_DEFINE([JEMALLOC_MUNMAP], [ ])
802fi
803AC_SUBST([enable_munmap])
804
805dnl Do not enable allocation from DSS by default.
806AC_ARG_ENABLE([dss],
807  [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
808[if test "x$enable_dss" = "xno" ; then
809  enable_dss="0"
810else
811  enable_dss="1"
812fi
813],
814[enable_dss="0"]
815)
816dnl Check whether the BSD/SUSv1 sbrk() exists.  If not, disable DSS support.
817AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
818if test "x$have_sbrk" = "x1" ; then
819  AC_DEFINE([JEMALLOC_HAVE_SBRK], [ ])
820else
821  enable_dss="0"
822fi
823
824if test "x$enable_dss" = "x1" ; then
825  AC_DEFINE([JEMALLOC_DSS], [ ])
826fi
827AC_SUBST([enable_dss])
828
829dnl Support the junk/zero filling option by default.
830AC_ARG_ENABLE([fill],
831  [AS_HELP_STRING([--disable-fill],
832                  [Disable support for junk/zero filling, quarantine, and redzones])],
833[if test "x$enable_fill" = "xno" ; then
834  enable_fill="0"
835else
836  enable_fill="1"
837fi
838],
839[enable_fill="1"]
840)
841if test "x$enable_fill" = "x1" ; then
842  AC_DEFINE([JEMALLOC_FILL], [ ])
843fi
844AC_SUBST([enable_fill])
845
846dnl Disable utrace(2)-based tracing by default.
847AC_ARG_ENABLE([utrace],
848  [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
849[if test "x$enable_utrace" = "xno" ; then
850  enable_utrace="0"
851else
852  enable_utrace="1"
853fi
854],
855[enable_utrace="0"]
856)
857JE_COMPILABLE([utrace(2)], [
858#include <sys/types.h>
859#include <sys/param.h>
860#include <sys/time.h>
861#include <sys/uio.h>
862#include <sys/ktrace.h>
863], [
864	utrace((void *)0, 0);
865], [je_cv_utrace])
866if test "x${je_cv_utrace}" = "xno" ; then
867  enable_utrace="0"
868fi
869if test "x$enable_utrace" = "x1" ; then
870  AC_DEFINE([JEMALLOC_UTRACE], [ ])
871fi
872AC_SUBST([enable_utrace])
873
874dnl Support Valgrind by default.
875AC_ARG_ENABLE([valgrind],
876  [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
877[if test "x$enable_valgrind" = "xno" ; then
878  enable_valgrind="0"
879else
880  enable_valgrind="1"
881fi
882],
883[enable_valgrind="1"]
884)
885if test "x$enable_valgrind" = "x1" ; then
886  JE_COMPILABLE([valgrind], [
887#include <valgrind/valgrind.h>
888#include <valgrind/memcheck.h>
889
890#if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
891#  error "Incompatible Valgrind version"
892#endif
893], [], [je_cv_valgrind])
894  if test "x${je_cv_valgrind}" = "xno" ; then
895    enable_valgrind="0"
896  fi
897  if test "x$enable_valgrind" = "x1" ; then
898    AC_DEFINE([JEMALLOC_VALGRIND], [ ])
899  fi
900fi
901AC_SUBST([enable_valgrind])
902
903dnl Do not support the xmalloc option by default.
904AC_ARG_ENABLE([xmalloc],
905  [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
906[if test "x$enable_xmalloc" = "xno" ; then
907  enable_xmalloc="0"
908else
909  enable_xmalloc="1"
910fi
911],
912[enable_xmalloc="0"]
913)
914if test "x$enable_xmalloc" = "x1" ; then
915  AC_DEFINE([JEMALLOC_XMALLOC], [ ])
916fi
917AC_SUBST([enable_xmalloc])
918
919AC_CACHE_CHECK([STATIC_PAGE_SHIFT],
920               [je_cv_static_page_shift],
921               AC_RUN_IFELSE([AC_LANG_PROGRAM(
922[[
923#include <strings.h>
924#ifdef _WIN32
925#include <windows.h>
926#else
927#include <unistd.h>
928#endif
929#include <stdio.h>
930]],
931[[
932    int result;
933    FILE *f;
934
935#ifdef _WIN32
936    SYSTEM_INFO si;
937    GetSystemInfo(&si);
938    result = si.dwPageSize;
939#else
940    result = sysconf(_SC_PAGESIZE);
941#endif
942    if (result == -1) {
943	return 1;
944    }
945    result = ffsl(result) - 1;
946
947    f = fopen("conftest.out", "w");
948    if (f == NULL) {
949	return 1;
950    }
951    fprintf(f, "%d\n", result);
952    fclose(f);
953
954    return 0;
955]])],
956                             [je_cv_static_page_shift=`cat conftest.out`],
957                             [je_cv_static_page_shift=undefined]))
958
959if test "x$je_cv_static_page_shift" != "xundefined"; then
960   AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$je_cv_static_page_shift])
961else
962   AC_MSG_ERROR([cannot determine value for STATIC_PAGE_SHIFT])
963fi
964
965dnl ============================================================================
966dnl jemalloc configuration.
967dnl 
968
969dnl Set VERSION if source directory has an embedded git repository.
970if test -d "${srcroot}.git" ; then
971  git describe --long --abbrev=40 > ${srcroot}VERSION
972fi
973jemalloc_version=`cat ${srcroot}VERSION`
974jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
975jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
976jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
977jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
978jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
979AC_SUBST([jemalloc_version])
980AC_SUBST([jemalloc_version_major])
981AC_SUBST([jemalloc_version_minor])
982AC_SUBST([jemalloc_version_bugfix])
983AC_SUBST([jemalloc_version_nrev])
984AC_SUBST([jemalloc_version_gid])
985
986dnl ============================================================================
987dnl Configure pthreads.
988
989if test "x$abi" != "xpecoff" ; then
990  AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
991  dnl Some systems may embed pthreads functionality in libc; check for libpthread
992  dnl first, but try libc too before failing.
993  AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
994               [AC_SEARCH_LIBS([pthread_create], , ,
995                               AC_MSG_ERROR([libpthread is missing]))])
996fi
997
998CPPFLAGS="$CPPFLAGS -D_REENTRANT"
999
1000dnl Check whether the BSD-specific _malloc_thread_cleanup() exists.  If so, use
1001dnl it rather than pthreads TSD cleanup functions to support cleanup during
1002dnl thread exit, in order to avoid pthreads library recursion during
1003dnl bootstrapping.
1004AC_CHECK_FUNC([_malloc_thread_cleanup],
1005              [have__malloc_thread_cleanup="1"],
1006              [have__malloc_thread_cleanup="0"]
1007             )
1008if test "x$have__malloc_thread_cleanup" = "x1" ; then
1009  AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1010  force_tls="1"
1011fi
1012
1013dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists.  If
1014dnl so, mutex initialization causes allocation, and we need to implement this
1015dnl callback function in order to prevent recursive allocation.
1016AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1017              [have__pthread_mutex_init_calloc_cb="1"],
1018              [have__pthread_mutex_init_calloc_cb="0"]
1019             )
1020if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1021  AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1022fi
1023
1024dnl Disable lazy locking by default.
1025AC_ARG_ENABLE([lazy_lock],
1026  [AS_HELP_STRING([--enable-lazy-lock],
1027  [Enable lazy locking (only lock when multi-threaded)])],
1028[if test "x$enable_lazy_lock" = "xno" ; then
1029  enable_lazy_lock="0"
1030else
1031  enable_lazy_lock="1"
1032fi
1033],
1034[enable_lazy_lock="0"]
1035)
1036if test "x$enable_lazy_lock" = "x0" -a "x${force_lazy_lock}" = "x1" ; then
1037  AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1038  enable_lazy_lock="1"
1039fi
1040if test "x$enable_lazy_lock" = "x1" ; then
1041  if test "x$abi" != "xpecoff" ; then
1042    AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1043    AC_CHECK_FUNC([dlsym], [],
1044      [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1045                    [AC_MSG_ERROR([libdl is missing])])
1046      ])
1047  fi
1048  AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1049fi
1050AC_SUBST([enable_lazy_lock])
1051
1052AC_ARG_ENABLE([tls],
1053  [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1054if test "x$enable_tls" = "xno" ; then
1055  enable_tls="0"
1056else
1057  enable_tls="1"
1058fi
1059,
1060enable_tls="1"
1061)
1062if test "x${enable_tls}" = "x0" -a "x${force_tls}" = "x1" ; then
1063  AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1064  enable_tls="1"
1065fi
1066if test "x${enable_tls}" = "x1" -a "x${force_tls}" = "x0" ; then
1067  AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1068  enable_tls="0"
1069fi
1070if test "x${enable_tls}" = "x1" ; then
1071AC_MSG_CHECKING([for TLS])
1072AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1073[[
1074    __thread int x;
1075]], [[
1076    x = 42;
1077
1078    return 0;
1079]])],
1080              AC_MSG_RESULT([yes]),
1081              AC_MSG_RESULT([no])
1082              enable_tls="0")
1083fi
1084AC_SUBST([enable_tls])
1085if test "x${enable_tls}" = "x1" ; then
1086  AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1087elif test "x${force_tls}" = "x1" ; then
1088  AC_MSG_ERROR([Failed to configure TLS, which is mandatory for correct function])
1089fi
1090
1091dnl ============================================================================
1092dnl Check for ffsl(3), and fail if not found.  This function exists on all
1093dnl platforms that jemalloc currently has a chance of functioning on without
1094dnl modification.
1095JE_COMPILABLE([a program using ffsl], [
1096#include <stdio.h>
1097#include <strings.h>
1098#include <string.h>
1099], [
1100	{
1101		int rv = ffsl(0x08);
1102		printf("%d\n", rv);
1103	}
1104], [je_cv_function_ffsl])
1105if test "x${je_cv_function_ffsl}" != "xyes" ; then
1106   AC_MSG_ERROR([Cannot build without ffsl(3)])
1107fi
1108
1109dnl ============================================================================
1110dnl Check for atomic(9) operations as provided on FreeBSD.
1111
1112JE_COMPILABLE([atomic(9)], [
1113#include <sys/types.h>
1114#include <machine/atomic.h>
1115#include <inttypes.h>
1116], [
1117	{
1118		uint32_t x32 = 0;
1119		volatile uint32_t *x32p = &x32;
1120		atomic_fetchadd_32(x32p, 1);
1121	}
1122	{
1123		unsigned long xlong = 0;
1124		volatile unsigned long *xlongp = &xlong;
1125		atomic_fetchadd_long(xlongp, 1);
1126	}
1127], [je_cv_atomic9])
1128if test "x${je_cv_atomic9}" = "xyes" ; then
1129  AC_DEFINE([JEMALLOC_ATOMIC9])
1130fi
1131
1132dnl ============================================================================
1133dnl Check for atomic(3) operations as provided on Darwin.
1134
1135JE_COMPILABLE([Darwin OSAtomic*()], [
1136#include <libkern/OSAtomic.h>
1137#include <inttypes.h>
1138], [
1139	{
1140		int32_t x32 = 0;
1141		volatile int32_t *x32p = &x32;
1142		OSAtomicAdd32(1, x32p);
1143	}
1144	{
1145		int64_t x64 = 0;
1146		volatile int64_t *x64p = &x64;
1147		OSAtomicAdd64(1, x64p);
1148	}
1149], [je_cv_osatomic])
1150if test "x${je_cv_osatomic}" = "xyes" ; then
1151  AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1152fi
1153
1154dnl ============================================================================
1155dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1156dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1157
1158AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1159  AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1160               [je_cv_sync_compare_and_swap_$2],
1161               [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1162                                                 #include <stdint.h>
1163                                                ],
1164                                                [
1165                                                 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1166                                                 {
1167                                                    uint$1_t x$1 = 0;
1168                                                    __sync_add_and_fetch(&x$1, 42);
1169                                                    __sync_sub_and_fetch(&x$1, 1);
1170                                                 }
1171                                                 #else
1172                                                 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1173                                                 #endif
1174                                                ])],
1175                               [je_cv_sync_compare_and_swap_$2=yes],
1176                               [je_cv_sync_compare_and_swap_$2=no])])
1177
1178  if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1179    AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1180  fi
1181])
1182
1183if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
1184  JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1185  JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1186fi
1187
1188dnl ============================================================================
1189dnl Check for spinlock(3) operations as provided on Darwin.
1190
1191JE_COMPILABLE([Darwin OSSpin*()], [
1192#include <libkern/OSAtomic.h>
1193#include <inttypes.h>
1194], [
1195	OSSpinLock lock = 0;
1196	OSSpinLockLock(&lock);
1197	OSSpinLockUnlock(&lock);
1198], [je_cv_osspin])
1199if test "x${je_cv_osspin}" = "xyes" ; then
1200  AC_DEFINE([JEMALLOC_OSSPIN], [ ])
1201fi
1202
1203dnl ============================================================================
1204dnl Darwin-related configuration.
1205
1206AC_ARG_ENABLE([zone-allocator],
1207  [AS_HELP_STRING([--disable-zone-allocator],
1208                  [Disable zone allocator for Darwin])],
1209[if test "x$enable_zone_allocator" = "xno" ; then
1210  enable_zone_allocator="0"
1211else
1212  enable_zone_allocator="1"
1213fi
1214],
1215[if test "x${abi}" = "xmacho"; then
1216  enable_zone_allocator="1"
1217fi
1218]
1219)
1220AC_SUBST([enable_zone_allocator])
1221
1222if test "x${enable_zone_allocator}" = "x1" ; then
1223  if test "x${abi}" != "xmacho"; then
1224    AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1225  fi
1226  AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
1227  AC_DEFINE([JEMALLOC_ZONE], [ ])
1228
1229  dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1230  dnl releases.  malloc_zone_t and malloc_introspection_t have new fields in
1231  dnl 10.6, which is the only source-level indication of the change.
1232  AC_MSG_CHECKING([malloc zone version])
1233  AC_DEFUN([JE_ZONE_PROGRAM],
1234    [AC_LANG_PROGRAM(
1235      [#include <malloc/malloc.h>],
1236      [static foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1237    )])
1238
1239  AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1240  AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1241  AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1242    AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1243    AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1244  )])],[
1245  AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1246  AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1247  )])])])])
1248  if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1249    AC_MSG_RESULT([unsupported])
1250    AC_MSG_ERROR([Unsupported malloc zone version])
1251  fi
1252  if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1253    JEMALLOC_ZONE_VERSION=8
1254    AC_MSG_RESULT([> 8])
1255  else
1256    AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1257  fi
1258  AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
1259fi
1260
1261dnl ============================================================================
1262dnl Check for typedefs, structures, and compiler characteristics.
1263AC_HEADER_STDBOOL
1264
1265AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1266  mkdir -p "include/jemalloc/internal"
1267  "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
1268])
1269
1270dnl Process .in files.
1271AC_SUBST([cfghdrs_in])
1272AC_SUBST([cfghdrs_out])
1273AC_CONFIG_HEADERS([$cfghdrs_tup])
1274
1275dnl ============================================================================
1276dnl Generate outputs.
1277AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
1278AC_SUBST([cfgoutputs_in])
1279AC_SUBST([cfgoutputs_out])
1280AC_OUTPUT
1281
1282dnl ============================================================================
1283dnl Print out the results of configuration.
1284AC_MSG_RESULT([===============================================================================])
1285AC_MSG_RESULT([jemalloc version   : ${jemalloc_version}])
1286AC_MSG_RESULT([library revision   : ${rev}])
1287AC_MSG_RESULT([])
1288AC_MSG_RESULT([CC                 : ${CC}])
1289AC_MSG_RESULT([CPPFLAGS           : ${CPPFLAGS}])
1290AC_MSG_RESULT([CFLAGS             : ${CFLAGS}])
1291AC_MSG_RESULT([LDFLAGS            : ${LDFLAGS}])
1292AC_MSG_RESULT([LIBS               : ${LIBS}])
1293AC_MSG_RESULT([RPATH_EXTRA        : ${RPATH_EXTRA}])
1294AC_MSG_RESULT([])
1295AC_MSG_RESULT([XSLTPROC           : ${XSLTPROC}])
1296AC_MSG_RESULT([XSLROOT            : ${XSLROOT}])
1297AC_MSG_RESULT([])
1298AC_MSG_RESULT([PREFIX             : ${PREFIX}])
1299AC_MSG_RESULT([BINDIR             : ${BINDIR}])
1300AC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
1301AC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
1302AC_MSG_RESULT([DATADIR            : ${DATADIR}])
1303AC_MSG_RESULT([MANDIR             : ${MANDIR}])
1304AC_MSG_RESULT([])
1305AC_MSG_RESULT([srcroot            : ${srcroot}])
1306AC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
1307AC_MSG_RESULT([objroot            : ${objroot}])
1308AC_MSG_RESULT([abs_objroot        : ${abs_objroot}])
1309AC_MSG_RESULT([])
1310AC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
1311AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1312AC_MSG_RESULT([                   : ${JEMALLOC_PRIVATE_NAMESPACE}])
1313AC_MSG_RESULT([install_suffix     : ${install_suffix}])
1314AC_MSG_RESULT([autogen            : ${enable_autogen}])
1315AC_MSG_RESULT([experimental       : ${enable_experimental}])
1316AC_MSG_RESULT([cc-silence         : ${enable_cc_silence}])
1317AC_MSG_RESULT([debug              : ${enable_debug}])
1318AC_MSG_RESULT([stats              : ${enable_stats}])
1319AC_MSG_RESULT([prof               : ${enable_prof}])
1320AC_MSG_RESULT([prof-libunwind     : ${enable_prof_libunwind}])
1321AC_MSG_RESULT([prof-libgcc        : ${enable_prof_libgcc}])
1322AC_MSG_RESULT([prof-gcc           : ${enable_prof_gcc}])
1323AC_MSG_RESULT([tcache             : ${enable_tcache}])
1324AC_MSG_RESULT([fill               : ${enable_fill}])
1325AC_MSG_RESULT([utrace             : ${enable_utrace}])
1326AC_MSG_RESULT([valgrind           : ${enable_valgrind}])
1327AC_MSG_RESULT([xmalloc            : ${enable_xmalloc}])
1328AC_MSG_RESULT([mremap             : ${enable_mremap}])
1329AC_MSG_RESULT([munmap             : ${enable_munmap}])
1330AC_MSG_RESULT([dss                : ${enable_dss}])
1331AC_MSG_RESULT([lazy_lock          : ${enable_lazy_lock}])
1332AC_MSG_RESULT([tls                : ${enable_tls}])
1333AC_MSG_RESULT([===============================================================================])
1334