Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
8.9KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_lib_expat.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_LIB_EXPAT([MINIMUM-VERSION])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro provides tests of availability of Expat XML Parser of
  12. # particular version or newer. This macro checks for Expat XML Parser
  13. # headers and libraries and defines compilation flags
  14. #
  15. # Macro supports following options and their values:
  16. #
  17. # 1) Single-option usage:
  18. #
  19. # --with-expat -- yes, no, or path to Expat XML Parser
  20. # installation prefix
  21. #
  22. # 2) Three-options usage (all options are required):
  23. #
  24. # --with-expat=yes
  25. # --with-expat-inc -- path to base directory with Expat headers
  26. # --with-expat-lib -- linker flags for Expat
  27. #
  28. # This macro calls:
  29. #
  30. # AC_SUBST(EXPAT_CFLAGS)
  31. # AC_SUBST(EXPAT_LIBS)
  32. # AC_SUBST(EXPAT_LDFLAGS)
  33. # AC_SUBST(EXPAT_VERSION) -- only if version requirement is used
  34. #
  35. # And sets:
  36. #
  37. # HAVE_EXPAT
  38. #
  39. # LICENSE
  40. #
  41. # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
  42. #
  43. # Copying and distribution of this file, with or without modification, are
  44. # permitted in any medium without royalty provided the copyright notice
  45. # and this notice are preserved. This file is offered as-is, without any
  46. # warranty.
  47. #serial 11
  48. AC_DEFUN([AX_LIB_EXPAT],
  49. [
  50. AC_ARG_WITH([expat],
  51. AS_HELP_STRING([--with-expat=@<:@ARG@:>@],
  52. [use Expat XML Parser from given prefix (ARG=path); check standard prefixes (ARG=yes); disable (ARG=no)]
  53. ),
  54. [
  55. if test "$withval" = "yes"; then
  56. if test -f /usr/local/include/expat.h ; then
  57. expat_prefix=/usr/local
  58. elif test -f /usr/include/expat.h ; then
  59. expat_prefix=/usr
  60. else
  61. expat_prefix=""
  62. fi
  63. expat_requested="yes"
  64. elif test -d "$withval"; then
  65. expat_prefix="$withval"
  66. expat_requested="yes"
  67. else
  68. expat_prefix=""
  69. expat_requested="no"
  70. fi
  71. ],
  72. [
  73. dnl Default behavior is implicit yes
  74. if test -f /usr/local/include/expat.h ; then
  75. expat_prefix=/usr/local
  76. elif test -f /usr/include/expat.h ; then
  77. expat_prefix=/usr
  78. else
  79. expat_prefix=""
  80. fi
  81. ]
  82. )
  83. AC_ARG_WITH([expat-inc],
  84. AS_HELP_STRING([--with-expat-inc=@<:@DIR@:>@],
  85. [path to Expat XML Parser headers]
  86. ),
  87. [expat_include_dir="$withval"],
  88. [expat_include_dir=""]
  89. )
  90. AC_ARG_WITH([expat-lib],
  91. AS_HELP_STRING([--with-expat-lib=@<:@ARG@:>@],
  92. [link options for Expat XML Parser libraries]
  93. ),
  94. [expat_lib_flags="$withval"],
  95. [expat_lib_flags=""]
  96. )
  97. EXPAT_CFLAGS=""
  98. EXPAT_LIBS=""
  99. EXPAT_VERSION=""
  100. dnl
  101. dnl Collect include/lib paths and flags
  102. dnl
  103. run_expat_test="no"
  104. if test -n "$expat_prefix"; then
  105. expat_include_dir="$expat_prefix/include"
  106. expat_ld_flags="-L$expat_prefix/lib"
  107. expat_lib_flags="-lexpat"
  108. run_expat_test="yes"
  109. elif test "$expat_requested" = "yes"; then
  110. if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then
  111. run_expat_test="yes"
  112. fi
  113. else
  114. run_expat_test="no"
  115. fi
  116. dnl
  117. dnl Check Expat XML Parser files
  118. dnl
  119. if test "$run_expat_test" = "yes"; then
  120. saved_CPPFLAGS="$CPPFLAGS"
  121. CPPFLAGS="$CPPFLAGS -I$expat_include_dir"
  122. saved_LIBS="$LIBS"
  123. LIBS="$LIBS $expat_lib_flags"
  124. saved_LDFLAGS="$LDFLAGS"
  125. LDFLAGS="$LDFLAGS $expat_ld_flags"
  126. dnl
  127. dnl Check Expat headers
  128. dnl
  129. AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir])
  130. AC_LANG_PUSH([C++])
  131. AC_COMPILE_IFELSE([
  132. AC_LANG_PROGRAM(
  133. [[
  134. @%:@include <expat.h>
  135. ]],
  136. [[]]
  137. )],
  138. [
  139. EXPAT_CFLAGS="-I$expat_include_dir"
  140. expat_header_found="yes"
  141. AC_MSG_RESULT([found])
  142. ],
  143. [
  144. expat_header_found="no"
  145. AC_MSG_RESULT([not found])
  146. ]
  147. )
  148. AC_LANG_POP([C++])
  149. dnl
  150. dnl Check Expat libraries
  151. dnl
  152. if test "$expat_header_found" = "yes"; then
  153. AC_MSG_CHECKING([for Expat XML Parser libraries])
  154. AC_LANG_PUSH([C++])
  155. AC_LINK_IFELSE([
  156. AC_LANG_PROGRAM(
  157. [[
  158. @%:@include <expat.h>
  159. ]],
  160. [[
  161. XML_Parser p = XML_ParserCreate(NULL);
  162. XML_ParserFree(p);
  163. p = NULL;
  164. ]]
  165. )],
  166. [
  167. EXPAT_LIBS="$expat_lib_flags"
  168. EXPAT_LDFLAGS="$expat_ld_flags"
  169. expat_lib_found="yes"
  170. AC_MSG_RESULT([found])
  171. ],
  172. [
  173. expat_lib_found="no"
  174. AC_MSG_RESULT([not found])
  175. ]
  176. )
  177. AC_LANG_POP([C++])
  178. fi
  179. CPPFLAGS="$saved_CPPFLAGS"
  180. LDFLAGS="$saved_LDFLAGS"
  181. LIBS="$saved_LIBS"
  182. fi
  183. AC_MSG_CHECKING([for Expat XML Parser])
  184. if test "$run_expat_test" = "yes"; then
  185. if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then
  186. AC_SUBST([EXPAT_CFLAGS])
  187. AC_SUBST([EXPAT_LDFLAGS])
  188. AC_SUBST([EXPAT_LIBS])
  189. HAVE_EXPAT="yes"
  190. else
  191. HAVE_EXPAT="no"
  192. fi
  193. AC_MSG_RESULT([$HAVE_EXPAT])
  194. dnl
  195. dnl Check Expat version
  196. dnl
  197. if test "$HAVE_EXPAT" = "yes"; then
  198. expat_version_req=ifelse([$1], [], [], [$1])
  199. if test -n "$expat_version_req"; then
  200. AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req])
  201. if test -f "$expat_include_dir/expat.h"; then
  202. expat_major=`cat $expat_include_dir/expat.h | \
  203. grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \
  204. sed -e 's/#define XML_MAJOR_VERSION.//'`
  205. expat_minor=`cat $expat_include_dir/expat.h | \
  206. grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \
  207. sed -e 's/#define XML_MINOR_VERSION.//'`
  208. expat_revision=`cat $expat_include_dir/expat.h | \
  209. grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \
  210. sed -e 's/#define XML_MICRO_VERSION.//'`
  211. EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision"
  212. AC_SUBST([EXPAT_VERSION])
  213. dnl Decompose required version string and calculate numerical representation
  214. expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'`
  215. expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  216. expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  217. if test "x$expat_version_req_revision" = "x"; then
  218. expat_version_req_revision="0"
  219. fi
  220. expat_version_req_number=`expr $expat_version_req_major \* 10000 \
  221. \+ $expat_version_req_minor \* 100 \
  222. \+ $expat_version_req_revision`
  223. dnl Calculate numerical representation of detected version
  224. expat_version_number=`expr $expat_major \* 10000 \
  225. \+ $expat_minor \* 100 \
  226. \+ $expat_revision`
  227. expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number`
  228. if test "$expat_version_check" = "1"; then
  229. AC_MSG_RESULT([yes])
  230. else
  231. AC_MSG_RESULT([no])
  232. AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.])
  233. fi
  234. else
  235. AC_MSG_RESULT([no])
  236. AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.])
  237. fi
  238. fi
  239. fi
  240. else
  241. HAVE_EXPAT="no"
  242. AC_MSG_RESULT([$HAVE_EXPAT])
  243. if test "$expat_requested" = "yes"; then
  244. AC_MSG_WARN([Expat XML Parser support requested but headers or library not found. Specify valid prefix of Expat using --with-expat=@<:@DIR@:>@ or provide include directory and linker flags using --with-expat-inc and --with-expat-lib])
  245. fi
  246. fi
  247. ])