1 # gpg-error.m4 - autoconf macro to detect libgpg-error.
2 # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020, 2021, 2022
5 # This file is free software; as a special exception the author gives
6 # unlimited permission to copy and/or distribute it, with or without
7 # modifications, as long as this notice is preserved.
9 # This file is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # Last-changed: 2023-04-01
16 dnl Find gpg-error-config, for backward compatibility
18 dnl _AM_PATH_POSSIBLE_GPG_ERROR_CONFIG
19 AC_DEFUN([_AM_PATH_POSSIBLE_GPG_ERROR_CONFIG],[dnl
20 gpg_error_config_prefix=""
21 dnl --with-libgpg-error-prefix=PFX is the preferred name for this option,
22 dnl since that is consistent with how our three siblings use the directory/
23 dnl package name in --with-$dir_name-prefix=PFX.
24 AC_ARG_WITH(libgpg-error-prefix,
25 AS_HELP_STRING([--with-libgpg-error-prefix=PFX],
26 [prefix where GPG Error is installed (optional)]),
27 [gpg_error_config_prefix="$withval"])
29 dnl Accept --with-gpg-error-prefix and make it work the same as
30 dnl --with-libgpg-error-prefix above, for backwards compatibility,
31 dnl but do not document this old, inconsistently-named option.
32 AC_ARG_WITH(gpg-error-prefix,,
33 [gpg_error_config_prefix="$withval"])
35 if test x"${GPG_ERROR_CONFIG}" = x ; then
36 if test x"${gpg_error_config_prefix}" != x ; then
37 GPG_ERROR_CONFIG="${gpg_error_config_prefix}/bin/gpg-error-config"
41 if test -x "${SYSROOT}/bin/gpg-error-config" ; then
42 GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config"
48 AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
54 AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
58 dnl Find gpgrt-config, which uses .pc file
59 dnl (minimum pkg-config functionality, supporting cross build)
61 dnl _AM_PATH_GPGRT_CONFIG
62 AC_DEFUN([_AM_PATH_GPGRT_CONFIG],[dnl
63 AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH])
64 if test "$GPGRT_CONFIG" != "no"; then
65 # Determine gpgrt_libdir
67 # Get the prefix of gpgrt-config assuming it's something like:
68 # <PREFIX>/bin/gpgrt-config
69 gpgrt_prefix=${GPGRT_CONFIG%/*/*}
70 possible_libdir1=${gpgrt_prefix}/lib
71 # Determine by using system libdir-format with CC, it's like:
72 # Normal style: /usr/lib
73 # GNU cross style: /usr/<triplet>/lib
74 # Debian style: /usr/lib/<multiarch-name>
75 # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64
76 # It is assumed that CC is specified to the one of host on cross build.
77 if libdir_candidates=$(${CC:-cc} -print-search-dirs | \
78 sed -n -e "/^libraries/{s/libraries: =//;s/:/\\
80 # From the output of -print-search-dirs, select valid pkgconfig dirs.
81 libdir_candidates=$(for dir in $libdir_candidates; do
82 if p=$(cd $dir 2>/dev/null && pwd); then
83 test -d "$p/pkgconfig" && echo $p;
87 for possible_libdir0 in $libdir_candidates; do
89 # Fallback candidate, the one of system-installed (by $CC)
90 # (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32)
92 # Another candidate, user-locally-installed
93 # (<gpgrt_prefix>/lib)
96 # (<gpgrt_prefix>/<triplet>/lib,
97 # <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32)
98 if test "${possible_libdir0##*/}" = "lib"; then
99 possible_prefix0=${possible_libdir0%/lib}
100 possible_prefix0_triplet=${possible_prefix0##*/}
101 if test -z "$possible_prefix0_triplet"; then
104 possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib
106 possible_prefix0=${possible_libdir0%%/lib*}
107 possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0}
109 if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then
110 gpgrt_libdir=${possible_libdir2}
111 elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then
112 gpgrt_libdir=${possible_libdir1}
113 elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then
114 gpgrt_libdir=${possible_libdir0}
116 if test -n "$gpgrt_libdir"; then break; fi
119 if test -z "$gpgrt_libdir"; then
120 # No valid pkgconfig dir in any of the system directories, fallback
121 gpgrt_libdir=${possible_libdir1}
127 if test -n "$gpgrt_libdir"; then
128 GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
129 if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
130 GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
131 AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
132 gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion`
134 gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
137 elif test "$GPG_ERROR_CONFIG" != "no"; then
138 gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
143 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
144 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
146 dnl Test for libgpg-error and define GPG_ERROR_CFLAGS, GPG_ERROR_LIBS,
147 dnl GPG_ERROR_MT_CFLAGS, and GPG_ERROR_MT_LIBS. The _MT_ variants are
148 dnl used for programs requireing real multi thread support.
150 dnl If a prefix option is not used, the config script is first
151 dnl searched in $SYSROOT/bin and then along $PATH. If the used
152 dnl config script does not match the host specification the script
153 dnl is added to the gpg_config_script_warn variable.
155 AC_DEFUN([AM_PATH_GPG_ERROR],[dnl
156 AC_REQUIRE([AC_CANONICAL_HOST])dnl
157 AC_REQUIRE([_AM_PATH_POSSIBLE_GPG_ERROR_CONFIG])dnl
158 AC_REQUIRE([_AM_PATH_GPGRT_CONFIG])dnl
159 min_gpg_error_version=ifelse([$1], ,1.33,$1)
161 if test "$GPG_ERROR_CONFIG" != "no"; then
162 req_major=`echo $min_gpg_error_version | \
163 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
164 req_minor=`echo $min_gpg_error_version | \
165 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
166 major=`echo $gpg_error_config_version | \
167 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
168 minor=`echo $gpg_error_config_version | \
169 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
170 if test "$major" -gt "$req_major"; then
173 if test "$major" -eq "$req_major"; then
174 if test "$minor" -ge "$req_minor"; then
180 AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
181 if test $ok = yes; then
182 GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags`
183 GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs`
184 if test -z "$GPGRT_CONFIG"; then
185 GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null`
186 GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null`
188 GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null`
189 GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS"
190 GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null`
191 GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS"
193 AC_MSG_RESULT([yes ($gpg_error_config_version)])
194 ifelse([$2], , :, [$2])
195 if test -z "$GPGRT_CONFIG"; then
196 gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none`
198 gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none`
200 if test x"$gpg_error_config_host" != xnone ; then
201 if test x"$gpg_error_config_host" != x"$host" ; then
204 *** The config script "$GPG_ERROR_CONFIG" was
205 *** built for $gpg_error_config_host and thus may not match the
207 *** You may want to use the configure option --with-libgpg-error-prefix
208 *** to specify a matching config script or use \$SYSROOT.
210 gpg_config_script_warn="$gpg_config_script_warn libgpg-error"
216 GPG_ERROR_MT_CFLAGS=""
219 ifelse([$3], , :, [$3])
221 AC_SUBST(GPG_ERROR_CFLAGS)
222 AC_SUBST(GPG_ERROR_LIBS)
223 AC_SUBST(GPG_ERROR_MT_CFLAGS)
224 AC_SUBST(GPG_ERROR_MT_LIBS)