Placate all the compilers. Ugly.
[beanstalkd.git] / configure.in
blob50a6faac3ac2b98e452742fa0b40fe9b73622e21
1 dnl this files has to be processed by autoconf
2 AC_PREREQ(2.61)
4 AC_INIT
5 AC_CONFIG_SRCDIR([README])
6 AC_CONFIG_SRCDIR(job.c)
7 AC_CONFIG_HEADERS(config.h)
8 AC_CONFIG_MACRO_DIR([m4])
10 AM_INIT_AUTOMAKE(beanstalkd,$($srcdir/version.sh))
11 AM_MAINTAINER_MODE
13 AS_COMPILER_FLAGS(CFLAGS, "-Wall -Werror")
15 AC_PROG_CC
16 AC_PROG_INSTALL
18 DEFAULT_INSTALL_PREFIX="/usr/local"
19 STANDARD_PREFIXES="/usr /usr/local /opt /local"
22 dnl {{{ --with-libdir
23 AC_ARG_WITH(libdir,
24   [AS_HELP_STRING([--with-libdir],[look for libraries in .../NAME rather than .../lib])
25   ],
26   [LIBDIR=$with_libdir],
27   [LIBDIR=lib]
29 dnl }}}
31 dnl {{{ --disable-rpath
32 AC_ARG_ENABLE(rpath,
33   [AS_HELP_STRING([--disable-rpath],[disable passing additional runtime library search paths])
34   ],
35   [BEAN_RPATH=no],
36   [BEAN_RPATH=yes]
38 dnl }}}
40 dnl {{{ check for rpath support
41 AC_MSG_CHECKING([if compiler supports -R])
42 AC_CACHE_VAL(bt_cv_cc_dashr,[
43   SAVE_LIBS=$LIBS
44   LIBS="-R /usr/$LIBDIR $LIBS"
45   AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[bt_cv_cc_dashr=yes],[bt_cv_cc_dashr=no])
46   LIBS=$SAVE_LIBS])
47 AC_MSG_RESULT([$bt_cv_cc_dashr])
48 if test $bt_cv_cc_dashr = "yes"; then
49   ld_runpath_switch=-R
50 else
51   AC_MSG_CHECKING([if compiler supports -Wl,-rpath,])
52   AC_CACHE_VAL(bt_cv_cc_rpath,[
53     SAVE_LIBS=$LIBS
54     LIBS="-Wl,-rpath,/usr/$LIBDIR $LIBS"
55     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[bt_cv_cc_rpath=yes],[bt_cv_cc_rpath=no])
56     LIBS=$SAVE_LIBS])
57   AC_MSG_RESULT([$bt_cv_cc_rpath])
58   if test $bt_cv_cc_rpath = "yes"; then
59     ld_runpath_switch=-Wl,-rpath,
60   else
61     ld_runpath_switch=-L
62   fi
64 if test "$BEAN_RPATH" = "no"; then
65   ld_runpath_switch=
67 dnl }}}
69 dnl {{{ --with-event
70 AC_ARG_WITH(event,
71   [AS_HELP_STRING([--with-event],[specify libevent install prefix])
72   ],
73   [ ],
74   [with_event=yes]
77 if test "x$with_event" = "xno"; then
78   AC_MSG_ERROR([can't continue without libevent])
79 else
80   AC_MSG_CHECKING([libevent install prefix])
82   if test "x$with_event" = "xyes"; then
83     for i in `echo "$STANDARD_PREFIXES"`; do
84       if test -f "$i/include/event.h"; then
85         LIBEVENT_DIR="$i"
86         break;
87       fi
88     done
89   else
90     if test -f "$with_event/include/event.h"; then
91       LIBEVENT_DIR="$with_event"
92       break;
93     else
94       AC_MSG_ERROR([Can't find libevent headers under $with_event directory])
95     fi
96   fi
98   if test "x$LIBEVENT_DIR" = "x"; then
99     AC_MSG_ERROR([Unable to locate libevent headers, please use --with-event=<DIR>])
100   fi
102   AC_MSG_RESULT([$LIBEVENT_DIR])
103   LDFLAGS="$LDFLAGS -L$LIBEVENT_DIR/$LIBDIR"
104   CFLAGS="$CFLAGS -I$LIBEVENT_DIR/include"
105   LIBS="$LIBS -levent"
107   AC_CHECK_FUNCS([posix_fallocate])
108   dnl {{{ make sure that fdatasync exits
109   AC_CACHE_CHECK([for fdatasync],[ac_cv_func_fdatasync],[
110     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
111   #include <unistd.h>
112   ]],[[
113   fdatasync(4);
114   ]])],
115   [ac_cv_func_fdatasync=yes],
116   [ac_cv_func_fdatasync=no])
117   ])
118   AS_IF([test "x${ac_cv_func_fdatasync}" = "xyes"],
119    [AC_DEFINE([HAVE_FDATASYNC],[1],[If the system defines fdatasync])])
120   dnl }}}
122   AC_CHECK_LIB([socket], [bind], [
123     LIBS="$LIBS -lsocket"
124   ])
126   AC_CHECK_LIB([nsl], [inet_aton], [
127     LIBS="$LIBS -lnsl"
128   ])
130   if test "$BEAN_RPATH" != "no"; then
131     LDFLAGS="$LDFLAGS $ld_runpath_switch$LIBEVENT_DIR/$LIBDIR"
132   fi
134   AC_CHECK_LIB([event], [event_get_version], [], [
135     AC_MSG_ERROR([event_get_version() is missing, check config.log for more details])
136   ])
138   AC_CHECK_LIB([event], [event_reinit], [], [
139     AC_MSG_ERROR([beanstalkd requires libevent version 1.4.1 or later.])
140   ])
142   if test -f "$LIBEVENT_DIR/$LIBDIR/libevent.so"; then
143     LIBEVENT="$LIBEVENT_DIR/$LIBDIR/libevent.so";
144   else 
145     if test -f "$LIBEVENT_DIR/lib/libevent.so"; then
146       LIBEVENT="$LIBEVENT_DIR/lib/libevent.so";
147     else 
148       if test -f "$LIBEVENT_DIR/lib64/libevent.so"; then 
149         LIBEVENT="$LIBEVENT_DIR/lib64/libevent.so";
150       fi
151     fi
152   fi
155 dnl }}}
157 dnl {{{ --enable-debug 
158 AC_ARG_ENABLE(debug,
159   [AS_HELP_STRING([--enable-debug],[enable debugging symbols and compile flags])
160   ],
161   [
162   if test x"$enableval" = xyes ; then
163     debug="yes"
164   else
165     debug="no"
166   fi
167   ]
170 if test x"$debug" = xyes ; then
171   AC_DEFINE([BEAN_DEBUG], [], [debug build])
173   if test x"$GCC" = xyes; then
174     dnl Remove any optimization flags from CFLAGS
175     changequote({,})
176     CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9s]*//g'`
177     CFLAGS=`echo "$CFLAGS" | sed -e 's/-g[0-2]\? //g'`
178     changequote([,])
179     CFLAGS="$CFLAGS -g3 -Wall -O0"
180   fi
182   dnl Do not strip symbols from developer object files.
183   INSTALL_STRIP_FLAG=""
184 else
185   dnl Make sure to strip symbols from non-developer object files.
186   INSTALL_STRIP_FLAG="-s"
188 dnl }}}
190 # Checks for typedefs, structures, and compiler characteristics.
191 AC_TYPE_UINT16_T
193 AC_SUBST(INSTALL_STRIP_FLAG)
195 # This is a distributed file -- we don't want make distclean to delete it.
196 # Automake "helpfully" causes make distclean to delete files listed in
197 # AC_CONFIG_FILES, but it doesn't know about shell variables. We can use
198 # that limitation to preserve beanstalkd.spec.
199 generate_but_do_not_delete_upon_distclean=beanstalkd.spec
201 AC_CONFIG_FILES([Makefile $generate_but_do_not_delete_upon_distclean])
202 AC_OUTPUT
204 dnl vim700: ts=2 sw=2 et