1 # gpg-error.m4 - autoconf macro to detect libgpg-error.
2 # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020, 2021
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: 2022-09-21
16 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
17 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
19 dnl Test for libgpg-error and define GPG_ERROR_CFLAGS, GPG_ERROR_LIBS,
20 dnl GPG_ERROR_MT_CFLAGS, and GPG_ERROR_MT_LIBS. The _MT_ variants are
21 dnl used for programs requireing real multi thread support.
23 dnl If a prefix option is not used, the config script is first
24 dnl searched in $SYSROOT/bin and then along $PATH. If the used
25 dnl config script does not match the host specification the script
26 dnl is added to the gpg_config_script_warn variable.
28 AC_DEFUN([AM_PATH_GPG_ERROR],
29 [ AC_REQUIRE([AC_CANONICAL_HOST])
30 gpg_error_config_prefix=""
31 dnl --with-libgpg-error-prefix=PFX is the preferred name for this option,
32 dnl since that is consistent with how our three siblings use the directory/
33 dnl package name in --with-$dir_name-prefix=PFX.
34 AC_ARG_WITH(libgpg-error-prefix,
35 AS_HELP_STRING([--with-libgpg-error-prefix=PFX],
36 [prefix where GPG Error is installed (optional)]),
37 [gpg_error_config_prefix="$withval"])
39 dnl Accept --with-gpg-error-prefix and make it work the same as
40 dnl --with-libgpg-error-prefix above, for backwards compatibility,
41 dnl but do not document this old, inconsistently-named option.
42 AC_ARG_WITH(gpg-error-prefix,,
43 [gpg_error_config_prefix="$withval"])
45 if test x"${GPG_ERROR_CONFIG}" = x ; then
46 if test x"${gpg_error_config_prefix}" != x ; then
47 GPG_ERROR_CONFIG="${gpg_error_config_prefix}/bin/gpg-error-config"
51 if test -x "${SYSROOT}/bin/gpg-error-config" ; then
52 GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config"
58 AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
64 AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
65 min_gpg_error_version=ifelse([$1], ,1.33,$1)
68 AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no, [$prefix/bin:$PATH])
69 if test "$GPGRT_CONFIG" != "no"; then
70 # Determine gpgrt_libdir
72 # Get the prefix of gpgrt-config assuming it's something like:
73 # <PREFIX>/bin/gpgrt-config
74 gpgrt_prefix=${GPGRT_CONFIG%/*/*}
75 possible_libdir1=${gpgrt_prefix}/lib
76 # Determine by using system libdir-format with CC, it's like:
77 # Normal style: /usr/lib
78 # GNU cross style: /usr/<triplet>/lib
79 # Debian style: /usr/lib/<multiarch-name>
80 # Fedora/openSUSE style: /usr/lib, /usr/lib32 or /usr/lib64
81 # It is assumed that CC is specified to the one of host on cross build.
82 if libdir_candidates=$(${CC:-cc} -print-search-dirs | \
83 sed -n -e "/^libraries/{s/libraries: =//;s/:/\\
85 # From the output of -print-search-dirs, select valid pkgconfig dirs.
86 libdir_candidates=$(for dir in $libdir_candidates; do
87 if p=$(cd $dir 2>/dev/null && pwd); then
88 test -d "$p/pkgconfig" && echo $p;
92 for possible_libdir0 in $libdir_candidates; do
94 # Fallback candidate, the one of system-installed (by $CC)
95 # (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32)
97 # Another candidate, user-locally-installed
98 # (<gpgrt_prefix>/lib)
101 # (<gpgrt_prefix>/<triplet>/lib,
102 # <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32)
103 if test "${possible_libdir0##*/}" = "lib"; then
104 possible_prefix0=${possible_libdir0%/lib}
105 possible_prefix0_triplet=${possible_prefix0##*/}
106 if test -z "$possible_prefix0_triplet"; then
109 possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib
111 possible_prefix0=${possible_libdir0%%/lib*}
112 possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0}
114 if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then
115 gpgrt_libdir=${possible_libdir2}
116 elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then
117 gpgrt_libdir=${possible_libdir1}
118 elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then
119 gpgrt_libdir=${possible_libdir0}
121 if test -n "$gpgrt_libdir"; then break; fi
123 if test -z "$libdir_candidates"; then
124 # No valid pkgconfig dir in any of the system directories, fallback
125 gpgrt_libdir=${possible_libdir1}
128 # When we cannot determine system libdir-format, use this:
129 gpgrt_libdir=${possible_libdir1}
135 if test -n "$gpgrt_libdir"; then
136 GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
137 if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
138 GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
139 AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
140 gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion`
144 elif test "$GPG_ERROR_CONFIG" != "no"; then
145 gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
148 if test "$GPG_ERROR_CONFIG" != "no"; then
149 req_major=`echo $min_gpg_error_version | \
150 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
151 req_minor=`echo $min_gpg_error_version | \
152 sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
153 major=`echo $gpg_error_config_version | \
154 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
155 minor=`echo $gpg_error_config_version | \
156 sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
157 if test "$major" -gt "$req_major"; then
160 if test "$major" -eq "$req_major"; then
161 if test "$minor" -ge "$req_minor"; then
167 AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
168 if test $ok = yes; then
169 GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags`
170 GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs`
171 if test -z "$GPGRT_CONFIG"; then
172 GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null`
173 GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null`
175 GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null`
176 GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS"
177 GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null`
178 GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS"
180 AC_MSG_RESULT([yes ($gpg_error_config_version)])
181 ifelse([$2], , :, [$2])
182 if test -z "$GPGRT_CONFIG"; then
183 gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none`
185 gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none`
187 if test x"$gpg_error_config_host" != xnone ; then
188 if test x"$gpg_error_config_host" != x"$host" ; then
191 *** The config script "$GPG_ERROR_CONFIG" was
192 *** built for $gpg_error_config_host and thus may not match the
194 *** You may want to use the configure option --with-libgpg-error-prefix
195 *** to specify a matching config script or use \$SYSROOT.
197 gpg_config_script_warn="$gpg_config_script_warn libgpg-error"
203 GPG_ERROR_MT_CFLAGS=""
206 ifelse([$3], , :, [$3])
208 AC_SUBST(GPG_ERROR_CFLAGS)
209 AC_SUBST(GPG_ERROR_LIBS)
210 AC_SUBST(GPG_ERROR_MT_CFLAGS)
211 AC_SUBST(GPG_ERROR_MT_LIBS)