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