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