configure.ac revision ef8897b4b938111fcc9b54725067f1dbb33a4c20
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_RUN_IFELSE([AC_LANG_PROGRAM(
18[[
19]], [[
20    return 0;
21]])],
22              AC_MSG_RESULT([yes]),
23              AC_MSG_RESULT([no])
24              [CFLAGS="${TCFLAGS}"]
25)
26])
27
28dnl JE_COMPILABLE(label, hcode, mcode, rvar)
29AC_DEFUN([JE_COMPILABLE],
30[
31AC_MSG_CHECKING([whether $1 is compilable])
32AC_RUN_IFELSE([AC_LANG_PROGRAM(
33[$2], [$3])],
34              AC_MSG_RESULT([yes])
35              [$4="yes"],
36              AC_MSG_RESULT([no])
37              [$4="no"]
38)
39])
40
41dnl ============================================================================
42
43dnl Library revision.
44rev=1
45AC_SUBST([rev])
46
47srcroot=$srcdir
48if test "x${srcroot}" = "x." ; then
49  srcroot=""
50else
51  srcroot="${srcroot}/"
52fi
53AC_SUBST([srcroot])
54abs_srcroot="`cd \"${srcdir}\"; pwd`/"
55AC_SUBST([abs_srcroot])
56
57objroot=""
58AC_SUBST([objroot])
59abs_objroot="`pwd`/"
60AC_SUBST([abs_objroot])
61
62dnl Munge install path variables.
63if test "x$prefix" = "xNONE" ; then
64  prefix="/usr/local"
65fi
66if test "x$exec_prefix" = "xNONE" ; then
67  exec_prefix=$prefix
68fi
69PREFIX=$prefix
70AC_SUBST([PREFIX])
71BINDIR=`eval echo $bindir`
72BINDIR=`eval echo $BINDIR`
73AC_SUBST([BINDIR])
74INCLUDEDIR=`eval echo $includedir`
75INCLUDEDIR=`eval echo $INCLUDEDIR`
76AC_SUBST([INCLUDEDIR])
77LIBDIR=`eval echo $libdir`
78LIBDIR=`eval echo $LIBDIR`
79AC_SUBST([LIBDIR])
80DATADIR=`eval echo $datadir`
81DATADIR=`eval echo $DATADIR`
82AC_SUBST([DATADIR])
83MANDIR=`eval echo $mandir`
84MANDIR=`eval echo $MANDIR`
85AC_SUBST([MANDIR])
86
87dnl Support for building documentation.
88AC_PATH_PROG([XSLTPROC], [xsltproc], , [$PATH])
89AC_ARG_WITH([xslroot],
90  [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])],
91if test "x$with_xslroot" = "xno" ; then
92  XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
93else
94  XSLROOT="${with_xslroot}"
95fi,
96  XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
97)
98AC_SUBST([XSLROOT])
99
100dnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
101dnl just prevent autoconf from molesting CFLAGS.
102CFLAGS=$CFLAGS
103AC_PROG_CC
104if test "x$CFLAGS" = "x" ; then
105  no_CFLAGS="yes"
106  if test "x$GCC" = "xyes" ; then
107    JE_CFLAGS_APPEND([-std=gnu99])
108    JE_CFLAGS_APPEND([-Wall])
109    JE_CFLAGS_APPEND([-pipe])
110    JE_CFLAGS_APPEND([-g3])
111  fi
112fi
113dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
114if test "x$EXTRA_CFLAGS" != "x" ; then
115  JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
116fi
117AC_PROG_CPP
118
119AC_CHECK_SIZEOF([void *])
120if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
121  LG_SIZEOF_PTR=3
122elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
123  LG_SIZEOF_PTR=2
124else
125  AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
126fi
127AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
128
129AC_CHECK_SIZEOF([int])
130if test "x${ac_cv_sizeof_int}" = "x8" ; then
131  LG_SIZEOF_INT=3
132elif test "x${ac_cv_sizeof_int}" = "x4" ; then
133  LG_SIZEOF_INT=2
134else
135  AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
136fi
137AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
138
139AC_CHECK_SIZEOF([long])
140if test "x${ac_cv_sizeof_long}" = "x8" ; then
141  LG_SIZEOF_LONG=3
142elif test "x${ac_cv_sizeof_long}" = "x4" ; then
143  LG_SIZEOF_LONG=2
144else
145  AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
146fi
147AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
148
149AC_CANONICAL_HOST
150dnl CPU-specific settings.
151CPU_SPINWAIT=""
152case "${host_cpu}" in
153  i[[345]]86)
154	;;
155  i686)
156	JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
157	              [asm])
158	if test "x${asm}" = "xyes" ; then
159	    CPU_SPINWAIT='__asm__ volatile("pause")'
160	fi
161	;;
162  x86_64)
163	JE_COMPILABLE([__asm__ syntax], [],
164	              [[__asm__ volatile("pause"); return 0;]], [asm])
165	if test "x${asm}" = "xyes" ; then
166	    CPU_SPINWAIT='__asm__ volatile("pause")'
167	fi
168	;;
169  *)
170	;;
171esac
172AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
173
174LD_PRELOAD_VAR="LD_PRELOAD"
175so="so"
176
177dnl Heap profiling uses the log(3) function.
178LIBS="$LIBS -lm"
179
180dnl Platform-specific settings.  abi and RPATH can probably be determined
181dnl programmatically, but doing so is error-prone, which makes it generally
182dnl not worth the trouble.
183dnl 
184dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
185dnl definitions need to be seen before any headers are included, which is a pain
186dnl to make happen otherwise.
187case "${host}" in
188  *-*-darwin*)
189	CFLAGS="$CFLAGS -fno-common -no-cpp-precomp"
190	abi="macho"
191	AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
192	RPATH=""
193	LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
194	so="dylib"
195	;;
196  *-*-freebsd*)
197	CFLAGS="$CFLAGS"
198	abi="elf"
199	AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
200	RPATH="-Wl,-rpath,"
201	;;
202  *-*-linux*)
203	CFLAGS="$CFLAGS"
204	CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
205	abi="elf"
206	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED])
207	RPATH="-Wl,-rpath,"
208	;;
209  *-*-netbsd*)
210	AC_MSG_CHECKING([ABI])
211        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
212[[#ifdef __ELF__
213/* ELF */
214#else
215#error aout
216#endif
217]])],
218                          [CFLAGS="$CFLAGS"; abi="elf"],
219                          [abi="aout"])
220	AC_MSG_RESULT([$abi])
221	AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
222	RPATH="-Wl,-rpath,"
223	;;
224  *-*-solaris2*)
225	CFLAGS="$CFLAGS"
226	abi="elf"
227	RPATH="-Wl,-R,"
228	dnl Solaris needs this for sigwait().
229	CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
230	LIBS="$LIBS -lposix4 -lsocket -lnsl"
231	;;
232  *-ibm-aix*)
233	if "$LG_SIZEOF_PTR" = "8"; then
234	  dnl 64bit AIX
235	  LD_PRELOAD_VAR="LDR_PRELOAD64"
236	else
237	  dnl 32bit AIX
238	  LD_PRELOAD_VAR="LDR_PRELOAD"
239	fi
240	abi="xcoff"
241	RPATH="-Wl,-rpath,"
242	;;
243  *)
244	AC_MSG_RESULT([Unsupported operating system: ${host}])
245	abi="elf"
246	RPATH="-Wl,-rpath,"
247	;;
248esac
249AC_SUBST([abi])
250AC_SUBST([RPATH])
251AC_SUBST([LD_PRELOAD_VAR])
252AC_SUBST([so])
253
254JE_COMPILABLE([__attribute__ syntax],
255              [static __attribute__((unused)) void foo(void){}],
256              [],
257              [attribute])
258if test "x${attribute}" = "xyes" ; then
259  AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
260  if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
261    JE_CFLAGS_APPEND([-fvisibility=hidden])
262  fi
263fi
264
265JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
266#define _GNU_SOURCE
267#include <sys/mman.h>
268], [
269void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
270], [mremap_fixed])
271if test "x${mremap_fixed}" = "xyes" ; then
272  AC_DEFINE([JEMALLOC_MREMAP_FIXED])
273fi
274
275dnl Support optional additions to rpath.
276AC_ARG_WITH([rpath],
277  [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
278if test "x$with_rpath" = "xno" ; then
279  RPATH_EXTRA=
280else
281  RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
282fi,
283  RPATH_EXTRA=
284)
285AC_SUBST([RPATH_EXTRA])
286
287dnl Disable rules that do automatic regeneration of configure output by default.
288AC_ARG_ENABLE([autogen],
289  [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
290if test "x$enable_autogen" = "xno" ; then
291  enable_autogen="0"
292else
293  enable_autogen="1"
294fi
295,
296enable_autogen="0"
297)
298AC_SUBST([enable_autogen])
299
300AC_PROG_INSTALL
301AC_PROG_RANLIB
302AC_PATH_PROG([AR], [ar], , [$PATH])
303AC_PATH_PROG([LD], [ld], , [$PATH])
304AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
305
306dnl Do not prefix public APIs by default.
307AC_ARG_WITH([jemalloc_prefix],
308  [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
309  [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
310  [if test "x$abi" != "xmacho" ; then
311  JEMALLOC_PREFIX=""
312else
313  JEMALLOC_PREFIX="je_"
314fi]
315)
316if test "x$JEMALLOC_PREFIX" != "x" ; then
317  JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
318  AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
319  AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
320  AC_DEFINE_UNQUOTED([JEMALLOC_P(string_that_no_one_should_want_to_use_as_a_jemalloc_API_prefix)], [${JEMALLOC_PREFIX}##string_that_no_one_should_want_to_use_as_a_jemalloc_API_prefix])
321fi
322
323dnl Do not mangle library-private APIs by default.
324AC_ARG_WITH([private_namespace],
325  [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
326  [JEMALLOC_PRIVATE_NAMESPACE="$with_private_namespace"],
327  [JEMALLOC_PRIVATE_NAMESPACE=""]
328)
329AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], ["$JEMALLOC_PRIVATE_NAMESPACE"])
330if test "x$JEMALLOC_PRIVATE_NAMESPACE" != "x" ; then
331  AC_DEFINE_UNQUOTED([JEMALLOC_N(string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix)], [${JEMALLOC_PRIVATE_NAMESPACE}##string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix])
332else
333  AC_DEFINE_UNQUOTED([JEMALLOC_N(string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix)], [string_that_no_one_should_want_to_use_as_a_jemalloc_private_namespace_prefix])
334fi
335
336dnl Do not add suffix to installed files by default.
337AC_ARG_WITH([install_suffix],
338  [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
339  [INSTALL_SUFFIX="$with_install_suffix"],
340  [INSTALL_SUFFIX=]
341)
342install_suffix="$INSTALL_SUFFIX"
343AC_SUBST([install_suffix])
344
345cfgoutputs_in="${srcroot}Makefile.in"
346cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
347cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
348cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
349cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
350cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
351cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
352
353cfgoutputs_out="Makefile"
354cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
355cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
356cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
357cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
358cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
359cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
360
361cfgoutputs_tup="Makefile"
362cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
363cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
364cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
365cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
366cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
367cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
368
369cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
370
371cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
372
373cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
374
375dnl Do not silence irrelevant compiler warnings by default, since enabling this
376dnl option incurs a performance penalty.
377AC_ARG_ENABLE([cc-silence],
378  [AS_HELP_STRING([--enable-cc-silence],
379                  [Silence irrelevant compiler warnings])],
380[if test "x$enable_cc_silence" = "xno" ; then
381  enable_cc_silence="0"
382else
383  enable_cc_silence="1"
384fi
385],
386[enable_cc_silence="0"]
387)
388if test "x$enable_cc_silence" = "x1" ; then
389  AC_DEFINE([JEMALLOC_CC_SILENCE])
390fi
391
392dnl Do not compile with debugging by default.
393AC_ARG_ENABLE([debug],
394  [AS_HELP_STRING([--enable-debug], [Build debugging code])],
395[if test "x$enable_debug" = "xno" ; then
396  enable_debug="0"
397else
398  enable_debug="1"
399fi
400],
401[enable_debug="0"]
402)
403if test "x$enable_debug" = "x1" ; then
404  AC_DEFINE([JEMALLOC_DEBUG], [ ])
405  AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
406fi
407AC_SUBST([enable_debug])
408
409dnl Only optimize if not debugging.
410if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
411  dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
412  optimize="no"
413  echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
414  if test "x${optimize}" = "xyes" ; then
415    if test "x$GCC" = "xyes" ; then
416      JE_CFLAGS_APPEND([-O3])
417      JE_CFLAGS_APPEND([-funroll-loops])
418    else
419      JE_CFLAGS_APPEND([-O])
420    fi
421  fi
422fi
423
424dnl Do not enable statistics calculation by default.
425AC_ARG_ENABLE([stats],
426  [AS_HELP_STRING([--enable-stats], [Enable statistics calculation/reporting])],
427[if test "x$enable_stats" = "xno" ; then
428  enable_stats="0"
429else
430  enable_stats="1"
431fi
432],
433[enable_stats="0"]
434)
435if test "x$enable_stats" = "x1" ; then
436  AC_DEFINE([JEMALLOC_STATS], [ ])
437fi
438AC_SUBST([enable_stats])
439
440dnl Do not enable profiling by default.
441AC_ARG_ENABLE([prof],
442  [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
443[if test "x$enable_prof" = "xno" ; then
444  enable_prof="0"
445else
446  enable_prof="1"
447fi
448],
449[enable_prof="0"]
450)
451if test "x$enable_prof" = "x1" ; then
452  backtrace_method=""
453else
454  backtrace_method="N/A"
455fi
456
457AC_ARG_ENABLE([prof-libunwind],
458  [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
459[if test "x$enable_prof_libunwind" = "xno" ; then
460  enable_prof_libunwind="0"
461else
462  enable_prof_libunwind="1"
463fi
464],
465[enable_prof_libunwind="0"]
466)
467AC_ARG_WITH([static_libunwind],
468  [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
469  [Path to static libunwind library; use rather than dynamically linking])],
470if test "x$with_static_libunwind" = "xno" ; then
471  LUNWIND="-lunwind"
472else
473  if test ! -f "$with_static_libunwind" ; then
474    AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
475  fi
476  LUNWIND="$with_static_libunwind"
477fi,
478  LUNWIND="-lunwind"
479)
480if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
481  AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
482  if test "x$LUNWIND" = "x-lunwind" ; then
483    AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
484                 [enable_prof_libunwind="0"])
485  else
486    LIBS="$LIBS $LUNWIND"
487  fi
488  if test "x${enable_prof_libunwind}" = "x1" ; then
489    backtrace_method="libunwind"
490    AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
491  fi
492fi
493
494AC_ARG_ENABLE([prof-libgcc],
495  [AS_HELP_STRING([--disable-prof-libgcc],
496  [Do not use libgcc for backtracing])],
497[if test "x$enable_prof_libgcc" = "xno" ; then
498  enable_prof_libgcc="0"
499else
500  enable_prof_libgcc="1"
501fi
502],
503[enable_prof_libgcc="1"]
504)
505if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
506     -a "x$GCC" = "xyes" ; then
507  AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
508  AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
509  dnl The following is conservative, in that it only has entries for CPUs on
510  dnl which jemalloc has been tested.
511  AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
512  case "${host_cpu}" in
513    i[[3456]]86)
514      AC_MSG_RESULT([unreliable])
515      enable_prof_libgcc="0";
516      ;;
517    x86_64)
518      AC_MSG_RESULT([reliable])
519      ;;
520    *)
521      AC_MSG_RESULT([unreliable])
522      enable_prof_libgcc="0";
523      ;;
524  esac
525  if test "x${enable_prof_libgcc}" = "x1" ; then
526    backtrace_method="libgcc"
527    AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
528  fi
529else
530  enable_prof_libgcc="0"
531fi
532
533AC_ARG_ENABLE([prof-gcc],
534  [AS_HELP_STRING([--disable-prof-gcc],
535  [Do not use gcc intrinsics for backtracing])],
536[if test "x$enable_prof_gcc" = "xno" ; then
537  enable_prof_gcc="0"
538else
539  enable_prof_gcc="1"
540fi
541],
542[enable_prof_gcc="1"]
543)
544if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
545     -a "x$GCC" = "xyes" ; then
546  backtrace_method="gcc intrinsics"
547  AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
548else
549  enable_prof_gcc="0"
550fi
551
552if test "x$backtrace_method" = "x" ; then
553  backtrace_method="none (disabling profiling)"
554  enable_prof="0"
555fi
556AC_MSG_CHECKING([configured backtracing method])
557AC_MSG_RESULT([$backtrace_method])
558if test "x$enable_prof" = "x1" ; then
559  AC_DEFINE([JEMALLOC_PROF], [ ])
560fi
561AC_SUBST([enable_prof])
562
563dnl Enable thread-specific caching by default.
564AC_ARG_ENABLE([tcache],
565  [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
566[if test "x$enable_tcache" = "xno" ; then
567  enable_tcache="0"
568else
569  enable_tcache="1"
570fi
571],
572[enable_tcache="1"]
573)
574if test "x$enable_tcache" = "x1" ; then
575  AC_DEFINE([JEMALLOC_TCACHE], [ ])
576fi
577AC_SUBST([enable_tcache])
578
579dnl Do not enable allocation from DSS by default.
580AC_ARG_ENABLE([dss],
581  [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
582[if test "x$enable_dss" = "xno" ; then
583  enable_dss="0"
584else
585  enable_dss="1"
586fi
587],
588[enable_dss="0"]
589)
590if test "x$enable_dss" = "x1" ; then
591  AC_DEFINE([JEMALLOC_DSS], [ ])
592fi
593AC_SUBST([enable_dss])
594
595dnl Do not support the junk/zero filling option by default.
596AC_ARG_ENABLE([fill],
597  [AS_HELP_STRING([--enable-fill], [Support junk/zero filling option])],
598[if test "x$enable_fill" = "xno" ; then
599  enable_fill="0"
600else
601  enable_fill="1"
602fi
603],
604[enable_fill="0"]
605)
606if test "x$enable_fill" = "x1" ; then
607  AC_DEFINE([JEMALLOC_FILL], [ ])
608fi
609AC_SUBST([enable_fill])
610
611dnl Do not support the xmalloc option by default.
612AC_ARG_ENABLE([xmalloc],
613  [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
614[if test "x$enable_xmalloc" = "xno" ; then
615  enable_xmalloc="0"
616else
617  enable_xmalloc="1"
618fi
619],
620[enable_xmalloc="0"]
621)
622if test "x$enable_xmalloc" = "x1" ; then
623  AC_DEFINE([JEMALLOC_XMALLOC], [ ])
624fi
625AC_SUBST([enable_xmalloc])
626
627dnl Do not support the SYSV option by default.
628AC_ARG_ENABLE([sysv],
629  [AS_HELP_STRING([--enable-sysv], [Support SYSV semantics option])],
630[if test "x$enable_sysv" = "xno" ; then
631  enable_sysv="0"
632else
633  enable_sysv="1"
634fi
635],
636[enable_sysv="0"]
637)
638if test "x$enable_sysv" = "x1" ; then
639  AC_DEFINE([JEMALLOC_SYSV], [ ])
640fi
641AC_SUBST([enable_sysv])
642
643dnl Do not determine page shift at run time by default.
644AC_ARG_ENABLE([dynamic_page_shift],
645  [AS_HELP_STRING([--enable-dynamic-page-shift],
646  [Determine page size at run time (don't trust configure result)])],
647[if test "x$enable_dynamic_page_shift" = "xno" ; then
648  enable_dynamic_page_shift="0"
649else
650  enable_dynamic_page_shift="1"
651fi
652],
653[enable_dynamic_page_shift="0"]
654)
655if test "x$enable_dynamic_page_shift" = "x1" ; then
656  AC_DEFINE([DYNAMIC_PAGE_SHIFT], [ ])
657fi
658AC_SUBST([enable_dynamic_page_shift])
659
660AC_MSG_CHECKING([STATIC_PAGE_SHIFT])
661AC_RUN_IFELSE([AC_LANG_PROGRAM(
662[[#include <stdio.h>
663#include <unistd.h>
664#include <strings.h>
665]], [[
666    long result;
667    FILE *f;
668
669    result = sysconf(_SC_PAGESIZE);
670    if (result == -1) {
671	return 1;
672    }
673    f = fopen("conftest.out", "w");
674    if (f == NULL) {
675	return 1;
676    }
677    fprintf(f, "%u\n", ffs((int)result) - 1);
678    close(f);
679
680    return 0;
681]])],
682              [STATIC_PAGE_SHIFT=`cat conftest.out`]
683              AC_MSG_RESULT([$STATIC_PAGE_SHIFT])
684              AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$STATIC_PAGE_SHIFT]),
685              AC_MSG_RESULT([error]))
686
687dnl ============================================================================
688dnl jemalloc configuration.
689dnl 
690
691dnl Set VERSION if source directory has an embedded git repository.
692if test -d "${srcroot}.git" ; then
693  git describe --long --abbrev=40 > ${srcroot}VERSION
694fi
695jemalloc_version=`cat ${srcroot}VERSION`
696jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
697jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
698jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
699jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
700jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
701AC_SUBST([jemalloc_version])
702AC_SUBST([jemalloc_version_major])
703AC_SUBST([jemalloc_version_minor])
704AC_SUBST([jemalloc_version_bugfix])
705AC_SUBST([jemalloc_version_nrev])
706AC_SUBST([jemalloc_version_gid])
707
708dnl ============================================================================
709dnl Configure pthreads.
710
711AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
712AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
713             [AC_MSG_ERROR([libpthread is missing])])
714
715CPPFLAGS="$CPPFLAGS -D_REENTRANT"
716
717dnl Disable lazy locking by default.
718AC_ARG_ENABLE([lazy_lock],
719  [AS_HELP_STRING([--enable-lazy-lock],
720  [Enable lazy locking (only lock when multi-threaded)])],
721[if test "x$enable_lazy_lock" = "xno" ; then
722  enable_lazy_lock="0"
723else
724  enable_lazy_lock="1"
725fi
726],
727[enable_lazy_lock="0"]
728)
729if test "x$enable_lazy_lock" = "x1" ; then
730  AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
731  AC_CHECK_LIB([dl], [dlopen], [LIBS="$LIBS -ldl"],
732               [AC_MSG_ERROR([libdl is missing])])
733  AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
734fi
735AC_SUBST([enable_lazy_lock])
736
737AC_ARG_ENABLE([tls],
738  [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
739if test "x$enable_tls" = "xno" ; then
740  enable_tls="0"
741else
742  enable_tls="1"
743fi
744,
745enable_tls="1"
746)
747if test "x${enable_tls}" = "x1" ; then
748AC_MSG_CHECKING([for TLS])
749AC_RUN_IFELSE([AC_LANG_PROGRAM(
750[[
751    __thread int x;
752]], [[
753    x = 42;
754
755    return 0;
756]])],
757              AC_MSG_RESULT([yes]),
758              AC_MSG_RESULT([no])
759              enable_tls="0")
760fi
761AC_SUBST([enable_tls])
762if test "x${enable_tls}" = "x0" ; then
763  AC_DEFINE_UNQUOTED([NO_TLS], [ ])
764fi
765
766dnl ============================================================================
767dnl Check for ffsl(3), and fail if not found.  This function exists on all
768dnl platforms that jemalloc currently has a chance of functioning on without
769dnl modification.
770
771AC_CHECK_FUNC([ffsl], [],
772	      [AC_MSG_ERROR([Cannot build without ffsl(3)])])
773
774dnl ============================================================================
775dnl Check for atomic(3) operations as provided on Darwin.
776
777JE_COMPILABLE([Darwin OSAtomic*()], [
778#include <libkern/OSAtomic.h>
779#include <inttypes.h>
780], [
781	{
782		int32_t x32 = 0;
783		volatile int32_t *x32p = &x32;
784		OSAtomicAdd32(1, x32p);
785	}
786	{
787		int64_t x64 = 0;
788		volatile int64_t *x64p = &x64;
789		OSAtomicAdd64(1, x64p);
790	}
791], [osatomic])
792if test "x${osatomic}" = "xyes" ; then
793  AC_DEFINE([JEMALLOC_OSATOMIC])
794fi
795
796dnl ============================================================================
797dnl Check for spinlock(3) operations as provided on Darwin.
798
799JE_COMPILABLE([Darwin OSSpin*()], [
800#include <libkern/OSAtomic.h>
801#include <inttypes.h>
802], [
803	OSSpinLock lock = 0;
804	OSSpinLockLock(&lock);
805	OSSpinLockUnlock(&lock);
806], [osspin])
807if test "x${osspin}" = "xyes" ; then
808  AC_DEFINE([JEMALLOC_OSSPIN])
809fi
810
811dnl ============================================================================
812dnl Check for allocator-related functions that should be wrapped.
813
814AC_CHECK_FUNC([memalign],
815	      [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN])])
816AC_CHECK_FUNC([valloc],
817	      [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC])])
818
819dnl ============================================================================
820dnl Darwin-related configuration.
821
822if test "x${abi}" = "xmacho" ; then
823  AC_DEFINE([JEMALLOC_IVSALLOC])
824  AC_DEFINE([JEMALLOC_ZONE])
825
826  dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
827  dnl releases.  malloc_zone_t and malloc_introspection_t have new fields in
828  dnl 10.6, which is the only source-level indication of the change.
829  AC_MSG_CHECKING([malloc zone version])
830  AC_TRY_COMPILE([#include <stdlib.h>
831#include <malloc/malloc.h>], [
832	static malloc_zone_t zone;
833	static struct malloc_introspection_t zone_introspect;
834
835	zone.size = NULL;
836	zone.malloc = NULL;
837	zone.calloc = NULL;
838	zone.valloc = NULL;
839	zone.free = NULL;
840	zone.realloc = NULL;
841	zone.destroy = NULL;
842	zone.zone_name = "jemalloc_zone";
843	zone.batch_malloc = NULL;
844	zone.batch_free = NULL;
845	zone.introspect = &zone_introspect;
846	zone.version = 6;
847	zone.memalign = NULL;
848	zone.free_definite_size = NULL;
849
850	zone_introspect.enumerator = NULL;
851	zone_introspect.good_size = NULL;
852	zone_introspect.check = NULL;
853	zone_introspect.print = NULL;
854	zone_introspect.log = NULL;
855	zone_introspect.force_lock = NULL;
856	zone_introspect.force_unlock = NULL;
857	zone_introspect.statistics = NULL;
858	zone_introspect.zone_locked = NULL;
859], [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [6])
860    AC_MSG_RESULT([6])],
861   [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [3])
862   AC_MSG_RESULT([3])])
863fi
864
865dnl ============================================================================
866dnl Check for typedefs, structures, and compiler characteristics.
867AC_HEADER_STDBOOL
868
869dnl Process .in files.
870AC_SUBST([cfghdrs_in])
871AC_SUBST([cfghdrs_out])
872AC_CONFIG_HEADERS([$cfghdrs_tup])
873
874dnl ============================================================================
875dnl Generate outputs.
876AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
877AC_SUBST([cfgoutputs_in])
878AC_SUBST([cfgoutputs_out])
879AC_OUTPUT
880
881dnl ============================================================================
882dnl Print out the results of configuration.
883AC_MSG_RESULT([===============================================================================])
884AC_MSG_RESULT([jemalloc version   : ${jemalloc_version}])
885AC_MSG_RESULT([library revision   : ${rev}])
886AC_MSG_RESULT([])
887AC_MSG_RESULT([CC                 : ${CC}])
888AC_MSG_RESULT([CPPFLAGS           : ${CPPFLAGS}])
889AC_MSG_RESULT([CFLAGS             : ${CFLAGS}])
890AC_MSG_RESULT([LDFLAGS            : ${LDFLAGS}])
891AC_MSG_RESULT([LIBS               : ${LIBS}])
892AC_MSG_RESULT([RPATH_EXTRA        : ${RPATH_EXTRA}])
893AC_MSG_RESULT([])
894AC_MSG_RESULT([XSLTPROC           : ${XSLTPROC}])
895AC_MSG_RESULT([XSLROOT            : ${XSLROOT}])
896AC_MSG_RESULT([])
897AC_MSG_RESULT([PREFIX             : ${PREFIX}])
898AC_MSG_RESULT([BINDIR             : ${BINDIR}])
899AC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
900AC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
901AC_MSG_RESULT([DATADIR            : ${DATADIR}])
902AC_MSG_RESULT([MANDIR             : ${MANDIR}])
903AC_MSG_RESULT([])
904AC_MSG_RESULT([srcroot            : ${srcroot}])
905AC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
906AC_MSG_RESULT([objroot            : ${objroot}])
907AC_MSG_RESULT([abs_objroot        : ${abs_objroot}])
908AC_MSG_RESULT([])
909AC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
910AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
911AC_MSG_RESULT([                   : ${JEMALLOC_PRIVATE_NAMESPACE}])
912AC_MSG_RESULT([install_suffix     : ${install_suffix}])
913AC_MSG_RESULT([autogen            : ${enable_autogen}])
914AC_MSG_RESULT([cc-silence         : ${enable_cc_silence}])
915AC_MSG_RESULT([debug              : ${enable_debug}])
916AC_MSG_RESULT([stats              : ${enable_stats}])
917AC_MSG_RESULT([prof               : ${enable_prof}])
918AC_MSG_RESULT([prof-libunwind     : ${enable_prof_libunwind}])
919AC_MSG_RESULT([prof-libgcc        : ${enable_prof_libgcc}])
920AC_MSG_RESULT([prof-gcc           : ${enable_prof_gcc}])
921AC_MSG_RESULT([tcache             : ${enable_tcache}])
922AC_MSG_RESULT([fill               : ${enable_fill}])
923AC_MSG_RESULT([xmalloc            : ${enable_xmalloc}])
924AC_MSG_RESULT([sysv               : ${enable_sysv}])
925AC_MSG_RESULT([dss                : ${enable_dss}])
926AC_MSG_RESULT([dynamic_page_shift : ${enable_dynamic_page_shift}])
927AC_MSG_RESULT([lazy_lock          : ${enable_lazy_lock}])
928AC_MSG_RESULT([tls                : ${enable_tls}])
929AC_MSG_RESULT([===============================================================================])
930