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