Merged revisions 74515 via svnmerge from
[asterisk/asterisk.git] / configure.ac
index 167a402..081a5e3 100644 (file)
@@ -1,6 +1,12 @@
 # Process this file with autoconf to produce a configure script.
+#
+# Make sure we use autoconf 2.60 to generate the "configure" script,
+# in case we want to commit it. Other than that, version 2.59 is
+# perfectly fine for our purposes, so people who want to modify
+# this file just have to remember to set the AC_PREREQ argument
+# to something that suits their needs.
 
-AC_PREREQ(2.60)
+AC_PREREQ(2.59)
 
 m4_define([PBX_VERSION],
           m4_bpatsubst(m4_esyscmd([build_tools/make_version .]),
@@ -21,10 +27,16 @@ AC_CONFIG_HEADER(include/asterisk/autoconfig.h)
 AC_COPYRIGHT("Asterisk")
 AC_REVISION($Revision$)
 
+AC_GNU_SOURCE
+AC_USE_SYSTEM_EXTENSIONS       # note- does not work on FreeBSD
+
 case "${host_os}" in
      freebsd*)
      ac_default_prefix=/usr/local
+     CPPFLAGS=-I/usr/local/include
+     LDFLAGS=-L/usr/local/lib
      ;;
+
      *)
      ac_default_prefix=/usr
      if test ${sysconfdir} = '${prefix}/etc'; then
@@ -87,18 +99,12 @@ if test ! x"${UNAME}" = xNo; then
 fi
 AC_SUBST(PBX_OSREV)
 
-# This needs to be before any macros that use the C compiler
-AC_GNU_SOURCE
-
 AH_TOP(
 #ifndef ASTERISK_AUTOCONFIG_H
 #define ASTERISK_AUTOCONFIG_H
 
 #include "asterisk/buildopts.h"
 
-#ifndef _REENTRANT
-#define _REENTRANT
-#endif
 )
 
 AH_BOTTOM(
@@ -112,7 +118,6 @@ then
    AC_CHECK_TOOL(CXX, g++, :)
    AC_CHECK_TOOL(LD, ld, :)
    AC_CHECK_TOOL(RANLIB, ranlib, :)
-   AC_CHECK_TOOL(AR, ar, :)
 fi
 
 # Checks for programs.
@@ -120,37 +125,25 @@ AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_CPP
 AC_PROG_CXXCPP
+# This macro is just copied into our local acinclude.m4 from libtool.m4 so that
+# the developers regenerating the configure script don't have to install libtool.
+AST_PROG_LD    # note, does not work on FreeBSD
 AC_PROG_AWK
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_RANLIB
 AST_CHECK_GNU_MAKE
 
-# http://www.mail-archive.com/bug-make@gnu.org/msg02871.html
-echo 'define A' > testMakefile
-echo '12345: $(1:.idl=.hh) $(1:.idl=S.h) $(1:.idl=C.h) $(1:.idl=SK.cc) $(1:.idl=DynSK.cc)' >> testMakefile
-echo 'endef' >> testMakefile
-echo '$(eval $(call A,01234567890123456789012345678901.idl))' >> testMakefile
-echo '01234567890123456789012345678901.hh:' >> testMakefile
-echo '01234567890123456789012345678901S.h:' >> testMakefile
-echo '01234567890123456789012345678901C.h:' >> testMakefile
-echo '01234567890123456789012345678901SK.cc:' >> testMakefile
-echo '01234567890123456789012345678901DynSK.cc:' >> testMakefile
-$GNU_MAKE -r -f testMakefile 2>&1 > /dev/null
-if test "$?" != "0" ; then
-  rm -f testMakefile
-  AC_MSG_NOTICE(********** ERROR **********)
-  AC_MSG_NOTICE(Your version of GNU Make contains a bug that will cause the Asterisk build)
-  AC_MSG_NOTICE(system to not function properly.  This bug is known to be fixed in version)
-  AC_MSG_NOTICE(3.81 as well as distributions of 3.80 that contain backported bug fixes.  You)
-  AC_MSG_NOTICE(must update GNU make to build Asterisk.)
-  AC_MSG_NOTICE(***************************)
-  exit 1
+AC_PATH_TOOL([STRIP], [strip], :)
+AC_PATH_TOOL([AR], [ar], :)
+
+GNU_LD=0
+if test "x$with_gnu_ld" = "xyes" ; then
+   GNU_LD=1
 fi
-rm -f testMakefile
+AC_SUBST(GNU_LD)
 
 AC_PATH_PROG([GREP], [grep], :)
-AC_PATH_PROG([AR], [ar], :)
 AC_PATH_PROG([FIND], [find], :)
 AC_PATH_PROG([COMPRESS], [compress], :)
 AC_PATH_PROG([BASENAME], [basename], :)
@@ -159,6 +152,17 @@ AC_PATH_PROG([DIRNAME], [dirname], :)
 AC_PATH_PROG([SHELL], [sh], :)
 AC_PATH_PROG([LN], [ln], :)
 AC_PATH_PROG([DOT], [dot], :)
+AC_PATH_PROG([WGET], [wget], :)
+AC_PATH_PROG([RUBBER], [rubber], :)
+if test "${WGET}" != ":" ; then
+  DOWNLOAD=${WGET}
+else
+  AC_PATH_PROG([FETCH], [fetch], [:])
+  DOWNLOAD=${FETCH}
+fi
+AC_SUBST(DOWNLOAD)
+
+ACX_PTHREAD
 
 AC_LANG(C)
 
@@ -175,13 +179,21 @@ AC_SUBST(AST_DEVMODE)
 # by the --with option name, to make things easier for the users :-)
 
 AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
+
+# BKTR is used for backtrace support on platforms that do not
+# have it natively.
+AST_EXT_LIB_SETUP([BKTR], [Stack Backtrace support], [execinfo])
+AST_EXT_LIB_SETUP([CAP], [POSIX 1.e capabilities], [cap])
+AST_EXT_LIB_SETUP([CURL], [cURL], [curl])
 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
+AST_EXT_LIB_SETUP([CRYPTO], [OpenSSL Cryptography support], [crypto])
 AST_EXT_LIB_SETUP([GNUTLS], [GNU TLS support (used for iksemel only)], [gnutls])
 AST_EXT_LIB_SETUP([GSM], [GSM], [gsm], [, or 'internal'])
 AST_EXT_LIB_SETUP([IKSEMEL], [Iksemel Jabber Library], [iksemel])
 AST_EXT_LIB_SETUP([IMAP_TK], [UW IMAP Toolkit], [imap])
 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
 AST_EXT_LIB_SETUP([KDE], [KDE], [kde])
+AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
 AST_EXT_LIB_SETUP([MISDN], [mISDN User Library], [misdn])
 AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
@@ -194,14 +206,16 @@ AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
 AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
+AST_EXT_LIB_SETUP([SS7], [ISDN SS7], [ss7])
 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
 AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
 AST_EXT_LIB_SETUP([QT], [Qt], [qt])
 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
 AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
+AST_EXT_LIB_SETUP([SQLITE3], [SQLite], [sqlite3])
 AST_EXT_LIB_SETUP([SUPPSERV], [mISDN Supplemental Services], [suppserv])
-AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL], [ssl])
+AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL Secure Sockets Layer support], [ssl])
 AST_EXT_LIB_SETUP([FREETDS], [FreeTDS], [tds])
 AST_EXT_LIB_SETUP([TERMCAP], [Termcap], [termcap])
 AST_EXT_LIB_SETUP([TINFO], [Term Info], [tinfo])
@@ -210,6 +224,8 @@ AST_EXT_LIB_SETUP([VORBIS], [Vorbis], [vorbis])
 AST_EXT_LIB_SETUP([VPB], [Voicetronix API], [vpb])
 AST_EXT_LIB_SETUP([ZLIB], [zlib], [z])
 AST_EXT_LIB_SETUP([ZAPTEL], [Zaptel], [zaptel])
+AST_EXT_LIB_SETUP([ZAPTEL_TRANSCODE], [Zaptel_transcode], [zaptel_transcode])
+AST_EXT_LIB_SETUP([ZAPTEL_VLDTMF], [Zaptel_vldtmf], [zaptel_vldtmf])
 
 # check for basic system features and functionality before
 # checking for package libraries
@@ -261,7 +277,17 @@ AC_FUNC_STRNLEN
 AC_FUNC_STRTOD
 AC_FUNC_UTIME_NULL
 AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent floor ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap pow putenv re_comp regcomp rint select setenv socket sqrt strcasecmp strcasestr strchr strcspn strdup strerror strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf])
+AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent floor ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap pow putenv re_comp regcomp rint select setenv socket sqrt strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf])
+
+# https support (in main/http.c) uses funopen on BSD systems,
+# fopencookie on linux
+AC_CHECK_FUNCS([funopen fopencookie])
+
+# some systems already have gethostbyname_r so we don't need to build ours in main/utils.c
+AC_CHECK_FUNCS([gethostbyname_r])
+
+AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [pthread.h])
+AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_PREFER_WRITER_NP], [PTHREAD_RWLOCK_PREFER_WRITER_NP], [pthread.h])
 
 AC_MSG_CHECKING(for compiler atomic operations)
 AC_LINK_IFELSE(
@@ -300,24 +326,47 @@ CFLAGS="${saved_CFLAGS}"
 AC_SUBST(GC_CFLAGS)
 AC_SUBST(GC_LDFLAGS)
 
-AC_MSG_CHECKING(for res_ninit)
-AC_LINK_IFELSE(
-       AC_LANG_PROGRAM([#include <resolv.h>],
-                       [int foo = res_ninit(NULL);]),
+AC_MSG_CHECKING(for -Wdeclaration-after-statement support)
+if $(${CC} -Wdeclaration-after-statement -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
        AC_MSG_RESULT(yes)
-       AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.]),
+       AST_DECLARATION_AFTER_STATEMENT=-Wdeclaration-after-statement
+else
        AC_MSG_RESULT(no)
+       AST_DECLARATION_AFTER_STATEMENT=
+fi
+AC_SUBST(AST_DECLARATION_AFTER_STATEMENT)
+
+
+AC_MSG_CHECKING(for sysinfo)
+AC_LINK_IFELSE(
+        AC_LANG_PROGRAM([#include <sys/sysinfo.h>],
+                        [struct sysinfo sys_info;]),
+        AC_MSG_RESULT(yes)
+        AC_DEFINE([HAVE_SYSINFO], 1, [Define to 1 if your system has sysinfo support]),
+        AC_MSG_RESULT(no)
 )
 
-AC_MSG_CHECKING(for RTLD_NOLOAD)
+AC_MSG_CHECKING(for res_ninit)
 AC_LINK_IFELSE(
-       AC_LANG_PROGRAM([#include <dlfcn.h>],
-                       [int foo = RTLD_NOLOAD;]),
+       AC_LANG_PROGRAM([#include <resolv.h>],
+                       [int foo = res_ninit(NULL);]),
        AC_MSG_RESULT(yes)
-       AC_DEFINE([HAVE_RTLD_NOLOAD], 1, [Define to 1 if your system has a dynamic linker that supports RTLD_NOLOAD.]),
+       AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.])
+       AC_MSG_CHECKING(for res_ndestroy)
+       AC_LINK_IFELSE(
+               AC_LANG_PROGRAM([#include <resolv.h>],
+                               [int foo = res_ndestroy(NULL);]),
+               AC_MSG_RESULT(yes)
+               AC_DEFINE([HAVE_RES_NDESTROY], 1, [Define to 1 if your system has the ndestroy resolver function.]),
+               AC_MSG_RESULT(no)
+       ),
        AC_MSG_RESULT(no)
 )
 
+AST_C_DEFINE_CHECK([RTLD_NOLOAD], [RTLD_NOLOAD], [dlfcn.h])
+
+AST_C_DEFINE_CHECK([IP_MTU_DISCOVER], [IP_MTU_DISCOVER], [netinet/in.h])
+
 AC_CHECK_HEADER([libkern/OSAtomic.h],
                 [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])
 
@@ -329,6 +378,20 @@ AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -l
 
 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
 
+if test "x${host_os}" = "xlinux-gnu" ; then
+  AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
+fi
+
+# BSD might not have exp2, and/or log2
+AST_EXT_LIB_CHECK([EXP2L], [m], [exp2l])
+AST_EXT_LIB_CHECK([LOG2L], [m], [log2l])
+AST_EXT_LIB_CHECK([EXP10L], [m], [exp10l])
+AST_EXT_LIB_CHECK([LOG10L], [m], [log10l])
+AST_EXT_LIB_CHECK([EXP2], [m], [exp2])
+AST_EXT_LIB_CHECK([LOG2], [m], [log2])
+AST_EXT_LIB_CHECK([EXP10], [m], [exp10])
+AST_EXT_LIB_CHECK([LOG10], [m], [log10])
+
 GSM_INTERNAL="yes"
 AC_SUBST(GSM_INTERNAL)
 GSM_SYSTEM="yes"
@@ -341,53 +404,101 @@ if test "${USE_GSM}" != "no"; then
    if test "${GSM_SYSTEM}" = "yes"; then
       gsmlibdir=""
       if test "x${GSM_DIR}" != "x"; then
-        if test -d ${GSM_DIR}/lib; then
-           gsmlibdir="-L${GSM_DIR}/lib"
-        else
-           gsmlibdir="-L${GSM_DIR}"
-        fi
+         if test -d ${GSM_DIR}/lib; then
+            gsmlibdir="-L${GSM_DIR}/lib"
+         else
+            gsmlibdir="-L${GSM_DIR}"
+         fi
       fi
       AC_CHECK_LIB([gsm], [gsm_create], AC_DEFINE_UNQUOTED([HAVE_GSM], 1,
       [Define to indicate the GSM library]), [], ${gsmlibdir})
       if test "${ac_cv_lib_gsm_gsm_create}" = "yes"; then
-        GSM_LIB="-lgsm"
-        if test "x${GSM_DIR}" != "x"; then
-           GSM_LIB="${gsmlibdir} ${GSM_LIB}"
-           GSM_INCLUDE="-I${GSM_DIR}/include"
-        fi
-        PBX_GSM=1
-        GSM_INTERNAL="no"
+         if test "x${GSM_DIR}" != "x" ; then
+            AC_CHECK_HEADER([${GSM_DIR}/include/gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
+            AC_CHECK_HEADER([${GSM_DIR}/include/gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
+         else
+            AC_CHECK_HEADER([gsm.h], [GSM_HEADER_FOUND=1], [GSM_HEADER_FOUND=0])
+            AC_CHECK_HEADER([gsm/gsm.h], [GSM_GSM_HEADER_FOUND=1], [GSM_GSM_HEADER_FOUND=0])
+         fi
+         if test "${GSM_HEADER_FOUND}" = "0" ; then
+            if test "{GSM_GSM_HEADER_FOUND}" = "0" ; then
+               if test "x${GSM_MANDATORY}" = "xyes" ; then
+                  AC_MSG_NOTICE([***])
+                  AC_MSG_NOTICE([*** It appears that you do not have the gsm development package installed.])
+                  AC_MSG_NOTICE([*** Please install it to include ${GSM_DESCRIP} support, or re-run configure])
+                  AC_MSG_NOTICE([*** without explicitly specifying --with-${GSM_OPTION}])
+                  exit 1
+               fi
+            fi
+         fi
+         GSM_OK=0
+         if test "${GSM_HEADER_FOUND}" = "1" ; then
+            AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
+            GSM_OK=1
+         else
+            if test "${GSM_GSM_HEADER_FOUND}" = "1" ; then
+               AC_DEFINE_UNQUOTED([HAVE_GSM_GSM_HEADER], 1, [Define to indicate that gsm.h is in gsm/gsm.h])
+               GSM_OK=1
+            fi
+         fi
+         if test "${GSM_OK}" = "1" ; then
+            GSM_LIB="-lgsm"
+            if test "x${GSM_DIR}" != "x"; then
+               GSM_LIB="${gsmlibdir} ${GSM_LIB}"
+               GSM_INCLUDE="-I${GSM_DIR}/include"
+            fi
+            PBX_GSM=1
+            GSM_INTERNAL="no"
+         fi
       fi
    fi
    if test "${GSM_INTERNAL}" = "yes"; then
       PBX_GSM=1
+      AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
    fi
 fi
 
 AST_EXT_LIB_CHECK([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])
 
 if test "${PBX_IKSEMEL}" = 1; then
-   AST_EXT_LIB_CHECK([GNUTLS], [gnutls], [gnutls_bye])
-   if test "${PBX_GNUTLS}" = 1; then
-      IKSEMEL_LIB="${IKSEMEL_LIB} -lgnutls -lz -lgcrypt -lnsl -lgpg-error"
-   fi
+   AST_EXT_LIB_CHECK([GNUTLS], [gnutls], [gnutls_bye], [gnutls/gnutls.h], [-lz -lgcrypt -lgpg-error])
 fi
 
 if test "${USE_IMAP_TK}" != "no"; then
-   if test "${IMAP_TK_DIR}" = ""; then
+   if test "${IMAP_TK_DIR}" = "system" ; then
+      AC_MSG_NOTICE([Checking for system c-client library...])
+   elif test "${IMAP_TK_DIR}" = ""; then
       IMAP_TK_DIR=`pwd`"/../imap-2004g"
+      if test  -n "${IMAP_TK_MANDATORY}"; then
+        AC_MSG_NOTICE([The --with-imap option does not search your system for installed])
+        AC_MSG_NOTICE([c-client library/header files. Since you did not provide a path])
+        AC_MSG_NOTICE([the configure script will assume you have placed built the c-client])
+        AC_MSG_NOTICE([files at ${IMAP_TK_DIR}, as outlined in the doc/imapstorage.txt file.])
+      fi
+   fi
+   if test "${IMAP_TK_DIR}" != "system" ; then
+      AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
    fi
-   AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
    saved_cppflags="${CPPFLAGS}"
    saved_libs="${LIBS}"
-   if test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
+   if test "${IMAP_TK_DIR}" = "system" ; then
+      imap_ldflags=""
+      imap_libs="-lc-client"
+      imap_include="-DUSE_SYSTEM_IMAP"
+   elif test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
       imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
+      imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
+      imap_include="-I${IMAP_TK_DIR}/c-client"
    fi
-   CPPFLAGS="${CPPFLAGS} -I${IMAP_TK_DIR}/c-client"
-   LIBS="${LIBS} ${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
+   CPPFLAGS="${CPPFLAGS} ${imap_include}"
+   LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
    AC_LINK_IFELSE(
        AC_LANG_PROGRAM(
-               [#include "c-client.h"
+               [#ifdef USE_SYSTEM_IMAP
+               #include <imap/c-client.h>
+               #else
+               #include "c-client.h"
+               #endif
                void mm_searched (MAILSTREAM *stream,unsigned long number)
                {
                }
@@ -443,7 +554,11 @@ if test "${USE_IMAP_TK}" != "no"; then
    if test "${ac_cv_imap_tk}" = "yes"; then
    AC_LINK_IFELSE(
       AC_LANG_PROGRAM(
-         [#include "c-client.h"
+         [#ifdef USE_SYSTEM_IMAP
+        #include <imap/c-client.h>
+        #else
+        #include "c-client.h"
+        #endif
          void mm_searched (MAILSTREAM *stream,unsigned long number)
          {
          }
@@ -501,25 +616,21 @@ if test "${USE_IMAP_TK}" != "no"; then
    LIBS="${saved_libs}"
    if test "${ac_cv_imap_tk}" = "yes"; then
       AC_MSG_RESULT(yes) 
-      IMAP_TK_LIB="${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
-      IMAP_TK_INCLUDE="-I${IMAP_TK_DIR}/c-client"
+      IMAP_TK_LIB="${imap_libs} "`echo ${imap_ldflags}`
+      IMAP_TK_INCLUDE="${imap_include}"
       PBX_IMAP_TK=1
       AC_DEFINE([HAVE_IMAP_TK], 1, [Define if your system has the UW IMAP Toolkit c-client library.])
       if test "${ac_cv_imap_tk2006}" = "yes"; then
          AC_DEFINE([HAVE_IMAP_TK2006], 1, [Define if your system has the UW IMAP Toolkit c-client library version 2006 or greater.])
       fi
-   elif test ! -z "${IMAP_TK_MANDATORY}"; then
-      AC_MSG_RESULT(no) 
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The UW IMAP Toolkit installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-imap.)
-      exit 1
    else
       AC_MSG_RESULT(no) 
    fi
 fi
 
+# Needed by unixodbc
+AST_EXT_LIB_CHECK([LTDL], [ltdl], [lt_dlinit], [ltdl.h], [])
+
 AC_LANG_PUSH(C++)
 
 if test "${USE_KDE}" != "no"; then
@@ -554,13 +665,6 @@ if test "${USE_KDE}" != "no"; then
       fi
       PBX_KDE=1
       AC_DEFINE([HAVE_LIBKDE], 1, [Define if your system has the KDE libraries.])
-   elif test ! -z "${KDE_MANDATORY}"; then
-      AC_MSG_RESULT(no) 
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The KDE installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-kde.)
-      exit 1
    else
       AC_MSG_RESULT(no) 
    fi
@@ -581,6 +685,7 @@ AST_EXT_LIB_CHECK([MISDN], [mISDN], [mISDN_open], [mISDNuser/mISDNlib.h])
 if test "${PBX_MISDN}" = 1; then
    AST_EXT_LIB_CHECK([ISDNNET], [isdnnet], [init_manager], [mISDNuser/isdn_net.h], [-lmISDN -lpthread])
    AST_EXT_LIB_CHECK([SUPPSERV], [suppserv], [encodeFac], [mISDNuser/suppserv.h])
+   AC_CHECK_HEADER([linux/mISDNdsp.h], [AC_DEFINE_UNQUOTED([MISDN_1_2], 1, [Build chan_misdn for mISDN 1.2 or later.])])
 fi
 
 AST_EXT_LIB_CHECK([NBS], [nbs], [nbs_connect], [nbs.h])
@@ -592,11 +697,11 @@ if test "${USE_NETSNMP}" != "no"; then
    if test "x${NETSNMP_DIR}" != "x"; then
       AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], No, [${NETSNMP_DIR}/bin])
       if test x"${NETSNMP_CONFIG}" = xNo; then
-         AC_MSG_NOTICE(***)
-         AC_MSG_NOTICE(*** net-snmp-config was not found in the path you specified:)
-         AC_MSG_NOTICE(*** ${NETSNMP_DIR}/bin)
-         AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-         AC_MSG_NOTICE(*** including --without-netsnmp)
+         AC_MSG_NOTICE([***])
+         AC_MSG_NOTICE([*** net-snmp-config was not found in the path you specified:])
+         AC_MSG_NOTICE([*** ${NETSNMP_DIR}/bin])
+         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
+         AC_MSG_NOTICE([*** including --without-netsnmp])
          exit 1
       fi
    else
@@ -604,7 +709,7 @@ if test "${USE_NETSNMP}" != "no"; then
    fi
 fi
 if test x"${NETSNMP_CONFIG}" != xNo; then
-   NETSNMP_libs=`net-snmp-config --agent-libs`
+   NETSNMP_libs=`${NETSNMP_CONFIG} --agent-libs`
    
    AC_CHECK_LIB([netsnmp], [snmp_register_callback], AC_DEFINE_UNQUOTED([HAVE_NETSNMP], 1,
    [Define to indicate the Net-SNMP library]), [], ${NETSNMP_libs})
@@ -612,58 +717,32 @@ if test x"${NETSNMP_CONFIG}" != xNo; then
    if test "${ac_cv_lib_netsnmp_snmp_register_callback}" = "yes"; then
       NETSNMP_LIB="${NETSNMP_libs}"
       PBX_NETSNMP=1
-   elif test ! -z "${NETSNMP_MANDATORY}";
-   then
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The Net-SNMP installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-netsnmp)
-      exit 1
    fi
-elif test ! -z "${NETSNMP_MANDATORY}";
-then
-   AC_MSG_NOTICE(***)
-   AC_MSG_NOTICE(*** The Net-SNMP installation on this system appears to be broken.)
-   AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-   AC_MSG_NOTICE(*** including --without-netsnmp)
-   exit 1
 fi
 
 AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])
 
-AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [-lltdl])
+AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [])
 
 AST_EXT_LIB_CHECK([OGG], [ogg], [ogg_sync_init], [])
 
-AST_EXT_LIB_CHECK([OSPTK], [osptk], [OSPPCryptoDecrypt], [osp/osp.h], [-lcrypto -lssl])
-
-PBX_OSS=0
-AC_CHECK_HEADER([linux/soundcard.h],
-               [
-               PBX_OSS=1
-                AC_DEFINE_UNQUOTED([HAVE_OSS], 1, [Define to indicate the Open Sound System library])
-               ])
-if test "$PBX_OSS" = "0"; then
-   AC_CHECK_HEADER([sys/soundcard.h],
-                   [
-                  PBX_OSS=1
-                  AC_DEFINE_UNQUOTED([HAVE_OSS], 1, [Define to indicate the Open Sound System library])
-                  ])
-fi
-if test "$PBX_OSS" = "0"; then
-   AST_EXT_LIB_CHECK([OSS], [ossaudio], [oss_ioctl_mixer], [soundcard.h])
-fi
+AST_EXT_LIB_CHECK([BKTR], [execinfo], [backtrace], [execinfo.h], [-lexecinfo])
+
+# possible places for oss definitions
+AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [linux/soundcard.h])
+AST_EXT_LIB_CHECK([OSS], [ossaudio], [], [sys/soundcard.h])
+AST_EXT_LIB_CHECK([OSS], [ossaudio], [oss_ioctl_mixer], [soundcard.h])
 
 PG_CONFIG=No
 if test "${USE_PGSQL}" != "no"; then   
    if test "x${PGSQL_DIR}" != "x"; then
       AC_PATH_TOOL([PG_CONFIG], [pg_config], No, [${PGSQL_DIR}/bin])
       if test x"${PG_CONFIG}" = xNo; then
-         AC_MSG_NOTICE(***)
-         AC_MSG_NOTICE(*** pg_config was not found in the path you specified:)
-         AC_MSG_NOTICE(*** ${PGSQL_DIR}/bin)
-         AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-         AC_MSG_NOTICE(*** including --without-postgres)
+         AC_MSG_NOTICE([***])
+         AC_MSG_NOTICE([*** pg_config was not found in the path you specified:])
+         AC_MSG_NOTICE([*** ${PGSQL_DIR}/bin])
+         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
+         AC_MSG_NOTICE([*** including --without-postgres])
          exit 1
       fi
    else
@@ -671,39 +750,43 @@ if test "${USE_PGSQL}" != "no"; then
    fi
 fi
 if test "${PG_CONFIG}" != No; then
-   PGSQL_libdir=`pg_config --libdir`
-   PGSQL_includedir=`pg_config --includedir`
-   
-   AC_CHECK_LIB([pq], [PQexec], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
-   [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)
-
-   if test "${ac_cv_lib_pq_PQexec}" = "yes"; then
-      PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz -lcrypt"
-      PGSQL_INCLUDE="-I${PGSQL_includedir}"
-      PBX_PGSQL=1
-   elif test ! -z "${PGSQL_MANDATORY}";
-   then
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The PostgreSQL installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-postgres)
-      exit 1
+   PGSQL_libdir=`${PG_CONFIG} --libdir`
+   PGSQL_includedir=`${PG_CONFIG} --includedir`
+   if test "x$?" != "x0" ; then
+      if test -n "${PGSQL_MANDATORY}" ; then
+         AC_MSG_NOTICE([***])
+         AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
+         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
+         AC_MSG_NOTICE([*** including --without-postgres])
+         exit 1
+         fi
+   else 
+      AC_CHECK_LIB([pq], [PQexec], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
+      [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)
+
+      if test "${ac_cv_lib_pq_PQexec}" = "yes"; then
+         PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz"
+         PGSQL_INCLUDE="-I${PGSQL_includedir}"
+         PBX_PGSQL=1
+      elif test -n "${PGSQL_MANDATORY}";
+      then
+         AC_MSG_NOTICE([***])
+         AC_MSG_NOTICE([*** The PostgreSQL installation on this system appears to be broken.])
+         AC_MSG_NOTICE([*** Either correct the installation, or run configure])
+         AC_MSG_NOTICE([*** including --without-postgres])
+         exit 1
+      fi
    fi
-elif test ! -z "${PGSQL_MANDATORY}";
-then
-   AC_MSG_NOTICE(***)
-   AC_MSG_NOTICE(*** The PostgreSQL installation on this system appears to be broken.)
-   AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-   AC_MSG_NOTICE(*** including --without-postgres)
-   exit 1
 fi
 
 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
 
-AST_EXT_LIB_CHECK([PRI], [pri], [pri_call], [libpri.h])
+AST_EXT_LIB_CHECK([PRI], [pri], [pri_keypad_facility], [libpri.h])
+
+AST_EXT_LIB_CHECK([SS7], [ss7], [ss7_new], [libss7.h])
 
 if test "${USE_PWLIB}" != "no"; then
-       if test ! -z "${PWLIB_DIR}"; then
+       if test -n "${PWLIB_DIR}"; then
                PWLIBDIR="${PWLIB_DIR}"
        fi
        AST_CHECK_PWLIB()
@@ -721,16 +804,8 @@ if test "${USE_PWLIB}" != "no"; then
        fi
 fi
 
-if test "${USE_PWLIB}" != "no" -a "x${ac_cv_lib_PWLIB}" != "xyes" -a ! -z "${PWLIB_MANDATORY}"; then
-   AC_MSG_NOTICE(***)
-   AC_MSG_NOTICE(*** The PWLIB installation on this system appears to be broken.)
-   AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-   AC_MSG_NOTICE(*** including --without-pwlib)
-   exit 1
-fi
-
 if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
-       if test ! -z "${OPENH323_DIR}"; then
+       if test -n "${OPENH323_DIR}"; then
                OPENH323DIR="${OPENH323_DIR}"
        fi
        AST_CHECK_OPENH323()
@@ -745,14 +820,6 @@ if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
                [H323EndPoint ep = H323EndPoint();],
                [${PWLIB_INCLUDE}], [${PWLIB_LIB}])
 fi
-if test "${USE_OPENH323}" != "no" -a "x${ac_cv_lib_OPENH323}" != "xyes" -a ! -z "${OPENH323_MANDATORY}"; then
-   AC_MSG_NOTICE(***)
-   AC_MSG_NOTICE(*** The PWLIB installation on this system appears to be broken.)
-   AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-   AC_MSG_NOTICE(*** including --without-pwlib)
-   exit 1
-fi
-
 
 AC_LANG_PUSH(C++)
 
@@ -813,13 +880,6 @@ if test "${USE_QT}" != "no"; then
       PBX_QT=1
       AC_DEFINE([HAVE_QT], 1, [Define if your system has the Qt library])
       AC_PATH_TOOL(QTMOC, moc, No)
-   elif test ! -z "${QT_MANDATORY}"; 
-   then
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The Qt installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-qt.)
-      exit 1
    fi
 fi
 
@@ -831,12 +891,27 @@ AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
 
 AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])
 
-AST_EXT_LIB_CHECK([OPENSSL], [ssl], [ssl2_connect], [openssl/ssl.h], [-lcrypto])
+AST_EXT_LIB_CHECK([SQLITE3], [sqlite3], [sqlite3_open], [sqlite3.h])
+
+AST_EXT_LIB_CHECK([CRYPTO], [crypto], [AES_encrypt], [openssl/aes.h])
+
+if test "$PBX_CRYPTO" = "1";
+then
+    AST_EXT_LIB_CHECK([OPENSSL], [ssl], [ssl2_connect], [openssl/ssl.h], [-lcrypto])
+fi
+
+if test "$PBX_OPENSSL" = "1";
+then
+    AST_EXT_LIB_CHECK([OSPTK], [osptk], [OSPPCryptoDecrypt], [osp/osp.h], [-lcrypto -lssl])
+fi
 
 AST_EXT_LIB_CHECK([FREETDS], [tds], [tds_version], [tds.h])
 if test "${PBX_FREETDS}" != "0";
 then
-    case `grep TDS_VERSION_NO ${FREETDS_DIR:-/usr/include}/tdsver.h` in
+    case `grep TDS_VERSION_NO ${FREETDS_DIR:-/usr}/include/tdsver.h` in
+       *0.64*)
+               FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_64"
+       ;;
     *0.63*)
         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_63"
        ;;
@@ -857,7 +932,10 @@ if test "${host_os}" != "linux-gnu" ; then
   tonezone_extra="-lm"
 fi
 
-AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/tonezone.h], [${tonezone_extra}])
+# new tonezone, version 1.4.0
+AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/tonezone.h], [${tonezone_extra}], [140])
+# other case, old tonezone (0.80)
+AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/zaptel.h], [${tonezone_extra}], [80])
 
 AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc])
 
@@ -900,12 +978,6 @@ if test "${USE_VPB}" != "no"; then
        fi
        PBX_VPB=1
        AC_DEFINE([HAVE_VPB], 1, [Define if your system has the VoiceTronix API libraries.])
-   elif test ! -z "${VPB_MANDATORY}"; then
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The VoiceTronix (vpb) installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-vpb.)
-      exit 1
    fi
 fi
 
@@ -913,41 +985,31 @@ AC_LANG_POP
 
 AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])
 
-if test "${USE_ZAPTEL}" != "no"; then
-   AC_MSG_CHECKING(for ZT_TONE_DTMF_BASE in zaptel.h)
-   saved_cppflags="${CPPFLAGS}"
-   if test "x${ZAPTEL_DIR}" != "x"; then
-      CPPFLAGS="${CPPFLAGS} -I${ZAPTEL_DIR}/include"
-   fi
-   AC_COMPILE_IFELSE(
-       [
-       AC_LANG_PROGRAM(
-       [#include <zaptel/zaptel.h>],
-       [int foo = ZT_TONE_DTMF_BASE;])
-       ],
-       [       AC_MSG_RESULT(yes) 
-               ac_cv_zaptel_h="yes" 
-       ],
-       [       AC_MSG_RESULT(no) 
-               ac_cv_zaptel_h="no" 
-       ]
-       )
-   CPPFLAGS="${saved_cppflags}"
-   if test "${ac_cv_zaptel_h}" = "yes"; then
-       if test "${ZAPTEL_DIR}" != ""; then
-          ZAPTEL_INCLUDE="-I${ZAPTEL_DIR}/include"
-       fi
-       PBX_ZAPTEL=1
-       AC_DEFINE([HAVE_ZAPTEL], 1, [Define if your system has the Zaptel headers.])
-   elif test ! -z "${ZAPTEL_MANDATORY}"; 
-   then
-      AC_MSG_NOTICE(***)
-      AC_MSG_NOTICE(*** The Zaptel installation on this system appears to be broken.)
-      AC_MSG_NOTICE(*** Either correct the installation, or run configure)
-      AC_MSG_NOTICE(*** including --without-zaptel.)
-      exit 1
-   fi
-fi
+# Check for various zaptel features and locations.
+# The version number, which goes into HAVE_ZAPTEL_VERSION,
+# will be used in the system headers to determine the location
+# of the zaptel.h header.
+
+AST_C_DEFINE_CHECK([ZAPTEL], [ZT_TONE_DTMF_BASE], [zaptel/zaptel.h], [140])
+AST_C_DEFINE_CHECK([ZAPTEL], [ZT_DIAL_OP_CANCEL], [zaptel/zaptel.h], [90])
+
+# Check for VLDTMF support
+AST_C_DEFINE_CHECK([ZAPTEL_VLDTMF], [ZT_EVENT_REMOVED], [zaptel/zaptel.h])
+
+# Check for transcode support
+AST_C_DEFINE_CHECK([ZAPTEL_TRANSCODE], [ZT_TCOP_ALLOCATE], [zaptel/zaptel.h])
+
+# On FreeBSD, try old zaptel (0.80 or so) and pretend we have vldtmf
+case "${host_os}" in
+    freebsd*)
+       AST_EXT_LIB_CHECK([ZAPTEL], [zaptel],, [zaptel.h],, [80])
+       AST_EXT_LIB_CHECK([ZAPTEL_VLDTMF], [zaptel],, [zaptel/zaptel.h],, [90])
+       AST_EXT_LIB_CHECK([ZAPTEL_VLDTMF], [zaptel],, [zaptel.h],, [80])
+
+       # other case, old tonezone (0.80)
+       AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel.h], [${tonezone_extra}], [80])
+       ;;
+esac
 
 EDITLINE_LIB=""
 if test "x$TERMCAP_LIB" != "x" ; then
@@ -986,31 +1048,53 @@ AC_SUBST(PBX_GTK)
 AC_SUBST(GTK_INCLUDE)
 AC_SUBST(GTK_LIB)
 
-PBX_CURL=0
-AC_PATH_TOOL([CURL], [curl-config], No)
-if test ! x"${CURL}" = xNo; then
-# check for version
-   if test "${host_os}" = "SunOS"; then
-      if [[ 0x`curl-config --vernum` -ge 0x70907 ]]; then
-         CURL_INCLUDE=$(${CURL} --cflags)
-         CURL_LIB=$(${CURL} --libs)
-         PBX_CURL=1
-         AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
-      fi
-   else
-      if [[[ 0x`curl-config --vernum` -ge 0x70907 ]]]; then
-         CURL_INCLUDE=$(${CURL} --cflags)
-         CURL_LIB=$(${CURL} --libs)
-         PBX_CURL=1
-         AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
+PBX_GTK2=0
+AC_CHECK_TOOL(PKGCONFIG, pkg-config, No)
+if test ! "x${PKGCONFIG}" = xNo; then
+   GTK2_INCLUDE=$(${PKGCONFIG} gtk+-2.0 --cflags 2>/dev/null)
+   GTK2_LIB=$(${PKGCONFIG} gtk+-2.0 --libs)
+   PBX_GTK2=1
+   AC_DEFINE([HAVE_GTK2], 1, [Define if your system has the GTK2 libraries.])
+fi
+AC_SUBST(PBX_GTK2)
+AC_SUBST(GTK2_INCLUDE)
+AC_SUBST(GTK2_LIB)
+
+if test "${USE_CURL}" != "no"; then
+   AC_PATH_TOOL([CURL_CONFIG], [curl-config], No)
+   if test ! x"${CURL_CONFIG}" = xNo; then
+   # check for version
+      if test $(printf "%d" 0x$(${CURL_CONFIG} --vernum)) -ge $(printf "%d" 0x070907); then
+         CURL_INCLUDE=$(${CURL_CONFIG} --cflags)
+         CURL_LIB=$(${CURL_CONFIG} --libs)
+
+         AC_MSG_CHECKING(for curl_version() in curl/curl.h)
+         saved_cppflags="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${CURL_INCLUDE}"
+         AC_COMPILE_IFELSE(
+            [AC_LANG_PROGRAM(
+                [#include <curl/curl.h>],
+                    [curl_version();])
+            ],[
+                AC_MSG_RESULT(yes)
+                ac_cv_curl_h="yes"
+            ],[
+                AC_MSG_RESULT(no)
+                ac_cv_curl_h="no"
+            ]
+        )
+        CPPFLAGS="${saved_cppflags}"
+         if test "${ac_cv_curl_h}" = "yes"; then
+             PBX_CURL=1
+             AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
+         fi
       fi
    fi
 fi
-AC_SUBST(PBX_CURL)
-AC_SUBST(CURL_INCLUDE)
-AC_SUBST(CURL_LIB)
 
 AC_CONFIG_FILES([build_tools/menuselect-deps makeopts channels/h323/Makefile])
+AST_CHECK_MANDATORY
+
 AC_OUTPUT
 
 if test "x${silent}" != "xyes" ; then