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