ast_ext_lib.m4 4.2 KB

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