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