Solaris doesn't like outputting a NULL to a %s in format strings.
[asterisk/asterisk.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2 #
3 # Make sure we use autoconf 2.60 to generate the "configure" script,
4 # in case we want to commit it. Other than that, version 2.59 is
5 # perfectly fine for our purposes, so people who want to modify
6 # this file just have to remember to set the AC_PREREQ argument
7 # to something that suits their needs.
8
9 AC_PREREQ(2.60)
10
11 AC_INIT(asterisk, 1.6, www.asterisk.org)
12
13 # cross-compile macros
14 AC_CANONICAL_BUILD
15 AC_CANONICAL_HOST
16
17 # check existence of the package
18 AC_CONFIG_SRCDIR([main/asterisk.c])
19
20 AC_COPYRIGHT("Asterisk")
21 AC_REVISION($Revision$)
22
23 # preserve any CFLAGS or LDFLAGS that may be set
24 # NOTE: This must be done before calling any macros that end up
25 # calling AC_PROG_CC or the like, since they will set a default
26 # set of CFLAGS ("-g -O2") if the user did not supply any, and
27 # we don't want those default flags to be carried over into the
28 # rest of the build system since we have other means of controlling
29 # debugging symbol generation and optimization.
30 CONFIG_CFLAGS="${CFLAGS}"
31 CONFIG_LDFLAGS="${LDFLAGS}"
32 AC_SUBST(CONFIG_CFLAGS)
33 AC_SUBST(CONFIG_LDFLAGS)
34
35 # specify output header file
36 AC_CONFIG_HEADER(include/asterisk/autoconfig.h)
37
38 AC_USE_SYSTEM_EXTENSIONS        # note- does not work on FreeBSD
39
40 case "${host_os}" in
41      freebsd*)
42      ac_default_prefix=/usr/local
43      CPPFLAGS=-I/usr/local/include
44      LDFLAGS=-L/usr/local/lib
45      ;;
46      openbsd*)
47      ac_default_prefix=/usr/local
48      if test ${prefix} = '/usr/local' || test ${prefix} = 'NONE'; then
49         if test ${sysconfdir} = '${prefix}/etc'; then
50            sysconfdir=/etc
51         fi
52         if test ${mandir} = '${prefix}/man'; then
53            mandir=/usr/share/man
54         fi
55      fi
56      CPPFLAGS=-I/usr/local/include
57      LDFLAGS=-L/usr/local/lib
58      ;;
59      darwin*)
60      AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be used.])
61      ;;
62      *)
63      ac_default_prefix=/usr
64      if test ${prefix} = '/usr' || test ${prefix} = 'NONE'; then
65         if test ${sysconfdir} = '${prefix}/etc'; then
66            sysconfdir=/etc
67         fi
68         if test ${mandir} = '${prefix}/man'; then
69            mandir=/usr/share/man
70         fi
71      fi
72      ;;
73 esac
74
75 if test ${prefix} = ${ac_default_prefix} || test ${prefix} = 'NONE'; then
76      if test ${localstatedir} = '${prefix}/var'; then
77         localstatedir=/var
78      fi
79 fi
80
81 BUILD_PLATFORM=${build}
82 BUILD_CPU=${build_cpu}
83 BUILD_VENDOR=${build_vendor}
84 BUILD_OS=${build_os}
85
86 AC_SUBST(BUILD_PLATFORM)
87 AC_SUBST(BUILD_CPU)
88 AC_SUBST(BUILD_VENDOR)
89 AC_SUBST(BUILD_OS)
90
91 HOST_PLATFORM=${host}
92 HOST_CPU=${host_cpu}
93 HOST_VENDOR=${host_vendor}
94 HOST_OS=${host_os}
95
96 AC_SUBST(HOST_PLATFORM)
97 AC_SUBST(HOST_CPU)
98 AC_SUBST(HOST_VENDOR)
99 AC_SUBST(HOST_OS)
100
101 PBX_WINARCH=0
102
103 case "${host_os}" in
104      freebsd*)
105      OSARCH=FreeBSD
106      ;;
107      netbsd*)
108      OSARCH=NetBSD
109      ;;
110      openbsd*)
111      OSARCH=OpenBSD
112      ;;
113      solaris*)
114      OSARCH=SunOS
115      ;;
116      mingw32)
117      OSARCH=mingw32
118      PBX_WINARCH=1
119      ;;
120      cygwin)
121      OSARCH=cygwin
122      PBX_WINARCH=1
123      ;;
124      linux-gnueabi)
125      OSARCH=linux-gnu
126      ;;
127      *)
128      OSARCH=${host_os}
129      ;;
130 esac
131
132 AC_SUBST(OSARCH)
133 AC_SUBST(PBX_WINARCH)
134
135 #  check for uname
136 AC_PATH_TOOL([UNAME], [uname], No)
137 if test ! x"${UNAME}" = xNo; then
138    PBX_OSREV=$(${UNAME} -r)
139 fi
140 AC_SUBST(PBX_OSREV)
141
142 AH_TOP(
143 #ifndef ASTERISK_AUTOCONFIG_H
144 #define ASTERISK_AUTOCONFIG_H
145
146 #include "asterisk/buildopts.h"
147
148 )
149
150 AH_BOTTOM(
151 #endif
152 )
153
154 # cross-compile checks
155 if test "${cross_compiling}" = "yes"; 
156 then
157    AC_CHECK_TOOL(CC, gcc, :)
158    AC_CHECK_TOOL(CXX, g++, :)
159    AC_CHECK_TOOL(LD, ld, :)
160    AC_CHECK_TOOL(RANLIB, ranlib, :)
161 fi
162
163 # Checks for programs.
164 AC_PROG_CC
165 AC_PROG_CXX
166 AC_PROG_CPP
167 AC_PROG_CXXCPP
168 # This macro is just copied into our local acinclude.m4 from libtool.m4 so that
169 # the developers regenerating the configure script don't have to install libtool.
170 AST_PROG_LD     # note, does not work on FreeBSD
171 AC_PROG_AWK
172 AC_PROG_INSTALL
173 AC_PROG_LN_S
174 AC_PROG_RANLIB
175 AST_CHECK_GNU_MAKE
176
177 AC_PATH_TOOL([STRIP], [strip], :)
178 AC_PATH_TOOL([AR], [ar], :)
179
180 GNU_LD=0
181 if test "x$with_gnu_ld" = "xyes" ; then
182    GNU_LD=1
183 fi
184 AC_SUBST(GNU_LD)
185
186 AC_PATH_PROG([BISON], [bison], :)
187 AC_PATH_PROG([FLEX], [flex], :)
188 AC_PATH_PROG([GREP], [grep], :)
189 AC_PATH_PROG([FIND], [find], :)
190 AC_PATH_PROG([COMPRESS], [compress], :)
191 AC_PATH_PROG([BASENAME], [basename], :)
192 AC_PATH_PROG([ID], [id], :)
193 AC_PATH_PROG([DIRNAME], [dirname], :)
194 AC_PATH_PROG([SHELL], [sh], :)
195 AC_PATH_PROG([LN], [ln], :)
196 AC_PATH_PROG([DOT], [dot], :)
197 AC_PATH_PROG([WGET], [wget], :)
198 AC_PATH_PROG([CURL], [curl], :)
199 AC_PATH_PROG([RUBBER], [rubber], :)
200 AC_PATH_PROG([KPATHSEA], [kpsewhich], :)
201 AC_PATH_PROG([XMLSTARLET], [xmlstarlet], :)
202 if test "${WGET}" != ":" ; then
203   DOWNLOAD=${WGET}
204 else if test "${CURL}" != ":" ; then
205   DOWNLOAD="${CURL} -O --progress-bar -w \"%{url_effective}\n\""
206 else
207   AC_PATH_PROG([FETCH], [fetch], [:])
208   DOWNLOAD=${FETCH}
209 fi
210 fi
211 AC_SUBST(DOWNLOAD)
212
213 AC_CACHE_CHECK([for bison that supports parse-param], [ac_cv_path_BISON2], [
214         if test "x$BISON" != "x:" ; then
215                 # Create a temporary directory $tmp in $TMPDIR (default /tmp).
216                 # Use mktemp if possible; otherwise fall back on mkdir,
217                 # with $RANDOM to make collisions less likely.
218                 : ${TMPDIR=/tmp}
219                 {
220                   tmp=`
221                     (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
222                   ` &&
223                   test -n "$tmp" && test -d "$tmp"
224                 } || {
225                   tmp=$TMPDIR/foo$$-$RANDOM
226                   (umask 077 && mkdir "$tmp")
227                 } || exit $?
228                 cat >$tmp/test.y <<__EOL__
229 %parse-param {struct parse_io *parseio}
230 %%
231 file : { \$\$ = parseio->pval = 1; }
232         ;
233 %%
234 __EOL__
235                 ${BISON} -o ${tmp}/test.tab.c ${tmp}/test.y >/dev/null 2>&1
236                 if test -e "${tmp}/test.tab.c"; then
237                         ac_cv_path_BISON2=${BISON}
238                 fi
239                 rm -rf ${tmp}
240         fi
241         ])
242 if test "x${ac_cv_path_BISON2}" = "x" ; then
243         BISON=:
244         PBX_BISON=0
245 else
246         PBX_BISON=1
247 fi
248 AC_SUBST(PBX_BISON)
249 if test "x${FLEX}" = "x:" ; then
250         PBX_FLEX=0
251 else
252         PBX_FLEX=1
253 fi
254 AC_SUBST(PBX_FLEX)
255
256 AC_CHECK_TOOL([SOXMIX], [soxmix], [:])
257 if test "${SOXMIX}" != ":" ; then
258         AC_DEFINE([HAVE_SOXMIX], 1, [Define to 1 if your system has soxmix application.])
259 fi
260
261 AC_CHECK_PROGS([MD5], [md5 md5sum gmd5sum digest])
262
263 if test "${MD5}" = "digest" ; then
264    MD5="${MD5} -a md5"   
265 fi
266
267 ACX_PTHREAD
268
269 AC_LANG(C)
270
271 AC_ARG_ENABLE([dev-mode],
272         [AS_HELP_STRING([--enable-dev-mode],
273                 [Turn on developer mode])],
274         [case "${enableval}" in
275               y|ye|yes) AST_DEVMODE=yes ;;
276               n|no)  AST_DEVMODE=no ;;
277               noisy)
278               AST_DEVMODE=yes
279               NOISY_BUILD=yes
280               ;;
281               *) AC_MSG_ERROR(bad value ${enableval} for --enable-dev-mode)  ;;
282         esac])
283 AC_SUBST(NOISY_BUILD)
284 AC_SUBST(AST_DEVMODE)
285
286 # AST_EXT_LIB_SETUP is used to tell configure to handle variables for
287 # various packages.
288 # $1 is the prefix for the variables in makeopts and autoconfig.h
289 # $2 is the short comment, $4 is the long comment
290 # $3 is the name used in --with- or --without- flags for configure.
291 #
292 # Package option names should be in alphabetical order
293 # by the --with option name (the third field),
294 # to make things easier for the users.
295
296 AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
297
298 # BKTR is used for backtrace support on platforms that do not
299 # have it natively.
300 AST_EXT_LIB_SETUP([BKTR], [Stack Backtrace support], [execinfo])
301 AST_EXT_LIB_SETUP([BLUETOOTH], [Bluetooth Support], [bluetooth])
302 AST_EXT_LIB_SETUP([CAP], [POSIX 1.e capabilities], [cap])
303 AST_EXT_LIB_SETUP([CURL], [cURL], [curl])
304 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
305 AST_EXT_LIB_SETUP([CRYPTO], [OpenSSL Cryptography support], [crypto])
306 AST_EXT_LIB_SETUP([DAHDI], [DAHDI], [dahdi])
307 AST_EXT_LIB_SETUP([FFMPEG], [Ffmpeg and avcodec library], [avcodec])
308 AST_EXT_LIB_SETUP([GSM], [External GSM library], [gsm], [, use 'internal' GSM otherwise])
309 AST_EXT_LIB_SETUP([GTK], [gtk libraries], [gtk])
310 AST_EXT_LIB_SETUP([GTK2], [gtk2 libraries], [gtk2])
311 AST_EXT_LIB_SETUP([GMIME], [GMime library], [gmime])
312 AST_EXT_LIB_SETUP([HOARD], [Hoard Memory Allocator], [hoard])
313 AST_EXT_LIB_SETUP([ICAL], [ical libraries], [ical])
314 AST_EXT_LIB_SETUP([ICONV], [Iconv Library], [iconv])
315 AST_EXT_LIB_SETUP([IKSEMEL], [Iksemel Jabber Library], [iksemel])
316 AST_EXT_LIB_SETUP([IMAP_TK], [UW IMAP Toolkit], [imap])
317 AST_EXT_LIB_SETUP([INOTIFY], [inotify support], [inotify])
318 AST_EXT_LIB_SETUP([IODBC], [iODBC], [iodbc])
319 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
320 AST_EXT_LIB_SETUP([JACK], [Jack Audio Connection Kit], [jack])
321 AST_EXT_LIB_SETUP([LDAP], [OpenLDAP], [ldap])
322 AST_EXT_LIB_SETUP([LIBXML2], [LibXML2], [libxml2])
323 AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
324 AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
325 AST_EXT_LIB_SETUP([MISDN], [mISDN User Library], [misdn])
326 AST_EXT_LIB_SETUP([MYSQLCLIENT], [mysqlclient], [mysqlclient])
327 AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
328 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
329 AST_EXT_LIB_SETUP([NEON], [neon], [neon])
330 AST_EXT_LIB_SETUP([NETSNMP], [Net-SNMP], [netsnmp])
331 AST_EXT_LIB_SETUP([NEWT], [newt], [newt])
332 AST_EXT_LIB_SETUP([OGG], [OGG], [ogg])
333 AST_EXT_LIB_SETUP([OSPTK], [OSP Toolkit], [osptk])
334 AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
335 AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
336 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
337 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
338 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
339 AST_EXT_LIB_SETUP_DEPENDENT([PRI_SUBADDR], [ISDN PRI subaddressing], [PRI], [pri])
340 AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_HOLD], [ISDN PRI call hold], [PRI], [pri])
341 AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_REROUTING], [ISDN PRI call rerouting and call deflection], [PRI], [pri])
342 AST_EXT_LIB_SETUP_DEPENDENT([PRI_SETUP_KEYPAD], [ISDN PRI keypad facility in SETUP], [PRI], [pri])
343 # ------------------------------------v
344 # TODO: The code can be changed to always include these features now.
345 # These features will always be present if pri_connected_line_update is available.
346 AST_EXT_LIB_SETUP_DEPENDENT([PRI_VERSION], [ISDN PRI get_version], [PRI], [pri])
347 AST_EXT_LIB_SETUP_DEPENDENT([PRI_INBANDDISCONNECT], [ISDN PRI set_inbanddisconnect], [PRI], [pri])
348 AST_EXT_LIB_SETUP_DEPENDENT([PRI_PROG_W_CAUSE], [ISDN progress with cause], [PRI], [pri])
349 AST_EXT_LIB_SETUP_DEPENDENT([PRI_SERVICE_MESSAGES], [ISDN service messages], [PRI], [pri])
350 AST_EXT_LIB_SETUP_DEPENDENT([PRI_REVERSE_CHARGE], [ISDN reverse charge], [PRI], [pri])
351 # ------------------------------------^
352 AST_EXT_LIB_SETUP([RESAMPLE], [LIBRESAMPLE], [resample])
353 AST_EXT_LIB_SETUP([SPANDSP], [SPANDSP], [spandsp])
354 AST_EXT_LIB_SETUP([SS7], [ISDN SS7], [ss7])
355 AST_EXT_LIB_SETUP([OPENR2], [MFR2], [openr2])
356 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
357 AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
358 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
359 AST_EXT_LIB_SETUP([SDL], [Sdl], [sdl])
360 AST_EXT_LIB_SETUP([SDL_IMAGE], [Sdl Image library], [SDL_image])
361 AST_EXT_LIB_SETUP([OPENAIS], [OpenAIS], [openais])
362 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
363 AST_EXT_LIB_SETUP([SPEEX_PREPROCESS], [Speex preprocess routines], [speex])
364 AST_EXT_LIB_SETUP([SPEEXDSP], [Speexdsp], [speexdsp])
365 AST_EXT_LIB_SETUP_DEPENDENT([SPEEX_PREPROCESS], [speex_preprocess_ctl], [], [speex])
366 AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
367 AST_EXT_LIB_SETUP([SQLITE3], [SQLite], [sqlite3])
368 AST_EXT_LIB_SETUP([SUPPSERV], [mISDN Supplemental Services], [suppserv])
369 AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL Secure Sockets Layer support], [ssl])
370 AST_EXT_LIB_SETUP([FREETDS], [FreeTDS], [tds])
371 AST_EXT_LIB_SETUP([TERMCAP], [Termcap], [termcap])
372 AST_EXT_LIB_SETUP([TINFO], [Term Info], [tinfo])
373 AST_EXT_LIB_SETUP([TONEZONE], [tonezone], [tonezone])
374 AST_EXT_LIB_SETUP([UNIXODBC], [unixODBC], [unixodbc])
375 AST_EXT_LIB_SETUP([USB], [usb], [usb])
376 AST_EXT_LIB_SETUP([VORBIS], [Vorbis], [vorbis])
377 AST_EXT_LIB_SETUP([VPB], [Voicetronix API], [vpb])
378 AST_EXT_LIB_SETUP([X11], [X11 support], [x11])
379 AST_EXT_LIB_SETUP([ZLIB], [zlib], [z])
380 AST_EXT_LIB_SETUP([TIMERFD], [timerfd], [timerfd])
381
382 # check for basic system features and functionality before
383 # checking for package libraries
384
385 AC_FUNC_ALLOCA
386 AC_HEADER_DIRENT
387 AC_HEADER_STDC
388 AC_HEADER_SYS_WAIT
389 AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h arpa/nameser.h sys/io.h])
390
391 AC_CHECK_HEADERS([winsock.h winsock2.h])
392
393 AC_CHECK_HEADER([sys/poll.h],
394          [],
395      AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be used.]))
396
397 AC_SYS_LARGEFILE
398
399 # Checks for typedefs, structures, and compiler characteristics.
400 AC_HEADER_STDBOOL
401 AC_C_CONST
402 AC_TYPE_UID_T
403 AC_C_INLINE
404 AC_TYPE_LONG_DOUBLE_WIDER
405 AC_TYPE_MODE_T
406 AC_TYPE_OFF_T
407 AC_TYPE_PID_T
408 AC_TYPE_SIZE_T
409 AC_CHECK_MEMBERS([struct stat.st_blksize])
410 AC_HEADER_TIME
411 AC_STRUCT_TM
412 AC_C_VOLATILE
413 AC_CHECK_TYPES([ptrdiff_t])
414
415 # Checks for library functions.
416 AC_FUNC_CHOWN
417 AC_FUNC_CLOSEDIR_VOID
418 AC_FUNC_ERROR_AT_LINE
419 AST_FUNC_FORK
420 AC_FUNC_FSEEKO
421 AC_PROG_GCC_TRADITIONAL
422 # XXX: these are commented out until we determine whether it matters if our malloc()
423 # acts exactly like glibc's or not
424 # AC_FUNC_MALLOC
425 # AC_FUNC_REALLOC
426 AC_FUNC_MEMCMP
427 AC_FUNC_MMAP
428 AC_FUNC_SELECT_ARGTYPES
429 AC_FUNC_SETVBUF_REVERSED
430 AC_TYPE_SIGNAL
431 AC_FUNC_STAT
432 AC_FUNC_STRCOLL
433 AC_FUNC_STRFTIME
434 AC_FUNC_STRNLEN
435 AC_FUNC_STRTOD
436 AC_FUNC_UTIME_NULL
437 AC_FUNC_VPRINTF
438 AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob htonll ioperm inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap ntohll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv utime vasprintf getpeereid sysctl swapctl])
439
440 # NOTE: we use AC_CHECK_LIB to get -lm into the arguments for later checks,
441 # so that AC_CHECK_FUNCS can detect functions in that library.
442 AC_CHECK_LIB([m], [sqrt])
443 # BSD might not have exp2, and/or log2
444 AC_CHECK_FUNCS([exp2 log2 exp10 log10 sin cos tan asin acos atan atan2 pow rint exp log remainder fmod round trunc floor ceil])
445
446 # Certain architectures don't really have long double, even though
447 # AC_CHECK_FUNCS would otherwise find the following functions.
448 if test "x${ac_cv_type_long_double_wider}" = "xyes" ; then
449         AC_CHECK_FUNCS([exp2l log2l exp10l log10l sinl cosl tanl asinl acosl atanl atan2l powl sqrtl rintl expl logl remainderl fmodl roundl truncl floorl ceill])
450 fi
451
452 AC_MSG_CHECKING(for timersub in time.h)
453 AC_LINK_IFELSE(
454         AC_LANG_PROGRAM([#include <sys/time.h>],
455                 [struct timeval *a; timersub(a, a, a);]),
456         AC_MSG_RESULT(yes)
457                 AC_DEFINE([HAVE_TIMERSUB], 1, [Define to 1 if your system defines timersub.]),
458         AC_MSG_RESULT(no)
459 )
460
461 AC_CHECK_HEADER([sys/poll.h], 
462    [HAS_POLL=1]
463    AC_DEFINE([HAVE_SYS_POLL_H], 1, [Define to 1 if your system has working sys/poll.h]),
464    )
465
466 AC_ARG_ENABLE([internal-poll],
467         [AS_HELP_STRING([--enable-internal-poll],
468                 [Use Asterisk's poll implementation])],
469         [case "${enableval}" in
470                 y|ye|yes) HAS_POLL="";;
471                 n|no) HAS_POLL="${HAS_POLL}" ;;
472                 *) AC_MSG_ERROR(bad value ${enableval} for --enable-internal-poll) ;;
473         esac])
474 AC_SUBST(HAS_POLL)
475
476
477
478 # https support (in main/http.c) uses funopen on BSD systems,
479 # fopencookie on linux
480 AC_CHECK_FUNCS([funopen fopencookie])
481
482 AC_CHECK_FUNCS([inet_aton])
483
484 # check if we have IP_PKTINFO constant defined
485 AC_MSG_CHECKING(for IP_PKTINFO)
486 AC_LINK_IFELSE(
487                 AC_LANG_PROGRAM([#include <netinet/in.h>],
488                                                 [int pi = IP_PKTINFO;]),
489                 AC_MSG_RESULT(yes)
490                 AC_DEFINE([HAVE_PKTINFO], 1, [Define to 1 if your system defines IP_PKTINFO.]),
491                 AC_MSG_RESULT(no)
492 )
493
494 # some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
495 AC_SEARCH_LIBS(gethostbyname_r, [socket nsl])
496
497 AC_MSG_CHECKING(for gethostbyname_r with 6 arguments)
498 AC_LINK_IFELSE(
499         AC_LANG_PROGRAM([#include <stdlib.h>
500                          #include <netdb.h>],
501                         [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);]),
502         AC_MSG_RESULT(yes)
503         AC_DEFINE([HAVE_GETHOSTBYNAME_R_6], 1, [Define to 1 if your system has gethostbyname_r with 6 arguments.]),
504         AC_MSG_RESULT(no)
505 )
506
507 AC_MSG_CHECKING(for gethostbyname_r with 5 arguments)
508 AC_LINK_IFELSE(
509         AC_LANG_PROGRAM([#include <stdlib.h>
510                          #include <netdb.h>],
511                         [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);]),
512         AC_MSG_RESULT(yes)
513         AC_DEFINE([HAVE_GETHOSTBYNAME_R_5], 1, [Define to 1 if your system has gethostbyname_r with 5 arguments.]),
514         AC_MSG_RESULT(no)
515 )
516
517 AC_CHECK_HEADER([byteswap.h], [AC_DEFINE_UNQUOTED([HAVE_BYTESWAP_H], 1, [Define to 1 if byteswap.h macros are available.])])
518
519 AC_MSG_CHECKING(for __swap16 variant of <sys/endian.h> byteswapping macros)
520 AC_LINK_IFELSE(
521 AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = __swap16(a);]),
522 AC_MSG_RESULT(yes)
523 AC_DEFINE([HAVE_SYS_ENDIAN_SWAP16], 1, [Define to 1 if your sys/endian.h header file provides the __swap16 macro.]),
524 AC_MSG_RESULT(no)
525 )
526
527 AC_MSG_CHECKING(for bswap16 variant of <sys/endian.h> byteswapping macros)
528 AC_LINK_IFELSE(
529 AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = bswap16(a);]),
530 AC_MSG_RESULT(yes)
531 AC_DEFINE([HAVE_SYS_ENDIAN_BSWAP16], 1, [Define to 1 if your sys/endian.h header file provides the bswap16 macro.]),
532 AC_MSG_RESULT(no)
533 )
534
535 if test "${cross_compiling}" = "no";
536 then
537   AC_CHECK_FILE(/dev/urandom, AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define to 1 if your system has /dev/urandom.]))
538 fi
539
540 AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [pthread.h])
541
542 AC_MSG_CHECKING(for PTHREAD_RWLOCK_PREFER_WRITER_NP in pthread.h)
543 AC_LINK_IFELSE(
544 AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_RWLOCK_PREFER_WRITER_NP;]),
545 AC_MSG_RESULT(yes)
546 AC_DEFINE([HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP], 1, [Define to 1 if your system defines PTHREAD_RWLOCK_PREFER_WRITER_NP in pthread.h]),
547 AC_MSG_RESULT(no)
548 )
549
550 AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE_NP in pthread.h)
551 AC_LINK_IFELSE(
552 AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_MUTEX_RECURSIVE_NP;]),
553 AC_MSG_RESULT(yes)
554 AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1, [Define to 1 if your system defines PTHREAD_MUTEX_RECURSIVE_NP in pthread.h]),
555 AC_MSG_RESULT(no)
556 )
557
558 AC_MSG_CHECKING(for pthread_rwlock_timedwrlock() in pthread.h)
559 AC_LINK_IFELSE(
560   [AC_LANG_PROGRAM(
561     [#include <pthread.h>
562      #include <time.h>],
563     [pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar)])
564   ],[
565     AC_MSG_RESULT(yes)
566     ac_cv_pthread_rwlock_timedwrlock="yes"
567   ],[
568     AC_MSG_RESULT(no)
569     ac_cv_pthread_rwlock_timedwrlock="no"
570   ]
571 )
572 if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then
573   AC_DEFINE([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK], 1, [Define if your system has pthread_rwlock_timedwrlock()])
574 fi
575
576 AC_MSG_CHECKING(if PTHREAD_ONCE_INIT needs braces)
577 saved_CFLAGS="${CFLAGS}"
578 CFLAGS="${CFLAGS} -Werror -Wmissing-braces"
579 AC_COMPILE_IFELSE(
580   [AC_LANG_PROGRAM(
581     [#include <pthread.h>
582      void empty(){}],
583         [pthread_once_t once = PTHREAD_ONCE_INIT; pthread_once(&once, empty);])
584   ],[
585     AC_MSG_RESULT(no)
586     ac_cv_pthread_once_needsbraces="no"
587   ],[
588     AC_MSG_RESULT(yes)
589     ac_cv_pthread_once_needsbraces="yes"
590   ]
591 )
592 CFLAGS="${saved_CFLAGS}"
593 if test "${ac_cv_pthread_once_needsbraces}" = "yes"; then
594   AC_DEFINE([PTHREAD_ONCE_INIT_NEEDS_BRACES], 1, [Define if your system needs braces around PTHREAD_ONCE_INIT])
595 fi
596
597 AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [pthread.h])
598
599 #if test "${cross_compiling}" = "no";
600 #then
601 #AC_MSG_CHECKING(for working epoll support)
602 #AC_LINK_IFELSE(
603 #AC_LANG_PROGRAM([#include <sys/epoll.h>], [int res = epoll_create(10);
604 #                                         if (res < 0)
605 #                                            return 1;
606 #                                         close (res);
607 #                                         return 0;]),
608 #AC_MSG_RESULT(yes)
609 #AC_DEFINE([HAVE_EPOLL], 1, [Define to 1 if your system has working epoll support.]),
610 #AC_MSG_RESULT(no)
611 #)
612 #fi
613
614 AC_MSG_CHECKING(for compiler atomic operations)
615 AC_LINK_IFELSE(
616 AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);]),
617 AC_MSG_RESULT(yes)
618 AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
619 AC_MSG_RESULT(no)
620 )
621
622 # glibc, AFAIK, is the only C library that makes printing a NULL to a string safe.
623 AC_MSG_CHECKING([if your system printf is NULL-safe.])
624 AC_RUN_IFELSE(
625         AC_LANG_PROGRAM([#include <stdio.h>],
626                 [printf("%s", NULL)]),
627         AC_DEFINE([HAVE_NULLSAFE_PRINTF], 1, [Define to 1 if your C library can safely print NULL to string formats.])
628         AC_MSG_RESULT(yes),
629         AC_MSG_RESULT(no),
630         # It's unlikely an embedded system will have this.
631         AC_MSG_RESULT(unknown)
632 )
633
634 AST_GCC_ATTRIBUTE(pure)
635 AST_GCC_ATTRIBUTE(malloc)
636 AST_GCC_ATTRIBUTE(const)
637 AST_GCC_ATTRIBUTE(unused)
638 AST_GCC_ATTRIBUTE(always_inline)
639 AST_GCC_ATTRIBUTE(deprecated)
640 AST_GCC_ATTRIBUTE(sentinel)
641 AST_GCC_ATTRIBUTE(warn_unused_result)
642 AST_GCC_ATTRIBUTE(weakref, [weakref("foo")], static)
643 AST_GCC_ATTRIBUTE(weak_import)
644
645 AC_MSG_CHECKING(for -ffunction-sections support)
646 saved_CFLAGS="${CFLAGS}"
647 CFLAGS="${CFLAGS} -ffunction-sections"
648 AC_COMPILE_IFELSE(
649         AC_LANG_PROGRAM([], [int x = 1;]),
650         AC_MSG_RESULT(yes)
651         [saved_LDFLAGS="${LDFLAGS}"]
652         [LDFLAGS="${LDFLAGS} -Wl,--gc-sections"]
653         AC_MSG_CHECKING(for --gc-sections support)
654         AC_LINK_IFELSE(
655                 AC_LANG_PROGRAM([], [int x = 1;]),
656                 AC_MSG_RESULT(yes)
657                 [GC_CFLAGS="-ffunction-sections"]
658                 [[GC_LDFLAGS="-Wl,--gc-sections"]],
659                 AC_MSG_RESULT(no)
660         )
661         [LDFLAGS="${saved_LDFLAGS}"],
662         AC_MSG_RESULT(no)
663 )
664 CFLAGS="${saved_CFLAGS}"
665 AC_SUBST(GC_CFLAGS)
666 AC_SUBST(GC_LDFLAGS)
667
668 AC_MSG_CHECKING(for -Wdeclaration-after-statement support)
669 if $(${CC} -Wdeclaration-after-statement -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
670         AC_MSG_RESULT(yes)
671         AST_DECLARATION_AFTER_STATEMENT=-Wdeclaration-after-statement
672 else
673         AC_MSG_RESULT(no)
674         AST_DECLARATION_AFTER_STATEMENT=
675 fi
676 AC_SUBST(AST_DECLARATION_AFTER_STATEMENT)
677
678 AC_MSG_CHECKING(for _FORTIFY_SOURCE support)
679 if $(${CC} -D_FORTIFY_SOURCE=2 -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
680         AC_MSG_RESULT(yes)
681         AST_FORTIFY_SOURCE=-D_FORTIFY_SOURCE=2
682 else
683         AC_MSG_RESULT(no)
684         AST_FORTIFY_SOURCE=
685 fi
686 AC_SUBST(AST_FORTIFY_SOURCE)
687
688 AC_MSG_CHECKING(for -fno-strict-overflow)
689 if $(${CC} -O2 -fno-strict-overflow -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
690         AC_MSG_RESULT(yes)
691         AST_NO_STRICT_OVERFLOW=-fno-strict-overflow
692 else
693         AC_MSG_RESULT(no)
694         AST_NO_STRICT_OVERFLOW=
695 fi
696 AC_SUBST(AST_NO_STRICT_OVERFLOW)
697
698 AC_MSG_CHECKING(for -Wshadow)
699 if $(${CC} -Wshadow -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
700         AC_MSG_RESULT(yes)
701         AST_SHADOW_WARNINGS=-Wshadow
702 else
703         AC_MSG_RESULT(no)
704         AST_SHADOW_WARNINGS=
705 fi
706 AC_SUBST(AST_SHADOW_WARNINGS)
707
708 AC_MSG_CHECKING(for sysinfo)
709 AC_LINK_IFELSE(
710         AC_LANG_PROGRAM([#include <sys/sysinfo.h>],
711                         [struct sysinfo sys_info; int uptime = sys_info.uptime]),
712         AC_MSG_RESULT(yes)
713         AC_DEFINE([HAVE_SYSINFO], 1, [Define to 1 if your system has sysinfo support]),
714         AC_MSG_RESULT(no)
715 )
716
717 AC_SEARCH_LIBS(res_9_ninit, resolv)
718 AC_MSG_CHECKING(for res_ninit)
719 AC_LINK_IFELSE(
720         AC_LANG_PROGRAM([
721                         #ifdef HAVE_SYS_SOCKET_H
722                         #include <sys/socket.h>
723                         #endif
724                         #ifdef HAVE_NETINET_IN_H
725                         #include <netinet/in.h>
726                         #endif
727                         #ifdef HAVE_ARPA_NAMESER_H
728                         #include <arpa/nameser.h>
729                         #endif
730                         #include <resolv.h>],
731                         [int foo = res_ninit(NULL);]),
732         AC_MSG_RESULT(yes)
733         AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.])
734         AC_SEARCH_LIBS(res_9_ndestroy, resolv)
735         AC_MSG_CHECKING(for res_ndestroy)
736         AC_LINK_IFELSE(
737                 AC_LANG_PROGRAM([
738                                 #ifdef HAVE_SYS_SOCKET_H
739                                 #include <sys/socket.h>
740                                 #endif
741                                 #ifdef HAVE_NETINET_IN_H
742                                 #include <netinet/in.h>
743                                 #endif
744                                 #ifdef HAVE_ARPA_NAMESER_H
745                                 #include <arpa/nameser.h>
746                                 #endif
747                                 #include <resolv.h>],
748                                 [res_ndestroy(NULL);]),
749                 AC_MSG_RESULT(yes)
750                 AC_DEFINE([HAVE_RES_NDESTROY], 1, [Define to 1 if your system has the ndestroy resolver function.]),
751                 AC_MSG_RESULT(no)
752         )
753         AC_SEARCH_LIBS(res_9_close, resolv)
754         AC_MSG_CHECKING(for res_close)
755         AC_LINK_IFELSE(
756                 AC_LANG_PROGRAM([
757                                 #ifdef HAVE_SYS_SOCKET_H
758                                 #include <sys/socket.h>
759                                 #endif
760                                 #ifdef HAVE_NETINET_IN_H
761                                 #include <netinet/in.h>
762                                 #endif
763                                 #ifdef HAVE_ARPA_NAMESER_H
764                                 #include <arpa/nameser.h>
765                                 #endif
766                                 #include <resolv.h>],
767                                 [res_close();]),
768                 AC_MSG_RESULT(yes)
769                 AC_DEFINE([HAVE_RES_CLOSE], 1, [Define to 1 if your system has the close resolver function.]),
770                 AC_MSG_RESULT(no)
771         ),
772         AC_MSG_RESULT(no)
773 )
774
775 AST_C_DEFINE_CHECK([GLOB_NOMAGIC], [GLOB_NOMAGIC], [glob.h])
776
777 AST_C_DEFINE_CHECK([GLOB_BRACE], [GLOB_BRACE], [glob.h])
778
779 AST_C_DEFINE_CHECK([IP_MTU_DISCOVER], [IP_MTU_DISCOVER], [netinet/in.h])
780
781 AC_CHECK_HEADER([libkern/OSAtomic.h],
782                 [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])
783
784 AC_CHECK_SIZEOF(int)
785
786 # do the package library checks now
787
788 AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])
789
790 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
791
792 if test "x${OSARCH}" = "xlinux-gnu" ; then
793   AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
794 fi
795
796 AST_C_DEFINE_CHECK([DAHDI], [DAHDI_CODE], [dahdi/user.h])
797
798 AST_C_DEFINE_CHECK([DAHDI_HALF_FULL], [DAHDI_POLICY_HALF_FULL], [dahdi/user.h])
799
800 AST_C_COMPILE_CHECK([DAHDI_LINEREVERSE_VMWI], [struct dahdi_vmwi_info booger], [dahdi/user.h], , [enhanced dahdi vmwi support])
801
802 AST_C_COMPILE_CHECK([DAHDI_ECHOCANCEL_FAX_MODE], [int foo = DAHDI_ECHOCANCEL_FAX_MODE], [dahdi/user.h])
803
804 AST_C_COMPILE_CHECK([GETIFADDRS], [struct ifaddrs *p; getifaddrs(&p)], [ifaddrs.h], , [getifaddrs() support])
805 AST_C_COMPILE_CHECK([TIMERFD], [timerfd_create(0,0); timerfd_settime(0,0,NULL,NULL);], [sys/timerfd.h], , [timerfd support])
806
807 GSM_INTERNAL="yes"
808 AC_SUBST(GSM_INTERNAL)
809 GSM_SYSTEM="yes"
810 if test "${USE_GSM}" != "no"; then
811    if test "${GSM_DIR}" = "internal"; then
812       GSM_SYSTEM="no"
813    elif test "${GSM_DIR}" != ""; then
814       GSM_INTERNAL="no"
815    fi
816    if test "${GSM_SYSTEM}" = "yes"; then
817       gsmlibdir=""
818       if test "x${GSM_DIR}" != "x"; then
819          if test -d ${GSM_DIR}/lib; then
820             gsmlibdir="-L${GSM_DIR}/lib"
821          else
822             gsmlibdir="-L${GSM_DIR}"
823          fi
824       fi
825       AC_CHECK_LIB([gsm], [gsm_create], AC_DEFINE_UNQUOTED([HAVE_GSM], 1,
826       [Define to indicate the GSM library]), [], ${gsmlibdir})
827       if test "${ac_cv_lib_gsm_gsm_create}" = "yes"; then
828          if test "x${GSM_DIR}" != "x" ; then
829             AC_CHECK_HEADER([${GSM_DIR}/include/gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
830             AC_CHECK_HEADER([${GSM_DIR}/include/gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
831          else
832             AC_CHECK_HEADER([gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
833             AC_CHECK_HEADER([gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
834          fi
835          if test "${GSM_HEADER_FOUND}" = "0" ; then
836             if test "{GSM_GSM_HEADER_FOUND}" = "0" ; then
837                if test "x${GSM_MANDATORY}" = "xyes" ; then
838                   AC_MSG_NOTICE([***])
839                   AC_MSG_NOTICE([*** It appears that you do not have the gsm development package installed.])
840                   AC_MSG_NOTICE([*** Please install it to include ${GSM_DESCRIP} support, or re-run configure])
841                   AC_MSG_NOTICE([*** without explicitly specifying --with-${GSM_OPTION}])
842                   exit 1
843                fi
844             fi
845          fi
846          GSM_OK=0
847          if test "${GSM_HEADER_FOUND}" = "1" ; then
848             AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
849             GSM_OK=1
850          else
851             if test "${GSM_GSM_HEADER_FOUND}" = "1" ; then
852                AC_DEFINE_UNQUOTED([HAVE_GSM_GSM_HEADER], 1, [Define to indicate that gsm.h is in gsm/gsm.h])
853                GSM_OK=1
854             fi
855          fi
856          if test "${GSM_OK}" = "1" ; then
857             GSM_LIB="-lgsm"
858             if test "x${GSM_DIR}" != "x"; then
859                GSM_LIB="${gsmlibdir} ${GSM_LIB}"
860                GSM_INCLUDE="-I${GSM_DIR}/include"
861             fi
862             PBX_GSM=1
863             GSM_INTERNAL="no"
864          fi
865       fi
866    fi
867    if test "${GSM_INTERNAL}" = "yes"; then
868       PBX_GSM=1
869       AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
870    fi
871 fi
872
873 AST_EXT_LIB_CHECK([ICONV], [iconv], [iconv_open], [iconv.h])
874 # Some versions of Linux package iconv in glibc
875 AST_EXT_LIB_CHECK([ICONV], [c], [iconv_close], [iconv.h])
876
877 AST_EXT_LIB_CHECK([ICAL], [ical], [icaltimezone_new], [libical/ical.h], [-lpthread])
878
879 AST_EXT_LIB_CHECK([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])
880
881 if test "${USE_IMAP_TK}" != "no"; then
882         saved_cppflags="${CPPFLAGS}"
883         saved_libs="${LIBS}"
884         switch_to_system_on_failure="no"
885         if test "${IMAP_TK_DIR}" = ""; then
886                 IMAP_TK_DIR=`pwd`"/../imap-2004g"
887                 switch_to_system_on_failure="yes"
888         fi
889         if test "${IMAP_TK_DIR}" != "system"; then
890                 AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
891                 if test -f "${IMAP_TK_DIR}/c-client/LDFLAGS"; then
892                 imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
893                 fi
894                 imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
895                 imap_include="-I${IMAP_TK_DIR}/c-client"
896         CPPFLAGS="${CPPFLAGS} ${imap_include}"
897                 LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
898                 AC_LINK_IFELSE(
899                 AC_LANG_PROGRAM(
900                                 [#include "c-client.h"
901                                 void mm_searched (MAILSTREAM *stream,unsigned long number)
902                                 {
903                                 }
904                                 void mm_exists (MAILSTREAM *stream,unsigned long number)
905                                 {
906                                 }
907                                 void mm_expunged (MAILSTREAM *stream,unsigned long number)
908                                 {
909                                 }
910                                 void mm_flags (MAILSTREAM *stream,unsigned long number)
911                                 {
912                                 }
913                                 void mm_notify (MAILSTREAM *stream,char *string,long errflg)
914                                 {
915                                 }
916                                 void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
917                                 {
918                                 }
919                                 void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
920                                 {
921                                 }
922                                 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
923                                 {
924                                 }
925                                 void mm_log (char *string,long errflg)
926                                 {
927                                 }
928                                 void mm_dlog (char *string)
929                                 {
930                                 }
931                                 void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
932                                 {
933                                 }
934                                 void mm_critical (MAILSTREAM *stream)
935                                 {
936                                 }
937                                 void mm_nocritical (MAILSTREAM *stream)
938                                 {
939                                 }
940                                 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
941                                 {
942                                 }
943                                 void mm_fatal (char *string)
944                                 {
945                                 }],
946                                 [
947                                 MAILSTREAM *foo = mail_open(NULL, "", 0);
948                                 ]
949                         ),
950                         [ac_cv_imap_tk="yes"],
951                         [ac_cv_imap_tk="no"]
952                 )
953                 if test "${ac_cv_imap_tk}" = "yes"; then
954                         AC_LINK_IFELSE(
955                                 AC_LANG_PROGRAM(
956                                         [#include "c-client.h"
957                                         void mm_searched (MAILSTREAM *stream,unsigned long number)
958                                         {
959                                         }
960                                         void mm_exists (MAILSTREAM *stream,unsigned long number)
961                                         {
962                                         }
963                                         void mm_expunged (MAILSTREAM *stream,unsigned long number)
964                                         {
965                                         }
966                                         void mm_flags (MAILSTREAM *stream,unsigned long number)
967                                         {
968                                         }
969                                         void mm_notify (MAILSTREAM *stream,char *string,long errflg)
970                                         {
971                                         }
972                                         void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
973                                         {
974                                         }
975                                         void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
976                                         {
977                                         }
978                                         void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
979                                         {
980                                         }
981                                         void mm_log (char *string,long errflg)
982                                         {
983                                         }
984                                         void mm_dlog (char *string)
985                                         {
986                                         }
987                                         void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
988                                         {
989                                         }
990                                         void mm_critical (MAILSTREAM *stream)
991                                         {
992                                         }
993                                         void mm_nocritical (MAILSTREAM *stream)
994                                         {
995                                         }
996                                         long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
997                                         {
998                                         }
999                                         void mm_fatal (char *string)
1000                                         {
1001                                         }],
1002                                         [
1003                                         long check = mail_expunge_full(NULL, "", 0);
1004                                         ]
1005                                 ),
1006                                 [ac_cv_imap_tk2006="yes"],
1007                                 [ac_cv_imap_tk2006="no"]
1008                         )
1009                 fi
1010                 CPPFLAGS="${saved_cppflags}"
1011                 LIBS="${saved_libs}"
1012                 if test "${ac_cv_imap_tk}" = "no"; then
1013                         AC_MSG_RESULT(no)
1014                         if test "${switch_to_system_on_failure}" = "yes"; then
1015                                 IMAP_TK_DIR="system"
1016                         else #This means they specified a directory. Search for a package installation there too
1017                                 AC_MSG_CHECKING([for system c-client library...])
1018                                 CPPFLAGS="${saved_cppflags}"
1019                                 LIBS="${saved_libs}"
1020                                 imap_include="-I${IMAP_TK_DIR}/include"
1021                                 imap_ldflags="-L${IMAP_TK_DIR}/lib"
1022                                 imap_libs="-lc-client"
1023                                 CPPFLAGS="${CPPFLAGS} ${imap_include}"
1024                                 LIBS="${LIBS} ${imap_libs} ${imap_ldflags}"
1025                                 AC_LINK_IFELSE(
1026                                 AC_LANG_PROGRAM(
1027                                                 [#include "c-client.h"
1028                                                 void mm_searched (MAILSTREAM *stream,unsigned long number)
1029                                                 {
1030                                                 }
1031                                                 void mm_exists (MAILSTREAM *stream,unsigned long number)
1032                                                 {
1033                                                 }
1034                                                 void mm_expunged (MAILSTREAM *stream,unsigned long number)
1035                                                 {
1036                                                 }
1037                                                 void mm_flags (MAILSTREAM *stream,unsigned long number)
1038                                                 {
1039                                                 }
1040                                                 void mm_notify (MAILSTREAM *stream,char *string,long errflg)
1041                                                 {
1042                                                 }
1043                                                 void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1044                                                 {
1045                                                 }
1046                                                 void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1047                                                 {
1048                                                 }
1049                                                 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
1050                                                 {
1051                                                 }
1052                                                 void mm_log (char *string,long errflg)
1053                                                 {
1054                                                 }
1055                                                 void mm_dlog (char *string)
1056                                                 {
1057                                                 }
1058                                                 void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
1059                                                 {
1060                                                 }
1061                                                 void mm_critical (MAILSTREAM *stream)
1062                                                 {
1063                                                 }
1064                                                 void mm_nocritical (MAILSTREAM *stream)
1065                                                 {
1066                                                 }
1067                                                 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
1068                                                 {
1069                                                 }
1070                                                 void mm_fatal (char *string)
1071                                                 {
1072                                                 }],
1073                                                 [
1074                                                 MAILSTREAM *foo = mail_open(NULL, "", 0);
1075                                                 ]
1076                                         ),
1077                                         [ac_cv_imap_tk="yes"],
1078                                         [ac_cv_imap_tk="no"]
1079                                 )
1080                                 if test "${ac_cv_imap_tk}" = "yes"; then
1081                                         AC_LINK_IFELSE(
1082                                                 AC_LANG_PROGRAM(
1083                                                         [#include "c-client.h"
1084                                                         void mm_searched (MAILSTREAM *stream,unsigned long number)
1085                                                         {
1086                                                         }
1087                                                         void mm_exists (MAILSTREAM *stream,unsigned long number)
1088                                                         {
1089                                                         }
1090                                                         void mm_expunged (MAILSTREAM *stream,unsigned long number)
1091                                                         {
1092                                                         }
1093                                                         void mm_flags (MAILSTREAM *stream,unsigned long number)
1094                                                         {
1095                                                         }
1096                                                         void mm_notify (MAILSTREAM *stream,char *string,long errflg)
1097                                                         {
1098                                                         }
1099                                                         void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1100                                                         {
1101                                                         }
1102                                                         void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1103                                                         {
1104                                                         }
1105                                                         void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
1106                                                         {
1107                                                         }
1108                                                         void mm_log (char *string,long errflg)
1109                                                         {
1110                                                         }
1111                                                         void mm_dlog (char *string)
1112                                                         {
1113                                                         }
1114                                                         void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
1115                                                         {
1116                                                         }
1117                                                         void mm_critical (MAILSTREAM *stream)
1118                                                         {
1119                                                         }
1120                                                         void mm_nocritical (MAILSTREAM *stream)
1121                                                         {
1122                                                         }
1123                                                         long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
1124                                                         {
1125                                                         }
1126                                                         void mm_fatal (char *string)
1127                                                         {
1128                                                         }],
1129                                                         [
1130                                                         long check = mail_expunge_full(NULL, "", 0);
1131                                                         ]
1132                                                 ),
1133                                                 [ac_cv_imap_tk2006="yes"],
1134                                                 [ac_cv_imap_tk2006="no"]
1135                                         )
1136                                 fi
1137                         fi
1138                 fi
1139         fi 
1140         if test "${IMAP_TK_DIR}" = "system"; then
1141                 #We will enter here if user specified "system" or if any of above checks failed
1142                 AC_MSG_CHECKING([for system c-client library...])
1143                 CPPFLAGS="${saved_cppflags}"
1144                 LIBS="${saved_libs}"
1145                 imap_ldflags=""
1146                 imap_libs="-lc-client"
1147                 imap_include="-DUSE_SYSTEM_IMAP" #Try the imap directory first
1148                 CPPFLAGS="${CPPFLAGS} ${imap_include}"
1149                 LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
1150                 AC_LINK_IFELSE(
1151                 AC_LANG_PROGRAM(
1152                                 [#include <stdio.h>
1153                                 #include <imap/c-client.h>
1154                                 void mm_searched (MAILSTREAM *stream,unsigned long number)
1155                                 {
1156                                 }
1157                                 void mm_exists (MAILSTREAM *stream,unsigned long number)
1158                                 {
1159                                 }
1160                                 void mm_expunged (MAILSTREAM *stream,unsigned long number)
1161                                 {
1162                                 }
1163                                 void mm_flags (MAILSTREAM *stream,unsigned long number)
1164                                 {
1165                                 }
1166                                 void mm_notify (MAILSTREAM *stream,char *string,long errflg)
1167                                 {
1168                                 }
1169                                 void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1170                                 {
1171                                 }
1172                                 void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1173                                 {
1174                                 }
1175                                 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
1176                                 {
1177                                 }
1178                                 void mm_log (char *string,long errflg)
1179                                 {
1180                                 }
1181                                 void mm_dlog (char *string)
1182                                 {
1183                                 }
1184                                 void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
1185                                 {
1186                                 }
1187                                 void mm_critical (MAILSTREAM *stream)
1188                                 {
1189                                 }
1190                                 void mm_nocritical (MAILSTREAM *stream)
1191                                 {
1192                                 }
1193                                 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
1194                                 {
1195                                 }
1196                                 void mm_fatal (char *string)
1197                                 {
1198                                 }],
1199                                 [
1200                                 MAILSTREAM *foo = mail_open(NULL, "", 0);
1201                                 ]
1202                         ),
1203                         [ac_cv_imap_tk="yes"],
1204                         [ac_cv_imap_tk="no"]
1205                 )
1206                 if test "${ac_cv_imap_tk}" = "yes"; then
1207                         AC_LINK_IFELSE(
1208                                 AC_LANG_PROGRAM(
1209                                         [#include <stdio.h>
1210                                         #include <imap/c-client.h>
1211                                         void mm_searched (MAILSTREAM *stream,unsigned long number)
1212                                         {
1213                                         }
1214                                         void mm_exists (MAILSTREAM *stream,unsigned long number)
1215                                         {
1216                                         }
1217                                         void mm_expunged (MAILSTREAM *stream,unsigned long number)
1218                                         {
1219                                         }
1220                                         void mm_flags (MAILSTREAM *stream,unsigned long number)
1221                                         {
1222                                         }
1223                                         void mm_notify (MAILSTREAM *stream,char *string,long errflg)
1224                                         {
1225                                         }
1226                                         void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1227                                         {
1228                                         }
1229                                         void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1230                                         {
1231                                         }
1232                                         void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
1233                                         {
1234                                         }
1235                                         void mm_log (char *string,long errflg)
1236                                         {
1237                                         }
1238                                         void mm_dlog (char *string)
1239                                         {
1240                                         }
1241                                         void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
1242                                         {
1243                                         }
1244                                         void mm_critical (MAILSTREAM *stream)
1245                                         {
1246                                         }
1247                                         void mm_nocritical (MAILSTREAM *stream)
1248                                         {
1249                                         }
1250                                         long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
1251                                         {
1252                                         }
1253                                         void mm_fatal (char *string)
1254                                         {
1255                                         }],
1256                                         [
1257                                         long check = mail_expunge_full(NULL, "", 0);
1258                                         ]
1259                                 ),
1260                                 [ac_cv_imap_tk2006="yes"],
1261                                 [ac_cv_imap_tk2006="no"]
1262                         )
1263                 else #looking in imap directory didn't work, try c-client
1264                         imap_ldflags=""
1265                         imap_libs="-lc-client"
1266                         imap_include="-DUSE_SYSTEM_CCLIENT"
1267                         CPPFLAGS="${saved_cppflags}"
1268                         LIBS="${saved_libs}"
1269                         CPPFLAGS="${CPPFLAGS} ${imap_include}"
1270                         LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
1271                         AC_LINK_IFELSE(
1272                         AC_LANG_PROGRAM(
1273                                         [#include <stdio.h>
1274                                         #include <c-client/c-client.h>
1275                                         void mm_searched (MAILSTREAM *stream,unsigned long number)
1276                                         {
1277                                         }
1278                                         void mm_exists (MAILSTREAM *stream,unsigned long number)
1279                                         {
1280                                         }
1281                                         void mm_expunged (MAILSTREAM *stream,unsigned long number)
1282                                         {
1283                                         }
1284                                         void mm_flags (MAILSTREAM *stream,unsigned long number)
1285                                         {
1286                                         }
1287                                         void mm_notify (MAILSTREAM *stream,char *string,long errflg)
1288                                         {
1289                                         }
1290                                         void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1291                                         {
1292                                         }
1293                                         void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1294                                         {
1295                                         }
1296                                         void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
1297                                         {
1298                                         }
1299                                         void mm_log (char *string,long errflg)
1300                                         {
1301                                         }
1302                                         void mm_dlog (char *string)
1303                                         {
1304                                         }
1305                                         void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
1306                                         {
1307                                         }
1308                                         void mm_critical (MAILSTREAM *stream)
1309                                         {
1310                                         }
1311                                         void mm_nocritical (MAILSTREAM *stream)
1312                                         {
1313                                         }
1314                                         long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
1315                                         {
1316                                         }
1317                                         void mm_fatal (char *string)
1318                                         {
1319                                         }],
1320                                         [
1321                                         MAILSTREAM *foo = mail_open(NULL, "", 0);
1322                                         ]
1323                                 ),
1324                                 [ac_cv_imap_tk="yes"],
1325                                 [ac_cv_imap_tk="no"]
1326                         )
1327                         if test "${ac_cv_imap_tk}" = "yes"; then
1328                                 AC_LINK_IFELSE(
1329                                         AC_LANG_PROGRAM(
1330                                                 [#include <stdio.h>
1331                                                 #include <c-client/c-client.h>
1332                                                 void mm_searched (MAILSTREAM *stream,unsigned long number)
1333                                                 {
1334                                                 }
1335                                                 void mm_exists (MAILSTREAM *stream,unsigned long number)
1336                                                 {
1337                                                 }
1338                                                 void mm_expunged (MAILSTREAM *stream,unsigned long number)
1339                                                 {
1340                                                 }
1341                                                 void mm_flags (MAILSTREAM *stream,unsigned long number)
1342                                                 {
1343                                                 }
1344                                                 void mm_notify (MAILSTREAM *stream,char *string,long errflg)
1345                                                 {
1346                                                 }
1347                                                 void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1348                                                 {
1349                                                 }
1350                                                 void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
1351                                                 {
1352                                                 }
1353                                                 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
1354                                                 {
1355                                                 }
1356                                                 void mm_log (char *string,long errflg)
1357                                                 {
1358                                                 }
1359                                                 void mm_dlog (char *string)
1360                                                 {
1361                                                 }
1362                                                 void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
1363                                                 {
1364                                                 }
1365                                                 void mm_critical (MAILSTREAM *stream)
1366                                                 {
1367                                                 }
1368                                                 void mm_nocritical (MAILSTREAM *stream)
1369                                                 {
1370                                                 }
1371                                                 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
1372                                                 {
1373                                                 }
1374                                                 void mm_fatal (char *string)
1375                                                 {
1376                                                 }],
1377                                                 [
1378                                                 long check = mail_expunge_full(NULL, "", 0);
1379                                                 ]
1380                                         ),
1381                                         [ac_cv_imap_tk2006="yes"],
1382                                         [ac_cv_imap_tk2006="no"]
1383                                 )
1384                         fi
1385                 fi
1386         fi
1387         if test "${ac_cv_imap_tk}" = "yes"; then
1388                 AC_MSG_RESULT(yes)
1389                 IMAP_TK_LIB="${imap_libs} "`echo ${imap_ldflags}`
1390                 IMAP_TK_INCLUDE="${imap_include}"
1391                 PBX_IMAP_TK=1
1392                 AC_DEFINE([HAVE_IMAP_TK], 1, [Define if your system has the UW IMAP Toolkit c-client library.])
1393                 if test "${ac_cv_imap_tk2006}" = "yes"; then
1394                         AC_DEFINE([HAVE_IMAP_TK2006], 1, [Define if your system has the UW IMAP Toolkit c-client library version 2006 or greater.])
1395                 fi
1396         else
1397                 AC_MSG_RESULT(no) 
1398         fi
1399         CPPFLAGS="${saved_cppflags}"
1400         LIBS="${saved_libs}"
1401 fi
1402
1403 AST_EXT_LIB_CHECK([IODBC], [iodbc], [SQLConnect], [sql.h], [-lpthread])
1404
1405 AST_EXT_LIB_CHECK([INOTIFY], [c], [inotify_init], [sys/inotify.h])
1406
1407 AST_EXT_LIB_CHECK([JACK], [jack], [jack_activate], [jack/jack.h])
1408
1409 # Needed by unixodbc
1410 AST_EXT_LIB_CHECK([LTDL], [ltdl], [lt_dlinit], [ltdl.h], [])
1411
1412 AST_EXT_LIB_CHECK([LDAP], [ldap], [ldap_initialize], [ldap.h])
1413
1414 AC_ARG_ENABLE([xmldoc],
1415         [AS_HELP_STRING([--disable-xmldoc],
1416                 [Explicity disable XML documentation])],
1417         [case "${enableval}" in
1418                 y|ye|yes) disable_xmldoc=no ;;
1419                 n|no)  disable_xmldoc=yes ;;
1420                 *) AC_MSG_ERROR(bad value ${enableval} for --disable-xmldoc)  ;;
1421         esac], [disable_xmldoc=no])
1422
1423 if test "${disable_xmldoc}" != "yes"; then
1424         AST_EXT_TOOL_CHECK([LIBXML2], [xml2-config], , ,
1425         [#include <libxml/tree.h>
1426         #include <libxml/parser.h>],
1427         [LIBXML_TEST_VERSION])
1428         if test "${PBX_LIBXML2}" != 1; then
1429                 AC_MSG_NOTICE(*** XML documentation will not be available because the 'libxml2' development package is missing.)
1430                 AC_MSG_NOTICE(*** Please run the 'configure' script with the '--disable-xmldoc' parameter option)
1431                 AC_MSG_NOTICE(*** or install the 'libxml2' development package.)
1432                 exit 1
1433         fi
1434 fi
1435
1436 AST_EXT_LIB_CHECK([MISDN], [mISDN], [mISDN_open], [mISDNuser/mISDNlib.h])
1437
1438 if test "${PBX_MISDN}" = 1; then
1439    AST_EXT_LIB_CHECK([ISDNNET], [isdnnet], [init_manager], [mISDNuser/isdn_net.h], [-lmISDN -lpthread])
1440    AST_EXT_LIB_CHECK([SUPPSERV], [suppserv], [encodeFac], [mISDNuser/suppserv.h])
1441    AST_C_DEFINE_CHECK([MISDN_FAC_RESULT], [Fac_RESULT], [mISDNuser/suppserv.h])
1442    AST_C_DEFINE_CHECK([MISDN_FAC_ERROR], [Fac_ERROR], [mISDNuser/suppserv.h])
1443    AC_CHECK_HEADER([linux/mISDNdsp.h], [AC_DEFINE_UNQUOTED([MISDN_1_2], 1, [Build chan_misdn for mISDN 1.2 or later.])])
1444    AC_CHECK_MEMBER([Q931_info_t.redirect_dn], [], [PBX_MISDN=0], [#include <mISDNuser/mISDNlib.h>])
1445 fi
1446
1447 AST_EXT_TOOL_CHECK([MYSQLCLIENT], [mysql_config])
1448
1449 AST_EXT_LIB_CHECK([NBS], [nbs], [nbs_connect], [nbs.h])
1450
1451 AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
1452
1453 AST_EXT_TOOL_CHECK([NEON], [neon-config])
1454
1455 AST_EXT_TOOL_CHECK([NETSNMP], [net-snmp-config], , [--agent-libs],
1456 [#include <net-snmp/net-snmp-config.h>
1457 #include <net-snmp/net-snmp-includes.h>
1458 #include <net-snmp/agent/net-snmp-agent-includes.h>],
1459 [int callback = snmp_register_callback(0, 0, NULL, NULL)])
1460
1461 AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])
1462
1463 AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [])
1464
1465 AST_EXT_LIB_CHECK([OGG], [ogg], [ogg_sync_init], [])
1466
1467 # Non-glibc platforms require libexecinfo for backtrace support
1468 AST_EXT_LIB_CHECK([BKTR], [execinfo], [backtrace], [execinfo.h])
1469 # Linux, however, has backtrace directly in glibc
1470 AST_EXT_LIB_CHECK([BKTR], [c], [backtrace], [execinfo.h])
1471
1472 AST_EXT_LIB_CHECK([BLUETOOTH], [bluetooth], [ba2str], [bluetooth/bluetooth.h])
1473
1474 # possible places for oss definitions
1475 AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [linux/soundcard.h])
1476 AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [sys/soundcard.h])
1477 AST_EXT_LIB_CHECK([OSS], [ossaudio], [oss_ioctl_mixer], [soundcard.h])
1478
1479 PG_CONFIG=No
1480 if test "${USE_PGSQL}" != "no"; then    
1481    if test "x${PGSQL_DIR}" != "x"; then
1482       AC_PATH_TOOL([PG_CONFIG], [pg_config], No, [${PGSQL_DIR}/bin])
1483       if test x"${PG_CONFIG}" = xNo; then
1484          AC_MSG_NOTICE([***])
1485          AC_MSG_NOTICE([*** pg_config was not found in the path you specified:])
1486          AC_MSG_NOTICE([*** ${PGSQL_DIR}/bin])
1487          AC_MSG_NOTICE([*** Either correct the installation, or run configure])
1488          AC_MSG_NOTICE([*** including --without-postgres])
1489          exit 1
1490       fi
1491    else
1492       AC_PATH_TOOL([PG_CONFIG], [pg_config], No)
1493    fi
1494 fi
1495 if test "${PG_CONFIG}" != No; then
1496    PGSQL_libdir=`${PG_CONFIG} --libdir`
1497    PGSQL_includedir=`${PG_CONFIG} --includedir`
1498    if test "x$?" != "x0" ; then
1499       if test -n "${PGSQL_MANDATORY}" ; then
1500          AC_MSG_NOTICE([***])
1501          AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
1502          AC_MSG_NOTICE([*** Either correct the installation, or run configure])
1503          AC_MSG_NOTICE([*** including --without-postgres])
1504          exit 1
1505           fi
1506    else 
1507       AC_CHECK_LIB([pq], [PQescapeStringConn], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
1508       [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)
1509
1510       if test "${ac_cv_lib_pq_PQescapeStringConn}" = "yes"; then
1511          PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz"
1512          PGSQL_INCLUDE="-I${PGSQL_includedir}"
1513          PBX_PGSQL=1
1514       elif test -n "${PGSQL_MANDATORY}";
1515       then
1516          AC_MSG_NOTICE([***])
1517          AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
1518          AC_MSG_NOTICE([*** Either correct the installation, or run configure])
1519          AC_MSG_NOTICE([*** including --without-postgres])
1520          exit 1
1521       fi
1522    fi
1523 fi
1524
1525 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
1526
1527 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
1528
1529 AST_EXT_LIB_CHECK([PRI], [pri], [pri_connected_line_update], [libpri.h])
1530 AST_EXT_LIB_CHECK([PRI_SUBADDR], [pri], [pri_sr_set_called_subaddress], [libpri.h])
1531 AST_EXT_LIB_CHECK([PRI_CALL_HOLD], [pri], [pri_hold_enable], [libpri.h])
1532 AST_EXT_LIB_CHECK([PRI_CALL_REROUTING], [pri], [pri_reroute_enable], [libpri.h])
1533 AST_EXT_LIB_CHECK([PRI_SETUP_KEYPAD], [pri], [pri_sr_set_keypad_digits], [libpri.h])
1534
1535 # ------------------------------------v
1536 # TODO: The code can be changed to always include these features now.
1537 # These features will always be present if pri_connected_line_update is available.
1538 AST_EXT_LIB_CHECK([PRI_PROG_W_CAUSE], [pri], [pri_progress_with_cause], [libpri.h])
1539 AST_EXT_LIB_CHECK([PRI_INBANDDISCONNECT], [pri], [pri_set_inbanddisconnect], [libpri.h])
1540 AST_EXT_LIB_CHECK([PRI_SERVICE_MESSAGES], [pri], [pri_maintenance_service], [libpri.h])
1541 AST_EXT_LIB_CHECK([PRI_REVERSE_CHARGE], [pri], [pri_sr_set_reversecharge], [libpri.h])
1542 # ------------------------------------^
1543
1544 AST_EXT_LIB_CHECK([RESAMPLE], [resample], [resample_open], [libresample.h], [-lm])
1545
1546 AST_C_COMPILE_CHECK([SPANDSP], [
1547                 #if SPANDSP_RELEASE_DATE < 20080516
1548                 #error "spandsp 0.0.5 or greater is required"
1549                 #endif
1550         ], [spandsp/version.h], , [minimum version of SpanDSP])
1551
1552 if test "x${PBX_SPANDSP}" = "x1" ; then
1553         # We found the correct version in the header, now let's make sure it links
1554         # properly, and that libtiff is available
1555         PBX_SPANDSP=0
1556         AST_EXT_LIB_CHECK([SPANDSP], [spandsp], [span_set_message_handler], [spandsp.h], [-ltiff])
1557 fi
1558
1559 if test "x${PBX_SPANDSP}" = "x1" ; then
1560         # We also need t38_terminal_init()
1561         PBX_SPANDSP=0
1562         AST_EXT_LIB_CHECK([SPANDSP], [spandsp], [t38_terminal_init], [spandsp.h], [-ltiff])
1563 fi
1564
1565 AST_EXT_LIB_CHECK([SS7], [ss7], [ss7_pollflags], [libss7.h])
1566
1567 AST_EXT_LIB_CHECK([OPENR2], [openr2], [openr2_chan_new], [openr2.h])
1568
1569 if test "${USE_PWLIB}" != "no"; then
1570         if test -n "${PWLIB_DIR}"; then
1571                 PWLIBDIR="${PWLIB_DIR}"
1572         fi
1573         AST_CHECK_PWLIB()
1574         AST_CHECK_PWLIB_VERSION([PWLib], [PWLIB], [ptbuildopts.h], [1], [9], [2], [P[[WT]]LIB_VERSION])
1575                 
1576         if test "${HAS_PWLIB:-unset}" != "unset"; then
1577                 AST_CHECK_PWLIB_PLATFORM()
1578
1579                 PLATFORM_PWLIB="pt_${PWLIB_PLATFORM}_r"
1580
1581                 AST_CHECK_PWLIB_BUILD([PWLib], [PWLIB],
1582                         [Define if your system has the PWLib libraries.],
1583                         [#include "ptlib.h"],
1584                         [int q = (int) PTime::IsDaylightSavings();])
1585         fi
1586 fi
1587
1588 if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
1589         if test -n "${OPENH323_DIR}"; then
1590                 OPENH323DIR="${OPENH323_DIR}"
1591         fi
1592         AST_CHECK_OPENH323()
1593         AST_CHECK_PWLIB_VERSION([OpenH323], [OPENH323], [openh323buildopts.h], [1], [17], [3])
1594         AST_CHECK_OPENH323_BUILD()
1595         PLATFORM_OPENH323="h323_${PWLIB_PLATFORM}_${OPENH323_SUFFIX}"
1596         AST_CHECK_PWLIB_BUILD([OpenH323], [OPENH323],
1597                 [Define if your system has the OpenH323 libraries.],
1598                 [#include "ptlib.h"
1599                 #include "h323.h"
1600                 #include "h323ep.h"],
1601                 [H323EndPoint ep = H323EndPoint();],
1602                 [${PWLIB_INCLUDE}], [${PWLIB_LIB}])
1603 fi
1604
1605 AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h], [-lm]) 
1606 if test "x${PBX_LUA}" = "x1" ; then
1607         AC_DEFINE_UNQUOTED([LUA51_PREFIX], [1], [Define to 1 if lua is found with a lua5.1 prefix])
1608 fi
1609         
1610 # Some distributions (like SuSE) remove the 5.1 suffix.
1611 AST_EXT_LIB_CHECK([LUA], [lua], [luaL_register], [lua.h], [-lm]) 
1612
1613 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
1614
1615 # This is a bit complex... in reality, Asterisk's AIS support is dependent on finding
1616 # *any* implementation of AIS, not just OpenAIS. However, the configure script needs
1617 # to know the specifics of each possible implementation, and then represent the one
1618 # that was found as 'AIS'.
1619
1620 PBX_AIS=0
1621
1622 # OpenAIS installs its libraries into /usr/lib/openais by default, so check there
1623
1624 AST_EXT_LIB_CHECK([OPENAIS], [SaClm], [saClmInitialize], [openais/saClm.h], [-L/usr/lib/openais -L/usr/lib64/openais])
1625
1626 if test "${PBX_OPENAIS}" = 1; then
1627    PBX_AIS=1
1628    if test -n "${OPENAIS_DIR}"; then
1629       AIS_INCLUDE="${OPENAIS_INCLUDE}/openais"
1630       AIS_LIB="-lSaEvt ${OPENAIS_LIB}"
1631    else
1632       AIS_INCLUDE="-I/usr/include/openais"
1633       AIS_LIB="-lSaClm -lSaEvt -L/usr/lib/openais -L/usr/lib64/openais"
1634    fi
1635 fi
1636
1637 AC_SUBST(PBX_AIS)
1638 AC_SUBST(AIS_INCLUDE)
1639 AC_SUBST(AIS_LIB)
1640
1641 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
1642
1643 # See if the main speex library contains the preprocess functions
1644 AST_EXT_LIB_CHECK([SPEEX_PREPROCESS], [speex], [speex_preprocess_ctl], [speex/speex.h], [-lm])
1645 if test "${PBX_SPEEX_PREPROCESS}" = 1; then
1646    PBX_SPEEX_PREPROCESS=1
1647 fi
1648
1649 AST_EXT_LIB_CHECK([SPEEXDSP], [speexdsp], [speex_preprocess_ctl], [speex/speex.h], [-lm])
1650 if test "${PBX_SPEEXDSP}" = 1; then
1651    PBX_SPEEX_PREPROCESS=1
1652 fi
1653
1654 AC_SUBST(PBX_SPEEX_PREPROCESS)
1655
1656 AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])
1657
1658 AST_EXT_LIB_CHECK([SQLITE3], [sqlite3], [sqlite3_open], [sqlite3.h])
1659
1660 AST_EXT_LIB_CHECK([CRYPTO], [crypto], [AES_encrypt], [openssl/aes.h])
1661
1662 if test "$PBX_CRYPTO" = "1";
1663 then
1664     AST_EXT_LIB_CHECK([OPENSSL], [ssl], [ssl2_connect], [openssl/ssl.h], [-lcrypto])
1665 fi
1666
1667 if test "$PBX_OPENSSL" = "1";
1668 then
1669     AST_CHECK_OSPTK([3], [6], [0])
1670 fi
1671
1672 AST_EXT_TOOL_CHECK([GMIME], [gmime-config], [], [], [#include <gmime/gmime.h>], [gboolean q = g_mime_check_version(0,0,0);])
1673
1674 AST_EXT_LIB_CHECK([HOARD], [hoard], [malloc], [])
1675
1676 AST_EXT_LIB_CHECK([FREETDS], [sybdb], [dbinit], [sybdb.h])
1677
1678 AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
1679
1680 AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])
1681
1682 AC_CHECK_LIB([tonezone], [tone_zone_find_by_num], tonezone_does_not_need_lm=yes, tonezone_does_not_need_lm=no)
1683
1684 if test "${tonezone_does_not_need_lm}" = "no" ; then
1685   tonezone_extra="-lm"
1686 fi
1687
1688 AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [dahdi/tonezone.h], [${tonezone_extra} ${DAHDI_INCLUDE}])
1689
1690 AST_EXT_LIB_CHECK([USB], [usb], [usb_init], [usb.h], [])
1691
1692 if test "${OSARCH}" = "OpenBSD";
1693 then
1694         AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc -logg])
1695 else
1696         AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc])
1697 fi
1698
1699 AC_LANG_PUSH(C++)
1700
1701 if test "${USE_VPB}" != "no"; then
1702    AC_MSG_CHECKING(for vpb_open in -lvpb)
1703    saved_libs="${LIBS}"
1704    saved_cppflags="${CPPFLAGS}"
1705    if test "x${VPB_DIR}" != "x"; then
1706       if test -d ${VPB_DIR}/lib; then
1707          vpblibdir=${VPB_DIR}/lib
1708       else
1709          vpblibdir=${VPB_DIR}
1710       fi
1711       LIBS="${LIBS} -L${vpblibdir}"
1712       CPPFLAGS="${CPPFLAGS} -I${VPB_DIR}/include"
1713    fi
1714    LIBS="${LIBS} -lvpb -lpthread"
1715    AC_LINK_IFELSE(
1716         [
1717         AC_LANG_PROGRAM(
1718         [#include <vpbapi.h>],
1719         [int q = vpb_open(0,0);])
1720         ],
1721         [       AC_MSG_RESULT(yes) 
1722                 ac_cv_lib_vpb_vpb_open="yes" 
1723         ],
1724         [       AC_MSG_RESULT(no) 
1725                 ac_cv_lib_vpb_vpb_open="no" 
1726         ]
1727         )
1728    LIBS="${saved_libs}"
1729    CPPFLAGS="${saved_cppflags}"
1730    if test "${ac_cv_lib_vpb_vpb_open}" = "yes"; then
1731         VPB_LIB="-lvpb"
1732         if test "${VPB_DIR}" != ""; then
1733            VPB_LIB="-L${vpblibdir}  ${VPB_LIB}"
1734            VPB_INCLUDE="-I${VPB_DIR}/include"
1735         fi
1736         PBX_VPB=1
1737         AC_DEFINE([HAVE_VPB], 1, [Define if your system has the VoiceTronix API libraries.])
1738    fi
1739 fi
1740
1741 AC_LANG_POP
1742
1743 AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])
1744
1745 EDITLINE_LIB=""
1746 if test "x$TERMCAP_LIB" != "x" ; then
1747   EDITLINE_LIB="$TERMCAP_LIB"
1748 elif test "x$TINFO_LIB" != "x" ; then
1749   EDITLINE_LIB="$TINFO_LIB"
1750 elif test "x$CURSES_LIB" != "x" ; then
1751   EDITLINE_LIB="$CURSES_LIB"
1752 elif test "x$NCURSES_LIB" != "x" ; then
1753   EDITLINE_LIB="$NCURSES_LIB"
1754 else
1755   AC_MSG_ERROR([*** termcap support not found (on modern systems, this typically means the ncurses development package is missing)])
1756 fi
1757 AC_SUBST(EDITLINE_LIB)
1758
1759 if test "x${PBX_UNIXODBC}" = "x1" -o "x${PBX_IODBC}" = "x1"; then
1760         # Does ODBC support wide characters?
1761         AC_MSG_CHECKING(whether ODBC has support for Unicode types)
1762         AC_LINK_IFELSE(
1763                 AC_LANG_PROGRAM(
1764                         [#include <sql.h>
1765 #include <sqlext.h>],
1766                         [int foo = SQL_WCHAR]),
1767                 AC_MSG_RESULT(yes)
1768                         AC_DEFINE([HAVE_ODBC_WCHAR], [1], [Define to 1 if your ODBC library has wide (Unicode) types.]),
1769                 AC_MSG_RESULT(no)
1770         )
1771 fi
1772
1773 AC_CHECK_HEADER([h323.h], [PBX_H323=1], [PBX_H323=0])
1774 AC_SUBST(PBX_H323)
1775
1776 AC_CHECK_HEADER([linux/compiler.h],
1777                 [AC_DEFINE_UNQUOTED([HAVE_LINUX_COMPILER_H], 1, [Define to 1 if your system has linux/compiler.h.])])
1778
1779 AC_CHECK_HEADER([linux/ixjuser.h], [PBX_IXJUSER=1], [PBX_IXJUSER=0], [
1780                                    #include <linux/version.h>
1781                                    #ifdef HAVE_LINUX_COMPILER_H
1782                                    #include <linux/compiler.h>
1783                                    #endif
1784                                    ])
1785 AC_SUBST(PBX_IXJUSER)
1786
1787 # Used in res/res_pktccops
1788 AST_C_DEFINE_CHECK([MSG_NOSIGNAL], [MSG_NOSIGNAL], [sys/socket.h])
1789 AST_C_DEFINE_CHECK([SO_NOSIGPIPE], [SO_NOSIGPIPE], [sys/socket.h])
1790
1791 AST_EXT_TOOL_CHECK([SDL], [sdl-config])
1792 AST_EXT_LIB_CHECK([SDL_IMAGE], [SDL_image], [IMG_Load], [SDL_image.h], [${SDL_LIB}], [${SDL_INCLUDE}])
1793 AST_EXT_LIB_CHECK([FFMPEG], [avcodec], [sws_getContext], [ffmpeg/avcodec.h], [-lpthread -lz -lm])
1794
1795 # possible places for video4linux version 1
1796 AC_CHECK_HEADER([linux/videodev.h],
1797         [AC_DEFINE_UNQUOTED([HAVE_VIDEODEV_H], 1, [Define to 1 if your system has linux/videodev.h.])])
1798
1799 # possible places for X11
1800 AST_EXT_LIB_CHECK([X11], [X11], [XOpenDisplay], [X11/Xlib.h],,, [standard_path])
1801 AST_EXT_LIB_CHECK([X11], [X11], [XOpenDisplay], [X11/Xlib.h],, [-I/usr/X11R6/include], [X11R6])
1802
1803 if test "${cross_compiling}" = "no";
1804 then
1805   AC_CHECK_FILE(/sbin/launchd, AC_DEFINE([HAVE_SBIN_LAUNCHD], 1, [Define to 1 if your system has /sbin/launchd.]))
1806 fi
1807
1808 PBX_GTK=0
1809 AST_EXT_TOOL_CHECK([GTK], [gtk-config], [--cflags gthread], [--libs gthread])
1810
1811 PBX_GTK2=0
1812 AC_CHECK_TOOL(PKGCONFIG, pkg-config, No)
1813 if test ! "x${PKGCONFIG}" = xNo; then
1814    GTK2_INCLUDE=$(${PKGCONFIG} gtk+-2.0 --cflags 2>/dev/null)
1815    GTK2_LIB=$(${PKGCONFIG} gtk+-2.0 --libs)
1816    PBX_GTK2=1
1817    AC_DEFINE([HAVE_GTK2], 1, [Define if your system has the GTK2 libraries.])
1818 fi
1819 AC_SUBST(PBX_GTK2)
1820 AC_SUBST(GTK2_INCLUDE)
1821 AC_SUBST(GTK2_LIB)
1822
1823 AST_LIBCURL_CHECK_CONFIG([], [7.10.1])
1824
1825 # build a GENERIC_ODBC result based on the presence of either UnixODBC (preferred)
1826 # or iODBC
1827
1828 PBX_GENERIC_ODBC=0
1829
1830 if test "${PBX_UNIXODBC}" = 1; then
1831    PBX_GENERIC_ODBC=1
1832    GENERIC_ODBC_LIB="${UNIXODBC_LIB}"
1833    GENERIC_ODBC_INCLUDE="${UNIXODBC_INCLUDE}"
1834 elif test "${PBX_IODBC}" = 1; then
1835    PBX_GENERIC_ODBC=1
1836    GENERIC_ODBC_LIB="${IODBC_LIB}"
1837    GENERIC_ODBC_INCLUDE="${IODBC_INCLUDE}"
1838 fi
1839
1840 AC_SUBST([GENERIC_ODBC_LIB])
1841 AC_SUBST([GENERIC_ODBC_INCLUDE])
1842 AC_SUBST([PBX_GENERIC_ODBC])
1843
1844 PBX_SYSLOG=0
1845
1846 if test "${ac_cv_header_syslog_h}" = "yes"; then
1847    # syslog facilities
1848    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_AUTH],     [LOG_AUTH],     [syslog.h])
1849    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_AUTHPRIV], [LOG_AUTHPRIV], [syslog.h])
1850    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_CRON],     [LOG_CRON],     [syslog.h])
1851    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_DAEMON],   [LOG_DAEMON],   [syslog.h])
1852    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_FTP],      [LOG_FTP],      [syslog.h])
1853    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_KERN],     [LOG_KERN],     [syslog.h])
1854    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_LPR],      [LOG_LPR],      [syslog.h])
1855    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_MAIL],     [LOG_MAIL],     [syslog.h])
1856    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_NEWS],     [LOG_NEWS],     [syslog.h])
1857    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_SYSLOG],   [LOG_SYSLOG],   [syslog.h])
1858    AST_C_DEFINE_CHECK([SYSLOG_FACILITY_LOG_UUCP],     [LOG_UUCP],     [syslog.h])
1859    PBX_SYSLOG=1
1860 fi
1861
1862 AC_SUBST([PBX_SYSLOG])
1863
1864 AC_CONFIG_FILES([build_tools/menuselect-deps makeopts channels/h323/Makefile])
1865 AST_CHECK_MANDATORY
1866
1867 if test -f build_tools/menuselect-deps; then
1868     # extract old values of all PBX_ variables from menuselect-deps
1869     # and preserve them so that menuselect can determine whether
1870     # any previously-met dependencies are no longer met and warn
1871     # the user appropriately
1872     while IFS="=:" read var val old_val; do
1873         eval "PBX_${var}=\${PBX_${var}}:${val}"
1874     done < build_tools/menuselect-deps
1875 fi
1876
1877 AC_OUTPUT
1878
1879 if test "x${silent}" != "xyes" ; then
1880 echo
1881 echo "               .\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$=..      "
1882 echo "            .\$7\$7..          .7\$\$7:.    "
1883 echo "          .\$\$:.                 ,\$7.7   "
1884 echo "        .\$7.     7\$\$\$\$           .\$\$77  "
1885 echo "     ..\$\$.       \$\$\$\$\$            .\$\$\$7 "
1886 echo "    ..7\$   .?.   \$\$\$\$\$   .?.       7\$\$\$."
1887 echo "   \$.\$.   .\$\$\$7. \$\$\$\$7 .7\$\$\$.      .\$\$\$."
1888 echo " .777.   .\$\$\$\$\$\$77\$\$\$77\$\$\$\$\$7.      \$\$\$,"
1889 echo " \$\$\$~      .7\$\$\$\$\$\$\$\$\$\$\$\$\$7.       .\$\$\$."
1890 echo ".\$\$7          .7\$\$\$\$\$\$\$7:          ?\$\$\$."
1891 echo "\$\$\$          ?7\$\$\$\$\$\$\$\$\$\$I        .\$\$\$7 "
1892 echo "\$\$\$       .7\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$      :\$\$\$. "
1893 echo "\$\$\$       \$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$\$\$\$    .\$\$\$.  "
1894 echo "\$\$\$        \$\$\$   7\$\$\$7  .\$\$\$    .\$\$\$.   "
1895 echo "\$\$\$\$             \$\$\$\$7         .\$\$\$.    "
1896 echo "7\$\$\$7            7\$\$\$\$        7\$\$\$      "
1897 echo " \$\$\$\$\$                        \$\$\$       "
1898 echo "  \$\$\$\$7.                       \$\$  (TM)     "
1899 echo "   \$\$\$\$\$\$\$.           .7\$\$\$\$\$\$  \$\$      "
1900 echo "     \$\$\$\$\$\$\$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$.\$\$\$\$\$\$      "
1901 echo "       \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$.                "
1902 echo
1903 fi
1904
1905 AC_MSG_NOTICE(Package configured for: )
1906 AC_MSG_NOTICE( OS type  : $host_os)
1907 AC_MSG_NOTICE( Host CPU : $host_cpu)
1908 AC_MSG_NOTICE( build-cpu:vendor:os: $build_cpu : $build_vendor : $build_os :) 
1909 AC_MSG_NOTICE( host-cpu:vendor:os: $host_cpu : $host_vendor : $host_os :) 
1910 if test "${cross_compiling}" = "yes"; then
1911    AC_MSG_NOTICE( Cross Compilation = YES)
1912 fi