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