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