Remove unnecessary (long time ago commented out) code
[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         PWLIB_LIBDIR="/usr/local/lib"
146       else
147         AC_CHECK_FILE(/usr/include/ptlib.h, HAS_PWLIB=1, )
148         if test "${HAS_PWLIB:-unset}" != "unset" ; then
149           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
150           PWLIB_INCDIR="/usr/include"
151           PWLIB_LIBDIR="/usr/lib"
152         fi
153       fi
154     fi
155   fi
156 fi
157
158 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
159 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
160 #  exit
161 #fi
162
163 if test "${HAS_PWLIB:-unset}" != "unset" ; then
164   if test "${PWLIBDIR:-unset}" = "unset" ; then
165     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
166       PWLIBDIR=`$PTLIB_CONFIG --prefix`
167     else
168       echo "Cannot find ptlib-config - please install and try again"
169       exit
170     fi
171   fi
172
173   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
174     PWLIBDIR="/usr/share/pwlib"
175     PWLIB_INCDIR="/usr/include"
176     PWLIB_LIBDIR="/usr/lib"
177   fi
178   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
179     PWLIBDIR="/usr/local/share/pwlib"
180     PWLIB_INCDIR="/usr/local/include"
181     PWLIB_LIBDIR="/usr/local/lib"
182   fi
183
184   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
185     PWLIB_INCDIR="${PWLIBDIR}/include"
186   fi
187   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
188     PWLIB_LIBDIR="${PWLIBDIR}/lib"
189   fi
190
191   AC_SUBST([PWLIBDIR])
192   AC_SUBST([PWLIB_INCDIR])
193   AC_SUBST([PWLIB_LIBDIR])
194 fi
195 ])
196
197
198 AC_DEFUN(
199 [AST_CHECK_OPENH323_PLATFORM], [
200 PWLIB_OSTYPE=
201 case "$host_os" in
202   linux*)          PWLIB_OSTYPE=linux ;
203                 ;;
204   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
205                 ;;
206   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
207                                    ENDLDLIBS="-lossaudio" ;
208                 ;;
209   netbsd* )        PWLIB_OSTYPE=NetBSD ;
210                                    ENDLDLIBS="-lossaudio" ;
211                 ;;
212   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
213                 ;;
214   darwin* )            PWLIB_OSTYPE=Darwin ;
215                 ;;
216   beos*)           PWLIB_OSTYPE=beos ;
217                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
218                 ;;
219   cygwin*)         PWLIB_OSTYPE=cygwin ;
220                 ;;
221   mingw*)              PWLIB_OSTYPE=mingw ;
222                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
223                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
224                 ;;
225   * )                  PWLIB_OSTYPE="$host_os" ;
226                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
227                 ;;
228 esac
229
230 PWLIB_MACHTYPE=
231 case "$host_cpu" in
232    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
233                    ;;
234
235    x86_64)         PWLIB_MACHTYPE=x86_64 ;
236                    P_64BIT=1 ;
237                    LIB64=1 ;
238                    ;;
239
240    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
241                    P_64BIT=1 ;
242                    ;;
243
244    sparc )         PWLIB_MACHTYPE=sparc ;
245                    ;;
246
247    powerpc )       PWLIB_MACHTYPE=ppc ;
248                    ;;
249
250    ppc )           PWLIB_MACHTYPE=ppc ;
251                    ;;
252
253    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
254                    P_64BIT=1 ;
255                    LIB64=1 ;
256                    ;;
257
258    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
259                    P_64BIT=1 ;
260                    LIB64=1 ;
261                    ;;
262
263    ia64)           PWLIB_MACHTYPE=ia64 ;
264                    P_64BIT=1 ;
265                    ;;
266
267    s390x)          PWLIB_MACHTYPE=s390x ;
268                    P_64BIT=1 ;
269                    LIB64=1 ;
270                    ;;
271
272    s390)           PWLIB_MACHTYPE=s390 ;
273                    ;;
274
275    * )             PWLIB_MACHTYPE="$host_cpu";
276                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
277 esac
278
279 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
280
281 AC_SUBST([PWLIB_PLATFORM])
282 ])
283
284
285 AC_DEFUN(
286 [AST_CHECK_OPENH323], [
287 OPENH323_INCDIR=
288 OPENH323_LIBDIR=
289 if test "${OPENH323DIR:-unset}" != "unset" ; then
290   AC_CHECK_FILE(${OPENH323DIR}/version.h, HAS_OPENH323=1, )
291 fi
292 if test "${HAS_OPENH323:-unset}" = "unset" ; then
293   AC_CHECK_FILE(${PWLIBDIR}/../openh323/version.h, OPENH323DIR="${PWLIBDIR}/../openh323"; HAS_OPENH323=1, )
294   if test "${HAS_OPENH323:-unset}" != "unset" ; then
295     OPENH323DIR="${PWLIBDIR}/../openh323"
296     AC_CHECK_FILE(${OPENH323DIR}/include/h323.h, , OPENH323_INCDIR="${PWLIB_INCDIR}/openh323"; OPENH323_LIBDIR="${PWLIB_LIBDIR}")
297   else
298     AC_CHECK_FILE(${HOME}/openh323/include/h323.h, HAS_OPENH323=1, )
299     if test "${HAS_OPENH323:-unset}" != "unset" ; then
300       OPENH323DIR="${HOME}/openh323"
301     else
302       AC_CHECK_FILE(/usr/local/include/openh323/h323.h, HAS_OPENH323=1, )
303       if test "${HAS_OPENH323:-unset}" != "unset" ; then
304         OPENH323DIR="/usr/local/share/openh323"
305         OPENH323_INCDIR="/usr/local/include/openh323"
306         OPENH323_LIBDIR="/usr/local/lib"
307       else
308         AC_CHECK_FILE(/usr/include/openh323/h323.h, HAS_OPENH323=1, )
309         if test "${HAS_OPENH323:-unset}" != "unset" ; then
310           OPENH323DIR="/usr/share/openh323"
311           OPENH323_INCDIR="/usr/include/openh323"
312           OPENH323_LIBDIR="/usr/lib"
313         fi
314       fi
315     fi
316   fi
317 fi
318
319 if test "${HAS_OPENH323:-unset}" != "unset" ; then
320   if test "${OPENH323_INCDIR:-unset}" = "unset"; then
321     OPENH323_INCDIR="${OPENH323DIR}/include"
322   fi
323   if test "${OPENH323_LIBDIR:-unset}" = "unset"; then
324     OPENH323_LIBDIR="${OPENH323DIR}/lib"
325   fi
326
327   AC_SUBST([OPENH323DIR])
328   AC_SUBST([OPENH323_INCDIR])
329   AC_SUBST([OPENH323_LIBDIR])
330 fi
331 ])
332
333
334 AC_DEFUN(
335 [AST_CHECK_PWLIB_VERSION], [
336         if test "${HAS_$2:-unset}" != "unset"; then
337                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | cut -f2 -d ' ' | sed -e 's/"//g'`
338                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
339                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
340                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
341                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
342                 let $2_REQ=$4*10000+$5*100+$6
343
344                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
345                 if test ${$2_VER} -lt ${$2_REQ}; then
346                         AC_MSG_RESULT(no)
347                         unset HAS_$2
348                 else
349                         AC_MSG_RESULT(yes)
350                 fi
351         fi
352 ])
353
354
355 AC_DEFUN(
356 [AST_CHECK_PWLIB_BUILD], [
357         if test "${HAS_$2:-unset}" != "unset"; then
358            AC_MSG_CHECKING($1 installation validity)
359
360            saved_cppflags="${CPPFLAGS}"
361            saved_libs="${LIBS}"
362            LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
363            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
364
365            AC_LANG_PUSH([C++])
366
367            AC_LINK_IFELSE(
368                 [AC_LANG_PROGRAM([$4],[$5])],
369                 [       AC_MSG_RESULT(yes) 
370                         ac_cv_lib_$2="yes" 
371                 ],
372                 [       AC_MSG_RESULT(no) 
373                         ac_cv_lib_$2="no" 
374                 ]
375                 )
376
377            AC_LANG_POP([C++])
378
379            LIBS="${saved_libs}"
380            CPPFLAGS="${saved_cppflags}"
381
382            if test "${ac_cv_lib_$2}" = "yes"; then
383               if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
384                  $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
385               else
386                  $2_LIB="-l${PLATFORM_$2}"
387               fi
388               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
389                  $2_INCLUDE="-I${$2_INCDIR}"
390               fi
391                   PBX_$2=1
392                   AC_DEFINE([HAVE_$2], 1, [$3])
393            fi
394         fi
395 ])
396
397 AC_DEFUN(
398 [AST_CHECK_OPENH323_BUILD], [
399         if test "${HAS_OPENH323:-unset}" != "unset"; then
400                 AC_MSG_CHECKING(OpenH323 build option)
401                 OPENH323_SUFFIX=
402                 files=`ls -l ${OPENH323_LIBDIR}/libh323_${PWLIB_PLATFORM}_*.so*`
403                 libfile=
404                 if test -n "$files"; then
405                         for f in $files; do
406                                 if test -f $f -a ! -L $f; then
407                                         libfile=`basename $f`
408                                         break;
409                                 fi
410                         done
411                 fi
412                 if test "${libfile:-unset}" != "unset"; then
413                         OPENH323_SUFFIX=`eval "echo ${libfile} | sed -e 's/libh323_${PWLIB_PLATFORM}_\(@<:@^.@:>@*\)\..*/\1/'"`
414                 fi
415                 case "${OPENH323_SUFFIX}" in
416                         n)
417                                 OPENH323_BUILD="notrace";;
418                         r)
419                                 OPENH323_BUILD="opt";;
420                         d)
421                                 OPENH323_BUILD="debug";;
422                         *)
423                                 OPENH323_BUILD="notrace";;
424                 esac
425                 AC_MSG_RESULT(${OPENH323_BUILD})
426
427                 AC_SUBST([OPENH323_SUFFIX])
428                 AC_SUBST([OPENH323_BUILD])
429         fi
430 ])
431
432
433 # AST_FUNC_FORK
434 # -------------
435 AN_FUNCTION([fork],  [AST_FUNC_FORK])
436 AN_FUNCTION([vfork], [AST_FUNC_FORK])
437 AC_DEFUN([AST_FUNC_FORK],
438 [AC_REQUIRE([AC_TYPE_PID_T])dnl
439 AC_CHECK_HEADERS(vfork.h)
440 AC_CHECK_FUNCS(fork vfork)
441 if test "x$ac_cv_func_fork" = xyes; then
442   _AST_FUNC_FORK
443 else
444   ac_cv_func_fork_works=$ac_cv_func_fork
445 fi
446 if test "x$ac_cv_func_fork_works" = xcross; then
447   case $host in
448     *-*-amigaos* | *-*-msdosdjgpp* | *-*-uclinux* )
449       # Override, as these systems have only a dummy fork() stub
450       ac_cv_func_fork_works=no
451       ;;
452     *)
453       ac_cv_func_fork_works=yes
454       ;;
455   esac
456   AC_MSG_WARN([result $ac_cv_func_fork_works guessed because of cross compilation])
457 fi
458 ac_cv_func_vfork_works=$ac_cv_func_vfork
459 if test "x$ac_cv_func_vfork" = xyes; then
460   _AC_FUNC_VFORK
461 fi;
462 if test "x$ac_cv_func_fork_works" = xcross; then
463   ac_cv_func_vfork_works=$ac_cv_func_vfork
464   AC_MSG_WARN([result $ac_cv_func_vfork_works guessed because of cross compilation])
465 fi
466
467 if test "x$ac_cv_func_vfork_works" = xyes; then
468   AC_DEFINE(HAVE_WORKING_VFORK, 1, [Define to 1 if `vfork' works.])
469 else
470   AC_DEFINE(vfork, fork, [Define as `fork' if `vfork' does not work.])
471 fi
472 if test "x$ac_cv_func_fork_works" = xyes; then
473   AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
474 fi
475 ])# AST_FUNC_FORK
476
477
478 # _AST_FUNC_FORK
479 # -------------
480 AC_DEFUN([_AST_FUNC_FORK],
481   [AC_CACHE_CHECK(for working fork, ac_cv_func_fork_works,
482     [AC_RUN_IFELSE(
483       [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
484         [
485           /* By Ruediger Kuhlmann. */
486           return fork () < 0;
487         ])],
488       [ac_cv_func_fork_works=yes],
489       [ac_cv_func_fork_works=no],
490       [ac_cv_func_fork_works=cross])])]
491 )# _AST_FUNC_FORK