Disable strict XML documentation config checking; fix crash caused by sorcery
[asterisk/asterisk.git] / configure.ac
index 5734b39..477e981 100644 (file)
@@ -37,32 +37,87 @@ AC_SUBST(CONFIG_LDFLAGS)
 # specify output header file
 AC_CONFIG_HEADER(include/asterisk/autoconfig.h)
 
-AC_USE_SYSTEM_EXTENSIONS       # note- does not work on FreeBSD
+# Note: AC_PROG_CC *must* be specified before AC_USE_SYSTEM_EXTENSIONS or any
+# other macro that uses the C compiler, or the default order will be used.
+AC_PROG_CC([gcc cc])
+
+AC_USE_SYSTEM_EXTENSIONS       dnl note- does not work on FreeBSD
+
+# System default paths
+AC_SUBST([astsbindir],        ['${sbindir}'])dnl
+AC_SUBST([astetcdir],         ['${sysconfdir}/asterisk'])dnl
+AC_SUBST([astheaderdir],      ['${includedir}/asterisk'])dnl
+AC_SUBST([astlibdir],         ['${libdir}'])dnl
+AC_SUBST([astmoddir],         ['${libdir}/asterisk/modules'])dnl
+AC_SUBST([astmandir],         ['${mandir}'])dnl
+AC_SUBST([astvarlibdir],      ['${localstatedir}/lib/asterisk'])dnl
+AC_SUBST([astdatadir],        ['${astvarlibdir}'])dnl
+AC_SUBST([astdbdir],          ['${astvarlibdir}'])dnl
+AC_SUBST([astkeydir],         ['${astvarlibdir}'])dnl
+AC_SUBST([astspooldir],       ['${localstatedir}/spool/asterisk'])dnl
+AC_SUBST([astlogdir],         ['${localstatedir}/log/asterisk'])dnl
+AC_SUBST([astvarrundir],      ['${localstatedir}/run/asterisk'])dnl
+
+case "${host_os}" in
+     *bsd*)
+     if test ${prefix} = 'NONE'; then
+        astvarlibdir='${prefix}/share/asterisk'
+        astdbdir='${localstatedir}/db/asterisk'
+     fi
+     ;;
+     darwin*)
+     if test ${prefix} = 'NONE'; then
+        astvarrundir='/Library/Application Support/Asterisk/Run'
+     fi
+     ;;
+esac
 
 case "${host_os}" in
      freebsd*)
-     AC_PREFIX_DEFAULT([/usr/local])
+     ac_default_prefix=/usr/local
      CPPFLAGS=-I/usr/local/include
      LDFLAGS=-L/usr/local/lib
      ;;
      openbsd*)
-     AC_PREFIX_DEFAULT([/usr/local])
+     ac_default_prefix=/usr/local
      if test ${prefix} = '/usr/local' || test ${prefix} = 'NONE'; then
         if test ${sysconfdir} = '${prefix}/etc'; then
-           sysconfdir=/etc
+           astetcdir=/etc/asterisk
         fi
         if test ${mandir} = '${prefix}/man'; then
-           mandir=/usr/share/man
+           astmandir=/usr/share/man
         fi
      fi
      CPPFLAGS=-I/usr/local/include
      LDFLAGS=-L/usr/local/lib
      ;;
      darwin*)
+     ac_default_prefix=/usr/local
+     if test ${prefix} = 'NONE'; then
+        astmoddir='/Library/Application Support/Asterisk/Modules'
+        astvarlibdir='/Library/Application Support/Asterisk'
+        astlogdir=/Library/Logs/Asterisk
+        astvarrundir='/Library/Application Support/Asterisk/Run'
+     fi
      AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be used.])
+     AC_DEFINE([_DARWIN_UNLIMITED_SELECT], 1, [Define to 1 if running on Darwin.])
+     ;;
+     solaris*)
+     if test ${prefix} = 'NONE'; then
+        astetcdir=/var/etc/asterisk
+        astsbindir=/opt/asterisk/sbin
+        astlibdir=/opt/asterisk/lib
+        astmoddir=/opt/asterisk/lib/modules
+        astheaderdir=/opt/asterisk/include
+        astmandir=/opt/asterisk/man
+        astvarlibdir=/var/opt/asterisk
+        astspooldir=/var/spool/asterisk
+        astlogdir=/var/log/asterisk
+        astvarrundir=/var/run/asterisk
+     fi
      ;;
      *)
-     AC_PREFIX_DEFAULT([/usr])
+     ac_default_prefix=/usr
      if test ${prefix} = '/usr' || test ${prefix} = 'NONE'; then
         if test ${sysconfdir} = '${prefix}/etc'; then
            sysconfdir=/etc
@@ -123,9 +178,12 @@ case "${host_os}" in
      OSARCH=cygwin
      PBX_WINARCH=1
      ;;
-     linux-gnueabi)
+     linux-gnueabi*)
      OSARCH=linux-gnu
      ;;
+     kfreebsd*-gnu)
+     OSARCH=kfreebsd-gnu
+     ;;
      *)
      OSARCH=${host_os}
      ;;
@@ -154,7 +212,7 @@ AH_BOTTOM(
 )
 
 # cross-compile checks
-if test "${cross_compiling}" = "yes"; 
+if test "${cross_compiling}" = "yes";
 then
    AC_CHECK_TOOL(CC, gcc, :)
    AC_CHECK_TOOL(CXX, g++, :)
@@ -163,7 +221,6 @@ then
 fi
 
 # Checks for programs.
-AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_CPP
 AC_PROG_CXXCPP
@@ -175,11 +232,10 @@ AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_RANLIB
 AST_CHECK_GNU_MAKE
+AC_PROG_EGREP
 
 AC_CHECK_TOOLS([STRIP], [strip gstrip], :)
 AC_CHECK_TOOLS([AR], [ar gar], :)
-AC_CHECK_TOOLS([SHA1SUM], [sha1sum], $ac_aux_dir/build_tools/sha1sum-sh)
-AC_CHECK_TOOLS([OPENSSL], [openssl], :)
 
 GNU_LD=0
 if test "x$with_gnu_ld" = "xyes" ; then
@@ -188,21 +244,26 @@ fi
 AC_SUBST(GNU_LD)
 
 AC_PATH_PROG([BISON], [bison], :)
+AC_PATH_PROG([CMP], [cmp], :)
 AC_PATH_PROG([FLEX], [flex], :)
 AC_PATH_PROG([GREP], [grep], :)
+AC_PATH_PROG([PYTHON], [python], :)
 AC_PATH_PROG([FIND], [find], :)
 AC_PATH_PROG([COMPRESS], [compress], :)
 AC_PATH_PROG([BASENAME], [basename], :)
 AC_PATH_PROG([DIRNAME], [dirname], :)
 AC_PATH_PROG([SHELL], [sh], :)
 AC_PATH_PROG([LN], [ln], :)
+AC_PATH_PROG([DOXYGEN], [doxygen], :)
 AC_PATH_PROG([DOT], [dot], :)
 AC_PATH_PROG([WGET], [wget], :)
 AC_PATH_PROG([CURL], [curl], :)
 AC_PATH_PROG([RUBBER], [rubber], :)
 AC_PATH_PROG([CATDVI], [catdvi], :)
 AC_PATH_PROG([KPATHSEA], [kpsewhich], :)
+AC_PATH_PROG([XMLLINT], [xmllint], :)
 AC_PATH_PROG([XMLSTARLET], [xmlstarlet], :)
+AC_PATH_PROG([GIT], [git], :)
 if test "${WGET}" != ":" ; then
   DOWNLOAD=${WGET}
 else if test "${CURL}" != ":" ; then
@@ -213,6 +274,9 @@ else
 fi
 fi
 AC_SUBST(DOWNLOAD)
+AC_PATH_PROG([LDCONFIG], [ldconfig], :)
+AC_PATH_PROG([SHA1SUM], [sha1sum], $ac_aux_dir/build_tools/sha1sum-sh)
+AC_PATH_PROG([OPENSSL], [openssl], :)
 
 AC_CACHE_CHECK([for bison that supports parse-param], [ac_cv_path_BISON2], [
        if test "x$BISON" != "x:" ; then
@@ -265,7 +329,7 @@ fi
 AC_CHECK_PROGS([MD5], [md5 md5sum gmd5sum digest])
 
 if test "${MD5}" = "digest" ; then
-   MD5="${MD5} -a md5"   
+   MD5="${MD5} -a md5"
 fi
 
 ACX_PTHREAD
@@ -282,10 +346,26 @@ AC_ARG_ENABLE([dev-mode],
              AST_DEVMODE=yes
              NOISY_BUILD=yes
              ;;
+             strict)
+             AST_DEVMODE=yes
+             AST_DEVMODE_STRICT=yes
+             ;;
              *) AC_MSG_ERROR(bad value ${enableval} for --enable-dev-mode)  ;;
        esac])
 AC_SUBST(NOISY_BUILD)
 AC_SUBST(AST_DEVMODE)
+AC_SUBST(AST_DEVMODE_STRICT)
+
+AST_CODE_COVERAGE=no
+AC_ARG_ENABLE([coverage],
+       [AS_HELP_STRING([--enable-coverage],
+               [Turn on code coverage tracking (for gcov)])],
+       [case "${enableval}" in
+             y|ye|yes) AST_CODE_COVERAGE=yes ;;
+             n|no) AST_CODE_COVERAGE=no ;;
+             *) AC_MSG_ERROR(bad value ${enableval} for --enable-coverage)  ;;
+       esac])
+AC_SUBST(AST_CODE_COVERAGE)
 
 # AST_EXT_LIB_SETUP is used to tell configure to handle variables for
 # various packages.
@@ -298,17 +378,22 @@ AC_SUBST(AST_DEVMODE)
 # to make things easier for the users.
 
 AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
-AST_EXT_LIB_SETUP([FFMPEG], [Ffmpeg and avcodec], [avcodec])
+AST_EXT_LIB_SETUP([BFD], [Debug symbol decoding], [bfd])
+
+# BKTR is used for backtrace support on platforms that do not
+# have it natively.
+AST_EXT_LIB_SETUP([BKTR], [Stack Backtrace], [execinfo])
 AST_EXT_LIB_SETUP([BLUETOOTH], [Bluetooth], [bluetooth])
 AST_EXT_LIB_SETUP([CAP], [POSIX 1.e capabilities], [cap])
+AST_EXT_LIB_SETUP([COROSYNC], [Corosync], [cpg])
+AST_EXT_LIB_SETUP_OPTIONAL([COROSYNC_CFG_STATE_TRACK], [A callback only in corosync 1.x], [COROSYNC], [cfg])
 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
 AST_EXT_LIB_SETUP([CRYPTO], [OpenSSL Cryptography], [crypto])
+AST_EXT_LIB_SETUP_OPTIONAL([OPENSSL_SRTP], [OpenSSL SRTP Extension Support], [CRYPTO], [crypto])
 AST_EXT_LIB_SETUP([DAHDI], [DAHDI], [dahdi])
-
-# BKTR is used for backtrace support on platforms that do not
-# have it natively.
-AST_EXT_LIB_SETUP([BKTR], [Stack Backtrace], [execinfo])
+AST_EXT_LIB_SETUP([FFMPEG], [Ffmpeg and avcodec], [avcodec])
 AST_EXT_LIB_SETUP([GSM], [External GSM], [gsm], [, use 'internal' GSM otherwise])
+AST_EXT_LIB_SETUP([ILBC], [System iLBC], [ilbc], [, use 'internal' iLBC otherwise])
 AST_EXT_LIB_SETUP([GTK2], [gtk2], [gtk2])
 AST_EXT_LIB_SETUP([GMIME], [GMime], [gmime])
 AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
@@ -321,9 +406,11 @@ AST_EXT_LIB_SETUP([INOTIFY], [inotify support], [inotify])
 AST_EXT_LIB_SETUP([IODBC], [iODBC], [iodbc])
 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux], [isdnnet])
 AST_EXT_LIB_SETUP([JACK], [Jack Audio Connection Kit], [jack])
+AST_EXT_LIB_SETUP([JANSSON], [Jansson JSON library], [jansson])
 AST_EXT_LIB_SETUP([KQUEUE], [kqueue support], [kqueue])
 AST_EXT_LIB_SETUP([LDAP], [OpenLDAP], [ldap])
 AST_LIBCURL_CHECK_CONFIG([], [7.10.1])
+AST_EXT_LIB_SETUP([LIBEDIT], [NetBSD Editline library], [libedit], [, use 'internal' Editline otherwise])
 AST_EXT_LIB_SETUP([LIBXML2], [LibXML2], [libxml2])
 AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
 AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
@@ -336,7 +423,6 @@ AST_EXT_LIB_SETUP([NEON29], [neon29], [neon29])
 AST_EXT_LIB_SETUP([NETSNMP], [Net-SNMP], [netsnmp])
 AST_EXT_LIB_SETUP([NEWT], [newt], [newt])
 AST_EXT_LIB_SETUP([OGG], [OGG], [ogg])
-AST_EXT_LIB_SETUP([OPENAIS], [OpenAIS], [openais])
 AST_EXT_LIB_SETUP([OPENR2], [MFR2], [openr2])
 AST_EXT_LIB_SETUP([OSPTK], [OSP Toolkit], [osptk])
 AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
@@ -344,31 +430,35 @@ AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_MWI], [ISDN PRI Message Waiting Indication], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_MCID], [ISDN PRI Malicious Call ID], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_WAITING], [ISDN PRI call waiting supplementary service], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_AOC_EVENTS], [ISDN PRI advice of charge supplementary service events], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_TRANSFER], [ISDN PRI call transfer supplementary service], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_CCSS], [ISDN PRI call completion supplementary service], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_HANGUP_FIX], [ISDN PRI hangup fix], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_SUBADDR], [ISDN PRI subaddressing], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_HOLD], [ISDN PRI call hold], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_REROUTING], [ISDN PRI call rerouting and call deflection], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_SETUP_KEYPAD], [ISDN PRI keypad facility in SETUP], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_L2_PERSISTENCE], [ISDN Layer 2 persistence option], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_DATETIME_SEND], [ISDN PRI Date/time ie send policy], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_MWI_V2], [ISDN PRI Message Waiting Indication (Fixed)], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_DISPLAY_TEXT], [ISDN PRI user display text IE contents during call], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_MWI], [ISDN PRI Message Waiting Indication], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_MCID], [ISDN PRI Malicious Call ID], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_CALL_WAITING], [ISDN PRI call waiting supplementary service], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_AOC_EVENTS], [ISDN PRI advice of charge supplementary service events], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_TRANSFER], [ISDN PRI call transfer supplementary service], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_CCSS], [ISDN PRI call completion supplementary service], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_HANGUP_FIX], [ISDN PRI hangup fix], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_SUBADDR], [ISDN PRI subaddressing], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_CALL_HOLD], [ISDN PRI call hold], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_CALL_REROUTING], [ISDN PRI call rerouting and call deflection], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_SETUP_KEYPAD], [ISDN PRI keypad facility in SETUP], [PRI], [pri])
 # ------------------------------------v
 # TODO: The code can be changed to always include these features now.
 # These features will always be present if pri_connected_line_update is available.
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_INBANDDISCONNECT], [ISDN PRI set_inbanddisconnect], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_PROG_W_CAUSE], [ISDN progress with cause], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_SERVICE_MESSAGES], [ISDN service messages], [PRI], [pri])
-AST_EXT_LIB_SETUP_DEPENDENT([PRI_REVERSE_CHARGE], [ISDN reverse charge], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_INBANDDISCONNECT], [ISDN PRI set_inbanddisconnect], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_PROG_W_CAUSE], [ISDN progress with cause], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_SERVICE_MESSAGES], [ISDN service messages], [PRI], [pri])
+AST_EXT_LIB_SETUP_OPTIONAL([PRI_REVERSE_CHARGE], [ISDN reverse charge], [PRI], [pri])
 # ------------------------------------^
 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
 AST_EXT_LIB_SETUP([RESAMPLE], [LIBRESAMPLE], [resample])
 AST_EXT_LIB_SETUP([SDL], [Sdl], [sdl])
 AST_EXT_LIB_SETUP([SDL_IMAGE], [Sdl Image], [SDL_image])
-AST_OPTION_ONLY([sounds-cache], [SOUNDS_CACHE_DIR], [cached sound tarfiles], [${HOME}/.asterisk_sounds_cache])
+AST_OPTION_ONLY([sounds-cache], [SOUNDS_CACHE_DIR], [cached sound tarfiles], [])
 AST_EXT_LIB_SETUP([SPANDSP], [SPANDSP], [spandsp])
 AST_EXT_LIB_SETUP([SS7], [ISDN SS7], [ss7])
 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
@@ -386,7 +476,6 @@ AST_EXT_LIB_SETUP([TIMERFD], [timerfd], [timerfd])
 AST_EXT_LIB_SETUP([TINFO], [Term Info], [tinfo])
 AST_EXT_LIB_SETUP([TONEZONE], [tonezone], [tonezone])
 AST_EXT_LIB_SETUP([UNIXODBC], [unixODBC], [unixodbc])
-AST_EXT_LIB_SETUP([USB], [usb], [usb])
 AST_EXT_LIB_SETUP([VORBIS], [Vorbis], [vorbis])
 AST_EXT_LIB_SETUP([VPB], [Voicetronix API], [vpb])
 AST_EXT_LIB_SETUP([X11], [X11], [x11])
@@ -401,6 +490,57 @@ AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 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/event.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])
 
+# Any one of these 5 packages support a mandatory requirement, so we want to check on them as early as possible.
+AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
+AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])
+AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
+AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
+AST_EXT_LIB_CHECK([UUID], [uuid], [uuid_generate_random], [uuid/uuid.h], [-luuid])
+
+EDITLINE_LIB=""
+if test "x$TERMCAP_LIB" != "x" ; then
+  EDITLINE_LIB="$TERMCAP_LIB"
+elif test "x$TINFO_LIB" != "x" ; then
+  EDITLINE_LIB="$TINFO_LIB"
+elif test "x$CURSES_LIB" != "x" ; then
+  EDITLINE_LIB="$CURSES_LIB"
+elif test "x$NCURSES_LIB" != "x" ; then
+  EDITLINE_LIB="$NCURSES_LIB"
+else
+  AC_MSG_ERROR([*** termcap support not found (on modern systems, this typically means the ncurses development package is missing)])
+fi
+AC_SUBST(EDITLINE_LIB)
+
+if test "x$UUID_LIB" == "x"; then
+  AC_MSG_ERROR([*** uuid support not found (this typically means the uuid development package is missing)])
+fi
+
+# Another mandatory item (unless it's explicitly disabled)
+AC_ARG_ENABLE([xmldoc],
+       [AS_HELP_STRING([--disable-xmldoc],
+               [Explicitly disable XML documentation])],
+       [case "${enableval}" in
+               y|ye|yes) disable_xmldoc=no ;;
+               n|no)  disable_xmldoc=yes ;;
+               *) AC_MSG_ERROR(bad value ${enableval} for --disable-xmldoc)  ;;
+       esac], [disable_xmldoc=no])
+
+if test "${disable_xmldoc}" != "yes"; then
+       AST_EXT_TOOL_CHECK([LIBXML2], [xml2-config], , ,
+       [#include <libxml/tree.h>
+       #include <libxml/parser.h>],
+       [LIBXML_TEST_VERSION])
+       if test "${PBX_LIBXML2}" != 1; then
+               AC_MSG_NOTICE(*** XML documentation will not be available because the 'libxml2' development package is missing.)
+               AC_MSG_NOTICE(*** Please run the 'configure' script with the '--disable-xmldoc' parameter option)
+               AC_MSG_NOTICE(*** or install the 'libxml2' development package.)
+               exit 1
+       fi
+fi
+
+# some embedded systems omit internationalization (locale) support
+AC_CHECK_HEADERS([xlocale.h])
+
 AC_CHECK_HEADERS([winsock.h winsock2.h])
 
 AC_CHECK_HEADER([sys/poll.h],
@@ -420,6 +560,9 @@ AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
 AC_CHECK_MEMBERS([struct stat.st_blksize])
+AC_CHECK_MEMBERS([struct ucred.uid, struct ucred.cr_uid, struct sockpeercred.uid], [], [], [#include <sys/types.h>
+#include <sys/socket.h> ])
+AC_CHECK_MEMBERS([struct ifreq.ifr_ifru.ifru_hwaddr], [], [], [#include <net/if.h>])
 AC_HEADER_TIME
 AC_STRUCT_TM
 AC_C_VOLATILE
@@ -448,13 +591,13 @@ AC_FUNC_STRNLEN
 AC_FUNC_STRTOD
 AC_FUNC_UTIME_NULL
 AC_FUNC_VPRINTF
-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 newlocale 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])
+AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob htonll ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap ntohll newlocale ppoll 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])
 
 # NOTE: we use AC_CHECK_LIB to get -lm into the arguments for later checks,
 # so that AC_CHECK_FUNCS can detect functions in that library.
 AC_CHECK_LIB([m], [sqrt])
 # BSD might not have exp2, and/or log2
-AC_CHECK_FUNCS([exp2 log2 exp10 log10 sin cos tan asin acos atan atan2 pow rint exp log remainder fmod round trunc floor ceil])
+AC_CHECK_FUNCS([exp2 log2 exp10 log10 sin cos tan asin acos atan atan2 pow rint exp log remainder fmod round roundf trunc floor ceil])
 
 # Certain architectures don't really have long double, even though
 # AC_CHECK_FUNCS would otherwise find the following functions.
@@ -462,16 +605,44 @@ if test "x${ac_cv_type_long_double_wider}" = "xyes" ; then
        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])
 fi
 
+AC_MSG_CHECKING(for LLONG_MAX in limits.h)
+AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM([#include <limits.h>],
+               [long long foo = LLONG_MAX])],
+       AC_MSG_RESULT(yes)
+       AC_DEFINE([HAVE_LLONG_MAX], 1, [Define to 1 if limits.h includes a LLONG_MAX definition.]),
+       AC_MSG_RESULT(no)
+)
+
 AC_MSG_CHECKING(for timersub in time.h)
 AC_LINK_IFELSE(
-       AC_LANG_PROGRAM([#include <sys/time.h>],
-               [struct timeval *a; timersub(a, a, a);]),
+       [AC_LANG_PROGRAM([#include <sys/time.h>],
+               [struct timeval *a; timersub(a, a, a);])],
        AC_MSG_RESULT(yes)
                AC_DEFINE([HAVE_TIMERSUB], 1, [Define to 1 if your system defines timersub.]),
        AC_MSG_RESULT(no)
 )
 
-AC_CHECK_HEADER([sys/poll.h], 
+AC_MSG_CHECKING(for a version of GNU ld that supports the --dynamic-list flag)
+old_LDFLAGS=${LDFLAGS}
+cat >conftest.dynamics <<_ACEOF
+{
+       *ast_*;
+};
+_ACEOF
+LDFLAGS="${LDFLAGS} -Wl,--dynamic-list,conftest.dynamics"
+PBX_DYNAMIC_LIST=0
+AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM([], [])],
+       PBX_DYNAMIC_LIST=1
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no)
+)
+AC_SUBST(PBX_DYNAMIC_LIST)
+LDFLAGS=${old_LDFLAGS}
+rm -f conftest.dynamics
+
+AC_CHECK_HEADER([sys/poll.h],
    [HAS_POLL=1]
    AC_DEFINE([HAVE_SYS_POLL_H], 1, [Define to 1 if your system has working sys/poll.h]),
    )
@@ -486,7 +657,15 @@ AC_ARG_ENABLE([internal-poll],
        esac])
 AC_SUBST(HAS_POLL)
 
-
+AC_ARG_ENABLE([asteriskssl],
+       [AS_HELP_STRING([--disable-asteriskssl],
+               [Disable Asterisk's SSL wrapper library])],
+       [case "${enableval}" in
+               y|ye|yes) AST_ASTERISKSSL=yes ;;
+               n|no)  AST_ASTERISKSSL=no ;;
+               *) AC_MSG_ERROR(bad value ${enableval} for --disable-asteriskssl)  ;;
+       esac], [AST_ASTERISKSSL=yes])
+AC_SUBST(AST_ASTERISKSSL)
 
 # https support (in main/http.c) uses funopen on BSD systems,
 # fopencookie on linux
@@ -497,8 +676,8 @@ AC_CHECK_FUNCS([inet_aton])
 # check if we have IP_PKTINFO constant defined
 AC_MSG_CHECKING(for IP_PKTINFO)
 AC_LINK_IFELSE(
-               AC_LANG_PROGRAM([#include <netinet/in.h>],
-                                               [int pi = IP_PKTINFO;]),
+               [AC_LANG_PROGRAM([#include <netinet/in.h>],
+                                               [int pi = IP_PKTINFO;])],
                AC_MSG_RESULT(yes)
                AC_DEFINE([HAVE_PKTINFO], 1, [Define to 1 if your system defines IP_PKTINFO.]),
                AC_MSG_RESULT(no)
@@ -509,9 +688,9 @@ AC_SEARCH_LIBS(gethostbyname_r, [socket nsl])
 
 AC_MSG_CHECKING(for gethostbyname_r with 6 arguments)
 AC_LINK_IFELSE(
-        AC_LANG_PROGRAM([#include <stdlib.h>
+        [AC_LANG_PROGRAM([#include <stdlib.h>
                          #include <netdb.h>],
-                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);]),
+                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (struct hostent **)NULL, (int *)NULL);])],
         AC_MSG_RESULT(yes)
         AC_DEFINE([HAVE_GETHOSTBYNAME_R_6], 1, [Define to 1 if your system has gethostbyname_r with 6 arguments.]),
         AC_MSG_RESULT(no)
@@ -519,9 +698,9 @@ AC_LINK_IFELSE(
 
 AC_MSG_CHECKING(for gethostbyname_r with 5 arguments)
 AC_LINK_IFELSE(
-        AC_LANG_PROGRAM([#include <stdlib.h>
+        [AC_LANG_PROGRAM([#include <stdlib.h>
                         #include <netdb.h>],
-                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);]),
+                        [struct hostent *he = gethostbyname_r((const char *)NULL, (struct hostent *)NULL, (char *)NULL, (int)0, (int *)NULL);])],
         AC_MSG_RESULT(yes)
         AC_DEFINE([HAVE_GETHOSTBYNAME_R_5], 1, [Define to 1 if your system has gethostbyname_r with 5 arguments.]),
         AC_MSG_RESULT(no)
@@ -531,7 +710,7 @@ AC_CHECK_HEADER([byteswap.h], [AC_DEFINE_UNQUOTED([HAVE_BYTESWAP_H], 1, [Define
 
 AC_MSG_CHECKING(for __swap16 variant of <sys/endian.h> byteswapping macros)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = __swap16(a);]),
+[AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = __swap16(a);])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_SYS_ENDIAN_SWAP16], 1, [Define to 1 if your sys/endian.h header file provides the __swap16 macro.]),
 AC_MSG_RESULT(no)
@@ -539,26 +718,21 @@ AC_MSG_RESULT(no)
 
 AC_MSG_CHECKING(for bswap16 variant of <sys/endian.h> byteswapping macros)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = bswap16(a);]),
+[AC_LANG_PROGRAM([#include <sys/endian.h>], [int a = 1; int b = bswap16(a);])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_SYS_ENDIAN_BSWAP16], 1, [Define to 1 if your sys/endian.h header file provides the bswap16 macro.]),
 AC_MSG_RESULT(no)
 )
 
-if test "${cross_compiling}" = "no";
-then
-  AC_CHECK_FILE(/dev/urandom, AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define to 1 if your system has /dev/urandom.]))
-fi
-
 AC_MSG_CHECKING(for locale_t in locale.h)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <locale.h>], [locale_t lt = NULL]),
+[AC_LANG_PROGRAM([#include <locale.h>], [locale_t lt = NULL])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_LOCALE_T_IN_LOCALE_H], 1, [Define to 1 if your system defines the locale_t type in locale.h]),
 AC_MSG_RESULT(no)
   AC_MSG_CHECKING(for locale_t in xlocale.h)
   AC_LINK_IFELSE(
-  AC_LANG_PROGRAM([#include <xlocale.h>], [locale_t lt = NULL]),
+  [AC_LANG_PROGRAM([#include <xlocale.h>], [locale_t lt = NULL])],
   AC_MSG_RESULT(yes)
   AC_DEFINE([HAVE_LOCALE_T_IN_XLOCALE_H], 1, [Define to 1 if your system defines the locale_t type in xlocale.h]),
   AC_MSG_RESULT(no)
@@ -567,7 +741,7 @@ AC_MSG_RESULT(no)
 
 AC_MSG_CHECKING(for O_EVTONLY in fcntl.h)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <fcntl.h>], [int a = O_EVTONLY;]),
+[AC_LANG_PROGRAM([#include <fcntl.h>], [int a = O_EVTONLY;])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_O_EVTONLY], 1, [Define to 1 if your system defines the file flag O_EVTONLY in fcntl.h]),
 AC_MSG_RESULT(no)
@@ -575,7 +749,7 @@ AC_MSG_RESULT(no)
 
 AC_MSG_CHECKING(for O_SYMLINK in fcntl.h)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <fcntl.h>], [int a = O_SYMLINK;]),
+[AC_LANG_PROGRAM([#include <fcntl.h>], [int a = O_SYMLINK;])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_O_SYMLINK], 1, [Define to 1 if your system defines the file flag O_SYMLINK in fcntl.h]),
 AC_MSG_RESULT(no)
@@ -585,7 +759,7 @@ AST_C_DEFINE_CHECK([PTHREAD_RWLOCK_INITIALIZER], [PTHREAD_RWLOCK_INITIALIZER], [
 
 AC_MSG_CHECKING(for PTHREAD_RWLOCK_PREFER_WRITER_NP in pthread.h)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_RWLOCK_PREFER_WRITER_NP;]),
+[AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_RWLOCK_PREFER_WRITER_NP;])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP], 1, [Define to 1 if your system defines PTHREAD_RWLOCK_PREFER_WRITER_NP in pthread.h]),
 AC_MSG_RESULT(no)
@@ -593,7 +767,7 @@ AC_MSG_RESULT(no)
 
 AC_MSG_CHECKING(for PTHREAD_MUTEX_RECURSIVE_NP in pthread.h)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_MUTEX_RECURSIVE_NP;]),
+[AC_LANG_PROGRAM([#include <pthread.h>], [int a = PTHREAD_MUTEX_RECURSIVE_NP;])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1, [Define to 1 if your system defines PTHREAD_MUTEX_RECURSIVE_NP in pthread.h]),
 AC_MSG_RESULT(no)
@@ -650,11 +824,11 @@ AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_
 # Generally yes on OpenBSD/FreeBSD and no on Mac OS X.
 AC_MSG_CHECKING(whether we can compare a mutex to its initial value)
 AC_LINK_IFELSE(
-       AC_LANG_PROGRAM([#include <pthread.h>], [pthread_mutex_t lock;
+       [AC_LANG_PROGRAM([#include <pthread.h>], [pthread_mutex_t lock;
        if ((lock) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
                return 0;
        }
-       return 0]),
+       return 0])],
        AC_MSG_RESULT(yes)
        AC_DEFINE([CAN_COMPARE_MUTEX_TO_INIT_VALUE], 1, [Define to 1 if your system's implementation of mutexes supports comparison of a mutex to its initializer.]),
        AC_MSG_RESULT(no)
@@ -675,9 +849,12 @@ AC_LINK_IFELSE(
 #)
 #fi
 
+# for FreeBSD thr_self
+AC_CHECK_HEADERS([sys/thr.h])
+
 AC_MSG_CHECKING(for compiler atomic operations)
 AC_LINK_IFELSE(
-AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);]),
+[AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);])],
 AC_MSG_RESULT(yes)
 AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
 AC_MSG_RESULT(no)
@@ -686,8 +863,8 @@ AC_MSG_RESULT(no)
 # glibc, AFAIK, is the only C library that makes printing a NULL to a string safe.
 AC_MSG_CHECKING([if your system printf is NULL-safe.])
 AC_RUN_IFELSE(
-       AC_LANG_PROGRAM([#include <stdio.h>],
-               [printf("%s", NULL)]),
+       [AC_LANG_PROGRAM([#include <stdio.h>],
+               [printf("%s", NULL)])],
        AC_DEFINE([HAVE_NULLSAFE_PRINTF], 1, [Define to 1 if your C library can safely print NULL to string formats.])
        AC_MSG_RESULT(yes),
        AC_MSG_RESULT(no),
@@ -695,6 +872,48 @@ AC_RUN_IFELSE(
        AC_MSG_RESULT(unknown)
 )
 
+AC_MSG_CHECKING(if we can increase the maximum select-able file descriptor)
+AC_RUN_IFELSE(
+[AC_LANG_PROGRAM([
+#include <stdio.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+], [[
+       struct rlimit rlim = { FD_SETSIZE * 2, FD_SETSIZE * 2 };
+       int fd0, fd1;
+       struct timeval tv = { 0, };
+       struct ast_fdset { long fds_bits[[1024]]; } fds = { { 0, } };
+       if (setrlimit(RLIMIT_NOFILE, &rlim)) { exit(1); }
+       if ((fd0 = open("/dev/null", O_RDONLY)) < 0) { exit(1); }
+       if (dup2(fd0, (fd1 = FD_SETSIZE + 1)) < 0) { exit(1); }
+       FD_SET(fd0, (fd_set *) &fds);
+       FD_SET(fd1, (fd_set *) &fds);
+       if (select(FD_SETSIZE + 2, (fd_set *) &fds, NULL, NULL, &tv) < 0) { exit(1); }
+       exit(0)]])],
+       AC_MSG_RESULT(yes)
+       AC_DEFINE([HAVE_VARIABLE_FDSET], 1, [Define to 1 if your system can support larger than default select bitmasks.]),
+       AC_MSG_RESULT(no),
+       AC_MSG_RESULT(cross-compile)
+)
+
+if test "${ac_cv_have_variable_fdset}x" = "0x"; then
+       AC_RUN_IFELSE(
+               [AC_LANG_PROGRAM([
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+], [if (getuid() != 0) { exit(1); }])],
+               AC_DEFINE([CONFIGURE_RAN_AS_ROOT], 1, [Some configure tests will unexpectedly fail if configure is run by a non-root user.  These may be able to be tested at runtime.]))
+fi
+
 AST_GCC_ATTRIBUTE(pure)
 AST_GCC_ATTRIBUTE(malloc)
 AST_GCC_ATTRIBUTE(const)
@@ -703,20 +922,49 @@ AST_GCC_ATTRIBUTE(always_inline)
 AST_GCC_ATTRIBUTE(deprecated)
 AST_GCC_ATTRIBUTE(sentinel)
 AST_GCC_ATTRIBUTE(warn_unused_result)
-AST_GCC_ATTRIBUTE(weakref, [weakref("foo")], static)
-AST_GCC_ATTRIBUTE(weak_import)
+
+# Support weak symbols on a platform specific basis.  The Mac OS X
+# (Darwin) support must be isolated from the other platforms because
+# it has caused other platforms to fail.
+#
+case "${OSARCH}" in
+       darwin*)
+       # Allow weak symbol support on Darwin platforms only because there
+       # is active community support for it.
+       # However, Darwin seems to break weak symbols for each new version.
+       #
+       AST_GCC_ATTRIBUTE(weak_import, [], [], PBX_WEAKREF)
+
+       # Several other platforms including Linux have GCC versions that
+       # define the weak attribute.  However, this attribute is only
+       # setup for use in the code by Darwin.
+       AST_GCC_ATTRIBUTE(weak, [], [], PBX_WEAKREF)
+       ;;
+       linux-gnu)
+       # Primarily support weak symbols on Linux platforms.
+       #
+       AST_GCC_ATTRIBUTE(weakref, [weakref("foo")], static, PBX_WEAKREF)
+       ;;
+       *)
+       # Allow weak symbols on other platforms.  However, any problems
+       # with this feature on other platforms must be fixed by the
+       # community.
+       #
+       AST_GCC_ATTRIBUTE(weakref, [weakref("foo")], static, PBX_WEAKREF)
+       ;;
+esac
 
 AC_MSG_CHECKING(for -ffunction-sections support)
 saved_CFLAGS="${CFLAGS}"
 CFLAGS="${CFLAGS} -ffunction-sections"
 AC_COMPILE_IFELSE(
-       AC_LANG_PROGRAM([], [int x = 1;]),
+       [AC_LANG_PROGRAM([], [int x = 1;])],
        AC_MSG_RESULT(yes)
        [saved_LDFLAGS="${LDFLAGS}"]
        [LDFLAGS="${LDFLAGS} -Wl,--gc-sections"]
        AC_MSG_CHECKING(for --gc-sections support)
        AC_LINK_IFELSE(
-               AC_LANG_PROGRAM([], [int x = 1;]),
+               [AC_LANG_PROGRAM([], [int x = 1;])],
                AC_MSG_RESULT(yes)
                [GC_CFLAGS="-ffunction-sections"]
                [[GC_LDFLAGS="-Wl,--gc-sections"]],
@@ -739,6 +987,16 @@ else
 fi
 AC_SUBST(AST_DECLARATION_AFTER_STATEMENT)
 
+AC_MSG_CHECKING(for -Wtrampolines support)
+if $(${CC} -Wtrampolines -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
+       AC_MSG_RESULT(yes)
+       AST_TRAMPOLINES=-Wtrampolines
+else
+       AC_MSG_RESULT(no)
+       AST_TRAMPOLINES=
+fi
+AC_SUBST(AST_TRAMPOLINES)
+
 AC_MSG_CHECKING(for _FORTIFY_SOURCE support)
 if $(${CC} -D_FORTIFY_SOURCE=2 -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
        AC_MSG_RESULT(yes)
@@ -769,10 +1027,58 @@ else
 fi
 AC_SUBST(AST_SHADOW_WARNINGS)
 
+AC_MSG_CHECKING(for -march=native support)
+if $(${CC} -march=native -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
+       if test "${CONFIG_CFLAGS}" = ""; then
+               AC_MSG_RESULT(yes)
+               AST_NATIVE_ARCH=1
+       else
+               AC_MSG_RESULT(user CFLAGS present)
+               AST_NATIVE_ARCH=
+       fi
+else
+       AC_MSG_RESULT(no)
+       AST_NATIVE_ARCH=
+fi
+AC_SUBST(AST_NATIVE_ARCH)
+
+dnl Nested functions required for RAII implementation
+AC_MSG_CHECKING(for -fnested-functions)
+AC_COMPILE_IFELSE(
+       dnl Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774
+       [AC_LANG_PROGRAM([], [auto void foo(void); void foo(void) {}])],
+       AC_MSG_RESULT(no)
+       [AST_NESTED_FUNCTIONS=],
+       AC_MSG_RESULT(required)
+       [AST_NESTED_FUNCTIONS=-fnested-functions]
+)
+AC_SUBST(AST_NESTED_FUNCTIONS)
+
+dnl Check to see if rpath should be set in LDFLAGS
+AC_ARG_ENABLE(rpath,
+       [AC_HELP_STRING([--disable-rpath],
+                       [Disables rpath linker option checking])],
+       [case "${enableval}" in
+               y|ye|yes) check_rpath=yes ;;
+               n|no) check_rpath=no ;;
+                *) AC_MSG_ERROR(bad value ${enableval} for --disable-rpath) ;;
+       esac], [check_rpath=yes])
+
+AC_MSG_CHECKING(whether to use rpath)
+AST_RPATH=
+if test "${check_rpath}" != yes; then
+       AC_MSG_RESULT(skipped)
+elif test "${prefix}" = /usr || test "${prefix}" = NONE; then
+       AC_MSG_RESULT(not needed)
+else
+       AST_RPATH="-Wl,-rpath,${libdir}"
+fi
+AC_SUBST(AST_RPATH)
+
 AC_MSG_CHECKING(for sysinfo)
 AC_LINK_IFELSE(
-        AC_LANG_PROGRAM([#include <sys/sysinfo.h>],
-                        [struct sysinfo sys_info; int uptime = sys_info.uptime]),
+        [AC_LANG_PROGRAM([#include <sys/sysinfo.h>],
+                        [struct sysinfo sys_info; int uptime = sys_info.uptime])],
         AC_MSG_RESULT(yes)
         AC_DEFINE([HAVE_SYSINFO], 1, [Define to 1 if your system has sysinfo support]),
         AC_MSG_RESULT(no)
@@ -781,7 +1087,7 @@ AC_LINK_IFELSE(
 AC_SEARCH_LIBS(res_9_ninit, resolv)
 AC_MSG_CHECKING(for res_ninit)
 AC_LINK_IFELSE(
-       AC_LANG_PROGRAM([
+       [AC_LANG_PROGRAM([
                        #ifdef HAVE_SYS_SOCKET_H
                        #include <sys/socket.h>
                        #endif
@@ -792,13 +1098,13 @@ AC_LINK_IFELSE(
                        #include <arpa/nameser.h>
                        #endif
                        #include <resolv.h>],
-                       [int foo = res_ninit(NULL);]),
+                       [int foo = res_ninit(NULL);])],
        AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.])
        AC_SEARCH_LIBS(res_9_ndestroy, resolv)
        AC_MSG_CHECKING(for res_ndestroy)
        AC_LINK_IFELSE(
-               AC_LANG_PROGRAM([
+               [AC_LANG_PROGRAM([
                                #ifdef HAVE_SYS_SOCKET_H
                                #include <sys/socket.h>
                                #endif
@@ -809,7 +1115,7 @@ AC_LINK_IFELSE(
                                #include <arpa/nameser.h>
                                #endif
                                #include <resolv.h>],
-                               [res_ndestroy(NULL);]),
+                               [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)
@@ -817,7 +1123,7 @@ AC_LINK_IFELSE(
        AC_SEARCH_LIBS(res_9_close, resolv)
        AC_MSG_CHECKING(for res_close)
        AC_LINK_IFELSE(
-               AC_LANG_PROGRAM([
+               [AC_LANG_PROGRAM([
                                #ifdef HAVE_SYS_SOCKET_H
                                #include <sys/socket.h>
                                #endif
@@ -828,7 +1134,7 @@ AC_LINK_IFELSE(
                                #include <arpa/nameser.h>
                                #endif
                                #include <resolv.h>],
-                               [res_close();]),
+                               [res_close();])],
                AC_MSG_RESULT(yes)
                AC_DEFINE([HAVE_RES_CLOSE], 1, [Define to 1 if your system has the close resolver function.]),
                AC_MSG_RESULT(no)
@@ -849,12 +1155,56 @@ AC_CHECK_SIZEOF([int])
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([long long])
 AC_CHECK_SIZEOF([char *])
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(long long)
+AC_COMPUTE_INT([ac_cv_sizeof_fd_set_fds_bits], [sizeof(foo.fds_bits[[0]])], [$ac_includes_default
+fd_set foo;])
+# This doesn't actually work; what it does is to use the variable set in the
+# previous test as a cached value to set the right output variables.
+AC_CHECK_SIZEOF(fd_set.fds_bits)
+
+# Set a type compatible with the previous.  We cannot just use a generic type
+# for these bits, because on big-endian systems, the bits won't match up
+# correctly if the size is wrong.
+if test $ac_cv_sizeof_int = $ac_cv_sizeof_fd_set_fds_bits; then
+  AC_DEFINE([TYPEOF_FD_SET_FDS_BITS], [int], [Define to a type of the same size as fd_set.fds_bits[[0]]])
+else if test $ac_cv_sizeof_long = $ac_cv_sizeof_fd_set_fds_bits; then
+  AC_DEFINE([TYPEOF_FD_SET_FDS_BITS], [long], [Define to a type of the same size as fd_set.fds_bits[[0]]])
+else if test $ac_cv_sizeof_long_long = $ac_cv_sizeof_fd_set_fds_bits; then
+  AC_DEFINE([TYPEOF_FD_SET_FDS_BITS], [long long], [Define to a type of the same size as fd_set.fds_bits[[0]]])
+fi ; fi ; fi
+
+AC_MSG_CHECKING(for dladdr in dlfcn.h)
+PBX_DLADDR=0
+old_LIBS=${LIBS}
+LIBS="${LIBS} -ldl"
+AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM([#define _GNU_SOURCE 1
+#include <dlfcn.h>],
+               [dladdr((void *)0, (void *)0)]
+       )],
+       AC_MSG_RESULT(yes)
+       PBX_DLADDR=1
+       AC_SUBST([PBX_DLADDR])
+       AC_DEFINE([HAVE_DLADDR], 1, [Define to 1 if your system has the dladdr() GNU extension]),
+       AC_MSG_RESULT(no)
+)
+LIBS=${old_LIBS}
+
+# PKGCONFIG is used in later tests
+PKG_PROG_PKG_CONFIG()
+
 
 # do the package library checks now
 
 AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])
 
-AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
+AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_openr], [bfd.h])
+
+if test "${PBX_BFD}" = "0"; then
+  # Fedora/RedHat/CentOS require extra libraries
+  AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_check_format], [bfd.h], [-ldl -liberty])
+fi
 
 if test "x${OSARCH}" = "xlinux-gnu" ; then
   AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
@@ -939,15 +1289,55 @@ if test "${USE_GSM}" != "no"; then
    fi
 fi
 
+ILBC_INTERNAL="yes"
+AC_SUBST(ILBC_INTERNAL)
+ILBC_SYSTEM="yes"
+if test "${USE_ILBC}" != "no"; then
+   if test "${ILBC_DIR}" = "internal"; then
+      ILBC_SYSTEM="no"
+   elif test "${ILBC_DIR}" != ""; then
+      ILBC_INTERNAL="no"
+   fi
+   if test "${ILBC_SYSTEM}" = "yes"; then
+      AST_PKG_CONFIG_CHECK(ILBC, libilbc)
+      if test "$PBX_ILBC" = "1"; then
+        ILBC_INTERNAL="no"
+      fi
+   fi
+   if test "${ILBC_INTERNAL}" = "yes"; then
+      PBX_ILBC=1
+   fi
+fi
+
+LIBEDIT_INTERNAL="yes"
+AC_SUBST(LIBEDIT_INTERNAL)
+LIBEDIT_SYSTEM="yes"
+if test "${USE_LIBEDIT}" != "no"; then
+   if test "${LIBEDIT_DIR}" = "internal"; then
+      LIBEDIT_SYSTEM="no"
+   elif test "${LIBEDIT_DIR}" != ""; then
+      LIBEDIT_INTERNAL="no"
+   fi
+   if test "${LIBEDIT_SYSTEM}" = "yes"; then
+      AST_PKG_CONFIG_CHECK(LIBEDIT, libedit)
+      if test "$PBX_LIBEDIT" = "1"; then
+        LIBEDIT_INTERNAL="no"
+      fi
+   fi
+   if test "${LIBEDIT_INTERNAL}" = "yes"; then
+      PBX_LIBEDIT=1
+   fi
+fi
+
 AST_EXT_LIB_CHECK([ICONV], [iconv], [iconv_open], [iconv.h])
+# GNU libiconv #define's iconv_open to libiconv_open, so we need to search for that symbol
+AST_EXT_LIB_CHECK([ICONV], [iconv], [libiconv_open], [iconv.h])
 # Some versions of Linux package iconv in glibc
 AST_EXT_LIB_CHECK([ICONV], [c], [iconv_close], [iconv.h])
 
-# Some distributions (like RedHat) add a libical subdirectory for the headers
+# If ical.h is NOT in the libical directory, then it is of a version insufficient for us.
 AST_EXT_LIB_CHECK([ICAL], [ical], [icaltimezone_get_utc_timezone], [libical/ical.h], [${PTHREAD_LIBS}], [${PTHREAD_CFLAGS}])
 
-AST_EXT_LIB_CHECK([ICAL], [ical], [icaltimezone_new], [ical.h], [${PTHREAD_LIBS}], [${PTHREAD_CFLAGS}])
-
 AST_EXT_LIB_CHECK([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])
 
 if test "${USE_IMAP_TK}" != "no"; then
@@ -968,7 +1358,7 @@ if test "${USE_IMAP_TK}" != "no"; then
        CPPFLAGS="${CPPFLAGS} ${imap_include}"
                LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
                AC_LINK_IFELSE(
-               AC_LANG_PROGRAM(
+               [AC_LANG_PROGRAM(
                                [#include "c-client.h"
                                void mm_searched (MAILSTREAM *stream,unsigned long number)
                                {
@@ -1018,13 +1408,13 @@ if test "${USE_IMAP_TK}" != "no"; then
                                [
                                MAILSTREAM *foo = mail_open(NULL, "", 0);
                                ]
-                       ),
+                       )],
                        [ac_cv_imap_tk="yes"],
                        [ac_cv_imap_tk="no"]
                )
                if test "${ac_cv_imap_tk}" = "yes"; then
                        AC_LINK_IFELSE(
-                               AC_LANG_PROGRAM(
+                               [AC_LANG_PROGRAM(
                                        [#include "c-client.h"
                                        void mm_searched (MAILSTREAM *stream,unsigned long number)
                                        {
@@ -1074,7 +1464,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                                        [
                                        long check = mail_expunge_full(NULL, "", 0);
                                        ]
-                               ),
+                               )],
                                [ac_cv_imap_tk2006="yes"],
                                [ac_cv_imap_tk2006="no"]
                        )
@@ -1095,7 +1485,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                                CPPFLAGS="${CPPFLAGS} ${imap_include}"
                                LIBS="${LIBS} ${imap_libs} ${imap_ldflags}"
                                AC_LINK_IFELSE(
-                               AC_LANG_PROGRAM(
+                               [AC_LANG_PROGRAM(
                                                [#include "c-client.h"
                                                void mm_searched (MAILSTREAM *stream,unsigned long number)
                                                {
@@ -1145,13 +1535,13 @@ if test "${USE_IMAP_TK}" != "no"; then
                                                [
                                                MAILSTREAM *foo = mail_open(NULL, "", 0);
                                                ]
-                                       ),
+                                       )],
                                        [ac_cv_imap_tk="yes"],
                                        [ac_cv_imap_tk="no"]
                                )
                                if test "${ac_cv_imap_tk}" = "yes"; then
                                        AC_LINK_IFELSE(
-                                               AC_LANG_PROGRAM(
+                                               [AC_LANG_PROGRAM(
                                                        [#include "c-client.h"
                                                        void mm_searched (MAILSTREAM *stream,unsigned long number)
                                                        {
@@ -1201,14 +1591,14 @@ if test "${USE_IMAP_TK}" != "no"; then
                                                        [
                                                        long check = mail_expunge_full(NULL, "", 0);
                                                        ]
-                                               ),
+                                               )],
                                                [ac_cv_imap_tk2006="yes"],
                                                [ac_cv_imap_tk2006="no"]
                                        )
                                fi
                        fi
                fi
-       fi 
+       fi
        if test "${IMAP_TK_DIR}" = "system"; then
                #We will enter here if user specified "system" or if any of above checks failed
                AC_MSG_CHECKING([for system c-client library...])
@@ -1220,7 +1610,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                CPPFLAGS="${CPPFLAGS} ${imap_include}"
                LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
                AC_LINK_IFELSE(
-               AC_LANG_PROGRAM(
+               [AC_LANG_PROGRAM(
                                [#include <stdio.h>
                                #include <imap/c-client.h>
                                void mm_searched (MAILSTREAM *stream,unsigned long number)
@@ -1271,13 +1661,13 @@ if test "${USE_IMAP_TK}" != "no"; then
                                [
                                MAILSTREAM *foo = mail_open(NULL, "", 0);
                                ]
-                       ),
+                       )],
                        [ac_cv_imap_tk="yes"],
                        [ac_cv_imap_tk="no"]
                )
                if test "${ac_cv_imap_tk}" = "yes"; then
                        AC_LINK_IFELSE(
-                               AC_LANG_PROGRAM(
+                               [AC_LANG_PROGRAM(
                                        [#include <stdio.h>
                                        #include <imap/c-client.h>
                                        void mm_searched (MAILSTREAM *stream,unsigned long number)
@@ -1328,7 +1718,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                                        [
                                        long check = mail_expunge_full(NULL, "", 0);
                                        ]
-                               ),
+                               )],
                                [ac_cv_imap_tk2006="yes"],
                                [ac_cv_imap_tk2006="no"]
                        )
@@ -1341,7 +1731,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                        CPPFLAGS="${CPPFLAGS} ${imap_include}"
                        LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
                        AC_LINK_IFELSE(
-                       AC_LANG_PROGRAM(
+                       [AC_LANG_PROGRAM(
                                        [#include <stdio.h>
                                        #include <c-client/c-client.h>
                                        void mm_searched (MAILSTREAM *stream,unsigned long number)
@@ -1392,13 +1782,13 @@ if test "${USE_IMAP_TK}" != "no"; then
                                        [
                                        MAILSTREAM *foo = mail_open(NULL, "", 0);
                                        ]
-                               ),
+                               )],
                                [ac_cv_imap_tk="yes"],
                                [ac_cv_imap_tk="no"]
                        )
                        if test "${ac_cv_imap_tk}" = "yes"; then
                                AC_LINK_IFELSE(
-                                       AC_LANG_PROGRAM(
+                                       [AC_LANG_PROGRAM(
                                                [#include <stdio.h>
                                                #include <c-client/c-client.h>
                                                void mm_searched (MAILSTREAM *stream,unsigned long number)
@@ -1449,7 +1839,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                                                [
                                                long check = mail_expunge_full(NULL, "", 0);
                                                ]
-                                       ),
+                                       )],
                                        [ac_cv_imap_tk2006="yes"],
                                        [ac_cv_imap_tk2006="no"]
                                )
@@ -1466,7 +1856,7 @@ if test "${USE_IMAP_TK}" != "no"; then
                        AC_DEFINE([HAVE_IMAP_TK2006], 1, [Define if your system has the UW IMAP Toolkit c-client library version 2006 or greater.])
                fi
        else
-               AC_MSG_RESULT(no) 
+               AC_MSG_RESULT(no)
        fi
        CPPFLAGS="${saved_cppflags}"
        LIBS="${saved_libs}"
@@ -1478,6 +1868,8 @@ AST_EXT_LIB_CHECK([INOTIFY], [c], [inotify_init], [sys/inotify.h])
 
 AST_EXT_LIB_CHECK([JACK], [jack], [jack_activate], [jack/jack.h])
 
+AST_EXT_LIB_CHECK([JANSSON], [jansson], [json_dumps], [jansson.h])
+
 # BSD (and OS X) equivalent of inotify
 AST_EXT_LIB_CHECK([KQUEUE], [c], [kqueue], [sys/event.h])
 
@@ -1489,28 +1881,6 @@ AST_EXT_LIB_CHECK([LTDL], [ltdl], [lt_dlinit], [ltdl.h], [])
 
 AST_EXT_LIB_CHECK([LDAP], [ldap], [ldap_initialize], [ldap.h])
 
-AC_ARG_ENABLE([xmldoc],
-       [AS_HELP_STRING([--disable-xmldoc],
-               [Explicity disable XML documentation])],
-       [case "${enableval}" in
-               y|ye|yes) disable_xmldoc=no ;;
-               n|no)  disable_xmldoc=yes ;;
-               *) AC_MSG_ERROR(bad value ${enableval} for --disable-xmldoc)  ;;
-       esac], [disable_xmldoc=no])
-
-if test "${disable_xmldoc}" != "yes"; then
-       AST_EXT_TOOL_CHECK([LIBXML2], [xml2-config], , ,
-       [#include <libxml/tree.h>
-       #include <libxml/parser.h>],
-       [LIBXML_TEST_VERSION])
-       if test "${PBX_LIBXML2}" != 1; then
-               AC_MSG_NOTICE(*** XML documentation will not be available because the 'libxml2' development package is missing.)
-               AC_MSG_NOTICE(*** Please run the 'configure' script with the '--disable-xmldoc' parameter option)
-               AC_MSG_NOTICE(*** or install the 'libxml2' development package.)
-               exit 1
-       fi
-fi
-
 AST_EXT_LIB_CHECK([MISDN], [mISDN], [mISDN_open], [mISDNuser/mISDNlib.h])
 
 if test "${PBX_MISDN}" = 1; then
@@ -1526,8 +1896,6 @@ AST_EXT_TOOL_CHECK([MYSQLCLIENT], [mysql_config])
 
 AST_EXT_LIB_CHECK([NBS], [nbs], [nbs_connect], [nbs.h])
 
-AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
-
 AST_EXT_TOOL_CHECK([NEON], [neon-config])
 
 AST_EXT_TOOL_CHECK([NEON29], [neon-config], , [--libs],
@@ -1561,7 +1929,7 @@ 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 "${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
@@ -1587,10 +1955,23 @@ if test "${PG_CONFIG}" != No; then
          AC_MSG_NOTICE([*** including --without-postgres])
          exit 1
          fi
-   else 
+   else
       AC_CHECK_LIB([pq], [PQescapeStringConn], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
       [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)
 
+      AC_MSG_CHECKING(for pg_encoding_to_char within Postgres headers)
+      old_CFLAGS=${CFLAGS}
+      CFLAGS="${CFLAGS} -I${PGSQL_includedir} -Werror"
+      old_LDFLAGS=${LDFLAGS}
+      LDFLAGS="${LDFLAGS} -L${PGSQL_libdir} -lpq -lz"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <libpq-fe.h>],
+          [const char *foo = pg_encoding_to_char(1)])],
+        [AC_MSG_RESULT(yes)
+         AC_DEFINE_UNQUOTED([HAVE_PGSQL_pg_encoding_to_char], 1, [Define to indicate presence of the pg_encoding_to_char API.])],
+        [AC_MSG_RESULT(no)])
+      CFLAGS=${old_CFLAGS}
+      LDFLAGS=${old_LDFLAGS}
+
       if test "${ac_cv_lib_pq_PQescapeStringConn}" = "yes"; then
          PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz"
          PGSQL_INCLUDE="-I${PGSQL_includedir}"
@@ -1611,6 +1992,10 @@ AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
 
 AST_EXT_LIB_CHECK([PRI], [pri], [pri_connected_line_update], [libpri.h])
+AST_EXT_LIB_CHECK([PRI_L2_PERSISTENCE], [pri], [pri_persistent_layer2_option], [libpri.h])
+AST_EXT_LIB_CHECK([PRI_DATETIME_SEND], [pri], [pri_date_time_send_option], [libpri.h])
+AST_EXT_LIB_CHECK([PRI_MWI_V2], [pri], [pri_mwi_indicate_v2], [libpri.h])
+AST_EXT_LIB_CHECK([PRI_DISPLAY_TEXT], [pri], [pri_display_text], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_MWI], [pri], [pri_mwi_indicate], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_MCID], [pri], [pri_mcid_enable], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_CALL_WAITING], [pri], [pri_connect_ack_enable], [libpri.h])
@@ -1653,7 +2038,8 @@ if test "x${PBX_SPANDSP}" = "x1" ; then
        AST_EXT_LIB_CHECK([SPANDSP], [spandsp], [t38_terminal_init], [spandsp.h], [-ltiff])
 fi
 
-AST_EXT_LIB_CHECK([SS7], [ss7], [ss7_pollflags], [libss7.h])
+# Check for libss7 v1.0 branch compatible version.
+AST_EXT_LIB_CHECK([SS7], [ss7], [ss7_set_adjpc], [libss7.h])
 
 AST_EXT_LIB_CHECK([OPENR2], [openr2], [openr2_chan_new], [openr2.h])
 
@@ -1663,7 +2049,7 @@ if test "${USE_PWLIB}" != "no"; then
        fi
        AST_CHECK_PWLIB()
        AST_CHECK_PWLIB_VERSION([PWLib], [PWLIB], [ptbuildopts.h], [1], [9], [2], [P[[WT]]LIB_VERSION])
-               
+
        if test "${HAS_PWLIB:-unset}" != "unset"; then
                AST_CHECK_PWLIB_PLATFORM()
 
@@ -1681,7 +2067,7 @@ if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
                OPENH323DIR="${OPENH323_DIR}"
        fi
        AST_CHECK_OPENH323()
-       AST_CHECK_PWLIB_VERSION([OpenH323], [OPENH323], [openh323buildopts.h], [1], [17], [3])
+       AST_CHECK_PWLIB_VERSION([OpenH323], [OPENH323], [openh323buildopts.h], [1], [17], [3], [], [1], [19], [0])
        AST_CHECK_OPENH323_BUILD()
        PLATFORM_OPENH323="h323_${PWLIB_PLATFORM}_${OPENH323_SUFFIX}"
        AST_CHECK_PWLIB_BUILD([OpenH323], [OPENH323],
@@ -1693,7 +2079,7 @@ if test "${PBX_PWLIB}" = "1" -a "${USE_OPENH323}" != "no" ; then
                [${PWLIB_INCLUDE}], [${PWLIB_LIB}])
 fi
 
-AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h], [-lm]) 
+AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h], [-lm])
 if test "x${PBX_LUA}" = "x1" ; then
        if test x"${LUA_DIR}" = x; then
                LUA_INCLUDE="${LUA_INCLUDE} -I/usr/include/lua5.1"
@@ -1701,37 +2087,14 @@ if test "x${PBX_LUA}" = "x1" ; then
                LUA_INCLUDE="${LUA_INCLUDE} -I${LUA_DIR}/lua5.1"
        fi
 fi
-       
+
 # Some distributions (like SuSE) remove the 5.1 suffix.
-AST_EXT_LIB_CHECK([LUA], [lua], [luaL_register], [lua.h], [-lm]) 
+AST_EXT_LIB_CHECK([LUA], [lua], [luaL_register], [lua.h], [-lm])
 
 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
 
-# This is a bit complex... in reality, Asterisk's AIS support is dependent on finding
-# *any* implementation of AIS, not just OpenAIS. However, the configure script needs
-# to know the specifics of each possible implementation, and then represent the one
-# that was found as 'AIS'.
-
-PBX_AIS=0
-
-# OpenAIS installs its libraries into /usr/lib/openais by default, so check there
-
-AST_EXT_LIB_CHECK([OPENAIS], [SaClm], [saClmInitialize], [openais/saClm.h], [-L/usr/lib/openais -L/usr/lib64/openais])
-
-if test "${PBX_OPENAIS}" = 1; then
-   PBX_AIS=1
-   if test -n "${OPENAIS_DIR}"; then
-      AIS_INCLUDE="${OPENAIS_INCLUDE}/openais"
-      AIS_LIB="-lSaEvt ${OPENAIS_LIB}"
-   else
-      AIS_INCLUDE="-I/usr/include/openais"
-      AIS_LIB="-lSaClm -lSaEvt -L/usr/lib/openais -L/usr/lib64/openais"
-   fi
-fi
-
-AC_SUBST(PBX_AIS)
-AC_SUBST(AIS_INCLUDE)
-AC_SUBST(AIS_LIB)
+AST_EXT_LIB_CHECK([COROSYNC], [cpg], [cpg_join], [corosync/cpg.h], [-lcfg])
+AST_EXT_LIB_CHECK([COROSYNC_CFG_STATE_TRACK], [cfg], [corosync_cfg_state_track], [corosync/cfg.h], [-lcfg])
 
 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
 
@@ -1750,31 +2113,77 @@ AC_SUBST(PBX_SPEEX_PREPROCESS)
 
 AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])
 
-AST_EXT_LIB_CHECK([SQLITE3], [sqlite3], [sqlite3_open], [sqlite3.h])
+AST_EXT_LIB_CHECK([SQLITE3], [sqlite3], [sqlite3_open], [sqlite3.h], [${PTHREAD_LIBS}], [${PTHREAD_CFLAGS}])
+
+if test "${PBX_SQLITE3}" != 1; then
+       AC_MSG_WARN(*** Asterisk now uses SQLite3 for the internal Asterisk database.)
+       AC_MSG_WARN(*** Please install the SQLite3 development package.)
+       exit 1
+fi
 
 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])
+       AST_EXT_LIB_CHECK([OPENSSL], [ssl], [SSL_connect], [openssl/ssl.h], [-lcrypto])
 fi
 
 if test "$PBX_OPENSSL" = "1";
 then
-    AST_CHECK_OSPTK([3], [6], [0])
+        AST_CHECK_OSPTK([4], [0], [0])
+        AST_EXT_LIB_CHECK([OPENSSL_SRTP], [ssl], [SSL_CTX_set_tlsext_use_srtp], [openssl/ssl.h], [-lcrypto])
 fi
 
 AST_EXT_LIB_CHECK([SRTP], [srtp], [srtp_init], [srtp/srtp.h])
 
-AST_EXT_TOOL_CHECK([GMIME], [gmime-config], [], [], [#include <gmime/gmime.h>], [gboolean q = g_mime_check_version(0,0,0);])
+if test "$PBX_SRTP" = "1";
+then
+    saved_libs="${LIBS}"
+    saved_ldflags="${LDFLAGS}"
+    saved_cflags="${CFLAGS}"
+    LIBS="${LIBS} ${SRTP_LIB}"
+    LDFLAGS="${LDFLAGS} -shared -fPIC"
+    CFLAGS="${CFLAGS} ${SRTP_INCLUDE}"
+    AC_MSG_CHECKING(for the ability of -lsrtp to be linked in a shared object)
+    AC_LINK_IFELSE(
+    [
+        AC_LANG_PROGRAM(
+            [#include <srtp/srtp.h>],
+            [srtp_init();]
+        )
+    ],
+    [ AC_MSG_RESULT(yes) ],
+    [
+        AC_MSG_RESULT(no)
+        AC_MSG_WARN(***)
+        AC_MSG_WARN(*** libsrtp could not be linked as a shared object.)
+        AC_MSG_WARN(*** Try compiling libsrtp manually. Configure libsrtp)
+        AC_MSG_WARN(*** with ./configure CFLAGS=-fPIC --prefix=/usr)
+        AC_MSG_WARN(*** replacing /usr with the prefix of your choice.)
+        AC_MSG_WARN(*** After re-installing libsrtp, re-run the Asterisk)
+        AC_MSG_WARN(*** configure script.)
+        AC_MSG_WARN(***)
+        AC_MSG_WARN(*** If you do not need SRTP support re-run configure)
+        AC_MSG_WARN(*** with the --without-srtp option.)
+        exit 1
+    ]
+    )
+    LIBS="${saved_libs}"
+    LDFLAGS="${saved_ldflags}"
+    CFLAGS="${saved_cflags}"
+fi
 
-AST_EXT_LIB_CHECK([HOARD], [hoard], [malloc], [])
 
-AST_EXT_LIB_CHECK([FREETDS], [sybdb], [dbinit], [sybdb.h])
+for ver in 2.0 2.2 2.4 2.6; do
+       AST_PKG_CONFIG_CHECK([GMIME], gmime-$ver)
+       if test "$PBX_GMIME" = 1; then
+               break;
+       fi
+done
 
-AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
+AST_EXT_LIB_CHECK([HOARD], [hoard], [malloc], [])
 
-AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])
+AST_EXT_LIB_CHECK([FREETDS], [sybdb], [dbinit], [sybdb.h])
 
 AC_CHECK_LIB([tonezone], [tone_zone_find_by_num], tonezone_does_not_need_lm=yes, tonezone_does_not_need_lm=no)
 
@@ -1784,14 +2193,13 @@ fi
 
 AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [dahdi/tonezone.h], [${tonezone_extra} ${DAHDI_INCLUDE}])
 
-AST_EXT_LIB_CHECK([USB], [usb], [usb_init], [usb.h], [])
-
 if test "${OSARCH}" = "OpenBSD";
 then
-       AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc -logg])
+       AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc -lvorbisfile -logg])
 else
-       AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc])
+       AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc -lvorbisfile])
 fi
+AST_C_DECLARE_CHECK([VORBIS_OPEN_CALLBACKS], [OV_CALLBACKS_NOCLOSE], [vorbis/vorbisfile.h])
 
 AC_LANG_PUSH(C++)
 
@@ -1816,11 +2224,11 @@ if test "${USE_VPB}" != "no"; then
        [#include <vpbapi.h>],
        [int q = vpb_open(0,0);])
        ],
-       [       AC_MSG_RESULT(yes) 
-               ac_cv_lib_vpb_vpb_open="yes" 
+       [       AC_MSG_RESULT(yes)
+               ac_cv_lib_vpb_vpb_open="yes"
        ],
-       [       AC_MSG_RESULT(no) 
-               ac_cv_lib_vpb_vpb_open="no" 
+       [       AC_MSG_RESULT(no)
+               ac_cv_lib_vpb_vpb_open="no"
        ]
        )
    LIBS="${saved_libs}"
@@ -1840,28 +2248,14 @@ AC_LANG_POP
 
 AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])
 
-EDITLINE_LIB=""
-if test "x$TERMCAP_LIB" != "x" ; then
-  EDITLINE_LIB="$TERMCAP_LIB"
-elif test "x$TINFO_LIB" != "x" ; then
-  EDITLINE_LIB="$TINFO_LIB"
-elif test "x$CURSES_LIB" != "x" ; then
-  EDITLINE_LIB="$CURSES_LIB"
-elif test "x$NCURSES_LIB" != "x" ; then
-  EDITLINE_LIB="$NCURSES_LIB"
-else
-  AC_MSG_ERROR([*** termcap support not found (on modern systems, this typically means the ncurses development package is missing)])
-fi
-AC_SUBST(EDITLINE_LIB)
-
 if test "x${PBX_UNIXODBC}" = "x1" -o "x${PBX_IODBC}" = "x1"; then
        # Does ODBC support wide characters?
        AC_MSG_CHECKING(whether ODBC has support for Unicode types)
        AC_LINK_IFELSE(
-               AC_LANG_PROGRAM(
+               [AC_LANG_PROGRAM(
                        [#include <sql.h>
 #include <sqlext.h>],
-                       [int foo = SQL_WCHAR]),
+                       [int foo = SQL_WCHAR])],
                AC_MSG_RESULT(yes)
                        AC_DEFINE([HAVE_ODBC_WCHAR], [1], [Define to 1 if your ODBC library has wide (Unicode) types.]),
                AC_MSG_RESULT(no)
@@ -1906,17 +2300,7 @@ then
 fi
 AC_SUBST(PBX_LAUNCHD)
 
-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)
+AST_PKG_CONFIG_CHECK([GTK2], [gtk+-2.0])
 
 # build a GENERIC_ODBC result based on the presence of either UnixODBC (preferred)
 # or iODBC
@@ -1957,6 +2341,12 @@ fi
 
 AC_SUBST([PBX_SYSLOG])
 
+if test -f makeopts; then
+       ${ac_cv_path_EGREP} 'CURSES|GTK2|OSARCH|NEWT' makeopts > makeopts.acbak
+else
+       touch makeopts.acbak
+fi
+
 AC_CONFIG_FILES([build_tools/menuselect-deps makeopts channels/h323/Makefile])
 AST_CHECK_MANDATORY
 
@@ -1972,6 +2362,16 @@ fi
 
 AC_OUTPUT
 
+${ac_cv_path_EGREP} 'CURSES|GTK2|OSARCH|NEWT' makeopts > makeopts.acbak2
+if test "x${ac_cv_path_CMP}" = "x:"; then
+       ( cd `pwd`/menuselect && ./configure )
+else if ${ac_cv_path_CMP} -s makeopts.acbak makeopts.acbak2; then : ; else
+       ( cd `pwd`/menuselect && ./configure )
+fi ; fi
+
+rm makeopts.acbak makeopts.acbak2
+
+
 if test "x${silent}" != "xyes" ; then
 echo
 echo "               .\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$=..      "
@@ -2001,8 +2401,8 @@ fi
 AC_MSG_NOTICE(Package configured for: )
 AC_MSG_NOTICE( OS type  : $host_os)
 AC_MSG_NOTICE( Host CPU : $host_cpu)
-AC_MSG_NOTICE( build-cpu:vendor:os: $build_cpu : $build_vendor : $build_os :) 
-AC_MSG_NOTICE( host-cpu:vendor:os: $host_cpu : $host_vendor : $host_os :) 
+AC_MSG_NOTICE( build-cpu:vendor:os: $build_cpu : $build_vendor : $build_os :)
+AC_MSG_NOTICE( host-cpu:vendor:os: $host_cpu : $host_vendor : $host_os :)
 if test "${cross_compiling}" = "yes"; then
    AC_MSG_NOTICE( Cross Compilation = YES)
 fi