1AC_PREREQ(2.52) 2m4_include([version.m4]) 3m4_include([m4/c99-backport.m4]) 4AC_INIT([memcached], [VERSION_NUMBER], [[email protected]]) 5AC_CANONICAL_HOST 6AC_CONFIG_SRCDIR([memcached.c]) 7AM_INIT_AUTOMAKE([foreign]) 8AM_CONFIG_HEADER([config.h]) 9 10AC_PROG_CC 11 12dnl ********************************************************************** 13dnl DETECT_ICC ([ACTION-IF-YES], [ACTION-IF-NO]) 14dnl 15dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES 16dnl sets the $ICC variable to "yes" or "no" 17dnl ********************************************************************** 18AC_DEFUN([DETECT_ICC], 19[ 20 ICC="no" 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], 25 AC_MSG_RESULT([no]) 26 [$2], 27 AC_MSG_RESULT([yes]) 28 [$1] 29 ICC="yes") 30 else 31 AC_MSG_RESULT([no]) 32 [$2] 33 fi 34]) 35 36DETECT_ICC([], []) 37 38dnl ********************************************************************** 39dnl DETECT_CLANG ([ACTION-IF-YES], [ACTION-IF-NO]) 40dnl 41dnl check if compiler is clang, and if so run the ACTION-IF-YES sets the 42dnl $CLANG variable to "yes" or "no" 43dnl ********************************************************************** 44AC_DEFUN([DETECT_CLANG], 45[ 46 AC_MSG_CHECKING([for clang in use]) 47 AC_COMPILE_IFELSE( 48 [AC_LANG_PROGRAM([], [[ 49 #ifndef __clang__ 50 not clang 51 #endif 52 ]])], 53 [CLANG=yes], [CLANG=no]) 54 AC_MSG_RESULT([$CLANG]) 55 AS_IF([test "$CLANG" = "yes"],[$1],[$2]) 56]) 57DETECT_CLANG([],[]) 58 59dnl ********************************************************************** 60dnl DETECT_SUNCC ([ACTION-IF-YES], [ACTION-IF-NO]) 61dnl 62dnl check if this is the Sun Studio compiler, and if so run the ACTION-IF-YES 63dnl sets the $SUNCC variable to "yes" or "no" 64dnl ********************************************************************** 65AC_DEFUN([DETECT_SUNCC], 66[ 67 AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) 68 AS_IF(test "x$SUNCC" = "xyes", [$1], [$2]) 69 70]) 71 72DETECT_SUNCC([CFLAGS="-mt $CFLAGS"], []) 73AS_IF([test "$ICC" = "yes" -o "$GCC" = "yes"], 74[ 75 AS_IF(test "$CLANG" = "no",[CFLAGS="$CFLAGS -pthread"]) 76]) 77 78if test "$ICC" = "no"; then 79 AC_PROG_CC_C99 80fi 81 82AM_PROG_CC_C_O 83AC_PROG_INSTALL 84 85AC_ARG_ENABLE(sasl, 86 [AS_HELP_STRING([--enable-sasl],[Enable SASL authentication])]) 87 88AC_ARG_ENABLE(sasl_pwdb, 89 [AS_HELP_STRING([--enable-sasl-pwdb],[Enable plaintext password db])]) 90 91AS_IF([test "x$enable_sasl_pwdb" = "xyes"], 92 [enable_sasl=yes ]) 93 94 95 96dnl ********************************************************************** 97dnl DETECT_SASL_CB_GETCONF 98dnl 99dnl check if we can use SASL_CB_GETCONF 100dnl ********************************************************************** 101AC_DEFUN([AC_C_DETECT_SASL_CB_GETCONF], 102[ 103 AC_CACHE_CHECK([for SASL_CB_GETCONF], 104 [ac_cv_c_sasl_cb_getconf], 105 [AC_TRY_COMPILE( 106 [ 107#include <sasl/sasl.h> 108 ], [ 109unsigned long val = SASL_CB_GETCONF; 110 ], 111 [ ac_cv_c_sasl_cb_getconf=yes ], 112 [ ac_cv_c_sasl_cb_getconf=no ]) 113 ]) 114 AS_IF([test "$ac_cv_c_sasl_cb_getconf" = "yes"], 115 [AC_DEFINE([HAVE_SASL_CB_GETCONF], 1, 116 [Set to nonzero if your SASL implementation supports SASL_CB_GETCONF])]) 117]) 118 119AC_CHECK_HEADERS([sasl/sasl.h]) 120if test "x$enable_sasl" = "xyes"; then 121 AC_C_DETECT_SASL_CB_GETCONF 122 AC_DEFINE([ENABLE_SASL],1,[Set to nonzero if you want to include SASL]) 123 AC_SEARCH_LIBS([sasl_server_init], [sasl2 sasl], [], 124 [ 125 AC_MSG_ERROR([Failed to locate the library containing sasl_server_init]) 126 ]) 127 128 AS_IF([test "x$enable_sasl_pwdb" = "xyes"], 129 [AC_DEFINE([ENABLE_SASL_PWDB], 1, 130 [Set to nonzero if you want to enable a SASL pwdb])]) 131fi 132 133AC_ARG_ENABLE(dtrace, 134 [AS_HELP_STRING([--enable-dtrace],[Enable dtrace probes])]) 135if test "x$enable_dtrace" = "xyes"; then 136 AC_PATH_PROG([DTRACE], [dtrace], "no", [/usr/sbin:$PATH]) 137 if test "x$DTRACE" != "xno"; then 138 AC_DEFINE([ENABLE_DTRACE],1,[Set to nonzero if you want to include DTRACE]) 139 build_dtrace=yes 140 # DTrace on MacOSX does not use -G option 141 $DTRACE -G -o conftest.$$ -s memcached_dtrace.d 2>/dev/zero 142 if test $? -eq 0 143 then 144 dtrace_instrument_obj=yes 145 rm conftest.$$ 146 fi 147 148 if test "`which tr`" = "/usr/ucb/tr"; then 149 AC_MSG_ERROR([Please remove /usr/ucb from your path. See man standards for more info]) 150 fi 151 else 152 AC_MSG_ERROR([Need dtrace binary and OS support.]) 153 fi 154fi 155 156AM_CONDITIONAL([BUILD_DTRACE],[test "$build_dtrace" = "yes"]) 157AM_CONDITIONAL([DTRACE_INSTRUMENT_OBJ],[test "$dtrace_instrument_obj" = "yes"]) 158AM_CONDITIONAL([ENABLE_SASL],[test "$enable_sasl" = "yes"]) 159 160AC_SUBST(DTRACE) 161AC_SUBST(DTRACEFLAGS) 162AC_SUBST(ENABLE_SASL) 163AC_SUBST(PROFILER_LDFLAGS) 164 165AC_ARG_ENABLE(coverage, 166 [AS_HELP_STRING([--disable-coverage],[Disable code coverage])]) 167 168if test "x$enable_coverage" != "xno"; then 169 if test "$GCC" = "yes" -a "$ICC" != "yes" -a "$CLANG" != "yes" 170 then 171 CFLAGS="$CFLAGS -pthread" 172 AC_PATH_PROG([PROFILER], [gcov], "no", [$PATH]) 173 if test "x$PROFILER" != "xno"; then 174 # Issue 97: The existense of gcov doesn't mean we have -lgcov 175 AC_CHECK_LIB(gcov, main, 176 [ 177 PROFILER_FLAGS="-fprofile-arcs -ftest-coverage" 178 PROFILER_LDFLAGS="-lgcov" 179 ], [ 180 PROFILER_FLAGS= 181 PROFILER_LDFLAGS= 182 ]) 183 fi 184 elif test "$SUNCC" = "yes" 185 then 186 AC_PATH_PROG([PROFILER], [tcov], "no", [$PATH]) 187 if test "x$PROFILER" != "xno"; then 188 PROFILER_FLAGS=-xprofile=tcov 189 fi 190 elif test "x$CLANG" != "xno" 191 then 192 AC_PATH_PROG([PROFILER], [gcov], "no", [$PATH]) 193 if test "x$PROFILER" != "xno" 194 then 195 PROFILER_FLAGS="-fprofile-arcs -ftest-coverage" 196 PROFILER_LDFLAGS= 197 fi 198 fi 199fi 200AC_SUBST(PROFILER_FLAGS) 201 202 203AC_ARG_ENABLE(64bit, 204 [AS_HELP_STRING([--enable-64bit],[build 64bit version])]) 205if test "x$enable_64bit" = "xyes" 206then 207 org_cflags=$CFLAGS 208 CFLAGS=-m64 209 AC_RUN_IFELSE( 210 [AC_LANG_PROGRAM([], [dnl 211return sizeof(void*) == 8 ? 0 : 1; 212 ]) 213 ],[ 214 CFLAGS="-m64 $org_cflags" 215 ],[ 216 AC_MSG_ERROR([Don't know how to build a 64-bit object.]) 217 ]) 218fi 219 220# Issue 213: Search for clock_gettime to help people linking 221# with a static version of libevent 222AC_SEARCH_LIBS(clock_gettime, rt) 223# Issue 214: Search for the network libraries _before_ searching 224# for libevent (to help people linking with static libevent) 225AC_SEARCH_LIBS(socket, socket) 226AC_SEARCH_LIBS(gethostbyname, nsl) 227 228trylibeventdir="" 229AC_ARG_WITH(libevent, 230 [ --with-libevent=PATH Specify path to libevent installation ], 231 [ 232 if test "x$withval" != "xno" ; then 233 trylibeventdir=$withval 234 fi 235 ] 236) 237 238dnl ------------------------------------------------------ 239dnl libevent detection. swiped from Tor. modified a bit. 240 241LIBEVENT_URL=http://www.monkey.org/~provos/libevent/ 242 243AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [ 244 saved_LIBS="$LIBS" 245 saved_LDFLAGS="$LDFLAGS" 246 saved_CPPFLAGS="$CPPFLAGS" 247 le_found=no 248 for ledir in $trylibeventdir "" $prefix /usr/local ; do 249 LDFLAGS="$saved_LDFLAGS" 250 LIBS="-levent $saved_LIBS" 251 252 # Skip the directory if it isn't there. 253 if test ! -z "$ledir" -a ! -d "$ledir" ; then 254 continue; 255 fi 256 if test ! -z "$ledir" ; then 257 if test -d "$ledir/lib" ; then 258 LDFLAGS="-L$ledir/lib $LDFLAGS" 259 else 260 LDFLAGS="-L$ledir $LDFLAGS" 261 fi 262 if test -d "$ledir/include" ; then 263 CPPFLAGS="-I$ledir/include $CPPFLAGS" 264 else 265 CPPFLAGS="-I$ledir $CPPFLAGS" 266 fi 267 fi 268 # Can I compile and link it? 269 AC_TRY_LINK([#include <sys/time.h> 270#include <sys/types.h> 271#include <event.h>], [ event_init(); ], 272 [ libevent_linked=yes ], [ libevent_linked=no ]) 273 if test $libevent_linked = yes; then 274 if test ! -z "$ledir" ; then 275 ac_cv_libevent_dir=$ledir 276 _myos=`echo $target_os | cut -f 1 -d .` 277 AS_IF(test "$SUNCC" = "yes" -o "x$_myos" = "xsolaris2", 278 [saved_LDFLAGS="$saved_LDFLAGS -Wl,-R$ledir/lib"], 279 [AS_IF(test "$GCC" = "yes", 280 [saved_LDFLAGS="$saved_LDFLAGS -Wl,-rpath,$ledir/lib"])]) 281 else 282 ac_cv_libevent_dir="(system)" 283 fi 284 le_found=yes 285 break 286 fi 287 done 288 LIBS="$saved_LIBS" 289 LDFLAGS="$saved_LDFLAGS" 290 CPPFLAGS="$saved_CPPFLAGS" 291 if test $le_found = no ; then 292 AC_MSG_ERROR([libevent is required. You can get it from $LIBEVENT_URL 293 294 If it's already installed, specify its path using --with-libevent=/dir/ 295]) 296 fi 297]) 298LIBS="-levent $LIBS" 299if test $ac_cv_libevent_dir != "(system)"; then 300 if test -d "$ac_cv_libevent_dir/lib" ; then 301 LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS" 302 le_libdir="$ac_cv_libevent_dir/lib" 303 else 304 LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS" 305 le_libdir="$ac_cv_libevent_dir" 306 fi 307 if test -d "$ac_cv_libevent_dir/include" ; then 308 CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS" 309 else 310 CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS" 311 fi 312fi 313 314dnl ---------------------------------------------------------------------------- 315 316AC_SEARCH_LIBS(umem_cache_create, umem) 317AC_SEARCH_LIBS(gethugepagesizes, hugetlbfs) 318 319AC_HEADER_STDBOOL 320AH_BOTTOM([#if HAVE_STDBOOL_H 321#include <stdbool.h> 322#else 323#define bool char 324#define false 0 325#define true 1 326#endif ]) 327 328AC_CHECK_HEADERS([inttypes.h]) 329AH_BOTTOM([#ifdef HAVE_INTTYPES_H 330#include <inttypes.h> 331#endif 332]) 333 334dnl ********************************************************************** 335dnl Figure out if this system has the stupid sasl_callback_ft 336dnl ********************************************************************** 337 338AC_DEFUN([AC_HAVE_SASL_CALLBACK_FT], 339[AC_CACHE_CHECK(for sasl_callback_ft, ac_cv_has_sasl_callback_ft, 340[ 341 AC_TRY_COMPILE([ 342 #ifdef HAVE_SASL_SASL_H 343 #include <sasl/sasl.h> 344 #include <sasl/saslplug.h> 345 #endif 346 ],[ 347 sasl_callback_ft a_callback; 348 ],[ 349 ac_cv_has_sasl_callback_ft=yes 350 ],[ 351 ac_cv_has_sasl_callback_ft=no 352 ]) 353]) 354if test $ac_cv_has_sasl_callback_ft = yes; then 355 AC_DEFINE(HAVE_SASL_CALLBACK_FT, 1, [we have sasl_callback_ft]) 356fi 357]) 358 359AC_HAVE_SASL_CALLBACK_FT 360 361dnl ********************************************************************** 362dnl DETECT_UINT64_SUPPORT 363dnl 364dnl check if we can use a uint64_t 365dnl ********************************************************************** 366AC_DEFUN([AC_C_DETECT_UINT64_SUPPORT], 367[ 368 AC_CACHE_CHECK([for print macros for integers (C99 section 7.8.1)], 369 [ac_cv_c_uint64_support], 370 [AC_TRY_COMPILE( 371 [ 372#ifdef HAVE_INTTYPES_H 373#include <inttypes.h> 374#endif 375#include <stdio.h> 376 ], [ 377 uint64_t val = 0; 378 fprintf(stderr, "%" PRIu64 "\n", val); 379 ], 380 [ ac_cv_c_uint64_support=yes ], 381 [ ac_cv_c_uint64_support=no ]) 382 ]) 383]) 384 385AC_C_DETECT_UINT64_SUPPORT 386AS_IF([test "x$ac_cv_c_uint64_support" = "xno"], 387 [AC_MSG_WARN([ 388 389Failed to use print macros (PRIu) as defined in C99 section 7.8.1. 390 391])]) 392 393AC_C_CONST 394 395dnl From licq: Copyright (c) 2000 Dirk Mueller 396dnl Check if the type socklen_t is defined anywhere 397AC_DEFUN([AC_C_SOCKLEN_T], 398[AC_CACHE_CHECK(for socklen_t, ac_cv_c_socklen_t, 399[ 400 AC_TRY_COMPILE([ 401 #include <sys/types.h> 402 #include <sys/socket.h> 403 ],[ 404 socklen_t foo; 405 ],[ 406 ac_cv_c_socklen_t=yes 407 ],[ 408 ac_cv_c_socklen_t=no 409 ]) 410]) 411if test $ac_cv_c_socklen_t = no; then 412 AC_DEFINE(socklen_t, int, [define to int if socklen_t not available]) 413fi 414]) 415 416AC_C_SOCKLEN_T 417 418dnl Check if we're a little-endian or a big-endian system, needed by hash code 419AC_DEFUN([AC_C_ENDIAN], 420[AC_CACHE_CHECK(for endianness, ac_cv_c_endian, 421[ 422 AC_RUN_IFELSE( 423 [AC_LANG_PROGRAM([], [dnl 424 long val = 1; 425 char *c = (char *) &val; 426 exit(*c == 1); 427 ]) 428 ],[ 429 ac_cv_c_endian=big 430 ],[ 431 ac_cv_c_endian=little 432 ]) 433]) 434if test $ac_cv_c_endian = big; then 435 AC_DEFINE(ENDIAN_BIG, 1, [machine is bigendian]) 436fi 437if test $ac_cv_c_endian = little; then 438 AC_DEFINE(ENDIAN_LITTLE, 1, [machine is littleendian]) 439fi 440]) 441 442AC_C_ENDIAN 443 444AC_DEFUN([AC_C_HTONLL], 445[ 446 AC_MSG_CHECKING([for htonll]) 447 have_htoll="no" 448 AC_TRY_LINK([ 449#include <sys/types.h> 450#include <netinet/in.h> 451#ifdef HAVE_INTTYPES_H 452#include <inttypes.h> */ 453#endif 454 ], [ 455 return htonll(0); 456 ], [ 457 have_htoll="yes" 458 AC_DEFINE([HAVE_HTONLL], [1], [Have ntohll]) 459 ], [ 460 have_htoll="no" 461 ]) 462 463 AC_MSG_RESULT([$have_htoll]) 464]) 465 466AC_C_HTONLL 467 468dnl Check whether the user's system supports pthread 469AC_SEARCH_LIBS(pthread_create, pthread) 470if test "x$ac_cv_search_pthread_create" = "xno"; then 471 AC_MSG_ERROR([Can't enable threads without the POSIX thread library.]) 472fi 473 474AC_CHECK_FUNCS(mlockall) 475AC_CHECK_FUNCS(getpagesizes) 476AC_CHECK_FUNCS(memcntl) 477AC_CHECK_FUNCS(sigignore) 478AC_CHECK_FUNCS(clock_gettime) 479AC_CHECK_FUNCS([accept4], [AC_DEFINE(HAVE_ACCEPT4, 1, [Define to 1 if support accept4])]) 480 481AC_DEFUN([AC_C_ALIGNMENT], 482[AC_CACHE_CHECK(for alignment, ac_cv_c_alignment, 483[ 484 AC_RUN_IFELSE( 485 [AC_LANG_PROGRAM([ 486#include <stdlib.h> 487#include <inttypes.h> 488 ], [ 489 char *buf = malloc(32); 490 491 uint64_t *ptr = (uint64_t*)(buf+2); 492 // catch sigbus, etc. 493 *ptr = 0x1; 494 495 // catch unaligned word access (ARM cpus) 496#ifdef ENDIAN_BIG 497#define ALIGNMENT 0x02030405 498#else 499#define ALIGNMENT 0x05040302 500#endif 501 *(buf + 0) = 1; 502 *(buf + 1) = 2; 503 *(buf + 2) = 3; 504 *(buf + 3) = 4; 505 *(buf + 4) = 5; 506 int* i = (int*)(buf+1); 507 return (ALIGNMENT == *i) ? 0 : 1; 508 ]) 509 ],[ 510 ac_cv_c_alignment=none 511 ],[ 512 ac_cv_c_alignment=need 513 ],[ 514 ac_cv_c_alignment=need 515 ]) 516]) 517if test $ac_cv_c_alignment = need; then 518 AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment]) 519fi 520]) 521 522AC_C_ALIGNMENT 523 524dnl Check for our specific usage of GCC atomics. 525dnl These were added in 4.1.2, but 32bit OS's may lack shorts and 4.1.2 526dnl lacks testable defines. 527have_gcc_atomics=no 528AC_MSG_CHECKING(for GCC atomics) 529AC_TRY_LINK([],[ 530 unsigned short a; 531 unsigned short b; 532 b = __sync_add_and_fetch(&a, 1); 533 b = __sync_sub_and_fetch(&a, 2); 534 ],[have_gcc_atomics=yes 535 AC_DEFINE(HAVE_GCC_ATOMICS, 1, [GCC Atomics available])]) 536AC_MSG_RESULT($have_gcc_atomics) 537 538dnl Check for usage of 64bit atomics 539dnl 32bit systems shouldn't have these. 540have_gcc_64atomics=no 541AC_MSG_CHECKING(for GCC 64bit atomics) 542AC_TRY_LINK([],[ 543 uint64_t a; 544 uint64_t b; 545 b = __sync_add_and_fetch(&a, 1); 546 b = __sync_sub_and_fetch(&a, 2); 547 ],[have_gcc_64atomics=yes 548 AC_DEFINE(HAVE_GCC_64ATOMICS, 1, [GCC 64bit Atomics available])]) 549AC_MSG_RESULT($have_gcc_64atomics) 550 551dnl Check for the requirements for running memcached with less privileges 552dnl than the default privilege set. On Solaris we need setppriv and priv.h 553dnl If you want to add support for other platforms you should check for 554dnl your requirements, define HAVE_DROP_PRIVILEGES, and make sure you add 555dnl the source file containing the implementation into memcached_SOURCE 556dnl in Makefile.am 557AC_CHECK_FUNCS(setppriv, [ 558 AC_CHECK_HEADER(priv.h, [ 559 AC_DEFINE([HAVE_DROP_PRIVILEGES], 1, 560 [Define this if you have an implementation of drop_privileges()]) 561 build_solaris_privs=yes 562 ], []) 563],[]) 564 565AM_CONDITIONAL([BUILD_SOLARIS_PRIVS],[test "$build_solaris_privs" = "yes"]) 566 567AC_CHECK_HEADER(umem.h, [ 568 AC_DEFINE([HAVE_UMEM_H], 1, 569 [Define this if you have umem.h]) 570 build_cache=no 571], [build_cache=yes]) 572 573AM_CONDITIONAL([BUILD_CACHE], [test "x$build_cache" = "xyes"]) 574 575AC_ARG_ENABLE(docs, 576 [AS_HELP_STRING([--disable-docs],[Disable documentation generation])]) 577 578AC_PATH_PROG([XML2RFC], [xml2rfc], "no") 579AC_PATH_PROG([XSLTPROC], [xsltproc], "no") 580 581AM_CONDITIONAL([BUILD_SPECIFICATIONS], 582 [test "x$enable_docs" != "xno" -a "x$XML2RFC" != "xno" -a "x$XSLTPROC" != "xno"]) 583 584 585dnl Let the compiler be a bit more picky. Please note that you cannot 586dnl specify these flags to the compiler before AC_CHECK_FUNCS, because 587dnl the test program will generate a compilation warning and hence fail 588dnl to detect the function ;-) 589if test "$ICC" = "yes" 590then 591 dnl ICC trying to be gcc. 592 CFLAGS="$CFLAGS -diag-disable 187 -Wall -Werror" 593 AC_DEFINE([_GNU_SOURCE],[1],[find sigignore on Linux]) 594elif test "$GCC" = "yes" 595then 596 GCC_VERSION=`$CC -dumpversion` 597 CFLAGS="$CFLAGS -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls" 598 case $GCC_VERSION in 599 4.4.*) 600 CFLAGS="$CFLAGS -fno-strict-aliasing" 601 ;; 602 esac 603 AC_DEFINE([_GNU_SOURCE],[1],[find sigignore on Linux]) 604elif test "$SUNCC" = "yes" 605then 606 CFLAGS="$CFLAGS -errfmt=error -errwarn -errshort=tags" 607fi 608 609AC_CONFIG_FILES(Makefile doc/Makefile) 610AC_OUTPUT 611