client_login_timeout: check wait_for_welcome
[pgbouncer.git] / configure.ac
blobafac0578b967febd14640d88ca0f56865c675c71
1 dnl Process this file with autoconf to produce a configure script.
3 AC_INIT(pgbouncer, 1.3.4)
4 AC_CONFIG_SRCDIR(src/janitor.c)
5 AC_CONFIG_HEADER(include/config.h)
6 AC_PREREQ([2.59])
8 dnl windows port check (Not use AC_CANONICAL_HOST)
9 AC_MSG_CHECKING([target host type])
10 xhost="$host_alias"
11 if test "x$xhost" = "x"; then
12   xhost=`uname -s`
14 case $xhost in
15 *cygwin* | *mingw* | *pw32* | *MINGW*)
16    LIBS="$LIBS -lws2_32"
17    PORTNAME=win32;;
18 *) PORTNAME=unix ;;
19 esac
20 AC_SUBST(PORTNAME)
21 AC_MSG_RESULT([$PORTNAME])
23 dnl Checks for programs.
24 AC_PROG_CC
25 AC_PROG_CPP
27 dnl ./install-sh must be manually set up if not using automake
28 AC_PROG_INSTALL
30 dnl Check if linker supports -Wl,--as-needed
31 dnl That helps to get rid of unnecessary -lrt
32 if test "$GCC" = "yes"; then
33   old_LDFLAGS="$LDFLAGS"
34   LDFLAGS="$LDFLAGS -Wl,--as-needed"
35   AC_MSG_CHECKING([whether linker supports --as-needed])
36   AC_LINK_IFELSE([int main(void) { return 0; }],
37     [AC_MSG_RESULT([yes])],
38     [AC_MSG_RESULT([no])
39      LDFLAGS="$old_LDFLAGS"])
42 dnl Check if compiler supports __func__
43 AC_CACHE_CHECK([whether compiler supports __func__], pgac_cv_funcname_func,
44   [AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
45                   [pgac_cv_funcname_func=yes], [pgac_cv_funcname_func=no])])
46 if test x"$pgac_cv_funcname_func" = xyes ; then
47   AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
48             [Define to 1 if your compiler understands __func__.])
51 dnl asciidoc >= 8.2
52 AC_CHECK_PROGS(ASCIIDOC, asciidoc)
53 if test -n "$ASCIIDOC"; then
54   AC_MSG_CHECKING([for asciidoc version >= 8.2])
55   ver=`$ASCIIDOC --version 2>&1 | sed -e 's/asciidoc //'`
56   case "$ver" in
57 dnl hack to make possible to use [, ] in regex
58 changequote({, })dnl
59   [0-7].*|8.[01]|8.[01].*)
60 changequote([, ])dnl
61       AC_MSG_RESULT([$ver, too old])
62       ASCIIDOC=""
63       ;;
64   *)
65       AC_MSG_RESULT([$ver, ok])
66       ;;
67   esac
70 dnl check for xmlto, but only if asciidoc is found
71 if test -n "$ASCIIDOC"; then
72   AC_CHECK_PROGS(XMLTO, xmlto)
75 dnl check for windows tools
76 if test "$PORTNAME" = "win32"; then
77   AC_CHECK_TOOL([WINDRES], [windres])
78   AC_CHECK_TOOL([DLLWRAP], [dllwrap])
79   AC_CHECK_TOOL([DLLTOOL], [dlltool])
81 AC_CHECK_TOOL([STRIP], [strip])
83 dnl Additional gcc tuning
84 if test x"$GCC" = xyes; then
85   AC_MSG_CHECKING([for working warning switches])
86   good_CFLAGS="$CFLAGS"
87   warnings=""
88   flags="-Wall -Wextra"
89   # turn off noise from Wextra
90   flags="$flags -Wno-unused-parameter -Wno-missing-field-initializers"
91   # Wextra does not turn those on?
92   flags="$flags -Wmissing-prototypes -Wpointer-arith -Wendif-labels"
93   flags="$flags -Wdeclaration-after-statement -Wold-style-definition"
94   flags="$flags -Wstrict-prototypes -Wundef -Wformat=2 -Wnonnull"
95   for f in $flags; do
96     CFLAGS="$good_CFLAGS $warnings $f"
97     AC_COMPILE_IFELSE([void foo(void){}], [warnings="$warnings $f"])
98   done
100   # avoid -Wextra if missing-field.initializers does not work
101   echo "$warnings" | grep missing-field-initializers > /dev/null \
102   || warnings=`echo "$warnings"|sed 's/-Wextra//'`
104   CFLAGS="$good_CFLAGS $warnings"
105   AC_MSG_RESULT([$warnings])
108 dnl Checks for header files.
109 AC_CHECK_HEADERS([crypt.h sys/param.h sys/socket.h sys/uio.h libgen.h pwd.h grp.h])
110 AC_CHECK_HEADERS([sys/resource.h sys/wait.h sys/un.h arpa/inet.h])
111 AC_CHECK_HEADERS([netinet/in.h netinet/tcp.h netdb.h regex.h])
113 dnl ucred.h may have prereqs
114 AC_CHECK_HEADERS([ucred.h sys/ucred.h], [], [], [
115 #ifdef HAVE_SYS_TYPES_H
116 #include <sys/types.h>
117 #endif
118 #ifdef HAVE_SYS_PARAM_H
119 #include <sys/param.h>
120 #endif
123 dnl Checks for typedefs, structures, and compiler characteristics.
124 AC_C_INLINE
125 AC_C_BIGENDIAN
126 AC_SYS_LARGEFILE
127 AC_TYPE_PID_T
128 AC_TYPE_SIZE_T
130 dnl autoconf 2.59 does not have UINT macros nor docdir
131 m4_ifdef([AC_TYPE_UINT8_T], [
132   AC_TYPE_UINT8_T
133   AC_TYPE_UINT32_T
134   AC_TYPE_UINT64_T
135 ], [
136   datarootdir='${prefix}/share'
137   docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
138   AC_SUBST(datarootdir)
139   AC_SUBST(docdir)
142 dnl Checks for library functions.
143 AC_CHECK_FUNCS(strlcpy strlcat getpeereid getpeerucred basename)
144 AC_SEARCH_LIBS(crypt, crypt)
145 AC_SEARCH_LIBS(clock_gettime, rt)
146 AC_SEARCH_LIBS(getsockname, socket)
147 AC_SEARCH_LIBS(gethostbyname, nsl)
148 AC_SEARCH_LIBS(hstrerror, resolv)
149 AC_SEARCH_LIBS(regcomp, regex, [], AC_MSG_ERROR([regcomp not found]))
150 AC_CHECK_FUNCS(crypt inet_ntop lstat)
152 dnl Find libevent
153 AC_MSG_CHECKING([for libevent])
154 AC_ARG_WITH(libevent,
155   AC_HELP_STRING([--with-libevent=prefix],[Specify where libevent is installed]),
156   [ test "$withval" = "no" && AC_MSG_ERROR("cannot work without libevent")
157     CPPFLAGS="$CPPFLAGS -I$withval/include"
158     LDFLAGS="$LDFLAGS -L$withval/lib" ])
159 LIBS="-levent $LIBS"
160 AC_LINK_IFELSE([
161   #include <sys/types.h>
162   #include <sys/time.h>
163   #include <stdio.h>
164   #include <event.h>
165   int main(void) {
166     struct event ev;
167     event_init();
168     event_set(&ev, 1, EV_READ, NULL, NULL);
169     /* this checks for 1.2+ but next we check for 1.3b+ anyway */
170     /* event_base_free(NULL); */
171   } ],
172 [AC_MSG_RESULT([found])],
173 [AC_MSG_ERROR([not found, cannot proceed])])
175 dnl libevent < 1.3b crashes on event_base_free()
176 dnl no good way to check libevent version.  use hack:
177 dnl evhttp.h defines HTTP_SERVUNAVAIL only since 1.3b
178 AC_MSG_CHECKING([whether libevent version >= 1.3b])
179 AC_EGREP_CPP([HTTP_SERVUNAVAIL],
180 [#include <evhttp.h>
181   HTTP_SERVUNAVAIL ],
182 [AC_MSG_ERROR([no, cannot proceed])],
183 [AC_MSG_RESULT([yes])])
185 AC_CHECK_FUNCS(event_loopbreak)
187 AC_ARG_ENABLE(debug,
188   AC_HELP_STRING([--disable-debug],[strip binary]),
189   [], [enable_debug=yes])
190 AC_MSG_CHECKING([whether to build debug binary])
191 if test "$enable_debug" = "yes"; then
192   LDFLAGS="-g $LDFLAGS"
193   BININSTALL="$INSTALL"
194   AC_MSG_RESULT([yes])
195 else
196   BININSTALL="$INSTALL -s"
197   AC_MSG_RESULT([no])
199 AC_SUBST(enable_debug)
200 AC_SUBST(BININSTALL)
202 AC_ARG_ENABLE(cassert, AC_HELP_STRING([--enable-cassert],[turn on assert checking in code]))
203 AC_MSG_CHECKING([whether to enable asserts])
204 if test "$enable_cassert" = "yes"; then
205   AC_DEFINE(CASSERT, 1, [Define to enable assert checking])
206   AC_MSG_RESULT([yes])
207 else
208   AC_MSG_RESULT([no])
211 AC_ARG_ENABLE(werror, AC_HELP_STRING([--enable-werror],[add -Werror to CFLAGS]))
212 AC_MSG_CHECKING([whether to fail on warnings])
213 if test "$enable_werror" = "yes"; then
214   CFLAGS="$CFLAGS -Werror"
215   AC_MSG_RESULT([yes])
216 else
217   AC_MSG_RESULT([no])
220 if test \! "$srcdir" = "$builddir"; then
221   CPPFLAGS="-I\$(builddir)/include $CPPFLAGS"
224 dnl Output findings
225 AC_OUTPUT([config.mak])
227 dnl If separate build dir, link Makefile over
228 test -f Makefile || {
229   echo "Linking Makefile"
230   ln -s $srcdir/Makefile