1dnl Process this file with autoconf to produce a configure script.
2
3AC_INIT([PgBouncer],
4        [1.16.0],
5        [https://github.com/pgbouncer/pgbouncer/issues], [],
6        [https://www.pgbouncer.org/])
7AC_CONFIG_SRCDIR(src/janitor.c)
8AC_CONFIG_HEADERS([lib/usual/config.h])
9AC_PREREQ([2.59])
10
11dnl basic init
12AC_USUAL_INIT
13
14dnl Checks for programs.
15AC_USUAL_PROGRAM_CHECK
16
17PKG_PROG_PKG_CONFIG
18
19AC_CHECK_PROGS(PANDOC, pandoc, pandoc)
20AC_CHECK_PROGS(PYTHON, [python python3 python2], python)
21
22dnl check for windows tools
23if test "$PORTNAME" = "win32"; then
24  AC_CHECK_TOOL([WINDRES], [windres])
25  AC_CHECK_TOOL([DLLWRAP], [dllwrap])
26  AC_CHECK_TOOL([DLLTOOL], [dlltool])
27fi
28AC_CHECK_TOOL([STRIP], [strip])
29
30dnl Checks for header files.
31AC_USUAL_HEADER_CHECK
32AC_CHECK_HEADERS([sys/resource.h sys/wait.h])
33
34dnl Checks for typedefs, structures, and compiler characteristics.
35AC_USUAL_TYPE_CHECK
36
37dnl autoconf 2.59 does not have UINT macros nor docdir
38m4_ifdef([AC_TYPE_UINT8_T], [
39  AC_TYPE_UINT8_T
40  AC_TYPE_UINT32_T
41  AC_TYPE_UINT64_T
42], [
43  datarootdir='${prefix}/share'
44  docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
45  AC_SUBST(datarootdir)
46  AC_SUBST(docdir)
47])
48
49dnl Checks for library functions.
50AC_USUAL_FUNCTION_CHECK
51AC_SEARCH_LIBS(clock_gettime, rt)
52AC_SEARCH_LIBS(getsockname, socket)
53AC_SEARCH_LIBS(gethostbyname, nsl)
54AC_SEARCH_LIBS(hstrerror, resolv)
55AC_CHECK_FUNCS(lstat)
56
57dnl Find libevent
58PKG_CHECK_MODULES(LIBEVENT, libevent)
59
60dnl Check for PAM authentication support
61pam_support=no
62AC_ARG_WITH(pam,
63  AS_HELP_STRING([--with-pam], [build with PAM support]),
64  [ PAM=
65    if test "$withval" != no; then
66        have_pthreads=no
67        # Look for PAM header and lib
68        AC_CHECK_HEADERS(security/pam_appl.h, [have_pam_header=t])
69        AC_CHECK_HEADERS(pthread.h, [have_pthreads=yes])
70        AC_SEARCH_LIBS(pam_start, pam, [have_libpam=t])
71        AC_SEARCH_LIBS(pthread_create, pthread, [], [have_pthreads=no])
72        if test x"${have_pthreads}" != xyes; then
73           AC_MSG_ERROR([pthread library should be available for PAM support])
74        fi
75        if test x"${have_pam_header}" != x -a x"${have_libpam}" != x -a x"${have_pthreads}" = xyes; then
76          pam_support=yes
77          AC_DEFINE(HAVE_PAM, 1, [PAM support])
78        fi
79    fi
80  ], [])
81
82dnl Check for systemd support
83AC_MSG_CHECKING([whether to build with systemd support])
84AC_ARG_WITH(systemd,
85            [AS_HELP_STRING([--with-systemd], [build with systemd support])],
86            [if test "$withval" != no; then with_systemd=yes; else with_systemd=no; fi],
87            [with_systemd=no])
88AC_MSG_RESULT([$with_systemd])
89AC_SUBST(with_systemd)[]dnl
90if test "$with_systemd" = yes; then
91  AC_DEFINE([USE_SYSTEMD], 1, [Define to build with systemd support. (--with-systemd)])
92  AC_CHECK_HEADER(systemd/sd-daemon.h, [], [AC_MSG_ERROR([header file <systemd/sd-daemon.h> is required for systemd support])])
93  AC_SEARCH_LIBS(sd_notify, systemd)
94fi
95
96##
97## DNS backend
98##
99
100# make sure all vars are set
101use_cares=no
102use_udns=no
103use_evdns=no
104
105dnl Find c-ares
106AC_MSG_CHECKING([whether to use c-ares for DNS lookups])
107AC_ARG_WITH(cares,
108  AS_HELP_STRING([--with-cares@<:@=PREFIX@:>@], [build with c-ares support]),
109  [ if test "$withval" = "no"; then
110      use_cares=no
111    elif test "$withval" = "yes"; then
112      use_cares="$withval"
113      CARES_CFLAGS=""
114      CARES_LIBS="-lcares"
115    elif test "$withval" = "auto"; then
116      use_cares="$withval"
117    else
118      use_cares=yes
119      CARES_CFLAGS="-I$withval/include"
120      CARES_LIBS="-L$withval/lib -lcares"
121    fi
122  ], [use_cares=auto])
123AC_MSG_RESULT([$use_cares])
124
125if test "$use_cares" = "auto"; then
126  PKG_CHECK_MODULES(CARES, [libcares >= 1.6.0], [use_cares=yes], [use_cares=no])
127fi
128
129if test "$use_cares" = "yes"; then
130  AC_DEFINE(USE_CARES, 1, [Use c-ares for name resolution.])
131
132  # does it support SOA parse
133  tmp_CFLAGS="$CFLAGS"
134  tmp_LIBS="$LIBS"
135  CFLAGS="$CARES_CFLAGS $CFLAGS"
136  LIBS="$CARES_LIBS $LIBS"
137  AC_CHECK_FUNCS(ares_parse_soa_reply)
138  LIBS="$tmp_LIBS"
139  CFLAGS="$tmp_CFLAGS"
140
141else # !cares
142
143dnl Find libudns
144AC_MSG_CHECKING([whether to use libudns])
145AC_ARG_WITH(udns,
146  AS_HELP_STRING([--with-udns@<:@=PREFIX@:>@], [build with udns support]),
147  [ if test "$withval" = "no"; then
148      use_udns=no
149    elif test "$withval" = "yes"; then
150      use_udns=yes
151    else
152      use_udns=yes
153      CPPFLAGS="$CPPFLAGS -I$withval/include"
154      LDFLAGS="$LDFLAGS -L$withval/lib"
155    fi
156  ], [])
157AC_MSG_RESULT([$use_udns])
158
159if test "$use_udns" = "yes"; then
160  AC_DEFINE(USE_UDNS, 1, [Use UDNS for name resolution.])
161  LIBS="-ludns $LIBS"
162  AC_MSG_CHECKING([whether libudns is available])
163  AC_LINK_IFELSE([AC_LANG_SOURCE([
164    #include <sys/types.h>
165    #include <sys/time.h>
166    #include <stddef.h>
167    #include <udns.h>
168    int main(void) {
169      struct dns_ctx *ctx = NULL;
170      dns_init(ctx, 0);
171      dns_reset(ctx);
172    } ])],
173  [AC_MSG_RESULT([found])],
174  [AC_MSG_ERROR([not found, cannot proceed])])
175
176else # !udns
177
178dnl Allow user to override the decision
179AC_ARG_ENABLE(evdns, AS_HELP_STRING([--disable-evdns], [do not use libevent for DNS lookups]),
180              [use_evdns=$enableval], [use_evdns=yes])
181AC_MSG_CHECKING([whether to use libevent for DNS lookups])
182if test "$use_evdns" = "yes"; then
183  AC_DEFINE(USE_EVDNS, 1, [Use libevent for DNS lookups.])
184  AC_MSG_RESULT([yes])
185else
186  AC_MSG_RESULT([no])
187fi
188
189dnl Check if need getaddinfo_a compat
190if test "$use_udns.$use_cares.$use_evdns" = "no.no.no"; then
191  AC_USUAL_GETADDRINFO_A
192fi
193
194fi # !udns
195
196fi # !cares
197
198## end of DNS
199
200AC_USUAL_TLS
201
202AC_USUAL_DEBUG
203AC_USUAL_CASSERT
204AC_USUAL_WERROR
205
206dnl Output findings
207AC_CONFIG_FILES([config.mak])
208AC_OUTPUT
209
210dnl If separate build dir, link Makefile over
211test -f Makefile || {
212  echo "Linking Makefile"
213  ln -s $srcdir/Makefile
214}
215
216echo ""
217echo "Results:"
218dnl Note: Report here should match selection in src/dnslookup.c
219if test "$use_cares" = "yes"; then
220  echo "  adns    = c-ares"
221elif test "$use_udns" = "yes"; then
222  echo "  adns    = udns"
223elif test "$use_evdns" = "yes"; then
224  echo "  adns    = evdns2"
225elif test "$ac_cv_usual_glibc_gaia" = "yes"; then
226  echo "  adns    = libc"
227else
228  echo "  adns    = compat"
229fi
230echo "  pam     = $pam_support"
231echo "  systemd = $with_systemd"
232echo "  tls     = $tls_support"
233echo ""
234