ast_ext_lib.m4 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. # AST_EXT_LIB_SETUP([package], [short description], [configure option name], [long description])
  7. AC_DEFUN([AST_EXT_LIB_SETUP],
  8. [
  9. $1_DESCRIP="$2"
  10. $1_OPTION="$3"
  11. PBX_$1=0
  12. AC_ARG_WITH([$3], AS_HELP_STRING([--with-$3=PATH],[use $2 files in PATH$4]),
  13. [
  14. case ${withval} in
  15. n|no)
  16. USE_$1=no
  17. # -1 is a magic value used by menuselect to know that the package
  18. # was disabled, other than 'not found'
  19. PBX_$1=-1
  20. ;;
  21. y|ye|yes)
  22. ac_mandatory_list="${ac_mandatory_list} $1"
  23. ;;
  24. *)
  25. $1_DIR="${withval}"
  26. ac_mandatory_list="${ac_mandatory_list} $1"
  27. ;;
  28. esac
  29. ])
  30. AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
  31. AC_SUBST([$1_LIB])
  32. AC_SUBST([$1_INCLUDE])
  33. AC_SUBST([$1_DIR])
  34. AC_SUBST([PBX_$1])
  35. ])
  36. # AST_OPTION_ONLY([option name], [option variable], [option description], [default value])
  37. AC_DEFUN([AST_OPTION_ONLY],
  38. [
  39. AC_ARG_WITH([$1], AS_HELP_STRING([--with-$1=PATH], [use $3 in PATH]),
  40. [
  41. case ${withval} in
  42. n|no)
  43. unset $2
  44. ;;
  45. *)
  46. if test "x${withval}" = "x"; then
  47. m4_ifval($4, [$2="$4"], [:])
  48. else
  49. $2="${withval}"
  50. fi
  51. ;;
  52. esac
  53. ],
  54. [m4_ifval($4, [$2="$4"], [:])])
  55. AC_SUBST($2)
  56. ])
  57. # Setup required dependent package
  58. # AST_EXT_LIB_SETUP_DEPENDENT([dependent package symbol name], [dependent package friendly name], [master package symbol name], [master package name])
  59. AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
  60. [
  61. $1_DESCRIP="$2"
  62. m4_ifval([$4], [$1_OPTION=$4])
  63. m4_ifval([$3], [
  64. for i in ${ac_mandatory_list}; do
  65. if test "x$3" = "x$i"; then
  66. ac_mandatory_list="${ac_mandatory_list} $1"
  67. break
  68. fi
  69. done
  70. $1_DIR=${$3_DIR}
  71. ])
  72. PBX_$1=0
  73. AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
  74. AC_SUBST([$1_LIB])
  75. AC_SUBST([$1_INCLUDE])
  76. AC_SUBST([$1_DIR])
  77. AC_SUBST([PBX_$1])
  78. ])
  79. # Setup optional dependent package
  80. # AST_EXT_LIB_SETUP_OPTIONAL([optional package symbol name], [optional package friendly name], [master package symbol name], [master package name])
  81. AC_DEFUN([AST_EXT_LIB_SETUP_OPTIONAL],
  82. [
  83. $1_DESCRIP="$2"
  84. m4_ifval([$4], [$1_OPTION=$4])
  85. m4_ifval([$3], [$1_DIR=${$3_DIR}
  86. ])
  87. PBX_$1=0
  88. AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if $3 has the $2 feature.])
  89. AC_SUBST([$1_LIB])
  90. AC_SUBST([$1_INCLUDE])
  91. AC_SUBST([$1_DIR])
  92. AC_SUBST([PBX_$1])
  93. ])
  94. # Check for existence of a given package ($1), either looking up a function
  95. # in a library, or, if no function is supplied, only check for the
  96. # existence of the header files.
  97. # AST_EXT_LIB_CHECK([package], [library], [function], [header],
  98. # [extra libs], [extra cflags], [version])
  99. AC_DEFUN([AST_EXT_LIB_CHECK],
  100. [
  101. if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
  102. pbxlibdir=""
  103. # if --with-$1=DIR has been specified, use it.
  104. if test "x${$1_DIR}" != "x"; then
  105. if test -d ${$1_DIR}/lib; then
  106. pbxlibdir="-L${$1_DIR}/lib"
  107. else
  108. pbxlibdir="-L${$1_DIR}"
  109. fi
  110. fi
  111. m4_ifval([$3], [
  112. ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
  113. CFLAGS="${CFLAGS} $6"
  114. AC_CHECK_LIB([$2], [$3], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
  115. CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
  116. ], [
  117. # empty lib, assume only headers
  118. AST_$1_FOUND=yes
  119. ])
  120. # now check for the header.
  121. if test "${AST_$1_FOUND}" = "yes"; then
  122. $1_LIB="${pbxlibdir} -l$2 $5"
  123. # if --with-$1=DIR has been specified, use it.
  124. if test "x${$1_DIR}" != "x"; then
  125. $1_INCLUDE="-I${$1_DIR}/include"
  126. fi
  127. $1_INCLUDE="${$1_INCLUDE} $6"
  128. m4_ifval([$4], [
  129. # check for the header
  130. ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
  131. CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
  132. AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
  133. CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
  134. ], [
  135. # no header, assume found
  136. $1_HEADER_FOUND="1"
  137. ])
  138. if test "x${$1_HEADER_FOUND}" = "x0" ; then
  139. $1_LIB=""
  140. $1_INCLUDE=""
  141. else
  142. m4_ifval([$3], [], [
  143. # only checking headers -> no library
  144. $1_LIB=""
  145. ])
  146. PBX_$1=1
  147. cat >>confdefs.h <<_ACEOF
  148. [@%:@define] HAVE_$1 1
  149. _ACEOF
  150. m4_ifval([$7], [
  151. cat >>confdefs.h <<_ACEOF
  152. [@%:@define] HAVE_$1_VERSION $7
  153. _ACEOF
  154. ])
  155. fi
  156. fi
  157. fi
  158. m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
  159. ])
  160. # Check if the previously discovered library can be dynamically linked.
  161. #
  162. # AST_EXT_LIB_CHECK_SHARED([package], [library], [function], [header],
  163. # [extra libs], [extra cflags], [action-if-true], [action-if-false])
  164. AC_DEFUN([AST_EXT_LIB_CHECK_SHARED],
  165. [
  166. if test "x${PBX_$1}" = "x1"; then
  167. ast_ext_lib_check_shared_saved_libs="${LIBS}"
  168. ast_ext_lib_check_shared_saved_ldflags="${LDFLAGS}"
  169. ast_ext_lib_check_shared_saved_cflags="${CFLAGS}"
  170. LIBS="${LIBS} ${$1_LIB} $5"
  171. LDFLAGS="${LDFLAGS} -shared -fPIC"
  172. CFLAGS="${CFLAGS} ${$1_INCLUDE} $6"
  173. AC_MSG_CHECKING(for the ability of -l$2 to be linked in a shared object)
  174. AC_LINK_IFELSE(
  175. [
  176. AC_LANG_PROGRAM(
  177. [#include <$4>],
  178. [$3();]
  179. )
  180. ],
  181. [
  182. AC_MSG_RESULT(yes)
  183. $7
  184. ],
  185. [
  186. AC_MSG_RESULT(no)
  187. $8
  188. ]
  189. )
  190. CFLAGS="${ast_ext_lib_check_shared_saved_cflags}"
  191. LDFLAGS="${ast_ext_lib_check_shared_saved_ldflags}"
  192. LIBS="${ast_ext_lib_check_shared_saved_libs}"
  193. fi
  194. ])