Add convenience macro GPGME_PROTOCOL_OPENPGP.
[gpgme.git] / configure.ac
1 # configure.ac for GPGME
2 # Copyright (C) 2000 Werner Koch (dd9jn)
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 #               2009, 2010, 2011, 2012, 2013  g10 Code GmbH
5 #
6 # This file is part of GPGME.
7 #
8 # GPGME is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as
10 # published by the Free Software Foundation; either version 2.1 of the
11 # License, or (at your option) any later version.
12 #
13 # GPGME is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
16 # Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, see <http://www.gnu.org/licenses/>.
20
21 # (Process this file with autoconf to produce a configure script.)
22 AC_PREREQ(2.59)
23 min_automake_version="1.11"
24
25 # To build a release you need to create a tag with the version number
26 # (git tag -s gpgme-n.m.k) and run "./autogen.sh --force".  Please
27 # bump the version number immediately after the release and do another
28 # commit and push so that the git magic is able to work.  See below
29 # for the LT versions.
30 m4_define(mym4_version_major, [1])
31 m4_define(mym4_version_minor, [4])
32 m4_define(mym4_version_micro, [2])
33
34 # Below is m4 magic to extract and compute the revision number, the
35 # decimalized short revision number, a beta version string, and a flag
36 # indicating a development version (mym4_isgit). Note that the m4
37 # processing is done by autoconf and not during the configure run.
38 m4_define(mym4_version,
39           [mym4_version_major.mym4_version_minor.mym4_version_micro])
40 m4_define([mym4_revision],
41           m4_esyscmd([git rev-parse --short HEAD | tr -d '\n\r']))
42 m4_define([mym4_revision_dec],
43           m4_esyscmd_s([echo $((0x$(echo ]mym4_revision[|head -c 4)))]))
44 m4_define([mym4_betastring],
45           m4_esyscmd_s([git describe --match 'gpgme-[0-9].*[0-9]' --long|\
46                         awk -F- '$3!=0{print"-beta"$3}']))
47 m4_define([mym4_isgit],m4_if(mym4_betastring,[],[no],[yes]))
48 m4_define([mym4_full_version],[mym4_version[]mym4_betastring])
49
50 AC_INIT([gpgme],[mym4_full_version],[http://bugs.gnupg.org])
51
52 # LT Version numbers, remember to change them just *before* a release.
53 #   (Code changed:                      REVISION++)
54 #   (Interfaces added/removed/changed:  CURRENT++, REVISION=0)
55 #   (Interfaces added:                  AGE++)
56 #   (Interfaces removed/changed:        AGE=0)
57 #
58 LIBGPGME_LT_CURRENT=20
59 # Subtract 2 from this value if you want to make the LFS transition an
60 # ABI break.  [Note to self: Remove this comment with the next regular break.]
61 LIBGPGME_LT_AGE=9
62 LIBGPGME_LT_REVISION=1
63
64 # If the API is changed in an incompatible way: increment the next counter.
65 GPGME_CONFIG_API_VERSION=1
66 ##############################################
67
68 NEED_GPG_ERROR_VERSION=1.8
69 NEED_LIBASSUAN_API=2
70 NEED_LIBASSUAN_VERSION=2.0.2
71
72
73 PACKAGE=$PACKAGE_NAME
74 VERSION=$PACKAGE_VERSION
75
76 AC_CONFIG_AUX_DIR([build-aux])
77 AC_CONFIG_MACRO_DIR([m4])
78 AC_CONFIG_SRCDIR(src/gpgme.h.in)
79 AC_CONFIG_HEADER(config.h)
80 AM_INIT_AUTOMAKE
81 AM_MAINTAINER_MODE
82 AC_CANONICAL_HOST
83
84 # Enable GNU extensions on systems that have them.
85 AC_GNU_SOURCE
86
87 AH_VERBATIM([_REENTRANT],
88 [/* To allow the use of GPGME in multithreaded programs we have to use
89   special features from the library.
90   IMPORTANT: gpgme is not yet fully reentrant and you should use it
91   only from one thread.  */
92 #ifndef _REENTRANT
93 # define _REENTRANT 1
94 #endif])
95
96 AC_PROG_CC
97 AC_PROG_CXX
98
99 # Note: A suitable gitlog-to-changelog script can be found in GnuPG master.
100 AC_CHECK_PROGS(GITLOG_TO_CHANGELOG, gitlog-to-changelog, [gitlog-to-changelog])
101
102 AC_SUBST(LIBGPGME_LT_CURRENT)
103 AC_SUBST(LIBGPGME_LT_AGE)
104 AC_SUBST(LIBGPGME_LT_REVISION)
105
106 AC_SUBST(PACKAGE)
107 AC_SUBST(VERSION)
108 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package])
109 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package])
110 VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_version_major \
111                           mym4_version_minor mym4_version_micro)
112 AC_SUBST(VERSION_NUMBER)
113
114 # Don't default to build static libs.
115 LT_PREREQ([2.2.6])
116 LT_INIT([win32-dll disable-static])
117 LT_LANG([Windows Resource])
118
119 # For now we hardcode the use of version scripts.  It would be better
120 # to write a test for this or even implement this within libtool.
121 have_ld_version_script=no
122 case "${host}" in
123     *-*-linux*)
124         have_ld_version_script=yes
125         ;;
126     *-*-gnu*)
127         have_ld_version_script=yes
128         ;;
129     *-apple-darwin*)
130         AC_DEFINE(_XOPEN_SOURCE, 500, Activate POSIX interface on MacOS X)
131         ;;
132 esac
133
134 AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
135
136 GPG_DEFAULT=no
137 GPGSM_DEFAULT=no
138 GPGCONF_DEFAULT=no
139 G13_DEFAULT=no
140 component_system=None
141 have_dosish_system=no
142 have_android_system=no
143 have_w32_system=no
144 have_w64_system=no
145 build_w32_glib=no
146 build_w32_qt=no
147 case "${host}" in
148     x86_64-*mingw32*)
149         have_w64_system=yes
150         ;;
151     *-mingw32ce*)
152         have_w32ce_system=yes
153         ;;
154     *-linux-androideabi)
155         have_android_system=yes
156         ;;
157 esac
158 case "${host}" in
159     *-mingw32ce*|*-mingw32*)
160         have_dosish_system=yes
161         have_w32_system=yes
162         GPG_DEFAULT='c:\\gnupg\\gpg.exe'
163         GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
164         GPGCONF_DEFAULT='c:\\gnupg\\gpgconf.exe'
165         G13_DEFAULT='c:\\gnupg\\g13.exe'
166         #component_system='COM+'
167
168         AM_PATH_GLIB_2_0
169         AC_ARG_ENABLE(w32-glib,
170             AC_HELP_STRING([--enable-w32-glib], [build GPGME Glib for W32]),
171                            build_w32_glib=$enableval)
172
173         # Check disabled, because the qt-dev packages in gpg4win do
174         # not provide any support for cross compilation.
175         # PKG_CHECK_MODULES(QT4_CORE, QtCore)
176
177         # Use it like this:
178         # ./configure --enable-w32-qt QT4_CORE_CFLAGS="..." QT4_CORE_LIBS="..."
179         AC_SUBST(QT4_CORE_CFLAGS)
180         AC_SUBST(QT4_CORE_LIBS)
181         AC_ARG_ENABLE(w32-qt,
182             AC_HELP_STRING([--enable-w32-qt], [build GPGME Qt for W32]),
183                            build_w32_qt=$enableval)
184         ;;
185     *)
186         AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
187         if test "$have_pthread" = yes; then
188           AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
189         fi
190
191         # XXX: Probably use exec-prefix here?
192 #       GPG_DEFAULT='/usr/bin/gpg'
193 #       GPGSM_DEFAULT='/usr/bin/gpgsm'
194 #       GPGCONF_DEFAULT='/usr/bin/gpgconf'
195 #       G13_DEFAULT='/usr/bin/g13'
196         ;;
197 esac
198
199 if test "$have_dosish_system" = yes; then
200    AC_DEFINE(HAVE_DOSISH_SYSTEM,1,
201              [Defined if we run on some of the PCDOS like systems
202               (DOS, Windoze. OS/2) with special properties like
203               no file modes])
204 fi
205 AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes)
206
207 if test "$have_w32_system" = yes; then
208    AC_DEFINE(HAVE_W32_SYSTEM,1,
209              [Defined if we run on any kind of W32 API based system])
210 fi
211 AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
212
213 if test "$have_w64_system" = yes; then
214    AC_DEFINE(HAVE_W64_SYSTEM,1,
215              [Defined if we run on a 64 bit W32 API based system])
216 fi
217 AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
218
219 if test "$have_w32ce_system" = yes; then
220    AC_DEFINE(HAVE_W32CE_SYSTEM,1,
221              [Defined if we run on a W32 CE API based system])
222 fi
223 AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
224
225 if test "$have_android_system" = yes; then
226    AC_DEFINE(HAVE_ANDROID_SYSTEM,1, [Defined if we build for an Android system])
227 fi
228 AM_CONDITIONAL(HAVE_ANDROID_SYSTEM, test "$have_android_system" = yes)
229
230 AM_CONDITIONAL(BUILD_W32_GLIB, test "$build_w32_glib" = yes)
231 AM_CONDITIONAL(BUILD_W32_QT, test "$build_w32_qt" = yes)
232
233 AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
234
235
236 #
237 # Provide information about the build.
238 #
239 BUILD_REVISION="mym4_revision"
240 AC_SUBST(BUILD_REVISION)
241 AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION",
242                    [GIT commit id revision used to build this package])
243
244 changequote(,)dnl
245 BUILD_FILEVERSION=`echo "$PACKAGE_VERSION"|sed 's/\([0-9.]*\).*/\1./;s/\./,/g'`
246 changequote([,])dnl
247 BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec"
248 AC_SUBST(BUILD_FILEVERSION)
249
250 BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date`
251 AC_SUBST(BUILD_TIMESTAMP)
252 AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
253                    [The time this package was configured for a build])
254
255
256
257
258 # Checks for header files.
259 AC_CHECK_HEADERS_ONCE([locale.h sys/select.h sys/uio.h argp.h
260                        unistd.h sys/time.h sys/types.h sys/stat.h])
261
262
263 # Type checks.
264 AC_C_INLINE
265 AC_CHECK_SIZEOF(unsigned int)
266 AC_SYS_LARGEFILE
267 AC_TYPE_OFF_T
268 AC_TYPE_UINTPTR_T
269
270 # A simple compile time check in gpgme.h for GNU/Linux systems that
271 # prevents a file offset bits mismatch between gpgme and the application.
272 NEED__FILE_OFFSET_BITS=0
273 if test "$have_w32_system" != yes; then
274   case "$ac_cv_sys_file_offset_bits" in
275     "" | no | unknown) ;;
276     *)
277     NEED__FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits
278     ;;
279   esac
280 fi
281 AC_SUBST(NEED__FILE_OFFSET_BITS)
282
283 # Figure out platform dependent typedefs for gpgme.h
284 if test "$have_w32_system" = yes; then
285     INSERT__TYPEDEFS_FOR_GPGME_H="
286 #ifdef _WIN64
287 # include <stdint.h>
288   typedef int64_t gpgme_off_t;
289   typedef int64_t gpgme_ssize_t;
290 #else /* _WIN32 */
291   typedef long gpgme_off_t;
292   typedef long gpgme_ssize_t;
293 #endif /* _WIN32 */"
294     API__OFF_T="gpgme_off_t"
295     API__SSIZE_T="gpgme_ssize_t"
296 else
297     INSERT__TYPEDEFS_FOR_GPGME_H="
298 #include <sys/types.h>
299 typedef off_t   gpgme_off_t;
300 typedef ssize_t gpgme_ssize_t;"
301     API__OFF_T="off_t"
302     API__SSIZE_T="ssize_t"
303 fi
304 AC_SUBST(INSERT__TYPEDEFS_FOR_GPGME_H)
305 AM_SUBST_NOTMAKE(INSERT__TYPEDEFS_FOR_GPGME_H)
306 AC_SUBST(API__OFF_T)
307 AM_SUBST_NOTMAKE(API__OFF_T)
308 AC_SUBST(API__SSIZE_T)
309 AM_SUBST_NOTMAKE(API__SSIZE_T)
310
311 # Checks for compiler features.
312 if test "$GCC" = yes; then
313     CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes"
314     if test "$have_w32_system" = yes; then
315        CFLAGS="$CFLAGS -mms-bitfields"
316     fi
317 fi
318
319 # Only used for debugging, so no serious test needed (for actual
320 # functionality you have to test libc as well, this only tests the
321 # compiler).
322 AC_CACHE_CHECK([for __thread],[gpgme_cv_tls_works],
323    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([__thread int foo;])],
324                      gpgme_cv_tls_works=yes,gpgme_cv_tls_works=no))
325 if test "$gpgme_cv_tls_works" = yes; then
326   AC_DEFINE(HAVE_TLS, [1], [Define if __thread is supported])
327 fi
328
329
330 # Checks for library functions.
331 AC_MSG_NOTICE([checking for libraries])
332
333 AC_FUNC_FSEEKO
334
335 AC_REPLACE_FUNCS(vasprintf)
336 if test "$ac_cv_func_vasprintf" != yes; then
337   GNUPG_CHECK_VA_COPY
338 fi
339
340 # Try to find a thread-safe version of ttyname().
341 gnupg_REPLACE_TTYNAME_R
342 if test "$ac_cv_func_ttyname_r" != yes; then
343   AC_MSG_WARN([
344 ***
345 *** ttyname() is not thread-safe and ttyname_r() does not exist
346 ***])
347 fi
348
349 # Try to find a thread-safe version of getenv().
350 have_thread_safe_getenv=no
351 jm_GLIBC21
352 if test $GLIBC21 = yes; then
353   have_thread_safe_getenv=yes
354 fi
355 if test $have_thread_safe_getenv = yes; then
356   AC_DEFINE(HAVE_THREAD_SAFE_GETENV, [1], [Define if getenv() is thread-safe])
357 fi
358 have_getenv_r=no
359 AC_CHECK_FUNCS(getenv_r, have_getenv_r=yes)
360 if test $have_getenv_r = no && test $have_thread_safe_getenv = no; then
361   AC_MSG_WARN([
362 ***
363 *** getenv() is not thread-safe and getenv_r() does not exist
364 ***])
365 fi
366
367 # For converting time strings to seconds since Epoch, we need the timegm
368 # function.
369 AC_CHECK_FUNCS(timegm)
370 if test "$ac_cv_func_timegm" != yes; then
371   AC_MSG_WARN([
372 ***
373 *** timegm() not available - a non-thread-safe kludge will be used
374 *** and the TZ variable might be changed at runtime.
375 ***])
376 fi
377
378 AC_CHECK_FUNCS(setlocale)
379
380 # Checking for libgpg-error.
381 have_gpg_error=no
382 AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
383                   have_gpg_error=yes, have_gpg_error=no)
384 AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
385           [The default error source for GPGME.])
386
387 # And for libassuan.
388 have_libassuan=no
389 AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
390                   have_libassuan=yes, have_libassuan=no)
391 if test "$have_libassuan" = "yes"; then
392   AC_DEFINE_UNQUOTED(GPGME_LIBASSUAN_VERSION, "$libassuan_version",
393                      [version of the libassuan library])
394 fi
395 AM_CONDITIONAL(HAVE_ASSUAN, test "$have_libassuan" = "yes")
396 if test "$have_libassuan" = "yes"; then
397   AC_DEFINE(ENABLE_ASSUAN,1,[Whether Assuan support is enabled])
398 fi
399
400 # Checks for system services
401 NEED_GPG_VERSION_DEFAULT=1.4.0
402 NEED_GPGSM_VERSION_DEFAULT=1.9.6
403 NEED_GPGCONF_VERSION_DEFAULT=2.0.4
404 NEED_G13_VERSION_DEFAULT=2.1.0
405 NEED_GPG_VERSION="$NEED_GPG_VERSION_DEFAULT"
406 NEED_GPGSM_VERSION="$NEED_GPGSM_VERSION_DEFAULT"
407 NEED_GPGCONF_VERSION="$NEED_GPGCONF_VERSION_DEFAULT"
408 NEED_G13_VERSION="$NEED_G13_VERSION_DEFAULT"
409 AC_ARG_WITH(gpg-version,
410             AC_HELP_STRING([--with-gpg-version=VER], [require GnuPG version VER]),
411             NEED_GPG_VERSION=$withval)
412 if test "$NEED_GPG_VERSION" = "yes"; then
413   NEED_GPG_VERSION="$NEED_GPG_VERSION_DEFAULT"
414 fi
415 if test "$NEED_GPG_VERSION" = "no"; then
416   NEED_GPG_VERSION=0.0.0
417 fi
418 AC_ARG_WITH(gpgsm-version,
419             AC_HELP_STRING([--with-gpgsm-version=VER], [require GPGSM version VER]),
420             NEED_GPGSM_VERSION=$withval)
421 if test "$NEED_GPGSM_VERSION" = "yes"; then
422   NEED_GPGSM_VERSION="$NEED_GPGSM_VERSION_DEFAULT"
423 fi
424 if test "$NEED_GPGSM_VERSION" = "no"; then
425   NEED_GPGSM_VERSION=0.0.0
426 fi
427 AC_ARG_WITH(gpgconf-version,
428             AC_HELP_STRING([--with-gpgconf-version=VER], [require GPGCONF version VER]),
429             NEED_GPGCONF_VERSION=$withval)
430 if test "$NEED_GPGCONF_VERSION" = "yes"; then
431   NEED_GPGCONF_VERSION="$NEED_GPGCONF_VERSION_DEFAULT"
432 fi
433 if test "$NEED_GPGCONF_VERSION" = "no"; then
434   NEED_GPGCONF_VERSION=0.0.0
435 fi
436 AC_ARG_WITH(g13-version,
437             AC_HELP_STRING([--with-g13-version=VER], [require G13 version VER]),
438             NEED_G13_VERSION=$withval)
439 if test "$NEED_G13_VERSION" = "yes"; then
440   NEED_G13_VERSION="$NEED_G13_VERSION_DEFAULT"
441 fi
442 if test "$NEED_G13_VERSION" = "no"; then
443   NEED_G13_VERSION=0.0.0
444 fi
445
446 AC_DEFINE_UNQUOTED(NEED_GPG_VERSION, "$NEED_GPG_VERSION",
447                                      [Min. needed GnuPG version.])
448 AC_DEFINE_UNQUOTED(NEED_GPGSM_VERSION, "$NEED_GPGSM_VERSION",
449                                        [Min. needed GPGSM version.])
450 AC_DEFINE_UNQUOTED(NEED_GPGCONF_VERSION, "$NEED_GPGCONF_VERSION",
451                                          [Min. needed GPGCONF version.])
452 AC_DEFINE_UNQUOTED(NEED_G13_VERSION, "$NEED_G13_VERSION",
453                                      [Min. needed G13 version.])
454
455
456 NO_OVERRIDE=no
457 AC_ARG_WITH(gpg,
458             AC_HELP_STRING([--with-gpg=PATH], [use GnuPG binary at PATH]),
459             GPG=$withval, NO_OVERRIDE=yes)
460 if test "$NO_OVERRIDE" = "yes" || test "$GPG" = "yes"; then
461   GPG=
462   NO_OVERRIDE=yes
463   if test "$cross_compiling" != "yes"; then
464     AC_PATH_PROG(GPG, gpg)
465   fi
466   if test -z "$GPG"; then
467     GPG="$GPG_DEFAULT"
468   fi
469 fi
470 if test "$GPG" = no; then
471   if test "$NO_OVERRIDE" = "yes"; then
472     if test "$cross_compiling" != "yes"; then
473       AC_MSG_WARN([
474 ***
475 *** Could not find GnuPG, install GnuPG or use --with-gpg=PATH to enable it
476 ***])
477     else
478       AC_MSG_ERROR([
479 ***
480 *** Can not determine path to GnuPG when cross-compiling, use --with-gpg=PATH
481 ***])
482     fi
483   fi
484 else
485   AC_DEFINE_UNQUOTED(GPG_PATH, "$GPG", [Path to the GnuPG binary.])
486   AC_SUBST(GPG)
487 fi
488 dnl Check for GnuPG version requirement.
489 GPG_VERSION=unknown
490 ok=maybe
491 if test -z "$GPG" -o "x$GPG" = "xno"; then
492   ok=no
493 else
494   if test "$cross_compiling" = "yes"; then
495     AC_MSG_WARN([GnuPG version can not be checked when cross compiling])
496     ok=no
497   else
498     if test ! -x "$GPG"; then
499       AC_MSG_WARN([GnuPG not executable, version check disabled])
500       ok=no
501     fi
502   fi
503 fi
504 if test "$ok" = "maybe"; then
505   AC_MSG_CHECKING(for GPG >= $NEED_GPG_VERSION)
506   req_major=`echo $NEED_GPG_VERSION | \
507              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
508   req_minor=`echo $NEED_GPG_VERSION | \
509              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
510   req_micro=`echo $NEED_GPG_VERSION | \
511              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
512   GPG_VERSION=`$GPG --version | sed -n '1 s/[[^0-9]]*\(.*\)/\1/p'`
513   major=`echo $GPG_VERSION | \
514          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
515   minor=`echo $GPG_VERSION | \
516          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
517   micro=`echo $GPG_VERSION | \
518          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
519
520   if test "$major" -gt "$req_major"; then
521     ok=yes
522   else
523     if test "$major" -eq "$req_major"; then
524       if test "$minor" -gt "$req_minor"; then
525         ok=yes
526       else
527         if test "$minor" -eq "$req_minor"; then
528           if test "$micro" -ge "$req_micro"; then
529             ok=yes
530           fi
531         fi
532       fi
533     fi
534   fi
535   if test "$ok" = "yes"; then
536     AC_MSG_RESULT(yes)
537   else
538     AC_MSG_RESULT(no)
539     AC_MSG_WARN([GPG must be at least version $NEED_GPG_VERSION])
540   fi
541 fi
542 run_gpg_test="$ok"
543 AC_ARG_ENABLE(gpg-test,
544   AC_HELP_STRING([--disable-gpg-test], [disable GPG run test]),
545          run_gpg_test=$enableval)
546 AM_CONDITIONAL(RUN_GPG_TESTS, test "$run_gpg_test" = "yes")
547 AC_SUBST(GPG_PATH)
548
549 NO_OVERRIDE=no
550 AC_ARG_WITH(gpgsm,
551             AC_HELP_STRING([--with-gpgsm=PATH], [use GpgSM binary at PATH]),
552             GPGSM=$withval, NO_OVERRIDE=yes)
553 if test "$NO_OVERRIDE" = "yes" || test "$GPGSM" = "yes"; then
554   GPGSM=
555   NO_OVERRIDE=yes
556   if test "$cross_compiling" != "yes"; then
557     AC_PATH_PROG(GPGSM, gpgsm)
558   fi
559   if test -z "$GPGSM"; then
560     GPGSM="$GPGSM_DEFAULT"
561   fi
562 fi
563 if test "$GPGSM" = no; then
564   if test "$NO_OVERRIDE" = "yes"; then
565     if test "$cross_compiling" != "yes"; then
566       AC_MSG_WARN([
567 ***
568 *** Could not find GpgSM, install GpgSM or use --with-gpgsm=PATH to enable it
569 ***])
570     else
571       AC_MSG_ERROR([
572 ***
573 *** Can not determine path to GpgSM when cross-compiling, use --with-gpgsm=PATH
574 ***])
575     fi
576   fi
577 else
578   AC_DEFINE_UNQUOTED(GPGSM_PATH, "$GPGSM", [Path to the GPGSM binary.])
579   AC_DEFINE(ENABLE_GPGSM,1,[Whether GPGSM support is enabled])
580 fi
581 AM_CONDITIONAL(HAVE_GPGSM, test "$GPGSM" != "no")
582
583
584 dnl Check for GPGSM version requirement.
585 GPGSM_VERSION=unknown
586 ok=maybe
587 if test -z "$GPGSM" -o "x$GPGSM" = "xno"; then
588   ok=no
589 else
590   if test "$cross_compiling" = "yes"; then
591     AC_MSG_WARN([GPGSM version can not be checked when cross compiling])
592     ok=no
593   else
594     if test ! -x "$GPGSM"; then
595       AC_MSG_WARN([GPGSM not executable, version check disabled])
596       ok=no
597     fi
598   fi
599 fi
600 if test "$ok" = "maybe"; then
601   AC_MSG_CHECKING(for GPGSM >= $NEED_GPGSM_VERSION)
602   req_major=`echo $NEED_GPGSM_VERSION | \
603              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
604   req_minor=`echo $NEED_GPGSM_VERSION | \
605              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
606   req_micro=`echo $NEED_GPGSM_VERSION | \
607              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
608   GPGSM_VERSION=`$GPGSM --version | sed -n '1 s/[[^0-9]]*\(.*\)/\1/p'`
609   major=`echo $GPGSM_VERSION | \
610          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
611   minor=`echo $GPGSM_VERSION | \
612          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
613   micro=`echo $GPGSM_VERSION | \
614          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
615
616   if test "$major" -gt "$req_major"; then
617     ok=yes
618   else
619     if test "$major" -eq "$req_major"; then
620       if test "$minor" -gt "$req_minor"; then
621         ok=yes
622       else
623         if test "$minor" -eq "$req_minor"; then
624           if test "$micro" -ge "$req_micro"; then
625             ok=yes
626           fi
627         fi
628       fi
629     fi
630   fi
631   if test "$ok" = "yes"; then
632     AC_MSG_RESULT(yes)
633   else
634     AC_MSG_RESULT(no)
635     AC_MSG_WARN([GPGSM must be at least version $NEED_GPGSM_VERSION])
636   fi
637 fi
638 run_gpgsm_test="$ok"
639 AC_ARG_ENABLE(gpgsm-test,
640   AC_HELP_STRING([--disable-gpgsm-test], [disable GPGSM run test]),
641          run_gpgsm_test=$enableval)
642 AM_CONDITIONAL(RUN_GPGSM_TESTS, test "$run_gpgsm_test" = "yes")
643
644
645 NO_OVERRIDE=no
646 AC_ARG_WITH(gpgconf,
647             AC_HELP_STRING([--with-gpgconf=PATH],
648                            [use gpgconf binary at PATH]),
649             GPGCONF=$withval, NO_OVERRIDE=yes)
650 if test "$NO_OVERRIDE" = "yes" || test "$GPGCONF" = "yes"; then
651   GPGCONF=
652   NO_OVERRIDE=yes
653   if test "$cross_compiling" != "yes"; then
654     AC_PATH_PROG(GPGCONF, gpgconf)
655   fi
656   if test -z "$GPGCONF"; then
657     GPGCONF="$GPGCONF_DEFAULT"
658   fi
659 fi
660 if test "$GPGCONF" = no; then
661   if test "$NO_OVERRIDE" = "yes"; then
662     if test "$cross_compiling" != "yes"; then
663       AC_MSG_WARN([
664 ***
665 *** Could not find gpgconf, install gpgconf or use --with-gpgconf=PATH to enable it
666 ***])
667     else
668       AC_MSG_ERROR([
669 ***
670 *** Can not determine path to gpgconf when cross-compiling, use --with-gpgconf=PATH
671 ***])
672     fi
673   fi
674 else
675   AC_DEFINE_UNQUOTED(GPGCONF_PATH, "$GPGCONF", [Path to the GPGCONF binary.])
676   AC_DEFINE(ENABLE_GPGCONF,1,[Whether GPGCONF support is enabled])
677 fi
678 AM_CONDITIONAL(HAVE_GPGCONF, test "$GPGCONF" != "no")
679
680 dnl Check for GPGCONF version requirement.
681 GPGCONF_VERSION=unknown
682 ok=maybe
683 if test -z "$GPGCONF" -o "x$GPGCONF" = "xno"; then
684   ok=no
685 else
686   if test "$cross_compiling" = "yes"; then
687     AC_MSG_WARN([GPGCONF version can not be checked when cross compiling])
688     ok=no
689   else
690     if test ! -x "$GPGCONF"; then
691       AC_MSG_WARN([GPGCONF not executable, version check disabled])
692       ok=no
693     fi
694   fi
695 fi
696 if test "$ok" = "maybe"; then
697   AC_MSG_CHECKING(for GPGCONF >= $NEED_GPGCONF_VERSION)
698   req_major=`echo $NEED_GPGCONF_VERSION | \
699              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
700   req_minor=`echo $NEED_GPGCONF_VERSION | \
701              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
702   req_micro=`echo $NEED_GPGCONF_VERSION | \
703              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
704   GPGCONF_VERSION=`$GPGCONF --version | sed -n '1 s/[[^0-9]]*\(.*\)/\1/p'`
705   major=`echo $GPGCONF_VERSION | \
706          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
707   minor=`echo $GPGCONF_VERSION | \
708          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
709   micro=`echo $GPGCONF_VERSION | \
710          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
711
712   if test "$major" -gt "$req_major"; then
713     ok=yes
714   else
715     if test "$major" -eq "$req_major"; then
716       if test "$minor" -gt "$req_minor"; then
717         ok=yes
718       else
719         if test "$minor" -eq "$req_minor"; then
720           if test "$micro" -ge "$req_micro"; then
721             ok=yes
722           fi
723         fi
724       fi
725     fi
726   fi
727   if test "$ok" = "yes"; then
728     AC_MSG_RESULT(yes)
729   else
730     AC_MSG_RESULT(no)
731     AC_MSG_WARN([GPGCONF must be at least version $NEED_GPGCONF_VERSION])
732   fi
733 fi
734 run_gpgconf_test="$ok"
735 AC_ARG_ENABLE(gpgconf-test,
736   AC_HELP_STRING([--disable-gpgconf-test], [disable GPGCONF run test]),
737          run_gpgconf_test=$enableval)
738 AM_CONDITIONAL(RUN_GPGCONF_TESTS, test "$run_gpgconf_test" = "yes")
739
740
741 NO_OVERRIDE=no
742 AC_ARG_WITH(g13,
743             AC_HELP_STRING([--with-g13=PATH],
744                            [use g13 binary at PATH]),
745             G13=$withval, NO_OVERRIDE=yes)
746 if test "$NO_OVERRIDE" = "yes" || test "$G13" = "yes"; then
747   G13=
748   NO_OVERRIDE=yes
749   if test "$cross_compiling" != "yes"; then
750     AC_PATH_PROG(G13, g13)
751   fi
752   if test -z "$G13"; then
753     G13="$G13_DEFAULT"
754   fi
755 fi
756 if test "$G13" = no; then
757   if test "$NO_OVERRIDE" = "yes"; then
758     if test "$cross_compiling" != "yes"; then
759       AC_MSG_WARN([
760 ***
761 *** Could not find g13, install g13 or use --with-g13=PATH to enable it
762 ***])
763     else
764       AC_MSG_ERROR([
765 ***
766 *** Can not determine path to g13 when cross-compiling, use --with-g13=PATH
767 ***])
768     fi
769   fi
770 else
771   AC_DEFINE_UNQUOTED(G13_PATH, "$G13", [Path to the G13 binary.])
772   AC_DEFINE(ENABLE_G13,1,[Whether G13 support is enabled])
773 fi
774 AM_CONDITIONAL(HAVE_G13, test "$G13" != "no")
775
776 dnl Check for G13 version requirement.
777 G13_VERSION=unknown
778 ok=maybe
779 if test -z "$G13" -o "x$G13" = "xno"; then
780   ok=no
781 else
782   if test "$cross_compiling" = "yes"; then
783     AC_MSG_WARN([G13 version can not be checked when cross compiling])
784     ok=no
785   else
786     if test ! -x "$G13"; then
787       AC_MSG_WARN([G13 not executable, version check disabled])
788       ok=no
789     fi
790   fi
791 fi
792 if test "$ok" = "maybe"; then
793   AC_MSG_CHECKING(for G13 >= $NEED_G13_VERSION)
794   req_major=`echo $NEED_G13_VERSION | \
795              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
796   req_minor=`echo $NEED_G13_VERSION | \
797              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
798   req_micro=`echo $NEED_G13_VERSION | \
799              sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
800   G13_VERSION=`$G13 --version | sed -n '1 s/.*\ \([[0-9]].*\)/\1/p'`
801   major=`echo $G13_VERSION | \
802          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
803   minor=`echo $G13_VERSION | \
804          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
805   micro=`echo $G13_VERSION | \
806          sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
807
808   if test "$major" -gt "$req_major"; then
809     ok=yes
810   else
811     if test "$major" -eq "$req_major"; then
812       if test "$minor" -gt "$req_minor"; then
813         ok=yes
814       else
815         if test "$minor" -eq "$req_minor"; then
816           if test "$micro" -ge "$req_micro"; then
817             ok=yes
818           fi
819         fi
820       fi
821     fi
822   fi
823   if test "$ok" = "yes"; then
824     AC_MSG_RESULT(yes)
825   else
826     AC_MSG_RESULT(no)
827     AC_MSG_WARN([G13 must be at least version $NEED_G13_VERSION])
828   fi
829 fi
830 run_g13_test="$ok"
831 AC_ARG_ENABLE(g13-test,
832   AC_HELP_STRING([--disable-g13-test], [disable G13 run test]),
833          run_g13_test=$enableval)
834 AM_CONDITIONAL(RUN_G13_TESTS, test "$run_g13_test" = "yes")
835
836
837 # Check for funopen
838 AC_CHECK_FUNCS(funopen)
839 if test $ac_cv_func_funopen != yes; then
840     # No funopen but we can implement that in terms of fopencookie.
841     AC_CHECK_FUNCS(fopencookie)
842     if test $ac_cv_func_fopencookie = yes; then
843         AC_REPLACE_FUNCS(funopen)
844     else
845         AC_MSG_WARN([
846 ***
847 *** No implementation of fopencookie or funopen available
848 ***])
849     fi
850 fi
851
852 # Check for getgid etc
853 AC_CHECK_FUNCS(getgid getegid)
854
855
856 # Replacement functions.
857 AC_REPLACE_FUNCS(stpcpy)
858 AC_REPLACE_FUNCS(setenv)
859
860 # Assuan check for descriptor passing.
861 AC_CHECK_MEMBER(struct cmsghdr.cmsg_len,
862                 [supports_descriptor_passing=yes],
863                 [supports_descriptor_passing=no
864                  AC_MSG_WARN([
865 ***
866 *** Data structure for sending ancillary data missing.
867 *** Descriptor passing won't work.
868 ***])],[
869 #include <stdlib.h>
870 #include <stddef.h>
871 #include <stdio.h>
872 #include <sys/types.h>
873 #include <sys/socket.h>
874 #include <sys/un.h>
875 #if HAVE_SYS_UIO_H
876 #include <sys/uio.h>
877 #endif
878 #include <unistd.h>
879        ])
880
881
882 dnl There seems to be a problem with Apple and decriptor passing.
883 dnl Until we found a solution we change the default to no.
884 dnl See bug 1483.
885 case "${host}" in
886     *-apple-darwin*)
887       use_descriptor_passing=no
888       ;;
889     *)
890       use_descriptor_passing=yes
891       ;;
892 esac
893 AC_ARG_ENABLE(fd-passing,
894   AC_HELP_STRING([--disable-fd-passing], [do not use FD passing]),
895   use_descriptor_passing=$enableval)
896
897 if test "$supports_descriptor_passing" != "yes"; then
898   use_descriptor_passing=no
899 fi
900
901 if test "$use_descriptor_passing" = "yes"; then
902 AC_DEFINE(USE_DESCRIPTOR_PASSING,1,
903           [Defined if descriptor passing is enabled and supported])
904 fi
905
906 AM_CONDITIONAL(USE_DESCRIPTOR_PASSING, test "$use_descriptor_passing" = "yes")
907
908
909 uiserver=no
910 if test "$use_descriptor_passing" = "yes" && test "$have_libassuan" = "yes"; then
911   uiserver=yes
912 fi
913 if test "$uiserver" != "no"; then
914   AC_DEFINE(ENABLE_UISERVER, 1,
915             [Defined if we are building with uiserver support.])
916 fi
917 AM_CONDITIONAL(HAVE_UISERVER, test "$uiserver" != "no")
918
919
920 # Add a few constants to help porting to W32
921 AH_VERBATIM([SEPCONSTANTS],
922 [
923 /* Separators as used in $PATH.  */
924 #ifdef HAVE_DOSISH_SYSTEM
925 #define PATHSEP_C ';'
926 #else
927 #define PATHSEP_C ':'
928 #endif
929 ])
930
931 AH_BOTTOM([
932 /* Definition of GCC specific attributes.  */
933 #if __GNUC__ > 2
934 # define GPGME_GCC_A_PURE  __attribute__ ((__pure__))
935 #else
936 # define GPGME_GCC_A_PURE
937 #endif
938
939 /* Under WindowsCE we need gpg-error's strerror macro.  */
940 #define GPG_ERR_ENABLE_ERRNO_MACROS 1
941
942 #define CRIGHTBLURB "Copyright (C) 2000 Werner Koch\n" \
943                     "Copyright (C) 2001--2013 g10 Code GmbH\n"
944 ])
945
946
947 # Substitution used for gpgme-config
948 GPGME_CONFIG_LIBS="-lgpgme"
949 GPGME_CONFIG_CFLAGS=""
950 GPGME_CONFIG_HOST="$host"
951 AC_SUBST(GPGME_CONFIG_API_VERSION)
952 AC_SUBST(GPGME_CONFIG_LIBS)
953 AC_SUBST(GPGME_CONFIG_CFLAGS)
954 AC_SUBST(GPGME_CONFIG_HOST)
955
956 # Frob'da Variables
957 LTLIBOBJS=`echo "$LIB@&t@OBJS" |
958            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
959 AC_SUBST(LTLIBOBJS)
960
961 # Some checks for gpgme-tool
962 # Done at top: AC_CHECK_HEADER([argp.h])
963 AC_CHECK_TYPES([error_t], [],
964    [AC_DEFINE([error_t], [int],
965    [Define to a type to use for `error_t' if it is not otherwise available.])],
966    [#include <errno.h>])
967
968
969 # A substitution to set generated files in a Emacs buffer to read-only.
970 AC_SUBST(emacs_local_vars_begin, [['Local][ ][Variables:']])
971 AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
972 AC_SUBST(emacs_local_vars_end, ['End:'])
973
974
975 # Last check.
976 die=no
977 if test "$have_gpg_error" = "no"; then
978    die=yes
979    AC_MSG_NOTICE([[
980 ***
981 *** You need libgpg-error to build this program.
982 **  This library is for example available at
983 ***   ftp://ftp.gnupg.org/gcrypt/libgpg-error
984 *** (at least version $NEED_GPG_ERROR_VERSION is required.)
985 ***]])
986 fi
987 if test "$have_libassuan" = "no"; then
988    die=yes
989    AC_MSG_NOTICE([[
990 ***
991 *** You need libassuan to build this program with GPGSM support.
992 *** This library is for example available at
993 ***   ftp://ftp.gnupg.org/gcrypt/libassuan/
994 *** (at least version $NEED_LIBASSUAN_VERSION (API $NEED_LIBASSUAN_API) is required).
995 ***]])
996 fi
997
998 if test "$die" = "yes"; then
999     AC_MSG_ERROR([[
1000 ***
1001 *** Required libraries not found. Please consult the above messages
1002 *** and install them before running configure again.
1003 ***]])
1004 fi
1005
1006
1007 #
1008 # Create config files
1009
1010 AC_CONFIG_FILES(Makefile src/Makefile
1011                 tests/Makefile
1012                 tests/gpg/Makefile
1013                 tests/gpgsm/Makefile
1014                 tests/opassuan/Makefile
1015                 doc/Makefile
1016                 src/versioninfo.rc
1017                 src/gpgme.h)
1018 AC_CONFIG_FILES(src/gpgme-config, chmod +x src/gpgme-config)
1019 AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd])
1020 AC_OUTPUT
1021
1022 echo "
1023         GPGME v${VERSION} has been configured as follows:
1024
1025         Revision:        mym4_revision  (mym4_revision_dec)
1026         Platform:        $host
1027
1028         GnuPG path:      $GPG
1029         GnuPG version:   $GPG_VERSION, min. $NEED_GPG_VERSION
1030         GpgSM path:      $GPGSM
1031         GpgSM version:   $GPGSM_VERSION, min. $NEED_GPGSM_VERSION
1032         GpgConf path:    $GPGCONF
1033         GpgConf version: $GPGCONF_VERSION, min. $NEED_GPGCONF_VERSION
1034         G13 path:        $G13
1035         G13 version:     $G13_VERSION, min. $NEED_G13_VERSION
1036
1037         Assuan version:  $libassuan_config_version, min. $NEED_LIBASSUAN_VERSION
1038
1039         UI Server:       $uiserver
1040         FD Passing:      $use_descriptor_passing
1041         GPGME Pthread:   $have_pthread
1042 "