start using asterisk/network.h for network related headers.
[asterisk/asterisk.git] / acinclude.m4
1 # AST_GCC_ATTRIBUTE([attribute name])
2
3 AC_DEFUN([AST_GCC_ATTRIBUTE],
4 [
5 AC_MSG_CHECKING(for compiler 'attribute $1' support)
6 AC_COMPILE_IFELSE(
7         AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}],
8                         []),
9         AC_MSG_RESULT(yes)
10         AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
11         AC_MSG_RESULT(no))
12 ])
13
14 # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text])
15
16 AC_DEFUN([AST_EXT_LIB_SETUP],
17 [
18 $1_DESCRIP="$2"
19 $1_OPTION="$3"
20 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),[
21 case ${withval} in
22      n|no)
23      USE_$1=no
24      ;;
25      y|ye|yes)
26      ac_mandatory_list="${ac_mandatory_list} $1"
27      ;;
28      *)
29      $1_DIR="${withval}"
30      ac_mandatory_list="${ac_mandatory_list} $1"
31      ;;
32 esac
33 ])
34 PBX_$1=0
35 AC_SUBST([$1_LIB])
36 AC_SUBST([$1_INCLUDE])
37 AC_SUBST([$1_DIR])
38 AC_SUBST([PBX_$1])
39 ])
40
41 # Check whether any of the mandatory modules are not present, and
42 # print error messages in case.
43
44 AC_DEFUN([AST_CHECK_MANDATORY],
45 [
46         AC_MSG_CHECKING([for mandatory modules: ${ac_mandatory_list}])
47         err=0;
48         for i in ${ac_mandatory_list}; do
49                 eval "a=\${PBX_$i}"
50                 if test "x${a}" = "x1" ; then continue; fi
51                 if test ${err} = "0" ; then AC_MSG_RESULT(fail) ; fi
52                 AC_MSG_RESULT()
53                 eval "a=\${${i}_OPTION}"
54                 AC_MSG_NOTICE([***])
55                 AC_MSG_NOTICE([*** The $i installation appears to be missing or broken.])
56                 AC_MSG_NOTICE([*** Either correct the installation, or run configure])
57                 AC_MSG_NOTICE([*** including --without-${a}.])
58                 err=1
59         done
60         if test $err = 1 ; then exit 1; fi
61         AC_MSG_RESULT(ok)
62 ])
63
64 #-- The following two tests are only performed if PBX_$1 != 1,
65 #   so you can use multiple tests and stop at the first matching one.
66 #   On success, set PBX_$1 = 1, and also #define HAVE_$1 1
67 #   and #define HAVE_$1_VERSION ${last_argument} so you can tell which
68 #   test succeeded.
69 #   They should be called after AST_EXT_LIB_SETUP($1, ...)
70
71 # Check if a given macro is defined in a certain header.
72
73 # AST_C_DEFINE_CHECK([package symbol name], [macro name], [header file], [version])
74 AC_DEFUN([AST_C_DEFINE_CHECK],
75 [
76     if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
77         AC_MSG_CHECKING([for $2 in $3])
78         saved_cppflags="${CPPFLAGS}"
79         if test "x${$1_DIR}" != "x"; then
80             $1_INCLUDE="-I${$1_DIR}/include"
81         fi
82         CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
83
84         AC_COMPILE_IFELSE(
85             [ AC_LANG_PROGRAM( [#include <$3>], [int foo = $2;]) ],
86             [   AC_MSG_RESULT(yes)
87                 PBX_$1=1
88                 AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 headers.])
89                 AC_DEFINE([HAVE_$1_VERSION], $4, [Define $1 headers version])
90             ],
91             [       AC_MSG_RESULT(no) ] 
92         )
93         CPPFLAGS="${saved_cppflags}"
94     fi
95 ])
96
97
98 # Check for existence of a given package ($1), either looking up a function
99 # in a library, or, if no function is supplied, only check for the
100 # existence of the header files.
101
102 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data], [version])
103 AC_DEFUN([AST_EXT_LIB_CHECK],
104 [
105 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
106    pbxlibdir=""
107    if test "x${$1_DIR}" != "x"; then
108       if test -d ${$1_DIR}/lib; then
109          pbxlibdir="-L${$1_DIR}/lib"
110       else
111          pbxlibdir="-L${$1_DIR}"
112       fi
113    fi
114    pbxfuncname="$3"
115    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
116       AST_$1_FOUND=yes
117    else
118       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
119    fi
120
121    if test "${AST_$1_FOUND}" = "yes"; then
122       $1_LIB="-l$2 $5"
123       $1_HEADER_FOUND="1"
124       if test "x${$1_DIR}" != "x"; then
125          $1_LIB="${pbxlibdir} ${$1_LIB}"
126          $1_INCLUDE="-I${$1_DIR}/include"
127          saved_cppflags="${CPPFLAGS}"
128          CPPFLAGS="${CPPFLAGS} -I${$1_DIR}/include"
129          if test "x$4" != "x" ; then
130             AC_CHECK_HEADER([${$1_DIR}/include/$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
131          fi
132          CPPFLAGS="${saved_cppflags}"
133       else
134          if test "x$4" != "x" ; then
135             AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
136          fi
137       fi
138       if test "x${$1_HEADER_FOUND}" = "x0" ; then
139          $1_LIB=""
140          $1_INCLUDE=""
141       else
142          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
143             $1_LIB=""
144          fi
145          PBX_$1=1
146          # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
147          AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define this to indicate the ${$1_DESCRIP} library])
148          AC_DEFINE_UNQUOTED([HAVE_$1_VERSION], [$6], [Define to indicate the ${$1_DESCRIP} library version])
149       fi
150    fi
151 fi
152 ])
153
154
155 # check for a tool using xxx-config
156 # AST_EXT_TOOL_CHECK([package symbol name], [package library name], [symbol], [version])
157 AC_DEFUN([AST_EXT_TOOL_CHECK],
158 [
159 PBX_$1=0
160 AC_CHECK_TOOL(CONFIG_$1, $2-config, No)
161 if test ! "x${CONFIG_$1}" = xNo; then
162    $1_INCLUDE=$(${CONFIG_$1} --cflags $3)
163    $1_LIB=$(${CONFIG_$1} --libs $3)
164    PBX_$1=1
165    AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
166 fi
167 AC_SUBST(PBX_$1)
168 AC_SUBST($1_INCLUDE)
169 AC_SUBST($1_LIB)
170 ])
171
172 AC_DEFUN(
173 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
174    GNU_MAKE='Not Found' ;
175    GNU_MAKE_VERSION_MAJOR=0 ;
176    GNU_MAKE_VERSION_MINOR=0 ;
177    for a in make gmake gnumake ; do
178       if test -z "$a" ; then continue ; fi ;
179       if ( sh -c "$a --version" 2> /dev/null | grep GNU  2>&1 > /dev/null ) ;  then
180          GNU_MAKE=$a ;
181          GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
182          GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
183          break;
184       fi
185    done ;
186 ) ;
187 if test  "x$GNU_MAKE" = "xNot Found"  ; then
188    AC_MSG_ERROR( *** Please install GNU make.  It is required to build Asterisk!)
189    exit 1
190 fi
191 AC_SUBST([GNU_MAKE])
192 ])
193
194
195 AC_DEFUN(
196 [AST_CHECK_PWLIB], [
197 PWLIB_INCDIR=
198 PWLIB_LIBDIR=
199 AC_LANG_PUSH([C++])
200 if test "${PWLIBDIR:-unset}" != "unset" ; then
201   AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
202 fi
203 if test "${HAS_PWLIB:-unset}" = "unset" ; then
204   if test "${OPENH323DIR:-unset}" != "unset"; then
205     AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
206   fi
207   if test "${HAS_PWLIB:-unset}" != "unset" ; then
208     PWLIBDIR="${OPENH323DIR}/../pwlib"
209   else
210     AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
211     if test "${HAS_PWLIB:-unset}" != "unset" ; then
212       PWLIBDIR="${HOME}/pwlib"
213     else
214       AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
215       if test "${HAS_PWLIB:-unset}" != "unset" ; then
216         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
217         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
218           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
219         fi
220         PWLIB_INCDIR="/usr/local/include"
221         PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
222         if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
223           if test "x$LIB64" != "x"; then
224             PWLIB_LIBDIR="/usr/local/lib64"
225           else
226             PWLIB_LIBDIR="/usr/local/lib"
227           fi
228         fi
229         PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
230         PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
231       else
232         AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
233         if test "${HAS_PWLIB:-unset}" != "unset" ; then
234           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
235           PWLIB_INCDIR="/usr/include"
236           PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
237           if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
238             if test "x$LIB64" != "x"; then
239               PWLIB_LIBDIR="/usr/lib64"
240             else
241               PWLIB_LIBDIR="/usr/lib"
242             fi
243           fi
244           PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
245           PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
246         fi
247       fi
248     fi
249   fi
250 fi
251
252 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
253 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
254 #  exit
255 #fi
256
257 if test "${HAS_PWLIB:-unset}" != "unset" ; then
258   if test "${PWLIBDIR:-unset}" = "unset" ; then
259     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
260       PWLIBDIR=`$PTLIB_CONFIG --prefix`
261     else
262       echo "Cannot find ptlib-config - please install and try again"
263       exit
264     fi
265   fi
266
267   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
268     PWLIBDIR="/usr/share/pwlib"
269     PWLIB_INCDIR="/usr/include"
270     if test "x$LIB64" != "x"; then
271       PWLIB_LIBDIR="/usr/lib64"
272     else
273       PWLIB_LIBDIR="/usr/lib"
274     fi
275   fi
276   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
277     PWLIBDIR="/usr/local/share/pwlib"
278     PWLIB_INCDIR="/usr/local/include"
279     if test "x$LIB64" != "x"; then
280       PWLIB_LIBDIR="/usr/local/lib64"
281     else
282       PWLIB_LIBDIR="/usr/local/lib"
283     fi
284   fi
285
286   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
287     PWLIB_INCDIR="${PWLIBDIR}/include"
288   fi
289   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
290     PWLIB_LIBDIR="${PWLIBDIR}/lib"
291   fi
292
293   AC_SUBST([PWLIBDIR])
294   AC_SUBST([PWLIB_INCDIR])
295   AC_SUBST([PWLIB_LIBDIR])
296 fi
297   AC_LANG_POP([C++])
298 ])
299
300
301 AC_DEFUN(
302 [AST_CHECK_OPENH323_PLATFORM], [
303 PWLIB_OSTYPE=
304 case "$host_os" in
305   linux*)          PWLIB_OSTYPE=linux ;
306                 ;;
307   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
308                 ;;
309   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
310                                    ENDLDLIBS="-lossaudio" ;
311                 ;;
312   netbsd* )        PWLIB_OSTYPE=NetBSD ;
313                                    ENDLDLIBS="-lossaudio" ;
314                 ;;
315   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
316                 ;;
317   darwin* )            PWLIB_OSTYPE=Darwin ;
318                 ;;
319   beos*)           PWLIB_OSTYPE=beos ;
320                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
321                 ;;
322   cygwin*)         PWLIB_OSTYPE=cygwin ;
323                 ;;
324   mingw*)              PWLIB_OSTYPE=mingw ;
325                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
326                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
327                 ;;
328   * )                  PWLIB_OSTYPE="$host_os" ;
329                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
330                 ;;
331 esac
332
333 PWLIB_MACHTYPE=
334 case "$host_cpu" in
335    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
336                    ;;
337
338    x86_64)         PWLIB_MACHTYPE=x86_64 ;
339                    P_64BIT=1 ;
340                    LIB64=1 ;
341                    ;;
342
343    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
344                    P_64BIT=1 ;
345                    ;;
346
347    sparc )         PWLIB_MACHTYPE=sparc ;
348                    ;;
349
350    powerpc )       PWLIB_MACHTYPE=ppc ;
351                    ;;
352
353    ppc )           PWLIB_MACHTYPE=ppc ;
354                    ;;
355
356    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
357                    P_64BIT=1 ;
358                    LIB64=1 ;
359                    ;;
360
361    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
362                    P_64BIT=1 ;
363                    LIB64=1 ;
364                    ;;
365
366    ia64)           PWLIB_MACHTYPE=ia64 ;
367                    P_64BIT=1 ;
368                    ;;
369
370    s390x)          PWLIB_MACHTYPE=s390x ;
371                    P_64BIT=1 ;
372                    LIB64=1 ;
373                    ;;
374
375    s390)           PWLIB_MACHTYPE=s390 ;
376                    ;;
377
378    * )             PWLIB_MACHTYPE="$host_cpu";
379                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
380 esac
381
382 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
383
384 AC_SUBST([PWLIB_PLATFORM])
385 ])
386
387
388 AC_DEFUN(
389 [AST_CHECK_OPENH323], [
390 OPENH323_INCDIR=
391 OPENH323_LIBDIR=
392 AC_LANG_PUSH([C++])
393 if test "${OPENH323DIR:-unset}" != "unset" ; then
394   AC_CHECK_HEADER(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
395 fi
396 if test "${HAS_OPENH323:-unset}" = "unset" ; then
397   AC_CHECK_HEADER(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
398   if test "${HAS_OPENH323:-unset}" != "unset" ; then
399     OPENH323DIR="${PWLIBDIR}/../openh323"
400     saved_cppflags="${CPPFLAGS}"
401     CPPFLAGS="${CPPFLAGS} -I${PWLIB_INCDIR}/openh323 -I${PWLIB_INCDIR}"
402     AC_CHECK_HEADER(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}", [#include <ptlib.h>])
403     CPPFLAGS="${saved_cppflags}"
404   else
405     saved_cppflags="${CPPFLAGS}"
406     CPPFLAGS="${CPPFLAGS} -I${HOME}/openh323/include -I${PWLIB_INCDIR}"
407     AC_CHECK_HEADER(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
408     CPPFLAGS="${saved_cppflags}"
409     if test "${HAS_OPENH323:-unset}" != "unset" ; then
410       OPENH323DIR="${HOME}/openh323"
411     else
412       saved_cppflags="${CPPFLAGS}"
413       CPPFLAGS="${CPPFLAGS} -I/usr/local/include/openh323 -I${PWLIB_INCDIR}"
414       AC_CHECK_HEADER(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
415       CPPFLAGS="${saved_cppflags}"
416       if test "${HAS_OPENH323:-unset}" != "unset" ; then
417         OPENH323DIR="/usr/local/share/openh323"
418         OPENH323_INCDIR="/usr/local/include/openh323"
419         if test "x$LIB64" != "x"; then
420           OPENH323_LIBDIR="/usr/local/lib64"
421         else
422           OPENH323_LIBDIR="/usr/local/lib"
423         fi
424       else
425         saved_cppflags="${CPPFLAGS}"
426         CPPFLAGS="${CPPFLAGS} -I/usr/include/openh323 -I${PWLIB_INCDIR}"
427         AC_CHECK_HEADER(/usr/include/openh323/h323.h, HAS_OPENH323=1, , [#include <ptlib.h>])
428         CPPFLAGS="${saved_cppflags}"
429         if test "${HAS_OPENH323:-unset}" != "unset" ; then
430           OPENH323DIR="/usr/share/openh323"
431           OPENH323_INCDIR="/usr/include/openh323"
432           if test "x$LIB64" != "x"; then
433             OPENH323_LIBDIR="/usr/lib64"
434           else
435             OPENH323_LIBDIR="/usr/lib"
436           fi
437         fi
438       fi
439     fi
440   fi
441 fi
442
443 if test "${HAS_OPENH323:-unset}" != "unset" ; then
444   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
445     OPENH323_INCDIR="${OPENH323DIR}/include"
446   fi
447   if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
448     OPENH323_LIBDIR="${OPENH323DIR}/lib"
449   fi
450
451   OPENH323_LIBDIR="`cd ${OPENH323_LIBDIR}; pwd`"
452   OPENH323_INCDIR="`cd ${OPENH323_INCDIR}; pwd`"
453   OPENH323DIR="`cd ${OPENH323DIR}; pwd`"
454
455   AC_SUBST([OPENH323DIR])
456   AC_SUBST([OPENH323_INCDIR])
457   AC_SUBST([OPENH323_LIBDIR])
458 fi
459   AC_LANG_POP([C++])
460 ])
461
462
463 AC_DEFUN(
464 [AST_CHECK_PWLIB_VERSION], [
465         if test "${HAS_$2:-unset}" != "unset"; then
466                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
467                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
468                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
469                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
470                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
471                 let $2_REQ=$4*10000+$5*100+$6
472
473                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
474                 if test ${$2_VER} -lt ${$2_REQ}; then
475                         AC_MSG_RESULT(no)
476                         unset HAS_$2
477                 else
478                         AC_MSG_RESULT(yes)
479                 fi
480         fi
481 ])
482
483
484 AC_DEFUN(
485 [AST_CHECK_PWLIB_BUILD], [
486         if test "${HAS_$2:-unset}" != "unset"; then
487            AC_MSG_CHECKING($1 installation validity)
488
489            saved_cppflags="${CPPFLAGS}"
490            saved_libs="${LIBS}"
491            if test "${$2_LIB:-unset}" != "unset"; then
492               LIBS="${LIBS} ${$2_LIB} $7"
493            else
494               LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
495            fi
496            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
497
498            AC_LANG_PUSH([C++])
499
500            AC_LINK_IFELSE(
501                 [AC_LANG_PROGRAM([$4],[$5])],
502                 [       AC_MSG_RESULT(yes) 
503                         ac_cv_lib_$2="yes" 
504                 ],
505                 [       AC_MSG_RESULT(no) 
506                         ac_cv_lib_$2="no" 
507                 ]
508                 )
509
510            AC_LANG_POP([C++])
511
512            LIBS="${saved_libs}"
513            CPPFLAGS="${saved_cppflags}"
514
515            if test "${ac_cv_lib_$2}" = "yes"; then
516               if test "${$2_LIB:-undef}" = "undef"; then
517                  if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
518                     $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
519                  else
520                     $2_LIB="-l${PLATFORM_$2}"
521                  fi
522               fi
523               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
524                  $2_INCLUDE="-I${$2_INCDIR}"
525               fi
526                   PBX_$2=1
527                   AC_DEFINE([HAVE_$2], 1, [$3])
528            fi
529         fi
530 ])
531
532 AC_DEFUN(
533 [AST_CHECK_OPENH323_BUILD], [
534         if test "${HAS_OPENH323:-unset}" != "unset"; then
535                 AC_MSG_CHECKING(OpenH323 build option)
536                 OPENH323_SUFFIX=
537                 prefixes="h323_${PWLIB_PLATFORM}_ h323_ openh323"
538                 for pfx in $prefixes; do
539                         files=`ls -l ${OPENH323_LIBDIR}/lib${pfx}*.so* 2>/dev/null`
540                         libfile=
541                         if test -n "$files"; then
542                                 for f in $files; do
543                                         if test -f $f -a ! -L $f; then
544                                                 libfile=`basename $f`
545                                                 break;
546                                         fi
547                                 done
548                         fi
549                         if test -n "$libfile"; then
550                                 OPENH323_PREFIX=$pfx
551                                 break;
552                         fi
553                 done
554                 if test "${libfile:-unset}" != "unset"; then
555                         OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/lib${OPENH323_PREFIX}\(@<:@^.@:>@*\)\..*/\1/'"`
556                 fi
557                 case "${OPENH323_SUFFIX}" in
558                         n)
559                                 OPENH323_BUILD="notrace";;
560                         r)
561                                 OPENH323_BUILD="opt";;
562                         d)
563                                 OPENH323_BUILD="debug";;
564                         *)
565                                 if test "${OPENH323_PREFIX:-undef}" = "openh323"; then
566                                         notrace=`eval "grep NOTRACE ${OPENH323DIR}/openh323u.mak | grep = | sed -e 's/@<:@A-Z0-9_@:>@*@<:@      @:>@*=@<:@      @:>@*//'"`
567                                         if test "x$notrace" = "x"; then
568                                                 notrace="0"
569                                         fi
570                                         if test "$notrace" -ne 0; then
571                                                 OPENH323_BUILD="notrace"
572                                         else
573                                                 OPENH323_BUILD="opt"
574                                         fi
575                                         OPENH323_LIB="-l${OPENH323_PREFIX}"
576                                 else
577                                         OPENH323_BUILD="notrace"
578                                 fi
579                                 ;;
580                 esac
581                 AC_MSG_RESULT(${OPENH323_BUILD})
582
583                 AC_SUBST([OPENH323_SUFFIX])
584                 AC_SUBST([OPENH323_BUILD])
585         fi
586 ])
587
588
589 # AST_FUNC_FORK
590 # -------------
591 AN_FUNCTION([fork],  [AST_FUNC_FORK])
592 AN_FUNCTION([vfork], [AST_FUNC_FORK])
593 AC_DEFUN([AST_FUNC_FORK],
594 [AC_REQUIRE([AC_TYPE_PID_T])dnl
595 AC_CHECK_HEADERS(vfork.h)
596 AC_CHECK_FUNCS(fork vfork)
597 if test "x$ac_cv_func_fork" = xyes; then
598   _AST_FUNC_FORK
599 else
600   ac_cv_func_fork_works=$ac_cv_func_fork
601 fi
602 if test "x$ac_cv_func_fork_works" = xcross; then
603   case $host in
604     *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* | *-*-linux-uclibc* )
605       # Override, as these systems have only a dummy fork() stub
606       ac_cv_func_fork_works=no
607       ;;
608     *)
609       ac_cv_func_fork_works=yes
610       ;;
611   esac
612   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
613 fi
614 ac_cv_func_vfork_works=$ac_cv_func_vfork
615 if test "x$ac_cv_func_vfork" = xyes; then
616   _AC_FUNC_VFORK
617 fi;
618 if test "x$ac_cv_func_fork_works" = xcross; then
619   ac_cv_func_vfork_works=$ac_cv_func_vfork
620   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
621 fi
622
623 if test "x$ac_cv_func_vfork_works" = xyes; then
624   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
625 else
626   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
627 fi
628 if test "x$ac_cv_func_fork_works" = xyes; then
629   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
630 fi
631 ])# AST_FUNC_FORK
632
633
634 # _AST_FUNC_FORK
635 # -------------
636 AC_DEFUN([_AST_FUNC_FORK],
637   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
638     [AC_RUN_IFELSE(
639       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
640         [
641           /* By Ruediger Kuhlmann. */
642           return fork () < 0;
643         ])],
644       [ac_cv_func_fork_works=yes],
645       [ac_cv_func_fork_works=no],
646       [ac_cv_func_fork_works=cross])])]
647 )# _AST_FUNC_FORK
648
649 # AST_PROG_LD
650 # ----------
651 # find the pathname to the GNU or non-GNU linker
652 AC_DEFUN([AST_PROG_LD],
653 [AC_ARG_WITH([gnu-ld],
654     [AC_HELP_STRING([--with-gnu-ld],
655         [assume the C compiler uses GNU ld @<:@default=no@:>@])],
656     [test "$withval" = no || with_gnu_ld=yes],
657     [with_gnu_ld=no])
658 AC_REQUIRE([AST_PROG_SED])dnl
659 AC_REQUIRE([AC_PROG_CC])dnl
660 AC_REQUIRE([AC_CANONICAL_HOST])dnl
661 AC_REQUIRE([AC_CANONICAL_BUILD])dnl
662 ac_prog=ld
663 if test "$GCC" = yes; then
664   # Check if gcc -print-prog-name=ld gives a path.
665   AC_MSG_CHECKING([for ld used by $CC])
666   case $host in
667   *-*-mingw*)
668     # gcc leaves a trailing carriage return which upsets mingw
669     ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
670   *)
671     ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
672   esac
673   case $ac_prog in
674     # Accept absolute paths.
675     [[\\/]]* | ?:[[\\/]]*)
676       re_direlt='/[[^/]][[^/]]*/\.\./'
677       # Canonicalize the pathname of ld
678       ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
679       while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
680         ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
681       done
682       test -z "$LD" && LD="$ac_prog"
683       ;;
684   "")
685     # If it fails, then pretend we aren't using GCC.
686     ac_prog=ld
687     ;;
688   *)
689     # If it is relative, then search for the first ld in PATH.
690     with_gnu_ld=unknown
691     ;;
692   esac
693 elif test "$with_gnu_ld" = yes; then
694   AC_MSG_CHECKING([for GNU ld])
695 else
696   AC_MSG_CHECKING([for non-GNU ld])
697 fi
698 AC_CACHE_VAL(lt_cv_path_LD,
699 [if test -z "$LD"; then
700   lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
701   for ac_dir in $PATH; do
702     IFS="$lt_save_ifs"
703     test -z "$ac_dir" && ac_dir=.
704     if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
705       lt_cv_path_LD="$ac_dir/$ac_prog"
706       # Check to see if the program is GNU ld.  I'd rather use --version,
707       # but apparently some variants of GNU ld only accept -v.
708       # Break only if it was the GNU/non-GNU ld that we prefer.
709       case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
710       *GNU* | *'with BFD'*)
711         test "$with_gnu_ld" != no && break
712         ;;
713       *)
714         test "$with_gnu_ld" != yes && break
715         ;;
716       esac
717     fi
718   done
719   IFS="$lt_save_ifs"
720 else
721   lt_cv_path_LD="$LD" # Let the user override the test with a path.
722 fi])
723 LD="$lt_cv_path_LD"
724 if test -n "$LD"; then
725   AC_MSG_RESULT($LD)
726 else
727   AC_MSG_RESULT(no)
728 fi
729 test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
730 AST_PROG_LD_GNU
731 ])# AST_PROG_LD
732
733
734 # AST_PROG_LD_GNU
735 # --------------
736 AC_DEFUN([AST_PROG_LD_GNU],
737 [AC_REQUIRE([AST_PROG_EGREP])dnl
738 AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
739 [# I'd rather use --version here, but apparently some GNU lds only accept -v.
740 case `$LD -v 2>&1 </dev/null` in
741 *GNU* | *'with BFD'*)
742   lt_cv_prog_gnu_ld=yes
743   ;;
744 *)
745   lt_cv_prog_gnu_ld=no
746   ;;
747 esac])
748 with_gnu_ld=$lt_cv_prog_gnu_ld
749 ])# AST_PROG_LD_GNU
750
751 # AST_PROG_EGREP
752 # -------------
753 m4_ifndef([AST_PROG_EGREP], [AC_DEFUN([AST_PROG_EGREP],
754 [AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
755    [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
756     then ac_cv_prog_egrep='grep -E'
757     else ac_cv_prog_egrep='egrep'
758     fi])
759  EGREP=$ac_cv_prog_egrep
760  AC_SUBST([EGREP])
761 ])]) # AST_PROG_EGREP
762
763 # AST_PROG_SED
764 # -----------
765 # Check for a fully functional sed program that truncates
766 # as few characters as possible.  Prefer GNU sed if found.
767 AC_DEFUN([AST_PROG_SED],
768 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
769     [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
770      dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
771      ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
772      for ac_i in 1 2 3 4 5 6 7; do
773        ac_script="$ac_script$as_nl$ac_script"
774      done
775      echo "$ac_script" | sed 99q >conftest.sed
776      $as_unset ac_script || ac_script=
777      _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
778         [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
779                 ["$ac_path_SED" -f conftest.sed])])])
780  SED="$ac_cv_path_SED"
781  AC_SUBST([SED])dnl
782  rm -f conftest.sed
783 ])# AST_PROG_SED
784
785 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
786 dnl
787 dnl @summary figure out how to build C programs using POSIX threads
788 dnl
789 dnl This macro figures out how to build C programs using POSIX threads.
790 dnl It sets the PTHREAD_LIBS output variable to the threads library and
791 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
792 dnl C compiler flags that are needed. (The user can also force certain
793 dnl compiler flags/libs to be tested by setting these environment
794 dnl variables.)
795 dnl
796 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
797 dnl multi-threaded programs (defaults to the value of CC otherwise).
798 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
799 dnl
800 dnl NOTE: You are assumed to not only compile your program with these
801 dnl flags, but also link it with them as well. e.g. you should link
802 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
803 dnl $LIBS
804 dnl
805 dnl If you are only building threads programs, you may wish to use
806 dnl these variables in your default LIBS, CFLAGS, and CC:
807 dnl
808 dnl        LIBS="$PTHREAD_LIBS $LIBS"
809 dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
810 dnl        CC="$PTHREAD_CC"
811 dnl
812 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
813 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
814 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
815 dnl
816 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
817 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
818 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
819 dnl default action will define HAVE_PTHREAD.
820 dnl
821 dnl Please let the authors know if this macro fails on any platform, or
822 dnl if you have any other suggestions or comments. This macro was based
823 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
824 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
825 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
826 dnl We are also grateful for the helpful feedback of numerous users.
827 dnl
828 dnl @category InstalledPackages
829 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
830 dnl @version 2006-05-29
831 dnl @license GPLWithACException
832
833 AC_DEFUN([ACX_PTHREAD], [
834 AC_REQUIRE([AC_CANONICAL_HOST])
835 AC_LANG_SAVE
836 AC_LANG_C
837 acx_pthread_ok=no
838
839 # We used to check for pthread.h first, but this fails if pthread.h
840 # requires special compiler flags (e.g. on True64 or Sequent).
841 # It gets checked for in the link test anyway.
842
843 # First of all, check if the user has set any of the PTHREAD_LIBS,
844 # etcetera environment variables, and if threads linking works using
845 # them:
846 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
847         save_CFLAGS="$CFLAGS"
848         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
849         save_LIBS="$LIBS"
850         LIBS="$PTHREAD_LIBS $LIBS"
851         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
852         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
853         AC_MSG_RESULT($acx_pthread_ok)
854         if test x"$acx_pthread_ok" = xno; then
855                 PTHREAD_LIBS=""
856                 PTHREAD_CFLAGS=""
857         fi
858         LIBS="$save_LIBS"
859         CFLAGS="$save_CFLAGS"
860 fi
861
862 # We must check for the threads library under a number of different
863 # names; the ordering is very important because some systems
864 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
865 # libraries is broken (non-POSIX).
866
867 # Create a list of thread flags to try.  Items starting with a "-" are
868 # C compiler flags, and other items are library names, except for "none"
869 # which indicates that we try without any flags at all, and "pthread-config"
870 # which is a program returning the flags for the Pth emulation library.
871
872 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
873
874 # The ordering *is* (sometimes) important.  Some notes on the
875 # individual items follow:
876
877 # pthreads: AIX (must check this before -lpthread)
878 # none: in case threads are in libc; should be tried before -Kthread and
879 #       other compiler flags to prevent continual compiler warnings
880 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
881 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
882 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
883 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
884 # -pthreads: Solaris/gcc
885 # -mthreads: Mingw32/gcc, Lynx/gcc
886 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
887 #      doesn't hurt to check since this sometimes defines pthreads too;
888 #      also defines -D_REENTRANT)
889 #      ... -mt is also the pthreads flag for HP/aCC
890 # pthread: Linux, etcetera
891 # --thread-safe: KAI C++
892 # pthread-config: use pthread-config program (for GNU Pth library)
893
894 case "${host_cpu}-${host_os}" in
895         *solaris*)
896
897         # On Solaris (at least, for some versions), libc contains stubbed
898         # (non-functional) versions of the pthreads routines, so link-based
899         # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
900         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
901         # a function called by this macro, so we could check for that, but
902         # who knows whether they'll stub that too in a future libc.)  So,
903         # we'll just look for -pthreads and -lpthread first:
904
905         acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
906         ;;
907 esac
908
909 if test x"$acx_pthread_ok" = xno; then
910 for flag in $acx_pthread_flags; do
911
912         case $flag in
913                 none)
914                 AC_MSG_CHECKING([whether pthreads work without any flags])
915                 ;;
916
917                 -*)
918                 AC_MSG_CHECKING([whether pthreads work with $flag])
919                 PTHREAD_CFLAGS="$flag"
920                 ;;
921
922                 pthread-config)
923                 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
924                 if test x"$acx_pthread_config" = xno; then continue; fi
925                 PTHREAD_CFLAGS="`pthread-config --cflags`"
926                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
927                 ;;
928
929                 *)
930                 AC_MSG_CHECKING([for the pthreads library -l$flag])
931                 PTHREAD_LIBS="-l$flag"
932                 ;;
933         esac
934
935         save_LIBS="$LIBS"
936         save_CFLAGS="$CFLAGS"
937         LIBS="$PTHREAD_LIBS $LIBS"
938         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
939
940         # Check for various functions.  We must include pthread.h,
941         # since some functions may be macros.  (On the Sequent, we
942         # need a special flag -Kthread to make this header compile.)
943         # We check for pthread_join because it is in -lpthread on IRIX
944         # while pthread_create is in libc.  We check for pthread_attr_init
945         # due to DEC craziness with -lpthreads.  We check for
946         # pthread_cleanup_push because it is one of the few pthread
947         # functions on Solaris that doesn't have a non-functional libc stub.
948         # We try pthread_create on general principles.
949         AC_TRY_LINK([#include <pthread.h>],
950                     [pthread_t th; pthread_join(th, 0);
951                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
952                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
953                     [acx_pthread_ok=yes])
954
955         LIBS="$save_LIBS"
956         CFLAGS="$save_CFLAGS"
957
958         AC_MSG_RESULT($acx_pthread_ok)
959         if test "x$acx_pthread_ok" = xyes; then
960                 break;
961         fi
962
963         PTHREAD_LIBS=""
964         PTHREAD_CFLAGS=""
965 done
966 fi
967
968 # Various other checks:
969 if test "x$acx_pthread_ok" = xyes; then
970         save_LIBS="$LIBS"
971         LIBS="$PTHREAD_LIBS $LIBS"
972         save_CFLAGS="$CFLAGS"
973         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
974
975         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
976         AC_MSG_CHECKING([for joinable pthread attribute])
977         attr_name=unknown
978         for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
979             AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
980                         [attr_name=$attr; break])
981         done
982         AC_MSG_RESULT($attr_name)
983         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
984             AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
985                                [Define to necessary symbol if this constant
986                                 uses a non-standard name on your system.])
987         fi
988
989         AC_MSG_CHECKING([if more special flags are required for pthreads])
990         flag=no
991         case "${host_cpu}-${host_os}" in
992             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
993             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
994         esac
995         AC_MSG_RESULT(${flag})
996         if test "x$flag" != xno; then
997             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
998         fi
999
1000         LIBS="$save_LIBS"
1001         CFLAGS="$save_CFLAGS"
1002
1003         # More AIX lossage: must compile with xlc_r or cc_r
1004         if test x"$GCC" != xyes; then
1005           AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1006         else
1007           PTHREAD_CC=$CC
1008         fi
1009 else
1010         PTHREAD_CC="$CC"
1011 fi
1012
1013 AC_SUBST(PTHREAD_LIBS)
1014 AC_SUBST(PTHREAD_CFLAGS)
1015 AC_SUBST(PTHREAD_CC)
1016
1017 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1018 if test x"$acx_pthread_ok" = xyes; then
1019         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
1020         :
1021 else
1022         acx_pthread_ok=no
1023         $2
1024 fi
1025 AC_LANG_RESTORE
1026 ])dnl ACX_PTHREAD