2 m4_include([version.m4])
3 m4_include([m4/c99-backport.m4])
4 AC_INIT(memcached, VERSION_NUMBER, memcached@googlegroups.com)
6 AC_CONFIG_SRCDIR(memcached.c)
7 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
8 AM_CONFIG_HEADER(config.h)
12 dnl **********************************************************************
13 dnl DETECT_ICC ([ACTION-IF-YES], [ACTION-IF-NO])
15 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
16 dnl sets the $ICC variable to "yes" or "no"
17 dnl **********************************************************************
18 AC_DEFUN([DETECT_ICC],
21 AC_MSG_CHECKING([for icc in use])
22 if test "$GCC" = "yes"; then
23 dnl check if this is icc acting as gcc in disguise
24 AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
38 dnl **********************************************************************
39 dnl DETECT_SUNCC ([ACTION-IF-YES], [ACTION-IF-NO])
41 dnl check if this is the Sun Studio compiler, and if so run the ACTION-IF-YES
42 dnl sets the $SUNCC variable to "yes" or "no"
43 dnl **********************************************************************
44 AC_DEFUN([DETECT_SUNCC],
46 AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
47 AS_IF(test "x$SUNCC" = "xyes", [$1], [$2])
51 DETECT_SUNCC([CFLAGS="-mt $CFLAGS"], [])
53 if test "$ICC" = "no"; then
61 [AS_HELP_STRING([--enable-sasl],[Enable SASL authentication])])
63 AC_ARG_ENABLE(sasl_pwdb,
64 [AS_HELP_STRING([--enable-sasl-pwdb],[Enable plaintext password db])])
66 AS_IF([test "x$enable_sasl_pwdb" = "xyes"],
70 dnl **********************************************************************
71 dnl DETECT_SASL_CB_GETCONF
73 dnl check if we can use SASL_CB_GETCONF
74 dnl **********************************************************************
75 AC_DEFUN([AC_C_DETECT_SASL_CB_GETCONF],
77 AC_CACHE_CHECK([for SASL_CB_GETCONF],
78 [ac_cv_c_sasl_cb_getconf],
81 #include <sasl/sasl.h>
83 unsigned long val = SASL_CB_GETCONF;
85 [ ac_cv_c_sasl_cb_getconf=yes ],
86 [ ac_cv_c_sasl_cb_getconf=no ])
88 AS_IF([test "$ac_cv_c_sasl_cb_getconf" = "yes"],
89 [AC_DEFINE([HAVE_SASL_CB_GETCONF], 1,
90 [Set to nonzero if your SASL implementation supports SASL_CB_GETCONF])])
93 AC_CHECK_HEADERS([sasl/sasl.h])
94 if test "x$enable_sasl" = "xyes"; then
95 AC_C_DETECT_SASL_CB_GETCONF
96 AC_DEFINE([ENABLE_SASL],1,[Set to nonzero if you want to include SASL])
97 AC_SEARCH_LIBS([sasl_server_init], [sasl2 sasl], [],
99 AC_MSG_ERROR([Failed to locate the library containing sasl_server_init])
102 AS_IF([test "x$enable_sasl_pwdb" = "xyes"],
103 [AC_DEFINE([ENABLE_SASL_PWDB], 1,
104 [Set to nonzero if you want to enable a SASL pwdb])])
107 AC_ARG_ENABLE(dtrace,
108 [AS_HELP_STRING([--enable-dtrace],[Enable dtrace probes])])
109 if test "x$enable_dtrace" = "xyes"; then
110 AC_PATH_PROG([DTRACE], [dtrace], "no", [/usr/sbin:$PATH])
111 if test "x$DTRACE" != "xno"; then
112 AC_DEFINE([ENABLE_DTRACE],1,[Set to nonzero if you want to include DTRACE])
114 # DTrace on MacOSX does not use -G option
115 $DTRACE -G -o conftest.$$ -s memcached_dtrace.d 2>/dev/zero
118 dtrace_instrument_obj=yes
122 if test "`which tr`" = "/usr/ucb/tr"; then
123 AC_MSG_ERROR([Please remove /usr/ucb from your path. See man standards for more info])
126 AC_MSG_ERROR([Need dtrace binary and OS support.])
130 AM_CONDITIONAL([BUILD_DTRACE],[test "$build_dtrace" = "yes"])
131 AM_CONDITIONAL([DTRACE_INSTRUMENT_OBJ],[test "$dtrace_instrument_obj" = "yes"])
132 AM_CONDITIONAL([ENABLE_SASL],[test "$enable_sasl" = "yes"])
135 AC_SUBST(DTRACEFLAGS)
136 AC_SUBST(ENABLE_SASL)
137 AC_SUBST(PROFILER_LDFLAGS)
139 AC_ARG_ENABLE(coverage,
140 [AS_HELP_STRING([--disable-coverage],[Disable code coverage])])
142 if test "x$enable_coverage" != "xno"; then
143 if test "$ICC" = "yes"
145 dnl ICC trying to be gcc, but not well
146 CFLAGS="$CFLAGS -pthread"
147 elif test "$GCC" = "yes"
149 CFLAGS="$CFLAGS -pthread"
150 AC_PATH_PROG([PROFILER], [gcov], "no", [$PATH])
151 if test "x$PROFILER" != "xno"; then
152 # Issue 97: The existense of gcov doesn't mean we have -lgcov
153 AC_CHECK_LIB(gcov, main,
155 PROFILER_FLAGS="-fprofile-arcs -ftest-coverage"
156 PROFILER_LDFLAGS="-lgcov"
162 elif test "$SUNCC" = "yes"
164 AC_PATH_PROG([PROFILER], [tcov], "no", [$PATH])
165 if test "x$PROFILER" != "xno"; then
166 PROFILER_FLAGS=-xprofile=tcov
170 AC_SUBST(PROFILER_FLAGS)
174 [AS_HELP_STRING([--enable-64bit],[build 64bit version])])
175 if test "x$enable_64bit" = "xyes"
180 [AC_LANG_PROGRAM([], [dnl
181 return sizeof(void*) == 8 ? 0 : 1;
184 CFLAGS="-m64 $org_cflags"
186 AC_MSG_ERROR([Don't know how to build a 64-bit object.])
190 # Issue 213: Search for clock_gettime to help people linking
191 # with a static version of libevent
192 AC_SEARCH_LIBS(clock_gettime, rt)
193 # Issue 214: Search for the network libraries _before_ searching
194 # for libevent (to help people linking with static libevent)
195 AC_SEARCH_LIBS(socket, socket)
196 AC_SEARCH_LIBS(gethostbyname, nsl)
199 AC_ARG_WITH(libevent,
200 [ --with-libevent=PATH Specify path to libevent installation ],
202 if test "x$withval" != "xno" ; then
203 trylibeventdir=$withval
208 dnl ------------------------------------------------------
209 dnl libevent detection. swiped from Tor. modified a bit.
211 LIBEVENT_URL=http://www.monkey.org/~provos/libevent/
213 AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [
215 saved_LDFLAGS="$LDFLAGS"
216 saved_CPPFLAGS="$CPPFLAGS"
218 for ledir in $trylibeventdir "" $prefix /usr/local ; do
219 LDFLAGS="$saved_LDFLAGS"
220 LIBS="-levent $saved_LIBS"
222 # Skip the directory if it isn't there.
223 if test ! -z "$ledir" -a ! -d "$ledir" ; then
226 if test ! -z "$ledir" ; then
227 if test -d "$ledir/lib" ; then
228 LDFLAGS="-L$ledir/lib $LDFLAGS"
230 LDFLAGS="-L$ledir $LDFLAGS"
232 if test -d "$ledir/include" ; then
233 CPPFLAGS="-I$ledir/include $CPPFLAGS"
235 CPPFLAGS="-I$ledir $CPPFLAGS"
238 # Can I compile and link it?
239 AC_TRY_LINK([#include <sys/time.h>
240 #include <sys/types.h>
241 #include <event.h>], [ event_init(); ],
242 [ libevent_linked=yes ], [ libevent_linked=no ])
243 if test $libevent_linked = yes; then
244 if test ! -z "$ledir" ; then
245 ac_cv_libevent_dir=$ledir
246 _myos=`echo $target_os | cut -f 1 -d .`
247 AS_IF(test "$SUNCC" = "yes" -o "x$_myos" = "xsolaris2",
248 [saved_LDFLAGS="$saved_LDFLAGS -Wl,-R$ledir/lib"],
249 [AS_IF(test "$GCC" = "yes",
250 [saved_LDFLAGS="$saved_LDFLAGS -Wl,-rpath,$ledir/lib"])])
252 ac_cv_libevent_dir="(system)"
259 LDFLAGS="$saved_LDFLAGS"
260 CPPFLAGS="$saved_CPPFLAGS"
261 if test $le_found = no ; then
262 AC_MSG_ERROR([libevent is required. You can get it from $LIBEVENT_URL
264 If it's already installed, specify its path using --with-libevent=/dir/
269 if test $ac_cv_libevent_dir != "(system)"; then
270 if test -d "$ac_cv_libevent_dir/lib" ; then
271 LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS"
272 le_libdir="$ac_cv_libevent_dir/lib"
274 LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
275 le_libdir="$ac_cv_libevent_dir"
277 if test -d "$ac_cv_libevent_dir/include" ; then
278 CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
280 CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
284 dnl ----------------------------------------------------------------------------
286 AC_SEARCH_LIBS(umem_cache_create, umem)
287 AC_SEARCH_LIBS(gethugepagesizes, hugetlbfs)
290 AH_BOTTOM([#if HAVE_STDBOOL_H
298 AC_CHECK_HEADERS([inttypes.h])
299 AH_BOTTOM([#ifdef HAVE_INTTYPES_H
300 #include <inttypes.h>
304 dnl **********************************************************************
305 dnl Figure out if this system has the stupid sasl_callback_ft
306 dnl **********************************************************************
308 AC_DEFUN([AC_HAVE_SASL_CALLBACK_FT],
309 [AC_CACHE_CHECK(for sasl_callback_ft, ac_cv_has_sasl_callback_ft,
312 #ifdef HAVE_SASL_SASL_H
313 #include <sasl/sasl.h>
314 #include <sasl/saslplug.h>
317 sasl_callback_ft a_callback;
319 ac_cv_has_sasl_callback_ft=yes
321 ac_cv_has_sasl_callback_ft=no
324 if test $ac_cv_has_sasl_callback_ft = yes; then
325 AC_DEFINE(HAVE_SASL_CALLBACK_FT, 1, [we have sasl_callback_ft])
329 AC_HAVE_SASL_CALLBACK_FT
331 dnl **********************************************************************
332 dnl DETECT_UINT64_SUPPORT
334 dnl check if we can use a uint64_t
335 dnl **********************************************************************
336 AC_DEFUN([AC_C_DETECT_UINT64_SUPPORT],
338 AC_CACHE_CHECK([for print macros for integers (C99 section 7.8.1)],
339 [ac_cv_c_uint64_support],
342 #ifdef HAVE_INTTYPES_H
343 #include <inttypes.h>
348 fprintf(stderr, "%" PRIu64 "\n", val);
350 [ ac_cv_c_uint64_support=yes ],
351 [ ac_cv_c_uint64_support=no ])
355 AC_C_DETECT_UINT64_SUPPORT
356 AS_IF([test "x$ac_cv_c_uint64_support" = "xno"],
359 Failed to use print macros (PRIu) as defined in C99 section 7.8.1.
365 dnl From licq: Copyright (c) 2000 Dirk Mueller
366 dnl Check if the type socklen_t is defined anywhere
367 AC_DEFUN([AC_C_SOCKLEN_T],
368 [AC_CACHE_CHECK(for socklen_t, ac_cv_c_socklen_t,
371 #include <sys/types.h>
372 #include <sys/socket.h>
376 ac_cv_c_socklen_t=yes
381 if test $ac_cv_c_socklen_t = no; then
382 AC_DEFINE(socklen_t, int, [define to int if socklen_t not available])
388 dnl Check if we're a little-endian or a big-endian system, needed by hash code
389 AC_DEFUN([AC_C_ENDIAN],
390 [AC_CACHE_CHECK(for endianness, ac_cv_c_endian,
393 [AC_LANG_PROGRAM([], [dnl
395 char *c = (char *) &val;
401 ac_cv_c_endian=little
404 if test $ac_cv_c_endian = big; then
405 AC_DEFINE(ENDIAN_BIG, 1, [machine is bigendian])
407 if test $ac_cv_c_endian = little; then
408 AC_DEFINE(ENDIAN_LITTLE, 1, [machine is littleendian])
414 AC_DEFUN([AC_C_HTONLL],
416 AC_MSG_CHECKING([for htonll])
419 #include <sys/types.h>
420 #include <netinet/in.h>
421 #ifdef HAVE_INTTYPES_H
422 #include <inttypes.h> */
428 AC_DEFINE([HAVE_HTONLL], [1], [Have ntohll])
433 AC_MSG_RESULT([$have_htoll])
438 dnl Check whether the user's system supports pthread
439 AC_SEARCH_LIBS(pthread_create, pthread)
440 if test "x$ac_cv_search_pthread_create" = "xno"; then
441 AC_MSG_ERROR([Can't enable threads without the POSIX thread library.])
444 AC_CHECK_FUNCS(mlockall)
445 AC_CHECK_FUNCS(getpagesizes)
446 AC_CHECK_FUNCS(memcntl)
447 AC_CHECK_FUNCS(sigignore)
448 AC_CHECK_FUNCS(clock_gettime)
450 AC_DEFUN([AC_C_ALIGNMENT],
451 [AC_CACHE_CHECK(for alignment, ac_cv_c_alignment,
456 #include <inttypes.h>
458 char *buf = malloc(32);
460 uint64_t *ptr = (uint64_t*)(buf+2);
461 // catch sigbus, etc.
464 // catch unaligned word access (ARM cpus)
465 *buf = 1; *(buf +1) = 2; *(buf + 2) = 2; *(buf + 3) = 3; *(buf + 4) = 4;
466 int* i = (int*)(buf+1);
467 return (84148994 == i) ? 0 : 1;
470 ac_cv_c_alignment=none
472 ac_cv_c_alignment=need
474 ac_cv_c_alignment=need
477 if test $ac_cv_c_alignment = need; then
478 AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment])
484 dnl Check for our specific usage of GCC atomics.
485 dnl These were added in 4.1.2, but 32bit OS's may lack shorts and 4.1.2
486 dnl lacks testable defines.
488 AC_MSG_CHECKING(for GCC atomics)
492 b = __sync_add_and_fetch(&a, 1);
493 b = __sync_sub_and_fetch(&a, 2);
494 ],[have_gcc_atomics=yes
495 AC_DEFINE(HAVE_GCC_ATOMICS, 1, [GCC Atomics available])])
496 AC_MSG_RESULT($have_gcc_atomics)
498 dnl Check for the requirements for running memcached with less privileges
499 dnl than the default privilege set. On Solaris we need setppriv and priv.h
500 dnl If you want to add support for other platforms you should check for
501 dnl your requirements, define HAVE_DROP_PRIVILEGES, and make sure you add
502 dnl the source file containing the implementation into memcached_SOURCE
504 AC_CHECK_FUNCS(setppriv, [
505 AC_CHECK_HEADER(priv.h, [
506 AC_DEFINE([HAVE_DROP_PRIVILEGES], 1,
507 [Define this if you have an implementation of drop_privileges()])
508 build_solaris_privs=yes
512 AM_CONDITIONAL([BUILD_SOLARIS_PRIVS],[test "$build_solaris_privs" = "yes"])
514 AC_CHECK_HEADER(umem.h, [
515 AC_DEFINE([HAVE_UMEM_H], 1,
516 [Define this if you have umem.h])
518 ], [build_cache=yes])
520 AM_CONDITIONAL([BUILD_CACHE], [test "x$build_cache" = "xyes"])
523 [AS_HELP_STRING([--disable-docs],[Disable documentation generation])])
525 AC_PATH_PROG([XML2RFC], [xml2rfc], "no")
526 AC_PATH_PROG([XSLTPROC], [xsltproc], "no")
528 AM_CONDITIONAL([BUILD_SPECIFICATIONS],
529 [test "x$enable_docs" != "xno" -a "x$XML2RFC" != "xno" -a "x$XSLTPROC" != "xno"])
532 dnl Let the compiler be a bit more picky. Please note that you cannot
533 dnl specify these flags to the compiler before AC_CHECK_FUNCS, because
534 dnl the test program will generate a compilation warning and hence fail
535 dnl to detect the function ;-)
536 if test "$ICC" = "yes"
538 dnl ICC trying to be gcc.
539 CFLAGS="$CFLAGS -diag-disable 187 -Wall -Werror"
540 AC_DEFINE([_GNU_SOURCE],[1],[find sigignore on Linux])
541 elif test "$GCC" = "yes"
543 GCC_VERSION=`$CC -dumpversion`
544 CFLAGS="$CFLAGS -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls"
547 CFLAGS="$CFLAGS -fno-strict-aliasing"
550 AC_DEFINE([_GNU_SOURCE],[1],[find sigignore on Linux])
551 elif test "$SUNCC" = "yes"
553 CFLAGS="$CFLAGS -errfmt=error -errwarn -errshort=tags"
556 AC_CONFIG_FILES(Makefile doc/Makefile)