ast_ext_lib.m4 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. # 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. pbxfuncname="$3"
  112. if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
  113. AST_$1_FOUND=yes
  114. else
  115. ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
  116. CFLAGS="${CFLAGS} $6"
  117. AC_CHECK_LIB([$2], [${pbxfuncname}], [AST_$1_FOUND=yes], [AST_$1_FOUND=no], [${pbxlibdir} $5])
  118. CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
  119. fi
  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. if test "x$4" = "x" ; then # no header, assume found
  129. $1_HEADER_FOUND="1"
  130. else # check for the header
  131. ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
  132. CPPFLAGS="${CPPFLAGS} ${$1_INCLUDE}"
  133. AC_CHECK_HEADER([$4], [$1_HEADER_FOUND=1], [$1_HEADER_FOUND=0])
  134. CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
  135. fi
  136. if test "x${$1_HEADER_FOUND}" = "x0" ; then
  137. $1_LIB=""
  138. $1_INCLUDE=""
  139. else
  140. if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
  141. $1_LIB=""
  142. fi
  143. PBX_$1=1
  144. cat >>confdefs.h <<_ACEOF
  145. [@%:@define] HAVE_$1 1
  146. _ACEOF
  147. m4_ifval([$7], [
  148. cat >>confdefs.h <<_ACEOF
  149. [@%:@define] HAVE_$1_VERSION $7
  150. _ACEOF
  151. ])
  152. fi
  153. fi
  154. fi
  155. m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
  156. ])