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