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