spelling: Fix "synchronize"
[gnupg.git] / m4 / gpg-error.m4
1 # gpg-error.m4 - autoconf macro to detect libgpg-error.
2 # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018 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: 2018-11-02
13
14
15 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
16 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
17 dnl
18 dnl Test for libgpg-error and define GPG_ERROR_CFLAGS, GPG_ERROR_LIBS,
19 dnl GPG_ERROR_MT_CFLAGS, and GPG_ERROR_MT_LIBS.  The _MT_ variants are
20 dnl used for programs requireing real multi thread support.
21 dnl
22 dnl If a prefix option is not used, the config script is first
23 dnl searched in $SYSROOT/bin and then along $PATH.  If the used
24 dnl config script does not match the host specification the script
25 dnl is added to the gpg_config_script_warn variable.
26 dnl
27 AC_DEFUN([AM_PATH_GPG_ERROR],
28 [ AC_REQUIRE([AC_CANONICAL_HOST])
29   gpg_error_config_prefix=""
30   dnl --with-libgpg-error-prefix=PFX is the preferred name for this option,
31   dnl since that is consistent with how our three siblings use the directory/
32   dnl package name in --with-$dir_name-prefix=PFX.
33   AC_ARG_WITH(libgpg-error-prefix,
34               AC_HELP_STRING([--with-libgpg-error-prefix=PFX],
35                              [prefix where GPG Error is installed (optional)]),
36               [gpg_error_config_prefix="$withval"])
37
38   dnl Accept --with-gpg-error-prefix and make it work the same as
39   dnl --with-libgpg-error-prefix above, for backwards compatibility,
40   dnl but do not document this old, inconsistently-named option.
41   AC_ARG_WITH(gpg-error-prefix,,
42               [gpg_error_config_prefix="$withval"])
43
44   if test x"${GPG_ERROR_CONFIG}" = x ; then
45      if test x"${gpg_error_config_prefix}" != x ; then
46         GPG_ERROR_CONFIG="${gpg_error_config_prefix}/bin/gpg-error-config"
47      else
48        case "${SYSROOT}" in
49          /*)
50            if test -x "${SYSROOT}/bin/gpg-error-config" ; then
51              GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config"
52            fi
53            ;;
54          '')
55            ;;
56           *)
57            AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
58            ;;
59        esac
60      fi
61   fi
62
63   AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
64   min_gpg_error_version=ifelse([$1], ,1.33,$1)
65   ok=no
66
67   if test "$prefix" = NONE ; then
68     prefix_option_expanded=/usr/local
69   else
70     prefix_option_expanded="$prefix"
71   fi
72   if test "$exec_prefix" = NONE ; then
73     exec_prefix_option_expanded=$prefix_option_expanded
74   else
75     exec_prefix_option_expanded=$(prefix=$prefix_option_expanded eval echo $exec_prefix)
76   fi
77   libdir_option_expanded=$(prefix=$prefix_option_expanded exec_prefix=$exec_prefix_option_expanded eval echo $libdir)
78
79   if test -f $libdir_option_expanded/pkgconfig/gpg-error.pc; then
80     gpgrt_libdir=$libdir_option_expanded
81   else
82     if crt1_path=$(${CC:-cc} -print-file-name=crt1.o 2>/dev/null); then
83       if possible_libdir=$(cd ${crt1_path%/*} && pwd 2>/dev/null); then
84         if test -f $possible_libdir/pkgconfig/gpg-error.pc; then
85           gpgrt_libdir=$possible_libdir
86         fi
87       fi
88     fi
89   fi
90
91   if test "$GPG_ERROR_CONFIG" = "no" -a -n "$gpgrt_libdir"; then
92     AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no)
93     if test "$GPGRT_CONFIG" = "no"; then
94       unset GPGRT_CONFIG
95     else
96       GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
97       if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
98         GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
99         AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
100         gpg_error_config_version=`$GPG_ERROR_CONFIG --modversion`
101       else
102         unset GPGRT_CONFIG
103       fi
104     fi
105   else
106     gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
107   fi
108   if test "$GPG_ERROR_CONFIG" != "no"; then
109     req_major=`echo $min_gpg_error_version | \
110                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
111     req_minor=`echo $min_gpg_error_version | \
112                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
113     major=`echo $gpg_error_config_version | \
114                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
115     minor=`echo $gpg_error_config_version | \
116                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
117     if test "$major" -gt "$req_major"; then
118         ok=yes
119     else
120         if test "$major" -eq "$req_major"; then
121             if test "$minor" -ge "$req_minor"; then
122                ok=yes
123             fi
124         fi
125     fi
126     if test -z "$GPGRT_CONFIG" -a -n "$gpgrt_libdir"; then
127       if test "$major" -gt 1 -o "$major" -eq 1 -a "$minor" -ge 33; then
128         AC_PATH_PROG(GPGRT_CONFIG, gpgrt-config, no)
129         if test "$GPGRT_CONFIG" = "no"; then
130           unset GPGRT_CONFIG
131         else
132           GPGRT_CONFIG="$GPGRT_CONFIG --libdir=$gpgrt_libdir"
133           if $GPGRT_CONFIG gpg-error >/dev/null 2>&1; then
134             GPG_ERROR_CONFIG="$GPGRT_CONFIG gpg-error"
135             AC_MSG_NOTICE([Use gpgrt-config with $gpgrt_libdir as gpg-error-config])
136           else
137             unset GPGRT_CONFIG
138           fi
139         fi
140       fi
141     fi
142   fi
143   AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
144   if test $ok = yes; then
145     GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags`
146     GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs`
147     if test -z "$GPGRT_CONFIG"; then
148       GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --mt --cflags 2>/dev/null`
149       GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --mt --libs 2>/dev/null`
150     else
151       GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG --variable=mtcflags 2>/dev/null`
152       GPG_ERROR_MT_CFLAGS="$GPG_ERROR_CFLAGS${GPG_ERROR_CFLAGS:+ }$GPG_ERROR_MT_CFLAGS"
153       GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG --variable=mtlibs 2>/dev/null`
154       GPG_ERROR_MT_LIBS="$GPG_ERROR_LIBS${GPG_ERROR_LIBS:+ }$GPG_ERROR_MT_LIBS"
155     fi
156     AC_MSG_RESULT([yes ($gpg_error_config_version)])
157     ifelse([$2], , :, [$2])
158     if test -z "$GPGRT_CONFIG"; then
159       gpg_error_config_host=`$GPG_ERROR_CONFIG --host 2>/dev/null || echo none`
160     else
161       gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none`
162     fi
163     if test x"$gpg_error_config_host" != xnone ; then
164       if test x"$gpg_error_config_host" != x"$host" ; then
165   AC_MSG_WARN([[
166 ***
167 *** The config script "$GPG_ERROR_CONFIG" was
168 *** built for $gpg_error_config_host and thus may not match the
169 *** used host $host.
170 *** You may want to use the configure option --with-libgpg-error-prefix
171 *** to specify a matching config script or use \$SYSROOT.
172 ***]])
173         gpg_config_script_warn="$gpg_config_script_warn libgpg-error"
174       fi
175     fi
176   else
177     GPG_ERROR_CFLAGS=""
178     GPG_ERROR_LIBS=""
179     GPG_ERROR_MT_CFLAGS=""
180     GPG_ERROR_MT_LIBS=""
181     AC_MSG_RESULT(no)
182     ifelse([$3], , :, [$3])
183   fi
184   AC_SUBST(GPG_ERROR_CFLAGS)
185   AC_SUBST(GPG_ERROR_LIBS)
186   AC_SUBST(GPG_ERROR_MT_CFLAGS)
187   AC_SUBST(GPG_ERROR_MT_LIBS)
188 ])