gpgme.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. # gpgme.m4 - autoconf macro to detect GPGME.
  2. # Copyright (C) 2002, 2003, 2004, 2014, 2018, 2022 g10 Code GmbH
  3. #
  4. # This file is free software; as a special exception the author gives
  5. # unlimited permission to copy and/or distribute it, with or without
  6. # modifications, as long as this notice is preserved.
  7. #
  8. # This file is distributed in the hope that it will be useful, but
  9. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  10. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. #
  12. # Last-changed: 2022-11-25
  13. dnl
  14. dnl Find gpgrt-config, which uses .pc file
  15. dnl (minimum pkg-config functionality, supporting cross build)
  16. dnl
  17. dnl _AM_PATH_GPGRT_CONFIG
  18. AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl
  19. AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH])
  20. if test "$GPGRT_CONFIG" != "no"; then
  21. # Determine gpgrt_libdir
  22. #
  23. # Get the prefix of gpgrt-config assuming it's something like:
  24. # <PREFIX>/bin/gpgrt-config
  25. gpgrt_prefix=${GPGRT_CONFIG%/*/*}
  26. possible_libdir1=${gpgrt_prefix}/lib
  27. # Determine by using system libdir-format with CC, it's like:
  28. # Normal style: /usr/lib
  29. # GNU cross style: /usr/<triplet>/lib
  30. # Debian style: /usr/lib/<multiarch-name>
  31. # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64
  32. # It is assumed that CC is specified to the one of host on cross build.
  33. if libdir_candidates=$(${CC:-cc} -print-search-dirs | \
  34. sed -n -e "/^libraries/{s/libraries: =//;s/:/\\
  35. /g;p;}"); then
  36. # From the output of -print-search-dirs, select valid pkgconfig dirs.
  37. libdir_candidates=$(for dir in $libdir_candidates; do
  38. if p=$(cd $dir 2>/dev/null && pwd); then
  39. test -d "$p/pkgconfig" && echo $p;
  40. fi
  41. done)
  42. for possible_libdir0 in $libdir_candidates; do
  43. # possible_libdir0:
  44. # Fallback candidate, the one of system-installed (by $CC)
  45. # (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32)
  46. # possible_libdir1:
  47. # Another candidate, user-locally-installed
  48. # (<gpgrt_prefix>/lib)
  49. # possible_libdir2
  50. # Most preferred
  51. # (<gpgrt_prefix>/<triplet>/lib,
  52. # <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32)
  53. if test "${possible_libdir0##*/}" = "lib"; then
  54. possible_prefix0=${possible_libdir0%/lib}
  55. possible_prefix0_triplet=${possible_prefix0##*/}
  56. if test -z "$possible_prefix0_triplet"; then
  57. continue
  58. fi
  59. possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib
  60. else
  61. possible_prefix0=${possible_libdir0%%/lib*}
  62. possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0}
  63. fi
  64. if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then
  65. gpgrt_libdir=${possible_libdir2}
  66. elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then
  67. gpgrt_libdir=${possible_libdir1}
  68. elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then
  69. gpgrt_libdir=${possible_libdir0}
  70. fi
  71. if test -n "$gpgrt_libdir"; then break; fi
  72. done
  73. if test -z "$libdir_candidates"; then
  74. # No valid pkgconfig dir in any of the system directories, fallback
  75. gpgrt_libdir=${possible_libdir1}
  76. fi
  77. else
  78. # When we cannot determine system libdir-format, use this:
  79. gpgrt_libdir=${possible_libdir1}
  80. fi
  81. else
  82. unset GPGRT_CONFIG
  83. fi
  84. if test -n "$gpgrt_libdir"; then
  85. GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
  86. if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
  87. GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
  88. AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
  89. gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion`
  90. else
  91. unset GPGRT_CONFIG
  92. fi
  93. elif test "$GPG_ERROR_CONFIG" != "no"; then
  94. gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
  95. unset GPGRT_CONFIG
  96. fi
  97. ])
  98. AC_DEFUN([_AM_PATH_GPGME_CONFIG],[dnl
  99. AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl
  100. AC_ARG_WITH(gpgme-prefix,
  101. AS_HELP_STRING([--with-gpgme-prefix=PFX],
  102. [prefix where GPGME is installed (optional)]),
  103. gpgme_config_prefix="$withval", gpgme_config_prefix="")
  104. if test x"${GPGME_CONFIG}" = x ; then
  105. if test x"${gpgme_config_prefix}" != x ; then
  106. GPGME_CONFIG="${gpgme_config_prefix}/bin/gpgme-config"
  107. else
  108. case "${SYSROOT}" in
  109. /*)
  110. if test -x "${SYSROOT}/bin/gpgme-config" ; then
  111. GPGME_CONFIG="${SYSROOT}/bin/gpgme-config"
  112. fi
  113. ;;
  114. '')
  115. ;;
  116. *)
  117. AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
  118. ;;
  119. esac
  120. fi
  121. fi
  122. use_gpgrt_config=""
  123. if test x"$GPGRT_CONFIG" != x -a "$GPGRT_CONFIG" != "no"; then
  124. if $GPGRT_CONFIG gpgme --exists; then
  125. GPGME_CONFIG="$GPGRT_CONFIG gpgme"
  126. AC_MSG_NOTICE([Use gpgrt-config as gpgme-config])
  127. use_gpgrt_config=yes
  128. fi
  129. fi
  130. if test -z "$use_gpgrt_config"; then
  131. AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no)
  132. fi
  133. if test "$GPGME_CONFIG" != "no" ; then
  134. if test -z "$use_gpgrt_config"; then
  135. gpgme_version=`$GPGME_CONFIG --version`
  136. else
  137. gpgme_version=`$GPGME_CONFIG --modversion`
  138. fi
  139. fi
  140. gpgme_version_major=`echo $gpgme_version | \
  141. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
  142. gpgme_version_minor=`echo $gpgme_version | \
  143. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
  144. gpgme_version_micro=`echo $gpgme_version | \
  145. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
  146. ])
  147. AC_DEFUN([_AM_PATH_GPGME_CONFIG_HOST_CHECK],
  148. [
  149. if test -z "$use_gpgrt_config"; then
  150. gpgme_config_host=`$GPGME_CONFIG --host 2>/dev/null || echo none`
  151. else
  152. gpgme_config_host=`$GPGME_CONFIG --variable=host 2>/dev/null || echo none`
  153. fi
  154. if test x"$gpgme_config_host" != xnone ; then
  155. if test x"$gpgme_config_host" != x"$host" ; then
  156. AC_MSG_WARN([[
  157. ***
  158. *** The config script "$GPGME_CONFIG" was
  159. *** built for $gpgme_config_host and thus may not match the
  160. *** used host $host.
  161. *** You may want to use the configure option --with-gpgme-prefix
  162. *** to specify a matching config script or use \$SYSROOT.
  163. ***]])
  164. gpg_config_script_warn="$gpg_config_script_warn gpgme"
  165. fi
  166. fi
  167. ])
  168. dnl AM_PATH_GPGME([MINIMUM-VERSION,
  169. dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
  170. dnl Test for libgpgme and define GPGME_CFLAGS and GPGME_LIBS.
  171. dnl
  172. dnl If a prefix option is not used, the config script is first
  173. dnl searched in $SYSROOT/bin and then along $PATH. If the used
  174. dnl config script does not match the host specification the script
  175. dnl is added to the gpg_config_script_warn variable.
  176. dnl
  177. AC_DEFUN([AM_PATH_GPGME],
  178. [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
  179. tmp=ifelse([$1], ,1:0.4.2,$1)
  180. if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
  181. req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
  182. min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
  183. else
  184. req_gpgme_api=0
  185. min_gpgme_version="$tmp"
  186. fi
  187. AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
  188. ok=no
  189. if test "$GPGME_CONFIG" != "no" ; then
  190. req_major=`echo $min_gpgme_version | \
  191. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
  192. req_minor=`echo $min_gpgme_version | \
  193. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
  194. req_micro=`echo $min_gpgme_version | \
  195. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
  196. if test "$gpgme_version_major" -gt "$req_major"; then
  197. ok=yes
  198. else
  199. if test "$gpgme_version_major" -eq "$req_major"; then
  200. if test "$gpgme_version_minor" -gt "$req_minor"; then
  201. ok=yes
  202. else
  203. if test "$gpgme_version_minor" -eq "$req_minor"; then
  204. if test "$gpgme_version_micro" -ge "$req_micro"; then
  205. ok=yes
  206. fi
  207. fi
  208. fi
  209. fi
  210. fi
  211. fi
  212. if test $ok = yes; then
  213. # If we have a recent GPGME, we should also check that the
  214. # API is compatible.
  215. if test "$req_gpgme_api" -gt 0 ; then
  216. if test -z "$use_gpgrt_config"; then
  217. tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
  218. else
  219. tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
  220. fi
  221. if test "$tmp" -gt 0 ; then
  222. if test "$req_gpgme_api" -ne "$tmp" ; then
  223. ok=no
  224. fi
  225. fi
  226. fi
  227. fi
  228. if test $ok = yes; then
  229. GPGME_CFLAGS=`$GPGME_CONFIG --cflags`
  230. GPGME_LIBS=`$GPGME_CONFIG --libs`
  231. AC_MSG_RESULT(yes)
  232. ifelse([$2], , :, [$2])
  233. _AM_PATH_GPGME_CONFIG_HOST_CHECK
  234. else
  235. GPGME_CFLAGS=""
  236. GPGME_LIBS=""
  237. AC_MSG_RESULT(no)
  238. ifelse([$3], , :, [$3])
  239. fi
  240. AC_SUBST(GPGME_CFLAGS)
  241. AC_SUBST(GPGME_LIBS)
  242. ])
  243. dnl AM_PATH_GPGME_PTHREAD([MINIMUM-VERSION,
  244. dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
  245. dnl Test for libgpgme and define GPGME_PTHREAD_CFLAGS
  246. dnl and GPGME_PTHREAD_LIBS.
  247. dnl
  248. AC_DEFUN([AM_PATH_GPGME_PTHREAD],[
  249. AC_OBSOLETE([$0], [; use AM_PATH_GPGME instead to use GPGME_CFLAGS and GPGME_LIBS])dnl
  250. AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
  251. tmp=ifelse([$1], ,1:0.4.2,$1)
  252. if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
  253. req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
  254. min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
  255. else
  256. req_gpgme_api=0
  257. min_gpgme_version="$tmp"
  258. fi
  259. AC_MSG_CHECKING(for GPGME pthread - version >= $min_gpgme_version)
  260. ok=no
  261. if test "$GPGME_CONFIG" != "no" ; then
  262. req_major=`echo $min_gpgme_version | \
  263. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
  264. req_minor=`echo $min_gpgme_version | \
  265. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
  266. req_micro=`echo $min_gpgme_version | \
  267. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
  268. if test "$gpgme_version_major" -gt "$req_major"; then
  269. ok=yes
  270. else
  271. if test "$gpgme_version_major" -eq "$req_major"; then
  272. if test "$gpgme_version_minor" -gt "$req_minor"; then
  273. ok=yes
  274. else
  275. if test "$gpgme_version_minor" -eq "$req_minor"; then
  276. if test "$gpgme_version_micro" -ge "$req_micro"; then
  277. ok=yes
  278. fi
  279. fi
  280. fi
  281. fi
  282. fi
  283. fi
  284. if test $ok = yes; then
  285. # If we have a recent GPGME, we should also check that the
  286. # API is compatible.
  287. if test "$req_gpgme_api" -gt 0 ; then
  288. if test -z "$use_gpgrt_config"; then
  289. tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
  290. else
  291. tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
  292. fi
  293. if test "$tmp" -gt 0 ; then
  294. if test "$req_gpgme_api" -ne "$tmp" ; then
  295. ok=no
  296. fi
  297. fi
  298. fi
  299. fi
  300. if test $ok = yes; then
  301. GPGME_PTHREAD_CFLAGS=`$GPGME_CONFIG --cflags`
  302. GPGME_PTHREAD_LIBS=`$GPGME_CONFIG --libs`
  303. AC_MSG_RESULT(yes)
  304. ifelse([$2], , :, [$2])
  305. _AM_PATH_GPGME_CONFIG_HOST_CHECK
  306. else
  307. GPGME_PTHREAD_CFLAGS=""
  308. GPGME_PTHREAD_LIBS=""
  309. AC_MSG_RESULT(no)
  310. ifelse([$3], , :, [$3])
  311. fi
  312. AC_SUBST(GPGME_PTHREAD_CFLAGS)
  313. AC_SUBST(GPGME_PTHREAD_LIBS)
  314. ])
  315. dnl AM_PATH_GPGME_GLIB([MINIMUM-VERSION,
  316. dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
  317. dnl Test for libgpgme-glib and define GPGME_GLIB_CFLAGS and GPGME_GLIB_LIBS.
  318. dnl
  319. AC_DEFUN([AM_PATH_GPGME_GLIB],
  320. [ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl
  321. tmp=ifelse([$1], ,1:0.4.2,$1)
  322. if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
  323. req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'`
  324. min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
  325. else
  326. req_gpgme_api=0
  327. min_gpgme_version="$tmp"
  328. fi
  329. AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version)
  330. ok=no
  331. if test "$GPGME_CONFIG" != "no" ; then
  332. req_major=`echo $min_gpgme_version | \
  333. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
  334. req_minor=`echo $min_gpgme_version | \
  335. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
  336. req_micro=`echo $min_gpgme_version | \
  337. sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
  338. if test "$gpgme_version_major" -gt "$req_major"; then
  339. ok=yes
  340. else
  341. if test "$gpgme_version_major" -eq "$req_major"; then
  342. if test "$gpgme_version_minor" -gt "$req_minor"; then
  343. ok=yes
  344. else
  345. if test "$gpgme_version_minor" -eq "$req_minor"; then
  346. if test "$gpgme_version_micro" -ge "$req_micro"; then
  347. ok=yes
  348. fi
  349. fi
  350. fi
  351. fi
  352. fi
  353. fi
  354. if test $ok = yes; then
  355. # If we have a recent GPGME, we should also check that the
  356. # API is compatible.
  357. if test "$req_gpgme_api" -gt 0 ; then
  358. if test -z "$use_gpgrt_config"; then
  359. tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0`
  360. else
  361. tmp=`$GPGME_CONFIG --variable=api_version 2>/dev/null || echo 0`
  362. fi
  363. if test "$tmp" -gt 0 ; then
  364. if test "$req_gpgme_api" -ne "$tmp" ; then
  365. ok=no
  366. fi
  367. fi
  368. fi
  369. fi
  370. if test $ok = yes; then
  371. if test -z "$use_gpgrt_config"; then
  372. GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --glib --cflags`
  373. GPGME_GLIB_LIBS=`$GPGME_CONFIG --glib --libs`
  374. else
  375. if $GPGRT_CONFIG gpgme-glib --exists; then
  376. GPGME_CONFIG="$GPGRT_CONFIG gpgme-glib"
  377. GPGME_GLIB_CFLAGS=`$GPGME_CONFIG --cflags`
  378. GPGME_GLIB_LIBS=`$GPGME_CONFIG --libs`
  379. else
  380. ok = no
  381. fi
  382. fi
  383. fi
  384. if test $ok = yes; then
  385. AC_MSG_RESULT(yes)
  386. ifelse([$2], , :, [$2])
  387. _AM_PATH_GPGME_CONFIG_HOST_CHECK
  388. else
  389. GPGME_GLIB_CFLAGS=""
  390. GPGME_GLIB_LIBS=""
  391. AC_MSG_RESULT(no)
  392. ifelse([$3], , :, [$3])
  393. fi
  394. AC_SUBST(GPGME_GLIB_CFLAGS)
  395. AC_SUBST(GPGME_GLIB_LIBS)
  396. ])