configure.ac 38 KB

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