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