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