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