Merged revisions 151240 via svnmerge from
[asterisk/asterisk.git] / autoconf / ast_check_pwlib.m4
1 AC_DEFUN([AST_CHECK_PWLIB], [
2 PWLIB_INCDIR=
3 PWLIB_LIBDIR=
4 AC_LANG_PUSH([C++])
5 if test "${PWLIBDIR:-unset}" != "unset" ; then
6   AC_CHECK_HEADER(${PWLIBDIR}/version.h, HAS_PWLIB=1, )
7 fi
8 if test "${HAS_PWLIB:-unset}" = "unset" ; then
9   if test "${OPENH323DIR:-unset}" != "unset"; then
10     AC_CHECK_HEADER(${OPENH323DIR}/../pwlib/version.h, HAS_PWLIB=1, )
11   fi
12   if test "${HAS_PWLIB:-unset}" != "unset" ; then
13     PWLIBDIR="${OPENH323DIR}/../pwlib"
14   else
15     AC_CHECK_HEADER(${HOME}/pwlib/include/ptlib.h, HAS_PWLIB=1, )
16     if test "${HAS_PWLIB:-unset}" != "unset" ; then
17       PWLIBDIR="${HOME}/pwlib"
18     else
19       AC_CHECK_HEADER(/usr/local/include/ptlib.h, HAS_PWLIB=1, )
20       if test "${HAS_PWLIB:-unset}" != "unset" ; then
21         AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/bin)
22         if test "${PTLIB_CONFIG:-unset}" = "unset" ; then
23           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/local/share/pwlib/make)
24         fi
25         PWLIB_INCDIR="/usr/local/include"
26         PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
27         if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
28           if test "x$LIB64" != "x"; then
29             PWLIB_LIBDIR="/usr/local/lib64"
30           else
31             PWLIB_LIBDIR="/usr/local/lib"
32           fi
33         fi
34         PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
35         PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
36       else
37         AC_CHECK_HEADER(/usr/include/ptlib.h, HAS_PWLIB=1, )
38         if test "${HAS_PWLIB:-unset}" != "unset" ; then
39           AC_PATH_PROG(PTLIB_CONFIG, ptlib-config, , /usr/share/pwlib/make)
40           PWLIB_INCDIR="/usr/include"
41           PWLIB_LIBDIR=`${PTLIB_CONFIG} --pwlibdir`
42           if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
43             if test "x$LIB64" != "x"; then
44               PWLIB_LIBDIR="/usr/lib64"
45             else
46               PWLIB_LIBDIR="/usr/lib"
47             fi
48           fi
49           PWLIB_LIB=`${PTLIB_CONFIG} --ldflags --libs`
50           PWLIB_LIB="-L${PWLIB_LIBDIR} `echo ${PWLIB_LIB}`"
51         fi
52       fi
53     fi
54   fi
55 fi
56
57 #if test "${HAS_PWLIB:-unset}" = "unset" ; then
58 #  echo "Cannot find pwlib - please install or set PWLIBDIR and try again"
59 #  exit
60 #fi
61
62 if test "${HAS_PWLIB:-unset}" != "unset" ; then
63   if test "${PWLIBDIR:-unset}" = "unset" ; then
64     if test "${PTLIB_CONFIG:-unset}" != "unset" ; then
65       PWLIBDIR=`$PTLIB_CONFIG --prefix`
66     else
67       echo "Cannot find ptlib-config - please install and try again"
68       exit
69     fi
70   fi
71
72   if test "x$PWLIBDIR" = "x/usr" -o "x$PWLIBDIR" = "x/usr/"; then
73     PWLIBDIR="/usr/share/pwlib"
74     PWLIB_INCDIR="/usr/include"
75     if test "x$LIB64" != "x"; then
76       PWLIB_LIBDIR="/usr/lib64"
77     else
78       PWLIB_LIBDIR="/usr/lib"
79     fi
80   fi
81   if test "x$PWLIBDIR" = "x/usr/local" -o "x$PWLIBDIR" = "x/usr/"; then
82     PWLIBDIR="/usr/local/share/pwlib"
83     PWLIB_INCDIR="/usr/local/include"
84     if test "x$LIB64" != "x"; then
85       PWLIB_LIBDIR="/usr/local/lib64"
86     else
87       PWLIB_LIBDIR="/usr/local/lib"
88     fi
89   fi
90
91   if test "${PWLIB_INCDIR:-unset}" = "unset"; then
92     PWLIB_INCDIR="${PWLIBDIR}/include"
93   fi
94   if test "${PWLIB_LIBDIR:-unset}" = "unset"; then
95     PWLIB_LIBDIR="${PWLIBDIR}/lib"
96   fi
97
98   AC_SUBST([PWLIBDIR])
99   AC_SUBST([PWLIB_INCDIR])
100   AC_SUBST([PWLIB_LIBDIR])
101 fi
102   AC_LANG_POP([C++])
103 ])
104
105 AC_DEFUN([AST_CHECK_PWLIB_VERSION], [
106         if test "${HAS_$2:-unset}" != "unset"; then
107                 $2_VERSION=`grep "$2_VERSION" ${$2_INCDIR}/$3 | sed -e 's/[[[:space:]]]\{1,\}/ /g' | cut -f3 -d ' ' | sed -e 's/"//g'`
108                 $2_MAJOR_VERSION=`echo ${$2_VERSION} | cut -f1 -d.`
109                 $2_MINOR_VERSION=`echo ${$2_VERSION} | cut -f2 -d.`
110                 $2_BUILD_NUMBER=`echo ${$2_VERSION} | cut -f3 -d.`
111                 let $2_VER=${$2_MAJOR_VERSION}*10000+${$2_MINOR_VERSION}*100+${$2_BUILD_NUMBER}
112                 let $2_REQ=$4*10000+$5*100+$6
113
114                 AC_MSG_CHECKING(if $1 version ${$2_VERSION} is compatible with chan_h323)
115                 if test ${$2_VER} -lt ${$2_REQ}; then
116                         AC_MSG_RESULT(no)
117                         unset HAS_$2
118                 else
119                         AC_MSG_RESULT(yes)
120                 fi
121         fi
122 ])
123
124 AC_DEFUN([AST_CHECK_PWLIB_BUILD], [
125         if test "${HAS_$2:-unset}" != "unset"; then
126            AC_MSG_CHECKING($1 installation validity)
127
128            saved_cppflags="${CPPFLAGS}"
129            saved_libs="${LIBS}"
130            if test "${$2_LIB:-unset}" != "unset"; then
131               LIBS="${LIBS} ${$2_LIB} $7"
132            else
133               LIBS="${LIBS} -L${$2_LIBDIR} -l${PLATFORM_$2} $7"
134            fi
135            CPPFLAGS="${CPPFLAGS} -I${$2_INCDIR} $6"
136
137            AC_LANG_PUSH([C++])
138
139            AC_LINK_IFELSE(
140                 [AC_LANG_PROGRAM([$4],[$5])],
141                 [       AC_MSG_RESULT(yes) 
142                         ac_cv_lib_$2="yes" 
143                 ],
144                 [       AC_MSG_RESULT(no) 
145                         ac_cv_lib_$2="no" 
146                 ]
147                 )
148
149            AC_LANG_POP([C++])
150
151            LIBS="${saved_libs}"
152            CPPFLAGS="${saved_cppflags}"
153
154            if test "${ac_cv_lib_$2}" = "yes"; then
155               if test "${$2_LIB:-undef}" = "undef"; then
156                  if test "${$2_LIBDIR}" != "" -a "${$2_LIBDIR}" != "/usr/lib"; then
157                     $2_LIB="-L${$2_LIBDIR} -l${PLATFORM_$2}"
158                  else
159                     $2_LIB="-l${PLATFORM_$2}"
160                  fi
161               fi
162               if test "${$2_INCDIR}" != "" -a "${$2_INCDIR}" != "/usr/include"; then
163                  $2_INCLUDE="-I${$2_INCDIR}"
164               fi
165                   PBX_$2=1
166                   AC_DEFINE([HAVE_$2], 1, [$3])
167            fi
168         fi
169 ])