9915a4652906a4e90c9a0d9d958a40ec4a6beb3f
[awesomized/libmemcached] / memcached / configure.ac
1 AC_PREREQ(2.52)
2 m4_include([version.m4])
3 m4_include([m4/c99-backport.m4])
4 AC_INIT(memcached, VERSION_NUMBER, memcached@googlegroups.com)
5 AC_CANONICAL_SYSTEM
6 AC_CONFIG_SRCDIR(memcached.c)
7 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
8 AM_CONFIG_HEADER(config.h)
9
10 AC_PROG_CC
11
12 dnl **********************************************************************
13 dnl DETECT_ICC ([ACTION-IF-YES], [ACTION-IF-NO])
14 dnl
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],
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
36 DETECT_ICC([], [])
37
38 dnl **********************************************************************
39 dnl DETECT_SUNCC ([ACTION-IF-YES], [ACTION-IF-NO])
40 dnl
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],
45 [
46 AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
47 AS_IF(test "x$SUNCC" = "xyes", [$1], [$2])
48
49 ])
50
51 DETECT_SUNCC([CFLAGS="-mt $CFLAGS"], [])
52
53 if test "$ICC" = "no"; then
54 AC_PROG_CC_C99
55 fi
56
57 AM_PROG_CC_C_O
58 AC_PROG_INSTALL
59
60 AC_ARG_ENABLE(sasl,
61 [AS_HELP_STRING([--enable-sasl],[Enable SASL authentication])])
62
63 AC_ARG_ENABLE(sasl_pwdb,
64 [AS_HELP_STRING([--enable-sasl-pwdb],[Enable plaintext password db])])
65
66 AS_IF([test "x$enable_sasl_pwdb" = "xyes"],
67 [enable_sasl=yes ])
68
69
70 dnl **********************************************************************
71 dnl DETECT_SASL_CB_GETCONF
72 dnl
73 dnl check if we can use SASL_CB_GETCONF
74 dnl **********************************************************************
75 AC_DEFUN([AC_C_DETECT_SASL_CB_GETCONF],
76 [
77 AC_CACHE_CHECK([for SASL_CB_GETCONF],
78 [ac_cv_c_sasl_cb_getconf],
79 [AC_TRY_COMPILE(
80 [
81 #include <sasl/sasl.h>
82 ], [
83 unsigned long val = SASL_CB_GETCONF;
84 ],
85 [ ac_cv_c_sasl_cb_getconf=yes ],
86 [ ac_cv_c_sasl_cb_getconf=no ])
87 ])
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])])
91 ])
92
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], [],
98 [
99 AC_MSG_ERROR([Failed to locate the library containing sasl_server_init])
100 ])
101
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])])
105 fi
106
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])
113 build_dtrace=yes
114 # DTrace on MacOSX does not use -G option
115 $DTRACE -G -o conftest.$$ -s memcached_dtrace.d 2>/dev/zero
116 if test $? -eq 0
117 then
118 dtrace_instrument_obj=yes
119 rm conftest.$$
120 fi
121
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])
124 fi
125 else
126 AC_MSG_ERROR([Need dtrace binary and OS support.])
127 fi
128 fi
129
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"])
133
134 AC_SUBST(DTRACE)
135 AC_SUBST(DTRACEFLAGS)
136 AC_SUBST(ENABLE_SASL)
137 AC_SUBST(PROFILER_LDFLAGS)
138
139 AC_ARG_ENABLE(coverage,
140 [AS_HELP_STRING([--disable-coverage],[Disable code coverage])])
141
142 if test "x$enable_coverage" != "xno"; then
143 if test "$ICC" = "yes"
144 then
145 dnl ICC trying to be gcc, but not well
146 CFLAGS="$CFLAGS -pthread"
147 elif test "$GCC" = "yes"
148 then
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,
154 [
155 PROFILER_FLAGS="-fprofile-arcs -ftest-coverage"
156 PROFILER_LDFLAGS="-lgcov"
157 ], [
158 PROFILER_FLAGS=
159 PROFILER_LDFLAGS=
160 ])
161 fi
162 elif test "$SUNCC" = "yes"
163 then
164 AC_PATH_PROG([PROFILER], [tcov], "no", [$PATH])
165 if test "x$PROFILER" != "xno"; then
166 PROFILER_FLAGS=-xprofile=tcov
167 fi
168 fi
169 fi
170 AC_SUBST(PROFILER_FLAGS)
171
172
173 AC_ARG_ENABLE(64bit,
174 [AS_HELP_STRING([--enable-64bit],[build 64bit version])])
175 if test "x$enable_64bit" = "xyes"
176 then
177 org_cflags=$CFLAGS
178 CFLAGS=-m64
179 AC_RUN_IFELSE(
180 [AC_LANG_PROGRAM([], [dnl
181 return sizeof(void*) == 8 ? 0 : 1;
182 ])
183 ],[
184 CFLAGS="-m64 $org_cflags"
185 ],[
186 AC_MSG_ERROR([Don't know how to build a 64-bit object.])
187 ])
188 fi
189
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)
197
198 trylibeventdir=""
199 AC_ARG_WITH(libevent,
200 [ --with-libevent=PATH Specify path to libevent installation ],
201 [
202 if test "x$withval" != "xno" ; then
203 trylibeventdir=$withval
204 fi
205 ]
206 )
207
208 dnl ------------------------------------------------------
209 dnl libevent detection. swiped from Tor. modified a bit.
210
211 LIBEVENT_URL=http://www.monkey.org/~provos/libevent/
212
213 AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [
214 saved_LIBS="$LIBS"
215 saved_LDFLAGS="$LDFLAGS"
216 saved_CPPFLAGS="$CPPFLAGS"
217 le_found=no
218 for ledir in $trylibeventdir "" $prefix /usr/local ; do
219 LDFLAGS="$saved_LDFLAGS"
220 LIBS="-levent $saved_LIBS"
221
222 # Skip the directory if it isn't there.
223 if test ! -z "$ledir" -a ! -d "$ledir" ; then
224 continue;
225 fi
226 if test ! -z "$ledir" ; then
227 if test -d "$ledir/lib" ; then
228 LDFLAGS="-L$ledir/lib $LDFLAGS"
229 else
230 LDFLAGS="-L$ledir $LDFLAGS"
231 fi
232 if test -d "$ledir/include" ; then
233 CPPFLAGS="-I$ledir/include $CPPFLAGS"
234 else
235 CPPFLAGS="-I$ledir $CPPFLAGS"
236 fi
237 fi
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"])])
251 else
252 ac_cv_libevent_dir="(system)"
253 fi
254 le_found=yes
255 break
256 fi
257 done
258 LIBS="$saved_LIBS"
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
263
264 If it's already installed, specify its path using --with-libevent=/dir/
265 ])
266 fi
267 ])
268 LIBS="-levent $LIBS"
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"
273 else
274 LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
275 le_libdir="$ac_cv_libevent_dir"
276 fi
277 if test -d "$ac_cv_libevent_dir/include" ; then
278 CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
279 else
280 CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
281 fi
282 fi
283
284 dnl ----------------------------------------------------------------------------
285
286 AC_SEARCH_LIBS(umem_cache_create, umem)
287 AC_SEARCH_LIBS(gethugepagesizes, hugetlbfs)
288
289 AC_HEADER_STDBOOL
290 AH_BOTTOM([#if HAVE_STDBOOL_H
291 #include <stdbool.h>
292 #else
293 #define bool char
294 #define false 0
295 #define true 1
296 #endif ])
297
298 AC_CHECK_HEADERS([inttypes.h])
299 AH_BOTTOM([#ifdef HAVE_INTTYPES_H
300 #include <inttypes.h>
301 #endif
302 ])
303
304 dnl **********************************************************************
305 dnl Figure out if this system has the stupid sasl_callback_ft
306 dnl **********************************************************************
307
308 AC_DEFUN([AC_HAVE_SASL_CALLBACK_FT],
309 [AC_CACHE_CHECK(for sasl_callback_ft, ac_cv_has_sasl_callback_ft,
310 [
311 AC_TRY_COMPILE([
312 #ifdef HAVE_SASL_SASL_H
313 #include <sasl/sasl.h>
314 #include <sasl/saslplug.h>
315 #endif
316 ],[
317 sasl_callback_ft a_callback;
318 ],[
319 ac_cv_has_sasl_callback_ft=yes
320 ],[
321 ac_cv_has_sasl_callback_ft=no
322 ])
323 ])
324 if test $ac_cv_has_sasl_callback_ft = yes; then
325 AC_DEFINE(HAVE_SASL_CALLBACK_FT, 1, [we have sasl_callback_ft])
326 fi
327 ])
328
329 AC_HAVE_SASL_CALLBACK_FT
330
331 dnl **********************************************************************
332 dnl DETECT_UINT64_SUPPORT
333 dnl
334 dnl check if we can use a uint64_t
335 dnl **********************************************************************
336 AC_DEFUN([AC_C_DETECT_UINT64_SUPPORT],
337 [
338 AC_CACHE_CHECK([for print macros for integers (C99 section 7.8.1)],
339 [ac_cv_c_uint64_support],
340 [AC_TRY_COMPILE(
341 [
342 #ifdef HAVE_INTTYPES_H
343 #include <inttypes.h>
344 #endif
345 #include <stdio.h>
346 ], [
347 uint64_t val = 0;
348 fprintf(stderr, "%" PRIu64 "\n", val);
349 ],
350 [ ac_cv_c_uint64_support=yes ],
351 [ ac_cv_c_uint64_support=no ])
352 ])
353 ])
354
355 AC_C_DETECT_UINT64_SUPPORT
356 AS_IF([test "x$ac_cv_c_uint64_support" = "xno"],
357 [AC_MSG_WARN([
358
359 Failed to use print macros (PRIu) as defined in C99 section 7.8.1.
360
361 ])])
362
363 AC_C_CONST
364
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,
369 [
370 AC_TRY_COMPILE([
371 #include <sys/types.h>
372 #include <sys/socket.h>
373 ],[
374 socklen_t foo;
375 ],[
376 ac_cv_c_socklen_t=yes
377 ],[
378 ac_cv_c_socklen_t=no
379 ])
380 ])
381 if test $ac_cv_c_socklen_t = no; then
382 AC_DEFINE(socklen_t, int, [define to int if socklen_t not available])
383 fi
384 ])
385
386 AC_C_SOCKLEN_T
387
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,
391 [
392 AC_RUN_IFELSE(
393 [AC_LANG_PROGRAM([], [dnl
394 long val = 1;
395 char *c = (char *) &val;
396 exit(*c == 1);
397 ])
398 ],[
399 ac_cv_c_endian=big
400 ],[
401 ac_cv_c_endian=little
402 ])
403 ])
404 if test $ac_cv_c_endian = big; then
405 AC_DEFINE(ENDIAN_BIG, 1, [machine is bigendian])
406 fi
407 if test $ac_cv_c_endian = little; then
408 AC_DEFINE(ENDIAN_LITTLE, 1, [machine is littleendian])
409 fi
410 ])
411
412 AC_C_ENDIAN
413
414 AC_DEFUN([AC_C_HTONLL],
415 [
416 AC_MSG_CHECKING([for htonll])
417 have_htoll="no"
418 AC_TRY_LINK([
419 #include <sys/types.h>
420 #include <netinet/in.h>
421 #ifdef HAVE_INTTYPES_H
422 #include <inttypes.h> */
423 #endif
424 ], [
425 return htonll(0);
426 ], [
427 have_htoll="yes"
428 AC_DEFINE([HAVE_HTONLL], [1], [Have ntohll])
429 ], [
430 have_htoll="no"
431 ])
432
433 AC_MSG_RESULT([$have_htoll])
434 ])
435
436 AC_C_HTONLL
437
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.])
442 fi
443
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)
449
450 AC_DEFUN([AC_C_ALIGNMENT],
451 [AC_CACHE_CHECK(for alignment, ac_cv_c_alignment,
452 [
453 AC_RUN_IFELSE(
454 [AC_LANG_PROGRAM([
455 #include <stdlib.h>
456 #include <inttypes.h>
457 ], [
458 char *buf = malloc(32);
459
460 uint64_t *ptr = (uint64_t*)(buf+2);
461 // catch sigbus, etc.
462 *ptr = 0x1;
463
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;
468 ])
469 ],[
470 ac_cv_c_alignment=none
471 ],[
472 ac_cv_c_alignment=need
473 ],[
474 ac_cv_c_alignment=need
475 ])
476 ])
477 if test $ac_cv_c_alignment = need; then
478 AC_DEFINE(NEED_ALIGN, 1, [Machine need alignment])
479 fi
480 ])
481
482 AC_C_ALIGNMENT
483
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.
487 have_gcc_atomics=no
488 AC_MSG_CHECKING(for GCC atomics)
489 AC_TRY_LINK([],[
490 unsigned short a;
491 unsigned short b;
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)
497
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
503 dnl in Makefile.am
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
509 ], [])
510 ],[])
511
512 AM_CONDITIONAL([BUILD_SOLARIS_PRIVS],[test "$build_solaris_privs" = "yes"])
513
514 AC_CHECK_HEADER(umem.h, [
515 AC_DEFINE([HAVE_UMEM_H], 1,
516 [Define this if you have umem.h])
517 build_cache=no
518 ], [build_cache=yes])
519
520 AM_CONDITIONAL([BUILD_CACHE], [test "x$build_cache" = "xyes"])
521
522 AC_ARG_ENABLE(docs,
523 [AS_HELP_STRING([--disable-docs],[Disable documentation generation])])
524
525 AC_PATH_PROG([XML2RFC], [xml2rfc], "no")
526 AC_PATH_PROG([XSLTPROC], [xsltproc], "no")
527
528 AM_CONDITIONAL([BUILD_SPECIFICATIONS],
529 [test "x$enable_docs" != "xno" -a "x$XML2RFC" != "xno" -a "x$XSLTPROC" != "xno"])
530
531
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"
537 then
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"
542 then
543 GCC_VERSION=`$CC -dumpversion`
544 CFLAGS="$CFLAGS -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls"
545 case $GCC_VERSION in
546 4.4.*)
547 CFLAGS="$CFLAGS -fno-strict-aliasing"
548 ;;
549 esac
550 AC_DEFINE([_GNU_SOURCE],[1],[find sigignore on Linux])
551 elif test "$SUNCC" = "yes"
552 then
553 CFLAGS="$CFLAGS -errfmt=error -errwarn -errshort=tags"
554 fi
555
556 AC_CONFIG_FILES(Makefile doc/Makefile)
557 AC_OUTPUT