Cache sound tarfiles in a common directory, such that a clean reinstall does not...
[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_OPTION_ONLY([option name], [option variable], [option description], [default value])
40 AC_DEFUN([AST_OPTION_ONLY],
41 [
42 AC_ARG_WITH([$1], AC_HELP_STRING([--with-$1=PATH], [use $3 in PATH]),
43         [
44         case ${withval} in
45         n|no)
46                 unset $2
47                 ;;
48         *)
49                 if test "x${$2}" = "x"; then
50                         m4_ifval($4, [$2="$4"], [:])
51                 else
52                         $2="${withval}"
53                 fi
54                 ;;
55         esac
56         ])
57 AC_SUBST($2)
58 ])
59
60 # AST_EXT_LIB_SETUP_DEPENDENT([package symbol name], [package friendly name], [master package symbol name], [master package option name])
61
62 AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
63 [
64 $1_DESCRIP="$2"
65 m4_ifval([$4], [$1_OPTION=$4])
66 m4_ifval([$3], [
67 for i in ${ac_mandatory_list}; do
68    if test "x$3" = "x$i"; then
69       ac_mandatory_list="${ac_mandatory_list} $1"
70       break
71    fi
72 done
73 ])
74 PBX_$1=0
75 AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
76 AC_SUBST([$1_LIB])
77 AC_SUBST([$1_INCLUDE])
78 AC_SUBST([$1_DIR])
79 AC_SUBST([PBX_$1])
80 ])
81
82 # Check for existence of a given package ($1), either looking up a function
83 # in a library, or, if no function is supplied, only check for the
84 # existence of the header files.
85
86 # AST_EXT_LIB_CHECK([package], [library], [function], [header],
87 #        [extra libs], [extra cflags], [version])
88 AC_DEFUN([AST_EXT_LIB_CHECK],
89 [
90 if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
91    pbxlibdir=""
92    # if --with-$1=DIR has been specified, use it.
93    if test "x${$1_DIR}" != "x"; then
94       if test -d ${$1_DIR}/lib; then
95          pbxlibdir="-L${$1_DIR}/lib"
96       else
97          pbxlibdir="-L${$1_DIR}"
98       fi
99    fi
100    pbxfuncname="$3"
101    if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
102       AST_$1_FOUND=yes
103    else
104       ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
105       CFLAGS="${CFLAGS} $6"
106       AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
107       CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
108    fi
109
110    # now check for the header.
111    if test "${AST_$1_FOUND}" = "yes"; then
112       $1_LIB="${pbxlibdir} -l$2 $5"
113       # if --with-$1=DIR has been specified, use it.
114       if test "x${$1_DIR}" != "x"; then
115          $1_INCLUDE="-I${$1_DIR}/include"
116       fi
117       $1_INCLUDE="${$1_INCLUDE} $6"
118       if test "x$4" = "x" ; then        # no header, assume found
119          $1_HEADER_FOUND="1"
120       else                              # check for the header
121          ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
122          CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
123          AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
124          CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
125       fi
126       if test "x${$1_HEADER_FOUND}" = "x0" ; then
127          $1_LIB=""
128          $1_INCLUDE=""
129       else
130          if test "x${pbxfuncname}" = "x" ; then         # only checking headers -> no library
131             $1_LIB=""
132          fi
133          PBX_$1=1
134          cat >>confdefs.h <<_ACEOF
135 [@%:@define] HAVE_$1 1
136 _ACEOF
137          m4_ifval([$7], [
138          cat >>confdefs.h <<_ACEOF
139 [@%:@define] HAVE_$1_VERSION $7
140 _ACEOF
141             ])
142       fi
143    fi
144 fi
145 m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
146 ])