ast_ext_lib.m4 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. AC_ARG_WITH([$3], AC_HELP_STRING([--with-$3=PATH],[use $2 files in PATH $4]),
  12. [
  13. case ${withval} in
  14. n|no)
  15. USE_$1=no
  16. ;;
  17. y|ye|yes)
  18. ac_mandatory_list="${ac_mandatory_list} $1"
  19. ;;
  20. *)
  21. $1_DIR="${withval}"
  22. ac_mandatory_list="${ac_mandatory_list} $1"
  23. ;;
  24. esac
  25. ])
  26. PBX_$1=0
  27. AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
  28. AC_SUBST([$1_LIB])
  29. AC_SUBST([$1_INCLUDE])
  30. AC_SUBST([$1_DIR])
  31. AC_SUBST([PBX_$1])
  32. ])
  33. # AST_EXT_LIB_SETUP_DEPENDENT([package symbol name], [package friendly name], [master package symbol name], [master package option name])
  34. AC_DEFUN([AST_EXT_LIB_SETUP_DEPENDENT],
  35. [
  36. $1_DESCRIP="$2"
  37. m4_ifval([$4], [$1_OPTION=$4])
  38. m4_ifval([$3], [
  39. for i in ${ac_mandatory_list}; do
  40. if test "x$3" = "x$i"; then
  41. ac_mandatory_list="${ac_mandatory_list} $1"
  42. break
  43. fi
  44. done
  45. ])
  46. PBX_$1=0
  47. AH_TEMPLATE(m4_bpatsubst([[HAVE_$1]], [(.*)]), [Define to 1 if you have the $2 library.])
  48. AC_SUBST([$1_LIB])
  49. AC_SUBST([$1_INCLUDE])
  50. AC_SUBST([$1_DIR])
  51. AC_SUBST([PBX_$1])
  52. ])
  53. # Check for existence of a given package ($1), either looking up a function
  54. # in a library, or, if no function is supplied, only check for the
  55. # existence of the header files.
  56. # AST_EXT_LIB_CHECK([package], [library], [function], [header],
  57. # [extra libs], [extra cflags], [version])
  58. AC_DEFUN([AST_EXT_LIB_CHECK],
  59. [
  60. if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
  61. pbxlibdir=""
  62. # if --with-$1=DIR has been specified, use it.
  63. if test "x${$1_DIR}" != "x"; then
  64. if test -d ${$1_DIR}/lib; then
  65. pbxlibdir="-L${$1_DIR}/lib"
  66. else
  67. pbxlibdir="-L${$1_DIR}"
  68. fi
  69. fi
  70. pbxfuncname="$3"
  71. if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
  72. AST_$1_FOUND=yes
  73. else
  74. ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
  75. CFLAGS="${CFLAGS} $6"
  76. AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
  77. CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
  78. fi
  79. # now check for the header.
  80. if test "${AST_$1_FOUND}" = "yes"; then
  81. $1_LIB="${pbxlibdir} -l$2 $5"
  82. # if --with-$1=DIR has been specified, use it.
  83. if test "x${$1_DIR}" != "x"; then
  84. $1_INCLUDE="-I${$1_DIR}/include"
  85. fi
  86. $1_INCLUDE="${$1_INCLUDE} $6"
  87. if test "x$4" = "x" ; then # no header, assume found
  88. $1_HEADER_FOUND="1"
  89. else # check for the header
  90. ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
  91. CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
  92. AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
  93. CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
  94. fi
  95. if test "x${$1_HEADER_FOUND}" = "x0" ; then
  96. $1_LIB=""
  97. $1_INCLUDE=""
  98. else
  99. if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
  100. $1_LIB=""
  101. fi
  102. PBX_$1=1
  103. cat >>confdefs.h <<_ACEOF
  104. [@%:@define] HAVE_$1 1
  105. _ACEOF
  106. m4_ifval([$7], [
  107. cat >>confdefs.h <<_ACEOF
  108. [@%:@define] HAVE_$1_VERSION $7
  109. _ACEOF
  110. ])
  111. fi
  112. fi
  113. fi
  114. m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
  115. ])