• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl Process this file with autoconf to produce a configure script.
2AC_PREREQ(2.68)
3AC_INIT([Makefile.in])
4
5AC_CONFIG_AUX_DIR([build-aux])
6
7dnl ============================================================================
8dnl Custom macro definitions.
9
10dnl JE_CONCAT_VVV(r, a, b)
11dnl
12dnl Set $r to the concatenation of $a and $b, with a space separating them iff
13dnl both $a and $b are non-empty.
14AC_DEFUN([JE_CONCAT_VVV],
15if test "x[$]{$2}" = "x" -o "x[$]{$3}" = "x" ; then
16  $1="[$]{$2}[$]{$3}"
17else
18  $1="[$]{$2} [$]{$3}"
19fi
20)
21
22dnl JE_APPEND_VS(a, b)
23dnl
24dnl Set $a to the concatenation of $a and b, with a space separating them iff
25dnl both $a and b are non-empty.
26AC_DEFUN([JE_APPEND_VS],
27  T_APPEND_V=$2
28  JE_CONCAT_VVV($1, $1, T_APPEND_V)
29)
30
31CONFIGURE_CFLAGS=
32SPECIFIED_CFLAGS="${CFLAGS}"
33dnl JE_CFLAGS_ADD(cflag)
34dnl
35dnl CFLAGS is the concatenation of CONFIGURE_CFLAGS and SPECIFIED_CFLAGS
36dnl (ignoring EXTRA_CFLAGS, which does not impact configure tests.  This macro
37dnl appends to CONFIGURE_CFLAGS and regenerates CFLAGS.
38AC_DEFUN([JE_CFLAGS_ADD],
39[
40AC_MSG_CHECKING([whether compiler supports $1])
41T_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
42JE_APPEND_VS(CONFIGURE_CFLAGS, $1)
43JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
44AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
45[[
46]], [[
47    return 0;
48]])],
49              [je_cv_cflags_added=$1]
50              AC_MSG_RESULT([yes]),
51              [je_cv_cflags_added=]
52              AC_MSG_RESULT([no])
53              [CONFIGURE_CFLAGS="${T_CONFIGURE_CFLAGS}"]
54)
55JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
56])
57
58dnl JE_CFLAGS_SAVE()
59dnl JE_CFLAGS_RESTORE()
60dnl
61dnl Save/restore CFLAGS.  Nesting is not supported.
62AC_DEFUN([JE_CFLAGS_SAVE],
63SAVED_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
64)
65AC_DEFUN([JE_CFLAGS_RESTORE],
66CONFIGURE_CFLAGS="${SAVED_CONFIGURE_CFLAGS}"
67JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
68)
69
70CONFIGURE_CXXFLAGS=
71SPECIFIED_CXXFLAGS="${CXXFLAGS}"
72dnl JE_CXXFLAGS_ADD(cxxflag)
73AC_DEFUN([JE_CXXFLAGS_ADD],
74[
75AC_MSG_CHECKING([whether compiler supports $1])
76T_CONFIGURE_CXXFLAGS="${CONFIGURE_CXXFLAGS}"
77JE_APPEND_VS(CONFIGURE_CXXFLAGS, $1)
78JE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
79AC_LANG_PUSH([C++])
80AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
81[[
82]], [[
83    return 0;
84]])],
85              [je_cv_cxxflags_added=$1]
86              AC_MSG_RESULT([yes]),
87              [je_cv_cxxflags_added=]
88              AC_MSG_RESULT([no])
89              [CONFIGURE_CXXFLAGS="${T_CONFIGURE_CXXFLAGS}"]
90)
91AC_LANG_POP([C++])
92JE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
93])
94
95dnl JE_COMPILABLE(label, hcode, mcode, rvar)
96dnl
97dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
98dnl cause failure.
99AC_DEFUN([JE_COMPILABLE],
100[
101AC_CACHE_CHECK([whether $1 is compilable],
102               [$4],
103               [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
104                                                [$3])],
105                               [$4=yes],
106                               [$4=no])])
107])
108
109dnl ============================================================================
110
111CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
112AC_SUBST([CONFIG])
113
114dnl Library revision.
115rev=2
116AC_SUBST([rev])
117
118srcroot=$srcdir
119if test "x${srcroot}" = "x." ; then
120  srcroot=""
121else
122  srcroot="${srcroot}/"
123fi
124AC_SUBST([srcroot])
125abs_srcroot="`cd \"${srcdir}\"; pwd`/"
126AC_SUBST([abs_srcroot])
127
128objroot=""
129AC_SUBST([objroot])
130abs_objroot="`pwd`/"
131AC_SUBST([abs_objroot])
132
133dnl Munge install path variables.
134if test "x$prefix" = "xNONE" ; then
135  prefix="/usr/local"
136fi
137if test "x$exec_prefix" = "xNONE" ; then
138  exec_prefix=$prefix
139fi
140PREFIX=$prefix
141AC_SUBST([PREFIX])
142BINDIR=`eval echo $bindir`
143BINDIR=`eval echo $BINDIR`
144AC_SUBST([BINDIR])
145INCLUDEDIR=`eval echo $includedir`
146INCLUDEDIR=`eval echo $INCLUDEDIR`
147AC_SUBST([INCLUDEDIR])
148LIBDIR=`eval echo $libdir`
149LIBDIR=`eval echo $LIBDIR`
150AC_SUBST([LIBDIR])
151DATADIR=`eval echo $datadir`
152DATADIR=`eval echo $DATADIR`
153AC_SUBST([DATADIR])
154MANDIR=`eval echo $mandir`
155MANDIR=`eval echo $MANDIR`
156AC_SUBST([MANDIR])
157
158dnl Support for building documentation.
159AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
160if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
161  DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
162elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
163  DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
164else
165  dnl Documentation building will fail if this default gets used.
166  DEFAULT_XSLROOT=""
167fi
168AC_ARG_WITH([xslroot],
169  [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
170if test "x$with_xslroot" = "xno" ; then
171  XSLROOT="${DEFAULT_XSLROOT}"
172else
173  XSLROOT="${with_xslroot}"
174fi
175],
176  XSLROOT="${DEFAULT_XSLROOT}"
177)
178AC_SUBST([XSLROOT])
179
180dnl If CFLAGS isn't defined, set CFLAGS to something reasonable.  Otherwise,
181dnl just prevent autoconf from molesting CFLAGS.
182CFLAGS=$CFLAGS
183AC_PROG_CC
184
185if test "x$GCC" != "xyes" ; then
186  AC_CACHE_CHECK([whether compiler is MSVC],
187                 [je_cv_msvc],
188                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
189                                                     [
190#ifndef _MSC_VER
191  int fail[-1];
192#endif
193])],
194                               [je_cv_msvc=yes],
195                               [je_cv_msvc=no])])
196fi
197
198dnl check if a cray prgenv wrapper compiler is being used
199je_cv_cray_prgenv_wrapper=""
200if test "x${PE_ENV}" != "x" ; then
201  case "${CC}" in
202    CC|cc)
203	je_cv_cray_prgenv_wrapper="yes"
204	;;
205    *)
206       ;;
207  esac
208fi
209
210AC_CACHE_CHECK([whether compiler is cray],
211              [je_cv_cray],
212              [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
213                                                  [
214#ifndef _CRAYC
215  int fail[-1];
216#endif
217])],
218                            [je_cv_cray=yes],
219                            [je_cv_cray=no])])
220
221if test "x${je_cv_cray}" = "xyes" ; then
222  AC_CACHE_CHECK([whether cray compiler version is 8.4],
223                [je_cv_cray_84],
224                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
225                                                      [
226#if !(_RELEASE_MAJOR == 8 && _RELEASE_MINOR == 4)
227  int fail[-1];
228#endif
229])],
230                              [je_cv_cray_84=yes],
231                              [je_cv_cray_84=no])])
232fi
233
234if test "x$GCC" = "xyes" ; then
235  JE_CFLAGS_ADD([-std=gnu11])
236  if test "x$je_cv_cflags_added" = "x-std=gnu11" ; then
237    AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
238  else
239    JE_CFLAGS_ADD([-std=gnu99])
240    if test "x$je_cv_cflags_added" = "x-std=gnu99" ; then
241      AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
242    fi
243  fi
244  JE_CFLAGS_ADD([-Wall])
245  JE_CFLAGS_ADD([-Wshorten-64-to-32])
246  JE_CFLAGS_ADD([-Wsign-compare])
247  JE_CFLAGS_ADD([-Wundef])
248  JE_CFLAGS_ADD([-Wno-format-zero-length])
249  JE_CFLAGS_ADD([-pipe])
250  JE_CFLAGS_ADD([-g3])
251elif test "x$je_cv_msvc" = "xyes" ; then
252  CC="$CC -nologo"
253  JE_CFLAGS_ADD([-Zi])
254  JE_CFLAGS_ADD([-MT])
255  JE_CFLAGS_ADD([-W3])
256  JE_CFLAGS_ADD([-FS])
257  JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat)
258fi
259if test "x$je_cv_cray" = "xyes" ; then
260  dnl cray compiler 8.4 has an inlining bug
261  if test "x$je_cv_cray_84" = "xyes" ; then
262    JE_CFLAGS_ADD([-hipa2])
263    JE_CFLAGS_ADD([-hnognu])
264  fi
265  dnl ignore unreachable code warning
266  JE_CFLAGS_ADD([-hnomessage=128])
267  dnl ignore redefinition of "malloc", "free", etc warning
268  JE_CFLAGS_ADD([-hnomessage=1357])
269fi
270AC_SUBST([CONFIGURE_CFLAGS])
271AC_SUBST([SPECIFIED_CFLAGS])
272AC_SUBST([EXTRA_CFLAGS])
273AC_PROG_CPP
274
275AC_ARG_ENABLE([cxx],
276  [AS_HELP_STRING([--disable-cxx], [Disable C++ integration])],
277if test "x$enable_cxx" = "xno" ; then
278  enable_cxx="0"
279else
280  enable_cxx="1"
281fi
282,
283enable_cxx="1"
284)
285if test "x$enable_cxx" = "x1" ; then
286  dnl Require at least c++14, which is the first version to support sized
287  dnl deallocation.  C++ support is not compiled otherwise.
288  m4_include([m4/ax_cxx_compile_stdcxx.m4])
289  AX_CXX_COMPILE_STDCXX([14], [noext], [optional])
290  if test "x${HAVE_CXX14}" = "x1" ; then
291    JE_CXXFLAGS_ADD([-Wall])
292    JE_CXXFLAGS_ADD([-g3])
293
294    SAVED_LIBS="${LIBS}"
295    JE_APPEND_VS(LIBS, -lstdc++)
296    JE_COMPILABLE([libstdc++ linkage], [
297#include <stdlib.h>
298], [[
299	int *arr = (int *)malloc(sizeof(int) * 42);
300	if (arr == NULL)
301		return 1;
302]], [je_cv_libstdcxx])
303    if test "x${je_cv_libstdcxx}" = "xno" ; then
304      LIBS="${SAVED_LIBS}"
305    fi
306  else
307    enable_cxx="0"
308  fi
309fi
310AC_SUBST([enable_cxx])
311AC_SUBST([CONFIGURE_CXXFLAGS])
312AC_SUBST([SPECIFIED_CXXFLAGS])
313AC_SUBST([EXTRA_CXXFLAGS])
314
315AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
316if test "x${ac_cv_big_endian}" = "x1" ; then
317  AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
318fi
319
320if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
321  JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat/C99)
322fi
323
324if test "x${je_cv_msvc}" = "xyes" ; then
325  LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
326  AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
327else
328  AC_CHECK_SIZEOF([void *])
329  if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
330    LG_SIZEOF_PTR=3
331  elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
332    LG_SIZEOF_PTR=2
333  else
334    AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
335  fi
336fi
337AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
338
339AC_CHECK_SIZEOF([int])
340if test "x${ac_cv_sizeof_int}" = "x8" ; then
341  LG_SIZEOF_INT=3
342elif test "x${ac_cv_sizeof_int}" = "x4" ; then
343  LG_SIZEOF_INT=2
344else
345  AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
346fi
347AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
348
349AC_CHECK_SIZEOF([long])
350if test "x${ac_cv_sizeof_long}" = "x8" ; then
351  LG_SIZEOF_LONG=3
352elif test "x${ac_cv_sizeof_long}" = "x4" ; then
353  LG_SIZEOF_LONG=2
354else
355  AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
356fi
357AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
358
359AC_CHECK_SIZEOF([long long])
360if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
361  LG_SIZEOF_LONG_LONG=3
362elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
363  LG_SIZEOF_LONG_LONG=2
364else
365  AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
366fi
367AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
368
369AC_CHECK_SIZEOF([intmax_t])
370if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
371  LG_SIZEOF_INTMAX_T=4
372elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
373  LG_SIZEOF_INTMAX_T=3
374elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
375  LG_SIZEOF_INTMAX_T=2
376else
377  AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
378fi
379AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
380
381AC_CANONICAL_HOST
382dnl CPU-specific settings.
383CPU_SPINWAIT=""
384case "${host_cpu}" in
385  i686|x86_64)
386	HAVE_CPU_SPINWAIT=1
387	if test "x${je_cv_msvc}" = "xyes" ; then
388	    AC_CACHE_VAL([je_cv_pause_msvc],
389	      [JE_COMPILABLE([pause instruction MSVC], [],
390					[[_mm_pause(); return 0;]],
391					[je_cv_pause_msvc])])
392	    if test "x${je_cv_pause_msvc}" = "xyes" ; then
393		CPU_SPINWAIT='_mm_pause()'
394	    fi
395	else
396	    AC_CACHE_VAL([je_cv_pause],
397	      [JE_COMPILABLE([pause instruction], [],
398					[[__asm__ volatile("pause"); return 0;]],
399					[je_cv_pause])])
400	    if test "x${je_cv_pause}" = "xyes" ; then
401		CPU_SPINWAIT='__asm__ volatile("pause")'
402	    fi
403	fi
404	;;
405  *)
406	HAVE_CPU_SPINWAIT=0
407	;;
408esac
409AC_DEFINE_UNQUOTED([HAVE_CPU_SPINWAIT], [$HAVE_CPU_SPINWAIT])
410AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
411
412AC_ARG_WITH([lg_vaddr],
413  [AS_HELP_STRING([--with-lg-vaddr=<lg-vaddr>], [Number of significant virtual address bits])],
414  [LG_VADDR="$with_lg_vaddr"], [LG_VADDR="detect"])
415
416case "${host_cpu}" in
417  aarch64)
418    if test "x$LG_VADDR" = "xdetect"; then
419      AC_MSG_CHECKING([number of significant virtual address bits])
420      if test "x${LG_SIZEOF_PTR}" = "x2" ; then
421        #aarch64 ILP32
422        LG_VADDR=32
423      else
424        #aarch64 LP64
425        LG_VADDR=48
426      fi
427      AC_MSG_RESULT([$LG_VADDR])
428    fi
429    ;;
430  x86_64)
431    if test "x$LG_VADDR" = "xdetect"; then
432      AC_CACHE_CHECK([number of significant virtual address bits],
433                     [je_cv_lg_vaddr],
434                     AC_RUN_IFELSE([AC_LANG_PROGRAM(
435[[
436#include <stdio.h>
437#ifdef _WIN32
438#include <limits.h>
439#include <intrin.h>
440typedef unsigned __int32 uint32_t;
441#else
442#include <stdint.h>
443#endif
444]], [[
445	uint32_t r[[4]];
446	uint32_t eax_in = 0x80000008U;
447#ifdef _WIN32
448	__cpuid((int *)r, (int)eax_in);
449#else
450	asm volatile ("cpuid"
451	    : "=a" (r[[0]]), "=b" (r[[1]]), "=c" (r[[2]]), "=d" (r[[3]])
452	    : "a" (eax_in), "c" (0)
453	);
454#endif
455	uint32_t eax_out = r[[0]];
456	uint32_t vaddr = ((eax_out & 0x0000ff00U) >> 8);
457	FILE *f = fopen("conftest.out", "w");
458	if (f == NULL) {
459		return 1;
460	}
461	if (vaddr > (sizeof(void *) << 3)) {
462		vaddr = sizeof(void *) << 3;
463	}
464	fprintf(f, "%u", vaddr);
465	fclose(f);
466	return 0;
467]])],
468                   [je_cv_lg_vaddr=`cat conftest.out`],
469                   [je_cv_lg_vaddr=error],
470                   [je_cv_lg_vaddr=57]))
471      if test "x${je_cv_lg_vaddr}" != "x" ; then
472        LG_VADDR="${je_cv_lg_vaddr}"
473      fi
474      if test "x${LG_VADDR}" != "xerror" ; then
475        AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
476      else
477        AC_MSG_ERROR([cannot determine number of significant virtual address bits])
478      fi
479    fi
480    ;;
481  *)
482    if test "x$LG_VADDR" = "xdetect"; then
483      AC_MSG_CHECKING([number of significant virtual address bits])
484      if test "x${LG_SIZEOF_PTR}" = "x3" ; then
485        LG_VADDR=64
486      elif test "x${LG_SIZEOF_PTR}" = "x2" ; then
487        LG_VADDR=32
488      elif test "x${LG_SIZEOF_PTR}" = "xLG_SIZEOF_PTR_WIN" ; then
489        LG_VADDR="(1U << (LG_SIZEOF_PTR_WIN+3))"
490      else
491        AC_MSG_ERROR([Unsupported lg(pointer size): ${LG_SIZEOF_PTR}])
492      fi
493      AC_MSG_RESULT([$LG_VADDR])
494    fi
495    ;;
496esac
497AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
498
499LD_PRELOAD_VAR="LD_PRELOAD"
500so="so"
501importlib="${so}"
502o="$ac_objext"
503a="a"
504exe="$ac_exeext"
505libprefix="lib"
506link_whole_archive="0"
507DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
508RPATH='-Wl,-rpath,$(1)'
509SOREV="${so}.${rev}"
510PIC_CFLAGS='-fPIC -DPIC'
511CTARGET='-o $@'
512LDTARGET='-o $@'
513TEST_LD_MODE=
514EXTRA_LDFLAGS=
515ARFLAGS='crus'
516AROUT=' $@'
517CC_MM=1
518
519if test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
520  TEST_LD_MODE='-dynamic'
521fi
522
523if test "x${je_cv_cray}" = "xyes" ; then
524  CC_MM=
525fi
526
527AN_MAKEVAR([AR], [AC_PROG_AR])
528AN_PROGRAM([ar], [AC_PROG_AR])
529AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
530AC_PROG_AR
531
532AN_MAKEVAR([NM], [AC_PROG_NM])
533AN_PROGRAM([nm], [AC_PROG_NM])
534AC_DEFUN([AC_PROG_NM], [AC_CHECK_TOOL(NM, nm, :)])
535AC_PROG_NM
536
537AC_PROG_AWK
538
539dnl Platform-specific settings.  abi and RPATH can probably be determined
540dnl programmatically, but doing so is error-prone, which makes it generally
541dnl not worth the trouble.
542dnl
543dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
544dnl definitions need to be seen before any headers are included, which is a pain
545dnl to make happen otherwise.
546default_retain="0"
547maps_coalesce="1"
548DUMP_SYMS="${NM} -a"
549SYM_PREFIX=""
550case "${host}" in
551  *-*-darwin* | *-*-ios*)
552	abi="macho"
553	RPATH=""
554	LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
555	so="dylib"
556	importlib="${so}"
557	force_tls="0"
558	DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
559	SOREV="${rev}.${so}"
560	sbrk_deprecated="1"
561	SYM_PREFIX="_"
562	;;
563  *-*-freebsd*)
564	abi="elf"
565	AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
566	force_lazy_lock="1"
567	;;
568  *-*-dragonfly*)
569	abi="elf"
570	;;
571  *-*-openbsd*)
572	abi="elf"
573	force_tls="0"
574	;;
575  *-*-bitrig*)
576	abi="elf"
577	;;
578  *-*-linux-android)
579	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
580	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
581	abi="elf"
582	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
583	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
584	AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
585	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
586	AC_DEFINE([JEMALLOC_C11_ATOMICS])
587	force_tls="0"
588	if test "${LG_SIZEOF_PTR}" = "3"; then
589	  default_retain="1"
590	fi
591	;;
592  *-*-linux*)
593	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
594	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
595	abi="elf"
596	AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
597	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
598	AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
599	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
600	AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
601	if test "${LG_SIZEOF_PTR}" = "3"; then
602	  default_retain="1"
603	fi
604	;;
605  *-*-kfreebsd*)
606	dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
607	JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
608	abi="elf"
609	AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
610	AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
611	AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
612	AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
613	;;
614  *-*-netbsd*)
615	AC_MSG_CHECKING([ABI])
616        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
617[[#ifdef __ELF__
618/* ELF */
619#else
620#error aout
621#endif
622]])],
623                          [abi="elf"],
624                          [abi="aout"])
625	AC_MSG_RESULT([$abi])
626	;;
627  *-*-solaris2*)
628	abi="elf"
629	RPATH='-Wl,-R,$(1)'
630	dnl Solaris needs this for sigwait().
631	JE_APPEND_VS(CPPFLAGS, -D_POSIX_PTHREAD_SEMANTICS)
632	JE_APPEND_VS(LIBS, -lposix4 -lsocket -lnsl)
633	;;
634  *-ibm-aix*)
635	if test "${LG_SIZEOF_PTR}" = "3"; then
636	  dnl 64bit AIX
637	  LD_PRELOAD_VAR="LDR_PRELOAD64"
638	else
639	  dnl 32bit AIX
640	  LD_PRELOAD_VAR="LDR_PRELOAD"
641	fi
642	abi="xcoff"
643	;;
644  *-*-mingw* | *-*-cygwin*)
645	abi="pecoff"
646	force_tls="0"
647	maps_coalesce="0"
648	RPATH=""
649	so="dll"
650	if test "x$je_cv_msvc" = "xyes" ; then
651	  importlib="lib"
652	  DSO_LDFLAGS="-LD"
653	  EXTRA_LDFLAGS="-link -DEBUG"
654	  CTARGET='-Fo$@'
655	  LDTARGET='-Fe$@'
656	  AR='lib'
657	  ARFLAGS='-nologo -out:'
658	  AROUT='$@'
659	  CC_MM=
660        else
661	  importlib="${so}"
662	  DSO_LDFLAGS="-shared"
663	  link_whole_archive="1"
664	fi
665	case "${host}" in
666	  *-*-cygwin*)
667	    DUMP_SYMS="dumpbin /SYMBOLS"
668	    ;;
669	  *)
670	    ;;
671	esac
672	a="lib"
673	libprefix=""
674	SOREV="${so}"
675	PIC_CFLAGS=""
676	;;
677  *)
678	AC_MSG_RESULT([Unsupported operating system: ${host}])
679	abi="elf"
680	;;
681esac
682
683JEMALLOC_USABLE_SIZE_CONST=const
684AC_CHECK_HEADERS([malloc.h], [
685  AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
686  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
687    [#include <malloc.h>
688     #include <stddef.h>
689    size_t malloc_usable_size(const void *ptr);
690    ],
691    [])],[
692                AC_MSG_RESULT([yes])
693         ],[
694                JEMALLOC_USABLE_SIZE_CONST=
695                AC_MSG_RESULT([no])
696         ])
697])
698AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
699AC_SUBST([abi])
700AC_SUBST([RPATH])
701AC_SUBST([LD_PRELOAD_VAR])
702AC_SUBST([so])
703AC_SUBST([importlib])
704AC_SUBST([o])
705AC_SUBST([a])
706AC_SUBST([exe])
707AC_SUBST([libprefix])
708AC_SUBST([link_whole_archive])
709AC_SUBST([DSO_LDFLAGS])
710AC_SUBST([EXTRA_LDFLAGS])
711AC_SUBST([SOREV])
712AC_SUBST([PIC_CFLAGS])
713AC_SUBST([CTARGET])
714AC_SUBST([LDTARGET])
715AC_SUBST([TEST_LD_MODE])
716AC_SUBST([MKLIB])
717AC_SUBST([ARFLAGS])
718AC_SUBST([AROUT])
719AC_SUBST([DUMP_SYMS])
720AC_SUBST([CC_MM])
721
722dnl Determine whether libm must be linked to use e.g. log(3).
723AC_SEARCH_LIBS([log], [m], , [AC_MSG_ERROR([Missing math functions])])
724if test "x$ac_cv_search_log" != "xnone required" ; then
725  LM="$ac_cv_search_log"
726else
727  LM=
728fi
729AC_SUBST(LM)
730
731JE_COMPILABLE([__attribute__ syntax],
732              [static __attribute__((unused)) void foo(void){}],
733              [],
734              [je_cv_attribute])
735if test "x${je_cv_attribute}" = "xyes" ; then
736  AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
737  if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
738    JE_CFLAGS_ADD([-fvisibility=hidden])
739    JE_CXXFLAGS_ADD([-fvisibility=hidden])
740  fi
741fi
742dnl Check for tls_model attribute support (clang 3.0 still lacks support).
743JE_CFLAGS_SAVE()
744JE_CFLAGS_ADD([-Werror])
745JE_CFLAGS_ADD([-herror_on_warning])
746JE_COMPILABLE([tls_model attribute], [],
747              [static __thread int
748               __attribute__((tls_model("initial-exec"), unused)) foo;
749               foo = 0;],
750              [je_cv_tls_model])
751JE_CFLAGS_RESTORE()
752dnl (Setting of JEMALLOC_TLS_MODEL is done later, after we've checked for
753dnl --disable-initial-exec-tls)
754
755dnl Check for alloc_size attribute support.
756JE_CFLAGS_SAVE()
757JE_CFLAGS_ADD([-Werror])
758JE_CFLAGS_ADD([-herror_on_warning])
759JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
760              [void *foo(size_t size) __attribute__((alloc_size(1)));],
761              [je_cv_alloc_size])
762JE_CFLAGS_RESTORE()
763if test "x${je_cv_alloc_size}" = "xyes" ; then
764  AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
765fi
766dnl Check for format(gnu_printf, ...) attribute support.
767JE_CFLAGS_SAVE()
768JE_CFLAGS_ADD([-Werror])
769JE_CFLAGS_ADD([-herror_on_warning])
770JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
771              [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
772              [je_cv_format_gnu_printf])
773JE_CFLAGS_RESTORE()
774if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
775  AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
776fi
777dnl Check for format(printf, ...) attribute support.
778JE_CFLAGS_SAVE()
779JE_CFLAGS_ADD([-Werror])
780JE_CFLAGS_ADD([-herror_on_warning])
781JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
782              [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
783              [je_cv_format_printf])
784JE_CFLAGS_RESTORE()
785if test "x${je_cv_format_printf}" = "xyes" ; then
786  AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
787fi
788
789dnl Support optional additions to rpath.
790AC_ARG_WITH([rpath],
791  [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
792if test "x$with_rpath" = "xno" ; then
793  RPATH_EXTRA=
794else
795  RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
796fi,
797  RPATH_EXTRA=
798)
799AC_SUBST([RPATH_EXTRA])
800
801dnl Disable rules that do automatic regeneration of configure output by default.
802AC_ARG_ENABLE([autogen],
803  [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
804if test "x$enable_autogen" = "xno" ; then
805  enable_autogen="0"
806else
807  enable_autogen="1"
808fi
809,
810enable_autogen="0"
811)
812AC_SUBST([enable_autogen])
813
814AC_PROG_INSTALL
815AC_PROG_RANLIB
816AC_PATH_PROG([LD], [ld], [false], [$PATH])
817AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
818
819dnl Perform no name mangling by default.
820AC_ARG_WITH([mangling],
821  [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
822  [mangling_map="$with_mangling"], [mangling_map=""])
823
824dnl Do not prefix public APIs by default.
825AC_ARG_WITH([jemalloc_prefix],
826  [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
827  [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
828  [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
829  JEMALLOC_PREFIX=""
830else
831  JEMALLOC_PREFIX="je_"
832fi]
833)
834if test "x$JEMALLOC_PREFIX" = "x" ; then
835  AC_DEFINE([JEMALLOC_IS_MALLOC])
836else
837  JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
838  AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
839  AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
840fi
841AC_SUBST([JEMALLOC_PREFIX])
842AC_SUBST([JEMALLOC_CPREFIX])
843
844AC_ARG_WITH([export],
845  [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
846  [if test "x$with_export" = "xno"; then
847  AC_DEFINE([JEMALLOC_EXPORT],[])
848fi]
849)
850
851public_syms="aligned_alloc calloc dallocx free mallctl mallctlbymib mallctlnametomib malloc malloc_conf malloc_message malloc_stats_print malloc_usable_size mallocx nallocx posix_memalign rallocx realloc sallocx sdallocx xallocx"
852dnl Check for additional platform-specific public API functions.
853AC_CHECK_FUNC([memalign],
854	      [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
855	       public_syms="${public_syms} memalign"])
856AC_CHECK_FUNC([valloc],
857	      [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
858	       public_syms="${public_syms} valloc"])
859
860dnl Check for allocator-related functions that should be wrapped.
861wrap_syms=
862if test "x${JEMALLOC_PREFIX}" = "x" ; then
863  AC_CHECK_FUNC([__libc_calloc],
864		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_CALLOC], [ ])
865		 wrap_syms="${wrap_syms} __libc_calloc"])
866  AC_CHECK_FUNC([__libc_free],
867		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_FREE], [ ])
868		 wrap_syms="${wrap_syms} __libc_free"])
869  AC_CHECK_FUNC([__libc_malloc],
870		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MALLOC], [ ])
871		 wrap_syms="${wrap_syms} __libc_malloc"])
872  AC_CHECK_FUNC([__libc_memalign],
873		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MEMALIGN], [ ])
874		 wrap_syms="${wrap_syms} __libc_memalign"])
875  AC_CHECK_FUNC([__libc_realloc],
876		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_REALLOC], [ ])
877		 wrap_syms="${wrap_syms} __libc_realloc"])
878  AC_CHECK_FUNC([__libc_valloc],
879		[AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_VALLOC], [ ])
880		 wrap_syms="${wrap_syms} __libc_valloc"])
881  AC_CHECK_FUNC([__posix_memalign],
882		[AC_DEFINE([JEMALLOC_OVERRIDE___POSIX_MEMALIGN], [ ])
883		 wrap_syms="${wrap_syms} __posix_memalign"])
884fi
885
886case "${host}" in
887  *-*-mingw* | *-*-cygwin*)
888    wrap_syms="${wrap_syms} tls_callback"
889    ;;
890  *)
891    ;;
892esac
893
894dnl Mangle library-private APIs.
895AC_ARG_WITH([private_namespace],
896  [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
897  [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
898  [JEMALLOC_PRIVATE_NAMESPACE="je_"]
899)
900AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
901private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
902AC_SUBST([private_namespace])
903
904dnl Do not add suffix to installed files by default.
905AC_ARG_WITH([install_suffix],
906  [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
907  [INSTALL_SUFFIX="$with_install_suffix"],
908  [INSTALL_SUFFIX=]
909)
910install_suffix="$INSTALL_SUFFIX"
911AC_SUBST([install_suffix])
912
913dnl Specify default malloc_conf.
914AC_ARG_WITH([malloc_conf],
915  [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
916  [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
917  [JEMALLOC_CONFIG_MALLOC_CONF=""]
918)
919config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
920AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
921
922dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
923dnl jemalloc_protos_jet.h easy.
924je_="je_"
925AC_SUBST([je_])
926
927cfgoutputs_in="Makefile.in"
928cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
929cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
930cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
931cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
932cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
933cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
934cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
935cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_preamble.h.in"
936cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
937cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
938
939cfgoutputs_out="Makefile"
940cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
941cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
942cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
943cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
944cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
945cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
946cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
947cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_preamble.h"
948cfgoutputs_out="${cfgoutputs_out} test/test.sh"
949cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
950
951cfgoutputs_tup="Makefile"
952cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
953cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
954cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
955cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
956cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
957cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
958cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
959cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_preamble.h"
960cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
961cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
962
963cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
964cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
965cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.sh"
966cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
967cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
968cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
969cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
970cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
971cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
972cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
973cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
974
975cfghdrs_out="include/jemalloc/jemalloc_defs.h"
976cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
977cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols.awk"
978cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols_jet.awk"
979cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
980cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
981cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
982cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
983cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
984cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
985cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
986cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
987cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
988cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
989
990cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
991cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
992cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
993
994dnl Do not compile with debugging by default.
995AC_ARG_ENABLE([debug],
996  [AS_HELP_STRING([--enable-debug],
997                  [Build debugging code])],
998[if test "x$enable_debug" = "xno" ; then
999  enable_debug="0"
1000else
1001  enable_debug="1"
1002fi
1003],
1004[enable_debug="0"]
1005)
1006if test "x$enable_debug" = "x1" ; then
1007  AC_DEFINE([JEMALLOC_DEBUG], [ ])
1008fi
1009if test "x$enable_debug" = "x1" ; then
1010  AC_DEFINE([JEMALLOC_DEBUG], [ ])
1011fi
1012AC_SUBST([enable_debug])
1013
1014dnl Only optimize if not debugging.
1015if test "x$enable_debug" = "x0" ; then
1016  if test "x$GCC" = "xyes" ; then
1017    JE_CFLAGS_ADD([-O3])
1018    JE_CXXFLAGS_ADD([-O3])
1019    JE_CFLAGS_ADD([-funroll-loops])
1020  elif test "x$je_cv_msvc" = "xyes" ; then
1021    JE_CFLAGS_ADD([-O2])
1022    JE_CXXFLAGS_ADD([-O2])
1023  else
1024    JE_CFLAGS_ADD([-O])
1025    JE_CXXFLAGS_ADD([-O])
1026  fi
1027fi
1028
1029dnl Enable statistics calculation by default.
1030AC_ARG_ENABLE([stats],
1031  [AS_HELP_STRING([--disable-stats],
1032                  [Disable statistics calculation/reporting])],
1033[if test "x$enable_stats" = "xno" ; then
1034  enable_stats="0"
1035else
1036  enable_stats="1"
1037fi
1038],
1039[enable_stats="1"]
1040)
1041if test "x$enable_stats" = "x1" ; then
1042  AC_DEFINE([JEMALLOC_STATS], [ ])
1043fi
1044AC_SUBST([enable_stats])
1045
1046dnl Do not enable profiling by default.
1047AC_ARG_ENABLE([prof],
1048  [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
1049[if test "x$enable_prof" = "xno" ; then
1050  enable_prof="0"
1051else
1052  enable_prof="1"
1053fi
1054],
1055[enable_prof="0"]
1056)
1057if test "x$enable_prof" = "x1" ; then
1058  backtrace_method=""
1059else
1060  backtrace_method="N/A"
1061fi
1062
1063AC_ARG_ENABLE([prof-libunwind],
1064  [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
1065[if test "x$enable_prof_libunwind" = "xno" ; then
1066  enable_prof_libunwind="0"
1067else
1068  enable_prof_libunwind="1"
1069fi
1070],
1071[enable_prof_libunwind="0"]
1072)
1073AC_ARG_WITH([static_libunwind],
1074  [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
1075  [Path to static libunwind library; use rather than dynamically linking])],
1076if test "x$with_static_libunwind" = "xno" ; then
1077  LUNWIND="-lunwind"
1078else
1079  if test ! -f "$with_static_libunwind" ; then
1080    AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
1081  fi
1082  LUNWIND="$with_static_libunwind"
1083fi,
1084  LUNWIND="-lunwind"
1085)
1086if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
1087  AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
1088  if test "x$LUNWIND" = "x-lunwind" ; then
1089    AC_CHECK_LIB([unwind], [unw_backtrace], [JE_APPEND_VS(LIBS, $LUNWIND)],
1090                 [enable_prof_libunwind="0"])
1091  else
1092    JE_APPEND_VS(LIBS, $LUNWIND)
1093  fi
1094  if test "x${enable_prof_libunwind}" = "x1" ; then
1095    backtrace_method="libunwind"
1096    AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
1097  fi
1098fi
1099
1100AC_ARG_ENABLE([prof-libgcc],
1101  [AS_HELP_STRING([--disable-prof-libgcc],
1102  [Do not use libgcc for backtracing])],
1103[if test "x$enable_prof_libgcc" = "xno" ; then
1104  enable_prof_libgcc="0"
1105else
1106  enable_prof_libgcc="1"
1107fi
1108],
1109[enable_prof_libgcc="1"]
1110)
1111if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
1112     -a "x$GCC" = "xyes" ; then
1113  AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
1114  if test "x${enable_prof_libgcc}" = "x1" ; then
1115    AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [JE_APPEND_VS(LIBS, -lgcc)], [enable_prof_libgcc="0"])
1116  fi
1117  if test "x${enable_prof_libgcc}" = "x1" ; then
1118    backtrace_method="libgcc"
1119    AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
1120  fi
1121else
1122  enable_prof_libgcc="0"
1123fi
1124
1125AC_ARG_ENABLE([prof-gcc],
1126  [AS_HELP_STRING([--disable-prof-gcc],
1127  [Do not use gcc intrinsics for backtracing])],
1128[if test "x$enable_prof_gcc" = "xno" ; then
1129  enable_prof_gcc="0"
1130else
1131  enable_prof_gcc="1"
1132fi
1133],
1134[enable_prof_gcc="1"]
1135)
1136if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
1137     -a "x$GCC" = "xyes" ; then
1138  JE_CFLAGS_ADD([-fno-omit-frame-pointer])
1139  backtrace_method="gcc intrinsics"
1140  AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
1141else
1142  enable_prof_gcc="0"
1143fi
1144
1145if test "x$backtrace_method" = "x" ; then
1146  backtrace_method="none (disabling profiling)"
1147  enable_prof="0"
1148fi
1149AC_MSG_CHECKING([configured backtracing method])
1150AC_MSG_RESULT([$backtrace_method])
1151if test "x$enable_prof" = "x1" ; then
1152  dnl Heap profiling uses the log(3) function.
1153  JE_APPEND_VS(LIBS, $LM)
1154
1155  AC_DEFINE([JEMALLOC_PROF], [ ])
1156fi
1157AC_SUBST([enable_prof])
1158
1159dnl Indicate whether adjacent virtual memory mappings automatically coalesce
1160dnl (and fragment on demand).
1161if test "x${maps_coalesce}" = "x1" ; then
1162  AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
1163fi
1164
1165dnl Indicate whether to retain memory (rather than using munmap()) by default.
1166if test "x$default_retain" = "x1" ; then
1167  AC_DEFINE([JEMALLOC_RETAIN], [ ])
1168fi
1169
1170dnl Enable allocation from DSS if supported by the OS.
1171have_dss="1"
1172dnl Check whether the BSD/SUSv1 sbrk() exists.  If not, disable DSS support.
1173AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
1174if test "x$have_sbrk" = "x1" ; then
1175  if test "x$sbrk_deprecated" = "x1" ; then
1176    AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
1177    have_dss="0"
1178  fi
1179else
1180  have_dss="0"
1181fi
1182
1183if test "x$have_dss" = "x1" ; then
1184  AC_DEFINE([JEMALLOC_DSS], [ ])
1185fi
1186
1187dnl Support the junk/zero filling option by default.
1188AC_ARG_ENABLE([fill],
1189  [AS_HELP_STRING([--disable-fill], [Disable support for junk/zero filling])],
1190[if test "x$enable_fill" = "xno" ; then
1191  enable_fill="0"
1192else
1193  enable_fill="1"
1194fi
1195],
1196[enable_fill="1"]
1197)
1198if test "x$enable_fill" = "x1" ; then
1199  AC_DEFINE([JEMALLOC_FILL], [ ])
1200fi
1201AC_SUBST([enable_fill])
1202
1203dnl Disable utrace(2)-based tracing by default.
1204AC_ARG_ENABLE([utrace],
1205  [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
1206[if test "x$enable_utrace" = "xno" ; then
1207  enable_utrace="0"
1208else
1209  enable_utrace="1"
1210fi
1211],
1212[enable_utrace="0"]
1213)
1214JE_COMPILABLE([utrace(2)], [
1215#include <sys/types.h>
1216#include <sys/param.h>
1217#include <sys/time.h>
1218#include <sys/uio.h>
1219#include <sys/ktrace.h>
1220], [
1221	utrace((void *)0, 0);
1222], [je_cv_utrace])
1223if test "x${je_cv_utrace}" = "xno" ; then
1224  enable_utrace="0"
1225fi
1226if test "x$enable_utrace" = "x1" ; then
1227  AC_DEFINE([JEMALLOC_UTRACE], [ ])
1228fi
1229AC_SUBST([enable_utrace])
1230
1231dnl Do not support the xmalloc option by default.
1232AC_ARG_ENABLE([xmalloc],
1233  [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1234[if test "x$enable_xmalloc" = "xno" ; then
1235  enable_xmalloc="0"
1236else
1237  enable_xmalloc="1"
1238fi
1239],
1240[enable_xmalloc="0"]
1241)
1242if test "x$enable_xmalloc" = "x1" ; then
1243  AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1244fi
1245AC_SUBST([enable_xmalloc])
1246
1247dnl Support cache-oblivious allocation alignment by default.
1248AC_ARG_ENABLE([cache-oblivious],
1249  [AS_HELP_STRING([--disable-cache-oblivious],
1250                  [Disable support for cache-oblivious allocation alignment])],
1251[if test "x$enable_cache_oblivious" = "xno" ; then
1252  enable_cache_oblivious="0"
1253else
1254  enable_cache_oblivious="1"
1255fi
1256],
1257[enable_cache_oblivious="1"]
1258)
1259if test "x$enable_cache_oblivious" = "x1" ; then
1260  AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1261fi
1262AC_SUBST([enable_cache_oblivious])
1263
1264dnl Do not log by default.
1265AC_ARG_ENABLE([log],
1266  [AS_HELP_STRING([--enable-log], [Support debug logging])],
1267[if test "x$enable_log" = "xno" ; then
1268  enable_log="0"
1269else
1270  enable_log="1"
1271fi
1272],
1273[enable_log="0"]
1274)
1275if test "x$enable_log" = "x1" ; then
1276  AC_DEFINE([JEMALLOC_LOG], [ ])
1277fi
1278AC_SUBST([enable_log])
1279
1280
1281JE_COMPILABLE([a program using __builtin_unreachable], [
1282void foo (void) {
1283  __builtin_unreachable();
1284}
1285], [
1286	{
1287		foo();
1288	}
1289], [je_cv_gcc_builtin_unreachable])
1290if test "x${je_cv_gcc_builtin_unreachable}" = "xyes" ; then
1291  AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [__builtin_unreachable])
1292else
1293  AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [abort])
1294fi
1295
1296dnl ============================================================================
1297dnl Check for  __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1298dnl One of those two functions should (theoretically) exist on all platforms
1299dnl that jemalloc currently has a chance of functioning on without modification.
1300dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
1301dnl ffsl() or __builtin_ffsl() are defined, respectively.
1302JE_COMPILABLE([a program using __builtin_ffsl], [
1303#include <stdio.h>
1304#include <strings.h>
1305#include <string.h>
1306], [
1307	{
1308		int rv = __builtin_ffsl(0x08);
1309		printf("%d\n", rv);
1310	}
1311], [je_cv_gcc_builtin_ffsl])
1312if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
1313  AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
1314  AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1315  AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1316else
1317  JE_COMPILABLE([a program using ffsl], [
1318  #include <stdio.h>
1319  #include <strings.h>
1320  #include <string.h>
1321  ], [
1322	{
1323		int rv = ffsl(0x08);
1324		printf("%d\n", rv);
1325	}
1326  ], [je_cv_function_ffsl])
1327  if test "x${je_cv_function_ffsl}" = "xyes" ; then
1328    AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
1329    AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1330    AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1331  else
1332    AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1333  fi
1334fi
1335
1336AC_ARG_WITH([lg_quantum],
1337  [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1338   [Base 2 log of minimum allocation alignment])],
1339  [LG_QUANTA="$with_lg_quantum"],
1340  [LG_QUANTA="3 4"])
1341if test "x$with_lg_quantum" != "x" ; then
1342  AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1343fi
1344
1345AC_ARG_WITH([lg_page],
1346  [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1347  [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
1348if test "x$LG_PAGE" = "xdetect"; then
1349  AC_CACHE_CHECK([LG_PAGE],
1350               [je_cv_lg_page],
1351               AC_RUN_IFELSE([AC_LANG_PROGRAM(
1352[[
1353#include <strings.h>
1354#ifdef _WIN32
1355#include <windows.h>
1356#else
1357#include <unistd.h>
1358#endif
1359#include <stdio.h>
1360]],
1361[[
1362    int result;
1363    FILE *f;
1364
1365#ifdef _WIN32
1366    SYSTEM_INFO si;
1367    GetSystemInfo(&si);
1368    result = si.dwPageSize;
1369#else
1370    result = sysconf(_SC_PAGESIZE);
1371#endif
1372    if (result == -1) {
1373	return 1;
1374    }
1375    result = JEMALLOC_INTERNAL_FFSL(result) - 1;
1376
1377    f = fopen("conftest.out", "w");
1378    if (f == NULL) {
1379	return 1;
1380    }
1381    fprintf(f, "%d", result);
1382    fclose(f);
1383
1384    return 0;
1385]])],
1386                             [je_cv_lg_page=`cat conftest.out`],
1387                             [je_cv_lg_page=undefined],
1388                             [je_cv_lg_page=12]))
1389fi
1390if test "x${je_cv_lg_page}" != "x" ; then
1391  LG_PAGE="${je_cv_lg_page}"
1392fi
1393if test "x${LG_PAGE}" != "xundefined" ; then
1394   AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1395else
1396   AC_MSG_ERROR([cannot determine value for LG_PAGE])
1397fi
1398
1399AC_ARG_WITH([lg_hugepage],
1400  [AS_HELP_STRING([--with-lg-hugepage=<lg-hugepage>],
1401   [Base 2 log of system huge page size])],
1402  [je_cv_lg_hugepage="${with_lg_hugepage}"],
1403  [je_cv_lg_hugepage=""])
1404if test "x${je_cv_lg_hugepage}" = "x" ; then
1405  dnl Look in /proc/meminfo (Linux-specific) for information on the default huge
1406  dnl page size, if any.  The relevant line looks like:
1407  dnl
1408  dnl   Hugepagesize:       2048 kB
1409  if test -e "/proc/meminfo" ; then
1410    hpsk=[`cat /proc/meminfo 2>/dev/null | \
1411          grep -e '^Hugepagesize:[[:space:]]\+[0-9]\+[[:space:]]kB$' | \
1412          awk '{print $2}'`]
1413    if test "x${hpsk}" != "x" ; then
1414      je_cv_lg_hugepage=10
1415      while test "${hpsk}" -gt 1 ; do
1416        hpsk="$((hpsk / 2))"
1417        je_cv_lg_hugepage="$((je_cv_lg_hugepage + 1))"
1418      done
1419    fi
1420  fi
1421
1422  dnl Set default if unable to automatically configure.
1423  if test "x${je_cv_lg_hugepage}" = "x" ; then
1424    je_cv_lg_hugepage=21
1425  fi
1426fi
1427if test "x${LG_PAGE}" != "xundefined" -a \
1428        "${je_cv_lg_hugepage}" -lt "${LG_PAGE}" ; then
1429  AC_MSG_ERROR([Huge page size (2^${je_cv_lg_hugepage}) must be at least page size (2^${LG_PAGE})])
1430fi
1431AC_DEFINE_UNQUOTED([LG_HUGEPAGE], [${je_cv_lg_hugepage}])
1432
1433AC_ARG_WITH([lg_page_sizes],
1434  [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1435   [Base 2 logs of system page sizes to support])],
1436  [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1437
1438dnl ============================================================================
1439dnl jemalloc configuration.
1440dnl
1441
1442AC_ARG_WITH([version],
1443  [AS_HELP_STRING([--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid>],
1444   [Version string])],
1445  [
1446    echo "${with_version}" | grep ['^[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+-g[0-9a-f]\+$'] 2>&1 1>/dev/null
1447    if test $? -eq 0 ; then
1448      echo "$with_version" > "${objroot}VERSION"
1449    else
1450      echo "${with_version}" | grep ['^VERSION$'] 2>&1 1>/dev/null
1451      if test $? -ne 0 ; then
1452        AC_MSG_ERROR([${with_version} does not match <major>.<minor>.<bugfix>-<nrev>-g<gid> or VERSION])
1453      fi
1454    fi
1455  ], [
1456    dnl Set VERSION if source directory is inside a git repository.
1457    if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
1458      dnl Pattern globs aren't powerful enough to match both single- and
1459      dnl double-digit version numbers, so iterate over patterns to support up
1460      dnl to version 99.99.99 without any accidental matches.
1461      for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1462                     '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1463                     '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1464                     '[0-9][0-9].[0-9][0-9].[0-9]' \
1465                     '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
1466        (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
1467        if test $? -eq 0 ; then
1468          mv "${objroot}VERSION.tmp" "${objroot}VERSION"
1469          break
1470        fi
1471      done
1472    fi
1473    rm -f "${objroot}VERSION.tmp"
1474  ])
1475
1476if test ! -e "${objroot}VERSION" ; then
1477  if test ! -e "${srcroot}VERSION" ; then
1478    AC_MSG_RESULT(
1479      [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1480    echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1481  else
1482    cp ${srcroot}VERSION ${objroot}VERSION
1483  fi
1484fi
1485jemalloc_version=`cat "${objroot}VERSION"`
1486jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1487jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1488jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1489jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1490jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
1491AC_SUBST([jemalloc_version])
1492AC_SUBST([jemalloc_version_major])
1493AC_SUBST([jemalloc_version_minor])
1494AC_SUBST([jemalloc_version_bugfix])
1495AC_SUBST([jemalloc_version_nrev])
1496AC_SUBST([jemalloc_version_gid])
1497
1498dnl ============================================================================
1499dnl Configure pthreads.
1500
1501if test "x$abi" != "xpecoff" ; then
1502  AC_DEFINE([JEMALLOC_HAVE_PTHREAD], [ ])
1503  AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1504  dnl Some systems may embed pthreads functionality in libc; check for libpthread
1505  dnl first, but try libc too before failing.
1506  AC_CHECK_LIB([pthread], [pthread_create], [JE_APPEND_VS(LIBS, -lpthread)],
1507               [AC_SEARCH_LIBS([pthread_create], , ,
1508                               AC_MSG_ERROR([libpthread is missing]))])
1509  wrap_syms="${wrap_syms} pthread_create"
1510  have_pthread="1"
1511  dnl Check if we have dlsym support.
1512  have_dlsym="1"
1513  AC_CHECK_HEADERS([dlfcn.h],
1514    AC_CHECK_FUNC([dlsym], [],
1515      [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"], [have_dlsym="0"])]),
1516    [have_dlsym="0"])
1517  if test "x$have_dlsym" = "x1" ; then
1518    AC_DEFINE([JEMALLOC_HAVE_DLSYM], [ ])
1519  fi
1520  JE_COMPILABLE([pthread_atfork(3)], [
1521#include <pthread.h>
1522], [
1523  pthread_atfork((void *)0, (void *)0, (void *)0);
1524], [je_cv_pthread_atfork])
1525  if test "x${je_cv_pthread_atfork}" = "xyes" ; then
1526    AC_DEFINE([JEMALLOC_HAVE_PTHREAD_ATFORK], [ ])
1527  fi
1528  dnl Check if pthread_setname_np is available with the expected API.
1529  JE_COMPILABLE([pthread_setname_np(3)], [
1530#include <pthread.h>
1531], [
1532  pthread_setname_np(pthread_self(), "setname_test");
1533], [je_cv_pthread_setname_np])
1534  if test "x${je_cv_pthread_setname_np}" = "xyes" ; then
1535    AC_DEFINE([JEMALLOC_HAVE_PTHREAD_SETNAME_NP], [ ])
1536  fi
1537fi
1538
1539JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
1540
1541dnl Check whether clock_gettime(2) is in libc or librt.
1542AC_SEARCH_LIBS([clock_gettime], [rt])
1543
1544dnl Cray wrapper compiler often adds `-lrt` when using `-static`. Check with
1545dnl `-dynamic` as well in case a user tries to dynamically link in jemalloc
1546if test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
1547  if test "$ac_cv_search_clock_gettime" != "-lrt"; then
1548    JE_CFLAGS_SAVE()
1549
1550    unset ac_cv_search_clock_gettime
1551    JE_CFLAGS_ADD([-dynamic])
1552    AC_SEARCH_LIBS([clock_gettime], [rt])
1553
1554    JE_CFLAGS_RESTORE()
1555  fi
1556fi
1557
1558dnl check for CLOCK_MONOTONIC_COARSE (Linux-specific).
1559JE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC_COARSE, ...)], [
1560#include <time.h>
1561], [
1562	struct timespec ts;
1563
1564	clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
1565], [je_cv_clock_monotonic_coarse])
1566if test "x${je_cv_clock_monotonic_coarse}" = "xyes" ; then
1567  AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC_COARSE])
1568fi
1569
1570dnl check for CLOCK_MONOTONIC.
1571JE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC, ...)], [
1572#include <unistd.h>
1573#include <time.h>
1574], [
1575	struct timespec ts;
1576
1577	clock_gettime(CLOCK_MONOTONIC, &ts);
1578#if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0
1579#  error _POSIX_MONOTONIC_CLOCK missing/invalid
1580#endif
1581], [je_cv_clock_monotonic])
1582if test "x${je_cv_clock_monotonic}" = "xyes" ; then
1583  AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC])
1584fi
1585
1586dnl Check for mach_absolute_time().
1587JE_COMPILABLE([mach_absolute_time()], [
1588#include <mach/mach_time.h>
1589], [
1590	mach_absolute_time();
1591], [je_cv_mach_absolute_time])
1592if test "x${je_cv_mach_absolute_time}" = "xyes" ; then
1593  AC_DEFINE([JEMALLOC_HAVE_MACH_ABSOLUTE_TIME])
1594fi
1595
1596dnl Use syscall(2) (if available) by default.
1597AC_ARG_ENABLE([syscall],
1598  [AS_HELP_STRING([--disable-syscall], [Disable use of syscall(2)])],
1599[if test "x$enable_syscall" = "xno" ; then
1600  enable_syscall="0"
1601else
1602  enable_syscall="1"
1603fi
1604],
1605[enable_syscall="1"]
1606)
1607if test "x$enable_syscall" = "x1" ; then
1608  dnl Check if syscall(2) is usable.  Treat warnings as errors, so that e.g. OS
1609  dnl X 10.12's deprecation warning prevents use.
1610  JE_CFLAGS_SAVE()
1611  JE_CFLAGS_ADD([-Werror])
1612  JE_COMPILABLE([syscall(2)], [
1613#include <sys/syscall.h>
1614#include <unistd.h>
1615], [
1616	syscall(SYS_write, 2, "hello", 5);
1617],
1618                [je_cv_syscall])
1619  JE_CFLAGS_RESTORE()
1620  if test "x$je_cv_syscall" = "xyes" ; then
1621    AC_DEFINE([JEMALLOC_USE_SYSCALL], [ ])
1622  fi
1623fi
1624
1625dnl Check if the GNU-specific secure_getenv function exists.
1626AC_CHECK_FUNC([secure_getenv],
1627              [have_secure_getenv="1"],
1628              [have_secure_getenv="0"]
1629             )
1630if test "x$have_secure_getenv" = "x1" ; then
1631  AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1632fi
1633
1634dnl Check if the GNU-specific sched_getcpu function exists.
1635AC_CHECK_FUNC([sched_getcpu],
1636              [have_sched_getcpu="1"],
1637              [have_sched_getcpu="0"]
1638             )
1639if test "x$have_sched_getcpu" = "x1" ; then
1640  AC_DEFINE([JEMALLOC_HAVE_SCHED_GETCPU], [ ])
1641fi
1642
1643dnl Check if the GNU-specific sched_setaffinity function exists.
1644AC_CHECK_FUNC([sched_setaffinity],
1645              [have_sched_setaffinity="1"],
1646              [have_sched_setaffinity="0"]
1647             )
1648if test "x$have_sched_setaffinity" = "x1" ; then
1649  AC_DEFINE([JEMALLOC_HAVE_SCHED_SETAFFINITY], [ ])
1650fi
1651
1652dnl Check if the Solaris/BSD issetugid function exists.
1653AC_CHECK_FUNC([issetugid],
1654              [have_issetugid="1"],
1655              [have_issetugid="0"]
1656             )
1657if test "x$have_issetugid" = "x1" ; then
1658  AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1659fi
1660
1661dnl Check whether the BSD-specific _malloc_thread_cleanup() exists.  If so, use
1662dnl it rather than pthreads TSD cleanup functions to support cleanup during
1663dnl thread exit, in order to avoid pthreads library recursion during
1664dnl bootstrapping.
1665AC_CHECK_FUNC([_malloc_thread_cleanup],
1666              [have__malloc_thread_cleanup="1"],
1667              [have__malloc_thread_cleanup="0"]
1668             )
1669if test "x$have__malloc_thread_cleanup" = "x1" ; then
1670  AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1671  wrap_syms="${wrap_syms} _malloc_thread_cleanup"
1672  force_tls="1"
1673fi
1674
1675dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists.  If
1676dnl so, mutex initialization causes allocation, and we need to implement this
1677dnl callback function in order to prevent recursive allocation.
1678AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1679              [have__pthread_mutex_init_calloc_cb="1"],
1680              [have__pthread_mutex_init_calloc_cb="0"]
1681             )
1682if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1683  AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1684  wrap_syms="${wrap_syms} _malloc_prefork _malloc_postfork"
1685fi
1686
1687dnl Disable lazy locking by default.
1688AC_ARG_ENABLE([lazy_lock],
1689  [AS_HELP_STRING([--enable-lazy-lock],
1690  [Enable lazy locking (only lock when multi-threaded)])],
1691[if test "x$enable_lazy_lock" = "xno" ; then
1692  enable_lazy_lock="0"
1693else
1694  enable_lazy_lock="1"
1695fi
1696],
1697[enable_lazy_lock=""]
1698)
1699if test "x${enable_lazy_lock}" = "x" ; then
1700  if test "x${force_lazy_lock}" = "x1" ; then
1701    AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1702    enable_lazy_lock="1"
1703  else
1704    enable_lazy_lock="0"
1705  fi
1706fi
1707if test "x${enable_lazy_lock}" = "x1" -a "x${abi}" = "xpecoff" ; then
1708  AC_MSG_RESULT([Forcing no lazy-lock because thread creation monitoring is unimplemented])
1709  enable_lazy_lock="0"
1710fi
1711if test "x$enable_lazy_lock" = "x1" ; then
1712  if test "x$have_dlsym" = "x1" ; then
1713    AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1714  else
1715    AC_MSG_ERROR([Missing dlsym support: lazy-lock cannot be enabled.])
1716  fi
1717fi
1718AC_SUBST([enable_lazy_lock])
1719
1720dnl Automatically configure TLS.
1721if test "x${force_tls}" = "x1" ; then
1722  enable_tls="1"
1723elif test "x${force_tls}" = "x0" ; then
1724  enable_tls="0"
1725else
1726  enable_tls="1"
1727fi
1728if test "x${enable_tls}" = "x1" ; then
1729AC_MSG_CHECKING([for TLS])
1730AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1731[[
1732    __thread int x;
1733]], [[
1734    x = 42;
1735
1736    return 0;
1737]])],
1738              AC_MSG_RESULT([yes]),
1739              AC_MSG_RESULT([no])
1740              enable_tls="0")
1741else
1742  enable_tls="0"
1743fi
1744AC_SUBST([enable_tls])
1745if test "x${enable_tls}" = "x1" ; then
1746  AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1747fi
1748
1749dnl ============================================================================
1750dnl Check for C11 atomics.
1751
1752JE_COMPILABLE([C11 atomics], [
1753#include <stdint.h>
1754#if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1755#include <stdatomic.h>
1756#else
1757#error Atomics not available
1758#endif
1759], [
1760    uint64_t *p = (uint64_t *)0;
1761    uint64_t x = 1;
1762    volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1763    uint64_t r = atomic_fetch_add(a, x) + x;
1764    return r == 0;
1765], [je_cv_c11_atomics])
1766if test "x${je_cv_c11_atomics}" = "xyes" ; then
1767  AC_DEFINE([JEMALLOC_C11_ATOMICS])
1768fi
1769
1770dnl ============================================================================
1771dnl Check for GCC-style __atomic atomics.
1772
1773JE_COMPILABLE([GCC __atomic atomics], [
1774], [
1775    int x = 0;
1776    int val = 1;
1777    int y = __atomic_fetch_add(&x, val, __ATOMIC_RELAXED);
1778    int after_add = x;
1779    return after_add == 1;
1780], [je_cv_gcc_atomic_atomics])
1781if test "x${je_cv_gcc_atomic_atomics}" = "xyes" ; then
1782  AC_DEFINE([JEMALLOC_GCC_ATOMIC_ATOMICS])
1783fi
1784
1785dnl ============================================================================
1786dnl Check for GCC-style __sync atomics.
1787
1788JE_COMPILABLE([GCC __sync atomics], [
1789], [
1790    int x = 0;
1791    int before_add = __sync_fetch_and_add(&x, 1);
1792    int after_add = x;
1793    return (before_add == 0) && (after_add == 1);
1794], [je_cv_gcc_sync_atomics])
1795if test "x${je_cv_gcc_sync_atomics}" = "xyes" ; then
1796  AC_DEFINE([JEMALLOC_GCC_SYNC_ATOMICS])
1797fi
1798
1799dnl ============================================================================
1800dnl Check for atomic(3) operations as provided on Darwin.
1801dnl We need this not for the atomic operations (which are provided above), but
1802dnl rather for the OSSpinLock type it exposes.
1803
1804JE_COMPILABLE([Darwin OSAtomic*()], [
1805#include <libkern/OSAtomic.h>
1806#include <inttypes.h>
1807], [
1808	{
1809		int32_t x32 = 0;
1810		volatile int32_t *x32p = &x32;
1811		OSAtomicAdd32(1, x32p);
1812	}
1813	{
1814		int64_t x64 = 0;
1815		volatile int64_t *x64p = &x64;
1816		OSAtomicAdd64(1, x64p);
1817	}
1818], [je_cv_osatomic])
1819if test "x${je_cv_osatomic}" = "xyes" ; then
1820  AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1821fi
1822
1823dnl ============================================================================
1824dnl Check for madvise(2).
1825
1826JE_COMPILABLE([madvise(2)], [
1827#include <sys/mman.h>
1828], [
1829	madvise((void *)0, 0, 0);
1830], [je_cv_madvise])
1831if test "x${je_cv_madvise}" = "xyes" ; then
1832  AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1833
1834  dnl Check for madvise(..., MADV_FREE).
1835  JE_COMPILABLE([madvise(..., MADV_FREE)], [
1836#include <sys/mman.h>
1837], [
1838	madvise((void *)0, 0, MADV_FREE);
1839], [je_cv_madv_free])
1840  if test "x${je_cv_madv_free}" = "xyes" ; then
1841    AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
1842  elif test "x${je_cv_madvise}" = "xyes" ; then
1843    case "${host_cpu}" in i686|x86_64)
1844        case "${host}" in *-*-linux*)
1845            AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
1846            AC_DEFINE([JEMALLOC_DEFINE_MADVISE_FREE], [ ])
1847	    ;;
1848        esac
1849        ;;
1850    esac
1851  fi
1852
1853  dnl Check for madvise(..., MADV_DONTNEED).
1854  JE_COMPILABLE([madvise(..., MADV_DONTNEED)], [
1855#include <sys/mman.h>
1856], [
1857	madvise((void *)0, 0, MADV_DONTNEED);
1858], [je_cv_madv_dontneed])
1859  if test "x${je_cv_madv_dontneed}" = "xyes" ; then
1860    AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
1861  fi
1862
1863  dnl Check for madvise(..., MADV_DO[NT]DUMP).
1864  JE_COMPILABLE([madvise(..., MADV_DO[[NT]]DUMP)], [
1865#include <sys/mman.h>
1866], [
1867	madvise((void *)0, 0, MADV_DONTDUMP);
1868	madvise((void *)0, 0, MADV_DODUMP);
1869], [je_cv_madv_dontdump])
1870  if test "x${je_cv_madv_dontdump}" = "xyes" ; then
1871    AC_DEFINE([JEMALLOC_MADVISE_DONTDUMP], [ ])
1872  fi
1873
1874  dnl Check for madvise(..., MADV_[NO]HUGEPAGE).
1875  JE_COMPILABLE([madvise(..., MADV_[[NO]]HUGEPAGE)], [
1876#include <sys/mman.h>
1877], [
1878	madvise((void *)0, 0, MADV_HUGEPAGE);
1879	madvise((void *)0, 0, MADV_NOHUGEPAGE);
1880], [je_cv_thp])
1881case "${host_cpu}" in
1882  arm*)
1883    ;;
1884  *)
1885  if test "x${je_cv_thp}" = "xyes" ; then
1886    AC_DEFINE([JEMALLOC_HAVE_MADVISE_HUGE], [ ])
1887  fi
1888  ;;
1889esac
1890fi
1891
1892dnl ============================================================================
1893dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1894dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1895
1896AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1897  AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1898               [je_cv_sync_compare_and_swap_$2],
1899               [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1900                                                 #include <stdint.h>
1901                                                ],
1902                                                [
1903                                                 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1904                                                 {
1905                                                    uint$1_t x$1 = 0;
1906                                                    __sync_add_and_fetch(&x$1, 42);
1907                                                    __sync_sub_and_fetch(&x$1, 1);
1908                                                 }
1909                                                 #else
1910                                                 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1911                                                 #endif
1912                                                ])],
1913                               [je_cv_sync_compare_and_swap_$2=yes],
1914                               [je_cv_sync_compare_and_swap_$2=no])])
1915
1916  if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1917    AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1918  fi
1919])
1920
1921if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
1922  JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1923  JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1924fi
1925
1926dnl ============================================================================
1927dnl Check for __builtin_clz() and __builtin_clzl().
1928
1929AC_CACHE_CHECK([for __builtin_clz],
1930               [je_cv_builtin_clz],
1931               [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1932                                                [
1933                                                {
1934                                                        unsigned x = 0;
1935                                                        int y = __builtin_clz(x);
1936                                                }
1937                                                {
1938                                                        unsigned long x = 0;
1939                                                        int y = __builtin_clzl(x);
1940                                                }
1941                                                ])],
1942                               [je_cv_builtin_clz=yes],
1943                               [je_cv_builtin_clz=no])])
1944
1945if test "x${je_cv_builtin_clz}" = "xyes" ; then
1946  AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1947fi
1948
1949dnl ============================================================================
1950dnl Check for os_unfair_lock operations as provided on Darwin.
1951
1952JE_COMPILABLE([Darwin os_unfair_lock_*()], [
1953#include <os/lock.h>
1954#include <AvailabilityMacros.h>
1955], [
1956	#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
1957	#error "os_unfair_lock is not supported"
1958	#else
1959	os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
1960	os_unfair_lock_lock(&lock);
1961	os_unfair_lock_unlock(&lock);
1962	#endif
1963], [je_cv_os_unfair_lock])
1964if test "x${je_cv_os_unfair_lock}" = "xyes" ; then
1965  AC_DEFINE([JEMALLOC_OS_UNFAIR_LOCK], [ ])
1966fi
1967
1968dnl ============================================================================
1969dnl Check for spinlock(3) operations as provided on Darwin.
1970
1971JE_COMPILABLE([Darwin OSSpin*()], [
1972#include <libkern/OSAtomic.h>
1973#include <inttypes.h>
1974], [
1975	OSSpinLock lock = 0;
1976	OSSpinLockLock(&lock);
1977	OSSpinLockUnlock(&lock);
1978], [je_cv_osspin])
1979if test "x${je_cv_osspin}" = "xyes" ; then
1980  AC_DEFINE([JEMALLOC_OSSPIN], [ ])
1981fi
1982
1983dnl ============================================================================
1984dnl Darwin-related configuration.
1985
1986AC_ARG_ENABLE([zone-allocator],
1987  [AS_HELP_STRING([--disable-zone-allocator],
1988                  [Disable zone allocator for Darwin])],
1989[if test "x$enable_zone_allocator" = "xno" ; then
1990  enable_zone_allocator="0"
1991else
1992  enable_zone_allocator="1"
1993fi
1994],
1995[if test "x${abi}" = "xmacho"; then
1996  enable_zone_allocator="1"
1997fi
1998]
1999)
2000AC_SUBST([enable_zone_allocator])
2001
2002if test "x${enable_zone_allocator}" = "x1" ; then
2003  if test "x${abi}" != "xmacho"; then
2004    AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
2005  fi
2006  AC_DEFINE([JEMALLOC_ZONE], [ ])
2007fi
2008
2009dnl ============================================================================
2010dnl Use initial-exec TLS by default.
2011AC_ARG_ENABLE([initial-exec-tls],
2012  [AS_HELP_STRING([--disable-initial-exec-tls],
2013                  [Disable the initial-exec tls model])],
2014[if test "x$enable_initial_exec_tls" = "xno" ; then
2015  enable_initial_exec_tls="0"
2016else
2017  enable_initial_exec_tls="1"
2018fi
2019],
2020[enable_initial_exec_tls="1"]
2021)
2022AC_SUBST([enable_initial_exec_tls])
2023
2024if test "x${je_cv_tls_model}" = "xyes" -a \
2025       "x${enable_initial_exec_tls}" = "x1" ; then
2026  AC_DEFINE([JEMALLOC_TLS_MODEL],
2027            [__attribute__((tls_model("initial-exec")))])
2028else
2029  AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
2030fi
2031
2032dnl ============================================================================
2033dnl Enable background threads if possible.
2034
2035if test "x${have_pthread}" = "x1" -a "x${have_dlsym}" = "x1" \
2036    -a "x${je_cv_os_unfair_lock}" != "xyes" \
2037    -a "x${je_cv_osspin}" != "xyes" ; then
2038  AC_DEFINE([JEMALLOC_BACKGROUND_THREAD])
2039fi
2040
2041dnl ============================================================================
2042dnl Check for glibc malloc hooks
2043
2044JE_COMPILABLE([glibc malloc hook], [
2045#include <stddef.h>
2046
2047extern void (* __free_hook)(void *ptr);
2048extern void *(* __malloc_hook)(size_t size);
2049extern void *(* __realloc_hook)(void *ptr, size_t size);
2050], [
2051  void *ptr = 0L;
2052  if (__malloc_hook) ptr = __malloc_hook(1);
2053  if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
2054  if (__free_hook && ptr) __free_hook(ptr);
2055], [je_cv_glibc_malloc_hook])
2056if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
2057  if test "x${JEMALLOC_PREFIX}" = "x" ; then
2058    AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
2059    wrap_syms="${wrap_syms} __free_hook __malloc_hook __realloc_hook"
2060  fi
2061fi
2062
2063JE_COMPILABLE([glibc memalign hook], [
2064#include <stddef.h>
2065
2066extern void *(* __memalign_hook)(size_t alignment, size_t size);
2067], [
2068  void *ptr = 0L;
2069  if (__memalign_hook) ptr = __memalign_hook(16, 7);
2070], [je_cv_glibc_memalign_hook])
2071if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
2072  if test "x${JEMALLOC_PREFIX}" = "x" ; then
2073    AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
2074    wrap_syms="${wrap_syms} __memalign_hook"
2075  fi
2076fi
2077
2078JE_COMPILABLE([pthreads adaptive mutexes], [
2079#include <pthread.h>
2080], [
2081  pthread_mutexattr_t attr;
2082  pthread_mutexattr_init(&attr);
2083  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
2084  pthread_mutexattr_destroy(&attr);
2085], [je_cv_pthread_mutex_adaptive_np])
2086if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
2087  AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
2088fi
2089
2090JE_CFLAGS_SAVE()
2091JE_CFLAGS_ADD([-D_GNU_SOURCE])
2092JE_CFLAGS_ADD([-Werror])
2093JE_CFLAGS_ADD([-herror_on_warning])
2094JE_COMPILABLE([strerror_r returns char with gnu source], [
2095#include <errno.h>
2096#include <stdio.h>
2097#include <stdlib.h>
2098#include <string.h>
2099], [
2100  char *buffer = (char *) malloc(100);
2101  char *error = strerror_r(EINVAL, buffer, 100);
2102  printf("%s\n", error);
2103], [je_cv_strerror_r_returns_char_with_gnu_source])
2104JE_CFLAGS_RESTORE()
2105if test "x${je_cv_strerror_r_returns_char_with_gnu_source}" = "xyes" ; then
2106  AC_DEFINE([JEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE], [ ])
2107fi
2108
2109dnl ============================================================================
2110dnl Check for typedefs, structures, and compiler characteristics.
2111AC_HEADER_STDBOOL
2112
2113dnl ============================================================================
2114dnl Define commands that generate output files.
2115
2116AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
2117  f="${objroot}include/jemalloc/internal/public_symbols.txt"
2118  mkdir -p "${objroot}include/jemalloc/internal"
2119  cp /dev/null "${f}"
2120  for nm in `echo ${mangling_map} |tr ',' ' '` ; do
2121    n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
2122    m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
2123    echo "${n}:${m}" >> "${f}"
2124    dnl Remove name from public_syms so that it isn't redefined later.
2125    public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
2126  done
2127  for sym in ${public_syms} ; do
2128    n="${sym}"
2129    m="${JEMALLOC_PREFIX}${sym}"
2130    echo "${n}:${m}" >> "${f}"
2131  done
2132], [
2133  srcdir="${srcdir}"
2134  objroot="${objroot}"
2135  mangling_map="${mangling_map}"
2136  public_syms="${public_syms}"
2137  JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
2138])
2139AC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols.awk], [
2140  f="${objroot}include/jemalloc/internal/private_symbols.awk"
2141  mkdir -p "${objroot}include/jemalloc/internal"
2142  export_syms=`for sym in ${public_syms}; do echo "${JEMALLOC_PREFIX}${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
2143  "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols.awk"
2144], [
2145  srcdir="${srcdir}"
2146  objroot="${objroot}"
2147  public_syms="${public_syms}"
2148  wrap_syms="${wrap_syms}"
2149  SYM_PREFIX="${SYM_PREFIX}"
2150  JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
2151])
2152AC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols_jet.awk], [
2153  f="${objroot}include/jemalloc/internal/private_symbols_jet.awk"
2154  mkdir -p "${objroot}include/jemalloc/internal"
2155  export_syms=`for sym in ${public_syms}; do echo "jet_${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
2156  "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols_jet.awk"
2157], [
2158  srcdir="${srcdir}"
2159  objroot="${objroot}"
2160  public_syms="${public_syms}"
2161  wrap_syms="${wrap_syms}"
2162  SYM_PREFIX="${SYM_PREFIX}"
2163])
2164AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
2165  mkdir -p "${objroot}include/jemalloc/internal"
2166  "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
2167], [
2168  srcdir="${srcdir}"
2169  objroot="${objroot}"
2170])
2171AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
2172  mkdir -p "${objroot}include/jemalloc/internal"
2173  "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
2174], [
2175  srcdir="${srcdir}"
2176  objroot="${objroot}"
2177])
2178AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
2179  mkdir -p "${objroot}include/jemalloc/internal"
2180  "${SHELL}" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" 3 "${LG_PAGE_SIZES}" 2 > "${objroot}include/jemalloc/internal/size_classes.h"
2181], [
2182  SHELL="${SHELL}"
2183  srcdir="${srcdir}"
2184  objroot="${objroot}"
2185  LG_QUANTA="${LG_QUANTA}"
2186  LG_PAGE_SIZES="${LG_PAGE_SIZES}"
2187])
2188AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
2189  mkdir -p "${objroot}include/jemalloc"
2190  cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
2191], [
2192  srcdir="${srcdir}"
2193  objroot="${objroot}"
2194])
2195AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
2196  mkdir -p "${objroot}include/jemalloc"
2197  "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
2198], [
2199  srcdir="${srcdir}"
2200  objroot="${objroot}"
2201])
2202AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
2203  mkdir -p "${objroot}include/jemalloc"
2204  "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
2205], [
2206  srcdir="${srcdir}"
2207  objroot="${objroot}"
2208])
2209AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
2210  mkdir -p "${objroot}include/jemalloc"
2211  "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
2212], [
2213  srcdir="${srcdir}"
2214  objroot="${objroot}"
2215])
2216AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
2217  mkdir -p "${objroot}include/jemalloc"
2218  "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
2219], [
2220  srcdir="${srcdir}"
2221  objroot="${objroot}"
2222  install_suffix="${install_suffix}"
2223])
2224
2225dnl Process .in files.
2226AC_SUBST([cfghdrs_in])
2227AC_SUBST([cfghdrs_out])
2228AC_CONFIG_HEADERS([$cfghdrs_tup])
2229
2230dnl ============================================================================
2231dnl Generate outputs.
2232
2233AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
2234AC_SUBST([cfgoutputs_in])
2235AC_SUBST([cfgoutputs_out])
2236AC_OUTPUT
2237
2238dnl ============================================================================
2239dnl Print out the results of configuration.
2240AC_MSG_RESULT([===============================================================================])
2241AC_MSG_RESULT([jemalloc version   : ${jemalloc_version}])
2242AC_MSG_RESULT([library revision   : ${rev}])
2243AC_MSG_RESULT([])
2244AC_MSG_RESULT([CONFIG             : ${CONFIG}])
2245AC_MSG_RESULT([CC                 : ${CC}])
2246AC_MSG_RESULT([CONFIGURE_CFLAGS   : ${CONFIGURE_CFLAGS}])
2247AC_MSG_RESULT([SPECIFIED_CFLAGS   : ${SPECIFIED_CFLAGS}])
2248AC_MSG_RESULT([EXTRA_CFLAGS       : ${EXTRA_CFLAGS}])
2249AC_MSG_RESULT([CPPFLAGS           : ${CPPFLAGS}])
2250AC_MSG_RESULT([CXX                : ${CXX}])
2251AC_MSG_RESULT([CONFIGURE_CXXFLAGS : ${CONFIGURE_CXXFLAGS}])
2252AC_MSG_RESULT([SPECIFIED_CXXFLAGS : ${SPECIFIED_CXXFLAGS}])
2253AC_MSG_RESULT([EXTRA_CXXFLAGS     : ${EXTRA_CXXFLAGS}])
2254AC_MSG_RESULT([LDFLAGS            : ${LDFLAGS}])
2255AC_MSG_RESULT([EXTRA_LDFLAGS      : ${EXTRA_LDFLAGS}])
2256AC_MSG_RESULT([DSO_LDFLAGS        : ${DSO_LDFLAGS}])
2257AC_MSG_RESULT([LIBS               : ${LIBS}])
2258AC_MSG_RESULT([RPATH_EXTRA        : ${RPATH_EXTRA}])
2259AC_MSG_RESULT([])
2260AC_MSG_RESULT([XSLTPROC           : ${XSLTPROC}])
2261AC_MSG_RESULT([XSLROOT            : ${XSLROOT}])
2262AC_MSG_RESULT([])
2263AC_MSG_RESULT([PREFIX             : ${PREFIX}])
2264AC_MSG_RESULT([BINDIR             : ${BINDIR}])
2265AC_MSG_RESULT([DATADIR            : ${DATADIR}])
2266AC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
2267AC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
2268AC_MSG_RESULT([MANDIR             : ${MANDIR}])
2269AC_MSG_RESULT([])
2270AC_MSG_RESULT([srcroot            : ${srcroot}])
2271AC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
2272AC_MSG_RESULT([objroot            : ${objroot}])
2273AC_MSG_RESULT([abs_objroot        : ${abs_objroot}])
2274AC_MSG_RESULT([])
2275AC_MSG_RESULT([JEMALLOC_PREFIX    : ${JEMALLOC_PREFIX}])
2276AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
2277AC_MSG_RESULT([                   : ${JEMALLOC_PRIVATE_NAMESPACE}])
2278AC_MSG_RESULT([install_suffix     : ${install_suffix}])
2279AC_MSG_RESULT([malloc_conf        : ${config_malloc_conf}])
2280AC_MSG_RESULT([autogen            : ${enable_autogen}])
2281AC_MSG_RESULT([debug              : ${enable_debug}])
2282AC_MSG_RESULT([stats              : ${enable_stats}])
2283AC_MSG_RESULT([prof               : ${enable_prof}])
2284AC_MSG_RESULT([prof-libunwind     : ${enable_prof_libunwind}])
2285AC_MSG_RESULT([prof-libgcc        : ${enable_prof_libgcc}])
2286AC_MSG_RESULT([prof-gcc           : ${enable_prof_gcc}])
2287AC_MSG_RESULT([fill               : ${enable_fill}])
2288AC_MSG_RESULT([utrace             : ${enable_utrace}])
2289AC_MSG_RESULT([xmalloc            : ${enable_xmalloc}])
2290AC_MSG_RESULT([log                : ${enable_log}])
2291AC_MSG_RESULT([lazy_lock          : ${enable_lazy_lock}])
2292AC_MSG_RESULT([cache-oblivious    : ${enable_cache_oblivious}])
2293AC_MSG_RESULT([cxx                : ${enable_cxx}])
2294AC_MSG_RESULT([===============================================================================])
2295