Merged revisions 151241 via svnmerge from
[asterisk/asterisk.git] / autoconf / ast_check_pwlib.m4
1 AC_DEFUN([AST_CHECK_PWLIB_PLATFORM], [
2 PWLIB_OSTYPE=
3 case "$host_os" in
4   linux*)          PWLIB_OSTYPE=linux ;
5                 ;;
6   freebsd* )       PWLIB_OSTYPE=FreeBSD ;
7                 ;;
8   openbsd* )       PWLIB_OSTYPE=OpenBSD ;
9                                    ENDLDLIBS="-lossaudio" ;
10                 ;;
11   netbsd* )        PWLIB_OSTYPE=NetBSD ;
12                                    ENDLDLIBS="-lossaudio" ;
13                 ;;
14   solaris* | sunos* ) PWLIB_OSTYPE=solaris ;
15                 ;;
16   darwin* )            PWLIB_OSTYPE=Darwin ;
17                 ;;
18   beos*)           PWLIB_OSTYPE=beos ;
19                    STDCCFLAGS="$STDCCFLAGS -D__BEOS__"
20                 ;;
21   cygwin*)         PWLIB_OSTYPE=cygwin ;
22                 ;;
23   mingw*)              PWLIB_OSTYPE=mingw ;
24                            STDCCFLAGS="$STDCCFLAGS -mms-bitfields" ;
25                            ENDLDLIBS="-lwinmm -lwsock32 -lsnmpapi -lmpr -lcomdlg32 -lgdi32 -lavicap32" ;
26                 ;;
27   * )                  PWLIB_OSTYPE="$host_os" ;
28                            AC_MSG_WARN("OS $PWLIB_OSTYPE not recognized - proceed with caution!") ;
29                 ;;
30 esac
31
32 PWLIB_MACHTYPE=
33 case "$host_cpu" in
34    x86 | i686 | i586 | i486 | i386 ) PWLIB_MACHTYPE=x86
35                    ;;
36
37    x86_64)         PWLIB_MACHTYPE=x86_64 ;
38                    P_64BIT=1 ;
39                    LIB64=1 ;
40                    ;;
41
42    alpha | alphaev56 | alphaev6 | alphaev67 | alphaev7) PWLIB_MACHTYPE=alpha ;
43                    P_64BIT=1 ;
44                    ;;
45
46    sparc )         PWLIB_MACHTYPE=sparc ;
47                    ;;
48
49    powerpc )       PWLIB_MACHTYPE=ppc ;
50                    ;;
51
52    ppc )           PWLIB_MACHTYPE=ppc ;
53                    ;;
54
55    powerpc64 )     PWLIB_MACHTYPE=ppc64 ;
56                    P_64BIT=1 ;
57                    LIB64=1 ;
58                    ;;
59
60    ppc64 )         PWLIB_MACHTYPE=ppc64 ;
61                    P_64BIT=1 ;
62                    LIB64=1 ;
63                    ;;
64
65    ia64)           PWLIB_MACHTYPE=ia64 ;
66                    P_64BIT=1 ;
67                    ;;
68
69    s390x)          PWLIB_MACHTYPE=s390x ;
70                    P_64BIT=1 ;
71                    LIB64=1 ;
72                    ;;
73
74    s390)           PWLIB_MACHTYPE=s390 ;
75                    ;;
76
77    * )             PWLIB_MACHTYPE="$host_cpu";
78                    AC_MSG_WARN("CPU $PWLIB_MACHTYPE not recognized - proceed with caution!") ;;
79 esac
80
81 PWLIB_PLATFORM="${PWLIB_OSTYPE}_${PWLIB_MACHTYPE}"
82
83 AC_SUBST([PWLIB_PLATFORM])
84 ])
85
86 AC_DEFUN([AST_CHECK_PWLIB], [
87 PWLIB_INCDIR=
88 PWLIB_LIBDIR=
89 AC_LANG_PUSH([C++])
90 if test "${PWLIBDIR:-unset}" != "unset" ; then
91   AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
92 fi
93 if test "${HAS_PWLIB:-unset}" = "unset" ; then
94   if test "${OPENH323DIR:-unset}" != "unset"; then
95     AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
96   fi
97   if test "${HAS_PWLIB:-unset}" != "unset" ; then
98     PWLIBDIR="${OPENH323DIR}/../pwlib"
99   else
100     AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
101     if test "${HAS_PWLIB:-unset}" != "unset" ; then
102       PWLIBDIR="${HOME}/pwlib"
103     else
104       AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
105       if test "${HAS_PWLIB:-unset}" != "unset" ; then
106         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
107         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
108           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
109         fi
110         PWLIB_INCDIR="/usr/local/include"
111         PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
112         if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
113           if test "x$LIB64" != "x"; then
114             PWLIB_LIBDIR="/usr/local/lib64"
115           else
116             PWLIB_LIBDIR="/usr/local/lib"
117           fi
118         fi
119         PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
120         PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
121       else
122         AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
123         if test "${HAS_PWLIB:-unset}" != "unset" ; then
124           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
125           PWLIB_INCDIR="/usr/include"
126           PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
127           if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
128             if test "x$LIB64" != "x"; then
129               PWLIB_LIBDIR="/usr/lib64"
130             else
131               PWLIB_LIBDIR="/usr/lib"
132             fi
133           fi
134           PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
135           PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
136         fi
137       fi
138     fi
139   fi
140 fi
141
142 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
143 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
144 #  exit
145 #fi
146
147 if test "${HAS_PWLIB:-unset}" != "unset" ; then
148   if test "${PWLIBDIR:-unset}" = "unset" ; then
149     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
150       PWLIBDIR=`$PTLIB_CONFIG --prefix`
151     else
152       echo "Cannot find ptlib-config - please install and try again"
153       exit
154     fi
155   fi
156
157   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
158     PWLIBDIR="/usr/share/pwlib"
159     PWLIB_INCDIR="/usr/include"
160     if test "x$LIB64" != "x"; then
161       PWLIB_LIBDIR="/usr/lib64"
162     else
163       PWLIB_LIBDIR="/usr/lib"
164     fi
165   fi
166   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
167     PWLIBDIR="/usr/local/share/pwlib"
168     PWLIB_INCDIR="/usr/local/include"
169     if test "x$LIB64" != "x"; then
170       PWLIB_LIBDIR="/usr/local/lib64"
171     else
172       PWLIB_LIBDIR="/usr/local/lib"
173     fi
174   fi
175
176   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
177     PWLIB_INCDIR="${PWLIBDIR}/include"
178   fi
179   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
180     PWLIB_LIBDIR="${PWLIBDIR}/lib"
181   fi
182
183   AC_SUBST([PWLIBDIR])
184   AC_SUBST([PWLIB_INCDIR])
185   AC_SUBST([PWLIB_LIBDIR])
186 fi
187   AC_LANG_POP([C++])
188 ])
189
190 AC_DEFUN([AST_CHECK_PWLIB_VERSION], [
191         if test "${HAS_$2:-unset}" != "unset"; then
192                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | sed -e 's/[[[:space:]]]\{1,\}/ /g' | cut -f3 -d ' ' | sed -e 's/"//g'`
193                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
194                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
195                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
196                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
197                 let $2_REQ=$4*10000+$5*100+$6
198
199                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
200                 if test ${$2_VER} -lt ${$2_REQ}; then
201                         AC_MSG_RESULT(no)
202                         unset HAS_$2
203                 else
204                         AC_MSG_RESULT(yes)
205                 fi
206         fi
207 ])
208
209 AC_DEFUN([AST_CHECK_PWLIB_BUILD], [
210         if test "${HAS_$2:-unset}" != "unset"; then
211            AC_MSG_CHECKING($1 installation validity)
212
213            saved_cppflags="${CPPFLAGS}"
214            saved_libs="${LIBS}"
215            if test "${$2_LIB:-unset}" != "unset"; then
216               LIBS="${LIBS} ${$2_LIB} $7"
217            else
218               LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
219            fi
220            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
221
222            AC_LANG_PUSH([C++])
223
224            AC_LINK_IFELSE(
225                 [AC_LANG_PROGRAM([$4],[$5])],
226                 [       AC_MSG_RESULT(yes) 
227                         ac_cv_lib_$2="yes" 
228                 ],
229                 [       AC_MSG_RESULT(no) 
230                         ac_cv_lib_$2="no" 
231                 ]
232                 )
233
234            AC_LANG_POP([C++])
235
236            LIBS="${saved_libs}"
237            CPPFLAGS="${saved_cppflags}"
238
239            if test "${ac_cv_lib_$2}" = "yes"; then
240               if test "${$2_LIB:-undef}" = "undef"; then
241                  if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
242                     $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
243                  else
244                     $2_LIB="-l${PLATFORM_$2}"
245                  fi
246               fi
247               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
248                  $2_INCLUDE="-I${$2_INCDIR}"
249               fi
250                   PBX_$2=1
251                   AC_DEFINE([HAVE_$2], 1, [$3])
252            fi
253         fi
254 ])