docs: Keep pwmd.html during clean.
[pwmd.git] / m4 / gpg-error.m4
blobd910754e8d0db4e7138bb695b773988a15f9e0eb
1 # gpg-error.m4 - autoconf macro to detect libgpg-error.
2 # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018, 2020, 2021
3 #               g10 Code GmbH
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: 2021-02-16
16 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
17 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
18 dnl
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.
22 dnl
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.
27 dnl
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"
48      else
49        case "${SYSROOT}" in
50          /*)
51            if test -x "${SYSROOT}/bin/gpg-error-config" ; then
52              GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config"
53            fi
54            ;;
55          '')
56            ;;
57           *)
58            AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
59            ;;
60        esac
61      fi
62   fi
64   AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
65   min_gpg_error_version=ifelse([$1], ,1.33,$1)
66   ok=no
68   AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no)
69   if test "$GPGRT_CONFIG" != "no"; then
70     # Determine gpgrt_libdir
71     #
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/:/\n/gp}"); then
84       # From the output of -print-search-dirs, select valid pkgconfig dirs.
85       libdir_candidates=$(for dir in $libdir_candidates; do
86         if p=$(cd $dir 2>/dev/null && pwd); then
87           test -d "$p/pkgconfig" && echo $p;
88         fi
89       done)
91       for possible_libdir0 in $libdir_candidates; do
92         # possible_libdir0:
93         #   Fallback candidate, the one of system-installed (by $CC)
94         #   (/usr/<triplet>/lib, /usr/lib/<multiarch-name> or /usr/lib32)
95         # possible_libdir1:
96         #   Another candidate, user-locally-installed
97         #   (<gpgrt_prefix>/lib)
98         # possible_libdir2
99         #   Most preferred
100         #   (<gpgrt_prefix>/<triplet>/lib,
101         #    <gpgrt_prefix>/lib/<multiarch-name> or <gpgrt_prefix>/lib32)
102         if test "${possible_libdir0##*/}" = "lib"; then
103           possible_prefix0=${possible_libdir0%/lib}
104           possible_prefix0_triplet=${possible_prefix0##*/}
105           if test -z "$possible_prefix0_triplet"; then
106             continue
107           fi
108           possible_libdir2=${gpgrt_prefix}/$possible_prefix0_triplet/lib
109         else
110           possible_prefix0=${possible_libdir0%%/lib*}
111           possible_libdir2=${gpgrt_prefix}${possible_libdir0#$possible_prefix0}
112         fi
113         if test -f ${possible_libdir2}/pkgconfig/gpg-error.pc; then
114           gpgrt_libdir=${possible_libdir2}
115         elif test -f ${possible_libdir1}/pkgconfig/gpg-error.pc; then
116           gpgrt_libdir=${possible_libdir1}
117         elif test -f ${possible_libdir0}/pkgconfig/gpg-error.pc; then
118           gpgrt_libdir=${possible_libdir0}
119         fi
120         if test -n "$gpgrt_libdir"; then break; fi
121       done
122     else
123       # When we cannot determine system libdir-format, use this:
124       gpgrt_libdir=${possible_libdir1}
125     fi
126   else
127     unset GPGRT_CONFIG
128   fi
130   if test -n "$gpgrt_libdir"; then
131     GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
132     if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
133       GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
134       AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
135       gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion`
136     else
137       unset GPGRT_CONFIG
138     fi
139   elif test "$GPG_ERROR_CONFIG" != "no"; then
140     gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
141   fi
142   if test "$GPG_ERROR_CONFIG" != "no"; then
143     req_major=`echo $min_gpg_error_version | \
144                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
145     req_minor=`echo $min_gpg_error_version | \
146                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
147     major=`echo $gpg_error_config_version | \
148                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
149     minor=`echo $gpg_error_config_version | \
150                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
151     if test "$major" -gt "$req_major"; then
152         ok=yes
153     else
154         if test "$major" -eq "$req_major"; then
155             if test "$minor" -ge "$req_minor"; then
156                ok=yes
157             fi
158         fi
159     fi
160   fi
161   AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
162   if test $ok = yes; then
163     GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags`
164     GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs`
165     if test -z "$GPGRT_CONFIG"; then
166       GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null`
167       GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null`
168     else
169       GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null`
170       GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS"
171       GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null`
172       GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS"
173     fi
174     AC_MSG_RESULT([yes ($gpg_error_config_version)])
175     ifelse([$2], , :, [$2])
176     if test -z "$GPGRT_CONFIG"; then
177       gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none`
178     else
179       gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none`
180     fi
181     if test x"$gpg_error_config_host" != xnone ; then
182       if test x"$gpg_error_config_host" != x"$host" ; then
183   AC_MSG_WARN([[
185 *** The config script "$GPG_ERROR_CONFIG" was
186 *** built for $gpg_error_config_host and thus may not match the
187 *** used host $host.
188 *** You may want to use the configure option --with-libgpg-error-prefix
189 *** to specify a matching config script or use \$SYSROOT.
190 ***]])
191         gpg_config_script_warn="$gpg_config_script_warn libgpg-error"
192       fi
193     fi
194   else
195     GPG_ERROR_CFLAGS=""
196     GPG_ERROR_LIBS=""
197     GPG_ERROR_MT_CFLAGS=""
198     GPG_ERROR_MT_LIBS=""
199     AC_MSG_RESULT(no)
200     ifelse([$3], , :, [$3])
201   fi
202   AC_SUBST(GPG_ERROR_CFLAGS)
203   AC_SUBST(GPG_ERROR_LIBS)
204   AC_SUBST(GPG_ERROR_MT_CFLAGS)
205   AC_SUBST(GPG_ERROR_MT_LIBS)