chiark / gitweb /
Import gnupg2_2.1.17.orig.tar.bz2
[gnupg2.git] / m4 / gpg-error.m4
1 # gpg-error.m4 - autoconf macro to detect libgpg-error.
2 # Copyright (C) 2002, 2003, 2004, 2011, 2014 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: 2014-10-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], ,0.0,$1)
65   AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
66   ok=no
67   if test "$GPG_ERROR_CONFIG" != "no" \
68      && test -f "$GPG_ERROR_CONFIG" ; then
69     req_major=`echo $min_gpg_error_version | \
70                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
71     req_minor=`echo $min_gpg_error_version | \
72                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
73     gpg_error_config_version=`$GPG_ERROR_CONFIG $gpg_error_config_args --version`
74     major=`echo $gpg_error_config_version | \
75                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
76     minor=`echo $gpg_error_config_version | \
77                sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
78     if test "$major" -gt "$req_major"; then
79         ok=yes
80     else
81         if test "$major" -eq "$req_major"; then
82             if test "$minor" -ge "$req_minor"; then
83                ok=yes
84             fi
85         fi
86     fi
87   fi
88   if test $ok = yes; then
89     GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --cflags`
90     GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --libs`
91     GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --mt --cflags 2>/dev/null`
92     GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --mt --libs 2>/dev/null`
93     AC_MSG_RESULT([yes ($gpg_error_config_version)])
94     ifelse([$2], , :, [$2])
95     gpg_error_config_host=`$GPG_ERROR_CONFIG $gpg_error_config_args --host 2>/dev/null || echo none`
96     if test x"$gpg_error_config_host" != xnone ; then
97       if test x"$gpg_error_config_host" != x"$host" ; then
98   AC_MSG_WARN([[
99 ***
100 *** The config script $GPG_ERROR_CONFIG was
101 *** built for $gpg_error_config_host and thus may not match the
102 *** used host $host.
103 *** You may want to use the configure option --with-gpg-error-prefix
104 *** to specify a matching config script or use \$SYSROOT.
105 ***]])
106         gpg_config_script_warn="$gpg_config_script_warn libgpg-error"
107       fi
108     fi
109   else
110     GPG_ERROR_CFLAGS=""
111     GPG_ERROR_LIBS=""
112     GPG_ERROR_MT_CFLAGS=""
113     GPG_ERROR_MT_LIBS=""
114     AC_MSG_RESULT(no)
115     ifelse([$3], , :, [$3])
116   fi
117   AC_SUBST(GPG_ERROR_CFLAGS)
118   AC_SUBST(GPG_ERROR_LIBS)
119   AC_SUBST(GPG_ERROR_MT_CFLAGS)
120   AC_SUBST(GPG_ERROR_MT_LIBS)
121 ])