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