1 # gpg-error.m4 - autoconf macro to detect libgpg-error.
2 # Copyright (C) 2002, 2003, 2004, 2011, 2014, 2018 g10 Code GmbH
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.
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.
12 # Last-changed: 2018-11-02
15 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
16 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
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.
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.
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"])
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"])
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"
50 if test -x "${SYSROOT}/bin/gpg-error-config" ; then
51 GPG_ERROR_CONFIG="${SYSROOT}/bin/gpg-error-config"
57 AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
63 AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no)
64 min_gpg_error_version=ifelse([$1], ,1.33,$1)
67 if test "$prefix" = NONE ; then
68 prefix_option_expanded=/usr/local
70 prefix_option_expanded="$prefix"
72 if test "$exec_prefix" = NONE ; then
73 exec_prefix_option_expanded=$prefix_option_expanded
75 exec_prefix_option_expanded=$(prefix=$prefix_option_expanded eval echo $exec_prefix)
77 libdir_option_expanded=$(prefix=$prefix_option_expanded exec_prefix=$exec_prefix_option_expanded eval echo $libdir)
79 if test -f $libdir_option_expanded/pkgconfig/gpg-error.pc; then
80 gpgrt_libdir=$libdir_option_expanded
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
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
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`
106 gpg_error_config_version=`$GPG_ERROR_CONFIG --version`
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
120 if test "$major" -eq "$req_major"; then
121 if test "$minor" -ge "$req_minor"; then
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
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])
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`
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"
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`
161 gpg_error_config_host=`$GPG_ERROR_CONFIG --variable=host 2>/dev/null || echo none`
163 if test x"$gpg_error_config_host" != xnone ; then
164 if test x"$gpg_error_config_host" != x"$host" ; then
167 *** The config script "$GPG_ERROR_CONFIG" was
168 *** built for $gpg_error_config_host and thus may not match the
170 *** You may want to use the configure option --with-libgpg-error-prefix
171 *** to specify a matching config script or use \$SYSROOT.
173 gpg_config_script_warn="$gpg_config_script_warn libgpg-error"
179 GPG_ERROR_MT_CFLAGS=""
182 ifelse([$3], , :, [$3])
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)