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