Check for 64-bit OpenH323/PWLib versions too, thanks to Mithraen (please, re-build...
[asterisk/asterisk.git] / acinclude.m4
1 # AST_GCC_ATTRIBUTE([attribute name])
2
3 AC_DEFUN([AST_GCC_ATTRIBUTE],
4 [
5 AC_MSG_CHECKING(for compiler 'attribute $1' support)
6 AC_COMPILE_IFELSE(
7         AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}],
8                         []),
9         AC_MSG_RESULT(yes)
10         AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]),
11         AC_MSG_RESULT(no))
12 ])
13
14 # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text])
15
16 AC_DEFUN([AST_EXT_LIB_SETUP],
17 [
18 $1_DESCRIP="$2"
19 $1_OPTION="$3"
20 AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),[
21 case ${withval} in
22      n|no)
23      USE_$1=no
24      ;;
25      y|ye|yes)
26      $1_MANDATORY="yes"
27      ;;
28      *)
29      $1_DIR="${withval}"
30      $1_MANDATORY="yes"
31      ;;
32 esac
33 ])
34 PBX_$1=0
35 AC_SUBST([$1_LIB])
36 AC_SUBST([$1_INCLUDE])
37 AC_SUBST([PBX_$1])
38 ])
39
40 # AST_EXT_LIB_CHECK([package symbol name], [package library name], [function to check], [package header], [additional LIB data])
41
42 AC_DEFUN([AST_EXT_LIB_CHECK],
43 [
44 if test "${USE_$1}" != "no"; then
45    pbxlibdir=""
46    if test "x${$1_DIR}" != "x"; then
47       if test -d ${$1_DIR}/lib; then
48          pbxlibdir="-L${$1_DIR}/lib"
49       else
50          pbxlibdir="-L${$1_DIR}"
51       fi
52    fi
53    AC_CHECK_LIB([$2], [$3], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], ${pbxlibdir} $5)
54
55    if test "${AST_$1_FOUND}" = "yes"; then
56       $1_LIB="-l$2 $5"
57       $1_HEADER_FOUND="1"
58       if test "x${$1_DIR}" != "x"; then
59          $1_LIB="${pbxlibdir} ${$1_LIB}"
60          $1_INCLUDE="-I${$1_DIR}/include"
61          if test "x$4" != "x" ; then
62             AC_CHECK_HEADER([${$1_DIR}/include/$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0] )
63          fi
64       else
65          if test "x$4" != "x" ; then
66             AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0] )
67          fi
68       fi
69       if test "x${$1_HEADER_FOUND}" = "x0" ; then
70          if test ! -z "${$1_MANDATORY}" ;
71          then
72             AC_MSG_NOTICE( ***)
73             AC_MSG_NOTICE( *** It appears that you do not have the $2 development package installed.)
74             AC_MSG_NOTICE( *** Please install it to include ${$1_DESCRIP} support, or re-run configure)
75             AC_MSG_NOTICE( *** without explicitly specifying --with-${$1_OPTION})
76             exit 1
77          fi
78          $1_LIB=""
79          $1_INCLUDE=""
80          PBX_$1=0
81       else
82          PBX_$1=1
83          AC_DEFINE_UNQUOTED([HAVE_$1], 1, [Define to indicate the ${$1_DESCRIP} library])
84       fi
85    elif test ! -z "${$1_MANDATORY}";
86    then
87       AC_MSG_NOTICE(***)
88       AC_MSG_NOTICE(*** The ${$1_DESCRIP} installation on this system appears to be broken.)
89       AC_MSG_NOTICE(*** Either correct the installation, or run configure)
90       AC_MSG_NOTICE(*** without explicitly specifying --with-${$1_OPTION})
91       exit 1
92    fi
93 fi
94 ])
95
96
97 AC_DEFUN(
98 [AST_CHECK_GNU_MAKE], [AC_CACHE_CHECK(for GNU make, GNU_MAKE,
99    GNU_MAKE='Not Found' ;
100    GNU_MAKE_VERSION_MAJOR=0 ;
101    GNU_MAKE_VERSION_MINOR=0 ;
102    for a in make gmake gnumake ; do
103       if test -z "$a" ; then continue ; fi ;
104       if ( sh -c "$a --version" 2> /dev/null | grep GNU  2>&1 > /dev/null ) ;  then
105          GNU_MAKE=$a ;
106          GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'`
107          GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2`
108          break;
109       fi
110    done ;
111 ) ;
112 if test  "x$GNU_MAKE" = "xNot Found"  ; then
113    AC_MSG_ERROR( *** Please install GNU make.  It is required to build Asterisk!)
114    exit 1
115 fi
116 AC_SUBST([GNU_MAKE])
117 ])
118
119
120 AC_DEFUN(
121 [AST_CHECK_PWLIB], [
122 PWLIB_INCDIR=
123 PWLIB_LIBDIR=
124 if test "${PWLIBDIR:-unset}" != "unset" ; then
125   AC_CHECK_FILE(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
126 fi
127 if test "${HAS_PWLIB:-unset}" = "unset" ; then
128   if test "${OPENH323DIR:-unset}" != "unset"; then
129     AC_CHECK_FILE(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
130   fi
131   if test "${HAS_PWLIB:-unset}" != "unset" ; then
132     PWLIBDIR="${OPENH323DIR}/../pwlib"
133   else
134     AC_CHECK_FILE(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
135     if test "${HAS_PWLIB:-unset}" != "unset" ; then
136       PWLIBDIR="${HOME}/pwlib"
137     else
138       AC_CHECK_FILE(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
139       if test "${HAS_PWLIB:-unset}" != "unset" ; then
140         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
141         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
142           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
143         fi
144         PWLIB_INCDIR="/usr/local/include"
145         if test "x$LIB64" != "x"; then
146           PWLIB_LIBDIR="/usr/local/lib64"
147         else
148           PWLIB_LIBDIR="/usr/local/lib"
149         fi
150       else
151         AC_CHECK_FILE(/usr/include/ptlib.h, HAS_PWLIB=1, )
152         if test "${HAS_PWLIB:-unset}" != "unset" ; then
153           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
154           PWLIB_INCDIR="/usr/include"
155           if test "x$LIB64" != "x"; then
156                 PWLIB_LIBDIR="/usr/lib64"
157           else
158                 PWLIB_LIBDIR="/usr/lib"
159               fi
160         fi
161       fi
162     fi
163   fi
164 fi
165
166 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
167 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
168 #  exit
169 #fi
170
171 if test "${HAS_PWLIB:-unset}" != "unset" ; then
172   if test "${PWLIBDIR:-unset}" = "unset" ; then
173     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
174       PWLIBDIR=`$PTLIB_CONFIG --prefix`
175     else
176       echo "Cannot find ptlib-config - please install and try again"
177       exit
178     fi
179   fi
180
181   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
182     PWLIBDIR="/usr/share/pwlib"
183     PWLIB_INCDIR="/usr/include"
184     if test "x$LIB64" != "x"; then
185       PWLIB_LIBDIR="/usr/lib64"
186     else
187       PWLIB_LIBDIR="/usr/lib"
188     fi
189   fi
190   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
191     PWLIBDIR="/usr/local/share/pwlib"
192     PWLIB_INCDIR="/usr/local/include"
193     if test "x$LIB64" != "x"; then
194       PWLIB_LIBDIR="/usr/local/lib64"
195     else
196       PWLIB_LIBDIR="/usr/local/lib"
197     fi
198   fi
199
200   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
201     PWLIB_INCDIR="${PWLIBDIR}/include"
202   fi
203   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
204     PWLIB_LIBDIR="${PWLIBDIR}/lib"
205   fi
206
207   AC_SUBST([PWLIBDIR])
208   AC_SUBST([PWLIB_INCDIR])
209   AC_SUBST([PWLIB_LIBDIR])
210 fi
211 ])
212
213
214 AC_DEFUN(
215 [AST_CHECK_OPENH323_PLATFORM], [
216 PWLIB_OSTYPE=
217 case "$host_os" in
218   linux*)          PWLIB_OSTYPE=linux ;
219                 ;;
220   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
221                 ;;
222   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
223                                    ENDLDLIBS="-lossaudio" ;
224                 ;;
225   netbsd* )        PWLIB_OSTYPE=NetBSD ;
226                                    ENDLDLIBS="-lossaudio" ;
227                 ;;
228   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
229                 ;;
230   darwin* )            PWLIB_OSTYPE=Darwin ;
231                 ;;
232   beos*)           PWLIB_OSTYPE=beos ;
233                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
234                 ;;
235   cygwin*)         PWLIB_OSTYPE=cygwin ;
236                 ;;
237   mingw*)              PWLIB_OSTYPE=mingw ;
238                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
239                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
240                 ;;
241   * )                  PWLIB_OSTYPE="$host_os" ;
242                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
243                 ;;
244 esac
245
246 PWLIB_MACHTYPE=
247 case "$host_cpu" in
248    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
249                    ;;
250
251    x86_64)         PWLIB_MACHTYPE=x86_64 ;
252                    P_64BIT=1 ;
253                    LIB64=1 ;
254                    ;;
255
256    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
257                    P_64BIT=1 ;
258                    ;;
259
260    sparc )         PWLIB_MACHTYPE=sparc ;
261                    ;;
262
263    powerpc )       PWLIB_MACHTYPE=ppc ;
264                    ;;
265
266    ppc )           PWLIB_MACHTYPE=ppc ;
267                    ;;
268
269    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
270                    P_64BIT=1 ;
271                    LIB64=1 ;
272                    ;;
273
274    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
275                    P_64BIT=1 ;
276                    LIB64=1 ;
277                    ;;
278
279    ia64)           PWLIB_MACHTYPE=ia64 ;
280                    P_64BIT=1 ;
281                    ;;
282
283    s390x)          PWLIB_MACHTYPE=s390x ;
284                    P_64BIT=1 ;
285                    LIB64=1 ;
286                    ;;
287
288    s390)           PWLIB_MACHTYPE=s390 ;
289                    ;;
290
291    * )             PWLIB_MACHTYPE="$host_cpu";
292                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
293 esac
294
295 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
296
297 AC_SUBST([PWLIB_PLATFORM])
298 ])
299
300
301 AC_DEFUN(
302 [AST_CHECK_OPENH323], [
303 OPENH323_INCDIR=
304 OPENH323_LIBDIR=
305 if test "${OPENH323DIR:-unset}" != "unset" ; then
306   AC_CHECK_FILE(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
307 fi
308 if test "${HAS_OPENH323:-unset}" = "unset" ; then
309   AC_CHECK_FILE(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
310   if test "${HAS_OPENH323:-unset}" != "unset" ; then
311     OPENH323DIR="${PWLIBDIR}/../openh323"
312     AC_CHECK_FILE(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}")
313   else
314     AC_CHECK_FILE(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
315     if test "${HAS_OPENH323:-unset}" != "unset" ; then
316       OPENH323DIR="${HOME}/openh323"
317     else
318       AC_CHECK_FILE(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
319       if test "${HAS_OPENH323:-unset}" != "unset" ; then
320         OPENH323DIR="/usr/local/share/openh323"
321         OPENH323_INCDIR="/usr/local/include/openh323"
322         if test "x$LIB64" != "x"; then
323           OPENH323_LIBDIR="/usr/local/lib64"
324         else
325           OPENH323_LIBDIR="/usr/local/lib"
326         fi
327       else
328         AC_CHECK_FILE(/usr/include/openh323/h323.h, HAS_OPENH323=1, )
329         if test "${HAS_OPENH323:-unset}" != "unset" ; then
330           OPENH323DIR="/usr/share/openh323"
331           OPENH323_INCDIR="/usr/include/openh323"
332           if test "x$LIB64" != "x"; then
333             OPENH323_LIBDIR="/usr/lib64"
334           else
335             OPENH323_LIBDIR="/usr/lib"
336           fi
337         fi
338       fi
339     fi
340   fi
341 fi
342
343 if test "${HAS_OPENH323:-unset}" != "unset" ; then
344   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
345     OPENH323_INCDIR="${OPENH323DIR}/include"
346   fi
347   if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
348     OPENH323_LIBDIR="${OPENH323DIR}/lib"
349   fi
350
351   AC_SUBST([OPENH323DIR])
352   AC_SUBST([OPENH323_INCDIR])
353   AC_SUBST([OPENH323_LIBDIR])
354 fi
355 ])
356
357
358 AC_DEFUN(
359 [AST_CHECK_PWLIB_VERSION], [
360         if test "${HAS_$2:-unset}" != "unset"; then
361                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
362                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
363                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
364                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
365                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
366                 let $2_REQ=$4*10000+$5*100+$6
367
368                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
369                 if test ${$2_VER} -lt ${$2_REQ}; then
370                         AC_MSG_RESULT(no)
371                         unset HAS_$2
372                 else
373                         AC_MSG_RESULT(yes)
374                 fi
375         fi
376 ])
377
378
379 AC_DEFUN(
380 [AST_CHECK_PWLIB_BUILD], [
381         if test "${HAS_$2:-unset}" != "unset"; then
382            AC_MSG_CHECKING($1 installation validity)
383
384            saved_cppflags="${CPPFLAGS}"
385            saved_libs="${LIBS}"
386            LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
387            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
388
389            AC_LANG_PUSH([C++])
390
391            AC_LINK_IFELSE(
392                 [AC_LANG_PROGRAM([$4],[$5])],
393                 [       AC_MSG_RESULT(yes) 
394                         ac_cv_lib_$2="yes" 
395                 ],
396                 [       AC_MSG_RESULT(no) 
397                         ac_cv_lib_$2="no" 
398                 ]
399                 )
400
401            AC_LANG_POP([C++])
402
403            LIBS="${saved_libs}"
404            CPPFLAGS="${saved_cppflags}"
405
406            if test "${ac_cv_lib_$2}" = "yes"; then
407               if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
408                  $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
409               else
410                  $2_LIB="-l${PLATFORM_$2}"
411               fi
412               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
413                  $2_INCLUDE="-I${$2_INCDIR}"
414               fi
415                   PBX_$2=1
416                   AC_DEFINE([HAVE_$2], 1, [$3])
417            fi
418         fi
419 ])
420
421 AC_DEFUN(
422 [AST_CHECK_OPENH323_BUILD], [
423         if test "${HAS_OPENH323:-unset}" != "unset"; then
424                 AC_MSG_CHECKING(OpenH323 build option)
425                 OPENH323_SUFFIX=
426                 files=`ls -l ${OPENH323_LIBDIR}/libh323_${PWLIB_PLATFORM}_*.so*`
427                 libfile=
428                 if test -n "$files"; then
429                         for f in $files; do
430                                 if test -f $f -a ! -L $f; then
431                                         libfile=`basename $f`
432                                         break;
433                                 fi
434                         done
435                 fi
436                 if test "${libfile:-unset}" != "unset"; then
437                         OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/libh323_${PWLIB_PLATFORM}_\(@<:@^.@:>@*\)\..*/\1/'"`
438                 fi
439                 case "${OPENH323_SUFFIX}" in
440                         n)
441                                 OPENH323_BUILD="notrace";;
442                         r)
443                                 OPENH323_BUILD="opt";;
444                         d)
445                                 OPENH323_BUILD="debug";;
446                         *)
447                                 OPENH323_BUILD="notrace";;
448                 esac
449                 AC_MSG_RESULT(${OPENH323_BUILD})
450
451                 AC_SUBST([OPENH323_SUFFIX])
452                 AC_SUBST([OPENH323_BUILD])
453         fi
454 ])
455
456
457 # AST_FUNC_FORK
458 # -------------
459 AN_FUNCTION([fork],  [AST_FUNC_FORK])
460 AN_FUNCTION([vfork], [AST_FUNC_FORK])
461 AC_DEFUN([AST_FUNC_FORK],
462 [AC_REQUIRE([AC_TYPE_PID_T])dnl
463 AC_CHECK_HEADERS(vfork.h)
464 AC_CHECK_FUNCS(fork vfork)
465 if test "x$ac_cv_func_fork" = xyes; then
466   _AST_FUNC_FORK
467 else
468   ac_cv_func_fork_works=$ac_cv_func_fork
469 fi
470 if test "x$ac_cv_func_fork_works" = xcross; then
471   case $host in
472     *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* )
473       # Override, as these systems have only a dummy fork() stub
474       ac_cv_func_fork_works=no
475       ;;
476     *)
477       ac_cv_func_fork_works=yes
478       ;;
479   esac
480   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
481 fi
482 ac_cv_func_vfork_works=$ac_cv_func_vfork
483 if test "x$ac_cv_func_vfork" = xyes; then
484   _AC_FUNC_VFORK
485 fi;
486 if test "x$ac_cv_func_fork_works" = xcross; then
487   ac_cv_func_vfork_works=$ac_cv_func_vfork
488   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
489 fi
490
491 if test "x$ac_cv_func_vfork_works" = xyes; then
492   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
493 else
494   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
495 fi
496 if test "x$ac_cv_func_fork_works" = xyes; then
497   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
498 fi
499 ])# AST_FUNC_FORK
500
501
502 # _AST_FUNC_FORK
503 # -------------
504 AC_DEFUN([_AST_FUNC_FORK],
505   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
506     [AC_RUN_IFELSE(
507       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
508         [
509           /* By Ruediger Kuhlmann. */
510           return fork () < 0;
511         ])],
512       [ac_cv_func_fork_works=yes],
513       [ac_cv_func_fork_works=no],
514       [ac_cv_func_fork_works=cross])])]
515 )# _AST_FUNC_FORK