Cleanup a bit more by getting rid of useless version defines. Also make library detec...
[asterisk/asterisk.git] / autoconf / ast_ext_lib.m4
1 # Helper function to setup variables for a package.
2 # $1 -> the package name. Used in configure.ac and also as a prefix
3 #       for the variables ($1_DIR, $1_INCLUDE, $1_LIB) in makeopts
4 # $3 -> option name, used in --with-$3 or --without-$3 when calling configure.
5 # $2 and $4 are just text describing the package (short and long form)
6
7 # AST_EXT_LIB_SETUP([package], [short description], [configure option name], [long description])
8
9 AC_DEFUN([AST_EXT_LIB_SETUP],
10 [
11     $1_DESCRIP="$2"
12     $1_OPTION="$3"
13     PBX_$1=0
14     AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH$4]),
15     [
16         case ${withval} in
17         n|no)
18         USE_$1=no
19         # -1 is a magic value used by menuselect to know that the package
20         # was disabled, other than 'not found'
21         PBX_$1=-1
22         ;;
23         y|ye|yes)
24         ac_mandatory_list="${ac_mandatory_list} $1"
25         ;;
26         *)
27         $1_DIR="${withval}"
28         ac_mandatory_list="${ac_mandatory_list} $1"
29         ;;
30         esac
31     ])
32     AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
33     AC_SUBST([$1_LIB])
34     AC_SUBST([$1_INCLUDE])
35     AC_SUBST([$1_DIR])
36     AC_SUBST([PBX_$1])
37 ])
38
39 # AST_EXT_LIB_SETUP_DEPENDENT([package symbol name], [package friendly name], [master package symbol name], [master package option name])
40
41 AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
42 [
43 $1_DESCRIP="$2"
44 m4_ifval([$4], [$1_OPTION=$4])
45 m4_ifval([$3], [
46 for i in ${ac_mandatory_list}; do
47    if test "x$3" = "x$i"; then
48       ac_mandatory_list="${ac_mandatory_list} $1"
49       break
50    fi
51 done
52 ])
53 PBX_$1=0
54 AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
55 AC_SUBST([$1_LIB])
56 AC_SUBST([$1_INCLUDE])
57 AC_SUBST([$1_DIR])
58 AC_SUBST([PBX_$1])
59 ])
60
61 # Check for existence of a given package ($1), either looking up a function
62 # in a library, or, if no function is supplied, only check for the
63 # existence of the header files.
64
65 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
66 #        [extra libs], [extra cflags], [version])
67 AC_DEFUN([AST_EXT_LIB_CHECK],
68 [
69 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
70    pbxlibdir=""
71    # if --with-$1=DIR has been specified, use it.
72    if test "x${$1_DIR}" != "x"; then
73       if test -d ${$1_DIR}/lib; then
74          pbxlibdir="-L${$1_DIR}/lib"
75       else
76          pbxlibdir="-L${$1_DIR}"
77       fi
78    fi
79    pbxfuncname="$3"
80    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
81       AST_$1_FOUND=yes
82    else
83       ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
84       CFLAGS="${CFLAGS} $6"
85       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
86       CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
87    fi
88
89    # now check for the header.
90    if test "${AST_$1_FOUND}" = "yes"; then
91       $1_LIB="${pbxlibdir} -l$2 $5"
92       # if --with-$1=DIR has been specified, use it.
93       if test "x${$1_DIR}" != "x"; then
94          $1_INCLUDE="-I${$1_DIR}/include"
95       fi
96       $1_INCLUDE="${$1_INCLUDE} $6"
97       if test "x$4" = "x" ; then        # no header, assume found
98          $1_HEADER_FOUND="1"
99       else                              # check for the header
100          ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
101          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
102          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
103          CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
104       fi
105       if test "x${$1_HEADER_FOUND}" = "x0" ; then
106          $1_LIB=""
107          $1_INCLUDE=""
108       else
109          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
110             $1_LIB=""
111          fi
112          PBX_$1=1
113          cat >>confdefs.h <<_ACEOF
114 [@%:@define] HAVE_$1 1
115 _ACEOF
116          m4_ifval([$7], [
117          cat >>confdefs.h <<_ACEOF
118 [@%:@define] HAVE_$1_VERSION $7
119 _ACEOF
120             ])
121       fi
122    fi
123 fi
124 m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
125 ])