Skip to content
Snippets Groups Projects
configure.ac 95.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    AC_MSG_CHECKING(for pthread_rwlock_timedwrlock() in pthread.h)
    
    AC_LINK_IFELSE(
      [AC_LANG_PROGRAM(
        [#include <pthread.h>
         #include <time.h>],
        [pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar)])
      ],[
        AC_MSG_RESULT(yes)
        ac_cv_pthread_rwlock_timedwrlock="yes"
      ],[
        AC_MSG_RESULT(no)
        ac_cv_pthread_rwlock_timedwrlock="no"
      ]
    )
    
    
    # Some platforms define sem_init(), but only support sem_open(). joyous.
    AC_MSG_CHECKING(for working unnamed semaphores)
    AC_RUN_IFELSE(
    	[AC_LANG_PROGRAM([#include <semaphore.h>],
    		[sem_t sem; return sem_init(&sem, 0, 0);])],
    	AC_MSG_RESULT(yes)
    	AC_DEFINE([HAS_WORKING_SEMAPHORE], 1, [Define to 1 if anonymous semaphores work.]),
    
    	AC_MSG_RESULT(no),
    	AC_MSG_RESULT(cross-compile)
    	AC_MSG_NOTICE([WARNING: result yes guessed because of cross compilation])
    	AC_DEFINE([HAS_WORKING_SEMAPHORE], 1, [Define to 1 if anonymous semaphores work.])
    
    if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then
      AC_DEFINE([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK], 1, [Define if your system has pthread_rwlock_timedwrlock()])
    fi
    
    
    AC_MSG_CHECKING(if PTHREAD_ONCE_INIT needs braces)
    saved_CFLAGS="${CFLAGS}"
    CFLAGS="${CFLAGS} -Werror -Wmissing-braces"
    AC_COMPILE_IFELSE(
      [AC_LANG_PROGRAM(
    
        [#include <pthread.h>
         void empty(){}],
    	[pthread_once_t once = PTHREAD_ONCE_INIT; pthread_once(&once, empty);])
    
      ],[
        AC_MSG_RESULT(no)
        ac_cv_pthread_once_needsbraces="no"
      ],[
        AC_MSG_RESULT(yes)
        ac_cv_pthread_once_needsbraces="yes"
      ]
    )
    CFLAGS="${saved_CFLAGS}"
    if test "${ac_cv_pthread_once_needsbraces}" = "yes"; then
      AC_DEFINE([PTHREAD_ONCE_INIT_NEEDS_BRACES], 1, [Define if your system needs braces around PTHREAD_ONCE_INIT])
    fi
    
    
    AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [pthread.h])
    
    # Can we compare a mutex to its initial value?
    # 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;
    
    	if ((lock) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
    		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)
    )
    
    
    #if test "${cross_compiling}" = "no";
    #then
    #AC_MSG_CHECKING(for working epoll support)
    #AC_LINK_IFELSE(
    #AC_LANG_PROGRAM([#include <sys/epoll.h>], [int res = epoll_create(10);
    #					  if (res < 0)
    #					     return 1;
    #					  close (res);
    #					  return 0;]),
    #AC_MSG_RESULT(yes)
    #AC_DEFINE([HAVE_EPOLL], 1, [Define to 1 if your system has working epoll support.]),
    #AC_MSG_RESULT(no)
    #)
    #fi
    
    # for FreeBSD thr_self
    AC_CHECK_HEADERS([sys/thr.h])
    
    
    AC_MSG_CHECKING(for compiler sync operations)
    
    [AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);])],
    
    ax_cv_have_gcc_atomics=1
    
    AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides __sync atomic operations.]),
    AC_MSG_RESULT(no)
    )
    
    AC_MSG_CHECKING(for compiler atomic operations)
    AC_LINK_IFELSE(
    [AC_LANG_PROGRAM([], [int foo1; int foo2 = __atomic_fetch_add(&foo1, 1, __ATOMIC_RELAXED);])],
    AC_MSG_RESULT(yes)
    
    ax_cv_have_c_atomics=1
    
    AC_DEFINE([HAVE_C_ATOMICS], 1, [Define to 1 if your C compiler provides __atomic operations.]),
    
    if test -z $ax_cv_have_c_atomics$ax_cv_have_gcc_atomics; then
    	AC_MSG_ERROR([*** Atomic operations are not supported by your compiler.])
    fi
    
    
    # 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_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),
    	# It's unlikely an embedded system will have this.
    	AC_MSG_RESULT(unknown)
    )
    
    
    AC_MSG_CHECKING(if we can increase the maximum select-able file descriptor)
    AC_RUN_IFELSE(
    
    #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); }
    
    	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(
    
    #include <unistd.h>
    #include <sys/types.h>
    #include <stdlib.h>
    
    		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
    
    
    AC_MSG_CHECKING([if we have usable eventfd support])
    AC_RUN_IFELSE(
      [AC_LANG_PROGRAM([#include <sys/eventfd.h>],
          [return eventfd(0, EFD_NONBLOCK | EFD_SEMAPHORE) == -1;])],
      AC_MSG_RESULT(yes)
      AC_DEFINE([HAVE_EVENTFD], 1, [Define to 1 if your system supports eventfd and the EFD_NONBLOCK and EFD_SEMAPHORE flags.]),
    
      AC_MSG_RESULT(no),
      AC_MSG_RESULT(cross-compile)
    
    AST_GCC_ATTRIBUTE(pure)
    AST_GCC_ATTRIBUTE(malloc)
    AST_GCC_ATTRIBUTE(const)
    AST_GCC_ATTRIBUTE(unused)
    AST_GCC_ATTRIBUTE(always_inline)
    
    AST_GCC_ATTRIBUTE(sentinel)
    
    AST_GCC_ATTRIBUTE(may_alias)
    AST_GCC_ATTRIBUTE(constructor)
    
    if test "$ax_cv_have_func_attribute_constructor" != "1"; then
    	AC_MSG_ERROR([*** Function constructor attribute is not supported by your compiler.])
    fi
    
    
    if test "$ax_cv_have_func_attribute_destructor" != "1"; then
    	AC_MSG_ERROR([*** Function destructor attribute is not supported by your compiler.])
    fi
    
    AST_GCC_ATTRIBUTE(noreturn,noreturn)
    
    AC_MSG_CHECKING(for -fsanitize=address support)
    saved_sanitize_CFLAGS="${CFLAGS}"
    saved_sanitize_LDFLAGS="${LDFLAGS}"
    CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
    LDFLAGS="-fsanitize=address"
    AC_COMPILE_IFELSE(
    	[AC_LANG_PROGRAM([], [int x = 1;])],
    	AC_MSG_RESULT(yes)
    	[AST_ADDRESS_SANITIZER=1],
    
    	[AST_ADDRESS_SANITIZER=0]
    
    	AC_MSG_RESULT(no)
    )
    CFLAGS="${saved_sanitize_CFLAGS}"
    LDFLAGS="${saved_sanitize_LDFLAGS}"
    AC_SUBST(AST_ADDRESS_SANITIZER)
    
    AC_MSG_CHECKING(for -fsanitize=thread support)
    saved_sanitize_CFLAGS="${CFLAGS}"
    saved_sanitize_LDFLAGS="${LDFLAGS}"
    CFLAGS="-fno-omit-frame-pointer -pie -fPIE -fsanitize=thread"
    LDFLAGS="-fsanitize=thread -pie -fPIE"
    AC_COMPILE_IFELSE(
    	[AC_LANG_PROGRAM([], [int x = 1;])],
    	AC_MSG_RESULT(yes)
    	[AST_THREAD_SANITIZER=1],
    
    	[AST_THREAD_SANITIZER=0]
    
    	AC_MSG_RESULT(no)
    )
    CFLAGS="${saved_sanitize_CFLAGS}"
    LDFLAGS="${saved_sanitize_LDFLAGS}"
    AC_SUBST(AST_THREAD_SANITIZER)
    
    AC_MSG_CHECKING(for -fsanitize=leak support)
    saved_sanitize_CFLAGS="${CFLAGS}"
    saved_sanitize_LDFLAGS="${LDFLAGS}"
    CFLAGS="-fno-omit-frame-pointer -fsanitize=leak"
    LDFLAGS="-fsanitize=leak"
    AC_COMPILE_IFELSE(
    	[AC_LANG_PROGRAM([], [int x = 1;])],
    	AC_MSG_RESULT(yes)
    	[AST_LEAK_SANITIZER=1],
    
    	AC_MSG_RESULT(no)
    )
    CFLAGS="${saved_sanitize_CFLAGS}"
    LDFLAGS="${saved_sanitize_LDFLAGS}"
    AC_SUBST(AST_LEAK_SANITIZER)
    
    AC_MSG_CHECKING(for -fsanitize=undefined support)
    saved_sanitize_CFLAGS="${CFLAGS}"
    saved_sanitize_LDFLAGS="${LDFLAGS}"
    CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined"
    LDFLAGS="-fsanitize=undefined"
    AC_COMPILE_IFELSE(
    	[AC_LANG_PROGRAM([], [int x = 1;])],
    	AC_MSG_RESULT(yes)
    	[AST_UNDEFINED_SANITIZER=1],
    
    	AC_MSG_RESULT(no)
    )
    CFLAGS="${saved_sanitize_CFLAGS}"
    LDFLAGS="${saved_sanitize_LDFLAGS}"
    AC_SUBST(AST_UNDEFINED_SANITIZER)
    
    
    AC_MSG_CHECKING(for -Wdeclaration-after-statement support)
    
    if $(${CC} -Wdeclaration-after-statement -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
    
    	AC_MSG_RESULT(yes)
    	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 -Wtrampolines support)
    
    if $(${CC} -Wtrampolines -Werror -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} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
    
    	AC_MSG_RESULT(yes)
    
    	AST_FORTIFY_SOURCE="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
    
    else
    	AC_MSG_RESULT(no)
    	AST_FORTIFY_SOURCE=
    fi
    AC_SUBST(AST_FORTIFY_SOURCE)
    
    
    AC_MSG_CHECKING(for -fno-strict-overflow)
    if $(${CC} -O2 -fno-strict-overflow -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
    
    	AC_MSG_RESULT(yes)
    	AST_NO_STRICT_OVERFLOW=-fno-strict-overflow
    
    else
    	AC_MSG_RESULT(no)
    	AST_NO_STRICT_OVERFLOW=
    fi
    AC_SUBST(AST_NO_STRICT_OVERFLOW)
    
    AC_MSG_CHECKING(for -Wno-format-truncation)
    
    if $(${CC} -Wno-format-truncation -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
    
    	AC_MSG_RESULT(yes)
    	AST_NO_FORMAT_TRUNCATION=-Wno-format-truncation
    else
    	AC_MSG_RESULT(no)
    	AST_NO_FORMAT_TRUNCATION=
    fi
    AC_SUBST(AST_NO_FORMAT_TRUNCATION)
    
    
    Corey Farrell's avatar
    Corey Farrell committed
    AC_MSG_CHECKING(for -Wno-stringop-truncation)
    if $(${CC} -Wno-stringop-truncation -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
    	AC_MSG_RESULT(yes)
    	AST_NO_STRINGOP_TRUNCATION=-Wno-stringop-truncation
    else
    	AC_MSG_RESULT(no)
    	AST_NO_STRINGOP_TRUNCATION=
    fi
    AC_SUBST(AST_NO_STRINGOP_TRUNCATION)
    
    
    if $(${CC} -Wshadow -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1); then
    
    	AC_MSG_RESULT(yes)
    	AST_SHADOW_WARNINGS=-Wshadow
    else
    	AC_MSG_RESULT(no)
    	AST_SHADOW_WARNINGS=
    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
    
    	AC_MSG_RESULT(yes)
    	AST_NATIVE_ARCH=1
    
    else
    	AC_MSG_RESULT(no)
    
    AC_SUBST(AST_NATIVE_ARCH)
    
    dnl Check to see if rpath should be set in LDFLAGS
    AC_ARG_ENABLE(rpath,
    
    	[AS_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 "${OSARCH}" = "NetBSD"; then
    	AST_RPATH="-Wl,-rpath,/usr/pkg/lib"
    fi
    
    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}"
    
    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_MSG_RESULT(yes)
            AC_DEFINE([HAVE_SYSINFO], 1, [Define to 1 if your system has sysinfo support]),
            AC_MSG_RESULT(no)
    )
    
    
    AC_SEARCH_LIBS(res_9_ninit, resolv)
    
    			#ifdef HAVE_SYS_SOCKET_H
    			#include <sys/socket.h>
    			#endif
    			#ifdef HAVE_NETINET_IN_H
    			#include <netinet/in.h>
    			#endif
    			#ifdef HAVE_ARPA_NAMESER_H
    			#include <arpa/nameser.h>
    			#endif
    			#include <resolv.h>],
    
    	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(
    
    				#ifdef HAVE_SYS_SOCKET_H
    				#include <sys/socket.h>
    				#endif
    				#ifdef HAVE_NETINET_IN_H
    				#include <netinet/in.h>
    				#endif
    				#ifdef HAVE_ARPA_NAMESER_H
    				#include <arpa/nameser.h>
    				#endif
    				#include <resolv.h>],
    
    		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_SEARCH_LIBS(res_9_close, resolv)
    	AC_MSG_CHECKING(for res_close)
    	AC_LINK_IFELSE(
    
    				#ifdef HAVE_SYS_SOCKET_H
    				#include <sys/socket.h>
    				#endif
    				#ifdef HAVE_NETINET_IN_H
    				#include <netinet/in.h>
    				#endif
    				#ifdef HAVE_ARPA_NAMESER_H
    				#include <arpa/nameser.h>
    				#endif
    				#include <resolv.h>],
    
    		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)
    
    David M. Lee's avatar
    David M. Lee committed
    AC_MSG_CHECKING(for BIND_8_COMPAT required)
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
    [[
    #undef BIND_8_COMPAT
    #include <arpa/nameser.h>
    ]],
    [[int x = NXDOMAIN]])],
    AC_MSG_RESULT(no),
    AC_MSG_RESULT(yes)
    [BIND8_CFLAGS=-DBIND_8_COMPAT])
    AC_SUBST(BIND8_CFLAGS)
    
    
    AST_C_DEFINE_CHECK([GLOB_NOMAGIC], [GLOB_NOMAGIC], [glob.h])
    
    AST_C_DEFINE_CHECK([GLOB_BRACE], [GLOB_BRACE], [glob.h])
    
    
    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_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]]])
    
    elif 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]]])
    
    elif 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]]])
    
    AC_MSG_CHECKING(for dladdr in dlfcn.h)
    PBX_DLADDR=0
    old_LIBS=${LIBS}
    LIBS="${LIBS} -ldl"
    AC_LINK_IFELSE(
    
    #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}
    
    
    # re-check without -ldl
    # Non-Linux platforms like FreeBSD and NetBSD do not need a library libdl.so.
    if test "${PBX_DLADDR}" = "0"; then
    	AC_MSG_CHECKING(for dladdr in dlfcn.h without -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)
    	)
    fi
    
    
    AST_EXT_LIB_CHECK([ALSA], [asound], [snd_pcm_open], [alsa/asoundlib.h])
    
    AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_openr], [bfd.h])
    
    # Fedora/RedHat/CentOS require extra libraries
    AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_openr], [bfd.h], [-ldl -liberty])
    # openSUSE requires -lz
    AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_openr], [bfd.h], [-ldl -liberty -lz])
    
    case "${OSARCH}" in
    linux*)
    
      AST_EXT_LIB_CHECK([CAP], [cap], [cap_from_text], [sys/capability.h])
    
    AST_C_DEFINE_CHECK([DAHDI], [DAHDI_RESET_COUNTERS], [dahdi/user.h], [230])
    AST_C_DEFINE_CHECK([DAHDI], [DAHDI_DEFAULT_MTU_MRU], [dahdi/user.h], [220])
    AST_C_DEFINE_CHECK([DAHDI], [DAHDI_CODE], [dahdi/user.h], [200])
    
    AST_C_DEFINE_CHECK([DAHDI_HALF_FULL], [DAHDI_POLICY_HALF_FULL], [dahdi/user.h])
    
    
    AST_C_COMPILE_CHECK([DAHDI_LINEREVERSE_VMWI], [struct dahdi_vmwi_info booger], [dahdi/user.h], , [enhanced dahdi vmwi support])
    
    
    AST_C_COMPILE_CHECK([DAHDI_ECHOCANCEL_FAX_MODE], [int foo = DAHDI_ECHOCANCEL_FAX_MODE], [dahdi/user.h])
    
    
    AST_C_COMPILE_CHECK([GETIFADDRS], [struct ifaddrs *p; getifaddrs(&p)], [ifaddrs.h], , [getifaddrs() support])
    
    AST_C_COMPILE_CHECK([TIMERFD], [timerfd_create(0,0); timerfd_settime(0,0,NULL,NULL);], [sys/timerfd.h], , [timerfd support])
    
       if test "${GSM_DIR}" = "internal"; then
          GSM_SYSTEM="no"
       elif test "${GSM_DIR}" != ""; then
          GSM_INTERNAL="no"
       fi
    
          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
    
          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
    
             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
    
             elif 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
             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
    
          AC_DEFINE_UNQUOTED([HAVE_GSM_HEADER], 1, [Define to indicate that gsm.h has no prefix for its location])
    
    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
    
    
    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])
    
    # 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([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])
    
    	saved_cppflags="${CPPFLAGS}"
    	saved_libs="${LIBS}"
    
    	switch_to_system_on_failure="no"
    
    	if test "${IMAP_TK_DIR}" = ""; then
    		IMAP_TK_DIR=`pwd`"/../imap-2004g"
    
    		switch_to_system_on_failure="yes"
    
    	fi
    	if test "${IMAP_TK_DIR}" != "system"; then
    		AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
    		if test -f "${IMAP_TK_DIR}/c-client/LDFLAGS"; then
          		imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
    		fi
    		imap_libs="${IMAP_TK_DIR}/c-client/c-client.a"
    	  	imap_include="-I${IMAP_TK_DIR}/c-client"
          	CPPFLAGS="${CPPFLAGS} ${imap_include}"
    	  	LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
    	  	AC_LINK_IFELSE(
    
    				[#include "c-client.h"
    				void mm_searched (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_exists (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_expunged (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_flags (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_notify (MAILSTREAM *stream,char *string,long errflg)
    				{
    				}
    				void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    				{
    				}
    				void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    				{
    				}
    				void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
    				{
    				}
    				void mm_log (char *string,long errflg)
    				{
    				}
    				void mm_dlog (char *string)
    				{
    				}
    				void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
    				{
    				}
    				void mm_critical (MAILSTREAM *stream)
    				{
    				}
    				void mm_nocritical (MAILSTREAM *stream)
    				{
    				}
    				long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
    				{
    				}
    				void mm_fatal (char *string)
    				{
    				}],
    				[
    				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(
    
    					[#include "c-client.h"
    					void mm_searched (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_exists (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_expunged (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_flags (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_notify (MAILSTREAM *stream,char *string,long errflg)
    					{
    					}
    					void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    					{
    					}
    					void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    					{
    					}
    					void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
    					{
    					}
    					void mm_log (char *string,long errflg)
    					{
    					}
    					void mm_dlog (char *string)
    					{
    					}
    					void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
    					{
    					}
    					void mm_critical (MAILSTREAM *stream)
    					{
    					}
    					void mm_nocritical (MAILSTREAM *stream)
    					{
    					}
    					long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
    					{
    					}
    					void mm_fatal (char *string)
    					{
    					}],
    					[
    					long check = mail_expunge_full(NULL, "", 0);
    					]
    
    				[ac_cv_imap_tk2006="yes"],
    				[ac_cv_imap_tk2006="no"]
    			)
    		fi
    		CPPFLAGS="${saved_cppflags}"
    		LIBS="${saved_libs}"
    
    		if test "${ac_cv_imap_tk}" = "no"; then
    
    			if test "${switch_to_system_on_failure}" = "yes"; then
    				IMAP_TK_DIR="system"
    
    			else #This means they specified a directory. Search for a package installation there too
    				AC_MSG_CHECKING([for system c-client library...])
    				CPPFLAGS="${saved_cppflags}"
    				LIBS="${saved_libs}"
    				imap_include="-I${IMAP_TK_DIR}/include"
    
    				imap_ldflags="-L${IMAP_TK_DIR}/lib"
    
    				imap_libs="-lc-client"
    				CPPFLAGS="${CPPFLAGS} ${imap_include}"
    				LIBS="${LIBS} ${imap_libs} ${imap_ldflags}"
    				AC_LINK_IFELSE(
    
    						[#include "c-client.h"
    						void mm_searched (MAILSTREAM *stream,unsigned long number)
    						{
    						}
    						void mm_exists (MAILSTREAM *stream,unsigned long number)
    						{
    						}
    						void mm_expunged (MAILSTREAM *stream,unsigned long number)
    						{
    						}
    						void mm_flags (MAILSTREAM *stream,unsigned long number)
    						{
    						}
    						void mm_notify (MAILSTREAM *stream,char *string,long errflg)
    						{
    						}
    						void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    						{
    						}
    						void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    						{
    						}
    						void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
    						{
    						}
    						void mm_log (char *string,long errflg)
    						{
    						}
    						void mm_dlog (char *string)
    						{
    						}
    						void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
    						{
    						}
    						void mm_critical (MAILSTREAM *stream)
    						{
    						}
    						void mm_nocritical (MAILSTREAM *stream)
    						{
    						}
    						long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
    						{
    						}
    						void mm_fatal (char *string)
    						{
    						}],
    						[
    						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(
    
    							[#include "c-client.h"
    							void mm_searched (MAILSTREAM *stream,unsigned long number)
    							{
    							}
    							void mm_exists (MAILSTREAM *stream,unsigned long number)
    							{
    							}
    							void mm_expunged (MAILSTREAM *stream,unsigned long number)
    							{
    							}
    							void mm_flags (MAILSTREAM *stream,unsigned long number)
    							{
    							}
    							void mm_notify (MAILSTREAM *stream,char *string,long errflg)
    							{
    							}
    							void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    							{
    							}
    							void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    							{
    							}
    							void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
    							{
    							}
    							void mm_log (char *string,long errflg)
    							{
    							}
    							void mm_dlog (char *string)
    							{
    							}
    							void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
    							{
    							}
    							void mm_critical (MAILSTREAM *stream)
    							{
    							}
    							void mm_nocritical (MAILSTREAM *stream)
    							{
    							}
    							long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
    							{
    							}
    							void mm_fatal (char *string)
    							{
    							}],
    							[
    							long check = mail_expunge_full(NULL, "", 0);
    							]
    
    						[ac_cv_imap_tk2006="yes"],
    						[ac_cv_imap_tk2006="no"]
    					)
    				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...])
    
    		CPPFLAGS="${saved_cppflags}"
    		LIBS="${saved_libs}"
    
    		imap_libs="-lcrypto -lssl -lc-client"
    
    		imap_include="-DUSE_SYSTEM_IMAP" #Try the imap directory first
    		CPPFLAGS="${CPPFLAGS} ${imap_include}"
    		LIBS="${LIBS} ${imap_libs} "`echo ${imap_ldflags}`
    		AC_LINK_IFELSE(
    
    				[#include <stdio.h>
    				#include <imap/c-client.h>
    				void mm_searched (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_exists (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_expunged (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_flags (MAILSTREAM *stream,unsigned long number)
    				{
    				}
    				void mm_notify (MAILSTREAM *stream,char *string,long errflg)
    				{
    				}
    				void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    				{
    				}
    				void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    				{
    				}
    				void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
    				{
    				}
    				void mm_log (char *string,long errflg)
    				{
    				}
    				void mm_dlog (char *string)
    				{
    				}
    				void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
    				{
    				}
    				void mm_critical (MAILSTREAM *stream)
    				{
    				}
    				void mm_nocritical (MAILSTREAM *stream)
    				{
    				}
    				long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
    				{
    				}
    				void mm_fatal (char *string)
    				{
    				}],
    				[
    				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(
    
    					[#include <stdio.h>
    					#include <imap/c-client.h>
    					void mm_searched (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_exists (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_expunged (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_flags (MAILSTREAM *stream,unsigned long number)
    					{
    					}
    					void mm_notify (MAILSTREAM *stream,char *string,long errflg)
    					{
    					}
    					void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    					{
    					}
    					void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
    					{
    					}
    					void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
    					{
    					}
    					void mm_log (char *string,long errflg)
    					{
    					}
    					void mm_dlog (char *string)
    					{
    					}
    					void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
    					{
    					}
    					void mm_critical (MAILSTREAM *stream)
    					{