configure.ac revision d073a321091800e71ea56f98701253dc0969d879
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"
370cfghdrs_in="${cfghdrs_in} ${srcroot}include/jemalloc/internal/size_classes.sh"
371
372cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
373cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
374
375cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
376
377dnl Do not silence irrelevant compiler warnings by default, since enabling this
378dnl option incurs a performance penalty.
379AC_ARG_ENABLE([cc-silence],
380  [AS_HELP_STRING([--enable-cc-silence],
381                  [Silence irrelevant compiler warnings])],
382[if test "x$enable_cc_silence" = "xno" ; then
383  enable_cc_silence="0"
384else
385  enable_cc_silence="1"
386fi
387],
388[enable_cc_silence="0"]
389)
390if test "x$enable_cc_silence" = "x1" ; then
391  AC_DEFINE([JEMALLOC_CC_SILENCE])
392fi
393
394dnl Do not compile with debugging by default.
395AC_ARG_ENABLE([debug],
396  [AS_HELP_STRING([--enable-debug], [Build debugging code])],
397[if test "x$enable_debug" = "xno" ; then
398  enable_debug="0"
399else
400  enable_debug="1"
401fi
402],
403[enable_debug="0"]
404)
405if test "x$enable_debug" = "x1" ; then
406  AC_DEFINE([JEMALLOC_DEBUG], [ ])
407  AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
408fi
409AC_SUBST([enable_debug])
410
411dnl Only optimize if not debugging.
412if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
413  dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
414  optimize="no"
415  echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
416  if test "x${optimize}" = "xyes" ; then
417    if test "x$GCC" = "xyes" ; then
418      JE_CFLAGS_APPEND([-O3])
419      JE_CFLAGS_APPEND([-funroll-loops])
420    else
421      JE_CFLAGS_APPEND([-O])
422    fi
423  fi
424fi
425
426dnl Enable statistics calculation by default.
427AC_ARG_ENABLE([stats],
428  [AS_HELP_STRING([--enable-stats], [Enable statistics calculation/reporting])],
429[if test "x$enable_stats" = "xno" ; then
430  enable_stats="0"
431else
432  enable_stats="1"
433fi
434],
435[enable_stats="1"]
436)
437if test "x$enable_stats" = "x1" ; then
438  AC_DEFINE([JEMALLOC_STATS], [ ])
439fi
440AC_SUBST([enable_stats])
441
442dnl Do not enable profiling by default.
443AC_ARG_ENABLE([prof],
444  [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
445[if test "x$enable_prof" = "xno" ; then
446  enable_prof="0"
447else
448  enable_prof="1"
449fi
450],
451[enable_prof="0"]
452)
453if test "x$enable_prof" = "x1" ; then
454  backtrace_method=""
455else
456  backtrace_method="N/A"
457fi
458
459AC_ARG_ENABLE([prof-libunwind],
460  [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
461[if test "x$enable_prof_libunwind" = "xno" ; then
462  enable_prof_libunwind="0"
463else
464  enable_prof_libunwind="1"
465fi
466],
467[enable_prof_libunwind="0"]
468)
469AC_ARG_WITH([static_libunwind],
470  [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
471  [Path to static libunwind library; use rather than dynamically linking])],
472if test "x$with_static_libunwind" = "xno" ; then
473  LUNWIND="-lunwind"
474else
475  if test ! -f "$with_static_libunwind" ; then
476    AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
477  fi
478  LUNWIND="$with_static_libunwind"
479fi,
480  LUNWIND="-lunwind"
481)
482if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
483  AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
484  if test "x$LUNWIND" = "x-lunwind" ; then
485    AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
486                 [enable_prof_libunwind="0"])
487  else
488    LIBS="$LIBS $LUNWIND"
489  fi
490  if test "x${enable_prof_libunwind}" = "x1" ; then
491    backtrace_method="libunwind"
492    AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
493  fi
494fi
495
496AC_ARG_ENABLE([prof-libgcc],
497  [AS_HELP_STRING([--disable-prof-libgcc],
498  [Do not use libgcc for backtracing])],
499[if test "x$enable_prof_libgcc" = "xno" ; then
500  enable_prof_libgcc="0"
501else
502  enable_prof_libgcc="1"
503fi
504],
505[enable_prof_libgcc="1"]
506)
507if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
508     -a "x$GCC" = "xyes" ; then
509  AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
510  AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
511  dnl The following is conservative, in that it only has entries for CPUs on
512  dnl which jemalloc has been tested.
513  AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
514  case "${host_cpu}" in
515    i[[3456]]86)
516      AC_MSG_RESULT([unreliable])
517      enable_prof_libgcc="0";
518      ;;
519    x86_64)
520      AC_MSG_RESULT([reliable])
521      ;;
522    *)
523      AC_MSG_RESULT([unreliable])
524      enable_prof_libgcc="0";
525      ;;
526  esac
527  if test "x${enable_prof_libgcc}" = "x1" ; then
528    backtrace_method="libgcc"
529    AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
530  fi
531else
532  enable_prof_libgcc="0"
533fi
534
535AC_ARG_ENABLE([prof-gcc],
536  [AS_HELP_STRING([--disable-prof-gcc],
537  [Do not use gcc intrinsics for backtracing])],
538[if test "x$enable_prof_gcc" = "xno" ; then
539  enable_prof_gcc="0"
540else
541  enable_prof_gcc="1"
542fi
543],
544[enable_prof_gcc="1"]
545)
546if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
547     -a "x$GCC" = "xyes" ; then
548  backtrace_method="gcc intrinsics"
549  AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
550else
551  enable_prof_gcc="0"
552fi
553
554if test "x$backtrace_method" = "x" ; then
555  backtrace_method="none (disabling profiling)"
556  enable_prof="0"
557fi
558AC_MSG_CHECKING([configured backtracing method])
559AC_MSG_RESULT([$backtrace_method])
560if test "x$enable_prof" = "x1" ; then
561  AC_DEFINE([JEMALLOC_PROF], [ ])
562fi
563AC_SUBST([enable_prof])
564
565dnl Enable thread-specific caching by default.
566AC_ARG_ENABLE([tcache],
567  [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
568[if test "x$enable_tcache" = "xno" ; then
569  enable_tcache="0"
570else
571  enable_tcache="1"
572fi
573],
574[enable_tcache="1"]
575)
576if test "x$enable_tcache" = "x1" ; then
577  AC_DEFINE([JEMALLOC_TCACHE], [ ])
578fi
579AC_SUBST([enable_tcache])
580
581dnl Do not enable allocation from DSS by default.
582AC_ARG_ENABLE([dss],
583  [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
584[if test "x$enable_dss" = "xno" ; then
585  enable_dss="0"
586else
587  enable_dss="1"
588fi
589],
590[enable_dss="0"]
591)
592if test "x$enable_dss" = "x1" ; then
593  AC_DEFINE([JEMALLOC_DSS], [ ])
594fi
595AC_SUBST([enable_dss])
596
597dnl Do not support the junk/zero filling option by default.
598AC_ARG_ENABLE([fill],
599  [AS_HELP_STRING([--enable-fill], [Support junk/zero filling option])],
600[if test "x$enable_fill" = "xno" ; then
601  enable_fill="0"
602else
603  enable_fill="1"
604fi
605],
606[enable_fill="0"]
607)
608if test "x$enable_fill" = "x1" ; then
609  AC_DEFINE([JEMALLOC_FILL], [ ])
610fi
611AC_SUBST([enable_fill])
612
613dnl Do not support the xmalloc option by default.
614AC_ARG_ENABLE([xmalloc],
615  [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
616[if test "x$enable_xmalloc" = "xno" ; then
617  enable_xmalloc="0"
618else
619  enable_xmalloc="1"
620fi
621],
622[enable_xmalloc="0"]
623)
624if test "x$enable_xmalloc" = "x1" ; then
625  AC_DEFINE([JEMALLOC_XMALLOC], [ ])
626fi
627AC_SUBST([enable_xmalloc])
628
629AC_MSG_CHECKING([STATIC_PAGE_SHIFT])
630AC_RUN_IFELSE([AC_LANG_PROGRAM(
631[[#include <stdio.h>
632#include <unistd.h>
633#include <strings.h>
634]], [[
635    long result;
636    FILE *f;
637
638    result = sysconf(_SC_PAGESIZE);
639    if (result == -1) {
640	return 1;
641    }
642    f = fopen("conftest.out", "w");
643    if (f == NULL) {
644	return 1;
645    }
646    fprintf(f, "%u\n", ffs((int)result) - 1);
647    close(f);
648
649    return 0;
650]])],
651              [STATIC_PAGE_SHIFT=`cat conftest.out`]
652              AC_MSG_RESULT([$STATIC_PAGE_SHIFT])
653              AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$STATIC_PAGE_SHIFT]),
654              AC_MSG_RESULT([error]))
655
656dnl ============================================================================
657dnl jemalloc configuration.
658dnl 
659
660dnl Set VERSION if source directory has an embedded git repository.
661if test -d "${srcroot}.git" ; then
662  git describe --long --abbrev=40 > ${srcroot}VERSION
663fi
664jemalloc_version=`cat ${srcroot}VERSION`
665jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
666jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
667jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
668jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
669jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
670AC_SUBST([jemalloc_version])
671AC_SUBST([jemalloc_version_major])
672AC_SUBST([jemalloc_version_minor])
673AC_SUBST([jemalloc_version_bugfix])
674AC_SUBST([jemalloc_version_nrev])
675AC_SUBST([jemalloc_version_gid])
676
677dnl ============================================================================
678dnl Configure pthreads.
679
680AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
681AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
682             [AC_MSG_ERROR([libpthread is missing])])
683
684CPPFLAGS="$CPPFLAGS -D_REENTRANT"
685
686dnl Disable lazy locking by default.
687AC_ARG_ENABLE([lazy_lock],
688  [AS_HELP_STRING([--enable-lazy-lock],
689  [Enable lazy locking (only lock when multi-threaded)])],
690[if test "x$enable_lazy_lock" = "xno" ; then
691  enable_lazy_lock="0"
692else
693  enable_lazy_lock="1"
694fi
695],
696[enable_lazy_lock="0"]
697)
698if test "x$enable_lazy_lock" = "x1" ; then
699  AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
700  AC_CHECK_LIB([dl], [dlopen], [LIBS="$LIBS -ldl"],
701               [AC_MSG_ERROR([libdl is missing])])
702  AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
703fi
704AC_SUBST([enable_lazy_lock])
705
706AC_ARG_ENABLE([tls],
707  [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
708if test "x$enable_tls" = "xno" ; then
709  enable_tls="0"
710else
711  enable_tls="1"
712fi
713,
714enable_tls="1"
715)
716if test "x${enable_tls}" = "x1" ; then
717AC_MSG_CHECKING([for TLS])
718AC_RUN_IFELSE([AC_LANG_PROGRAM(
719[[
720    __thread int x;
721]], [[
722    x = 42;
723
724    return 0;
725]])],
726              AC_MSG_RESULT([yes]),
727              AC_MSG_RESULT([no])
728              enable_tls="0")
729fi
730AC_SUBST([enable_tls])
731if test "x${enable_tls}" = "x0" ; then
732  AC_DEFINE_UNQUOTED([NO_TLS], [ ])
733fi
734
735dnl ============================================================================
736dnl Check for ffsl(3), and fail if not found.  This function exists on all
737dnl platforms that jemalloc currently has a chance of functioning on without
738dnl modification.
739
740AC_CHECK_FUNC([ffsl], [],
741	      [AC_MSG_ERROR([Cannot build without ffsl(3)])])
742
743dnl ============================================================================
744dnl Check for atomic(3) operations as provided on Darwin.
745
746JE_COMPILABLE([Darwin OSAtomic*()], [
747#include <libkern/OSAtomic.h>
748#include <inttypes.h>
749], [
750	{
751		int32_t x32 = 0;
752		volatile int32_t *x32p = &x32;
753		OSAtomicAdd32(1, x32p);
754	}
755	{
756		int64_t x64 = 0;
757		volatile int64_t *x64p = &x64;
758		OSAtomicAdd64(1, x64p);
759	}
760], [osatomic])
761if test "x${osatomic}" = "xyes" ; then
762  AC_DEFINE([JEMALLOC_OSATOMIC])
763fi
764
765dnl ============================================================================
766dnl Check for spinlock(3) operations as provided on Darwin.
767
768JE_COMPILABLE([Darwin OSSpin*()], [
769#include <libkern/OSAtomic.h>
770#include <inttypes.h>
771], [
772	OSSpinLock lock = 0;
773	OSSpinLockLock(&lock);
774	OSSpinLockUnlock(&lock);
775], [osspin])
776if test "x${osspin}" = "xyes" ; then
777  AC_DEFINE([JEMALLOC_OSSPIN])
778fi
779
780dnl ============================================================================
781dnl Check for allocator-related functions that should be wrapped.
782
783AC_CHECK_FUNC([memalign],
784	      [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN])])
785AC_CHECK_FUNC([valloc],
786	      [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC])])
787
788dnl ============================================================================
789dnl Darwin-related configuration.
790
791if test "x${abi}" = "xmacho" ; then
792  AC_DEFINE([JEMALLOC_IVSALLOC])
793  AC_DEFINE([JEMALLOC_ZONE])
794
795  dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
796  dnl releases.  malloc_zone_t and malloc_introspection_t have new fields in
797  dnl 10.6, which is the only source-level indication of the change.
798  AC_MSG_CHECKING([malloc zone version])
799  AC_TRY_COMPILE([#include <stdlib.h>
800#include <malloc/malloc.h>], [
801	static malloc_zone_t zone;
802	static struct malloc_introspection_t zone_introspect;
803
804	zone.size = NULL;
805	zone.malloc = NULL;
806	zone.calloc = NULL;
807	zone.valloc = NULL;
808	zone.free = NULL;
809	zone.realloc = NULL;
810	zone.destroy = NULL;
811	zone.zone_name = "jemalloc_zone";
812	zone.batch_malloc = NULL;
813	zone.batch_free = NULL;
814	zone.introspect = &zone_introspect;
815	zone.version = 6;
816	zone.memalign = NULL;
817	zone.free_definite_size = NULL;
818
819	zone_introspect.enumerator = NULL;
820	zone_introspect.good_size = NULL;
821	zone_introspect.check = NULL;
822	zone_introspect.print = NULL;
823	zone_introspect.log = NULL;
824	zone_introspect.force_lock = NULL;
825	zone_introspect.force_unlock = NULL;
826	zone_introspect.statistics = NULL;
827	zone_introspect.zone_locked = NULL;
828], [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [6])
829    AC_MSG_RESULT([6])],
830   [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [3])
831   AC_MSG_RESULT([3])])
832fi
833
834dnl ============================================================================
835dnl Check for typedefs, structures, and compiler characteristics.
836AC_HEADER_STDBOOL
837
838AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
839  mkdir -p "include/jemalloc/internal"
840  "${srcdir}/include/jemalloc/internal/size_classes.sh" > "${objroot}include/jemalloc/internal/size_classes.h"
841])
842
843dnl Process .in files.
844AC_SUBST([cfghdrs_in])
845AC_SUBST([cfghdrs_out])
846AC_CONFIG_HEADERS([$cfghdrs_tup])
847
848dnl ============================================================================
849dnl Generate outputs.
850AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc.sh])
851AC_SUBST([cfgoutputs_in])
852AC_SUBST([cfgoutputs_out])
853AC_OUTPUT
854
855dnl ============================================================================
856dnl Print out the results of configuration.
857AC_MSG_RESULT([===============================================================================])
858AC_MSG_RESULT([jemalloc version   : ${jemalloc_version}])
859AC_MSG_RESULT([library revision   : ${rev}])
860AC_MSG_RESULT([])
861AC_MSG_RESULT([CC                 : ${CC}])
862AC_MSG_RESULT([CPPFLAGS           : ${CPPFLAGS}])
863AC_MSG_RESULT([CFLAGS             : ${CFLAGS}])
864AC_MSG_RESULT([LDFLAGS            : ${LDFLAGS}])
865AC_MSG_RESULT([LIBS               : ${LIBS}])
866AC_MSG_RESULT([RPATH_EXTRA        : ${RPATH_EXTRA}])
867AC_MSG_RESULT([])
868AC_MSG_RESULT([XSLTPROC           : ${XSLTPROC}])
869AC_MSG_RESULT([XSLROOT            : ${XSLROOT}])
870AC_MSG_RESULT([])
871AC_MSG_RESULT([PREFIX             : ${PREFIX}])
872AC_MSG_RESULT([BINDIR             : ${BINDIR}])
873AC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
874AC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
875AC_MSG_RESULT([DATADIR            : ${DATADIR}])
876AC_MSG_RESULT([MANDIR             : ${MANDIR}])
877AC_MSG_RESULT([])
878AC_MSG_RESULT([srcroot            : ${srcroot}])
879AC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
880AC_MSG_RESULT([objroot            : ${objroot}])
881AC_MSG_RESULT([abs_objroot        : ${abs_objroot}])
882AC_MSG_RESULT([])
883AC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
884AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
885AC_MSG_RESULT([                   : ${JEMALLOC_PRIVATE_NAMESPACE}])
886AC_MSG_RESULT([install_suffix     : ${install_suffix}])
887AC_MSG_RESULT([autogen            : ${enable_autogen}])
888AC_MSG_RESULT([cc-silence         : ${enable_cc_silence}])
889AC_MSG_RESULT([debug              : ${enable_debug}])
890AC_MSG_RESULT([stats              : ${enable_stats}])
891AC_MSG_RESULT([prof               : ${enable_prof}])
892AC_MSG_RESULT([prof-libunwind     : ${enable_prof_libunwind}])
893AC_MSG_RESULT([prof-libgcc        : ${enable_prof_libgcc}])
894AC_MSG_RESULT([prof-gcc           : ${enable_prof_gcc}])
895AC_MSG_RESULT([tcache             : ${enable_tcache}])
896AC_MSG_RESULT([fill               : ${enable_fill}])
897AC_MSG_RESULT([xmalloc            : ${enable_xmalloc}])
898AC_MSG_RESULT([dss                : ${enable_dss}])
899AC_MSG_RESULT([lazy_lock          : ${enable_lazy_lock}])
900AC_MSG_RESULT([tls                : ${enable_tls}])
901AC_MSG_RESULT([===============================================================================])
902