blob: e317d0a27798f17aa47e62962c8db025227e1ed4 [file] [log] [blame]
Jason Evansb7924f52009-06-23 19:01:18 -07001dnl Process this file with autoconf to produce a configure script.
2AC_INIT([Makefile.in])
3
Jason Evansf3340ca2009-06-30 16:17:05 -07004dnl ============================================================================
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])
Jason Evans9f949f92011-03-22 20:44:40 -070032AC_RUN_IFELSE([AC_LANG_PROGRAM(
Jason Evansf3340ca2009-06-30 16:17:05 -070033[$2], [$3])],
34 AC_MSG_RESULT([yes])
35 [$4="yes"],
36 AC_MSG_RESULT([no])
37 [$4="no"]
38)
39])
40
41dnl ============================================================================
42
Jason Evansb7924f52009-06-23 19:01:18 -070043srcroot=$srcdir
44if test "x${srcroot}" = "x." ; then
45 srcroot=""
46else
47 srcroot="${srcroot}/"
48fi
49AC_SUBST([srcroot])
50abs_srcroot="`cd \"${srcdir}\"; pwd`/"
51AC_SUBST([abs_srcroot])
52
53objroot=""
54AC_SUBST([objroot])
55abs_objroot="`pwd`/"
56AC_SUBST([abs_objroot])
57
58dnl Munge install path variables.
59if test "x$prefix" = "xNONE" ; then
60 prefix="/usr/local"
61fi
62if test "x$exec_prefix" = "xNONE" ; then
63 exec_prefix=$prefix
64fi
65PREFIX=$prefix
66AC_SUBST([PREFIX])
67BINDIR=`eval echo $bindir`
68BINDIR=`eval echo $BINDIR`
69AC_SUBST([BINDIR])
70INCLUDEDIR=`eval echo $includedir`
71INCLUDEDIR=`eval echo $INCLUDEDIR`
72AC_SUBST([INCLUDEDIR])
73LIBDIR=`eval echo $libdir`
74LIBDIR=`eval echo $LIBDIR`
75AC_SUBST([LIBDIR])
76DATADIR=`eval echo $datadir`
77DATADIR=`eval echo $DATADIR`
78AC_SUBST([DATADIR])
79MANDIR=`eval echo $mandir`
80MANDIR=`eval echo $MANDIR`
81AC_SUBST([MANDIR])
82
Jason Evansaee7fd22010-11-24 22:00:02 -080083dnl Support for building documentation.
84AC_PATH_PROG([XSLTPROC], [xsltproc], , [$PATH])
85AC_ARG_WITH([xslroot],
86 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])],
87if test "x$with_xslroot" = "xno" ; then
88 XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
89else
90 XSLROOT="${with_xslroot}"
91fi,
92 XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
93)
94AC_SUBST([XSLROOT])
95
Jason Evansf3340ca2009-06-30 16:17:05 -070096dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
97dnl just prevent autoconf from molesting CFLAGS.
Jason Evansb7924f52009-06-23 19:01:18 -070098CFLAGS=$CFLAGS
99AC_PROG_CC
100if test "x$CFLAGS" = "x" ; then
101 no_CFLAGS="yes"
Jason Evanscfeccd32010-03-03 15:48:20 -0800102 if test "x$GCC" = "xyes" ; then
103 JE_CFLAGS_APPEND([-std=gnu99])
104 JE_CFLAGS_APPEND([-Wall])
105 JE_CFLAGS_APPEND([-pipe])
106 JE_CFLAGS_APPEND([-g3])
107 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700108fi
109dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
110if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -0700111 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -0700112fi
113AC_PROG_CPP
114
Jason Evansb7924f52009-06-23 19:01:18 -0700115AC_CHECK_SIZEOF([void *])
116if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800117 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700118elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800119 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700120else
121 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
122fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800123AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
124
125AC_CHECK_SIZEOF([int])
126if test "x${ac_cv_sizeof_int}" = "x8" ; then
127 LG_SIZEOF_INT=3
128elif test "x${ac_cv_sizeof_int}" = "x4" ; then
129 LG_SIZEOF_INT=2
130else
131 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
132fi
133AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700134
Jason Evans84c8eef2011-03-16 10:30:13 -0700135AC_CHECK_SIZEOF([long])
136if test "x${ac_cv_sizeof_long}" = "x8" ; then
137 LG_SIZEOF_LONG=3
138elif test "x${ac_cv_sizeof_long}" = "x4" ; then
139 LG_SIZEOF_LONG=2
140else
141 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
142fi
143AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
144
Jason Evansb7924f52009-06-23 19:01:18 -0700145AC_CANONICAL_HOST
146dnl CPU-specific settings.
147CPU_SPINWAIT=""
148case "${host_cpu}" in
149 i[[345]]86)
150 ;;
151 i686)
Jason Evansf3340ca2009-06-30 16:17:05 -0700152 JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
153 [asm])
154 if test "x${asm}" = "xyes" ; then
155 CPU_SPINWAIT='__asm__ volatile("pause")'
156 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700157 ;;
158 x86_64)
Jason Evansf3340ca2009-06-30 16:17:05 -0700159 JE_COMPILABLE([__asm__ syntax], [],
160 [[__asm__ volatile("pause"); return 0;]], [asm])
161 if test "x${asm}" = "xyes" ; then
162 CPU_SPINWAIT='__asm__ volatile("pause")'
163 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700164 ;;
165 *)
166 ;;
167esac
168AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
169
170dnl Platform-specific settings. abi and RPATH can probably be determined
171dnl programmatically, but doing so is error-prone, which makes it generally
172dnl not worth the trouble.
173dnl
174dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
175dnl definitions need to be seen before any headers are included, which is a pain
176dnl to make happen otherwise.
177case "${host}" in
178 *-*-darwin*)
179 CFLAGS="$CFLAGS -fno-common -no-cpp-precomp"
180 abi="macho"
Jason Evansce930552010-10-24 13:03:07 -0700181 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
Jason Evansb7924f52009-06-23 19:01:18 -0700182 RPATH=""
183 ;;
184 *-*-freebsd*)
185 CFLAGS="$CFLAGS"
186 abi="elf"
Jason Evans2dbecf12010-09-05 10:35:13 -0700187 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
Jason Evansb7924f52009-06-23 19:01:18 -0700188 RPATH="-Wl,-rpath,"
189 ;;
190 *-*-linux*)
191 CFLAGS="$CFLAGS"
192 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
193 abi="elf"
Jason Evans2dbecf12010-09-05 10:35:13 -0700194 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED])
Jason Evansb7924f52009-06-23 19:01:18 -0700195 RPATH="-Wl,-rpath,"
196 ;;
197 *-*-netbsd*)
198 AC_MSG_CHECKING([ABI])
199 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
200[[#ifdef __ELF__
201/* ELF */
202#else
203#error aout
204#endif
205]])],
206 [CFLAGS="$CFLAGS"; abi="elf"],
207 [abi="aout"])
208 AC_MSG_RESULT([$abi])
Jason Evans2dbecf12010-09-05 10:35:13 -0700209 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
Jason Evansb7924f52009-06-23 19:01:18 -0700210 RPATH="-Wl,-rpath,"
211 ;;
212 *-*-solaris2*)
213 CFLAGS="$CFLAGS"
214 abi="elf"
215 RPATH="-Wl,-R,"
216 dnl Solaris needs this for sigwait().
217 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
218 LIBS="$LIBS -lposix4 -lsocket -lnsl"
219 ;;
220 *)
221 AC_MSG_RESULT([Unsupported operating system: ${host}])
222 abi="elf"
223 RPATH="-Wl,-rpath,"
224 ;;
225esac
226AC_SUBST([abi])
227AC_SUBST([RPATH])
228
Jason Evansfa5d2452011-03-15 10:25:59 -0700229JE_COMPILABLE([__attribute__ syntax],
230 [static __attribute__((unused)) void foo(void){}],
231 [],
232 [attribute])
233if test "x${attribute}" = "xyes" ; then
234 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
235 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
236 JE_CFLAGS_APPEND([-fvisibility=hidden])
237 fi
238fi
239
Jason Evanscfdc8cf2010-11-30 16:50:58 -0800240JE_COMPILABLE([mremap(...MREMAP_FIXED...)], [
241#define _GNU_SOURCE
242#include <sys/mman.h>
243], [
244void *p = mremap((void *)0, 0, 0, MREMAP_MAYMOVE|MREMAP_FIXED, (void *)0);
245], [mremap_fixed])
246if test "x${mremap_fixed}" = "xyes" ; then
247 AC_DEFINE([JEMALLOC_MREMAP_FIXED])
248fi
249
Jason Evansb7924f52009-06-23 19:01:18 -0700250dnl Support optional additions to rpath.
251AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800252 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700253if test "x$with_rpath" = "xno" ; then
254 RPATH_EXTRA=
255else
256 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
257fi,
258 RPATH_EXTRA=
259)
260AC_SUBST([RPATH_EXTRA])
261
262dnl Disable rules that do automatic regeneration of configure output by default.
263AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800264 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700265if test "x$enable_autogen" = "xno" ; then
266 enable_autogen="0"
267else
268 enable_autogen="1"
269fi
270,
271enable_autogen="0"
272)
273AC_SUBST([enable_autogen])
274
275AC_PROG_INSTALL
276AC_PROG_RANLIB
277AC_PATH_PROG([AR], [ar], , [$PATH])
278AC_PATH_PROG([LD], [ld], , [$PATH])
279AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
280
Jason Evans90895cf2009-12-29 00:09:15 -0800281dnl Do not prefix public APIs by default.
282AC_ARG_WITH([jemalloc_prefix],
283 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800284 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700285 [if test "x$abi" != "xmacho" ; then
286 JEMALLOC_PREFIX=""
287else
288 JEMALLOC_PREFIX="je_"
289fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800290)
291if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700292 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
293 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
294 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evansb0fd5012010-01-17 01:49:20 -0800295 jemalloc_prefix="$JEMALLOC_PREFIX"
Jason Evanse7339702010-10-23 18:37:06 -0700296 jemalloc_cprefix="$JEMALLOC_CPREFIX"
Jason Evans90895cf2009-12-29 00:09:15 -0800297 AC_SUBST([jemalloc_prefix])
Jason Evanse7339702010-10-23 18:37:06 -0700298 AC_SUBST([jemalloc_cprefix])
Jason Evanse476f8a2010-01-16 09:53:50 -0800299 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])
Jason Evans90895cf2009-12-29 00:09:15 -0800300fi
301
Jason Evansb0fd5012010-01-17 01:49:20 -0800302dnl Do not add suffix to installed files by default.
303AC_ARG_WITH([install_suffix],
304 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
305 [INSTALL_SUFFIX="$with_install_suffix"],
306 [INSTALL_SUFFIX=]
307)
308install_suffix="$INSTALL_SUFFIX"
309AC_SUBST([install_suffix])
310
Jason Evansaee7fd22010-11-24 22:00:02 -0800311cfgoutputs_in="${srcroot}Makefile.in"
312cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/html.xsl.in"
313cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/manpages.xsl.in"
314cfgoutputs_in="${cfgoutputs_in} ${srcroot}doc/jemalloc.xml.in"
Jason Evans0656ec02010-04-07 23:37:35 -0700315cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
316cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700317cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800318
Jason Evansaee7fd22010-11-24 22:00:02 -0800319cfgoutputs_out="Makefile"
320cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
321cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
322cfgoutputs_out="${cfgoutputs_out} doc/jemalloc${install_suffix}.xml"
Jason Evans376b1522010-02-11 14:45:59 -0800323cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
324cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700325cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800326
Jason Evansaee7fd22010-11-24 22:00:02 -0800327cfgoutputs_tup="Makefile"
328cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
329cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
330cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc${install_suffix}.xml:doc/jemalloc.xml.in"
Jason Evans376b1522010-02-11 14:45:59 -0800331cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
332cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700333cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800334
Jason Evans0656ec02010-04-07 23:37:35 -0700335cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800336
Jason Evans376b1522010-02-11 14:45:59 -0800337cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800338
Jason Evans376b1522010-02-11 14:45:59 -0800339cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800340
Jason Evans355b4382010-09-20 19:20:48 -0700341dnl Do not silence irrelevant compiler warnings by default, since enabling this
342dnl option incurs a performance penalty.
343AC_ARG_ENABLE([cc-silence],
344 [AS_HELP_STRING([--enable-cc-silence],
345 [Silence irrelevant compiler warnings])],
346[if test "x$enable_cc_silence" = "xno" ; then
347 enable_cc_silence="0"
348else
349 enable_cc_silence="1"
350fi
351],
352[enable_cc_silence="0"]
353)
354if test "x$enable_cc_silence" = "x1" ; then
355 AC_DEFINE([JEMALLOC_CC_SILENCE])
356fi
357
Jason Evansb7924f52009-06-23 19:01:18 -0700358dnl Do not compile with debugging by default.
359AC_ARG_ENABLE([debug],
360 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
361[if test "x$enable_debug" = "xno" ; then
362 enable_debug="0"
363else
364 enable_debug="1"
365fi
366],
367[enable_debug="0"]
368)
369if test "x$enable_debug" = "x1" ; then
370 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700371 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700372fi
373AC_SUBST([enable_debug])
374
375dnl Only optimize if not debugging.
376if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
377 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700378 optimize="no"
379 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
380 if test "x${optimize}" = "xyes" ; then
381 if test "x$GCC" = "xyes" ; then
382 JE_CFLAGS_APPEND([-O3])
383 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700384 else
385 JE_CFLAGS_APPEND([-O])
386 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700387 fi
388fi
389
390dnl Do not enable statistics calculation by default.
391AC_ARG_ENABLE([stats],
392 [AS_HELP_STRING([--enable-stats], [Enable statistics calculation/reporting])],
393[if test "x$enable_stats" = "xno" ; then
394 enable_stats="0"
395else
396 enable_stats="1"
397fi
398],
399[enable_stats="0"]
400)
401if test "x$enable_stats" = "x1" ; then
402 AC_DEFINE([JEMALLOC_STATS], [ ])
403fi
404AC_SUBST([enable_stats])
405
Jason Evans6109fe02010-02-10 10:37:56 -0800406dnl Do not enable profiling by default.
407AC_ARG_ENABLE([prof],
408 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
409[if test "x$enable_prof" = "xno" ; then
410 enable_prof="0"
411else
412 enable_prof="1"
413fi
414],
415[enable_prof="0"]
416)
Jason Evans77f350b2011-03-15 22:23:12 -0700417if test "x$enable_prof" = "x1" ; then
418 backtrace_method=""
Jason Evansb27805b2010-02-10 18:15:53 -0800419else
Jason Evans77f350b2011-03-15 22:23:12 -0700420 backtrace_method="N/A"
Jason Evansb27805b2010-02-10 18:15:53 -0800421fi
Jason Evans77f350b2011-03-15 22:23:12 -0700422
Jason Evans6109fe02010-02-10 10:37:56 -0800423AC_ARG_ENABLE([prof-libunwind],
424 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
425[if test "x$enable_prof_libunwind" = "xno" ; then
426 enable_prof_libunwind="0"
427else
428 enable_prof_libunwind="1"
429fi
430],
431[enable_prof_libunwind="0"]
432)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800433AC_ARG_WITH([static_libunwind],
434 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
435 [Path to static libunwind library; use rather than dynamically linking])],
436if test "x$with_static_libunwind" = "xno" ; then
437 LUNWIND="-lunwind"
438else
439 if test ! -f "$with_static_libunwind" ; then
440 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
441 fi
442 LUNWIND="$with_static_libunwind"
443fi,
444 LUNWIND="-lunwind"
445)
Jason Evans77f350b2011-03-15 22:23:12 -0700446if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
447 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
448 if test "x$LUNWIND" = "x-lunwind" ; then
449 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
450 [enable_prof_libunwind="0"])
451 else
452 LIBS="$LIBS $LUNWIND"
453 fi
454 if test "x${enable_prof_libunwind}" = "x1" ; then
455 backtrace_method="libunwind"
456 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
457 fi
458fi
459
460AC_ARG_ENABLE([prof-libgcc],
461 [AS_HELP_STRING([--disable-prof-libgcc],
462 [Do not use libgcc for backtracing])],
463[if test "x$enable_prof_libgcc" = "xno" ; then
464 enable_prof_libgcc="0"
465else
466 enable_prof_libgcc="1"
467fi
468],
469[enable_prof_libgcc="1"]
470)
471if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
472 -a "x$GCC" = "xyes" ; then
473 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
474 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
475 dnl The following is conservative, in that it only has entries for CPUs on
476 dnl which jemalloc has been tested.
477 AC_MSG_CHECKING([libgcc-based backtracing reliability on ${host_cpu}])
478 case "${host_cpu}" in
479 i[[3456]]86)
480 AC_MSG_RESULT([unreliable])
481 enable_prof_libgcc="0";
482 ;;
483 x86_64)
484 AC_MSG_RESULT([reliable])
485 ;;
486 *)
487 AC_MSG_RESULT([unreliable])
488 enable_prof_libgcc="0";
489 ;;
490 esac
491 if test "x${enable_prof_libgcc}" = "x1" ; then
492 backtrace_method="libgcc"
493 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
494 fi
495else
496 enable_prof_libgcc="0"
497fi
498
499AC_ARG_ENABLE([prof-gcc],
500 [AS_HELP_STRING([--disable-prof-gcc],
501 [Do not use gcc intrinsics for backtracing])],
502[if test "x$enable_prof_gcc" = "xno" ; then
503 enable_prof_gcc="0"
504else
505 enable_prof_gcc="1"
506fi
507],
508[enable_prof_gcc="1"]
509)
510if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
511 -a "x$GCC" = "xyes" ; then
512 backtrace_method="gcc intrinsics"
513 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
514else
515 enable_prof_gcc="0"
516fi
517
518if test "x$backtrace_method" = "x" ; then
519 backtrace_method="none (disabling profiling)"
520 enable_prof="0"
521fi
522AC_MSG_CHECKING([configured backtracing method])
523AC_MSG_RESULT([$backtrace_method])
Jason Evans2dbecf12010-09-05 10:35:13 -0700524if test "x$enable_prof" = "x1" ; then
525 LIBS="$LIBS -lm"
526 AC_DEFINE([JEMALLOC_PROF], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700527fi
528AC_SUBST([enable_prof])
Jason Evans2dbecf12010-09-05 10:35:13 -0700529
Jason Evansb7924f52009-06-23 19:01:18 -0700530dnl Enable tiny allocations by default.
531AC_ARG_ENABLE([tiny],
532 [AS_HELP_STRING([--disable-tiny], [Disable tiny (sub-quantum) allocations])],
533[if test "x$enable_tiny" = "xno" ; then
534 enable_tiny="0"
535else
536 enable_tiny="1"
537fi
538],
539[enable_tiny="1"]
540)
541if test "x$enable_tiny" = "x1" ; then
542 AC_DEFINE([JEMALLOC_TINY], [ ])
543fi
544AC_SUBST([enable_tiny])
545
Jason Evans84cbbcb2009-12-29 00:09:15 -0800546dnl Enable thread-specific caching by default.
547AC_ARG_ENABLE([tcache],
548 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
549[if test "x$enable_tcache" = "xno" ; then
550 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700551else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800552 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700553fi
554],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800555[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700556)
Jason Evans2dbecf12010-09-05 10:35:13 -0700557if test "x$enable_tcache" = "x1" ; then
558 AC_DEFINE([JEMALLOC_TCACHE], [ ])
559fi
560AC_SUBST([enable_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700561
Jason Evans4201af02010-01-24 02:53:40 -0800562dnl Do not enable mmap()ped swap files by default.
563AC_ARG_ENABLE([swap],
564 [AS_HELP_STRING([--enable-swap], [Enable mmap()ped swap files])],
565[if test "x$enable_swap" = "xno" ; then
566 enable_swap="0"
567else
568 enable_swap="1"
569fi
570],
571[enable_swap="0"]
572)
573if test "x$enable_swap" = "x1" ; then
574 AC_DEFINE([JEMALLOC_SWAP], [ ])
575fi
576AC_SUBST([enable_swap])
Jason Evans4201af02010-01-24 02:53:40 -0800577
Jason Evansb7924f52009-06-23 19:01:18 -0700578dnl Do not enable allocation from DSS by default.
579AC_ARG_ENABLE([dss],
580 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
581[if test "x$enable_dss" = "xno" ; then
582 enable_dss="0"
583else
584 enable_dss="1"
585fi
586],
587[enable_dss="0"]
588)
589if test "x$enable_dss" = "x1" ; then
590 AC_DEFINE([JEMALLOC_DSS], [ ])
591fi
592AC_SUBST([enable_dss])
593
594dnl Do not support the junk/zero filling option by default.
595AC_ARG_ENABLE([fill],
596 [AS_HELP_STRING([--enable-fill], [Support junk/zero filling option])],
597[if test "x$enable_fill" = "xno" ; then
598 enable_fill="0"
599else
600 enable_fill="1"
601fi
602],
603[enable_fill="0"]
604)
605if test "x$enable_fill" = "x1" ; then
606 AC_DEFINE([JEMALLOC_FILL], [ ])
607fi
608AC_SUBST([enable_fill])
609
610dnl Do not support the xmalloc option by default.
611AC_ARG_ENABLE([xmalloc],
612 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
613[if test "x$enable_xmalloc" = "xno" ; then
614 enable_xmalloc="0"
615else
616 enable_xmalloc="1"
617fi
618],
619[enable_xmalloc="0"]
620)
621if test "x$enable_xmalloc" = "x1" ; then
622 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
623fi
624AC_SUBST([enable_xmalloc])
625
626dnl Do not support the SYSV option by default.
627AC_ARG_ENABLE([sysv],
628 [AS_HELP_STRING([--enable-sysv], [Support SYSV semantics option])],
629[if test "x$enable_sysv" = "xno" ; then
630 enable_sysv="0"
631else
632 enable_sysv="1"
633fi
634],
635[enable_sysv="0"]
636)
637if test "x$enable_sysv" = "x1" ; then
638 AC_DEFINE([JEMALLOC_SYSV], [ ])
639fi
640AC_SUBST([enable_sysv])
641
642dnl Do not determine page shift at run time by default.
643AC_ARG_ENABLE([dynamic_page_shift],
644 [AS_HELP_STRING([--enable-dynamic-page-shift],
645 [Determine page size at run time (don't trust configure result)])],
646[if test "x$enable_dynamic_page_shift" = "xno" ; then
647 enable_dynamic_page_shift="0"
648else
649 enable_dynamic_page_shift="1"
650fi
651],
652[enable_dynamic_page_shift="0"]
653)
654if test "x$enable_dynamic_page_shift" = "x1" ; then
655 AC_DEFINE([DYNAMIC_PAGE_SHIFT], [ ])
656fi
657AC_SUBST([enable_dynamic_page_shift])
658
659AC_MSG_CHECKING([STATIC_PAGE_SHIFT])
660AC_RUN_IFELSE([AC_LANG_PROGRAM(
661[[#include <stdio.h>
662#include <unistd.h>
663#include <strings.h>
664]], [[
665 long result;
666 FILE *f;
667
668 result = sysconf(_SC_PAGESIZE);
669 if (result == -1) {
670 return 1;
671 }
672 f = fopen("conftest.out", "w");
673 if (f == NULL) {
674 return 1;
675 }
676 fprintf(f, "%u\n", ffs((int)result) - 1);
677 close(f);
678
679 return 0;
680]])],
681 [STATIC_PAGE_SHIFT=`cat conftest.out`]
682 AC_MSG_RESULT([$STATIC_PAGE_SHIFT])
683 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$STATIC_PAGE_SHIFT]),
684 AC_MSG_RESULT([error]))
685
686dnl ============================================================================
687dnl jemalloc configuration.
688dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800689
690dnl Set VERSION if source directory has an embedded git repository.
Jason Evans955851f2011-03-31 22:38:51 -0700691if test -d "${srcroot}.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700692 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800693fi
Jason Evansb7924f52009-06-23 19:01:18 -0700694jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800695jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
696jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
697jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
698jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
699jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700700AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800701AC_SUBST([jemalloc_version_major])
702AC_SUBST([jemalloc_version_minor])
703AC_SUBST([jemalloc_version_bugfix])
704AC_SUBST([jemalloc_version_nrev])
705AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700706
707dnl ============================================================================
708dnl Configure pthreads.
709
710AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
711AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
712 [AC_MSG_ERROR([libpthread is missing])])
713
714CPPFLAGS="$CPPFLAGS -D_REENTRANT"
715
Jason Evanscc00a152009-06-25 18:06:48 -0700716dnl Enable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700717AC_ARG_ENABLE([lazy_lock],
Jason Evansa1624022009-11-09 14:58:12 -0800718 [AS_HELP_STRING([--disable-lazy-lock],
Jason Evanscc00a152009-06-25 18:06:48 -0700719 [Disable lazy locking (always lock, even when single-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700720[if test "x$enable_lazy_lock" = "xno" ; then
721 enable_lazy_lock="0"
722else
723 enable_lazy_lock="1"
724fi
725],
Jason Evanscc00a152009-06-25 18:06:48 -0700726[enable_lazy_lock="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700727)
728if test "x$enable_lazy_lock" = "x1" ; then
729 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
730 AC_CHECK_LIB([dl], [dlopen], [LIBS="$LIBS -ldl"],
731 [AC_MSG_ERROR([libdl is missing])])
732 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
733fi
734AC_SUBST([enable_lazy_lock])
735
Jason Evans78d815c2010-01-17 14:06:20 -0800736AC_ARG_ENABLE([tls],
737 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
738if test "x$enable_tls" = "xno" ; then
739 enable_tls="0"
740else
741 enable_tls="1"
742fi
743,
744enable_tls="1"
745)
746if test "x${enable_tls}" = "x1" ; then
747AC_MSG_CHECKING([for TLS])
748AC_RUN_IFELSE([AC_LANG_PROGRAM(
749[[
750 __thread int x;
751]], [[
752 x = 42;
753
754 return 0;
755]])],
756 AC_MSG_RESULT([yes]),
757 AC_MSG_RESULT([no])
758 enable_tls="0")
759fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700760AC_SUBST([enable_tls])
Jason Evans78d815c2010-01-17 14:06:20 -0800761if test "x${enable_tls}" = "x0" ; then
762 AC_DEFINE_UNQUOTED([NO_TLS], [ ])
763fi
764
Jason Evans2dbecf12010-09-05 10:35:13 -0700765dnl ============================================================================
Jason Evans84c8eef2011-03-16 10:30:13 -0700766dnl Check for ffsl(3), and fail if not found. This function exists on all
767dnl platforms that jemalloc currently has a chance of functioning on without
768dnl modification.
769
770AC_CHECK_FUNC([ffsl], [],
771 [AC_MSG_ERROR([Cannot build without ffsl(3)])])
772
773dnl ============================================================================
Jason Evans763baa62011-03-18 19:10:31 -0700774dnl Check for atomic(3) operations as provided on Darwin.
775
776JE_COMPILABLE([Darwin OSAtomic*()], [
777#include <libkern/OSAtomic.h>
778#include <inttypes.h>
779], [
780 {
781 int32_t x32 = 0;
782 volatile int32_t *x32p = &x32;
783 OSAtomicAdd32(1, x32p);
784 }
785 {
786 int64_t x64 = 0;
787 volatile int64_t *x64p = &x64;
788 OSAtomicAdd64(1, x64p);
789 }
790], [osatomic])
791if test "x${osatomic}" = "xyes" ; then
792 AC_DEFINE([JEMALLOC_OSATOMIC])
793fi
794
795dnl ============================================================================
Jason Evans893a0ed2011-03-18 19:30:18 -0700796dnl Check for spinlock(3) operations as provided on Darwin.
797
798JE_COMPILABLE([Darwin OSSpin*()], [
799#include <libkern/OSAtomic.h>
800#include <inttypes.h>
801], [
802 OSSpinLock lock = 0;
803 OSSpinLockLock(&lock);
804 OSSpinLockUnlock(&lock);
805], [osspin])
806if test "x${osspin}" = "xyes" ; then
807 AC_DEFINE([JEMALLOC_OSSPIN])
808fi
809
810dnl ============================================================================
Jason Evans6a0d2912010-09-20 16:44:23 -0700811dnl Check for allocator-related functions that should be wrapped.
812
813AC_CHECK_FUNC([memalign],
814 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN])])
815AC_CHECK_FUNC([valloc],
816 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC])])
817
818dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -0700819dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -0800820
Jason Evans2dbecf12010-09-05 10:35:13 -0700821if test "x${abi}" = "xmacho" ; then
822 AC_DEFINE([JEMALLOC_IVSALLOC])
823 AC_DEFINE([JEMALLOC_ZONE])
Jason Evans6109fe02010-02-10 10:37:56 -0800824
Jason Evans2dbecf12010-09-05 10:35:13 -0700825 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
826 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
827 dnl 10.6, which is the only source-level indication of the change.
828 AC_MSG_CHECKING([malloc zone version])
829 AC_TRY_COMPILE([#include <stdlib.h>
830#include <malloc/malloc.h>], [
831 static malloc_zone_t zone;
832 static struct malloc_introspection_t zone_introspect;
833
834 zone.size = NULL;
835 zone.malloc = NULL;
836 zone.calloc = NULL;
837 zone.valloc = NULL;
838 zone.free = NULL;
839 zone.realloc = NULL;
840 zone.destroy = NULL;
841 zone.zone_name = "jemalloc_zone";
842 zone.batch_malloc = NULL;
843 zone.batch_free = NULL;
844 zone.introspect = &zone_introspect;
845 zone.version = 6;
846 zone.memalign = NULL;
847 zone.free_definite_size = NULL;
848
849 zone_introspect.enumerator = NULL;
850 zone_introspect.good_size = NULL;
851 zone_introspect.check = NULL;
852 zone_introspect.print = NULL;
853 zone_introspect.log = NULL;
854 zone_introspect.force_lock = NULL;
855 zone_introspect.force_unlock = NULL;
856 zone_introspect.statistics = NULL;
857 zone_introspect.zone_locked = NULL;
858], [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [6])
859 AC_MSG_RESULT([6])],
860 [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [3])
861 AC_MSG_RESULT([3])])
Jason Evansb27805b2010-02-10 18:15:53 -0800862fi
863
Jason Evansb7924f52009-06-23 19:01:18 -0700864dnl ============================================================================
865dnl Check for typedefs, structures, and compiler characteristics.
866AC_HEADER_STDBOOL
867
868dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -0800869AC_SUBST([cfghdrs_in])
870AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -0700871AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -0700872
873dnl ============================================================================
874dnl Generate outputs.
Jason Evans0656ec02010-04-07 23:37:35 -0700875AC_CONFIG_FILES([$cfgoutputs_tup config.stamp])
Jason Evansb0fd5012010-01-17 01:49:20 -0800876AC_SUBST([cfgoutputs_in])
877AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -0700878AC_OUTPUT
879
880dnl ============================================================================
881dnl Print out the results of configuration.
882AC_MSG_RESULT([===============================================================================])
883AC_MSG_RESULT([jemalloc version : $jemalloc_version])
884AC_MSG_RESULT([])
885AC_MSG_RESULT([CC : ${CC}])
886AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
887AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
888AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
889AC_MSG_RESULT([LIBS : ${LIBS}])
890AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
891AC_MSG_RESULT([])
Jason Evansaee7fd22010-11-24 22:00:02 -0800892AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
893AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
894AC_MSG_RESULT([])
Jason Evansb7924f52009-06-23 19:01:18 -0700895AC_MSG_RESULT([PREFIX : ${PREFIX}])
896AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -0700897AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
898AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -0700899AC_MSG_RESULT([DATADIR : ${DATADIR}])
900AC_MSG_RESULT([MANDIR : ${MANDIR}])
901AC_MSG_RESULT([])
902AC_MSG_RESULT([srcroot : ${srcroot}])
903AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
904AC_MSG_RESULT([objroot : ${objroot}])
905AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
906AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -0800907AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evansb0fd5012010-01-17 01:49:20 -0800908AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -0700909AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -0700910AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -0700911AC_MSG_RESULT([debug : ${enable_debug}])
912AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -0800913AC_MSG_RESULT([prof : ${enable_prof}])
914AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evans77f350b2011-03-15 22:23:12 -0700915AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
916AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
Jason Evansb7924f52009-06-23 19:01:18 -0700917AC_MSG_RESULT([tiny : ${enable_tiny}])
Jason Evans84cbbcb2009-12-29 00:09:15 -0800918AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -0700919AC_MSG_RESULT([fill : ${enable_fill}])
920AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
921AC_MSG_RESULT([sysv : ${enable_sysv}])
Jason Evans4201af02010-01-24 02:53:40 -0800922AC_MSG_RESULT([swap : ${enable_swap}])
Jason Evansb7924f52009-06-23 19:01:18 -0700923AC_MSG_RESULT([dss : ${enable_dss}])
924AC_MSG_RESULT([dynamic_page_shift : ${enable_dynamic_page_shift}])
925AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -0700926AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -0700927AC_MSG_RESULT([===============================================================================])