[commit message]
[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.4, 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 # specify output header file
21 AC_CONFIG_HEADER(include/asterisk/autoconfig.h)
22
23 AC_COPYRIGHT("Asterisk")
24 AC_REVISION($Revision$)
25
26 AC_GNU_SOURCE
27 AC_USE_SYSTEM_EXTENSIONS        # note- does not work on FreeBSD
28
29 case "${host_os}" in
30      freebsd*)
31      ac_default_prefix=/usr/local
32      CPPFLAGS=-I/usr/local/include
33      LDFLAGS=-L/usr/local/lib
34      ;;
35
36      *)
37      ac_default_prefix=/usr
38      if test ${sysconfdir} = '${prefix}/etc'; then
39         sysconfdir=/etc
40      fi
41      if test ${mandir} = '${prefix}/man'; then
42         mandir=/usr/share/man
43      fi
44      ;;
45 esac
46
47 if test ${localstatedir} = '${prefix}/var'; then
48      localstatedir=/var
49 fi
50
51 BUILD_PLATFORM=${build}
52 BUILD_CPU=${build_cpu}
53 BUILD_VENDOR=${build_vendor}
54 BUILD_OS=${build_os}
55
56 AC_SUBST(BUILD_PLATFORM)
57 AC_SUBST(BUILD_CPU)
58 AC_SUBST(BUILD_VENDOR)
59 AC_SUBST(BUILD_OS)
60
61 HOST_PLATFORM=${host}
62 HOST_CPU=${host_cpu}
63 HOST_VENDOR=${host_vendor}
64 HOST_OS=${host_os}
65
66 AC_SUBST(HOST_PLATFORM)
67 AC_SUBST(HOST_CPU)
68 AC_SUBST(HOST_VENDOR)
69 AC_SUBST(HOST_OS)
70
71 WINARCH=0
72
73 case "${host_os}" in
74      freebsd*)
75      OSARCH=FreeBSD
76      ;;
77      netbsd*)
78      OSARCH=NetBSD
79      ;;
80      openbsd*)
81      OSARCH=OpenBSD
82      ;;
83      solaris*)
84      OSARCH=SunOS
85      ;;
86      mingw32)
87      OSARCH=mingw32
88      WINARCH=1
89      ;;
90      cygwin)
91      OSARCH=cygwin
92      WINARCH=1
93      ;;
94      *)
95      OSARCH=${host_os}
96      ;;
97 esac
98
99 AC_SUBST(OSARCH)
100 AC_SUBST(WINARCH)
101
102 #  check for uname
103 AC_PATH_TOOL([UNAME], [uname], No)
104 if test ! x"${UNAME}" = xNo; then
105    PBX_OSREV=$(${UNAME} -r)
106 fi
107 AC_SUBST(PBX_OSREV)
108
109 AH_TOP(
110 #ifndef ASTERISK_AUTOCONFIG_H
111 #define ASTERISK_AUTOCONFIG_H
112
113 #include "asterisk/buildopts.h"
114
115 )
116
117 AH_BOTTOM(
118 #endif
119 )
120
121 # cross-compile checks
122 if test "${cross_compiling}" = "yes"; 
123 then
124    AC_CHECK_TOOL(CC, gcc, :)
125    AC_CHECK_TOOL(CXX, g++, :)
126    AC_CHECK_TOOL(LD, ld, :)
127    AC_CHECK_TOOL(RANLIB, ranlib, :)
128 fi
129
130 # Checks for programs.
131 AC_PROG_CC
132 AC_PROG_CXX
133 AC_PROG_CPP
134 AC_PROG_CXXCPP
135 # This macro is just copied into our local acinclude.m4 from libtool.m4 so that
136 # the developers regenerating the configure script don't have to install libtool.
137 AST_PROG_LD     # note, does not work on FreeBSD
138 AC_PROG_AWK
139 AC_PROG_INSTALL
140 AC_PROG_LN_S
141 AC_PROG_RANLIB
142 AST_CHECK_GNU_MAKE
143
144 AC_PATH_TOOL([STRIP], [strip], :)
145 AC_PATH_TOOL([AR], [ar], :)
146
147 GNU_LD=0
148 if test "x$with_gnu_ld" = "xyes" ; then
149    GNU_LD=1
150 fi
151 AC_SUBST(GNU_LD)
152
153 AC_PATH_PROG([AWK], [awk], :)
154 AC_PATH_PROG([GREP], [grep], :)
155 AC_PATH_PROG([FIND], [find], :)
156 AC_PATH_PROG([COMPRESS], [compress], :)
157 AC_PATH_PROG([BASENAME], [basename], :)
158 AC_PATH_PROG([ID], [id], :)
159 AC_PATH_PROG([DIRNAME], [dirname], :)
160 AC_PATH_PROG([SHELL], [sh], :)
161 AC_PATH_PROG([LN], [ln], :)
162 AC_PATH_PROG([DOT], [dot], :)
163 AC_PATH_PROG([WGET], [wget], :)
164 AC_PATH_PROG([RUBBER], [rubber], :)
165 if test "${WGET}" != ":" ; then
166   DOWNLOAD=${WGET}
167 else
168   AC_PATH_PROG([FETCH], [fetch], [:])
169   DOWNLOAD=${FETCH}
170 fi
171 AC_SUBST(DOWNLOAD)
172
173 AC_CHECK_TOOL([SOXMIX], [soxmix], [:])
174 if test "${SOXMIX}" != ":" ; then
175         AC_DEFINE([HAVE_SOXMIX], 1, [Define to 1 if your system has soxmix application.])
176 fi
177
178 ACX_PTHREAD
179
180 AC_LANG(C)
181
182 AC_ARG_ENABLE(dev-mode,
183         [  --enable-dev-mode    Turn on developer mode],
184         [case "${enableval}" in
185               y|ye|yes) AST_DEVMODE=yes ;;
186               n|no)  AST_DEVMODE=no ;;
187               *) AC_MSG_ERROR(bad value ${enableval} for --enable-dev-mode)  ;;
188         esac])
189 AC_SUBST(AST_DEVMODE)
190
191 # AST_EXT_LIB_SETUP is used to tell configure to handle variables for
192 # various packages.
193 # $1 is the prefix for the variables in makeopts and autoconfig.h
194 # $2 is the short comment, $4 is the long comment
195 # $3 is the name used in --with- or --without- flags for configure.
196 #
197 # Package option names should be in alphabetical order
198 # by the --with option name (the third field),
199 # to make things easier for the users.
200
201 AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
202
203 # BKTR is used for backtrace support on platforms that do not
204 # have it natively.
205 AST_EXT_LIB_SETUP([BKTR], [Stack Backtrace support], [execinfo])
206 AST_EXT_LIB_SETUP([CAP], [POSIX 1.e capabilities], [cap])
207 AST_EXT_LIB_SETUP([CURL], [cURL], [curl])
208 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
209 AST_EXT_LIB_SETUP([CRYPTO], [OpenSSL Cryptography support], [crypto])
210 AST_EXT_LIB_SETUP([GSM], [External GSM library], [gsm], [, use 'internal' GSM otherwise])
211 AST_EXT_LIB_SETUP([GTK], [gtk libraries], [gtk])
212 AST_EXT_LIB_SETUP([GTK2], [gtk2 libraries], [gtk2])
213 AST_EXT_LIB_SETUP([ICONV], [Iconv Library], [iconv])
214 AST_EXT_LIB_SETUP([IKSEMEL], [Iksemel Jabber Library], [iksemel])
215 AST_EXT_LIB_SETUP([IMAP_TK], [UW IMAP Toolkit], [imap])
216 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
217 AST_EXT_LIB_SETUP([KDE], [KDE], [kde])
218 AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
219 AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
220 AST_EXT_LIB_SETUP([MISDN], [mISDN User Library], [misdn])
221 AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
222 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
223 AST_EXT_LIB_SETUP([NETSNMP], [Net-SNMP], [netsnmp])
224 AST_EXT_LIB_SETUP([NEWT], [newt], [newt])
225 AST_EXT_LIB_SETUP([UNIXODBC], [unixODBC], [odbc])
226 AST_EXT_LIB_SETUP([OGG], [OGG], [ogg])
227 AST_EXT_LIB_SETUP([OSPTK], [OSP Toolkit], [osptk])
228 AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
229 AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
230 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
231 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
232 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
233 AST_EXT_LIB_SETUP([SS7], [ISDN SS7], [ss7])
234 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
235 AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
236 AST_EXT_LIB_SETUP([QT], [Qt], [qt])
237 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
238 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
239 AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
240 AST_EXT_LIB_SETUP([SQLITE3], [SQLite], [sqlite3])
241 AST_EXT_LIB_SETUP([SUPPSERV], [mISDN Supplemental Services], [suppserv])
242 AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL Secure Sockets Layer support], [ssl])
243 AST_EXT_LIB_SETUP([FREETDS], [FreeTDS], [tds])
244 AST_EXT_LIB_SETUP([TERMCAP], [Termcap], [termcap])
245 AST_EXT_LIB_SETUP([TINFO], [Term Info], [tinfo])
246 AST_EXT_LIB_SETUP([TONEZONE], [tonezone], [tonezone])
247 AST_EXT_LIB_SETUP([USB], [usb], [usb])
248 AST_EXT_LIB_SETUP([VORBIS], [Vorbis], [vorbis])
249 AST_EXT_LIB_SETUP([VPB], [Voicetronix API], [vpb])
250 AST_EXT_LIB_SETUP([X11], [X11 support], [x11])
251 AST_EXT_LIB_SETUP([ZLIB], [zlib], [z])
252 AST_EXT_LIB_SETUP([ZAPTEL], [Zaptel], [zaptel])
253 AST_EXT_LIB_SETUP([ZAPTEL_TRANSCODE], [Zaptel Transcoder Support], [zaptel_transcode])
254 AST_EXT_LIB_SETUP([ZAPTEL_VLDTMF], [Zaptel VLDTMF Support], [zaptel_vldtmf])
255 AST_EXT_LIB_SETUP([ZAPTEL_HWGAIN], [Zaptel Hardware Gain Support], [zaptel_hwgain])
256 AST_EXT_LIB_SETUP([ZAPTEL_ECHOCANPARAMS], [Zaptel Echo Canceler Parameter Support], [zaptel_echocanparams])
257 AST_EXT_LIB_SETUP([ZAPTEL_CHANALARMS], [Zaptel Channel Alarm Support], [zaptel_chanalarms])
258
259 AST_EXT_LIB_SETUP([SDL], [Sdl], [sdl])
260 AST_EXT_LIB_SETUP([SDL_IMAGE], [Sdl Image library], [SDL_image])
261 AST_EXT_LIB_SETUP([FFMPEG], [Ffmpeg and avcodec library], [avcodec])
262
263 # check for basic system features and functionality before
264 # checking for package libraries
265
266 AC_FUNC_ALLOCA
267 AC_HEADER_DIRENT
268 AC_HEADER_STDC
269 AC_HEADER_SYS_WAIT
270 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])
271
272 AC_CHECK_HEADERS([winsock.h winsock2.h])
273
274 AC_SYS_LARGEFILE
275
276 # Checks for typedefs, structures, and compiler characteristics.
277 AC_HEADER_STDBOOL
278 AC_C_CONST
279 AC_TYPE_UID_T
280 AC_C_INLINE
281 AC_TYPE_MODE_T
282 AC_TYPE_OFF_T
283 AC_TYPE_PID_T
284 AC_TYPE_SIZE_T
285 AC_CHECK_MEMBERS([struct stat.st_blksize])
286 AC_HEADER_TIME
287 AC_STRUCT_TM
288 AC_C_VOLATILE
289 AC_CHECK_TYPES([ptrdiff_t])
290
291 # Checks for library functions.
292 AC_FUNC_CHOWN
293 AC_FUNC_CLOSEDIR_VOID
294 AC_FUNC_ERROR_AT_LINE
295 AST_FUNC_FORK
296 AC_FUNC_FSEEKO
297 AC_PROG_GCC_TRADITIONAL
298 # XXX: these are commented out until we determine whether it matters if our malloc()
299 # acts exactly like glibc's or not
300 # AC_FUNC_MALLOC
301 # AC_FUNC_REALLOC
302 AC_FUNC_MEMCMP
303 AC_FUNC_MKTIME
304 AC_FUNC_MMAP
305 AC_FUNC_SELECT_ARGTYPES
306 AC_FUNC_SETVBUF_REVERSED
307 AC_TYPE_SIGNAL
308 AC_FUNC_STAT
309 AC_FUNC_STRCOLL
310 AC_FUNC_STRFTIME
311 AC_FUNC_STRNLEN
312 AC_FUNC_STRTOD
313 AC_FUNC_UTIME_NULL
314 AC_FUNC_VPRINTF
315 AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf])
316
317 AC_CHECK_FUNCS([glob])
318
319 AC_MSG_CHECKING(for timersub in time.h)
320 AC_LINK_IFELSE(
321         AC_LANG_PROGRAM([#include <sys/time.h>],
322                 [struct timeval *a; timersub(a, a, a);]),
323         AC_MSG_RESULT(yes)
324                 AC_DEFINE([HAVE_TIMERSUB], 1, [Define to 1 if your system defines timersub.]),
325         AC_MSG_RESULT(no)
326 )
327
328 AC_CHECK_HEADER([sys/poll.h], 
329    [HAS_POLL=1]
330    AC_DEFINE([HAVE_SYS_POLL_H], 1, [Define to 1 if your system has working sys/poll.h]),
331    )
332 AC_SUBST(HAS_POLL)
333
334 # https support (in main/http.c) uses funopen on BSD systems,
335 # fopencookie on linux
336 AC_CHECK_FUNCS([funopen fopencookie])
337
338 AC_CHECK_FUNCS([inet_aton])
339
340 # check if we have IP_PKTINFO constant defined
341 AC_MSG_CHECKING(for IP_PKTINFO)
342 AC_LINK_IFELSE(
343                 AC_LANG_PROGRAM([#include <netinet/in.h>],
344                                                 [int pi = IP_PKTINFO;]),
345                 AC_MSG_RESULT(yes)
346                 AC_DEFINE([HAVE_PKTINFO], 1, [Define to 1 if your system defines IP_PKTINFO.]),
347                 AC_MSG_RESULT(no)
348 )
349
350 # some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
351 AC_SEARCH_LIBS(gethostbyname_r, [socket nsl])
352
353 AC_MSG_CHECKING(for gethostbyname_r with 6 arguments)
354 AC_LINK_IFELSE(
355         AC_LANG_PROGRAM([#include <stdlib.h>
356                          #include <netdb.h>],
357                         [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);]),
358         AC_MSG_RESULT(yes)
359         AC_DEFINE([HAVE_GETHOSTBYNAME_R_6], 1, [Define to 1 if your system has gethostbyname_r with 6 arguments.]),
360         AC_MSG_RESULT(no)
361 )
362
363 AC_MSG_CHECKING(for gethostbyname_r with 5 arguments)
364 AC_LINK_IFELSE(
365         AC_LANG_PROGRAM([#include <stdlib.h>
366                          #include <netdb.h>],
367                         [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);]),
368         AC_MSG_RESULT(yes)
369         AC_DEFINE([HAVE_GETHOSTBYNAME_R_5], 1, [Define to 1 if your system has gethostbyname_r with 5 arguments.]),
370         AC_MSG_RESULT(no)
371 )
372
373 AC_CHECK_HEADER([byteswap.h], [AC_DEFINE_UNQUOTED([HAVE_BYTESWAP_H], 1, [Define to 1 if byteswap.h macros are available.])])
374
375 AC_MSG_CHECKING(for __swap16 variant of <sys/endian.h> byteswapping macros)
376 AC_LINK_IFELSE(
377 AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = __swap16(a);]),
378 AC_MSG_RESULT(yes)
379 AC_DEFINE([HAVE_SYS_ENDIAN_SWAP16], 1, [Define to 1 if your sys/endian.h header file provides the __swap16 macro.]),
380 AC_MSG_RESULT(no)
381 )
382
383 AC_MSG_CHECKING(for bswap16 variant of <sys/endian.h> byteswapping macros)
384 AC_LINK_IFELSE(
385 AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = bswap16(a);]),
386 AC_MSG_RESULT(yes)
387 AC_DEFINE([HAVE_SYS_ENDIAN_BSWAP16], 1, [Define to 1 if your sys/endian.h header file provides the bswap16 macro.]),
388 AC_MSG_RESULT(no)
389 )
390
391 if test "${cross_compiling}" = "no";
392 then
393   AC_CHECK_FILE(/dev/urandom, AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define to 1 if your system has /dev/urandom.]))
394 fi
395
396 AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [pthread.h])
397
398 AC_MSG_CHECKING(for PTHREAD_RWLOCK_PREFER_WRITER_NP in pthread.h)
399 AC_LINK_IFELSE(
400 AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_RWLOCK_PREFER_WRITER_NP;]),
401 AC_MSG_RESULT(yes)
402 AC_DEFINE([HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP], 1, [Define to 1 if your system defines PTHREAD_RWLOCK_PREFER_WRITER_NP in pthread.h]),
403 AC_MSG_RESULT(no)
404 )
405
406 AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE_NP in pthread.h)
407 AC_LINK_IFELSE(
408 AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_MUTEX_RECURSIVE_NP;]),
409 AC_MSG_RESULT(yes)
410 AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1, [Define to 1 if your system defines PTHREAD_MUTEX_RECURSIVE_NP in pthread.h]),
411 AC_MSG_RESULT(no)
412 )
413
414 AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [pthread.h])
415
416 if test "${cross_compiling}" = "no";
417 then
418 AC_MSG_CHECKING(for working epoll support)
419 AC_LINK_IFELSE(
420 AC_LANG_PROGRAM([#include <sys/epoll.h>], [int res = epoll_create(10);
421                                           if (res < 0)
422                                              return 1;
423                                           close (res);
424                                           return 0;]),
425 AC_MSG_RESULT(yes)
426 AC_DEFINE([HAVE_EPOLL], 1, [Define to 1 if your system has working epoll support.]),
427 AC_MSG_RESULT(no)
428 )
429 fi
430
431 AC_MSG_CHECKING(for compiler atomic operations)
432 AC_LINK_IFELSE(
433 AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);]),
434 AC_MSG_RESULT(yes)
435 AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
436 AC_MSG_RESULT(no)
437 )
438
439 AST_GCC_ATTRIBUTE(pure)
440 AST_GCC_ATTRIBUTE(malloc)
441 AST_GCC_ATTRIBUTE(const)
442 AST_GCC_ATTRIBUTE(unused)
443 AST_GCC_ATTRIBUTE(always_inline)
444 AST_GCC_ATTRIBUTE(deprecated)
445
446 AC_MSG_CHECKING(for -ffunction-sections support)
447 saved_CFLAGS="${CFLAGS}"
448 CFLAGS="${CFLAGS} -ffunction-sections"
449 AC_COMPILE_IFELSE(
450         AC_LANG_PROGRAM([], [int x = 1;]),
451         AC_MSG_RESULT(yes)
452         [saved_LDFLAGS="${LDFLAGS}"]
453         [LDFLAGS="${LDFLAGS} -Wl,--gc-sections"]
454         AC_MSG_CHECKING(for --gc-sections support)
455         AC_LINK_IFELSE(
456                 AC_LANG_PROGRAM([], [int x = 1;]),
457                 AC_MSG_RESULT(yes)
458                 [GC_CFLAGS="-ffunction-sections"]
459                 [[GC_LDFLAGS="-Wl,--gc-sections"]],
460                 AC_MSG_RESULT(no)
461         )
462         [LDFLAGS="${saved_LDFLAGS}"],
463         AC_MSG_RESULT(no)
464 )
465 CFLAGS="${saved_CFLAGS}"
466 AC_SUBST(GC_CFLAGS)
467 AC_SUBST(GC_LDFLAGS)
468
469 AC_MSG_CHECKING(for -Wdeclaration-after-statement support)
470 if $(${CC} -Wdeclaration-after-statement -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
471         AC_MSG_RESULT(yes)
472         AST_DECLARATION_AFTER_STATEMENT=-Wdeclaration-after-statement
473 else
474         AC_MSG_RESULT(no)
475         AST_DECLARATION_AFTER_STATEMENT=
476 fi
477 AC_SUBST(AST_DECLARATION_AFTER_STATEMENT)
478
479
480 AC_MSG_CHECKING(for sysinfo)
481 AC_LINK_IFELSE(
482         AC_LANG_PROGRAM([#include <sys/sysinfo.h>],
483                         [struct sysinfo sys_info; int uptime = sys_info.uptime]),
484         AC_MSG_RESULT(yes)
485         AC_DEFINE([HAVE_SYSINFO], 1, [Define to 1 if your system has sysinfo support]),
486         AC_MSG_RESULT(no)
487 )
488
489 AC_MSG_CHECKING(for res_ninit)
490 AC_LINK_IFELSE(
491         AC_LANG_PROGRAM([#include <resolv.h>],
492                         [int foo = res_ninit(NULL);]),
493         AC_MSG_RESULT(yes)
494         AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.])
495         AC_MSG_CHECKING(for res_ndestroy)
496         AC_LINK_IFELSE(
497                 AC_LANG_PROGRAM([#include <resolv.h>],
498                                 [int foo = res_ndestroy(NULL);]),
499                 AC_MSG_RESULT(yes)
500                 AC_DEFINE([HAVE_RES_NDESTROY], 1, [Define to 1 if your system has the ndestroy resolver function.]),
501                 AC_MSG_RESULT(no)
502         ),
503         AC_MSG_RESULT(no)
504 )
505
506 AST_C_DEFINE_CHECK([RTLD_NOLOAD], [RTLD_NOLOAD], [dlfcn.h])
507
508 AST_C_DEFINE_CHECK([IP_MTU_DISCOVER], [IP_MTU_DISCOVER], [netinet/in.h])
509
510 AC_CHECK_HEADER([libkern/OSAtomic.h],
511                 [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])
512
513 AC_CHECK_SIZEOF(int)
514
515 # do the package library checks now
516
517 AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])
518
519 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
520
521 if test "x${host_os}" = "xlinux-gnu" ; then
522   AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
523 fi
524
525 # BSD might not have exp2, and/or log2
526 AST_EXT_LIB_CHECK([EXP2L], [m], [exp2l])
527 AST_EXT_LIB_CHECK([LOG2L], [m], [log2l])
528 AST_EXT_LIB_CHECK([EXP10L], [m], [exp10l])
529 AST_EXT_LIB_CHECK([LOG10L], [m], [log10l])
530 AST_EXT_LIB_CHECK([SINL], [m], [sinl])
531 AST_EXT_LIB_CHECK([COSL], [m], [cosl])
532 AST_EXT_LIB_CHECK([TANL], [m], [tanl])
533 AST_EXT_LIB_CHECK([ASINL], [m], [asinl])
534 AST_EXT_LIB_CHECK([ACOSL], [m], [acosl])
535 AST_EXT_LIB_CHECK([ATANL], [m], [atanl])
536 AST_EXT_LIB_CHECK([ATAN2L], [m], [atan2l])
537 AST_EXT_LIB_CHECK([POWL], [m], [powl])
538 AST_EXT_LIB_CHECK([SQRTL], [m], [sqrtl])
539 AST_EXT_LIB_CHECK([RINTL], [m], [rintl])
540 AST_EXT_LIB_CHECK([EXPL], [m], [expl])
541 AST_EXT_LIB_CHECK([LOGL], [m], [logl])
542 AST_EXT_LIB_CHECK([REMAINDERL], [m], [remainderl])
543 AST_EXT_LIB_CHECK([FMODL], [m], [fmodl])
544 AST_EXT_LIB_CHECK([ROUNDL], [m], [roundl])
545 AST_EXT_LIB_CHECK([TRUNCL], [m], [truncl])
546 AST_EXT_LIB_CHECK([STRTOLD], [c], [strtold], [stdlib.h])
547 AST_EXT_LIB_CHECK([FLOORL], [m], [floorl])
548 AST_EXT_LIB_CHECK([CEILL], [m], [ceill])
549 AST_EXT_LIB_CHECK([EXP2], [m], [exp2])
550 AST_EXT_LIB_CHECK([LOG2], [m], [log2])
551 AST_EXT_LIB_CHECK([EXP10], [m], [exp10])
552 AST_EXT_LIB_CHECK([LOG10], [m], [log10])
553 AST_EXT_LIB_CHECK([SIN], [m], [sin])
554 AST_EXT_LIB_CHECK([COS], [m], [cos])
555 AST_EXT_LIB_CHECK([TAN], [m], [tan])
556 AST_EXT_LIB_CHECK([ASIN], [m], [asin])
557 AST_EXT_LIB_CHECK([ACOS], [m], [acos])
558 AST_EXT_LIB_CHECK([ATAN], [m], [atan])
559 AST_EXT_LIB_CHECK([ATAN2], [m], [atan2])
560 AST_EXT_LIB_CHECK([POW], [m], [pow])
561 AST_EXT_LIB_CHECK([SQRT], [m], [sqrt])
562 AST_EXT_LIB_CHECK([RINT], [m], [rint])
563 AST_EXT_LIB_CHECK([EXP], [m], [exp])
564 AST_EXT_LIB_CHECK([LOG], [m], [log])
565 AST_EXT_LIB_CHECK([REMAINDER], [m], [remainder])
566 AST_EXT_LIB_CHECK([FMOD], [m], [fmod])
567 AST_EXT_LIB_CHECK([ROUND], [m], [round])
568 AST_EXT_LIB_CHECK([TRUNC], [m], [trunc])
569 AST_EXT_LIB_CHECK([STRTOD], [c], [strtod], [stdlib.h])
570 AST_EXT_LIB_CHECK([FLOOR], [m], [floor])
571 AST_EXT_LIB_CHECK([CEIL], [m], [ceil])
572
573 GSM_INTERNAL="yes"
574 AC_SUBST(GSM_INTERNAL)
575 GSM_SYSTEM="yes"
576 if test "${USE_GSM}" != "no"; then
577    if test "${GSM_DIR}" = "internal"; then
578       GSM_SYSTEM="no"
579    elif test "${GSM_DIR}" != ""; then
580       GSM_INTERNAL="no"
581    fi
582    if test "${GSM_SYSTEM}" = "yes"; then
583       gsmlibdir=""
584       if test "x${GSM_DIR}" != "x"; then
585          if test -d ${GSM_DIR}/lib; then
586             gsmlibdir="-L${GSM_DIR}/lib"
587          else
588             gsmlibdir="-L${GSM_DIR}"
589          fi
590       fi
591       AC_CHECK_LIB([gsm], [gsm_create], AC_DEFINE_UNQUOTED([HAVE_GSM], 1,
592       [Define to indicate the GSM library]), [], ${gsmlibdir})
593       if test "${ac_cv_lib_gsm_gsm_create}" = "yes"; then
594          if test "x${GSM_DIR}" != "x" ; then
595             AC_CHECK_HEADER([${GSM_DIR}/include/gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
596             AC_CHECK_HEADER([${GSM_DIR}/include/gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
597          else
598             AC_CHECK_HEADER([gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
599             AC_CHECK_HEADER([gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
600          fi
601          if test "${GSM_HEADER_FOUND}" = "0" ; then
602             if test "{GSM_GSM_HEADER_FOUND}" = "0" ; then
603                if test "x${GSM_MANDATORY}" = "xyes" ; then
604                   AC_MSG_NOTICE([***])
605                   AC_MSG_NOTICE([*** It appears that you do not have the gsm development package installed.])
606                   AC_MSG_NOTICE([*** Please install it to include ${GSM_DESCRIP} support, or re-run configure])
607                   AC_MSG_NOTICE([*** without explicitly specifying --with-${GSM_OPTION}])
608                   exit 1
609                fi
610             fi
611          fi
612          GSM_OK=0
613          if test "${GSM_HEADER_FOUND}" = "1" ; then
614             AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
615             GSM_OK=1
616          else
617             if test "${GSM_GSM_HEADER_FOUND}" = "1" ; then
618                AC_DEFINE_UNQUOTED([HAVE_GSM_GSM_HEADER], 1, [Define to indicate that gsm.h is in gsm/gsm.h])
619                GSM_OK=1
620             fi
621          fi
622          if test "${GSM_OK}" = "1" ; then
623             GSM_LIB="-lgsm"
624             if test "x${GSM_DIR}" != "x"; then
625                GSM_LIB="${gsmlibdir} ${GSM_LIB}"
626                GSM_INCLUDE="-I${GSM_DIR}/include"
627             fi
628             PBX_GSM=1
629             GSM_INTERNAL="no"
630          fi
631       fi
632    fi
633    if test "${GSM_INTERNAL}" = "yes"; then
634       PBX_GSM=1
635       AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
636    fi
637 fi
638
639 if test "${host_os}" != "linux-gnu" ; then
640   AST_EXT_LIB_CHECK([ICONV], [iconv], [iconv_open], [iconv.h])
641 else
642   PBX_ICONV=1
643 fi
644
645 AST_EXT_LIB_CHECK([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])
646
647 if test "${USE_IMAP_TK}" != "no"; then
648    if test "${IMAP_TK_DIR}" = "system" ; then
649       AC_MSG_NOTICE([Checking for system c-client library...])
650    elif test "${IMAP_TK_DIR}" = ""; then
651       IMAP_TK_DIR=`pwd`"/../imap-2004g"
652       if test  -n "${IMAP_TK_MANDATORY}"; then
653          AC_MSG_NOTICE([The --with-imap option does not search your system for installed])
654          AC_MSG_NOTICE([c-client library/header files. Since you did not provide a path])
655          AC_MSG_NOTICE([the configure script will assume you have placed built the c-client])
656          AC_MSG_NOTICE([files at ${IMAP_TK_DIR}, as outlined in the doc/imapstorage.txt file.])
657       fi
658    fi
659    if test "${IMAP_TK_DIR}" != "system" ; then
660       AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
661    fi
662    saved_cppflags="${CPPFLAGS}"
663    saved_libs="${LIBS}"
664    if test "${IMAP_TK_DIR}" = "system" ; then
665       imap_ldflags=""
666       imap_libs="-lc-client"
667       imap_include="-DUSE_SYSTEM_IMAP"
668    elif test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
669       imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
670       imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
671       imap_include="-I${IMAP_TK_DIR}/c-client"
672    fi
673    CPPFLAGS="${CPPFLAGS} ${imap_include}"
674    LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
675    AC_LINK_IFELSE(
676         AC_LANG_PROGRAM(
677                 [#ifdef USE_SYSTEM_IMAP
678                 #include <imap/c-client.h>
679                 #else
680                 #include "c-client.h"
681                 #endif
682                 void mm_searched (MAILSTREAM *stream,unsigned long number)
683                 {
684                 }
685                 void mm_exists (MAILSTREAM *stream,unsigned long number)
686                 {
687                 }
688                 void mm_expunged (MAILSTREAM *stream,unsigned long number)
689                 {
690                 }
691                 void mm_flags (MAILSTREAM *stream,unsigned long number)
692                 {
693                 }
694                 void mm_notify (MAILSTREAM *stream,char *string,long errflg)
695                 {
696                 }
697                 void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
698                 {
699                 }
700                 void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
701                 {
702                 }
703                 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
704                 {
705                 }
706                 void mm_log (char *string,long errflg)
707                 {
708                 }
709                 void mm_dlog (char *string)
710                 {
711                 }
712                 void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
713                 {
714                 }
715                 void mm_critical (MAILSTREAM *stream)
716                 {
717                 }
718                 void mm_nocritical (MAILSTREAM *stream)
719                 {
720                 }
721                 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
722                 {
723                 }
724                 void mm_fatal (char *string)
725                 {
726                 }],
727                 [
728                 MAILSTREAM *foo = mail_open(NULL, "", 0);
729                 ]
730         ),
731         [ac_cv_imap_tk="yes"],
732         [ac_cv_imap_tk="no"]
733    )
734    if test "${ac_cv_imap_tk}" = "yes"; then
735    AC_LINK_IFELSE(
736       AC_LANG_PROGRAM(
737          [#ifdef USE_SYSTEM_IMAP
738          #include <imap/c-client.h>
739          #else
740          #include "c-client.h"
741          #endif
742          void mm_searched (MAILSTREAM *stream,unsigned long number)
743          {
744          }
745          void mm_exists (MAILSTREAM *stream,unsigned long number)
746          {
747          }
748          void mm_expunged (MAILSTREAM *stream,unsigned long number)
749          {
750          }
751          void mm_flags (MAILSTREAM *stream,unsigned long number)
752          {
753          }
754          void mm_notify (MAILSTREAM *stream,char *string,long errflg)
755          {
756          }
757          void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
758          {
759          }
760          void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
761          {
762          }
763          void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
764          {
765          }
766          void mm_log (char *string,long errflg)
767          {
768          }
769          void mm_dlog (char *string)
770          {
771          }
772          void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
773          {
774          }
775          void mm_critical (MAILSTREAM *stream)
776          {
777          }
778          void mm_nocritical (MAILSTREAM *stream)
779          {
780          }
781          long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
782          {
783          }
784          void mm_fatal (char *string)
785          {
786          }],
787          [
788          long check = mail_expunge_full(NULL, "", 0);
789          ]
790       ),
791       [ac_cv_imap_tk2006="yes"],
792       [ac_cv_imap_tk2006="no"]
793   )
794   fi
795    CPPFLAGS="${saved_cppflags}"
796    LIBS="${saved_libs}"
797    if test "${ac_cv_imap_tk}" = "yes"; then
798       AC_MSG_RESULT(yes) 
799       IMAP_TK_LIB="${imap_libs} "`echo ${imap_ldflags}`
800       IMAP_TK_INCLUDE="${imap_include}"
801       PBX_IMAP_TK=1
802       AC_DEFINE([HAVE_IMAP_TK], 1, [Define if your system has the UW IMAP Toolkit c-client library.])
803       if test "${ac_cv_imap_tk2006}" = "yes"; then
804          AC_DEFINE([HAVE_IMAP_TK2006], 1, [Define if your system has the UW IMAP Toolkit c-client library version 2006 or greater.])
805       fi
806    else
807       AC_MSG_RESULT(no) 
808    fi
809 fi
810
811 # Needed by unixodbc
812 AST_EXT_LIB_CHECK([LTDL], [ltdl], [lt_dlinit], [ltdl.h], [])
813
814 AC_LANG_PUSH(C++)
815
816 if test "${USE_KDE}" != "no"; then
817    AC_MSG_CHECKING(for crashHandler in -lkdecore)
818    saved_libs="${LIBS}"
819    saved_cppflags="${CPPFLAGS}"
820    CPPFLAGS="${CPPFLAGS} -I${KDE_DIR}/include"
821    if test -d ${KDE_DIR}/lib; then
822       kdelibdir="${KDE_DIR}/lib"
823    else
824       kdelibdir="${KDE_DIR}"
825    fi
826    LIBS="${LIBS} -L${kdelibdir} -lkdecore"
827
828    AC_LINK_IFELSE(
829         [AC_LANG_PROGRAM(
830                         [#include "kcrash.h"],
831                         [KCrash::defaultCrashHandler(1);])
832         ],
833         [ac_cv_lib_kde_crash="yes"],
834         [ac_cv_lib_kde_crash="no"])
835                 
836    LIBS="${saved_libs}"
837    CPPFLAGS="${saved_cppflags}"
838         
839    if test "${ac_cv_lib_kde_crash}" = "yes"; then
840       AC_MSG_RESULT(yes) 
841       KDE_LIB="-lkdecore -lkdeui"
842       if test "${KDE_DIR}" != ""; then
843          KDE_LIB="-L${kdelibdir} ${KDE_LIB}"
844          KDE_INCLUDE="-I${KDE_DIR}/include"
845       fi
846       PBX_KDE=1
847       AC_DEFINE([HAVE_LIBKDE], 1, [Define if your system has the KDE libraries.])
848    else
849       AC_MSG_RESULT(no) 
850    fi
851 fi
852 if test "${PBX_KDE}" = 1; then
853    AC_PATH_TOOL(KDEINIT, kdeinit, No)
854    if test ! x"${KDEINIT}" = xNo; then
855       KDEDIR=$(${DIRNAME} ${KDEINIT})
856       KDEDIR=$(${DIRNAME} ${KDEDIR})
857    fi
858    AC_SUBST([KDEDIR])
859 fi
860
861 AC_LANG_POP
862
863 AST_EXT_LIB_CHECK([MISDN], [mISDN], [mISDN_open], [mISDNuser/mISDNlib.h])
864
865 if test "${PBX_MISDN}" = 1; then
866    AST_EXT_LIB_CHECK([ISDNNET], [isdnnet], [init_manager], [mISDNuser/isdn_net.h], [-lmISDN -lpthread])
867    AST_EXT_LIB_CHECK([SUPPSERV], [suppserv], [encodeFac], [mISDNuser/suppserv.h])
868    AST_C_DEFINE_CHECK([MISDN_FAC_RESULT], [Fac_RESULT], [mISDNuser/suppserv.h])
869    AST_C_DEFINE_CHECK([MISDN_FAC_ERROR], [Fac_ERROR], [mISDNuser/suppserv.h])
870    AC_CHECK_HEADER([linux/mISDNdsp.h], [AC_DEFINE_UNQUOTED([MISDN_1_2], 1, [Build chan_misdn for mISDN 1.2 or later.])])
871 fi
872
873 AST_EXT_LIB_CHECK([NBS], [nbs], [nbs_connect], [nbs.h])
874
875 AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
876
877 # XXX do we need to check for snmp_register_callback ?
878 AST_EXT_TOOL_CHECK([NETSNMP], [net-snmp], , [--agent-libs])
879
880 AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])
881
882 AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [])
883
884 AST_EXT_LIB_CHECK([OGG], [ogg], [ogg_sync_init], [])
885
886 AST_EXT_LIB_CHECK([BKTR], [execinfo], [backtrace], [execinfo.h])
887
888 # possible places for oss definitions
889 AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [linux/soundcard.h])
890 AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [sys/soundcard.h])
891 AST_EXT_LIB_CHECK([OSS], [ossaudio], [oss_ioctl_mixer], [soundcard.h])
892
893 PG_CONFIG=No
894 if test "${USE_PGSQL}" != "no"; then    
895    if test "x${PGSQL_DIR}" != "x"; then
896       AC_PATH_TOOL([PG_CONFIG], [pg_config], No, [${PGSQL_DIR}/bin])
897       if test x"${PG_CONFIG}" = xNo; then
898          AC_MSG_NOTICE([***])
899          AC_MSG_NOTICE([*** pg_config was not found in the path you specified:])
900          AC_MSG_NOTICE([*** ${PGSQL_DIR}/bin])
901          AC_MSG_NOTICE([*** Either correct the installation, or run configure])
902          AC_MSG_NOTICE([*** including --without-postgres])
903          exit 1
904       fi
905    else
906       AC_PATH_TOOL([PG_CONFIG], [pg_config], No)
907    fi
908 fi
909 if test "${PG_CONFIG}" != No; then
910    PGSQL_libdir=`${PG_CONFIG} --libdir`
911    PGSQL_includedir=`${PG_CONFIG} --includedir`
912    if test "x$?" != "x0" ; then
913       if test -n "${PGSQL_MANDATORY}" ; then
914          AC_MSG_NOTICE([***])
915          AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
916          AC_MSG_NOTICE([*** Either correct the installation, or run configure])
917          AC_MSG_NOTICE([*** including --without-postgres])
918          exit 1
919           fi
920    else 
921       AC_CHECK_LIB([pq], [PQescapeStringConn], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
922       [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)
923
924       if test "${ac_cv_lib_pq_PQescapeStringConn}" = "yes"; then
925          PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz"
926          PGSQL_INCLUDE="-I${PGSQL_includedir}"
927          PBX_PGSQL=1
928       elif test -n "${PGSQL_MANDATORY}";
929       then
930          AC_MSG_NOTICE([***])
931          AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
932          AC_MSG_NOTICE([*** Either correct the installation, or run configure])
933          AC_MSG_NOTICE([*** including --without-postgres])
934          exit 1
935       fi
936    fi
937 fi
938
939 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
940
941 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
942
943 AST_EXT_LIB_CHECK([PRI], [pri], [pri_new_bri], [libpri.h])
944
945 AST_EXT_LIB_CHECK([SS7], [ss7], [isup_cqr], [libss7.h])
946
947 if test "${USE_PWLIB}" != "no"; then
948         if test -n "${PWLIB_DIR}"; then
949                 PWLIBDIR="${PWLIB_DIR}"
950         fi
951         AST_CHECK_PWLIB()
952         AST_CHECK_PWLIB_VERSION([PWLib], [PWLIB], [ptbuildopts.h], [1], [9], [2])
953                 
954         if test "${HAS_PWLIB:-unset}" != "unset"; then
955                 AST_CHECK_OPENH323_PLATFORM()
956
957                 PLATFORM_PWLIB="pt_${PWLIB_PLATFORM}_r"
958
959                 AST_CHECK_PWLIB_BUILD([PWLib], [PWLIB],
960                         [Define if your system has the PWLib libraries.],
961                         [#include "ptlib.h"],
962                         [BOOL q = PTime::IsDaylightSavings();])
963         fi
964 fi
965
966 if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
967         if test -n "${OPENH323_DIR}"; then
968                 OPENH323DIR="${OPENH323_DIR}"
969         fi
970         AST_CHECK_OPENH323()
971         AST_CHECK_PWLIB_VERSION([OpenH323], [OPENH323], [openh323buildopts.h], [1], [17], [3])
972         AST_CHECK_OPENH323_BUILD()
973         PLATFORM_OPENH323="h323_${PWLIB_PLATFORM}_${OPENH323_SUFFIX}"
974         AST_CHECK_PWLIB_BUILD([OpenH323], [OPENH323],
975                 [Define if your system has the OpenH323 libraries.],
976                 [#include "ptlib.h"
977                 #include "h323.h"
978                 #include "h323ep.h"],
979                 [H323EndPoint ep = H323EndPoint();],
980                 [${PWLIB_INCLUDE}], [${PWLIB_LIB}])
981 fi
982
983 AC_LANG_PUSH(C++)
984
985 if test "${USE_QT}" != "no"; then
986    AC_MSG_CHECKING(for QDate in -lqt)
987    saved_libs="${LIBS}"
988    saved_cppflags="${CPPFLAGS}"
989    if test "x${QT_DIR}" != "x"; then
990       LIBS="${LIBS} -L${QT_DIR}/lib"
991       CPPFLAGS="${CPPFLAGS} -I${QT_DIR}/include"
992    fi
993    LIBS="${LIBS} -lqt"
994    qtlib="qt"
995    AC_LINK_IFELSE(
996         [
997                 AC_LANG_PROGRAM(
998                 [#include <qt3/qdatetime.h>],
999                 [QDate date();])
1000         ],
1001         [ac_cv_lib_qt_qt_date="yes"],
1002         [ac_cv_lib_qt_qt_date="no"])
1003    LIBS="${saved_libs}"
1004    CPPFLAGS="${saved_cppflags}"
1005         
1006    if test "${ac_cv_lib_qt_qt_date}" = "no"; then
1007       saved_libs="${LIBS}"
1008       saved_cppflags="${CPPFLAGS}"
1009       if test "x${QT_DIR}" != "x"; then
1010          LIBS="${LIBS} -L${QT_DIR}/lib"
1011          CPPFLAGS="${CPPFLAGS} -I${QT_DIR}/include"
1012       fi
1013       LIBS="${LIBS} -lqt-mt"
1014       qtlib="qt-mt"     
1015       AC_LINK_IFELSE(
1016                 [
1017                         AC_LANG_PROGRAM(
1018                         [#include <qt3/qdatetime.h>],
1019                         [QDate date();])
1020                 ],
1021                 [ac_cv_lib_qt_qt_date="yes"],
1022                 [ac_cv_lib_qt_qt_date="no"])
1023       LIBS="${saved_libs}"
1024       CPPFLAGS="${saved_cppflags}"
1025    fi   
1026
1027    if test "${ac_cv_lib_qt_qt_date}" = "yes"; then
1028       AC_MSG_RESULT(yes) 
1029    else
1030       AC_MSG_RESULT(no) 
1031    fi
1032         
1033    if test "${ac_cv_lib_qt_qt_date}" = "yes"; then
1034       QT_LIB="-l${qtlib}"
1035       if test "${QT_DIR}" != ""; then
1036          QT_LIB="-L${QT_DIR}/lib ${QT_LIB}"
1037          QT_INCLUDE="-I${QT_DIR}/include"
1038       fi
1039       PBX_QT=1
1040       AC_DEFINE([HAVE_QT], 1, [Define if your system has the Qt library])
1041       AC_PATH_TOOL(QTMOC, moc, No)
1042    fi
1043 fi
1044
1045 AC_LANG_POP
1046
1047 LUA_INCLUDE="-I/usr/include/lua5.1"
1048 LUA_LIB="-llua5.1"
1049 AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h]) 
1050
1051 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
1052
1053 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
1054
1055 AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])
1056
1057 AST_EXT_LIB_CHECK([SQLITE3], [sqlite3], [sqlite3_open], [sqlite3.h])
1058
1059 AST_EXT_LIB_CHECK([CRYPTO], [crypto], [AES_encrypt], [openssl/aes.h])
1060
1061 if test "$PBX_CRYPTO" = "1";
1062 then
1063     AST_EXT_LIB_CHECK([OPENSSL], [ssl], [ssl2_connect], [openssl/ssl.h], [-lcrypto])
1064 fi
1065
1066 if test "$PBX_OPENSSL" = "1";
1067 then
1068     AST_EXT_LIB_CHECK([OSPTK], [osptk], [OSPPCryptoDecrypt], [osp/osp.h], [-lcrypto -lssl])
1069 fi
1070
1071 AST_EXT_LIB_CHECK([FREETDS], [tds], [tds_version], [tds.h])
1072 if test "${PBX_FREETDS}" != "0";
1073 then
1074     case `grep TDS_VERSION_NO ${FREETDS_DIR:-/usr}/include/tdsver.h` in
1075         *0.64*)
1076                 FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_64"
1077         ;;
1078     *0.63*)
1079         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_63"
1080         ;;
1081     *0.62*)
1082         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_62"
1083         ;;
1084     *)
1085         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_PRE_0_62"
1086         ;;
1087     esac
1088 fi
1089
1090 AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
1091
1092 AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])
1093
1094 if test "${host_os}" != "linux-gnu" ; then
1095   tonezone_extra="-lm"
1096 fi
1097
1098 # new tonezone, version 1.4.0
1099 AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/tonezone.h], [${tonezone_extra}], [], [140])
1100 # other case, old tonezone (0.80)
1101 AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/zaptel.h], [${tonezone_extra}], [], [80])
1102
1103 AST_EXT_LIB_CHECK([USB], [usb], [usb_init], [usb.h], [])
1104
1105 AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc])
1106
1107 AC_LANG_PUSH(C++)
1108
1109 if test "${USE_VPB}" != "no"; then
1110    AC_MSG_CHECKING(for vpb_open in -lvpb)
1111    saved_libs="${LIBS}"
1112    saved_cppflags="${CPPFLAGS}"
1113    if test "x${VPB_DIR}" != "x"; then
1114       if test -d ${VPB_DIR}/lib; then
1115          vpblibdir=${VPB_DIR}/lib
1116       else
1117          vpblibdir=${VPB_DIR}
1118       fi
1119       LIBS="${LIBS} -L${vpblibdir}"
1120       CPPFLAGS="${CPPFLAGS} -I${VPB_DIR}/include"
1121    fi
1122    LIBS="${LIBS} -lvpb -lpthread"
1123    AC_LINK_IFELSE(
1124         [
1125         AC_LANG_PROGRAM(
1126         [#include <vpbapi.h>],
1127         [int q = vpb_open(0,0);])
1128         ],
1129         [       AC_MSG_RESULT(yes) 
1130                 ac_cv_lib_vpb_vpb_open="yes" 
1131         ],
1132         [       AC_MSG_RESULT(no) 
1133                 ac_cv_lib_vpb_vpb_open="no" 
1134         ]
1135         )
1136    LIBS="${saved_libs}"
1137    CPPFLAGS="${saved_cppflags}"
1138    if test "${ac_cv_lib_vpb_vpb_open}" = "yes"; then
1139         VPB_LIB="-lvpb"
1140         if test "${VPB_DIR}" != ""; then
1141            VPB_LIB="-L${vpblibdir}  ${VPB_LIB}"
1142            VPB_INCLUDE="-I${VPB_DIR}/include"
1143         fi
1144         PBX_VPB=1
1145         AC_DEFINE([HAVE_VPB], 1, [Define if your system has the VoiceTronix API libraries.])
1146    fi
1147 fi
1148
1149 AC_LANG_POP
1150
1151 AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])
1152
1153 # Check for various zaptel features and locations.
1154 # The version number, which goes into HAVE_ZAPTEL_VERSION,
1155 # will be used in the system headers to determine the location
1156 # of the zaptel.h header.
1157
1158 AST_C_DEFINE_CHECK([ZAPTEL], [ZT_TONE_DTMF_BASE], [zaptel/zaptel.h], [140])
1159 AST_C_DEFINE_CHECK([ZAPTEL], [ZT_DIAL_OP_CANCEL], [zaptel/zaptel.h], [90])
1160
1161 # Check for VLDTMF support
1162 AST_C_DEFINE_CHECK([ZAPTEL_VLDTMF], [ZT_EVENT_REMOVED], [zaptel/zaptel.h])
1163
1164 # Check for echo canceler parameters support
1165 AST_C_DEFINE_CHECK([ZAPTEL_ECHOCANPARAMS], [ZT_ECHOCANCEL_PARAMS], [zaptel/zaptel.h])
1166
1167 # Check for transcoder support
1168 AST_C_DEFINE_CHECK([ZAPTEL_TRANSCODE], [ZT_TCOP_ALLOCATE], [zaptel/zaptel.h])
1169
1170 # Check for hwgain support
1171 AST_C_DEFINE_CHECK([ZAPTEL_HWGAIN], [ZT_SET_HWGAIN], [zaptel/zaptel.h])
1172
1173 # Check for channel alarm support
1174 AST_C_COMPILE_CHECK([ZAPTEL_CHANALARMS], [size_t foo = sizeof(struct zt_params_v1)], [zaptel/zaptel.h])
1175
1176 # On FreeBSD, try old zaptel (0.80 or so) and pretend we have vldtmf
1177 case "${host_os}" in
1178     freebsd*)
1179         AST_EXT_LIB_CHECK([ZAPTEL], [zaptel],, [zaptel.h],,, [80])
1180         AST_EXT_LIB_CHECK([ZAPTEL_VLDTMF], [zaptel],, [zaptel/zaptel.h],,, [90])
1181         AST_EXT_LIB_CHECK([ZAPTEL_VLDTMF], [zaptel],, [zaptel.h],,, [80])
1182
1183         # other case, old tonezone (0.80)
1184         AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel.h], [${tonezone_extra}],, [80])
1185         ;;
1186 esac
1187
1188 EDITLINE_LIB=""
1189 if test "x$TERMCAP_LIB" != "x" ; then
1190   EDITLINE_LIB="$TERMCAP_LIB"
1191 elif test "x$TINFO_LIB" != "x" ; then
1192   EDITLINE_LIB="$TINFO_LIB"
1193 elif test "x$CURSES_LIB" != "x" ; then
1194   EDITLINE_LIB="$CURSES_LIB"
1195 elif test "x$NCURSES_LIB" != "x" ; then
1196   EDITLINE_LIB="$NCURSES_LIB"
1197 else
1198   AC_MSG_ERROR(*** termcap support not found)
1199 fi
1200 AC_SUBST(EDITLINE_LIB)
1201
1202 AC_CHECK_HEADER([h323.h], [PBX_H323=1], [PBX_H323=0])
1203 AC_SUBST(PBX_H323)
1204
1205 AC_CHECK_HEADER([linux/compiler.h],
1206                 [AC_DEFINE_UNQUOTED([HAVE_LINUX_COMPILER_H], 1, [Define to 1 if your system has linux/compiler.h.])])
1207
1208 AC_CHECK_HEADER([linux/ixjuser.h], [PBX_IXJUSER=1], [PBX_IXJUSER=0], [
1209                                    #include <linux/version.h>
1210                                    #ifdef HAVE_LINUX_COMPILER_H
1211                                    #include <linux/compiler.h>
1212                                    #endif
1213                                    ])
1214 AC_SUBST(PBX_IXJUSER)
1215
1216 AST_EXT_TOOL_CHECK([SDL], [sdl])
1217 AST_EXT_LIB_CHECK([SDL_IMAGE], [SDL_image], [IMG_Load], [SDL_image.h], [${SDL_LIB}], [${SDL_INCLUDE}])
1218 AST_EXT_LIB_CHECK([FFMPEG], [avcodec], [sws_getContext], [ffmpeg/avcodec.h], [-lpthread -lz -lm])
1219
1220 # possible places for video4linux version 1
1221 AC_CHECK_HEADER([linux/videodev.h],
1222         [AC_DEFINE_UNQUOTED([HAVE_VIDEODEV_H], 1, [Define to 1 if your system has linux/videodev.h.])])
1223
1224 # possible places for X11
1225 AST_EXT_LIB_CHECK([X11], [X11], [XOpenDisplay], [X11/Xlib.h],,, [standard_path])
1226 AST_EXT_LIB_CHECK([X11], [X11], [XOpenDisplay], [X11/Xlib.h],, [-I/usr/X11R6/include], [X11R6])
1227
1228 # we don't use gtk right now...
1229 AST_EXT_TOOL_CHECK([GTK], [gtk])
1230
1231 PBX_GTK2=0
1232 AC_CHECK_TOOL(PKGCONFIG, pkg-config, No)
1233 if test ! "x${PKGCONFIG}" = xNo; then
1234    GTK2_INCLUDE=$(${PKGCONFIG} gtk+-2.0 --cflags 2>/dev/null)
1235    GTK2_LIB=$(${PKGCONFIG} gtk+-2.0 --libs)
1236    PBX_GTK2=1
1237    AC_DEFINE([HAVE_GTK2], 1, [Define if your system has the GTK2 libraries.])
1238 fi
1239 AC_SUBST(PBX_GTK2)
1240 AC_SUBST(GTK2_INCLUDE)
1241 AC_SUBST(GTK2_LIB)
1242
1243 if test "${USE_CURL}" != "no"; then
1244    AC_PATH_TOOL([CURL_CONFIG], [curl-config], No)
1245    if test ! x"${CURL_CONFIG}" = xNo; then
1246    # check for version
1247       if test $(printf "%d" 0x$(${CURL_CONFIG} --vernum)) -ge $(printf "%d" 0x070907); then
1248          CURL_INCLUDE=$(${CURL_CONFIG} --cflags)
1249          CURL_LIB=$(${CURL_CONFIG} --libs)
1250
1251          AC_MSG_CHECKING(for curl_version() in curl/curl.h)
1252          saved_cppflags="${CPPFLAGS}"
1253          CPPFLAGS="${CPPFLAGS} ${CURL_INCLUDE}"
1254          AC_COMPILE_IFELSE(
1255             [AC_LANG_PROGRAM(
1256                 [#include <curl/curl.h>],
1257                     [curl_version();])
1258             ],[
1259                 AC_MSG_RESULT(yes)
1260                 ac_cv_curl_h="yes"
1261             ],[
1262                 AC_MSG_RESULT(no)
1263                 ac_cv_curl_h="no"
1264             ]
1265          )
1266          CPPFLAGS="${saved_cppflags}"
1267          if test "${ac_cv_curl_h}" = "yes"; then
1268              PBX_CURL=1
1269              AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
1270          fi
1271       fi
1272    fi
1273 fi
1274
1275 AC_CONFIG_FILES([build_tools/menuselect-deps makeopts channels/h323/Makefile])
1276 AST_CHECK_MANDATORY
1277
1278 AC_OUTPUT
1279
1280 if test "x${silent}" != "xyes" ; then
1281 echo
1282 echo "               .\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$=..      "
1283 echo "            .\$7\$7..          .7\$\$7:.    "
1284 echo "          .\$\$:.                 ,\$7.7   "
1285 echo "        .\$7.     7\$\$\$\$           .\$\$77  "
1286 echo "     ..\$\$.       \$\$\$\$\$            .\$\$\$7 "
1287 echo "    ..7\$   .?.   \$\$\$\$\$   .?.       7\$\$\$."
1288 echo "   \$.\$.   .\$\$\$7. \$\$\$\$7 .7\$\$\$.      .\$\$\$."
1289 echo " .777.   .\$\$\$\$\$\$77\$\$\$77\$\$\$\$\$7.      \$\$\$,"
1290 echo " \$\$\$~      .7\$\$\$\$\$\$\$\$\$\$\$\$\$7.       .\$\$\$."
1291 echo ".\$\$7          .7\$\$\$\$\$\$\$7:          ?\$\$\$."
1292 echo "\$\$\$          ?7\$\$\$\$\$\$\$\$\$\$I        .\$\$\$7 "
1293 echo "\$\$\$       .7\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$      :\$\$\$. "
1294 echo "\$\$\$       \$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$\$\$\$    .\$\$\$.  "
1295 echo "\$\$\$        \$\$\$   7\$\$\$7  .\$\$\$    .\$\$\$.   "
1296 echo "\$\$\$\$             \$\$\$\$7         .\$\$\$.    "
1297 echo "7\$\$\$7            7\$\$\$\$        7\$\$\$      "
1298 echo " \$\$\$\$\$                        \$\$\$       "
1299 echo "  \$\$\$\$7.                       \$\$  (TM)     "
1300 echo "   \$\$\$\$\$\$\$.           .7\$\$\$\$\$\$  \$\$      "
1301 echo "     \$\$\$\$\$\$\$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$.\$\$\$\$\$\$      "
1302 echo "       \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$.                "
1303 echo
1304 fi
1305
1306 AC_MSG_NOTICE(Package configured for: )
1307 AC_MSG_NOTICE( OS type  : $host_os)
1308 AC_MSG_NOTICE( Host CPU : $host_cpu)
1309 AC_MSG_NOTICE( build-cpu:vendor:os: $build_cpu : $build_vendor : $build_os :) 
1310 AC_MSG_NOTICE( host-cpu:vendor:os: $host_cpu : $host_vendor : $host_os :) 
1311 if test "${cross_compiling}" = "yes"; then
1312    AC_MSG_NOTICE( Cross Compilation = YES)
1313 fi