We have autoconf...let's actually use it.
[asterisk/asterisk.git] / configure.ac
1 # Process this file with autoconf to produce a configure script.
2
3 AC_PREREQ(2.60)
4
5 m4_define([PBX_VERSION],
6           m4_bpatsubst(m4_esyscmd([build_tools/make_version .]),
7                        [\([0-9.]*\)\(\w\|\W\)*],
8                        [\1]))
9 AC_INIT(asterisk, PBX_VERSION, www.asterisk.org)
10
11 # cross-compile macros
12 AC_CANONICAL_BUILD
13 AC_CANONICAL_HOST
14
15 # check existence of the package
16 AC_CONFIG_SRCDIR([main/asterisk.c])
17
18 # specify output header file
19 AC_CONFIG_HEADER(include/asterisk/autoconfig.h)
20
21 AC_COPYRIGHT("Asterisk")
22 AC_REVISION($Revision$)
23
24 case "${host_os}" in
25      freebsd*)
26      ac_default_prefix=/usr/local
27      ;;
28      *)
29      ac_default_prefix=/usr
30      if test ${sysconfdir} = '${prefix}/etc'; then
31         sysconfdir=/etc
32      fi
33      if test ${mandir} = '${prefix}/man'; then
34         mandir=/usr/share/man
35      fi
36      ;;
37 esac
38
39 if test ${localstatedir} = '${prefix}/var'; then
40      localstatedir=/var
41 fi
42
43 BUILD_PLATFORM=${build}
44 BUILD_CPU=${build_cpu}
45 BUILD_VENDOR=${build_vendor}
46 BUILD_OS=${build_os}
47
48 AC_SUBST(BUILD_PLATFORM)
49 AC_SUBST(BUILD_CPU)
50 AC_SUBST(BUILD_VENDOR)
51 AC_SUBST(BUILD_OS)
52
53 HOST_PLATFORM=${host}
54 HOST_CPU=${host_cpu}
55 HOST_VENDOR=${host_vendor}
56 HOST_OS=${host_os}
57
58 AC_SUBST(HOST_PLATFORM)
59 AC_SUBST(HOST_CPU)
60 AC_SUBST(HOST_VENDOR)
61 AC_SUBST(HOST_OS)
62
63 #  check for uname
64 AC_PATH_TOOL([UNAME], [uname], No)
65 if test ! x"${UNAME}" = xNo; then
66    PBX_OSREV=$(${UNAME} -r)
67 fi
68 AC_SUBST(PBX_OSREV)
69
70 # This needs to be before any macros that use the C compiler
71 AC_GNU_SOURCE
72
73 AH_TOP(
74 #ifndef ASTERISK_AUTOCONFIG_H
75 #define ASTERISK_AUTOCONFIG_H
76
77 #include "asterisk/buildopts.h"
78
79 #ifndef _REENTRANT
80 #define _REENTRANT
81 #endif
82 )
83
84 AH_BOTTOM(
85 #endif
86 )
87
88 # cross-compile checks
89 if test "${cross_compiling}" = "yes"; 
90 then
91    AC_CHECK_TOOL(CC, gcc, :)
92    AC_CHECK_TOOL(CXX, g++, :)
93    AC_CHECK_TOOL(LD, ld, :)
94    AC_CHECK_TOOL(RANLIB, ranlib, :)
95    AC_CHECK_TOOL(AR, ar, :)
96 fi
97
98 # Checks for programs.
99 AC_PROG_CC
100 AC_PROG_CXX
101 AC_PROG_CPP
102 AC_PROG_CXXCPP
103 AC_PROG_AWK
104 AC_PROG_INSTALL
105 AC_PROG_LN_S
106 AC_PROG_RANLIB
107 AST_CHECK_GNU_MAKE
108
109 # http://www.mail-archive.com/bug-make@gnu.org/msg02871.html
110 echo 'define A' > testMakefile
111 echo '12345: $(1:.idl=.hh) $(1:.idl=S.h) $(1:.idl=C.h) $(1:.idl=SK.cc) $(1:.idl=DynSK.cc)' >> testMakefile
112 echo 'endef' >> testMakefile
113 echo '$(eval $(call A,01234567890123456789012345678901.idl))' >> testMakefile
114 echo '01234567890123456789012345678901.hh:' >> testMakefile
115 echo '01234567890123456789012345678901S.h:' >> testMakefile
116 echo '01234567890123456789012345678901C.h:' >> testMakefile
117 echo '01234567890123456789012345678901SK.cc:' >> testMakefile
118 echo '01234567890123456789012345678901DynSK.cc:' >> testMakefile
119 $GNU_MAKE -r -f testMakefile 2>&1 > /dev/null
120 if test "$?" != "0" ; then
121   rm -f testMakefile
122   AC_MSG_NOTICE(********** ERROR **********)
123   AC_MSG_NOTICE(Your version of GNU Make contains a bug that will cause the Asterisk build)
124   AC_MSG_NOTICE(system to not function properly.  This bug is known to be fixed in version)
125   AC_MSG_NOTICE(3.81 as well as distributions of 3.80 that contain backported bug fixes.  You)
126   AC_MSG_NOTICE(must update GNU make to build Asterisk.)
127   AC_MSG_NOTICE(***************************)
128   exit 1
129 fi
130 rm -f testMakefile
131
132 AC_PATH_PROG([GREP], [grep], :)
133 AC_PATH_PROG([AR], [ar], :)
134 AC_PATH_PROG([FIND], [find], :)
135 AC_PATH_PROG([COMPRESS], [compress], :)
136 AC_PATH_PROG([BASENAME], [basename], :)
137 AC_PATH_PROG([ID], [id], :)
138 AC_PATH_PROG([DIRNAME], [dirname], :)
139 AC_PATH_PROG([SHELL], [sh], :)
140 AC_PATH_PROG([LN], [ln], :)
141 AC_PATH_PROG([DOT], [dot], :)
142
143 AC_LANG(C)
144
145 AC_ARG_ENABLE(dev-mode,
146         [  --enable-dev-mode    Turn on developer mode],
147         [case "${enableval}" in
148               y|ye|yes) AST_DEVMODE=yes ;;
149               n|no)  AST_DEVMODE=no ;;
150               *) AC_MSG_ERROR(bad value ${enableval} for --enable-dev-mode)  ;;
151         esac])
152 AC_SUBST(AST_DEVMODE)
153
154 # package option names should be in alphabetical order
155 # by the --with option name, to make things easier for the users :-)
156
157 AST_EXT_LIB_SETUP([ALSA], [Advanced Linux Sound Architecture], [asound])
158 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
159 AST_EXT_LIB_SETUP([GNUTLS], [GNU TLS support (used for iksemel only)], [gnutls])
160 AST_EXT_LIB_SETUP([GSM], [GSM], [gsm], [, or 'internal'])
161 AST_EXT_LIB_SETUP([IKSEMEL], [Iksemel Jabber Library], [iksemel])
162 AST_EXT_LIB_SETUP([IMAP_TK], [UW IMAP Toolkit], [imap])
163 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
164 AST_EXT_LIB_SETUP([KDE], [KDE], [kde])
165 AST_EXT_LIB_SETUP([MISDN], [mISDN User Library], [misdn])
166 AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
167 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
168 AST_EXT_LIB_SETUP([NETSNMP], [Net-SNMP], [netsnmp])
169 AST_EXT_LIB_SETUP([NEWT], [newt], [newt])
170 AST_EXT_LIB_SETUP([UNIXODBC], [unixODBC], [odbc])
171 AST_EXT_LIB_SETUP([OGG], [OGG], [ogg])
172 AST_EXT_LIB_SETUP([OSPTK], [OSP Toolkit], [osptk])
173 AST_EXT_LIB_SETUP([OSS], [Open Sound System], [oss])
174 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
175 AST_EXT_LIB_SETUP([PGSQL], [PostgreSQL], [postgres])
176 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
177 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
178 AST_EXT_LIB_SETUP([QT], [Qt], [qt])
179 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
180 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
181 AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
182 AST_EXT_LIB_SETUP([SUPPSERV], [mISDN Supplemental Services], [suppserv])
183 AST_EXT_LIB_SETUP([OPENSSL], [OpenSSL], [ssl])
184 AST_EXT_LIB_SETUP([FREETDS], [FreeTDS], [tds])
185 AST_EXT_LIB_SETUP([TERMCAP], [Termcap], [termcap])
186 AST_EXT_LIB_SETUP([TINFO], [Term Info], [tinfo])
187 AST_EXT_LIB_SETUP([TONEZONE], [tonezone], [tonezone])
188 AST_EXT_LIB_SETUP([VORBIS], [Vorbis], [vorbis])
189 AST_EXT_LIB_SETUP([VPB], [Voicetronix API], [vpb])
190 AST_EXT_LIB_SETUP([ZLIB], [zlib], [z])
191 AST_EXT_LIB_SETUP([ZAPTEL], [Zaptel], [zaptel])
192
193 # check for basic system features and functionality before
194 # checking for package libraries
195
196 AC_FUNC_ALLOCA
197 AC_HEADER_DIRENT
198 AC_HEADER_STDC
199 AC_HEADER_SYS_WAIT
200 AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h])
201
202 AC_SYS_LARGEFILE
203
204 # Checks for typedefs, structures, and compiler characteristics.
205 AC_HEADER_STDBOOL
206 AC_C_CONST
207 AC_TYPE_UID_T
208 AC_C_INLINE
209 AC_TYPE_MODE_T
210 AC_TYPE_OFF_T
211 AC_TYPE_PID_T
212 AC_TYPE_SIZE_T
213 AC_CHECK_MEMBERS([struct stat.st_blksize])
214 AC_HEADER_TIME
215 AC_STRUCT_TM
216 AC_C_VOLATILE
217 AC_CHECK_TYPES([ptrdiff_t])
218
219 # Checks for library functions.
220 AC_FUNC_CHOWN
221 AC_FUNC_CLOSEDIR_VOID
222 AC_FUNC_ERROR_AT_LINE
223 AST_FUNC_FORK
224 AC_FUNC_FSEEKO
225 AC_PROG_GCC_TRADITIONAL
226 # XXX: these are commented out until we determine whether it matters if our malloc()
227 # acts exactly like glibc's or not
228 # AC_FUNC_MALLOC
229 # AC_FUNC_REALLOC
230 AC_FUNC_MEMCMP
231 AC_FUNC_MKTIME
232 AC_FUNC_MMAP
233 AC_FUNC_SELECT_ARGTYPES
234 AC_FUNC_SETVBUF_REVERSED
235 AC_TYPE_SIGNAL
236 AC_FUNC_STAT
237 AC_FUNC_STRCOLL
238 AC_FUNC_STRFTIME
239 AC_FUNC_STRNLEN
240 AC_FUNC_STRTOD
241 AC_FUNC_UTIME_NULL
242 AC_FUNC_VPRINTF
243 AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent floor ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap pow putenv re_comp regcomp rint select setenv socket sqrt strcasecmp strcasestr strchr strcspn strdup strerror strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf])
244
245 AC_MSG_CHECKING(for compiler atomic operations)
246 AC_LINK_IFELSE(
247 AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);]),
248 AC_MSG_RESULT(yes)
249 AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
250 AC_MSG_RESULT(no)
251 )
252
253 AST_GCC_ATTRIBUTE(pure)
254 AST_GCC_ATTRIBUTE(malloc)
255 AST_GCC_ATTRIBUTE(const)
256 AST_GCC_ATTRIBUTE(unused)
257 AST_GCC_ATTRIBUTE(always_inline)
258
259 AC_MSG_CHECKING(for -ffunction-sections support)
260 saved_CFLAGS="${CFLAGS}"
261 CFLAGS="${CFLAGS} -ffunction-sections"
262 AC_COMPILE_IFELSE(
263         AC_LANG_PROGRAM([], [int x = 1;]),
264         AC_MSG_RESULT(yes)
265         [saved_LDFLAGS="${LDFLAGS}"]
266         [LDFLAGS="${LDFLAGS} -Wl,--gc-sections"]
267         AC_MSG_CHECKING(for --gc-sections support)
268         AC_LINK_IFELSE(
269                 AC_LANG_PROGRAM([], [int x = 1;]),
270                 AC_MSG_RESULT(yes)
271                 [GC_CFLAGS="-ffunction-sections"]
272                 [[GC_LDFLAGS="-Wl,--gc-sections"]],
273                 AC_MSG_RESULT(no)
274         )
275         [LDFLAGS="${saved_LDFLAGS}"],
276         AC_MSG_RESULT(no)
277 )
278 CFLAGS="${saved_CFLAGS}"
279 AC_SUBST(GC_CFLAGS)
280 AC_SUBST(GC_LDFLAGS)
281
282 AC_MSG_CHECKING(for res_ninit)
283 AC_LINK_IFELSE(
284         AC_LANG_PROGRAM([#include <resolv.h>],
285                         [int foo = res_ninit(NULL);]),
286         AC_MSG_RESULT(yes)
287         AC_DEFINE([HAVE_RES_NINIT], 1, [Define to 1 if your system has the re-entrant resolver functions.]),
288         AC_MSG_RESULT(no)
289 )
290
291 AC_MSG_CHECKING(for RTLD_NOLOAD)
292 AC_LINK_IFELSE(
293         AC_LANG_PROGRAM([#include <dlfcn.h>],
294                         [int foo = RTLD_NOLOAD;]),
295         AC_MSG_RESULT(yes)
296         AC_DEFINE([HAVE_RTLD_NOLOAD], 1, [Define to 1 if your system has a dynamic linker that supports RTLD_NOLOAD.]),
297         AC_MSG_RESULT(no)
298 )
299
300 AC_CHECK_HEADER([libkern/OSAtomic.h],
301                 [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])
302
303 AC_CHECK_SIZEOF(int)
304
305 # do the package library checks now
306
307 AST_EXT_LIB_CHECK([ALSA], [asound], [snd_spcm_init], [alsa/asoundlib.h], [-lm -ldl])
308
309 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
310
311 GSM_INTERNAL="yes"
312 AC_SUBST(GSM_INTERNAL)
313 GSM_SYSTEM="yes"
314 if test "${USE_GSM}" != "no"; then
315    if test "${GSM_DIR}" = "internal"; then
316       GSM_SYSTEM="no"
317    elif test "${GSM_DIR}" != ""; then
318       GSM_INTERNAL="no"
319    fi
320    if test "${GSM_SYSTEM}" = "yes"; then
321       gsmlibdir=""
322       if test "x${GSM_DIR}" != "x"; then
323          if test -d ${GSM_DIR}/lib; then
324             gsmlibdir="-L${GSM_DIR}/lib"
325          else
326             gsmlibdir="-L${GSM_DIR}"
327          fi
328       fi
329       AC_CHECK_LIB([gsm], [gsm_create], AC_DEFINE_UNQUOTED([HAVE_GSM], 1,
330       [Define to indicate the GSM library]), [], ${gsmlibdir})
331       if test "${ac_cv_lib_gsm_gsm_create}" = "yes"; then
332          GSM_LIB="-lgsm"
333          if test "x${GSM_DIR}" != "x"; then
334             GSM_LIB="${gsmlibdir} ${GSM_LIB}"
335             GSM_INCLUDE="-I${GSM_DIR}/include"
336          fi
337          PBX_GSM=1
338          GSM_INTERNAL="no"
339       fi
340    fi
341    if test "${GSM_INTERNAL}" = "yes"; then
342       PBX_GSM=1
343    fi
344 fi
345
346 AST_EXT_LIB_CHECK([IKSEMEL], [iksemel], [iks_start_sasl], [iksemel.h])
347
348 if test "${PBX_IKSEMEL}" = 1; then
349    AST_EXT_LIB_CHECK([GNUTLS], [gnutls], [gnutls_bye])
350    if test "${PBX_GNUTLS}" = 1; then
351       IKSEMEL_LIB="${IKSEMEL_LIB} -lgnutls -lz -lgcrypt -lnsl -lgpg-error"
352    fi
353 fi
354
355 if test "${USE_IMAP_TK}" != "no"; then
356    if test "${IMAP_TK_DIR}" = ""; then
357       IMAP_TK_DIR=`pwd`"/../imap-2004g"
358    fi
359    AC_MSG_CHECKING(for UW IMAP Toolkit c-client library)
360    saved_cppflags="${CPPFLAGS}"
361    saved_libs="${LIBS}"
362    if test -f ${IMAP_TK_DIR}/c-client/LDFLAGS ; then
363       imap_ldflags=`cat ${IMAP_TK_DIR}/c-client/LDFLAGS`
364    fi
365    CPPFLAGS="${CPPFLAGS} -I${IMAP_TK_DIR}/c-client"
366    LIBS="${LIBS} ${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
367    AC_LINK_IFELSE(
368         AC_LANG_PROGRAM(
369                 [#include "c-client.h"
370                 void mm_searched (MAILSTREAM *stream,unsigned long number)
371                 {
372                 }
373                 void mm_exists (MAILSTREAM *stream,unsigned long number)
374                 {
375                 }
376                 void mm_expunged (MAILSTREAM *stream,unsigned long number)
377                 {
378                 }
379                 void mm_flags (MAILSTREAM *stream,unsigned long number)
380                 {
381                 }
382                 void mm_notify (MAILSTREAM *stream,char *string,long errflg)
383                 {
384                 }
385                 void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
386                 {
387                 }
388                 void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
389                 {
390                 }
391                 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
392                 {
393                 }
394                 void mm_log (char *string,long errflg)
395                 {
396                 }
397                 void mm_dlog (char *string)
398                 {
399                 }
400                 void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
401                 {
402                 }
403                 void mm_critical (MAILSTREAM *stream)
404                 {
405                 }
406                 void mm_nocritical (MAILSTREAM *stream)
407                 {
408                 }
409                 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
410                 {
411                 }
412                 void mm_fatal (char *string)
413                 {
414                 }],
415                 [
416                 MAILSTREAM *foo = mail_open(NULL, "", 0);
417                 ]
418         ),
419         [ac_cv_imap_tk="yes"],
420         [ac_cv_imap_tk="no"]
421    )
422    if test "${ac_cv_imap_tk}" = "yes"; then
423    AC_LINK_IFELSE(
424       AC_LANG_PROGRAM(
425          [#include "c-client.h"
426          void mm_searched (MAILSTREAM *stream,unsigned long number)
427          {
428          }
429          void mm_exists (MAILSTREAM *stream,unsigned long number)
430          {
431          }
432          void mm_expunged (MAILSTREAM *stream,unsigned long number)
433          {
434          }
435          void mm_flags (MAILSTREAM *stream,unsigned long number)
436          {
437          }
438          void mm_notify (MAILSTREAM *stream,char *string,long errflg)
439          {
440          }
441          void mm_list (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
442          {
443          }
444          void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
445          {
446          }
447          void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
448          {
449          }
450          void mm_log (char *string,long errflg)
451          {
452          }
453          void mm_dlog (char *string)
454          {
455          }
456          void mm_login (NETMBX *mb,char *user,char *pwd,long trial)
457          {
458          }
459          void mm_critical (MAILSTREAM *stream)
460          {
461          }
462          void mm_nocritical (MAILSTREAM *stream)
463          {
464          }
465          long mm_diskerror (MAILSTREAM *stream,long errcode,long serious)
466          {
467          }
468          void mm_fatal (char *string)
469          {
470          }],
471          [
472          long check = mail_expunge_full(NULL, "", 0);
473          ]
474       ),
475       [ac_cv_imap_tk2006="yes"],
476       [ac_cv_imap_tk2006="no"]
477   )
478   fi
479    CPPFLAGS="${saved_cppflags}"
480    LIBS="${saved_libs}"
481    if test "${ac_cv_imap_tk}" = "yes"; then
482       AC_MSG_RESULT(yes) 
483       IMAP_TK_LIB="${IMAP_TK_DIR}/c-client/c-client.a "`echo ${imap_ldflags}`
484       IMAP_TK_INCLUDE="-I${IMAP_TK_DIR}/c-client"
485       PBX_IMAP_TK=1
486       AC_DEFINE([HAVE_IMAP_TK], 1, [Define if your system has the UW IMAP Toolkit c-client library.])
487       if test "${ac_cv_imap_tk2006}" = "yes"; then
488          AC_DEFINE([HAVE_IMAP_TK2006], 1, [Define if your system has the UW IMAP Toolkit c-client library version 2006 or greater.])
489       fi
490    elif test ! -z "${IMAP_TK_MANDATORY}"; then
491       AC_MSG_RESULT(no) 
492       AC_MSG_NOTICE(***)
493       AC_MSG_NOTICE(*** The UW IMAP Toolkit installation on this system appears to be broken.)
494       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
495       AC_MSG_NOTICE(*** including --without-imap.)
496       exit 1
497    else
498       AC_MSG_RESULT(no) 
499    fi
500 fi
501
502 AC_LANG_PUSH(C++)
503
504 if test "${USE_KDE}" != "no"; then
505    AC_MSG_CHECKING(for crashHandler in -lkdecore)
506    saved_libs="${LIBS}"
507    saved_cppflags="${CPPFLAGS}"
508    CPPFLAGS="${CPPFLAGS} -I${KDE_DIR}/include"
509    if test -d ${KDE_DIR}/lib; then
510       kdelibdir="${KDE_DIR}/lib"
511    else
512       kdelibdir="${KDE_DIR}"
513    fi
514    LIBS="${LIBS} -L${kdelibdir} -lkdecore"
515
516    AC_LINK_IFELSE(
517         [AC_LANG_PROGRAM(
518                         [#include "kcrash.h"],
519                         [KCrash::defaultCrashHandler(1);])
520         ],
521         [ac_cv_lib_kde_crash="yes"],
522         [ac_cv_lib_kde_crash="no"])
523                 
524    LIBS="${saved_libs}"
525    CPPFLAGS="${saved_cppflags}"
526         
527    if test "${ac_cv_lib_kde_crash}" = "yes"; then
528       AC_MSG_RESULT(yes) 
529       KDE_LIB="-lkdecore -lkdeui"
530       if test "${KDE_DIR}" != ""; then
531          KDE_LIB="-L${kdelibdir} ${KDE_LIB}"
532          KDE_INCLUDE="-I${KDE_DIR}/include"
533       fi
534       PBX_KDE=1
535       AC_DEFINE([HAVE_LIBKDE], 1, [Define if your system has the KDE libraries.])
536    elif test ! -z "${KDE_MANDATORY}"; then
537       AC_MSG_RESULT(no) 
538       AC_MSG_NOTICE(***)
539       AC_MSG_NOTICE(*** The KDE installation on this system appears to be broken.)
540       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
541       AC_MSG_NOTICE(*** including --without-kde.)
542       exit 1
543    else
544       AC_MSG_RESULT(no) 
545    fi
546 fi
547 if test "${PBX_KDE}" = 1; then
548    AC_PATH_TOOL(KDEINIT, kdeinit, No)
549    if test ! x"${KDEINIT}" = xNo; then
550       KDEDIR=$(${DIRNAME} ${KDEINIT})
551       KDEDIR=$(${DIRNAME} ${KDEDIR})
552    fi
553    AC_SUBST([KDEDIR])
554 fi
555
556 AC_LANG_POP
557
558 AST_EXT_LIB_CHECK([MISDN], [mISDN], [mISDN_open], [mISDNuser/mISDNlib.h])
559
560 if test "${PBX_MISDN}" = 1; then
561    AST_EXT_LIB_CHECK([ISDNNET], [isdnnet], [init_manager], [mISDNuser/isdn_net.h], [-lmISDN -lpthread])
562    AST_EXT_LIB_CHECK([SUPPSERV], [suppserv], [encodeFac], [mISDNuser/suppserv.h])
563 fi
564
565 AST_EXT_LIB_CHECK([NBS], [nbs], [nbs_connect], [nbs.h])
566
567 AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
568
569 NETSNMP_CONFIG=No
570 if test "${USE_NETSNMP}" != "no"; then  
571    if test "x${NETSNMP_DIR}" != "x"; then
572       AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], No, [${NETSNMP_DIR}/bin])
573       if test x"${NETSNMP_CONFIG}" = xNo; then
574          AC_MSG_NOTICE(***)
575          AC_MSG_NOTICE(*** net-snmp-config was not found in the path you specified:)
576          AC_MSG_NOTICE(*** ${NETSNMP_DIR}/bin)
577          AC_MSG_NOTICE(*** Either correct the installation, or run configure)
578          AC_MSG_NOTICE(*** including --without-netsnmp)
579          exit 1
580       fi
581    else
582       AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], No)
583    fi
584 fi
585 if test x"${NETSNMP_CONFIG}" != xNo; then
586    NETSNMP_libs=`net-snmp-config --agent-libs`
587    
588    AC_CHECK_LIB([netsnmp], [snmp_register_callback], AC_DEFINE_UNQUOTED([HAVE_NETSNMP], 1,
589    [Define to indicate the Net-SNMP library]), [], ${NETSNMP_libs})
590
591    if test "${ac_cv_lib_netsnmp_snmp_register_callback}" = "yes"; then
592       NETSNMP_LIB="${NETSNMP_libs}"
593       PBX_NETSNMP=1
594    elif test ! -z "${NETSNMP_MANDATORY}";
595    then
596       AC_MSG_NOTICE(***)
597       AC_MSG_NOTICE(*** The Net-SNMP installation on this system appears to be broken.)
598       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
599       AC_MSG_NOTICE(*** including --without-netsnmp)
600       exit 1
601    fi
602 elif test ! -z "${NETSNMP_MANDATORY}";
603 then
604    AC_MSG_NOTICE(***)
605    AC_MSG_NOTICE(*** The Net-SNMP installation on this system appears to be broken.)
606    AC_MSG_NOTICE(*** Either correct the installation, or run configure)
607    AC_MSG_NOTICE(*** including --without-netsnmp)
608    exit 1
609 fi
610
611 AST_EXT_LIB_CHECK([NEWT], [newt], [newtBell], [newt.h])
612
613 AST_EXT_LIB_CHECK([UNIXODBC], [odbc], [SQLConnect], [sql.h], [-lltdl])
614
615 AST_EXT_LIB_CHECK([OGG], [ogg], [ogg_sync_init], [])
616
617 AST_EXT_LIB_CHECK([OSPTK], [osptk], [OSPPCryptoDecrypt], [osp/osp.h], [-lcrypto -lssl])
618
619 PBX_OSS=0
620 AC_CHECK_HEADER([linux/soundcard.h],
621                 [
622                 PBX_OSS=1
623                 AC_DEFINE_UNQUOTED([HAVE_OSS], 1, [Define to indicate the Open Sound System library])
624                 ])
625 if test "$PBX_OSS" = "0"; then
626    AC_CHECK_HEADER([sys/soundcard.h],
627                    [
628                    PBX_OSS=1
629                    AC_DEFINE_UNQUOTED([HAVE_OSS], 1, [Define to indicate the Open Sound System library])
630                    ])
631 fi
632 if test "$PBX_OSS" = "0"; then
633    AST_EXT_LIB_CHECK([OSS], [ossaudio], [oss_ioctl_mixer], [soundcard.h])
634 fi
635
636 PG_CONFIG=No
637 if test "${USE_PGSQL}" != "no"; then    
638    if test "x${PGSQL_DIR}" != "x"; then
639       AC_PATH_TOOL([PG_CONFIG], [pg_config], No, [${PGSQL_DIR}/bin])
640       if test x"${PG_CONFIG}" = xNo; then
641          AC_MSG_NOTICE(***)
642          AC_MSG_NOTICE(*** pg_config was not found in the path you specified:)
643          AC_MSG_NOTICE(*** ${PGSQL_DIR}/bin)
644          AC_MSG_NOTICE(*** Either correct the installation, or run configure)
645          AC_MSG_NOTICE(*** including --without-postgres)
646          exit 1
647       fi
648    else
649       AC_PATH_TOOL([PG_CONFIG], [pg_config], No)
650    fi
651 fi
652 if test "${PG_CONFIG}" != No; then
653    PGSQL_libdir=`pg_config --libdir`
654    PGSQL_includedir=`pg_config --includedir`
655    
656    AC_CHECK_LIB([pq], [PQexec], AC_DEFINE_UNQUOTED([HAVE_PGSQL], 1,
657    [Define to indicate the PostgreSQL library]), [], -L${PGSQL_libdir} -lz)
658
659    if test "${ac_cv_lib_pq_PQexec}" = "yes"; then
660       PGSQL_LIB="-L${PGSQL_libdir} -lpq -lz -lcrypt"
661       PGSQL_INCLUDE="-I${PGSQL_includedir}"
662       PBX_PGSQL=1
663    elif test ! -z "${PGSQL_MANDATORY}";
664    then
665       AC_MSG_NOTICE(***)
666       AC_MSG_NOTICE(*** The PostgreSQL installation on this system appears to be broken.)
667       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
668       AC_MSG_NOTICE(*** including --without-postgres)
669       exit 1
670    fi
671 elif test ! -z "${PGSQL_MANDATORY}";
672 then
673    AC_MSG_NOTICE(***)
674    AC_MSG_NOTICE(*** The PostgreSQL installation on this system appears to be broken.)
675    AC_MSG_NOTICE(*** Either correct the installation, or run configure)
676    AC_MSG_NOTICE(*** including --without-postgres)
677    exit 1
678 fi
679
680 AST_EXT_LIB_CHECK([POPT], [popt], [poptStrerror], [popt.h])
681
682 AST_EXT_LIB_CHECK([PRI], [pri], [pri_call], [libpri.h])
683
684 PLATFORM_PTLIB="ptlib_${OSTYPE}_${MACHTYPE}_r"
685 if test "${USE_PWLIB}" != "no"; then
686    AC_MSG_CHECKING(for existence of pwlib)
687         
688    saved_cppflags="${CPPFLAGS}"
689    saved_libs="${LIBS}"
690    LIBS="${LIBS} -L${PWLIB_DIR} -l${PLATFORM_PTLIB}"
691    CPPFLAGS="${CPPFLAGS} -I${PWLIB_DIR}/include"
692         
693    AC_LINK_IFELSE(
694         [
695         AC_LANG_PROGRAM(
696         [#include "ptime.h"],
697         [int q = PTime::IsDaylightSaving();])
698         ],
699         [       AC_MSG_RESULT(yes) 
700                 ac_cv_lib_pwlib="yes" 
701         ],
702         [       AC_MSG_RESULT(no) 
703                 ac_cv_lib_pwlib="no" 
704         ]
705         )
706
707    LIBS="${saved_libs}"
708    CPPFLAGS="${saved_cppflags}"
709
710    if test "${ac_cv_lib_pwlib}" = "yes"; then
711       PWLIB_LIB="-l{PLATFORM_PWLIB}"
712       if test "${PWLIB_DIR}" != ""; then
713          PWLIB_LIB="-L${PWLIB_DIR}/lib ${PWLIB_LIB}"
714          PWLIB_INCLUDE="-I${PWLIB_DIR}/include"
715       fi
716         PBX_PWLIB=1
717         AC_DEFINE([HAVE_PWLIB], 1, [Define if your system has the pwlib libraries.])
718    elif test ! -z "${PWLIB_MANDATORY}"; then
719       AC_MSG_NOTICE(***)
720       AC_MSG_NOTICE(*** The PWLIB installation on this system appears to be broken.)
721       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
722       AC_MSG_NOTICE(*** including --without-pwlib)
723       exit 1
724    fi
725 fi
726
727 AC_LANG_PUSH(C++)
728
729 if test "${USE_QT}" != "no"; then
730    AC_MSG_CHECKING(for QDate in -lqt)
731    saved_libs="${LIBS}"
732    saved_cppflags="${CPPFLAGS}"
733    if test "x${QT_DIR}" != "x"; then
734       LIBS="${LIBS} -L${QT_DIR}/lib"
735       CPPFLAGS="${CPPFLAGS} -I${QT_DIR}/include"
736    fi
737    LIBS="${LIBS} -lqt"
738    qtlib="qt"
739    AC_LINK_IFELSE(
740         [
741                 AC_LANG_PROGRAM(
742                 [#include <qt3/qdatetime.h>],
743                 [QDate date();])
744         ],
745         [ac_cv_lib_qt_qt_date="yes"],
746         [ac_cv_lib_qt_qt_date="no"])
747    LIBS="${saved_libs}"
748    CPPFLAGS="${saved_cppflags}"
749         
750    if test "${ac_cv_lib_qt_qt_date}" = "no"; then
751       saved_libs="${LIBS}"
752       saved_cppflags="${CPPFLAGS}"
753       if test "x${QT_DIR}" != "x"; then
754          LIBS="${LIBS} -L${QT_DIR}/lib"
755          CPPFLAGS="${CPPFLAGS} -I${QT_DIR}/include"
756       fi
757       LIBS="${LIBS} -lqt-mt"
758       qtlib="qt-mt"     
759       AC_LINK_IFELSE(
760                 [
761                         AC_LANG_PROGRAM(
762                         [#include <qt3/qdatetime.h>],
763                         [QDate date();])
764                 ],
765                 [ac_cv_lib_qt_qt_date="yes"],
766                 [ac_cv_lib_qt_qt_date="no"])
767       LIBS="${saved_libs}"
768       CPPFLAGS="${saved_cppflags}"
769    fi   
770
771    if test "${ac_cv_lib_qt_qt_date}" = "yes"; then
772       AC_MSG_RESULT(yes) 
773    else
774       AC_MSG_RESULT(no) 
775    fi
776         
777    if test "${ac_cv_lib_qt_qt_date}" = "yes"; then
778       QT_LIB="-l${qtlib}"
779       if test "${QT_DIR}" != ""; then
780          QT_LIB="-L${QT_DIR}/lib ${QT_LIB}"
781          QT_INCLUDE="-I${QT_DIR}/include"
782       fi
783       PBX_QT=1
784       AC_DEFINE([HAVE_QT], 1, [Define if your system has the Qt library])
785       AC_PATH_TOOL(QTMOC, moc, No)
786    elif test ! -z "${QT_MANDATORY}"; 
787    then
788       AC_MSG_NOTICE(***)
789       AC_MSG_NOTICE(*** The Qt installation on this system appears to be broken.)
790       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
791       AC_MSG_NOTICE(*** including --without-qt.)
792       exit 1
793    fi
794 fi
795
796 AC_LANG_POP
797
798 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
799
800 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
801
802 AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])
803
804 AST_EXT_LIB_CHECK([OPENSSL], [ssl], [ssl2_connect], [openssl/ssl.h], [-lcrypto])
805
806 AST_EXT_LIB_CHECK([FREETDS], [tds], [tds_version], [tds.h])
807 if test "${PBX_FREETDS}" != "0";
808 then
809     case `grep TDS_VERSION_NO ${FREETDS_DIR:-/usr/include}/tdsver.h` in
810     *0.63*)
811         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_63"
812         ;;
813     *0.62*)
814         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_0_62"
815         ;;
816     *)
817         FREETDS_INCLUDE="${FREETDS_INCLUDE} -DFREETDS_PRE_0_62"
818         ;;
819     esac
820 fi
821
822 AST_EXT_LIB_CHECK([TERMCAP], [termcap], [tgetent], [])
823
824 AST_EXT_LIB_CHECK([TINFO], [tinfo], [tgetent], [])
825
826 if test "${host_os}" != "linux-gnu" ; then
827   tonezone_extra="-lm"
828 fi
829
830 AST_EXT_LIB_CHECK([TONEZONE], [tonezone], [tone_zone_find], [zaptel/tonezone.h], [${tonezone_extra}])
831
832 AST_EXT_LIB_CHECK([VORBIS], [vorbis], [vorbis_info_init], [vorbis/codec.h], [-lm -lvorbisenc])
833
834 AC_LANG_PUSH(C++)
835
836 if test "${USE_VPB}" != "no"; then
837    AC_MSG_CHECKING(for vpb_open in -lvpb)
838    saved_libs="${LIBS}"
839    saved_cppflags="${CPPFLAGS}"
840    if test "x${VPB_DIR}" != "x"; then
841       if test -d ${VPB_DIR}/lib; then
842          vpblibdir=${VPB_DIR}/lib
843       else
844          vpblibdir=${VPB_DIR}
845       fi
846       LIBS="${LIBS} -L${vpblibdir}"
847       CPPFLAGS="${CPPFLAGS} -I${VPB_DIR}/include"
848    fi
849    LIBS="${LIBS} -lvpb -lpthread"
850    AC_LINK_IFELSE(
851         [
852         AC_LANG_PROGRAM(
853         [#include <vpbapi.h>],
854         [int q = vpb_open(0,0);])
855         ],
856         [       AC_MSG_RESULT(yes) 
857                 ac_cv_lib_vpb_vpb_open="yes" 
858         ],
859         [       AC_MSG_RESULT(no) 
860                 ac_cv_lib_vpb_vpb_open="no" 
861         ]
862         )
863    LIBS="${saved_libs}"
864    CPPFLAGS="${saved_cppflags}"
865    if test "${ac_cv_lib_vpb_vpb_open}" = "yes"; then
866         VPB_LIB="-lvpb"
867         if test "${VPB_DIR}" != ""; then
868            VPB_LIB="-L${vpblibdir}  ${VPB_LIB}"
869            VPB_INCLUDE="-I${VPB_DIR}/include"
870         fi
871         PBX_VPB=1
872         AC_DEFINE([HAVE_VPB], 1, [Define if your system has the VoiceTronix API libraries.])
873    elif test ! -z "${VPB_MANDATORY}"; then
874       AC_MSG_NOTICE(***)
875       AC_MSG_NOTICE(*** The VoiceTronix (vpb) installation on this system appears to be broken.)
876       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
877       AC_MSG_NOTICE(*** including --without-vpb.)
878       exit 1
879    fi
880 fi
881
882 AC_LANG_POP
883
884 AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])
885
886 if test "${USE_ZAPTEL}" != "no"; then
887    AC_MSG_CHECKING(for ZT_TONE_DTMF_BASE in zaptel.h)
888    saved_cppflags="${CPPFLAGS}"
889    if test "x${ZAPTEL_DIR}" != "x"; then
890       CPPFLAGS="${CPPFLAGS} -I${ZAPTEL_DIR}/include"
891    fi
892    AC_COMPILE_IFELSE(
893         [
894         AC_LANG_PROGRAM(
895         [#include <zaptel/zaptel.h>],
896         [int foo = ZT_TONE_DTMF_BASE;])
897         ],
898         [       AC_MSG_RESULT(yes) 
899                 ac_cv_zaptel_h="yes" 
900         ],
901         [       AC_MSG_RESULT(no) 
902                 ac_cv_zaptel_h="no" 
903         ]
904         )
905    CPPFLAGS="${saved_cppflags}"
906    if test "${ac_cv_zaptel_h}" = "yes"; then
907         if test "${ZAPTEL_DIR}" != ""; then
908            ZAPTEL_INCLUDE="-I${ZAPTEL_DIR}/include"
909         fi
910         PBX_ZAPTEL=1
911         AC_DEFINE([HAVE_ZAPTEL], 1, [Define if your system has the Zaptel headers.])
912    elif test ! -z "${ZAPTEL_MANDATORY}"; 
913    then
914       AC_MSG_NOTICE(***)
915       AC_MSG_NOTICE(*** The Zaptel installation on this system appears to be broken.)
916       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
917       AC_MSG_NOTICE(*** including --without-zaptel.)
918       exit 1
919    fi
920 fi
921
922 EDITLINE_LIB=""
923 if test "x$TERMCAP_LIB" != "x" ; then
924   EDITLINE_LIB="$TERMCAP_LIB"
925 elif test "x$TINFO_LIB" != "x" ; then
926   EDITLINE_LIB="$TINFO_LIB"
927 elif test "x$CURSES_LIB" != "x" ; then
928   EDITLINE_LIB="$CURSES_LIB"
929 elif test "x$NCURSES_LIB" != "x" ; then
930   EDITLINE_LIB="$NCURSES_LIB"
931 else
932   AC_MSG_ERROR(*** termcap support not found)
933 fi
934 AC_SUBST(EDITLINE_LIB)
935
936 AC_CHECK_HEADER([h323.h], [PBX_H323=1], [PBX_H323=0])
937 AC_SUBST(PBX_H323)
938
939 AC_CHECK_HEADER([linux/ixjuser.h], [PBX_IXJUSER=1], [PBX_IXJUSER=0], [
940                                    #include <linux/version.h>
941                                    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
942                                    #include <linux/compiler.h>
943                                    #endif
944                                    ])
945 AC_SUBST(PBX_IXJUSER)
946
947 PBX_GTK=0
948 AC_CHECK_TOOL(GTKCONFIG, gtk-config, No)
949 if test ! "x${GTKCONFIG}" = xNo; then
950    GTK_INCLUDE=$(${GTKCONFIG} --cflags gthread)
951    GTK_LIB=$(${GTKCONFIG} --libs gthread)
952    PBX_GTK=1
953    AC_DEFINE([HAVE_GTK], 1, [Define if your system has the GTK libraries.])
954 fi
955 AC_SUBST(PBX_GTK)
956 AC_SUBST(GTK_INCLUDE)
957 AC_SUBST(GTK_LIB)
958
959 PBX_CURL=0
960 AC_PATH_TOOL([CURL], [curl-config], No)
961 if test ! x"${CURL}" = xNo; then
962 # check for version
963    if test "${host_os}" = "SunOS"; then
964       if [[ 0x`curl-config --vernum` -ge 0x70907 ]]; then
965          CURL_INCLUDE=$(${CURL} --cflags)
966          CURL_LIB=$(${CURL} --libs)
967          PBX_CURL=1
968          AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
969       fi
970    else
971       if [[[ 0x`curl-config --vernum` -ge 0x70907 ]]]; then
972          CURL_INCLUDE=$(${CURL} --cflags)
973          CURL_LIB=$(${CURL} --libs)
974          PBX_CURL=1
975          AC_DEFINE([HAVE_CURL], 1, [Define if your system has the curl libraries.])
976       fi
977    fi
978 fi
979 AC_SUBST(PBX_CURL)
980 AC_SUBST(CURL_INCLUDE)
981 AC_SUBST(CURL_LIB)
982
983 AC_CONFIG_FILES([build_tools/menuselect-deps makeopts])
984 AC_OUTPUT
985
986 if test "x${silent}" != "xyes" ; then
987 echo
988 echo "               .\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$=..      "
989 echo "            .\$7\$7..          .7\$\$7:.    "
990 echo "          .\$\$:.                 ,\$7.7   "
991 echo "        .\$7.     7\$\$\$\$           .\$\$77  "
992 echo "     ..\$\$.       \$\$\$\$\$            .\$\$\$7 "
993 echo "    ..7\$   .?.   \$\$\$\$\$   .?.       7\$\$\$."
994 echo "   \$.\$.   .\$\$\$7. \$\$\$\$7 .7\$\$\$.      .\$\$\$."
995 echo " .777.   .\$\$\$\$\$\$77\$\$\$77\$\$\$\$\$7.      \$\$\$,"
996 echo " \$\$\$~      .7\$\$\$\$\$\$\$\$\$\$\$\$\$7.       .\$\$\$."
997 echo ".\$\$7          .7\$\$\$\$\$\$\$7:          ?\$\$\$."
998 echo "\$\$\$          ?7\$\$\$\$\$\$\$\$\$\$I        .\$\$\$7 "
999 echo "\$\$\$       .7\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$      :\$\$\$. "
1000 echo "\$\$\$       \$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$\$\$\$    .\$\$\$.  "
1001 echo "\$\$\$        \$\$\$   7\$\$\$7  .\$\$\$    .\$\$\$.   "
1002 echo "\$\$\$\$             \$\$\$\$7         .\$\$\$.    "
1003 echo "7\$\$\$7            7\$\$\$\$        7\$\$\$      "
1004 echo " \$\$\$\$\$                        \$\$\$       "
1005 echo "  \$\$\$\$7.                       \$\$  (TM)     "
1006 echo "   \$\$\$\$\$\$\$.           .7\$\$\$\$\$\$  \$\$      "
1007 echo "     \$\$\$\$\$\$\$\$\$\$\$\$7\$\$\$\$\$\$\$\$\$.\$\$\$\$\$\$      "
1008 echo "       \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$.                "
1009 echo
1010 fi
1011
1012 AC_MSG_NOTICE(Package configured for: )
1013 AC_MSG_NOTICE( OS type  : $host_os)
1014 AC_MSG_NOTICE( Host CPU : $host_cpu)
1015 if test "${cross_compiling}" = "yes"; then
1016    AC_MSG_NOTICE( Cross Compilation = YES)
1017 fi