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