blob: 0ed13739b5f308b5f1ef9fb111076af570db4e12 [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])
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
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 Evansf3340ca2009-06-30 16:17:05 -070083dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
84dnl just prevent autoconf from molesting CFLAGS.
Jason Evansb7924f52009-06-23 19:01:18 -070085CFLAGS=$CFLAGS
86AC_PROG_CC
87if test "x$CFLAGS" = "x" ; then
88 no_CFLAGS="yes"
Jason Evanscfeccd32010-03-03 15:48:20 -080089 if test "x$GCC" = "xyes" ; then
90 JE_CFLAGS_APPEND([-std=gnu99])
91 JE_CFLAGS_APPEND([-Wall])
92 JE_CFLAGS_APPEND([-pipe])
93 JE_CFLAGS_APPEND([-g3])
94 fi
Jason Evansb7924f52009-06-23 19:01:18 -070095fi
96dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
97if test "x$EXTRA_CFLAGS" != "x" ; then
Jason Evansf3340ca2009-06-30 16:17:05 -070098 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
Jason Evansb7924f52009-06-23 19:01:18 -070099fi
100AC_PROG_CPP
101
Jason Evansb7924f52009-06-23 19:01:18 -0700102AC_CHECK_SIZEOF([void *])
103if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800104 LG_SIZEOF_PTR=3
Jason Evansb7924f52009-06-23 19:01:18 -0700105elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
Jason Evans94ad2b52009-12-29 00:09:15 -0800106 LG_SIZEOF_PTR=2
Jason Evansb7924f52009-06-23 19:01:18 -0700107else
108 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
109fi
Jason Evans94ad2b52009-12-29 00:09:15 -0800110AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
111
112AC_CHECK_SIZEOF([int])
113if test "x${ac_cv_sizeof_int}" = "x8" ; then
114 LG_SIZEOF_INT=3
115elif test "x${ac_cv_sizeof_int}" = "x4" ; then
116 LG_SIZEOF_INT=2
117else
118 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
119fi
120AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
Jason Evansb7924f52009-06-23 19:01:18 -0700121
122AC_CANONICAL_HOST
123dnl CPU-specific settings.
124CPU_SPINWAIT=""
125case "${host_cpu}" in
126 i[[345]]86)
127 ;;
128 i686)
Jason Evansf3340ca2009-06-30 16:17:05 -0700129 JE_COMPILABLE([__asm__], [], [[__asm__ volatile("pause"); return 0;]],
130 [asm])
131 if test "x${asm}" = "xyes" ; then
132 CPU_SPINWAIT='__asm__ volatile("pause")'
133 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700134 ;;
135 x86_64)
Jason Evansf3340ca2009-06-30 16:17:05 -0700136 JE_COMPILABLE([__asm__ syntax], [],
137 [[__asm__ volatile("pause"); return 0;]], [asm])
138 if test "x${asm}" = "xyes" ; then
139 CPU_SPINWAIT='__asm__ volatile("pause")'
140 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700141 ;;
142 *)
143 ;;
144esac
145AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
146
Jason Evansf3340ca2009-06-30 16:17:05 -0700147JE_COMPILABLE([__attribute__ syntax],
148 [static __attribute__((unused)) void foo(void){}],
149 [],
150 [attribute])
151if test "x${attribute}" = "xyes" ; then
Jason Evans9ad48232010-01-03 11:59:20 -0800152 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700153 if test "x$GCC" = "xyes" -a "${abi}" = "xelf"; then
Jason Evanse476f8a2010-01-16 09:53:50 -0800154 JE_CFLAGS_APPEND([-fvisibility=internal])
155 fi
Jason Evansf3340ca2009-06-30 16:17:05 -0700156fi
157
Jason Evansb7924f52009-06-23 19:01:18 -0700158dnl Platform-specific settings. abi and RPATH can probably be determined
159dnl programmatically, but doing so is error-prone, which makes it generally
160dnl not worth the trouble.
161dnl
162dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
163dnl definitions need to be seen before any headers are included, which is a pain
164dnl to make happen otherwise.
165case "${host}" in
166 *-*-darwin*)
167 CFLAGS="$CFLAGS -fno-common -no-cpp-precomp"
168 abi="macho"
Jason Evansce930552010-10-24 13:03:07 -0700169 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
Jason Evansb7924f52009-06-23 19:01:18 -0700170 RPATH=""
171 ;;
172 *-*-freebsd*)
173 CFLAGS="$CFLAGS"
174 abi="elf"
Jason Evans2dbecf12010-09-05 10:35:13 -0700175 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
Jason Evansb7924f52009-06-23 19:01:18 -0700176 RPATH="-Wl,-rpath,"
177 ;;
178 *-*-linux*)
179 CFLAGS="$CFLAGS"
180 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
181 abi="elf"
Jason Evans2dbecf12010-09-05 10:35:13 -0700182 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED])
Jason Evansb7924f52009-06-23 19:01:18 -0700183 RPATH="-Wl,-rpath,"
184 ;;
185 *-*-netbsd*)
186 AC_MSG_CHECKING([ABI])
187 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
188[[#ifdef __ELF__
189/* ELF */
190#else
191#error aout
192#endif
193]])],
194 [CFLAGS="$CFLAGS"; abi="elf"],
195 [abi="aout"])
196 AC_MSG_RESULT([$abi])
Jason Evans2dbecf12010-09-05 10:35:13 -0700197 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE])
Jason Evansb7924f52009-06-23 19:01:18 -0700198 RPATH="-Wl,-rpath,"
199 ;;
200 *-*-solaris2*)
201 CFLAGS="$CFLAGS"
202 abi="elf"
203 RPATH="-Wl,-R,"
204 dnl Solaris needs this for sigwait().
205 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
206 LIBS="$LIBS -lposix4 -lsocket -lnsl"
207 ;;
208 *)
209 AC_MSG_RESULT([Unsupported operating system: ${host}])
210 abi="elf"
211 RPATH="-Wl,-rpath,"
212 ;;
213esac
214AC_SUBST([abi])
215AC_SUBST([RPATH])
216
217dnl Support optional additions to rpath.
218AC_ARG_WITH([rpath],
Jason Evans90895cf2009-12-29 00:09:15 -0800219 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700220if test "x$with_rpath" = "xno" ; then
221 RPATH_EXTRA=
222else
223 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
224fi,
225 RPATH_EXTRA=
226)
227AC_SUBST([RPATH_EXTRA])
228
229dnl Disable rules that do automatic regeneration of configure output by default.
230AC_ARG_ENABLE([autogen],
Jason Evans78d815c2010-01-17 14:06:20 -0800231 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
Jason Evansb7924f52009-06-23 19:01:18 -0700232if test "x$enable_autogen" = "xno" ; then
233 enable_autogen="0"
234else
235 enable_autogen="1"
236fi
237,
238enable_autogen="0"
239)
240AC_SUBST([enable_autogen])
241
242AC_PROG_INSTALL
243AC_PROG_RANLIB
244AC_PATH_PROG([AR], [ar], , [$PATH])
245AC_PATH_PROG([LD], [ld], , [$PATH])
246AC_PATH_PROG([AUTOCONF], [autoconf], , [$PATH])
247
Jason Evans90895cf2009-12-29 00:09:15 -0800248dnl Do not prefix public APIs by default.
249AC_ARG_WITH([jemalloc_prefix],
250 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
Jason Evansb0fd5012010-01-17 01:49:20 -0800251 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
Jason Evans2dbecf12010-09-05 10:35:13 -0700252 [if test "x$abi" != "xmacho" ; then
253 JEMALLOC_PREFIX=""
254else
255 JEMALLOC_PREFIX="je_"
256fi]
Jason Evans90895cf2009-12-29 00:09:15 -0800257)
258if test "x$JEMALLOC_PREFIX" != "x" ; then
Jason Evanse7339702010-10-23 18:37:06 -0700259 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
260 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
261 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
Jason Evansb0fd5012010-01-17 01:49:20 -0800262 jemalloc_prefix="$JEMALLOC_PREFIX"
Jason Evanse7339702010-10-23 18:37:06 -0700263 jemalloc_cprefix="$JEMALLOC_CPREFIX"
Jason Evans90895cf2009-12-29 00:09:15 -0800264 AC_SUBST([jemalloc_prefix])
Jason Evanse7339702010-10-23 18:37:06 -0700265 AC_SUBST([jemalloc_cprefix])
Jason Evanse476f8a2010-01-16 09:53:50 -0800266 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 -0800267fi
268
Jason Evansb0fd5012010-01-17 01:49:20 -0800269dnl Do not add suffix to installed files by default.
270AC_ARG_WITH([install_suffix],
271 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
272 [INSTALL_SUFFIX="$with_install_suffix"],
273 [INSTALL_SUFFIX=]
274)
275install_suffix="$INSTALL_SUFFIX"
276AC_SUBST([install_suffix])
277
Jason Evans0656ec02010-04-07 23:37:35 -0700278cfgoutputs_in="${srcroot}Makefile.in ${srcroot}doc/jemalloc.3.in"
279cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/jemalloc.h.in"
280cfgoutputs_in="${cfgoutputs_in} ${srcroot}include/jemalloc/internal/jemalloc_internal.h.in"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700281cfgoutputs_in="${cfgoutputs_in} ${srcroot}test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800282
283cfgoutputs_out="Makefile doc/jemalloc${install_suffix}.3"
Jason Evans376b1522010-02-11 14:45:59 -0800284cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc${install_suffix}.h"
285cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700286cfgoutputs_out="${cfgoutputs_out} test/jemalloc_test.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800287
288cfgoutputs_tup="Makefile doc/jemalloc${install_suffix}.3:doc/jemalloc.3.in"
Jason Evans376b1522010-02-11 14:45:59 -0800289cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc${install_suffix}.h:include/jemalloc/jemalloc.h.in"
290cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
Jason Evans9f3b0a72010-10-07 09:53:26 -0700291cfgoutputs_tup="${cfgoutputs_tup} test/jemalloc_test.h:test/jemalloc_test.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800292
Jason Evans0656ec02010-04-07 23:37:35 -0700293cfghdrs_in="${srcroot}include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800294
Jason Evans376b1522010-02-11 14:45:59 -0800295cfghdrs_out="include/jemalloc/jemalloc_defs${install_suffix}.h"
Jason Evansb0fd5012010-01-17 01:49:20 -0800296
Jason Evans376b1522010-02-11 14:45:59 -0800297cfghdrs_tup="include/jemalloc/jemalloc_defs${install_suffix}.h:include/jemalloc/jemalloc_defs.h.in"
Jason Evansb0fd5012010-01-17 01:49:20 -0800298
Jason Evans355b4382010-09-20 19:20:48 -0700299dnl Do not silence irrelevant compiler warnings by default, since enabling this
300dnl option incurs a performance penalty.
301AC_ARG_ENABLE([cc-silence],
302 [AS_HELP_STRING([--enable-cc-silence],
303 [Silence irrelevant compiler warnings])],
304[if test "x$enable_cc_silence" = "xno" ; then
305 enable_cc_silence="0"
306else
307 enable_cc_silence="1"
308fi
309],
310[enable_cc_silence="0"]
311)
312if test "x$enable_cc_silence" = "x1" ; then
313 AC_DEFINE([JEMALLOC_CC_SILENCE])
314fi
315
Jason Evansb7924f52009-06-23 19:01:18 -0700316dnl Do not compile with debugging by default.
317AC_ARG_ENABLE([debug],
318 [AS_HELP_STRING([--enable-debug], [Build debugging code])],
319[if test "x$enable_debug" = "xno" ; then
320 enable_debug="0"
321else
322 enable_debug="1"
323fi
324],
325[enable_debug="0"]
326)
327if test "x$enable_debug" = "x1" ; then
328 AC_DEFINE([JEMALLOC_DEBUG], [ ])
Jason Evans2dbecf12010-09-05 10:35:13 -0700329 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
Jason Evansb7924f52009-06-23 19:01:18 -0700330fi
331AC_SUBST([enable_debug])
Jason Evanse7339702010-10-23 18:37:06 -0700332if test "x$enable_debug" = "x0" ; then
333 roff_debug=".\\\" "
334 roff_no_debug=""
335else
336 roff_debug=""
337 roff_no_debug=".\\\" "
338fi
339AC_SUBST([roff_debug])
340AC_SUBST([roff_no_debug])
Jason Evansb7924f52009-06-23 19:01:18 -0700341
342dnl Only optimize if not debugging.
343if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
344 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
Jason Evansf3340ca2009-06-30 16:17:05 -0700345 optimize="no"
346 echo "$EXTRA_CFLAGS" | grep "\-O" >/dev/null || optimize="yes"
347 if test "x${optimize}" = "xyes" ; then
348 if test "x$GCC" = "xyes" ; then
349 JE_CFLAGS_APPEND([-O3])
350 JE_CFLAGS_APPEND([-funroll-loops])
Jason Evansf3340ca2009-06-30 16:17:05 -0700351 else
352 JE_CFLAGS_APPEND([-O])
353 fi
Jason Evansb7924f52009-06-23 19:01:18 -0700354 fi
355fi
356
357dnl Do not enable statistics calculation by default.
358AC_ARG_ENABLE([stats],
359 [AS_HELP_STRING([--enable-stats], [Enable statistics calculation/reporting])],
360[if test "x$enable_stats" = "xno" ; then
361 enable_stats="0"
362else
363 enable_stats="1"
364fi
365],
366[enable_stats="0"]
367)
368if test "x$enable_stats" = "x1" ; then
369 AC_DEFINE([JEMALLOC_STATS], [ ])
370fi
371AC_SUBST([enable_stats])
Jason Evanscc00a152009-06-25 18:06:48 -0700372if test "x$enable_stats" = "x0" ; then
373 roff_stats=".\\\" "
374else
375 roff_stats=""
376fi
377AC_SUBST([roff_stats])
Jason Evansb7924f52009-06-23 19:01:18 -0700378
Jason Evans6109fe02010-02-10 10:37:56 -0800379dnl Do not enable profiling by default.
380AC_ARG_ENABLE([prof],
381 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
382[if test "x$enable_prof" = "xno" ; then
383 enable_prof="0"
384else
385 enable_prof="1"
386fi
387],
388[enable_prof="0"]
389)
Jason Evansb27805b2010-02-10 18:15:53 -0800390AC_ARG_ENABLE([prof-libgcc],
391 [AS_HELP_STRING([--disable-prof-libgcc],
392 [Do not use libgcc for backtracing])],
393[if test "x$enable_prof_libgcc" = "xno" ; then
394 enable_prof_libgcc="0"
395else
396 enable_prof_libgcc="1"
397fi
398],
399[enable_prof_libgcc="1"]
400)
Jason Evans6109fe02010-02-10 10:37:56 -0800401AC_ARG_ENABLE([prof-libunwind],
402 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
403[if test "x$enable_prof_libunwind" = "xno" ; then
404 enable_prof_libunwind="0"
405else
406 enable_prof_libunwind="1"
407fi
408],
409[enable_prof_libunwind="0"]
410)
Jason Evansca6bd4f2010-03-02 14:12:58 -0800411AC_ARG_WITH([static_libunwind],
412 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
413 [Path to static libunwind library; use rather than dynamically linking])],
414if test "x$with_static_libunwind" = "xno" ; then
415 LUNWIND="-lunwind"
416else
417 if test ! -f "$with_static_libunwind" ; then
418 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
419 fi
420 LUNWIND="$with_static_libunwind"
421fi,
422 LUNWIND="-lunwind"
423)
Jason Evans2dbecf12010-09-05 10:35:13 -0700424if test "x$enable_prof" = "x1" ; then
425 LIBS="$LIBS -lm"
426 AC_DEFINE([JEMALLOC_PROF], [ ])
427 if test "x$enable_prof_libunwind" = "x1" ; then
428 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
429 if test "x$LUNWIND" = "x-lunwind" ; then
430 AC_CHECK_LIB([unwind], [backtrace], [LIBS="$LIBS $LUNWIND"],
431 [enable_prof_libunwind="0"])
432 else
433 LIBS="$LIBS $LUNWIND"
434 fi
435 if test "x${enable_prof_libunwind}" = "x1" ; then
436 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
437 fi
438 fi
439fi
440AC_SUBST([enable_prof])
441if test "x$enable_prof" = "x0" ; then
442 roff_prof=".\\\" "
443 roff_no_prof=""
444else
445 roff_prof=""
446 roff_no_prof=".\\\" "
447fi
448AC_SUBST([roff_prof])
449AC_SUBST([roff_no_prof])
450
451dnl If libunwind isn't enabled, try to use libgcc rather than gcc intrinsics
452dnl for backtracing.
Jason Evansac6f3c22010-10-07 11:59:12 -0700453if test "x$enable_prof" = "x1" -a "x$enable_prof_libgcc" = "x1" ; then
454 if test "x$enable_prof_libunwind" = "x0" -a "x$GCC" = "xyes" ; then
455 enable_prof_libgcc="1"
456 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
457 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
458 if test "x${enable_prof_libgcc}" = "x1" ; then
459 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
460 fi
461 else
462 enable_prof_libgcc="0"
Jason Evans2dbecf12010-09-05 10:35:13 -0700463 fi
464fi
Jason Evans6109fe02010-02-10 10:37:56 -0800465
Jason Evansb7924f52009-06-23 19:01:18 -0700466dnl Enable tiny allocations by default.
467AC_ARG_ENABLE([tiny],
468 [AS_HELP_STRING([--disable-tiny], [Disable tiny (sub-quantum) allocations])],
469[if test "x$enable_tiny" = "xno" ; then
470 enable_tiny="0"
471else
472 enable_tiny="1"
473fi
474],
475[enable_tiny="1"]
476)
477if test "x$enable_tiny" = "x1" ; then
478 AC_DEFINE([JEMALLOC_TINY], [ ])
479fi
480AC_SUBST([enable_tiny])
Jason Evanscc00a152009-06-25 18:06:48 -0700481if test "x$enable_tiny" = "x0" ; then
482 roff_tiny=".\\\" "
483 roff_no_tiny=""
484else
485 roff_tiny=""
486 roff_no_tiny=".\\\" "
487fi
488AC_SUBST([roff_tiny])
489AC_SUBST([roff_no_tiny])
Jason Evansb7924f52009-06-23 19:01:18 -0700490
Jason Evans84cbbcb2009-12-29 00:09:15 -0800491dnl Enable thread-specific caching by default.
492AC_ARG_ENABLE([tcache],
493 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
494[if test "x$enable_tcache" = "xno" ; then
495 enable_tcache="0"
Jason Evansb7924f52009-06-23 19:01:18 -0700496else
Jason Evans84cbbcb2009-12-29 00:09:15 -0800497 enable_tcache="1"
Jason Evansb7924f52009-06-23 19:01:18 -0700498fi
499],
Jason Evans84cbbcb2009-12-29 00:09:15 -0800500[enable_tcache="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700501)
Jason Evans2dbecf12010-09-05 10:35:13 -0700502if test "x$enable_tcache" = "x1" ; then
503 AC_DEFINE([JEMALLOC_TCACHE], [ ])
504fi
505AC_SUBST([enable_tcache])
506if test "x$enable_tcache" = "x0" ; then
507 roff_tcache=".\\\" "
508 roff_no_tcache=""
509else
510 roff_tcache=""
511 roff_no_tcache=".\\\" "
512fi
513AC_SUBST([roff_tcache])
514AC_SUBST([roff_no_tcache])
Jason Evansb7924f52009-06-23 19:01:18 -0700515
Jason Evans4201af02010-01-24 02:53:40 -0800516dnl Do not enable mmap()ped swap files by default.
517AC_ARG_ENABLE([swap],
518 [AS_HELP_STRING([--enable-swap], [Enable mmap()ped swap files])],
519[if test "x$enable_swap" = "xno" ; then
520 enable_swap="0"
521else
522 enable_swap="1"
523fi
524],
525[enable_swap="0"]
526)
527if test "x$enable_swap" = "x1" ; then
528 AC_DEFINE([JEMALLOC_SWAP], [ ])
529fi
530AC_SUBST([enable_swap])
531if test "x$enable_swap" = "x0" ; then
532 roff_swap=".\\\" "
533else
534 roff_swap=""
535fi
536AC_SUBST([roff_swap])
537
Jason Evansb7924f52009-06-23 19:01:18 -0700538dnl Do not enable allocation from DSS by default.
539AC_ARG_ENABLE([dss],
540 [AS_HELP_STRING([--enable-dss], [Enable allocation from DSS])],
541[if test "x$enable_dss" = "xno" ; then
542 enable_dss="0"
543else
544 enable_dss="1"
545fi
546],
547[enable_dss="0"]
548)
549if test "x$enable_dss" = "x1" ; then
550 AC_DEFINE([JEMALLOC_DSS], [ ])
551fi
552AC_SUBST([enable_dss])
Jason Evanscc00a152009-06-25 18:06:48 -0700553if test "x$enable_dss" = "x0" ; then
554 roff_dss=".\\\" "
555else
556 roff_dss=""
557fi
558AC_SUBST([roff_dss])
Jason Evansb7924f52009-06-23 19:01:18 -0700559
560dnl Do not support the junk/zero filling option by default.
561AC_ARG_ENABLE([fill],
562 [AS_HELP_STRING([--enable-fill], [Support junk/zero filling option])],
563[if test "x$enable_fill" = "xno" ; then
564 enable_fill="0"
565else
566 enable_fill="1"
567fi
568],
569[enable_fill="0"]
570)
571if test "x$enable_fill" = "x1" ; then
572 AC_DEFINE([JEMALLOC_FILL], [ ])
573fi
574AC_SUBST([enable_fill])
Jason Evanscc00a152009-06-25 18:06:48 -0700575if test "x$enable_fill" = "x0" ; then
576 roff_fill=".\\\" "
577else
578 roff_fill=""
579fi
580AC_SUBST([roff_fill])
Jason Evansb7924f52009-06-23 19:01:18 -0700581
582dnl Do not support the xmalloc option by default.
583AC_ARG_ENABLE([xmalloc],
584 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
585[if test "x$enable_xmalloc" = "xno" ; then
586 enable_xmalloc="0"
587else
588 enable_xmalloc="1"
589fi
590],
591[enable_xmalloc="0"]
592)
593if test "x$enable_xmalloc" = "x1" ; then
594 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
595fi
596AC_SUBST([enable_xmalloc])
Jason Evanscc00a152009-06-25 18:06:48 -0700597if test "x$enable_xmalloc" = "x0" ; then
598 roff_xmalloc=".\\\" "
599else
600 roff_xmalloc=""
601fi
602AC_SUBST([roff_xmalloc])
Jason Evansb7924f52009-06-23 19:01:18 -0700603
604dnl Do not support the SYSV option by default.
605AC_ARG_ENABLE([sysv],
606 [AS_HELP_STRING([--enable-sysv], [Support SYSV semantics option])],
607[if test "x$enable_sysv" = "xno" ; then
608 enable_sysv="0"
609else
610 enable_sysv="1"
611fi
612],
613[enable_sysv="0"]
614)
615if test "x$enable_sysv" = "x1" ; then
616 AC_DEFINE([JEMALLOC_SYSV], [ ])
617fi
618AC_SUBST([enable_sysv])
Jason Evanscc00a152009-06-25 18:06:48 -0700619if test "x$enable_sysv" = "x0" ; then
620 roff_sysv=".\\\" "
621else
622 roff_sysv=""
623fi
624AC_SUBST([roff_sysv])
Jason Evansb7924f52009-06-23 19:01:18 -0700625
626dnl Do not determine page shift at run time by default.
627AC_ARG_ENABLE([dynamic_page_shift],
628 [AS_HELP_STRING([--enable-dynamic-page-shift],
629 [Determine page size at run time (don't trust configure result)])],
630[if test "x$enable_dynamic_page_shift" = "xno" ; then
631 enable_dynamic_page_shift="0"
632else
633 enable_dynamic_page_shift="1"
634fi
635],
636[enable_dynamic_page_shift="0"]
637)
638if test "x$enable_dynamic_page_shift" = "x1" ; then
639 AC_DEFINE([DYNAMIC_PAGE_SHIFT], [ ])
640fi
641AC_SUBST([enable_dynamic_page_shift])
642
643AC_MSG_CHECKING([STATIC_PAGE_SHIFT])
644AC_RUN_IFELSE([AC_LANG_PROGRAM(
645[[#include <stdio.h>
646#include <unistd.h>
647#include <strings.h>
648]], [[
649 long result;
650 FILE *f;
651
652 result = sysconf(_SC_PAGESIZE);
653 if (result == -1) {
654 return 1;
655 }
656 f = fopen("conftest.out", "w");
657 if (f == NULL) {
658 return 1;
659 }
660 fprintf(f, "%u\n", ffs((int)result) - 1);
661 close(f);
662
663 return 0;
664]])],
665 [STATIC_PAGE_SHIFT=`cat conftest.out`]
666 AC_MSG_RESULT([$STATIC_PAGE_SHIFT])
667 AC_DEFINE_UNQUOTED([STATIC_PAGE_SHIFT], [$STATIC_PAGE_SHIFT]),
668 AC_MSG_RESULT([error]))
669
670dnl ============================================================================
671dnl jemalloc configuration.
672dnl
Jason Evansa40bc7a2010-03-02 13:01:16 -0800673
674dnl Set VERSION if source directory has an embedded git repository.
675if test -d "${srcroot}../.git" ; then
Jason Evans79d660d2010-09-17 17:38:24 -0700676 git describe --long --abbrev=40 > ${srcroot}VERSION
Jason Evansa40bc7a2010-03-02 13:01:16 -0800677fi
Jason Evansb7924f52009-06-23 19:01:18 -0700678jemalloc_version=`cat ${srcroot}VERSION`
Jason Evansa40bc7a2010-03-02 13:01:16 -0800679jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
680jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
681jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
682jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
683jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
Jason Evansb7924f52009-06-23 19:01:18 -0700684AC_SUBST([jemalloc_version])
Jason Evansa40bc7a2010-03-02 13:01:16 -0800685AC_SUBST([jemalloc_version_major])
686AC_SUBST([jemalloc_version_minor])
687AC_SUBST([jemalloc_version_bugfix])
688AC_SUBST([jemalloc_version_nrev])
689AC_SUBST([jemalloc_version_gid])
Jason Evansb7924f52009-06-23 19:01:18 -0700690
691dnl ============================================================================
692dnl Configure pthreads.
693
694AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
695AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
696 [AC_MSG_ERROR([libpthread is missing])])
697
698CPPFLAGS="$CPPFLAGS -D_REENTRANT"
699
Jason Evanscc00a152009-06-25 18:06:48 -0700700dnl Enable lazy locking by default.
Jason Evansb7924f52009-06-23 19:01:18 -0700701AC_ARG_ENABLE([lazy_lock],
Jason Evansa1624022009-11-09 14:58:12 -0800702 [AS_HELP_STRING([--disable-lazy-lock],
Jason Evanscc00a152009-06-25 18:06:48 -0700703 [Disable lazy locking (always lock, even when single-threaded)])],
Jason Evansb7924f52009-06-23 19:01:18 -0700704[if test "x$enable_lazy_lock" = "xno" ; then
705 enable_lazy_lock="0"
706else
707 enable_lazy_lock="1"
708fi
709],
Jason Evanscc00a152009-06-25 18:06:48 -0700710[enable_lazy_lock="1"]
Jason Evansb7924f52009-06-23 19:01:18 -0700711)
712if test "x$enable_lazy_lock" = "x1" ; then
713 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
714 AC_CHECK_LIB([dl], [dlopen], [LIBS="$LIBS -ldl"],
715 [AC_MSG_ERROR([libdl is missing])])
716 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
717fi
718AC_SUBST([enable_lazy_lock])
719
Jason Evans78d815c2010-01-17 14:06:20 -0800720AC_ARG_ENABLE([tls],
721 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
722if test "x$enable_tls" = "xno" ; then
723 enable_tls="0"
724else
725 enable_tls="1"
726fi
727,
728enable_tls="1"
729)
730if test "x${enable_tls}" = "x1" ; then
731AC_MSG_CHECKING([for TLS])
732AC_RUN_IFELSE([AC_LANG_PROGRAM(
733[[
734 __thread int x;
735]], [[
736 x = 42;
737
738 return 0;
739]])],
740 AC_MSG_RESULT([yes]),
741 AC_MSG_RESULT([no])
742 enable_tls="0")
743fi
Jason Evansb267d0f2010-08-13 15:42:29 -0700744AC_SUBST([enable_tls])
Jason Evans78d815c2010-01-17 14:06:20 -0800745if test "x${enable_tls}" = "x0" ; then
746 AC_DEFINE_UNQUOTED([NO_TLS], [ ])
747fi
748
Jason Evans2dbecf12010-09-05 10:35:13 -0700749dnl ============================================================================
Jason Evans6a0d2912010-09-20 16:44:23 -0700750dnl Check for allocator-related functions that should be wrapped.
751
752AC_CHECK_FUNC([memalign],
753 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN])])
754AC_CHECK_FUNC([valloc],
755 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC])])
756
757dnl ============================================================================
Jason Evans2dbecf12010-09-05 10:35:13 -0700758dnl Darwin-related configuration.
Jason Evans78d815c2010-01-17 14:06:20 -0800759
Jason Evans2dbecf12010-09-05 10:35:13 -0700760if test "x${abi}" = "xmacho" ; then
761 AC_DEFINE([JEMALLOC_IVSALLOC])
762 AC_DEFINE([JEMALLOC_ZONE])
Jason Evans6109fe02010-02-10 10:37:56 -0800763
Jason Evans2dbecf12010-09-05 10:35:13 -0700764 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
765 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
766 dnl 10.6, which is the only source-level indication of the change.
767 AC_MSG_CHECKING([malloc zone version])
768 AC_TRY_COMPILE([#include <stdlib.h>
769#include <malloc/malloc.h>], [
770 static malloc_zone_t zone;
771 static struct malloc_introspection_t zone_introspect;
772
773 zone.size = NULL;
774 zone.malloc = NULL;
775 zone.calloc = NULL;
776 zone.valloc = NULL;
777 zone.free = NULL;
778 zone.realloc = NULL;
779 zone.destroy = NULL;
780 zone.zone_name = "jemalloc_zone";
781 zone.batch_malloc = NULL;
782 zone.batch_free = NULL;
783 zone.introspect = &zone_introspect;
784 zone.version = 6;
785 zone.memalign = NULL;
786 zone.free_definite_size = NULL;
787
788 zone_introspect.enumerator = NULL;
789 zone_introspect.good_size = NULL;
790 zone_introspect.check = NULL;
791 zone_introspect.print = NULL;
792 zone_introspect.log = NULL;
793 zone_introspect.force_lock = NULL;
794 zone_introspect.force_unlock = NULL;
795 zone_introspect.statistics = NULL;
796 zone_introspect.zone_locked = NULL;
797], [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [6])
798 AC_MSG_RESULT([6])],
799 [AC_DEFINE_UNQUOTED([JEMALLOC_ZONE_VERSION], [3])
800 AC_MSG_RESULT([3])])
Jason Evansb27805b2010-02-10 18:15:53 -0800801fi
802
Jason Evansb7924f52009-06-23 19:01:18 -0700803dnl ============================================================================
804dnl Check for typedefs, structures, and compiler characteristics.
805AC_HEADER_STDBOOL
806
807dnl Process .in files.
Jason Evansb0fd5012010-01-17 01:49:20 -0800808AC_SUBST([cfghdrs_in])
809AC_SUBST([cfghdrs_out])
Jason Evans0656ec02010-04-07 23:37:35 -0700810AC_CONFIG_HEADERS([$cfghdrs_tup])
Jason Evansb7924f52009-06-23 19:01:18 -0700811
812dnl ============================================================================
813dnl Generate outputs.
Jason Evans0656ec02010-04-07 23:37:35 -0700814AC_CONFIG_FILES([$cfgoutputs_tup config.stamp])
Jason Evansb0fd5012010-01-17 01:49:20 -0800815AC_SUBST([cfgoutputs_in])
816AC_SUBST([cfgoutputs_out])
Jason Evansb7924f52009-06-23 19:01:18 -0700817AC_OUTPUT
818
819dnl ============================================================================
820dnl Print out the results of configuration.
821AC_MSG_RESULT([===============================================================================])
822AC_MSG_RESULT([jemalloc version : $jemalloc_version])
823AC_MSG_RESULT([])
824AC_MSG_RESULT([CC : ${CC}])
825AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
826AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
827AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
828AC_MSG_RESULT([LIBS : ${LIBS}])
829AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
830AC_MSG_RESULT([])
831AC_MSG_RESULT([PREFIX : ${PREFIX}])
832AC_MSG_RESULT([BINDIR : ${BINDIR}])
Jason Evans662a0172009-07-01 19:24:31 -0700833AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
834AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
Jason Evansb7924f52009-06-23 19:01:18 -0700835AC_MSG_RESULT([DATADIR : ${DATADIR}])
836AC_MSG_RESULT([MANDIR : ${MANDIR}])
837AC_MSG_RESULT([])
838AC_MSG_RESULT([srcroot : ${srcroot}])
839AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
840AC_MSG_RESULT([objroot : ${objroot}])
841AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
842AC_MSG_RESULT([])
Jason Evans90895cf2009-12-29 00:09:15 -0800843AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
Jason Evansb0fd5012010-01-17 01:49:20 -0800844AC_MSG_RESULT([install_suffix : ${install_suffix}])
Jason Evansb7924f52009-06-23 19:01:18 -0700845AC_MSG_RESULT([autogen : ${enable_autogen}])
Jason Evans355b4382010-09-20 19:20:48 -0700846AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
Jason Evansb7924f52009-06-23 19:01:18 -0700847AC_MSG_RESULT([debug : ${enable_debug}])
848AC_MSG_RESULT([stats : ${enable_stats}])
Jason Evans6109fe02010-02-10 10:37:56 -0800849AC_MSG_RESULT([prof : ${enable_prof}])
Jason Evans4d5c0992010-10-02 21:35:27 -0700850AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
Jason Evans6109fe02010-02-10 10:37:56 -0800851AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
Jason Evansb7924f52009-06-23 19:01:18 -0700852AC_MSG_RESULT([tiny : ${enable_tiny}])
Jason Evans84cbbcb2009-12-29 00:09:15 -0800853AC_MSG_RESULT([tcache : ${enable_tcache}])
Jason Evansb7924f52009-06-23 19:01:18 -0700854AC_MSG_RESULT([fill : ${enable_fill}])
855AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
856AC_MSG_RESULT([sysv : ${enable_sysv}])
Jason Evans4201af02010-01-24 02:53:40 -0800857AC_MSG_RESULT([swap : ${enable_swap}])
Jason Evansb7924f52009-06-23 19:01:18 -0700858AC_MSG_RESULT([dss : ${enable_dss}])
859AC_MSG_RESULT([dynamic_page_shift : ${enable_dynamic_page_shift}])
860AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
Jason Evans2dbecf12010-09-05 10:35:13 -0700861AC_MSG_RESULT([tls : ${enable_tls}])
Jason Evansb7924f52009-06-23 19:01:18 -0700862AC_MSG_RESULT([===============================================================================])